function comprobarSiBisisesto(anio){
if ( ( anio % 100 != 0) && ((anio % 4 == 0) || (anio % 400 == 0))) {
	return true;
	}
else {
	return false;
	}
}

function esFechaValida(fecha){

       if (fecha != undefined && fecha.value != "" ){
		if (!/^\d{2}\/\d{2}\/\d{4}$/.test(fecha.value)){
			//alert("formato de fecha no válido (dd/mm/aaaa)");
			return false;
		}
		var dia  =  parseInt(fecha.value.substring(0,2),10);
		var mes  =  parseInt(fecha.value.substring(3,5),10);
		var anio =  parseInt(fecha.value.substring(6),10);
	switch(mes){
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			numDias=31;
			break;
		case 4: case 6: case 9: case 11:
			numDias=30;
			break;
		case 2:
			if (comprobarSiBisisesto(anio)){ numDias=29 }else{ numDias=28};
			break;
		default:
			//alert("Fecha introducida errónea");
			return false;
	}
		if (dia>numDias || dia==0){
			//alert("Fecha introducida errónea");
			return false;
		}
		return true;
	}
}

function isExtension(file){
extensiones_permitidas = new Array(".gif", ".jpg", ".jpeg");
extension = (file.substring(file.lastIndexOf("."))).toLowerCase();
permitida = false;

for (var i = 0; i < extensiones_permitidas.length; i++) { 
         if (extensiones_permitidas[i] == extension) { 
         permitida = true; 
         break; 
         } 
      }
 
if (!permitida) {
return(false);
}else{
return(true);
}

}

$(document).ready(function(){
	$("#sendcontactform").click(function(){
		var valid = '';
		var isr = '* ';
		
		var get_name = $("#get_name").val();
		var get_apellido = $("#get_apellido").val();
		var get_fecnac = $("#get_fecnac").val();
        var get_mail = $("#get_mail").val();
		var get_direccion = $("#get_direccion").val();
		var get_distrito = $("#get_distrito").val();
		var get_fono = $("#get_fono").val();
		var get_celular = $("#get_celular").val();
		var rb_sexo = $("#rb_sexo").val();
		var txt_description = $("#txt_description").val();
		var file_image = $("#file_image").val();
		
		if (get_name.length<1) {
			valid += '<br />'+isr+'Sus nombres.';
		}
        if (get_apellido.length<1) {
			valid += '<br />'+isr+'Sus Apellidos.';
		}
		
		if (get_fecnac=='' || !esFechaValida(document.getElementById('get_fecnac'))  ) {
			 valid += '<br />'+isr+'Fecha de Nacimiento.';
		}
		
		if (!get_mail.match(/^([a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,4}$)/i)) {
			valid += '<br />'+isr+'Su E-mail.';
		}
		
        if (get_direccion.length<1) {
			valid += '<br />'+isr+'Ingrese su dirección donde vive';
		}

		if (get_distrito.length<1) {
			valid += '<br />'+isr+'Su Distrito.';
		}
		
		if (get_fono.length<1) {
			valid += '<br />'+isr+'Ingrese su teléfono fijo.';
		}

		if (get_celular.length<1) {
			valid += '<br />'+isr+'Su Celular.';
		}

        if (file_image.length==0 || !isExtension(file_image)) {
			valid += '<br />'+isr+'Seleccione un archivo de imagen válido, [*.JPG, *.JPEG].';
		}
		
		
		if (valid!='') {
			$("#responsecontactform").fadeIn("slow");
			$("#responsecontactform").html("<strong>Verifique los siguientes campos :<br></strong> "+valid);
		}
		else {
			$("#responsecontactform").css("display", "block");
			$("#responsecontactform").html("Procesando formulario .... ");
			$("#responsecontactform").fadeIn("slow");
			return (true) ;
		}
		return false;
	});
});
 
function returnpage (mod){
var filereturn ;
	
if(!mod)
mod = 0;

if(mod==1)
filereturn = 'index.php';
else
filereturn = 'index.html';

location.href = filereturn;	
}