﻿function LoadSkinFromCookie()
{   
    var preSetCookie;
    preSetCookie = getCookie("SelectedCssSkin");   
	if (preSetCookie != null) {
	    SetSkin(preSetCookie)
	    var dropDownList = document.getElementById("ctl00_DropDownListSkinSelection"); 
        if (dropDownList == null) {
        dropDownList = document.getElementById("ctl00_ctl00_DropDownListSkinSelection"); 
        }    
        var newIndex;	
	    for (i = 0; i < dropDownList.length - 1; ++i)
            if (dropDownList.options[i].value == preSetCookie) {
            dropDownList.selectedIndex = i;	    
            }
	}
	CheckLayoutWidthResolution()
}

function CheckLayoutWidthResolution()
{
    var cssFileUrlLayout = document.getElementById("ctl00_CssFileUrlLayout");	
	if (cssFileUrlLayout == null) {
	    	     cssFileUrlLayout = document.getElementById("ctl00_ctl00_CssFileUrlLayout");
	}	
    if (screen.width<640)
    {
    cssFileUrlLayout.href = "/Web/CSS/Blank.css";
    }    
	return true;
}

   
function SwitchSkin()
{
    var dropDownList = document.getElementById("ctl00_DropDownListSkinSelection"); 
    if (dropDownList == null) {    
        dropDownList = document.getElementById("ctl00_ctl00_DropDownListSkinSelection"); 
    }    
    var selectedIndex;
	var selectedValue;	
	selectedIndex = dropDownList.selectedIndex;
	selectedValue = dropDownList.options[selectedIndex].value;	
	SetSkin(selectedValue)
}

function SetSkin(newValue)
{
	var HtmlBody = document.getElementById("HtmlBody");
	if (HtmlBody.className != newValue) {	
	    HtmlBody.className = newValue;
	    }
	setCookie("SelectedCssSkin",newValue,365);
		
	var cssFileUrlGlobal = document.getElementById("ctl00_CssFileUrlGlobal");
	var cssFileUrlLayout = document.getElementById("ctl00_CssFileUrlLayout");
	if (cssFileUrlGlobal == null) {
	    	     cssFileUrlGlobal = document.getElementById("ctl00_ctl00_CssFileUrlGlobal");
	}
	if (cssFileUrlLayout == null) {
	    	     cssFileUrlLayout = document.getElementById("ctl00_ctl00_CssFileUrlLayout");
	}	
	if ((newValue == "Accessibility") || (newValue == "HighContrastWB") || (newValue == "HandheldDemo") || (newValue == "Alpha") || (newValue == "HighContrastBW")) {	    
	    cssFileUrlGlobal.href = "/Web/CSS/" + newValue + ".css"
	    cssFileUrlLayout.href = "/Web/CSS/Blank.css"
	    }
	else {
	    var cssFileUrlGlobalHiddenField = document.getElementById("ctl00_CssFileUrlGlobalHiddenField").value;	    
	    if (cssFileUrlGlobalHiddenField == null) {
	    	     cssFileUrlGlobalHiddenField = document.getElementById("ctl00_ctl00_CssFileUrlGlobalHiddenField").value;
	    }	    
	    if (cssFileUrlGlobal.href != cssFileUrlGlobalHiddenField) {
	        cssFileUrlGlobal.href = cssFileUrlGlobalHiddenField;
	        }	    
	    var cssFileUrlLayoutHiddenField = document.getElementById("ctl00_CssFileUrlLayoutHiddenField").value;
	    if (cssFileUrlLayoutHiddenField == null) {
	    	     cssFileUrlLayoutHiddenField = document.getElementById("ctl00_ctl00_CssFileUrlLayoutHiddenField").value;
	    }
	    if (cssFileUrlLayout.href != cssFileUrlLayoutHiddenField) {   
	        cssFileUrlLayout.href = cssFileUrlLayoutHiddenField;	    
	        }
	}		    	
	return true;
}

function setCookie(name,value,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=/";
}
function getCookie(name){
	name += "=";
	var s = document.cookie.split("; ");
	for(var i=0; i<s.length; i++){
		var c = s[i];
		if(c.indexOf(name) == 0){
			return unescape(c.substring(name.length,c.length));
		}
	}
	return null;
}