﻿
function SetStyleSheet(title)
 {
   // alert(title);
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}
function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
  
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled)  return a.getAttribute("title");
  }
  return null;
}
function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}
function createCookie(name,value,days)
 {

  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
 
}


function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  var returnValue = "";
  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;
}


window.onload = function(e)
 {
    var cookie1= readCookie("style");
    if(cookie1 == null)
    {
        cookie1 = "Medium_Standard_Default";
    }
  //alert('window load event function');
    if(document.getElementById('ctl00_ContentPlaceHolder1_hdfAccessValue')!=null)
    {
        GetAccesssValue(cookie1);
    }
    var StyleSheet =cookie1.split('_');
   
    SetStyleSheet(StyleSheet[1]);
    GetStylesheetName(cookie1);
  
}

window.onunload = function(e) {
//var style=getActiveStyleSheet();

 var cookie1= readCookie("style");
    if(cookie1 == null)
    {
        cookie1 = "Medium_Standard_Default";
    }
var style1 =cookie1.split('_');
var style = style1[1];
  var title ="";
  if( document.getElementById("ctl00_hdfSize")!=null && document.getElementById("ctl00_hdfSpacing")!=null)
  {
    title =document.getElementById("ctl00_hdfSize").value+"_"+ style+"_"+document.getElementById("ctl00_hdfSpacing").value;
  
  }
  else
  {
    title =document.getElementById("hdfSize").value+"_"+ style+"_"+document.getElementById("hdfSpacing").value;
  
  }

 
  createCookie("style", title, 365);
   var curcookie = readCookie("style");
   
   var StyleSheet =curcookie.split('_');
  
    SetStyleSheet(StyleSheet[1]);
   GetStylesheetName(curcookie);
 // var StyleSheet =title.split('_');

 // SetStyleSheet(StyleSheet[1]);
   
}

function selectStyleSheet(size)
{


    createCookie("style",size,365);
	var cookie1= readCookie("style");
  

	
}
function GetAccesssValue(curcookie)
{
    var radioButtons = document.getElementsByName("ctl00$ContentPlaceHolder1$rdbListTextSize");
    var radioButtoms1 =  document.getElementsByName("ctl00$ContentPlaceHolder1$rdbListcontrastscheme");
    var rdbListWordSpacing =  document.getElementsByName("ctl00$ContentPlaceHolder1$rdbListWordSpacing");
    document.getElementById('ctl00_ContentPlaceHolder1_hdfAccessValue').value=curcookie;
    var Access =document.getElementById('ctl00_ContentPlaceHolder1_hdfAccessValue').value.split('_');
    var FontSize="";;
    var View="";
    var Spacing="";

    if(Access[0]!=null && Access[0]!="")
    { 
        for (var i = 0; i < radioButtons.length; i++)
        {
         if( radioButtons[i].value==Access[0])
         {
            radioButtons[i].checked=true;
         }
        }
    }
    else
    {
        radioButtons.value="Medium";
    }
    if(Access[1]!=null && Access[1]!="")
    { 
        for (var j=0; j < radioButtoms1.length; j++)
        {
             if( radioButtoms1[j].value==Access[1])
             {
               radioButtoms1[j].checked=true;
             }
        }
    }
    else
    {
        radioButtoms1.value="Standard";
    }
    if(Access[2]!=null && Access[2]!="")
    { 
      for (var k=0; k < rdbListWordSpacing.length; k++)
      {      
        if( rdbListWordSpacing[k].value==Access[2])
        {
         rdbListWordSpacing[k].checked=true;
        }
      }
    }
    else
    {
        rdbListWordSpacing.value="Default";
    }
}

function homepagereadcookie()
{
var cookie1= readCookie("style");
if(cookie1 == null)
{
    cookie1 = "Medium_Standard_Default";
}

  createCookie("style", cookie1, 365);
   var curcookie = readCookie("style");
 
   var StyleSheet =curcookie.split('_');
  
    SetStyleSheet(StyleSheet[1]);
   GetStylesheetName(curcookie);
}
var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
var StyleSheet =title.split('_');
SetStyleSheet(StyleSheet[1]);

