﻿function validarContactenos(f) {
    if((f.email != null) &&  (!isValidEmail(f.email))) {
        alert("Debe introducir un email válido");
    } else {
        f.submit();
    }
}

function isValidEmail(emailForm) {
    var idx_at = emailForm.value.indexOf('@');
    if (idx_at == -1 || idx_at == 0) return false;
    var idx_dot = emailForm.value.indexOf('.', (idx_at + 2));
    if (idx_dot == -1 ) return false;
    return true;
}

function isEmptyField(campo) {
    if (campo.value.length==0 || campo.value==null) return true;
    else return false;
}

function changeMovility(f) {
    if (f.movility[f.movility.selectedIndex].value == '1') {
        f.cityMovility.disabled = false;
    } else {
        f.cityMovility.disabled = true;
    }
}

function changeWork(f) {
    if (f.workCapio[f.workCapio.selectedIndex].value == '1') {
        f.centerWorkCapio.disabled = false;
        f.monthIniWork.disabled = false;
        f.monthEndWork.disabled = false;
        f.yearIniWork.disabled = false;
        f.yearEndWork.disabled = false;
    } else {
        f.centerWorkCapio.disabled = true;
        f.monthIniWork.disabled = true;
        f.monthEndWork.disabled = true;
        f.yearIniWork.disabled = true;
        f.yearEndWork.disabled = true;
    }
}

function controlarCurriculum() {
    var f = document.forms[1];


    if (f.workCapio[f.workCapio.selectedIndex].value == '1') {
        f.centerWorkCapio.disabled = false;
        f.monthIniWork.disabled = false;
        f.monthEndWork.disabled = false;
        f.yearIniWork.disabled = false;
        f.yearEndWork.disabled = false;
    } else {
        f.centerWorkCapio.disabled = true;
        f.monthIniWork.disabled = true;
        f.monthEndWork.disabled = true;
        f.yearIniWork.disabled = true;
        f.yearEndWork.disabled = true;
    }

    if (f.movility[f.movility.selectedIndex].value == '1') {
        f.cityMovility.disabled = false;
    } else {
        f.cityMovility.disabled = true;
    }

    var div = document.getElementById("div_comentarios");
    if (f.idUser.value != '') {
        div.style.display = 'block';
    } else {
        div.style.display = 'none';
    }

    var div2 = document.getElementById("div_vip");
    if (f.admin.value != '' && f.admin.value == '1') {
        div2.style.display = 'block';
    } else {
        div2.style.display = 'none';
    }
}

function validarFormulario(f) {

    if (f.conditions.checked == false) {
        alert ('Debe aceptar las condiciones de politica y privacidad');
    }
    else {
        f.submit();
    }
}

function isBadFormat(s){
    if(s!= null && s.value!=null) {
        if(s.value == "") {
            return true;
        }
        if(!isNaN(s.value)) {
            return false;
        }
    }
    return true;
}

function hideLevel( _levelId ) {
    var thisLevel = document.getElementById( _levelId );
    if(thisLevel != null) {
        thisLevel.style.display = "none";
    }
}

function showLevel( _levelId ) {
	if ( _levelId != "null" ) {
        var thisLevel = document.getElementById( _levelId );
        //alert(thisLevel);
        if(thisLevel != null) {
            //alert(thisLevel.style);
            if ( thisLevel.style.display == "none") {
            	//alert("lo muestro");
                thisLevel.style.display = "block";
            } else {
                hideLevel( _levelId);
            }
        }
    }
}

function changeTypeContact(f) {
    var v = f.typeContact.options[f.typeContact.selectedIndex].value;
    var sug = document.getElementById("tr_sugerencia");
    var inf = document.getElementById("tr_information");
    var env = document.getElementById("tr_enviar");
    if (v == '0') {
        sug.style.display = 'block';
        env.style.display = 'block';
        inf.style.display = 'none';
    } else if (v == '1') {
        sug.style.display = 'none';
        env.style.display = 'block';
        inf.style.display = 'block';
    } else {
        sug.style.display = 'none';
        env.style.display = 'none';
        inf.style.display = 'none';
    }
}

function isInteger(value){
    if (value.indexOf('.') >= 0) {
        return false;
    }
    if (isNaN(value)) {
        return false;
    }else{
        return true;
    }
}

function controlarCurriculum() {
	var workCapio = document.getElementById("workCapio");
	var centerWorkCapio = document.getElementById("centerWorkCapio");
	var monthIniWork = document.getElementById("monthIniWork");
	var monthEndWork = document.getElementById("monthEndWork");
	var yearIniWork = document.getElementById("yearIniWork");
	var yearEndWork = document.getElementById("yearEndWork");
	var movility = document.getElementById("movility");
	var cityMovility = document.getElementById("cityMovility");
	
	if (workCapio[workCapio.selectedIndex].value == '1') {
    	centerWorkCapio.disabled = false;
        monthIniWork.disabled = false;
        monthEndWork.disabled = false;
        yearIniWork.disabled = false;
        yearEndWork.disabled = false;
    } else {
    	centerWorkCapio.disabled = true;
        monthIniWork.disabled = true;
        monthEndWork.disabled = true;
        yearIniWork.disabled = true;
        yearEndWork.disabled = true;
    }

    if (movility[movility.selectedIndex].value == '1') {
        cityMovility.disabled = false;
    } else {
        cityMovility.disabled = true;
    }
}



