// Set a cookie for the standard CSS if we dont have one
// Check the cookie for the type we want
// Unload the other CSS file we dont want


var text = "/dir_ws/2aww/css/textVersion.css"
var standard = "/dir_ws/2aww/css/style.css"
var days = 60

if (getCookie("mysheet")==null){
	var unloadfile, loadfile
	loadfile = standard
	unloadfile = text
	unloadStylesheet(unloadfile)
	setCookie("mysheet", loadfile, days)
}
else{
	if (getCookie("mysheet") == text){
		loadfile = text
		unloadfile = standard
	}
	else{
		loadfile = standard
		unloadfile = text
	}
	unloadStylesheet(unloadfile)
}

function switchStyle(){
	if (document.getElementById){
		var unloadfile, loadfile
		if (getCookie("mysheet") == text){
			loadfile = standard
			unloadfile = text
		}
		else
		{
			loadfile = text
			unloadfile = standard
		}
		setCookie("mysheet", loadfile, days)//set cookie
//		unloadStylesheet(unloadfile) //reload page instead
		window.location.reload()
	}
}

function unloadStylesheet(unload){
	var targetelement= "link"
	var targetattr= "href" 
	var allsuspects=document.getElementsByTagName(targetelement)
	for (var i=allsuspects.length; i>=0; i--)
	{ //search backwards within nodelist for matching elements to remove
		if (allsuspects[i] && allsuspects[i].getAttribute(targetattr)!=null && allsuspects[i].getAttribute(targetattr).indexOf(unload)!=-1)
			allsuspects[i].parentNode.removeChild(allsuspects[i]) //remove element by calling parentNode.removeChild()
	}
}
		

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
	return null
}

function setCookie(name, value) {
	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 styleText(){
	if (getCookie("mysheet") == text){
		document.write("Standard version")
	}
	else{
		document.write("Text only version")
	}
}
