

function getCookie(Name) { 
	var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
	
	if (document.cookie.match(re)){ //if cookie found
		return document.cookie.match(re)[0].split("=")[1] ;//return its value
	}else{
		return null;
	}
}

function setCookie(name, value, days) {
	var expireDate = new Date()
	//set "expstring" to either future or past date, to set or delete cookie, respectively
	var expstring=(typeof days!="undefined")? expireDate.setDate(expireDate.getDate()+parseInt(days)) : expireDate.setDate(expireDate.getDate()-5)
	document.cookie = name+"="+value+"; expires="+expireDate.toGMTString()+"; path=/";
}

function deleteCookie(name){
	setCookie(name, "moot")
}

function setStylesheet(title) {
	var i, cacheobj;
	cacheobj=document.getElementsByTagName("link");
	
	for(i=0; i<cacheobj.length; i++) {
		if(cacheobj[i].getAttribute("rel").indexOf("style") != -1 && cacheobj[i].getAttribute("title")!="black") {
			cacheobj[i].disabled = true
		if(cacheobj[i].getAttribute("title") == title)
			cacheobj[i].disabled = false //enable chosen style sheet
		}
	}
}

function chooseStyle(styletitle, days){
	//if (document.getElementById){
		setStylesheet(styletitle);
		setCookie("mysheet", styletitle, days);
	//}
}

function indicateSelected(element){ //Optional function that shows which style sheet is currently selected within group of radio buttons or select menu 
	var i
	if (selectedtitle!=null && (element.type==undefined || element.type=="select-one")){ //if element is a radio button or select menu
		var element=(element.type=="select-one") ? element.options : element
		for (i=0; i<element.length; i++){
			if (element.value==selectedtitle){ //if match found between form element value and cookie value
				if (element.tagName=="OPTION") //if this is a select menu
					element.selected=true
				else //else if it's a radio button
					element.checked=true
				break
			}
		}
	}
}

var selectedtitle=getCookie("mysheet");

if (document.getElementById && selectedtitle!=null) //load user chosen style sheet if there is one stored
	setStylesheet(selectedtitle);




document.writeln("<!--[if lte IE 6]>");
document.writeln("<style type=\"text/css\">");
document.writeln(" a { behavior:url(\"/focus.htc\"); }");
document.writeln("</style>");
document.writeln("<![endif]-->");

