﻿var KaizennetLogo = new Image();
var CurrentPage = "";
var LoadedStyle = "";

function getcss(cssfile) {
    loadcss = document.createElement('link');
    loadcss.setAttribute("rel", "Stylesheet");
    loadcss.setAttribute("type", "text/CSS");
    loadcss.setAttribute("href", "Vault/Scripts/" + cssfile);
    document.getElementsByTagName("head")[0].appendChild(loadcss);
}

function Load_CSS() {
    if (screen.availHeight <= '1050') {
        getcss('KaizennetCorpStyle850.css');
        LoadedStyle = "850";
    }

    else if (screen.availHeight > '1050') {
        getcss('KaizennetCorpStyle850.css');
        LoadedStyle = "1000";
    }

    else {
        getcss('KaizennetCorpStyle850.css');
        LoadedStyle = "850";
    }
}

function InitialLoad() {
    //Navigator.browserlanguage used by IE       Navigator.Language used by Firefox + Opera

    if (navigator.appName == "Microsoft Internet Explorer") {
        if (navigator.browserLanguage.substr(0, 2) == "zh") {
            LoadControls('简体中文');
        }
        else {
            LoadControls('English');
        }
    }
    else if (navigator.appName == "Netscape") {
        if (navigator.language.substr(0, 2) == "zh") {
            LoadControls('简体中文');
        }
        else {
            LoadControls('English');
        }
    }
    else
        LoadControls('English');
}

function LoadControls(language) {
    KaizennetCorp.KaizennetCorpService.LoadTranslations(language, OnComplete);
}

function OnComplete(result) {
    if (result == "SUCCESS") {
        KaizennetCorp.KaizennetCorpService.Get_imgLogo(Load_imgLogo);
        if (CurrentPage == "") {
            LoadPage('Kaizennet')
        }
        else {
            LoadPage(CurrentPage);
        }
        KaizennetCorp.KaizennetCorpService.Get_option1(Load_option1);
        /*KaizennetCorp.KaizennetCorpService.Get_option2(Load_option2);
        KaizennetCorp.KaizennetCorpService.Get_option3(Load_option3);*/
    }
    else {
        KaizennetLogo.src = "./Vault/Images/KaizennetName52.png";
        document.getElementById("imgLogo").src = KaizennetLogo.src;
        document.getElementById("imgLoading").style.visibility = "hidden";
        document.getElementById("imgLogo").style.visibility = "visible";
        document.getElementById("childDiv1a").style.visibility = "visible";
        document.getElementById("childDiv1b").style.visibility = "visible";
        document.getElementById("optionsPane").style.visibility = "visible";
        document.getElementById("bannerDiv").style.visibility = "visible";
        document.getElementById("pageBody").style.visibility = "visible";
        document.getElementById("childDivBody").innerHTML = '<p class="tab">There was some trouble loading this page from the WCF service. Please contact the administrator - gp@kaizennet.net.</p><br><br>' + result;
    }
}

function LoadPage(curpage) {
    CurrentPage = curpage;
    switch (CurrentPage) {
        case "Kaizennet":
            KaizennetCorp.KaizennetCorpService.Get_divKaizennet(Load_childDivBody);
            /*if (LoadedStyle == "1000")
                document.getElementById("pageBody").style.backgroundImage = "url('Vault/Images/KaizennetPage748-1.png')";
            else if (LoadedStyle == "850")
                document.getElementById("pageBody").style.backgroundImage = "url('Vault/Images/KaizennetPage603-1.png')";*/
            KaizennetCorp.KaizennetCorpService.Get_div_Kaizennet_optionsPane(Load_optionsPane);
            break;
        /*case "Products":
            KaizennetCorp.KaizennetCorpService.Get_divProducts(Load_childDivBody);
            /*if (LoadedStyle == "1000")
                document.getElementById("pageBody").style.backgroundImage = "url('Vault/Images/KaizennetPage748-2.png')";
            else if (LoadedStyle == "850")
                document.getElementById("pageBody").style.backgroundImage = "url('Vault/Images/KaizennetPage603-2.png')";
            KaizennetCorp.KaizennetCorpService.Get_div_Products_optionsPane(Load_optionsPane);
            break;
        case "Services":
            KaizennetCorp.KaizennetCorpService.Get_divServices(Load_childDivBody);
            /*if (LoadedStyle == "1000")
                document.getElementById("pageBody").style.backgroundImage = "url('Vault/Images/KaizennetPage748-3.png')";
            else if (LoadedStyle == "850")
                document.getElementById("pageBody").style.backgroundImage = "url('Vault/Images/KaizennetPage603-3.png')";
            KaizennetCorp.KaizennetCorpService.Get_div_Services_optionsPane(Load_optionsPane);
            break;*/
        case "Kaizennet_Profile":
            KaizennetCorp.KaizennetCorpService.Get_div_Kaizennet_Profile(Load_childDivBody);
            break;
        case "Kaizennet_SQLServer":
            KaizennetCorp.KaizennetCorpService.Get_div_Kaizennet_SQLServer(Load_childDivBody);
            break;
        case "Kaizennet_Interests":
            KaizennetCorp.KaizennetCorpService.Get_div_Kaizennet_Interests(Load_childDivBody);
            break;
        case "Kaizennet_This_Site":
            KaizennetCorp.KaizennetCorpService.Get_div_Kaizennet_This_Site(Load_childDivBody);
            break;
       /* case "Kaizennet_Staff":
            KaizennetCorp.KaizennetCorpService.Get_div_Kaizennet_Staff(Load_childDivBody);
            break;
        case "Kaizennet_Employment":
            KaizennetCorp.KaizennetCorpService.Get_div_Kaizennet_Employement(Load_childDivBody);
            break;
        case "Kaizennet_Contact":
            KaizennetCorp.KaizennetCorpService.Get_div_Kaizennet_Contact(Load_childDivBody);
            break;
        /*case "Products_Frontier":
            KaizennetCorp.KaizennetCorpService.Get_div_Products_Frontier(Load_childDivBody);
            break;
        case "Services_Development":
            KaizennetCorp.KaizennetCorpService.Get_div_Services_Development(Load_childDivBody);
           /* if (LoadedStyle == "1000")
                document.getElementById("pageBody").style.backgroundImage = "url('Vault/Images/KaizennetPage748-3.png')";
            else if (LoadedStyle == "850")
                document.getElementById("pageBody").style.backgroundImage = "url('Vault/Images/KaizennetPage603-3.png')";
            KaizennetCorp.KaizennetCorpService.Get_div_Services_optionsPane(Load_optionsPane);
            break;
        case "Services_Analytics":
            KaizennetCorp.KaizennetCorpService.Get_div_Services_Analytics(Load_childDivBody);
            /*if (LoadedStyle == "1000")
                document.getElementById("pageBody").style.backgroundImage = "url('Vault/Images/KaizennetPage748-3.png')";
            else if (LoadedStyle == "850")
                document.getElementById("pageBody").style.backgroundImage = "url('Vault/Images/KaizennetPage603-3.png')";
            KaizennetCorp.KaizennetCorpService.Get_div_Services_optionsPane(Load_optionsPane);
            break;
        case "Services_Database":
            KaizennetCorp.KaizennetCorpService.Get_div_Services_Database(Load_childDivBody);
            /*if (LoadedStyle == "1000")
                document.getElementById("pageBody").style.backgroundImage = "url('Vault/Images/KaizennetPage748-3.png')";
            else if (LoadedStyle == "850")
                document.getElementById("pageBody").style.backgroundImage = "url('Vault/Images/KaizennetPage603-3.png')";
            KaizennetCorp.KaizennetCorpService.Get_div_Services_optionsPane(Load_optionsPane);
            break;
        case "Services_SAP_BPC":
            KaizennetCorp.KaizennetCorpService.Get_div_Services_SAP_BPC(Load_childDivBody);
            /*if (LoadedStyle == "1000")
                document.getElementById("pageBody").style.backgroundImage = "url('Vault/Images/KaizennetPage748-3.png')";
            else if (LoadedStyle == "850")
                document.getElementById("pageBody").style.backgroundImage = "url('Vault/Images/KaizennetPage603-3.png')";
            KaizennetCorp.KaizennetCorpService.Get_div_Services_optionsPane(Load_optionsPane);
            break;*/
        default:
            KaizennetCorp.KaizennetCorpService.Get_divKaizennet(Load_childDivBody);
            /*if (LoadedStyle == "1000")
                document.getElementById("pageBody").style.backgroundImage = "url('Vault/Images/KaizennetPage748-1.png')";
            else if (LoadedStyle == "850")
                document.getElementById("pageBody").style.backgroundImage = "url('Vault/Images/KaizennetPage603-1.png')";*/
            KaizennetCorp.KaizennetCorpService.Get_div_Kaizennet_optionsPane(Load_optionsPane);
            break;
    }
}

function Load_imgLogo(result) {
    if (result != "NULL") {
        KaizennetLogo.src = result;
        document.getElementById("imgLogo").src = KaizennetLogo.src;
    }
}

function Load_childDivBody(result) {
    if (result != "NULL") {   
        document.getElementById("childDivBody").innerHTML = result;
    }
}

function Load_option1(result) {
    if (result != "NULL") {
        //document.getElementById("option1").style.backgroundImage = "url" + "('" + result + "')";
    }
}

//function Load_option2(result) {
//    if (result != "NULL") {
//        //document.getElementById("option2").style.backgroundImage = "url" + "('" + result + "')";
//    }
//}

//function Load_option3(result) {
//    if (result != "NULL") {
//       // document.getElementById("option3").style.backgroundImage = "url" + "('" + result + "')";
//    }
//}

function Load_optionsPane(result) {
    if (result != "NULL") {
        document.getElementById("optionsPane").innerHTML = result;
        document.getElementById("imgLoading").style.visibility = "hidden";
        document.getElementById("imgLogo").style.visibility = "visible";
        document.getElementById("englishButton").style.visibility = "hidden";
        document.getElementById("chineseButton").style.visibility = "hidden";
        document.getElementById("childDiv1a").style.visibility = "visible";
        document.getElementById("childDiv1b").style.visibility = "visible";
        document.getElementById("optionsPane").style.visibility = "visible";
        document.getElementById("bannerDiv").style.visibility = "visible";
        document.getElementById("pageBody").style.visibility = "visible";
    }
}
