function show(){
    $('.contact_form').css('display','block');
    $('#amigo_form').css('display','none');
    $('#fade').css('display','block');
}
function hide(){
    $('.contact_form').css('display','none');
    $('#amigo_form').css('display','none');
    $('#fade').css('display','none');
}
function showAmigo(){
    $('#amigo_form').css('display','block');
    $('#fade').css('display','block');
}
function hideAmigo(){
    $('#amigo_form').css('display','none');
    $('#fade').css('display','none');
}
function showTerminos(){
    $('#terminos_de_uso').css('display','block');
    $('#fade').css('display','block');
}
function hideTerminos(){
    $('#terminos_de_uso').css('display','none');
    $('#fade').css('display','none');
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf("@")
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   //alert("E-mail Incorrecto")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("E-mail Incorrecto")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   // alert("E-mail Incorrecto")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("E-mail Incorrecto")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   // alert("E-mail Incorrecto")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		   // alert("E-mail Incorrecto")
		    return false
		 }

		 if (str.indexOf(" ")!=-1){
		    //alert("E-mail Incorrecto")
		    return false
		 }

 		 return true
	}

function depForm(nameForm,update){
    error = 0;
    //alert(nameForm);
    if (nameForm=='search')
    {
            if($("input[name='expresion']").val()==''){
                $("input[name='expresion']").val('Introduzca la palabra a buscar');
                error = 1;
            }
            if(!error){
                document.search.submit();
                $("form").submit(function() {
                  return false;
                });
            }
    }
    else if (nameForm == 'socio' || nameForm =='socio_update')
    {
            if($("input[name='data[Socio][nombre]']").val()=='' || $("input[name='data[Socio][nombre]']").val().lenght<3){
                $("#error_nombre").html('Introduzca un nombre válido');
                error = 1;
            }
            else{
                $("#error_nombre").html('');
            }
            if($("input[name='data[Socio][apellidos]']").val()=='' || $("input[name='data[Socio][apellidos]']").val().lenght<3){
                $("#error_apellidos").html('Introduzca un apellido válido');
                error = 1;
            }
            else{
                $("#error_apellidos").html('');
            }
            var email = ($("input[name='data[Socio][email]']").val());
            if($("input[name='data[Socio][email]']").val()==''|| echeck(email)==false){
                $("#error_email").html('Introduzca un email válido');
                error = 1;
            }
            else{
                $("#error_email").html('');
            }
            if($("input[name='data[Socio][tlf]']").val()=='' || $("input[name='data[Socio][tlf]']").val().lenght<9){
                $("#error_tlf").html('Introduzca su número de telefono');
                error = 1;
            }
            else{
                $("#error_tlf").html('');
            }
            if($("input[name='data[Socio][profesion]']").val()==''|| $("input[name='data[Socio][profesion]']").val().lenght<5){
                $("#error_profesion").html('Introduzca su profesión actual');
                error = 1;
            }
            else{
                $("#error_profesion").html('');
            }
            if($("input[name='data[Socio][cp]']").val()==''|| $("input[name='data[Socio][cp]']").val().lenght<5){
                $("#error_cp").html('Introduzca su cp');
                error = 1;
            }
            else{
                $("#error_cp").html('');
            }
            
            if($("input[name='data[Socio][cargo]']").val()==''|| $("input[name='data[Socio][cargo]']").val().lenght<5){
                $("#error_cargo").html('Introduzca su cargo actual');
                error = 1;
            }
            else{
                $("#error_cargo").html('');
            }
            if($("input[name='data[Socio][lugar_trabajo]']").val()==''|| $("input[name='data[Socio][lugar_trabajo]']").val().lenght<5){
                $("#error_lugar_trabajo").html('Introduzca su lugar de trabajo actual');
                error = 1;
            }
            else{
                $("#error_lugar_trabajo").html('');
            }
            if($("input[name='data[Socio][iban]']").val()==''|| $("input[name='data[Socio][iban]']").val().lenght<12){
                $("#error_iban").html('Introduzca un número IBAN válido');
                error = 1;
            }
            else{
             $("#error_iban").html('');
            }
            if($("input[name='data[Socio][departamento]']").val()==''|| $("input[name='data[Socio][departamento]']").val().lenght<3){
                $("#error_departamento").html('Introduzca el departamento en el que trabaja');
                error = 1;
            }
            else{
                $("#error_departamento").html('');
            }
            if($("input[name='data[Socio][direccion]']").val()==''|| $("input[name='data[Socio][direccion]']").val().lenght<5){
                $("#error_direccion").html('Introduzca su dirección actual');
                error = 1;
            }
            else{
                $("#error_direccion").html('');
            }
            if($("input[name='data[Socio][ciudad]']").val()==''|| $("input[name='data[Socio][ciudad]']").val().lenght<5){
                $("#error_ciudad").html('Introduzca la ciudad en la que reside');
                error = 1;
            }
            else{
                $("#error_ciudad").html('');
            }
            if($("input[name='data[Socio][pais]']").val()==''|| $("input[name='data[Socio][pais]']").val().lenght<5){
                $("#error_pais").html('Introduzca el pais de origen');
                error = 1;
            }
            else{
                $("#error_pais").html('');
            }
            if($("input[name='acepto']").checked==false){
                alert('Debe aceptar nuestra política de privacidad');
                error = 1;
            }

            if(!error){
               // alert(update);
                if(update=='1'){
                    document.socio.action='/socios/update';
                }
                //alert(document.socio.action);
                document.socio.submit();
                $("form").submit(function() {
                  return false;
                });
            }
    }
    else if (nameForm == 'faq')
    {
            if($("input[name='data[Faq][nombre]']").val()=='' ||$("input[name='data[Faq][nombre]']").val().lenght<3){
                $("#error_nombre").html('Introduzca un nombre válido');
                error = 1;
            }
            if($("input[name='data[Faq][apellidos]']").val()=='' ||$("input[name='data[Faq][apellidos]']").val().lenght<3){
                $("#error_apellidos").html('Introduzca un apellido válido');
                error = 1;
            }
            var email = ($("input[name='data[Faq][email]']").val());

            if($("input[name='data[Faq][email]']").val()=='' || echeck(email)==false){
                $("#error_email").html('Introduzca un email válido');
                error = 1;
            }
            if($("input[name='data[Faq][pregunta]']").val()==''){
                $("input[name='data[Faq][pregunta]']").val('Introduzca una pregunta');
                error = 1;
            }
            
            if(!error){
                document.faq.submit();
                $("form").submit(function() {
                  return false;
                });
            }
     }
}

function estadoSocio(check, texto){

    $('.estado_socio').val(check);
    $('.titulo_boton_socio').val(texto);

   /* if(check==1){
        $('.actualizo_dato').css('display','block');
    }
    else{
        $('.actualizo_dato').css('display','none');
    }*/

}
