﻿/*
MAIN HORIZONTAL MENU ADJUSTMENT
This method will adjust main navigation placement
based upon the language selected and the 
browser being used by the user.  This needs to 
happen because the English and Spanish menu text
are different lengths which leads to the Spanish 
text being cut off.
8/17/10
*/
function menuwidths(languageType) {
    var langID = String(languageType);

    //alert("menuwidths functioni called: " + langID);
    //alert("cookie: " + langID);
    
    // Check to see if no language has been selected by the user yet.  If not then set the language to English (1033)
    if (langID == "undefined") {
        //langID = "1033";
        // Check the saved cookie
       // langID = readCookie('language')
        //alert("cookie: " + langID);
        //if (langID == "undefined") {
            // just hard code it at this point
            langID = "1033";
            //alert("cookie: " + x);
        //}
//
    }
    //alert("langID: " + langID);
    // Run a check for the DOM to make sure older browsers can still view site correctly
    if (document.getElementById) {
        // Now based on the language selected update menu placement
        switch (langID) {
            case "1033":
                
                document.getElementById("div1").style.left = "160px";
                document.getElementById("div2").style.left = "247px";
                document.getElementById("div3").style.left = "295px";
                document.getElementById("div4").style.left = "391px";
                document.getElementById("div5").style.left = "490px";
                document.getElementById("div6").style.left = "592px";
                break;
            case "1034":
                
                document.getElementById("div1").style.left = "145px";
                document.getElementById("div2").style.left = "265px";
                document.getElementById("div3").style.left = "330px";
                document.getElementById("div4").style.left = "437px";
                document.getElementById("div5").style.left = "515px";
                document.getElementById("div6").style.left = "620px";
                break;
        }
    // Older browser... IE4
    } else if (document.all) {
        // Now based on the language selected update menu placement
        switch (langID) {
            case "1033":
                document.all("div1").style.left = "160px";
                document.all("div2").style.left = "247px";
                document.all("div3").style.left = "295px";
                document.all("div4").style.left = "391px";
                document.all("div5").style.left = "490px";
                document.all("div6").style.left = "592px";
                break;
            case "1034":
                document.all("div1").style.left = "145px";
                document.all("div2").style.left = "265px";
                document.all("div3").style.left = "330px";
                document.all("div4").style.left = "437px";
                document.all("div5").style.left = "515px";
                document.all("div6").style.left = "620px";
                break;
        }
    // Older browser... Netscape4    
    } else {
        // Now based on the language selected update menu placement
        switch (langID) {
            case "1033":
                document.layers("div1").style.left = "160px";
                document.layers("div2").style.left = "247px";
                document.layers("div3").style.left = "295px";
                document.layers("div4").style.left = "391px";
                document.layers("div5").style.left = "490px";
                document.layers("div6").style.left = "592px";
                break;
            case "1034":
                document.layers("div1").style.left = "145px";
                document.layers("div2").style.left = "265px";
                document.layers("div3").style.left = "330px";
                document.layers("div4").style.left = "437px";
                document.layers("div5").style.left = "515px";
                document.layers("div6").style.left = "620px";
                break;
        }
    }
}

/*
WRITE COOKIE
Save the language ID to a cookie on the 
users computer.  This will fix the issues 
happening with the menu if someone leaves their
browser open while in Spanish and lets the
Session variable timeout.
*/
function createCookie(name, value, days) {
    //alert("c is for cookie:"+name+"value: "+value+"days: "+days);
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    } else {
        var expires = "";
    }
    document.cookie = name + "=" + value + expires + "; path=/";
}
/*
READ COOKIE
*/
function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}




