var myFormCheck = new Array();

window.addEvent('domready', function() {
	
	myFormCheck[1] = new FormCheck('frmRegistro',
        {
                submitByAjax: true,
                display:
                {
                        errorsLocation: 1,
                        showErrors: 1,
						scrollToFirst: false
                },
                onAjaxSuccess: function(responseText, responseXML)
                {
                     if(responseText==1)
                     {
                        document.location = "index.php";
                     }
                     else
                     {
                        mostrarError("#FormularioRegistro");
						//alert("Error1");
                     }
                },
                onAjaxFailure: function()
                {
                        mostrarError("#FormularioRegistro");
						//alert("Error2");
                }
        });
	
	myFormCheck[2] = new FormCheck('frmLogin',
        {
                submitByAjax: true,
                display:
                {
                        errorsLocation: 1,
                        showErrors: 1,
						scrollToFirst: false
                },
                onAjaxSuccess: function(responseText, responseXML)
                {
                     if(responseText==1)
                     {
                        document.location = "index.php";
                     }
                     else
                     {
                        mostrarError("#FormularioLogin");
                     }
                },
                onAjaxFailure: function()
                {
                        mostrarError("#FormularioLogin");
                }
        });
	
	
	myFormCheck[3] = new FormCheck('frmRecuperar',
        {
                submitByAjax: true,
                display:
                {
                        errorsLocation: 1,
                        showErrors: 1,
						scrollToFirst: false
                },
                onAjaxSuccess: function(responseText, responseXML)
                {
                     if(responseText==1)
                     {
                        $$("#FormularioRecuperar .AlertasFormulario").set("html", "La contrase&ntilde;a ha sido enviada a tu correo");
						$$("#FormularioRecuperar .AlertasFormulario").setStyle('display', 'block');
                     }
                     else
                     {
						$$("#FormularioRecuperar .AlertasFormulario").set("html", "El email ingresado no existe");
						mostrarError("#FormularioRecuperar");
                     }
                },
                onAjaxFailure: function()
                {
                        mostrarError("#FormularioRecuperar");
                }
        });
	
	
	myFormCheck[4] = new FormCheck('frmContacto',
        {
                submitByAjax: true,
                display:
                {
                        errorsLocation: 1,
                        showErrors: 1,
						scrollToFirst: false
                },
                onAjaxSuccess: function(responseText, responseXML)
                {

                        $$("#FormularioContacto .AlertasFormulario").set("html", "Gracias, tus comentarios han sido enviados.");
						$$("#FormularioContacto .AlertasFormulario").setStyle('display', 'block');

                },
                onAjaxFailure: function()
                {
                        mostrarError("#FormularioContacto");
                }
        });
	
});

function mostrarError(cualDiv)
{
	$$(cualDiv+" .AlertasFormulario").setStyle('display', 'block');
}

function SoloLogin(){
	//cerrarTooltips();
	$('vertical_slide').tween('height', '230');
	$('FormularioRegistro').style.display='none';
	$('FormularioRecuperar').style.display='none';
	$('FormularioContacto').style.display='none';
	$('FormularioSesion').style.display='none';
	setTimeout("$('FormularioLogin').style.display='block';",300);

}

function SoloRegistro(){
	//cerrarTooltips();

	$('vertical_slide').tween('height', '360');
	$('FormularioLogin').style.display='none';
	$('FormularioRecuperar').style.display='none';	
	$('FormularioContacto').style.display='none';
	$('FormularioSesion').style.display='none';
	setTimeout("$('FormularioRegistro').style.display='block';",300);
}

function SoloRecuperar(){
	//cerrarTooltips();
	$('vertical_slide').tween('height', '170');
	$('FormularioLogin').style.display='none';
	$('FormularioRegistro').style.display='none';
	$('FormularioContacto').style.display='none';
	$('FormularioSesion').style.display='none';
	setTimeout("$('FormularioRecuperar').style.display='block';",300);

}

function SoloContacto(){
	//cerrarTooltips();
	$('vertical_slide').tween('height', '340');
	$('FormularioLogin').style.display='none';
	$('FormularioRegistro').style.display='none';
	$('FormularioRecuperar').style.display='none';
	$('FormularioSesion').style.display='none';
	setTimeout("$('FormularioContacto').style.display='block';",300);

}

function SoloSesion(){
	//cerrarTooltips();
	$('vertical_slide').tween('height', '160');
	$('FormularioLogin').style.display='none';
	$('FormularioRegistro').style.display='none';
	$('FormularioRecuperar').style.display='none';
	$('FormularioContacto').style.display='none';
	setTimeout("$('FormularioSesion').style.display='block';",300);

}

function CerrarFormularios(){
	//cerrarTooltips();
	$('vertical_slide').tween('height', '0');
	$('FormularioLogin').style.display='none';
	$('FormularioRegistro').style.display='none';
	$('FormularioRecuperar').style.display='none';
	$('FormularioContacto').style.display='none';
	$('FormularioSesion').style.display='none';
}

function cambiarProducto(chimage,title,description,enlace){
	$('fotoquecambia').src=chimage;
	$('productTitle').innerHTML=title;
	$('productDescription').innerHTML=description;
	$('productLink').href=enlace;
}

function cerrarTooltips()
{
	myFormCheck.each(
		function(elemento, indice)
		{
			elemento.reinitialize('forced');
		}
	);
}

function updateSelect(id,elTarget)
{
	localidad(id);	
	prueba = id.substr(0,2);
	if(prueba=="10"){
		comp="4";
		comp2="10";
	}else{	
	comp = id.substr(0,1);
	comp2=comp;
	}	
	if(comp=="1" || comp=="2" || comp=="3" || comp=="5" || comp=="4" ){
		selectTarget = document.getElementById(elTarget+comp);
	}else{
	selectTarget = document.getElementById(elTarget+"1");
	}	
	var prueboRequest = new Request({
	   method: 'get',
	   url: 'services/localidades.php?pais='+comp2+'',
	   onSuccess: function(texto, xmlrespuesta)
	    { 	   	 	 
			selectTarget.options.length = 0;
			if (id!='') 
			{
				selectTarget.options[selectTarget.options.length]=new Option('-- Select --','')
				sTempAry = texto.split("*");
				for (i=0; i<sTempAry.length; i++) 
				{
					
					sTempValAry = sTempAry[i].split("|");	
					selectTarget.options[selectTarget.options.length]=new Option(sTempValAry[1],sTempValAry[0]) 
				}
			}
			else 
			{
				selectTarget.options[selectTarget.options.length]=new Option('-- Select --','') 
			}
		
		},	  
	}).send(); 	
}

function municipios(id, targuet){
	var prueboRequest = new Request({
	   method: 'get',
	   url: 'services/localidades.php?ciudad='+id+'',
	   onSuccess: function(texto, xmlrespuesta)
	    { 
	   	  // alert('Respuesta:\n' + texto);
		   selectTarget = document.getElementById(targuet);			
			selectTarget.options.length = 0;
			if (id!='') 
			{
				selectTarget.options[selectTarget.options.length]=new Option('-- Select --','')
				sTempAry = texto.split("*");
				for (i=0; i<sTempAry.length; i++) 
				{
					
					sTempValAry = sTempAry[i].split("|");	
					selectTarget.options[selectTarget.options.length]=new Option(sTempValAry[1],sTempValAry[0]) 
				}
			}
			else 
			{
				selectTarget.options[selectTarget.options.length]=new Option('-- Select --','') 
			}
		
		},	  
	}).send(); 
}

function distritos(id, targuet){
	var prueboRequest = new Request({
	   method: 'get',
	   url: 'services/localidades.php?distrito='+id+'',
	   onSuccess: function(texto, xmlrespuesta)
	    { 
	   	  // alert('Respuesta:\n' + texto);
		   selectTarget = document.getElementById(targuet);			
			selectTarget.options.length = 0;
			if (id!='') 
			{
				selectTarget.options[selectTarget.options.length]=new Option('-- Select --','')
				sTempAry = texto.split("*");
				//alert(texto);
				for (i=0; i<sTempAry.length; i++) 
				{
					
					sTempValAry = sTempAry[i].split("|");	
					selectTarget.options[selectTarget.options.length]=new Option(sTempValAry[1],sTempValAry[0]) 
				}
			}
			else 
			{
				selectTarget.options[selectTarget.options.length]=new Option('-- Select --','') 
			}
		
		},	  
	}).send(); 
}

function localidad(campo)
{	
prueba = campo.substr(0,2);
if(prueba=="10"){
	campo1=prueba;
}else{	
campo1 = campo.substr(0,1);
}
	if(campo1=="1"){
		$('comboscolombia').setStyles({display: "block"});		
		$('combosmexico').setStyles({display: "none"});
		$('combosguatemala').setStyles({display: "none"});
		$('comboselsalvador').setStyles({display: "none"});
		$('comboscostarica').setStyles({display: "none"});
	}else{			
		if(campo1=="2"){
			$('comboscolombia').setStyles({display: "none"});		
			$('combosmexico').setStyles({display: "block"});
			$('combosguatemala').setStyles({display: "none"});
			$('comboselsalvador').setStyles({display: "none"});
			$('comboscostarica').setStyles({display: "none"});
		}else{
			if(campo1=="3" ){
				$('comboscolombia').setStyles({display: "none"});		
				$('combosmexico').setStyles({display: "none"});
				$('combosguatemala').setStyles({display: "block"});
				$('comboselsalvador').setStyles({display: "none"});
				$('comboscostarica').setStyles({display: "none"});
			}else{
				if(campo1=="5"){
					$('comboscolombia').setStyles({display: "none"});		
					$('combosmexico').setStyles({display: "none"});
					$('combosguatemala').setStyles({display: "none"});
					$('comboselsalvador').setStyles({display: "none"});
					$('comboscostarica').setStyles({display: "block"});
				}else{
					if(campo1=="10"){
						$('comboscolombia').setStyles({display: "none"});		
						$('combosmexico').setStyles({display: "none"});
						$('combosguatemala').setStyles({display: "none"});
						$('comboselsalvador').setStyles({display: "block"});
						$('comboscostarica').setStyles({display: "none"});
					}else{
						$('comboscolombia').setStyles({display: "block"});		
						$('combosmexico').setStyles({display: "none"});
						$('combosguatemala').setStyles({display: "none"});
						$('comboselsalvador').setStyles({display: "none"});
						$('comboscostarica').setStyles({display: "none"});
					}
				}		
			}	
		}		
	}		
}