/**
 * @author d.alblas
 */

function setActiveStyleSheet(p_strTitle) {

  var l_intCount, l_objTag, l_blnShown, l_strCookieName;
  l_blnShown = false;
  l_strCookieName = 'KWWStyleSize'
  
  for(l_intCount=0; (l_objTag = document.getElementsByTagName("link")[l_intCount]); l_intCount++) {
    if(l_objTag.getAttribute("rel").indexOf("Alternate ") != -1 && l_objTag.getAttribute("title")) {
      l_objTag.disabled = true;
      document.getElementById(l_objTag.getAttribute("title")+'Font').style.color='#B2B2B2';
      if(l_objTag.getAttribute("title") == p_strTitle){
        l_objTag.disabled = false;
        l_blnShown = true;
        document.getElementById(p_strTitle+'Font').style.color='#ff6600';
      }
    }
  }
    
  if (!l_blnShown){
    if (readCookie(l_strCookieName) != null)
        setActiveStyleSheet(readCookie(l_strCookieName))
    else
        setActiveStyleSheet("Default");
  }else{
    eraseCookie(l_strCookieName);
    createCookie(l_strCookieName,p_strTitle,365);
  }
}

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 var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

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;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}