// JavaScript Document

function abrir2(){
	document.getElementById("apDiv1").style.visibility="visible";
}
function cerrar(){
	document.getElementById("apDiv1").style.visibility="hidden";
}

function alerta(texto_msg,tipo){
	
	if(tipo=="r"){
		msg="El campo \""+texto_msg+"\" es obligatorio";
	}
	
	if(tipo=="L"){
		msg=texto_msg;	
	}
	
	alert(msg);
}

function longitud(cadena){
	return cadena.length;
}

function validaFormRegistro(){
	
	nombre=trim(document.getElementById("name").value);
	conociste=trim(document.getElementById("como_conociste").value);
	email=trim(document.getElementById("email").value);
	fono=trim(document.getElementById("fono").value);
	sexoM=document.getElementById("sexo1");
	sexoF=document.getElementById("sexo2");
	
	pass=trim(document.getElementById("pass").value);
	pass2=trim(document.getElementById("pass2").value);
	
	if(nombre==""){
		alerta("Nombre y Apellido","r");
		document.getElementById("name").focus();
		return false;
		r=false;
	}else{
		if(longitud(nombre)>=4){
			r=true;		
		}else{
			alerta("Longitud del campo \"Nombre y Apellido\" es peque\xF1o","L");
			document.getElementById("name").focus();
			return false;
			r=false;
		}
	}
	
	if(conociste==""){
		alerta("C\xF3mo nos conociste","r");
		document.getElementById("como_conociste").focus();
		return false;
		r=false;
	}else{
		if(longitud(conociste)>=4){
			r=true;		
		}else{
			alerta("Longitud del campo \"C\xF3mo nos conociste\" es peque\xF1o","L");
			document.getElementById("como_conociste").focus();
			return false;
			r=false;
		}
	}
	
	if(email==""){
		alerta("Email","r");
		document.getElementById("email").focus();
		return false;
		r=false;
	}else{
		if(emailCheck(email)==0){
			alerta("Ingrese un email v\xE1lido","L");
			document.getElementById("email").focus();
			return false;
			r=false;	
		}else{
			r=true;		
		}
	}
	
	if(fono==""){
		alerta("Tel\xE9fono","r");
		document.getElementById("fono").focus();
		return false;
		r=false;
	}else{
		if(longitud(fono)>=7){
			r=true;		
		}else{
			alerta("El n\xFAmero de tel\xE9fono es incorrecto","L");
			document.getElementById("fono").focus();
			return false;
			r=false;
		}
	}
	
	if(sexoM.checked==false && sexoF.checked==false){
		alerta("Sexo","r");
		document.getElementById("sexo1").focus();
		return false;
		r=false;
	}else{
		r=true;	
	}
	
	if(pass==""){
		alerta("Contrase\xF1a","r");
		document.getElementById("pass").focus();
		return false;
		r=false;
	}else{
		r=true;		
	}
	
	if(pass2==""){
		alerta("Repita su contrase\xF1a, por favor","L");
		document.getElementById("pass2").focus();
		return false;
		r=false;
	}else{
		r=true;		
	}
//	frm=document.forms["form1"];
//	var	r=validaForm(frm);
		
	if(r!=false){
		if(document.getElementById("pass").value==document.getElementById("pass2").value){
			if(document.getElementById("optAceptar").checked==true){
				url="&action=checkMailClient&email="+document.getElementById("email").value;			
				myConn.connect("process_login.php","GET",url,submitFormRegistered);
			}else{
				alert("Debe aceptar los terminos y condiciones para registrarse");
				return false;
			}	
		}else{
			alert("Las contrase\xF1as deben ser iguales");
			return false;
		}
	}else{
		return false;	
	}
}

var submitFormRegistered=function (oXML){	
	var rpta = oXML.responseText;
	if(rpta=="ok"){ // todo ok, no existe el email
		frm=document.forms["form1"];
		frm.submit();
	}else{		
		alert("Este email ya esta registrado");
	}
};

function loadBanner_lateral(tot,timeSg)
{
	
    try {
        clearTimeout(too);
    } catch (e) {}
	next_banner_lateral();
	if(tot>1)
    	too = setTimeout("loadBanner_lateral("+tot+","+timeSg+")",timeSg);
		
}

function next_banner_lateral(){
	var url='#';
	myConn.connect("ajax_banner_lateral.php","GET",url,end_banner_lateral);
}

var end_banner_lateral=function (oXML){	
	var rpta = oXML.responseText;
	//alert("test");
	document.getElementById("showbanner_lateral").innerHTML	= rpta;
};


function loadBanner_float(tot,timeSg)
{
	
    try {
        clearTimeout(too);
    } catch (e) {}
	next_banner_float();
	if(tot>1)
    	too = setTimeout("loadBanner_float("+tot+","+timeSg+")",timeSg);
		
}

function next_banner_float(){
	var url='#';
	myConn.connect("ajax_banner_float.php","GET",url,end_banner_float);
}

var end_banner_float=function (oXML){	
	var rpta = oXML.responseText;
	//alert("test");
	document.getElementById("showbanner_float").innerHTML	= rpta;
};