/* Funciones de uso general y de interés para VT */
function modifyLinks(){
	var links=document.getElementsByTagName("a")
	l=window.location.toString().replace("http://","").split("/")
	l=l[0]
	for(i=0;i<links.length;i++){
		var a=links[i];
		var href=a.getAttribute("href");
		if(href!="" && href!=window.l && (href.indexOf("http://")==-1 || href.indexOf(l)!=-1) && href.indexOf("mailto:")!=0 && href.indexOf(COKCodigo)==-1 && href.indexOf(".php")==-1){
			if(href.indexOf("?")!=-1){
				href=href.split("?")
				a.setAttribute("href",href[0]+"?"+COKCodigo+"þ"+href[1]);
			}else if(href.indexOf("#")!=-1){
				href=href.split("#")
				a.setAttribute("href",href[0]+"?"+COKCodigo+"þ#"+href[1]);
			}else{
				a.setAttribute("href",href+"?"+COKCodigo+"þ");
			}
		}
	}
}
function show(x){
	document.getElementById(x).style.visibility="visible"
}
function Cargar(evento){
	if(document.addEventListener){
		window.addEventListener("load",evento,false);
	}else if(document.attachEvent){
		window.attachEvent("onload",evento);
	}else{
		return false;
	};
	return true;
}
function EnviarAlto(){
	if(document.images) new Image().src=SalirDir+"programas/enviaralto.php?"+PAGCodigo+","+Idio+","+document.getElementById("cuerpo").clientHeight;
};
function ColocarTope(){
	//Cambiar tope
	obj=document.getElementById("lateral");
	obj.style.top=document.getElementById("contenido").clientHeight+190+'px';
	obj.style.display="block";
};
function CheckWidth(){
	if (800>=screen.width){
		//Añadir la hoja de estilos
		var head = document.getElementsByTagName('head')[0];
		var buffer = document.createElement('link');
		buffer.setAttribute("rel","stylesheet");
		buffer.setAttribute("type","text/css");
		buffer.setAttribute("href",SalirDir+"800.css");
		head.appendChild(buffer);
		Cargar(ColocarTope);
	};
};
function subetufoto(mostrar){
	if (mostrar!==false) mostrar=true;
	iframe=document.getElementById("ISubeTuFoto");
	if (mostrar){
		iframe.src=ISubeTuFoto;
		iframe.style.display='block';
	}else{
		iframe.style.display='none';
	};
};
function RatingMouseOver(SUBCodigo,NroEstrella){
	if (!Iniciado902) return false;
	MostrarEstrellas(SUBCodigo,NroEstrella);
};
function RatingMouseOut(SUBCodigo,NroEstrella){
	if (!Iniciado902) return false;
	MostrarEstrellas(SUBCodigo,RD[SUBCodigo]);
};
function RatingClick(SUBCodigo,SURCant1){
	if (!Iniciado902) return false;
	Ajax("POST",SalirDir+"programas/enviarrating.php",{"SUBCodigo":SUBCodigo,"SURCant1":SURCant1},true,"RatingListo");
	RD[SUBCodigo]=SURCant1;
	MostrarEstrellas(SUBCodigo,SURCant1);
};
function RatingListo(Respuesta){
	// no hace falta hacer nada
	return true;
};
function MostrarEstrellas(SUBCodigo,CantidadEstrellas){
	Estrella="";
	for (i=1;i<6;i++){
		if (i<=CantidadEstrellas){
			Estrella="estrellaamarilla.gif";
		}else{
			Estrella="estrellavacia.gif";
		};
		document.getElementById("S"+SUBCodigo+i).src=SalirDir+"images/"+Estrella;
	};
};
function login(COKO){
	window.location="#ALogin";
	Iframe=document.getElementById("ILogin");
	Iframe.style.display="block";
	Iframe.src=N2C+"n2c/versup.php?"+COKO+",login.htm,rating.htm";
};
function Iniciado(){
	window.location.reload();
}; 
/*---------------------------------- FUNCIONES PARA AJAX --------------------------------*/
function Cliente(){
	/* genera un cliente de ajax, dependiendo del navegador */
	Success=false;
	try{
	// Mozilla / Safari / IE7
		xmlhttp=new XMLHttpRequest();
	}catch(e){
	// IE
		var XMLHTTP_IDS=['MSXML2.XMLHTTP.5.0','MSXML2.XMLHTTP.4.0','MSXML2.XMLHTTP.3.0','MSXML2.XMLHTTP','Microsoft.XMLHTTP'];
		var success=false;
		for(i=0;i<XMLHTTP_IDS.length && !success;i++) {
			try{
				xmlhttp=new ActiveXObject(XMLHTTP_IDS[i]);
				success=true;
			}catch(e){};
		};
		if(!success) return false;
	};
	return xmlhttp;
};
function Ajax(Method,Programa,ParametrosObj,Asincrono,FuncionRetorno,Mensaje){
	var ParametrosUrl="";
	for (Llave in ParametrosObj){
		ParametrosUrl+="&"+Llave+"="+escape(ParametrosObj[Llave]);
	};
	xmlhttp=Cliente();
	if (!xmlhttp){
		return false;
	};
	xmlhttp.open(Method,Programa,Asincrono);
	xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded;charset=UTF-8;');
	xmlhttp.setRequestHeader('Content-length',ParametrosUrl.length);
	xmlhttp.setRequestHeader('Connection','close');
	//En caso de querer un div de advertencia
	if (Asincrono){
		xmlhttp.onreadystatechange=function(){
			if (4==xmlhttp.readyState){
				return Listo(xmlhttp.responseText,FuncionRetorno);
			};
		};
		xmlhttp.send(ParametrosUrl);
		return true;
	}else{
		xmlhttp.send(ParametrosUrl);
		if(4==xmlhttp.readyState){
			return Listo(xmlhttp.responseText,function(){});
		}else{
			return false;
		};
	};
};
function Listo(TextoServidor,FuncionRetorno){
	var Respuesta=new Array();
	try{
		eval("Respuesta="+TextoServidor);
		Respuesta=DecodificarArreglo(Respuesta);
	}catch (e){
		Respuesta=TextoServidor;
	};
	eval(FuncionRetorno+"(Respuesta)");
	return Respuesta;
};
function decode(str){
	var d = document;
	if (!window.__formater){
		window.__formater = d.all ? d.createElement('<textarea>') : d.createElement('textarea');
	};
	__formater.innerHTML = str;
	return __formater.value;
};
