// function to retrieve the cookie.
function getCookie(stystate){
var cstystate = stystate + "=";               
var dc = document.cookie;             
    if (dc.length > 0) {              
    begin = dc.indexOf(cstystate);       
        if (begin != -1) {           
        begin += cstystate.length;       
        end = dc.indexOf(";", begin);
            if (end == -1) end = dc.length;
            return unescape(dc.substring(begin, end));
        } 
    }
return null;
}

// function to save the cookie.
function setCookie(stystate, value, expires) {
document.cookie = stystate + "=" + escape(value) + "; path=/" +
((expires == null) ? "" : "; expires=" + expires.toGMTString());
}

// function to delete the cookie.
function delCookie(stystate) {
document.cookie = stystate + "=; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
}


// Function to check the style at first
function stylestate() {
    if (getCookie(cookieName) == null ||      
        getCookie(cookieName) == "style1") { 
    setCookie(cookieName, "style1", exp);
    applyStyle1()
    }
    if (getCookie(cookieName) == "style4") { 
    applyStyle4();
    }
    if (getCookie(cookieName) == "style3") { 
    applyStyle3();
    }
    if (getCookie(cookieName) == "style2") { 
    applyStyle2();
    }
    else return;
}

// Function to change the style
function changestyle(){
    if (getCookie(cookieName) == "style4") { 
    resetCookie();
    return;
    }
    if (getCookie(cookieName) == "style3") { 
    applyStyle4();
    setCookie(cookieName, "style4", exp);    
    return;
    }
    if (getCookie(cookieName) == "style2") { 
    applyStyle3();
    setCookie(cookieName, "style3", exp);    
    return;
    }
    if (getCookie(cookieName) == "style1") { 
    applyStyle2();
    setCookie(cookieName, "style2", exp);
    return;
    }
    else return;
  }


function resetCookie(){
    applyStyle1();
    setCookie(cookieName, "style1", exp);
    return;
    }

// These are the styles


function applyStyle2(){
  document.styleSheets(0).addRule("P", "{color: #660000; font-size: 120%; font-family: Arial, Helvetica, sans-serif}")
  document.styleSheets(0).addRule("BODY", "{background-color: cornsilk}")
  document.styleSheets(0).addRule("A", "{color: #800000}")
  document.styleSheets(0).addRule("TD.title", "{color: black}")
  }

function applyStyle3(){
  document.styleSheets(0).addRule("P", "{color: black; font-size: 100%; font-family: Georgia, Times New Roman, Times New, serif}")
  document.styleSheets(0).addRule("BODY", "{background-color: #CCCCCC}")
  document.styleSheets(0).addRule("A", "{color: #800000}")
  document.styleSheets(0).addRule("TD.title", "{color: black}")
  }

function applyStyle4(){
  document.styleSheets(0).addRule("P", "{color: white; font-size: 105%; font-family: Arial, Helvetica, sans-serif}")
  document.styleSheets(0).addRule("BODY", "{background-color: #000066}")
  document.styleSheets(0).addRule("A", "{color: blue}")
  document.styleSheets(0).addRule("TD.title", "{color: white}")
  }

function applyStyle1(){
  document.styleSheets(0).addRule("P", "{color: black; font-size: 100%; font-family: Arial, Helvetica, sans-serif}")
  document.styleSheets(0).addRule("BODY", "{background-color: white}")
  document.styleSheets(0).addRule("A", "{color: #800000}")
  document.styleSheets(0).addRule("TD.title", "{color: black}")
  }


var exp = new Date();
exp.setTime(exp.getTime() +  (24 * 60 * 60 * 1000 * 365)); 
var cookieName = '_stystate'; 

//This is the end
