function getNumberValue1(s,n) {
	s=removeBlanks1(s)
	var pairs=s.split(";")
	for (var i=0;i<pairs.length;++i) {
		var pairSplit=pairs[i].split("=")
		if(pairSplit[0]==n) {
			return pairSplit[1]
		}
	}
	return 0
}

function removeBlanks1(s) {
	var temp=""
	for (var i=0;i<s.length;++i) {
		var c=s.charAt(i)
		if(c!=" ") temp +=c
	}
	return temp
}
   

function createCookie(name,value) {
	cookie=document.cookie
	prefstyle=getActiveStyleSheet();
	//alert("Style Now :"+prefstyle);
	//alert("Current Cookie:"+cookie);
	
	// Get the style that is set now, if not the same then set it
	styleInCookie=getNumberValue1(cookie,'style');
	//alert("Style In Cookie :"+styleInCookie);
	if (styleInCookie != 0) {
		if (prefstyle != styleInCookie) {
			var exp = new Date();
                        exp.setTime (exp.getTime() + 1000 * 60 * 60 * 24 * 365 * 5); 
			//alert(exp.toGMTString());
			document.cookie = "style="+prefstyle+"; path=/; expires=" + exp.toGMTString()
			//document.cookie = "style="+prefstyle+"; path=/"
			//alert("Style reset :"+prefstyle);
			//alert("New New Cookie:"+cookie);

		} else {
			//alert("Same style NOT reset");
		}
	} else if (prefstyle != 0 && prefstyle != 'style1') {
		//alert(styleInCookie);
                var exp = new Date();
                exp.setTime (exp.getTime() + 1000 * 60 * 60 * 24 * 365 * 5);
                //alert(exp.toGMTString());
		document.cookie = "style="+prefstyle+"; path=/; expires=" + exp.toGMTString()
		//document.cookie = "style="+prefstyle+"; path=/"
		//alert("Style NEWLY set :"+prefstyle);	

	} else {
		//alert("Style NOT set");
	}
	//alert(cookie);
}

function readCookie1() {
	cookie=document.cookie
	//alert("Read Cookie:"+cookie);
	prefstyle=getNumberValue1(cookie,'style');
	//alert(cookie);
	if (prefstyle == 0) {
		prefstyle = "style1";
	}
	
	setActiveStyleSheet(prefstyle);
	//alert("Style In Use:"+prefstyle);
}

function setActiveStyleSheet(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 refreshpage() {
document.location = document.location;
}
