// JavaScript Document

//funcciones  para popups 


//para mostrar

var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;
if (checkIt('konqueror')){
	browser = "Konqueror";
	OS = "Linux";}
else if (checkIt('safari')) browser = "Safari"
else if (checkIt('omniweb')) browser = "OmniWeb"
else if (checkIt('opera')) browser = "Opera"
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab"
else if (checkIt('msie 6.0')) browser = "Internet Explorer 6"
else if (checkIt('msie')) browser = "Internet Explorer"
else if (checkIt('firefox/2.0.0')) { browser = "Firefox 2"}
/*else if (!checkIt('compatible')){
	browser = "Netscape Navigator"
	version = detect.charAt(8);}*/
else browser = "An unknown browser";
if (!version) version = detect.charAt(place + thestring.length);
if (!OS){
	if (checkIt('linux')) OS = "Linux";
	else if (checkIt('x11')) OS = "Unix";
	else if (checkIt('mac')) OS = "Mac"
	else if (checkIt('win')) OS = "Windows"
	else OS = "an unknown operating system";
}
function checkIt(string){
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

function showMap(ident){
	var mapdiv=document.getElementById(ident);
	
	
	mapdiv.style.display="block";

	//alert(browser+' '+OS);
	var nav=navigator.appName;
	
		
	
//
	if(nav=="Netscape" || nav=="opera"){
		
		setOpacity(0.1,ident);
		setTimeout('setOpacity(0.1,"'+ident+'")',50);
		setTimeout('setOpacity(0.2,"'+ident+'")',100);
		setTimeout('setOpacity(0.3,"'+ident+'")',150);
		setTimeout('setOpacity(0.4,"'+ident+'")',200);
		setTimeout('setOpacity(0.5,"'+ident+'")',250);
		setTimeout('setOpacity(0.6,"'+ident+'")',300);
		if(browser == "Firefox 2"){
			if (OS == "Mac"){
				document.getElementById('contacto').style.position = 'inherit';
				document.getElementById('contacto').style.margin = 'inherit';
				document.getElementById('contacto').style.width = 'inherit';
				document.getElementById('contacto').style.background = 'transparent';
				document.getElementById('contacto').style.display = 'block';
				document.getElementById('contacto').style.padding = 0;
				document.getElementById('cajaContacto').style.border = "10px solid #999";				
				}
			}
	}else{
		IEsetOpacity(0,ident);
		var alto=document.body.offsetHeight;
		mapdiv.style.height=alto+"px";
		var ancho=document.body.offsetWidth;
		mapdiv.style.width=ancho+"px";
		setTimeout('IEsetOpacity(10,"'+ident+'")',150);
		setTimeout('IEsetOpacity(20,"'+ident+'")',300);
		setTimeout('IEsetOpacity(30,"'+ident+'")',450);
		setTimeout('IEsetOpacity(40,"'+ident+'")',600);
		setTimeout('IEsetOpacity(50,"'+ident+'")',750);
		setTimeout('IEsetOpacity(60,"'+ident+'")',900);
	}
	showCon();
}

function showCon(){
	var mapdiv=document.getElementById("cajaContacto");
	var ident = "cajaContacto";
	
	mapdiv.style.display="block";


	var nav=navigator.appName;
//
	if(nav=="Netscape" || nav=="opera"){

		setOpacity(0.1,ident);

		setTimeout('setOpacity(0.1,"'+ident+'")',50);
		setTimeout('setOpacity(0.2,"'+ident+'")',100);
		setTimeout('setOpacity(0.4,"'+ident+'")',150);
		setTimeout('setOpacity(0.6,"'+ident+'")',200);
		setTimeout('setOpacity(0.9,"'+ident+'")',250);
		setTimeout('setOpacity(1,"'+ident+'")',300);
	}else{
		IEsetOpacity(0,ident);
		setTimeout('IEsetOpacity(10,"'+ident+'")',150);
		setTimeout('IEsetOpacity(30,"'+ident+'")',300);
		setTimeout('IEsetOpacity(50,"'+ident+'")',450);
		setTimeout('IEsetOpacity(70,"'+ident+'")',600);
		setTimeout('IEsetOpacity(90,"'+ident+'")',750);
		setTimeout('IEsetOpacity(100,"'+ident+'")',900);
	}
}

//para ocultar
function hideMap(ident){
	
	var mapdiv=document.getElementById(ident);

	var nav=navigator.appName;
//	
	if(nav=="Netscape" || nav=="opera"){
	
		setTimeout('setOpacity(0.5,"'+ident+'")',100);
		setTimeout('setOpacity(0.4,"'+ident+'")',150);
		setTimeout('setOpacity(0.3,"'+ident+'")',200);
		setTimeout('setOpacity(0.2,"'+ident+'")',250);
		setTimeout('MapDisplay("'+ident+'")',300);
		setTimeout('restaurarContacto()',320);
	}else{
		setTimeout('IEsetOpacity(50,"'+ident+'")',100);
		setTimeout('IEsetOpacity(40,"'+ident+'")',150);
		setTimeout('IEsetOpacity(30,"'+ident+'")',200);
		setTimeout('IEsetOpacity(20,"'+ident+'")',250);
		setTimeout('MapDisplay("'+ident+'")',300);
		setTimeout('restaurarContacto()',320);
		
	}
}

function hideCon(){
	
	var mapdiv=document.getElementById("cajaContacto");
	var ident = "cajaContacto";

	var nav=navigator.appName;
//	
	if(nav=="Netscape" || nav=="opera"){
	
		setTimeout('setOpacity(0.8,"'+ident+'")',100);
		setTimeout('setOpacity(0.6,"'+ident+'")',150);
		setTimeout('setOpacity(0.4,"'+ident+'")',200);
		setTimeout('setOpacity(0.2,"'+ident+'")',250);
		setTimeout('MapDisplay("'+ident+'")',300);
		setTimeout('restaurarContacto()',320);
	}else{
		setTimeout('IEsetOpacity(90,"'+ident+'")',100);
		setTimeout('IEsetOpacity(70,"'+ident+'")',150);
		setTimeout('IEsetOpacity(50,"'+ident+'")',200);
		setTimeout('IEsetOpacity(30,"'+ident+'")',250);
		setTimeout('MapDisplay("'+ident+'")',300);
		setTimeout('restaurarContacto()',320);
		
	}
}

var opacidad=0;

//para establecer la opacidad
function setOpacity(op , ident){ var mapdiv=document.getElementById(ident);	mapdiv.style.opacity=op; }

function IEsetOpacity(op, ident){ var mapdiv=document.getElementById(ident);	mapdiv.style.filter="alpha(opacity='"+op+"')";}



//para ocultar el div completamente
function MapDisplay(ident){
	var mapdiv=document.getElementById(ident);	
	mapdiv.style.display="none";

}


//---------------------------------------------------------------------------------------------------------------------------------


/* EL AJAX IMPROVISADO */

// JavaScript Document

function llamarContacto(ruta, variables){
	peticion=AjaxRef();
	if (peticion){
		URL=ruta;
		peticion.open("POST", URL, true);
		peticion.onreadystatechange=asignardatosContacto;
		peticion.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		peticion.send(variables);
	}
}


function asignardatosContacto(){
	if(peticion.readyState==3){		
			midiv.innerHTML="cargando";

	}
	if(peticion.readyState==4){		
		var respuesta=peticion.responseText;
		var midiv=document.getElementById("formulario");
		midiv.innerHTML=respuesta;
	}
}

function validarVacio(nombre, tel, email, coment){
	if (nombre == ""){
		alert("Es necesario ingresar un nombre");
		return 2;
	}
	if (email == ""){
		alert("Es necesario ingresar un correo electr\u00F3nico");
		return 2;
	}
	if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)){
		alert("La direcci\u00F3n de email " + email + " no es v\u00E1lida.");
		return 2;
	}
	if (tel == ""){
		alert("Es necesario ingresar un n\u00FAmero telef\u00F3nico");
		return 2;
	}
	if (!/^([0-9])*$/.test(tel)){
	alert("El valor " + tel + " no es un n\u00FAmero telefonico v\u00E1lido");
		return 2;
	}
	if (coment == ""){
		alert("No has ingresado un comentario");
		return 2;
	}
		return 1;
	
}

/*function validarEmail(valor) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
	return 1;
	} else {
	alert("La direcci\u00F3n de email " + valor + " no es v\u00E1lida.");
	}
}

function validarTel(numero){
	if (!/^([0-9])*$/.test(numero)){
	alert("El valor " + numero + " no es un n\u00FAmero telefonico v\u00E1lido");
	}else{
		return 1;
		}
}*/

function formulario(){
	var nombreIn=document.getElementById('fnombre');
	var telIn=document.getElementById('ftelefono');
	var emailIn=document.getElementById('fmail');
	var comentIn=document.getElementById('fcoment');
	
	nombreIn.value=nombreIn.value.replace(/ /g, "%20")
	nombreIn.value=nombreIn.value.toLowerCase()
	/*nombreIn.value=nombreIn.value.replace(/á/g, "&aacute;")
	nombreIn.value=nombreIn.value.replace(/é/g, "&eacute;")
	nombreIn.value=nombreIn.value.replace(/í/g, "&iacute;")
	nombreIn.value=nombreIn.value.replace(/ó/g, "&oacute;")
	nombreIn.value=nombreIn.value.replace(/ú/g, "&uacute;")*/
	
	
	comentIn.value=comentIn.value.replace(/ /g, "%20")
	comentIn.vlaue=comentIn.value.toLowerCase()
	/*comentIn.value=comentIn.value.replace(/á/g, "&aacute;")
	comentIn.value=comentIn.value.replace(/é/g, "&eacute;")
	comentIn.value=comentIn.value.replace(/í/g, "&iacute;")
	comentIn.value=comentIn.value.replace(/ó/g, "&oacute;")
	comentIn.value=comentIn.value.replace(/ú/g, "&uacute;")*/

	
	
	var nombre= nombreIn.value;
	var tel=telIn.value;
	var email=emailIn.value;
	var coment= comentIn.value;
	
	
	if( validarVacio(nombre, tel, email, coment) == 1){
		var variables="nombre="+nombre+"&tel="+tel+"&email="+email+"&coment="+coment;
		//enviarcorreo(variables)
		llamarContacto("mailer.asp",variables);
		} 
	//var busq= email.indexOf("@");
	//alert(busq);
	/*
	if(){
		var variables="nombre="+nombre+"&tel="+tel+"&email="+email+"&coment="+coment;
		llamarContacto("mailer.php",variables);

	}else{
		alert('no pasa la validacion');
	}*/
	
	
	
	
	//alert(variables);
	
	
}

function enviarcorreo(variables)
{	
	window.location="mailer.asp?"+variables
	/*hideMap('contacto'); 
	hideCon('cajaContacto');*/
}//enviarcorreo

function restaurarContacto(){
	var formulario ="<form action='javascript:formulario();' method='post' name='Formcontacto'>             	<label class='flotarIzq'>nombre </label>                    <input name='Nombre' type='text' id='fnombre'/><br />                   <label class='flotarIzq'>e-mail</label>                    <input name='mail' type='text' id='fmail' /><br />                    <label class='flotarIzq'>telefono</label>                    <input name='telefono' type='text' id='ftelefono'/><br />                    <label class='flotarIzq'>comentarios</label>                    <textarea name='comentario' id='fcoment'></textarea><br />                    <input class='boton' name='Limpiar' type='reset' value='Limpiar' />                    <input class='boton' name='Enviar' type='submit' value='Enviar' />                </form>";
	var divForm=document.getElementById('formulario');
	divForm.innerHTML=formulario;
}
