// JavaScript Document
function getCategoria(){
	var str = $("#form_promoCategoria").serialize();
	window.location.href = "index.php?"+str;
}

function getCiudad(){
	var str = $("#form_ciudad").serialize();
	window.location.href = "index.php?"+str;
}

function buscar(){
	var str = $("#form_buscar").serialize();
	window.location.href = "index.php?"+str;
}

function cargaCaptcha(){
	$('#captchaimg').html('cargando..');
	$.get("captcha.php",function(){	
							$('#captchaimg').html('<img src="images/cap.png?'+Math.random ( )+'" width="132" height="50" alt="Captcha image" />');
								 });
}

function promoEdit(){
	$("#promoEdit").toggle();
}

function promoGuarda(){
	document.getElementById("form_promo").action = 'index.php';
	document.getElementById("form_promo").submit();
}

function validarContacto() {
	// validate the comment form when it is submitted
	$("#form_contacto").validate({
		rules: {
			captcha: {
				required: true,
				remote: "captchaVerifica.php"
			}
		},
		submitHandler: function(form) {
				//var str = $("#form_contacto").serialize();
				document.getElementById("form_contacto").action = 'index.php';
				document.getElementById("form_contacto").submit();
			}
	});
}

function sendForm(formSend){
	var str = $("#"+formSend).serialize();
	$.ajax({
		   type: "POST",
		   url: 'index.php',
		   data: str,
		   success: function(msg){
			  if( parseInt(msg) == "0" ){
					window.location.href = 'index.php';
			   }else{
				   //alert(msg);
				   cargaRecordar();
			   }
		   }
		   });
}

function cargaRecordar(){
	var params = { view: 'recordar'};
	$('#htmlRecordar').load('index.php',params,function(){
			$("#incorrecto").fadeIn("slow");
			$("#incorrecto").addClass("recordar");
/*			$("#incorrecto").fadeOut("slow");
			$("#incorrecto").removeClass("recordar");
			*/
		}
	);	
}
function cancelaRecordar(){
	$("#htmlRecordar").html('<form class="cmxform" id="form_login" name="form_login" action="" method="post" style="margin:0px;"><span class="red">Documento:</span><input name="documento" id="documento" class="inputText" type="text" /><span class="red">Clave:</span><input name="pwd" id="pwd" class="inputText" type="password" /><input type="image" src="images/btn_ingresar.gif" alt="ingresar" width="76" vspace="0" height="18" border="0" onclick="javascript:validarLogin();"  style="vertical-align:middle" /> l <a href="index.php?view=registro" class="red">Reg&iacute;strese</a> l <a class="red" href="index.php?view=contactenos">Cont&aacute;ctenos</a><input type="hidden" name="view" id="view" value="login" /></form>');
}

function validarRegistro() {
	// validate the register form when it is submitted
	$("#form_registro").validate({
		rules: {
			documento: {
				required: true,
				remote: "registroVerificaUsuario.php"
			},
			login: {
				required: true,
				remote: "registroVerificaUsuario.php"
			},
			email: {
				required: true,
				remote: "registroVerificaUsuario.php"
			},
			captcha: {
				required: true,
				remote: "captchaVerifica.php"
			},
			confirma_password: {
				required: true,
				equalTo: "#password"
			}
		},
		submitHandler: function(form) {
			document.getElementById("form_registro").action = 'index.php';
			document.getElementById("form_registro").submit();
		},
		messages: {
			documento: {
				required: "Por favor ingrese un documento",
				remote: jQuery.format("{0} se encuentra en uso, por favor ingrese otro documento.")	
			},
			login: {
				required: "Por favor ingrese un nombre de Usuario",
				remote: jQuery.format("{0} se encuentra en uso, por favor ingrese otro nombre de usuario.")	
			},
			email: {
				required: "Por favor ingrese su email.",
				email: "Ingrese un correo válido  (xxxxx@xxxxx.com).",
				remote: jQuery.format("{0} se encuentra en uso, por favor ingrese otro email.")	
			},
			confirma_password: {
				required: "Debe confirmar la contraseña",
				equalTo: "La contraseña no coincide"
			}
		}
	});
}

function validarRecordar() {
	// validate the register form when it is submitted
	$("#form_recordar").validate({
		rules: {
			email: {
				required: true
			}
		},
		submitHandler: function(form) {
			document.getElementById("form_recordar").action = 'index.php';
			document.getElementById("form_recordar").submit();
		},
		messages: {
			email: {
				required: "Por favor ingrese su email.",
				email: "Ingrese un correo válido  (xxxxx@xxxxx.com)."
			}
		}
	});
}

function validarLogin() {
	// validate the comment form when it is submitted
	$("#form_login").validate({
		submitHandler: function(form) {
				//var str = $("#form_contacto").serialize();
				sendForm('form_login');
				//document.getElementById("form_login").action = 'index.php';
				//document.getElementById("form_login").submit();
			}
	});
}

function validarCiudad() {

	$('#htmlCiudad').load('registroCiudad.php',{id: document.form_registro.idCiudad.value});
}