extensiones_doc = new Array(".doc", ".docx", ".pdf");
extensiones_img = new Array(".jpg", ".jpeg");

function isExtension(file,extensiones_permitidas){
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_nameape = $("#get_nameape").val();
		var get_distrito = $("#get_distrito").val();
		var get_fonocel = $("#get_fonocel").val();
		var get_mail = $("#get_mail").val();
        var file_image = $("#file_image").val();
		var get_description = $("#txt_description").val();
		var get_puesto = $("#sle_puesto").val();
		var file_photobody = $("#file_imagephoto").val();
		
		if (get_nameape.length<1) {
			valid += '<br />'+isr+'Sus nombres y apellidos.';
		}
		
		if (get_distrito.length<1) {
			valid += '<br />'+isr+'Su Distrito.';
		}

		if (get_fonocel.length<1) {
			valid += '<br />'+isr+'Su Teléfono y/o Celular.';
		}
		
		if (!get_mail.match(/^([a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,4}$)/i)) {
			valid += '<br />'+isr+'Su E-mail.';
		}

		if (file_image.length==0 || !isExtension(file_image,extensiones_doc)) {
			valid += '<br />'+isr+'Seleccione un archivo válido del C.V.';
		}
		
		if(get_puesto=="" || get_puesto=='0'){
			valid += '<br />'+isr+'Seleccione el puesto al que postula.';
		}
		
		if (file_photobody.length==0 || !isExtension(file_photobody,extensiones_img)) {
			valid += '<br />'+isr+'Seleccione un archivo válido de la imagen completa.';
		}




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;	
}