var MAX_SCHEME_ID = 13;
var COOKIE_DURATION = 365;

var URL_PARAM_NAME = "cs";

var textColors = new Array();
var bgColors = new Array();
var linkColors = new Array();

//index 0 not used
textColors[1] = "#000000";
textColors[2] = "#FFFFFF";
textColors[3] = "#000000";
textColors[4] = "#000000";
textColors[5] = "#000000";
textColors[6] = "#000000";
textColors[7] = "#000000";
textColors[8] = "#000000";
textColors[9] = "#000000";
textColors[10] = "#000000";
textColors[11] = "#000000";
textColors[12] = "#000000";
textColors[13] = "#000000";

//index 0 not used
bgColors[1] = "#FFFFFF"; //white
bgColors[2] = "#000000"; //black
bgColors[3] = "#DDDDDD"; //grey
bgColors[4] = "#FC7A86"; //red
bgColors[5] = "#FFCC99"; //orange
bgColors[6] = "#FFFFCC"; //cream
bgColors[7] = "#FEFD82"; //yellow
bgColors[8] = "#99CC99"; //green
bgColors[9] = "#CCCC99"; //olive green
bgColors[10] = "#CCFFFF"; //turquoise  
bgColors[11] = "#99CCFF"; //blue
bgColors[12] = "#CCCCFF"; //violet
bgColors[13] = "#FFC9F2"; //pink

//index 0 not used
linkColors[1] = "#000000";
linkColors[2] = "#FFFFFF";
linkColors[3] = "#000000";
linkColors[4] = "#000000";
linkColors[5] = "#000000";
linkColors[6] = "#000000";
linkColors[7] = "#000000";
linkColors[8] = "#000000";
linkColors[9] = "#000000";
linkColors[10] = "#000000";
linkColors[11] = "#000000";
linkColors[12] = "#000000";
linkColors[13] = "#000000";


var cookieVal = getCookie ("color_scheme");
if (isNaN(parseInt(cookieVal)) || (parseInt(cookieVal) < 0)) {

    cookieVal = 0

}



//must add the B to the end to avoid a conflict with code in toolbarInit.js
var oldEvtB = window.onload;

window.onload = function() { 
    
    if (oldEvtB) { 
        oldEvtB();
    } 
    
   
    if((cookieVal != "") && (cookieVal != "0") && !(parseInt(cookieVal) > MAX_SCHEME_ID)) {
    
 
        
 
        setColorScheme(parseInt(cookieVal));
    
    }   
   
}




function isHomepage () {

    //return true;
    return ((window.location.pathname == "/home.aspx") || (window.location.pathname == "/"));
}

function setColorScheme(schemeID) {

    setCookie("color_scheme", "" + schemeID, COOKIE_DURATION);

    if((schemeID == 0) || (schemeID > MAX_SCHEME_ID)) {
    
          
        window.location.reload();    
        

        
        return;
    }
    


    var textColor = textColors[schemeID];
    var bgColor = bgColors[schemeID];
    var linkColor = linkColors[schemeID];


    changeElementStyle("request_row", "borderTop", "10px solid " + textColor);
    changeElementStyle("request_row", "borderBottom", "5px solid " + textColor);

    changeElementStyle("register_row", "borderBottom", "3px solid " + textColor);

    //changeClassStyle("div", "liquid-round", "borderTop", "1px solid " + textColor);
    //changeClassStyle("div", "liquid-round", "borderBottom", "1px solid " + textColor);
    changeElementStyle("footer", "borderTop", "1px solid " + textColor);
    //changeElementStyle("siteMapXML", "border", "1px solid " + textColor);

    //changeElementStyle("furtherInfo", "border", "1px solid " + textColor);

    //changeClassStyle("div", "body", "border", "1px solid " + textColor);

    changeTagStyle("input", "border", "1px solid " + textColor);

    changeTagStyle("textarea", "border", "1px solid " + textColor);


    changeTextColor(textColor);

    
    changeTagStyle("a", "color", linkColor);
    changeTagStyle("a", "textDecoration", "underline");

    changeBackgroundColor(bgColor);



}




function getElemsByClass(tagName, className) {

    var results = new Array(); 

    var elements = document.getElementsByTagName(tagName);

    for (var i = 0; i < elements.length; i++) {


        if(elements[i].className == className) {
            results.push(elements[i]);
        }

    }

    return results;


}


function changeClassStyle(tagName, className, styleProperty, styleValue) {

    var elements = getElemsByClass(tagName, className);

    for (var i = 0; i < elements.length; i++) {


        if(elements[i]) {
            elements[i].style[styleProperty] = styleValue;
        }

    }
} 

function changeTagStyle(tagName, styleProperty, styleValue) {

    var elements = document.getElementsByTagName(tagName);

    for (var i = 0; i < elements.length; i++) {


        if(elements[i]) {
            elements[i].style[styleProperty] = styleValue;
        }

    }
}

function changeElementStyle(elementId, styleProperty, styleValue) {

    var elem = document.getElementById(elementId);
    if (elem) {
    
        elem.style[styleProperty] = styleValue;
    
    }

}


function changeTextColor(color) {

    changeTagStyle("div", "color", color);
    changeTagStyle("p", "color", color);
    changeTagStyle("span", "color", color);
    changeTagStyle("li", "color", color);
    changeTagStyle("h1", "color", color);
    changeTagStyle("h2", "color", color);
    changeTagStyle("h3", "color", color);
    changeTagStyle("h4", "color", color);
    changeTagStyle("h5", "color", color);
    changeTagStyle("h6", "color", color);
    
    changeTagStyle("input", "color", color);
    changeTagStyle("label", "color", color);


    changeTagStyle("select", "color", color);
    changeTagStyle("legend", "color", color);
    changeTagStyle("textarea", "color", color);
    changeTagStyle("fieldset", "color", color);

    //changeTagStyle("table", "color", color);
    //changeTagStyle("tbody", "color", color);
    //changeTagStyle("table", "color", color);
    changeTagStyle("th", "color", color);
    changeTagStyle("td", "color", color);
}


function changeBackgroundColor(color) {

    changeTagStyle("body", "backgroundColor", color);

    changeTagStyle("div", "backgroundColor", color);
    changeTagStyle("div", "backgroundImage", "none");
 
    changeTagStyle("p", "backgroundImage", "none");    
    
    changeTagStyle("h2", "backgroundImage", "none");
    changeTagStyle("h3", "backgroundColor", color);
    changeElementStyle("header", "backgroundImage", "none");
    changeElementStyle("mainContent", "borderBottomColor", color);
    changeElementStyle("mainContent", "borderTopColor", color);
    
    changeElementStyle("footer", "backgroundImage", "none");
    
    changeTagStyle("span", "backgroundImage", "none");
    
    changeTagStyle("input", "backgroundColor", color);
    
    changeTagStyle("select", "backgroundColor", color);
    changeTagStyle("legend", "backgroundColor", color);
    changeTagStyle("textarea", "backgroundColor", color);
    changeTagStyle("fieldset", "backgroundColor", color);  

    changeTagStyle("th", "backgroundColor", color);
    changeTagStyle("td", "backgroundColor", color);  
    
    changeTagStyle("a", "backgroundImage", "none");
            
    var AElements = document.getElementsByTagName("a");

    for (var i = 0; i < AElements.length; i++) {


        if(AElements[i]) {
            AElements[i].onmouseover = function() {
                this.style.backgroundColor = "transparent";
            }
        }

    }    

    //homepage specific stuff
    changeTagStyle("ul", "backgroundImage", "none");
    changeTagStyle("a", "border", "none");
 
}