// Funciones principales en JS

function focusin(id){
	if(id.value=="[Campo necesario]"){
		id.value="";
		id.className="";
	}
	else{
		if(id.type=="text"){
			id.select();
		}
	}
}
function focusoff(id){
	if(id.value!="" && id.value!="[Campo necesario]"){
		id.className="changed";
	}
	else{
		id.value="[Campo necesario]";
		id.className="";
	}
}

function activa(id){
	document.getElementById(id).className="activo";
}

function mostrar_enlaces(info){
	if(document.getElementById(info).style.display == "none"){
		ocultar_enlaces();
		document.getElementById(info).style.display = "block";
		document.getElementById(info).style.visibility = "visible";
	}
	else{
		ocultar_enlaces();
	}
}

function abrir1(info){
	if(document.getElementById(info).style.display == "none"){
		document.getElementById("Instalaciones").style.display = "none";
		document.getElementById(info).style.display = "block";
		document.getElementById(info).style.visibility = "visible";
	}
	else{
		document.getElementById(info).style.display = "none";
	}
}

function over(obj){
	document.getElementById(obj).style.borderColor="#003B87";
}

function out(obj){
	document.getElementById(obj).style.borderColor="#CCC";
}

function precarga() { 
	if (!document.images) return; 
	var ar = new Array(); 
	var arguments = precarga.arguments;
	for (var i = 0; i < arguments.length; i++) { 
		ar[i] = new Image(); 
		ar[i].src = arguments[i]; 
	} 
}

function limpia(id){
	if(id.value=="Búsqueda"){
		id.value="";
	}
}

function recupera(id){
	if(id.value==""){
		id.value="Búsqueda";
	}
}

function cambiaimg(foto,ancho,alto){
	if(ancho>400){
		alto=400/(ancho/alto);
		ancho=400;
	}
	document.getElementById("fotogrande").src=foto;
	document.getElementById("fotogrande").height=alto;
	document.getElementById("fotogrande").width=ancho;
	$("#divfotogrande").animate({ 
		width:(parseFloat(ancho)+10)+"px",
	}, 200 );
	$("#divfotogrande").animate({ 
		height:(parseFloat(alto)+41)+"px",
	}, 200 );
}

function esmovil(){
	if(parseFloat(screen.width) < 640){
		resultado=1;
	}
	else{
		resultado=0;
	}
	return resultado;
}

function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name + "=" + escape(value) + ((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}

function getCookie(c_name){
	if (document.cookie.length>0){
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1){
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

function guardapos_inicio(){
	posicion="123";
	alto1=document.getElementById("inicio1").offsetTop;
	alto2=document.getElementById("inicio2").offsetTop;
	alto3=document.getElementById("inicio3").offsetTop;
	if(alto1<alto2 && alto1<alto3){
		if(alto2<alto3){ posicion="123"; }
		else{ posicion="132"; }
	}
	if(alto2<alto1 && alto2<alto3){
		if(alto1<alto3){ posicion="213"; }
		else{ posicion="231"; }
	}
	if(alto3<alto1 && alto3<alto2){
		if(alto1<alto2){ posicion="312"; }
		else{ posicion="321"; }
	}
	setCookie("copaz_inicio",posicion,1000);
}

function guardapos_lateral(){
	posicion="";
	alto1=document.getElementById("lateral1").offsetTop;
	alto2=document.getElementById("lateral2").offsetTop;
	posicion="21";
	if(alto1<alto2){
		posicion="12";
	}
	setCookie("copaz_lateral",posicion,1000);
}

function guarda_barra(estado){
	setCookie("copaz_barra",estado,1000);
}

function textsize(val){
	setCookie("copaz_texto",val,1000);
	document.location.reload();
}

function setcolor(val){
	setCookie("copaz_color",val,1000);
	document.location=document.location;
}
