/*Mike Golding*/
function makeCookie(Name,Value,Expiry,Path,Domain,Secure){
	if (Expiry != null) {
		var datenow = new Date();
		datenow.setTime(datenow.getTime() + Math.round(86400000*Expiry));
		Expiry = datenow.toGMTString();
	}

	Expiry = (Expiry != null) ? '; expires='+Expiry : '';
	Path = (Path != null)?'; path='+Path:'';
	Domain = (Domain != null) ? '; domain='+Domain : '';
	Secure = (Secure != null) ? '; secure' : '';
	
	document.cookie = Name + '=' + escape(Value) + Expiry + Path + Domain + Secure;
}

function readCookie(Name) {
	var cookies = document.cookie;
	if (cookies.indexOf(Name + '=') == -1) return null;
	var start = cookies.indexOf(Name + '=') + (Name.length + 1);
	var finish = cookies.substring(start,cookies.length);
	finish = (finish.indexOf(';') == -1) ? cookies.length : start + finish.indexOf(';');
	return unescape(cookies.substring(start,finish));
}

function setActiveStyleSheet(pTitle) {
	var vLink, i;
	if((parent.TOP && parent.BOT) && parent.TOP.document.getElementsByTagName("link")[2] && parent.BOT.document.getElementsByTagName("link")[2]){
		var loaded=true;														//MODIFIED
		var parente = parent.document.getElementsByTagName("link");				//MODIFIED
		var parentT = parent.TOP.document.getElementsByTagName("link");			//MODIFIED
		var parentB = parent.BOT.document.getElementsByTagName("link");			//MODIFIED
	}
	
	for(i=0; (vLink = document.getElementsByTagName("link")[i] ); i++) {
		if(vLink.getAttribute("rel").indexOf("style") != -1 && vLink.getAttribute("title")) {
			vLink.disabled = true;
			if(loaded)parente[i].disabled = true;
			if(loaded)parentT[i].disabled = true;				//MODIFIED
			if(loaded)parentB[i].disabled = true;				//MODIFIED
			
			if(vLink.getAttribute("title") == pTitle){
				vLink.disabled = false;
				if(loaded)parente[i].disabled = false;	
				if(loaded)parentB[i].disabled = false;			//MODIFIED
				if(loaded)parentT[i].disabled = false;			//MODIFIED
			}
		}
	}
	
//	if(pTitle == 'ruraq-yana'){//alert(parent.document.getElementById('CP').style.backgroundColor);
//		parent.document.getElementById('CP').style.backgroundColor='#000000';
//		parent.document.getElementById('TOP').style.backgroundColor='#000000';
//		parent.document.getElementById('BOT').style.backgroundColor='#000000';

//		parent.TOP.document.body.style.backgroundColor='#000000';
//		parent.BOT.document.body.style.backgroundColor='#000000';
		//document.styleSheets[0].addRule("body", "background-color:#000000")
		//parent.TOP.document.styleSheets[0].addRule("body", "background-color:#000000")
		//parent.BOT.document.styleSheets[0].addRule("body", "background-color:#000000")
//	}
//	else if (pTitle == 'ruraq-uqi'){
		
//		parent.document.getElementById('CP').style.backgroundColor='#404040';
//		parent.document.getElementById('TOP').style.backgroundColor='#404040';
//		parent.document.getElementById('BOT').style.backgroundColor='#404040';

//		parent.TOP.document.body.style.backgroundColor='#404040';
//		parent.BOT.document.body.style.backgroundColor='#404040';
		
		//document.styleSheets[1].addRule("body", "background-color:#404040")
		/*document.styleSheets[1].addRule("body", "color:#FFFD00")*/;
//	}
//	else if (pTitle == 'ruraq-yuraq') {
//		parent.document.getElementById('CP').style.backgroundColor='#FFFFFF';
//		parent.document.getElementById('TOP').style.backgroundColor='#FFFFFF';
//		parent.document.getElementById('BOT').style.backgroundColor='#FFFFFF';
		
//		parent.TOP.document.body.style.backgroundColor='#EEEEEE';
//		parent.BOT.document.body.style.backgroundColor='#EEEEEE';
		
		//document.styleSheets[2].addRule("body", "background-color:#FFFFFF")
		//parent.TOP.document.styleSheets[0].addRule("body", "background-color:#000000")
		//parent.BOT.document.styleSheets[0].addRule("body", "background-color:#000000")	}
//	}
	
	parentT = null;
	parentB = null;
	//css = null;
}

function selectStyle (vCookieName, vSelection) {
	//WRITE COOKIE
	if(vSelection=='ruraq-yuraq')makeCookie(vCookieName, vSelection, 0, '/');			//MODIFIED borra cookie si blanco IE es lento
	else makeCookie(vCookieName, vSelection, 90, '/');
	css = readCookie(vCookieName);
	//ACTIVE SELECTED ALTERNAT STYLE SHEET
	setActiveStyleSheet(vSelection)
}
//////////////////////////////////////////////////////////
	var css = readCookie('ruraq');
	
	if(!window.ss0){
		if (document.cookie.indexOf('ruraq=')!=-1) {
			//ACTIVATE SELECTED STYLE SHEET
			setActiveStyleSheet(css)
		}
	}
	
function opera(){
	if(navigator.userAgent.indexOf("Opera")==-1)return;
	if(parent.document.getElementById('CP')){
		var s = new Array();
		s[0] = 'ruraq-yana';s[1] = 'ruraq-uqi';s[2] = 'ruraq-yuraq';
		var yana	='#000000';
		var uqi		='#252525';
		var yuraq	='#FFFFFF';
		for(var x=0; x<3; x++){
			if(css==s[x]){
				if(x==0)var color= yana;else if(x==1)var color=uqi;else var color=yuraq;
				document.body.style.backgroundColor=color;	//Esto es porq opera no muestra bgcolor de frameset, a travez del color transparent
			}
		}
	}
	if (document.cookie.indexOf('ruraq=')!=-1) {setTimeout("selectStyle('ruraq', css)",200);}
}
	
	
	
	
	
	
	
	
	
	
