/*
All program code, including but not limited to html, xhtml,  javascript, php, and css contained herein is copyrighted by Magic Lamp Computing, LLC.
Any use of this code without express written approval of Magic Lamp Computing, LLC is prohibited.
*/
MLC.Init = function ()
{
  MLC.WindowRefArr = {"TechCombine":false};
  
  MLC.TestStatus = 0; //0=production, 1=192.168.1.101
  
  MLC.SystemFailed = false;
  MLC.ROHandleArr   = new Array(0);
  MLC.ROSourceArr   = new Array(0);
  MLC.ROSendDataArr = new Array(0);
  MLC.ROMethodArr   = new Array(0);
  MLC.ROStatusArr   = new Array(0);
  MLC.ROResponseArr = new Array(0);
  MLC.ROTimerArr    = new Array(0);
  MLC.ROTryCountArr = new Array(0); 
  MLC.AccountMaintenanceROIdx = 0;
  
  MLC.ROIdxCount = 1;
  
  for (i=0; i<MLC.ROIdxCount; i++)
  {
    MLC.ROHandleArr[i]   = false;
    MLC.ROSourceArr[i]   = "";
    MLC.ROSendDataArr[i] = "";
    MLC.ROMethodArr[i]   = "";
    MLC.ROStatusArr[i]   = "";
    MLC.ROResponseArr[i] = "";
    MLC.ROTimerArr[i]    = false;
    MLC.ROTryCountArr[i] = false;
    MLC.CreateRO(i);
    if (MLC.SystemFailed)
    {
      break;
    }
  }
  MLC.IsLoggedIn = false;
  MLC.ConstructCustomerFieldsObj();
  MLC.CustomerAccountFunction2 = "";   
  MLC.FieldNamesList = "";
  MLC.FieldValuesList = "";
  MLC.UpdateAction = "";
  MLC.UpdateIsPending = false;
  
  MLC.CloseAllMenus();
  
  var CopyRightYear = new Date().getFullYear();
  CopyRightYear = (CopyRightYear < 2009) ? 2009 : CopyRightYear;  
  MLC.$("mlcCopyRightYear").innerHTML = CopyRightYear;
  
  MLC.VMarquee();
  
  //process any autostart slideshows
  var URLArgs,URLArgsArr,ArgKey,ArgVal,i,OpenProjects;

  OpenProjects = false;
  URLArgs = window.location.search;
  if (URLArgs != "")
  {
    URLArgsArr = URLArgs.substring(1).split("&");
    for (i = 0; i < URLArgsArr.length; i++)
    {
      ArgKey = URLArgsArr[i].substring(0,3);
      ArgVal = URLArgsArr[i].substring(3);
      if (ArgKey.substring(0,1) == "p")
      {
        if (!OpenProjects)
        {
          OpenProjects = confirm("You have been directed here to view project slide show(s)\n" + 
                                 "If you do not wish to have the slide show open automatically,\n" +
                                 "hit cancel. Slide shows can always be selected from the Projects menu.")
        }
        // show slideshow for project
        if (OpenProjects)
        {
          MLC.SelectProject(ArgVal);
        }
        else
        {
          break;
        }
      }
    }
    if (OpenProjects)
    {
      MLC.ProjectsOpenClose();
    }
  }
}
MLC.ConstructCustomerFieldsObj = function ()
{
    MLC.CustomerFieldsObj = new Object();
    var InputTagsArr = MLC.$("mlcCustomerAccount").getElementsByTagName("input");
    var FieldName = ""
    for (var i=0; i < InputTagsArr.length; i++)
    {
      if (InputTagsArr[i].id.substring(0,5) == "mlcdb")
      {
        FieldName = InputTagsArr[i].id.substring(5);
        eval("MLC.CustomerFieldsObj."+FieldName+"=''");
      }
    }
}
MLC.GoToTechCombine = function ()
{
  var TechCombineIsOpen = false;
  if (MLC.WindowRefArr["TechCombine"])
  {
    TechCombineIsOpen = (MLC.WindowRefArr["TechCombine"].closed) ? false : true;
  }
  if (!TechCombineIsOpen)
  {
    MLC.WindowRefArr["TechCombine"] = false;
    TechCombineIsOpen = (typeof(window.opener) == "undefined" || window.opener == null) ? false : true;
    if (TechCombineIsOpen)
    {
      TechCombineIsOpen = (window.opener.closed) ? false : true;
    }
    if (TechCombineIsOpen)
    {
      try
      {
        TechCombineIsOpen = ("TC" in window.opener) ? true : false;
      }
      catch (e)
      {
        TechCombineIsOpen = true;
      }
    }
  }
  if (TechCombineIsOpen)
  {
    alert("The TechCombine website is already open in another window or tab.");
  }
  else
  {
     MLC.WindowRefArr["TechCombine"] = window.open("http://www.techcombine.com");
  }
}
MLC.AboutMLCOpenClose = function ()
{
  if (MLC.$("mlcAboutMLCBtn").innerHTML == "close")
  {
    MLC.CloseAllMenus();
  }
  else
  {  
    if (MLC.CloseAllMenus())
    {
      MLC.$("mlcAboutMLCPanel").style.visibility = "visible";
      MLC.$("mlcAboutMLCBtn").innerHTML = "close";    
    }
  }
}
MLC.WorkingWithOpenClose = function ()
{
  if (MLC.$("mlcWorkingWithBtn").innerHTML == "open")
  {
    if (MLC.CloseAllMenus())
    {
      MLC.$("mlcWorkingWithSelect").style.visibility = "visible";
      MLC.$("mlcWorkingWithBtn").innerHTML = "close";
    }
  }
  else if (MLC.$("mlcSlideShowHelp").style.display == "none")
  {
    MLC.CloseAllMenus();
  }
  else
  {
    MLC.$("mlcSlideShowHelp").style.display = "none";
  }  
}
 
MLC.SelectWorkingWith = function (WorkingWithSel)
{
}

MLC.CustomerAccountsOpenClose = function ()
{
  if (MLC.$("mlcCustomerAccountsBtn").innerHTML == "close")
  {
    MLC.CloseAllMenus();
  }
  else
  { 
    if (MLC.CloseAllMenus())
    {
      MLC.$("mlcCustomerAccountsBtn").innerHTML = "close"; 
      if (MLC.IsLoggedIn)
      {
        MLC.$("mlcCustomerAccountSelect").style.visibility = "visible";
      }
      else
      {
        MLC.ShowCustomerLogin();
      }
    }
  }
}
MLC.ShowCustomerLogin = function ()
{
  MLC.$("mlcCustomerAccountLogin").style.visibility = "visible"; 
}
MLC.LoginCustomer = function ()
{
  var CustomerID = MLC.$("mlcCustomerID").value;
  var CustomerPassword = MLC.$("mlcCustomerPassword").value;
  var LoginOK = true;
  if (CustomerID == "" || CustomerPassword == "")
  {
    LoginOK = false;
    alert("Please enter both your Customer ID and your Password");
  }
  if (LoginOK)
  {
    MLC.FieldNamesList = "CustomerID" + "^" + "Password";
    MLC.FieldValuesList = CustomerID + "^" + CustomerPassword;
    MLC.UpdateAction = "get";
    MLC.CustomerAccountFunction2 = "MLC.LoginCustomer2()";
    MLC.MaintainCustomerAccount();
  }
}
MLC.LoginCustomer2 = function ()
{
  MLC.CloseAllMenus();
  MLC.$("mlcCustomerAccountsBtn").innerHTML = "close"; 
  MLC.IsLoggedIn = true;
  MLC.UpdateAction = "update";
  MLC.$("mlcCustomerAccountSelect").style.visibility = "visible";
}
MLC.CancelCustomerLogin = function ()
{
  MLC.CloseAllMenus();
  MLC.IsLoggedIn = false;
}
MLC.CustomerForgot = function ()
{
  alert("Forgot function not available");
  MLC.IsLoggedIn = false;
}
MLC.CustomerRegister = function ()
{
  alert("Register function not available");
  MLC.IsLoggedIn = false;
}
MLC.SelectCustomerAccount = function (Selection)
{
  if (Selection == "10")
  {
    MLC.UpdateCustomerAccount();  
  }
  else if (Selection == "20")
  {
  }
}
MLC.ProjectsOpenClose = function ()
{
  if (MLC.$("mlcProjectBtn").innerHTML == "open")
  {
    if (MLC.CloseAllMenus())
    {
      MLC.$("mlcProjectSelect").style.visibility = "visible";
      MLC.$("mlcProjectBtn").innerHTML = "close";
    }
  }
  else if (MLC.$("mlcSlideShowHelp").style.display == "none")
  {
    MLC.CloseAllMenus();
  }
  else
  {
    MLC.$("mlcSlideShowHelp").style.display = "none";
  }  
}
MLC.SelectProject = function (ProjID)
{

  switch (ProjID)
  {
    case "1": //Slide Show Help
      MLC.$("mlcSlideShowHelp").style.display = "block";
      MLC.$("mlcProjectBtn").innerHTML = "close";
      break;
    case "10": //Ethiopia Construction Project
      window.open("EthiopiaConstructionProject.html", "", 
                  "menubar,toolbar,width=700px, height=750px, status, resizable, scrollbars");
      break;
    case "11": //Ethiopia Project Management
      window.open("EthiopiaProjectManagement.html", "", 
                  "menubar,toolbar,width=700px, height=750px, status, resizable, scrollbars");
      break;
    case "12": //Business Operations Accounting
      window.open("BusinessOpsAccounting.html", "", 
                  "width=700px, height=750px, status, resizable, scrollbars");
      break;
    case "13": //Restaurant Operations
      window.open("RestaurantOperations.html", "", 
                  "menubar,toolbar,width=700px, height=750px, status, resizable, scrollbars");
      break;     
    case "20": //Slide Show For KARE Web Site
      window.open("KAREWebSite.html", "", 
                  "menubar,toolbar,width=700px, height=750px, status, resizable, scrollbars");
      break;
    case "21": //Visit KARE Web Site
      if (MLC.TestStatus == 0)
      {
        window.open("http://www.amplv.com/karelv", "", 
                    "menubar, toolbar, status, resizable, scrollbars");
      }
      else // MLC.TestStatus == 1
      {
        window.open("http://192.168.1.101/magiclampcomputing/karelv/index.html", "", 
                    "menubar, toolbar, status, resizable, scrollbars");
      }
      break;
    case "30": //Slide Show For  RealyTechPro Web Site
      window.open("RealtyTechProWebSite.html", "", 
                  "width=700px, height=670px, status, resizable, scrollbars");
      break;
    case "31": //Visit Realty Tech Pro Web Site
      if (MLC.TestStatus == 0)
      {
        window.open("http://www.amplv.com/realtytechpro", "", 
                    "menubar, toolbar, status, resizable, scrollbars");
      }
      else // MLC.TestStatus == 1
      {
        window.open("http://192.168.1.101/magiclampcomputing/realtytechpro/", "", 
                    "menubar, toolbar, status, resizable, scrollbars");
      }
      break;
    case "41": //Visit Nubani Web Site
      if (MLC.TestStatus == 0)
      {
        window.open("http://www.nubanitradingcompany.com/", "", 
                    "menubar, toolbar, status, resizable, scrollbars");
      }
      else // MLC.TestStatus == 1
      {
        window.open("http://192.168.1.101/magiclampcomputing/nubani/", "", 
                    "menubar, toolbar, status, resizable, scrollbars");
      }
      break;
    case "51": //Visit Zoon Web Site
      if (MLC.TestStatus == 0)
      {
        window.open("http://www.zoonchip.com/", "", 
                    "menubar, toolbar, status, resizable, scrollbars");
      }
      else // MLC.TestStatus == 1
      {
        window.open("http://192.168.1.101/magiclampcomputing/zoonchip/", "", 
                    "menubar, toolbar, status, resizable, scrollbars");
      }
      break;
    case "99": //www.MagicLampComputing.com
      window.open("MagicLampComputingWebSite.html", "", 
                  "width=700px, height=670px, status, resizable, scrollbars");
      break;
  }
  MLC.$("mlcProjectsSelections").value = "0";
}
MLC.ResourcesOpenClose = function ()
{
  if (MLC.$("mlcResourcesBtn").innerHTML == "close")
  {
    MLC.CloseAllMenus();
  }
  else
  {  
    if (MLC.CloseAllMenus())
    {
      MLC.$("mlcResourceSelect").style.visibility = "visible";
      MLC.$("mlcResourcesBtn").innerHTML = "close";     
    }
  }
} 
MLC.SelectResource = function (ResourceOption)
{
  MLC.$("mlcTextBox").style.visibility = "hidden";
  if (ResourceOption == "010")
  {
    window.open('Resumes/RDannaker-Resume.pdf');
  }
  else if (ResourceOption == "020")
  {
    alert("Resume not yet available on-line.\n" + 
          "For further info contact us a MagicLampComputing@gmail.com");
  }
  else if (ResourceOption >= "200" && ResourceOption < "300")
  {
    MLC.ShowTextBox("mlcResources" + ResourceOption + "Txt");
    MLC.$("mlcResourceSelections").value = "0";
  }
}

MLC.DevelopersOpenClose = function ()
{
  if (MLC.$("mlcDevelopersBtn").innerHTML == "close")
  {
    MLC.CloseAllMenus();
  }
  else
  {  
    if (MLC.CloseAllMenus())
    {
      MLC.$("mlcDevelopersSelect").style.visibility = "visible";
      MLC.$("mlcDevelopersBtn").innerHTML = "close";    
    }
  }
} 
MLC.SelectDevelopers = function (DevelopersOption)
{
  MLC.$("mlcTextBox").style.visibility = "hidden";
  if (DevelopersOption == "010") // Tips & Tricks of the Trade
  {
    alert("Sorry. Temporarily unavailable.")
    //MLC.ShowTTTContent();
  }
  else if (DevelopersOption == "020")
  {
    window.open("http://www.magiclampcomputing.com/phpbb/index.php", "", 
                "width=700px, height=670px, status, resizable, scrollbars");
  }
  else if (DevelopersOption == "030") // Developer's Resources
  {
    alert("Sorry. Temporarily unavailable.")
  }
  MLC.$("mlcDevelopersSelections").value = "0";
}
MLC.ShowTTTContent = function ()
{  
  MLC.$("mlcTTT_Text_Container").style.visibility = "hidden";
  MLC.$("mlcTTT_Contents_Container").style.visibility = "visible"; 
}
MLC.CloseTTT = function ()
{
  MLC.$("mlcTTT_Text_Container").style.visibility = "hidden";
  MLC.$("mlcTTT_Contents_Container").style.visibility = "hidden"; 
}
MLC.CompanyPrivate = function ()
{
  if (MLC.CloseAllMenus())
  {
    MLC.$("CPSelect").style.visibility = "hidden";
    MLC.$("CPLogin").style.visibility = "visible";
    MLC.$("CompanyPrivatePanel").style.visibility = "visible";
  }
}
MLC.CPLogin = function ()
{
  var CPLoginID = MLC.$("CPLoginIDInp").value;
  var CPPassword = MLC.$("CPPasswordInp").value;
  if (CPLoginID == "webmaster" && CPPassword == "password")
  {
    MLC.$("CPLogin").style.visibility = "hidden";
    MLC.$("CPSelect").style.visibility = "visible";
  }
  else   
  {
    alert("Invalid login!");
  }  
}
MLC.CPCancel = function ()
{
  MLC.CloseAllMenus();
}
MLC.CPSelect = function (CPSelection)
{
  if (CPSelection != "0")
  {
    MLC.$("CompanyPrivatePanel").style.visibility = "hidden";
  }
  if (CPSelection == "10")
  {
    alert("No company news at this time.");
  }
  if (CPSelection == "20") //Maintain Customer Accounts
  {
    MLC.DisableInput("mlcdbCustomerID",true);
    MLC.DisableInput("mlcdbPassword",true);
    MLC.DisableInput("mlcdbCustomerStatus",true);
    MLC.$("mlcCustomerAccount").reset();
    MLC.$("CPSelect").style.visibility = "hidden";
    MLC.$("CPMaintainCustomerAccount").style.visibility = "visible";
  }
  else if (CPSelection == "30")
  {
        window.open("forum/mlcForumAdmin.php?", "", 
                "width=700px, height=670px, status, resizable, scrollbars");
  }
}
MLC.CPMaintainAccount = function ()
{
  var Action = MLC.WhichRadioChecked("CPAccountactionRad");
  var CustomerID = MLC.$("CPCustomerIDInp").value;
  if (Action == "" || CustomerID == "")
  {
    alert("Indicate what action to take and enter a Customer ID.");
  }
  else 
  {
    MLC.UpdateIsPending = true;
    MLC.$("CompanyPrivatePanel").style.visibility = "hidden";
    MLC.DisableInput("CPAccountContinueBtn",true);
    MLC.DisableInput("CPAccountCancelBtn",true);
    MLC.DisableInput("mlcdbPassword",false);
    MLC.DisableInput("mlcdbCustomerStatus",false);
    if (Action == "CPAccountActionRad1") // add
    {
      MLC.UpdateAction = "add";
      document.mlcCustomerAccount.reset();
      MLC.$("mlcdbCustomerID").value = CustomerID;
      MLC.$("mlcCustomerAccount").style.visibility = "visible";
    }
    else if  (Action == "CPAccountActionRad2") // update
    {
      MLC.FieldNamesList = "CustomerID" + "^" + "Password";
      MLC.FieldValuesList = CustomerID + "^" + MLC.$("mlcdbPassword").value;
      MLC.UpdateAction = "getnopassword";
      MLC.CustomerAccountFunction2 = "MLC.CPUpdateAccount2()";
      MLC.MaintainCustomerAccount();   
    }
  }
}
MLC.CPUpdateAccount2 = function ()
{
  MLC.UpdateAction = "update";
  MLC.$("mlcCustomerAccount").style.visibility = "visible";
}
 
MLC.CPCancelMaintainAccount = function ()
{
  MLC.$("mlcCustomerAccount").style.visibility = "hidden";
  MLC.$("CPMaintainCustomerAccount").style.visibility = "hidden";
  MLC.$("CPSelect").style.visibility = "visible";
  MLC.$("CompanyPrivatePanel").style.visibility = "visible";
}
MLC.CloseCompanyPrivate = function ()
{
  MLC.CloseAllMenus();
}

MLC.ShowTextBox = function (TextEle)
{
  MLC.$("mlcTextContainer").innerHTML = MLC.$(TextEle).innerHTML;
  MLC.$("mlcTextContainer").top = MLC.$(TextEle).top;
  MLC.$("mlcTextContainer").left = MLC.$(TextEle).left;
  MLC.$("mlcTextBox").style.visibility = "visible";
}
MLC.CloseTextBox = function ()
{
  MLC.$("mlcTextBox").style.visibility = "hidden";
}
MLC.CloseAllMenus = function ()
{
  if (MLC.UpdateIsPending)
  {
    alert("Updates are pending.\n\n" + 
          "Complete and save updates or cancel update.")
  }
  else
  {
    MLC.$("mlcAboutMLCPanel").style.visibility = "hidden";
    MLC.$("mlcAboutMLCBtn").innerHTML = "open";
    MLC.$("mlcWorkingWithSelect").style.visibility = "hidden";
    MLC.$("mlcWorkingWithBtn").innerHTML = "open"; 
    MLC.$("mlcCustomerAccountSelect").style.visibility = "hidden";
    MLC.$("mlcCustomerAccountLogin").style.visibility = "hidden";
    MLC.$("mlcCustomerAccountsBtn").innerHTML = "open";
    MLC.$("mlcCustomerAccount").style.visibility = "hidden";
    MLC.$("mlcProjectSelect").style.visibility = "hidden";
    MLC.$("mlcProjectBtn").innerHTML = "open";
    MLC.$("mlcSlideShowHelp").style.display = "none";
    MLC.$("mlcResourceSelect").style.visibility = "hidden";
    MLC.$("mlcResourcesBtn").innerHTML = "open";
    MLC.$("mlcDevelopersSelect").style.visibility = "hidden";
    MLC.$("mlcDevelopersBtn").innerHTML = "open";
    MLC.$("mlcTTT_Contents_Container").style.visibility = "hidden";   
    MLC.$("mlcTTT_Text_Container").style.visibility = "hidden";    
    MLC.$("CompanyPrivatePanel").style.visibility = "hidden";
    MLC.$("CPLogin").style.visibility = "hidden";
    MLC.$("CPSelect").style.visibility = "hidden"; 
    MLC.$("CPMaintainCustomerAccount").style.visibility = "hidden"; 
    MLC.$("mlcTextBox").style.visibility = "hidden";
    MLC.DisableInput("CPAccountContinueBtn",false);
    MLC.DisableInput("CPAccountCancelBtn",false);
  }
  return !MLC.UpdateIsPending;  
}

MLC.UpdateCustomerAccount = function ()
{
  MLC.UpdateIsPending = true;
  MLC.UpdateAction = "update";
  MLC.$("mlcCustomerAccount").style.visibility = "visible";  
}
MLC.CancelCustomerAccountUpdate = function ()
{ 
  var Confirmed = confirm("Are you sure you want to cancel your changes?\n\n" +
                      "Click 'OK' to discard your changes.\n" +
                      "Click 'Cancel' to continue making changes.");
  if (Confirmed)
  {  
    MLC.$("mlcCustomerAccount").style.visibility = "hidden";
    MLC.DisableInput("CPAccountContinueBtn",false);
    MLC.DisableInput("CPAccountCancelBtn",false);
    MLC.UpdateIsPending = false;
  }
}
MLC.SaveCustomerAccountUpdate = function ()
{
  MLC.DisableInput("CPAccountContinueBtn",false);
  MLC.DisableInput("CPAccountCancelBtn",false);
  MLC.FieldNamesList = "";
  MLC.FieldValuesList = "";
  for (var FieldName in MLC.CustomerFieldsObj)
  {
    MLC.FieldNamesList = MLC.FieldNamesList + FieldName + "^";
    MLC.FieldValuesList = MLC.FieldValuesList + MLC.$("mlcdb"+FieldName).value + "^";    
  }
  MLC.FieldNamesList = MLC.FieldNamesList.substring(0,MLC.FieldNamesList.length - 1);
  MLC.FieldValuesList = MLC.FieldValuesList.substring(0,MLC.FieldValuesList.length - 1);
  MLC.CustomerAccountFunction2 = "MLC.SaveCustomerAccountUpdate2()";
  MLC.MaintainCustomerAccount();
}
MLC.SaveCustomerAccountUpdate2 = function ()
{
  if (MLC.UpdateAction == "update")
  {
    alert("Customer Account has been updated.");
  }
  else if (MLC.UpdateAction == "add")
  {
    alert("Customer Account has been added.");
  }
  MLC.DisableInput("CPAccountContinueBtn",false);
  MLC.DisableInput("CPAccountCancelBtn",false);
  MLC.$("mlcCustomerAccount").style.visibility = "hidden";
  MLC.UpdateIsPending = false;
}
MLC.MaintainCustomerAccount = function ()
{
  var SendKey = MLC.GenSendKey();
  var Codes = "";
  Codes = "Codes=" +
           MLC.Encode(MLC.UpdateAction + "|" + MLC.FieldNamesList + "|" +
                      MLC.FieldValuesList,SendKey) +
           "|" + MLC.Encode(SendKey,"");
  MLC.ROSourceArr[MLC.AccountMaintenanceROIdx] = "MaintainCustomerAccount.php";
  MLC.ROSendDataArr[MLC.AccountMaintenanceROIdx] = Codes;
  MLC.ROMethodArr[MLC.AccountMaintenanceROIdx] = "POST";
  MLC.OpenAsyncRO(MLC.AccountMaintenanceROIdx);
}
MLC.MaintainCustomerAccount2 = function ()
{
  if (MLC.ROResponseArr[MLC.AccountMaintenanceROIdx].substring(0,16) == "Customer Record:")
  {
    var ValsKeysArr = MLC.ROResponseArr[MLC.AccountMaintenanceROIdx].substring(16).split("~");
    var KeysArr = ValsKeysArr[0].split("^");
    var ValsArr = ValsKeysArr[1].split("^");
    for (var i=0; i<KeysArr.length; i++)
    {
      if (KeysArr[i] in MLC.CustomerFieldsObj)
      {
        MLC.$("mlcdb"+KeysArr[i]).value = ValsArr[i];
      }
    }
    eval(MLC.CustomerAccountFunction2);
  }
  else if (MLC.ROResponseArr[MLC.AccountMaintenanceROIdx].substring(0,15) == "Customer Error:")
  {
    alert(MLC.ROResponseArr[MLC.AccountMaintenanceROIdx].substring(15));
  }
  else
  {
    alert(MLC.ROResponseArr[MLC.AccountMaintenanceROIdx]);
  }
}

