/***********************Crea el Objeto AJAX******************************/
function nuevoAjax(){ 
	var xmlhttp=false; 
	try{ 
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
	}catch(e){ 
		try{ 
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		catch(E) { xmlhttp=false; }
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp=new XMLHttpRequest(); } 
	return xmlhttp;
}
/************************************************************************************************/
function registro_usuario(datos){
	if(datos.email.value == ""){
		alert("Ingrese su direccion de correo electronico");
		return false;
	}
	if(datos.clave.value == ""){
		alert("Ingrese su clave");
		return false;
	}
	if(isEmailAddress(datos.email)) datos.submit();
}
/************************************************************************************************/
function acceso_usuario(datos){
	if(datos.email.value == ""){
		alert("Ingrese su direccion de correo electronico");
		return false;
	}
	if(datos.clave.value == ""){
		alert("Ingrese su clave");
		return false;
	}
	if(isEmailAddress(datos.email)) datos.submit();
}
/************************************************************************************************/
function enviar_datos(datos){
	if(datos.email.value == ""){
		alert("Ingrese su direccion de correo electronico");
		return false;
	}
	if(datos.clave.value == ""){
		alert("Ingrese su clave");
		return false;
	}
	if(datos.medio.value == 0){
		alert("Seleccione el Medio de contacto");
		return false;
	}
	if(isEmailAddress(datos.email)) datos.submit();
}
/************************************************************************************************/
function isEmailAddress(theElement){
	var s = theElement.value;
	var filter=/^[A-Za-z][A-Za-z0-9_.-]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
	if (s.length == 0 ) return true;
	if (filter.test(s))
		return true;
	else
		alert("Ingrese una dirección de correo válida");
	theElement.focus();
	return false;
}
/************************************************************************************************/
function isCP(theElement){
	var s = theElement.value;
	if(s.length > 5 || s.length < 4){
		alert("Ingrese un Codigo Postal válido");
		theElement.focus();
		return false;
	}
	if(Number(s)) return true;
	else 
		alert("Ingrese un Codigo Postal válido");
	theElement.focus();
	return false;
}
/************************************************************************************************/
function validarNumero(elemento,nombre){
	if (isNaN(elemento.value)){
		alert ("El valor del campo "+nombre+" debe ser numerico.");
		elemento.selected;
		elemento.focus();
		return false;
	}
	else{
		return elemento.value;
	}
}
/************************************************************************************************/
function isNSS(theElement){
	var s = theElement.value;
	if(s.length < 11){
		alert("Ingrese un Numero de Seguro Social válido");
		theElement.focus();
		return false;
	}else
	return true;
}
/************************************************************************************************/
function buscar(datos){
	if(datos.estado.value == 0){
		alert("Seleccione un estado");
		return false;
	}else datos.submit();
}
/************************************************************************************************/
function buscar2(datos){
	if(datos.estado.value == 0){
		alert("Seleccione un estado");
		return false;
	}else datos.submit();
}
/************************************************************************************************/
function acoordion(div){
	if(document.getElementById(div).style.display == 'none'){
		document.getElementById(div).style.display = 'inline';
	}else{
		document.getElementById(div).style.display = 'none';
	}
}
/************************************************************************************************/
function loadDate(num){
	if(document.getElementById('dia_'+num).value != 0 && document.getElementById('mes_'+num).value != 0 && document.getElementById('anio_'+num).value != 0){
		ajax=nuevoAjax();
		ajax.open("POST", "fecha.php",true);
		ajax.onreadystatechange=function() {
			if (ajax.readyState==4){
				document.getElementById('fecha_'+num).innerHTML = ajax.responseText;
			}
		}
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		ajax.send("dia="+document.getElementById('dia_'+num).value+"&mes="+document.getElementById('mes_'+num).value+"&anio="+document.getElementById('anio_'+num).value+"&num="+num);
	}
}
/************************************************************************************************/
function salvar_cv(form){
	var campo = {'0':'Titulo','1':'Especialidad','2':'el Area de interes'
				,'3':'','4':'Nombre','5':'Fecha de Nacimiento ( dia )','6':'Fecha de Nacimiento ( mes )','7':'Fecha de Nacimiento ( año )','8':'Estado Civil','9':'Genero','10':'Lada Telefono','11':'Telefono','12':'Lada Celular','13':'Celular','14':'E-mail','15':''
				,'16':'Calle','17':'No exterior','18':'','19':'el Estado','20':'Municipio','21':'Colonia','22':'Ciudad','23':'Codigo Postal'
				,'24':'Ultimo grado de estudios','25':'Escuela','26':'Periodo cursado ( de )','27':'Periodo cursado ( a )','28':'Comprobante'
				,'29':'Actividades extracurriculares'
				,'30':'','31':'','32':'','33':'','34':'','35':'','36':'','37':''
				,'38':'','39':'','40':'','41':'','42':'','43':'','44':'','45':'','46':'','47':'','48':''
				,'49':'','50':'','51':'','52':'','53':'','54':'','55':'','56':'','57':'','58':'','59':'','60':'','61':'','62':'','63':'','64':'','65':'','66':'','67':'','68':'','69':'','70':'','71':'','72':'','73':'','74':'','75':'','76':'','77':'','78':'','79':'','80':'','81':'','82':'','83':'','84':'','85':'','86':'','87':''
				,'88':'','89':'','90':'','91':'','92':'','93':''
				,'94':'','95':'','96':'','97':'','98':'','99':'','100':'','101':'','102':'','103':'','104':'','105':'','106':'Pretensiones minimas','107':'Pretensiones esperadas'
				};
	for (i=0;i<document.forms[1].elements.length;i++) {
		if(document.forms[1].elements[i].type == 'text' || document.forms[1].elements[i].type == 'textarea'){
			if(document.forms[1].elements[i].value == "" && campo[i] != ''){
				alert("El campo "+campo[i]+" es obligatorio ");
				document.forms[1].elements[i].focus();
				return false;
			}
			if(i == 10){
				if(!validarNumero(document.forms[1].elements[10],campo[10])){
					return false;
				}
			}
			if(i == 11){
				if(!validarNumero(document.forms[1].elements[11],campo[11])){
					return false;
				}
			}
			if(i == 12){
				if(!validarNumero(document.forms[1].elements[12],campo[12])){
					return false;
				}
			}
			if(i == 13){
				if(!validarNumero(document.forms[1].elements[13],campo[13])){
					return false;
				}
			}
			if(i == 14){
				if(!isEmailAddress(document.forms[1].elements[14])){
					return false;
				}
			}
			if(i == 15 && document.forms[1].elements[15].value != ''){
				if(!isNSS(document.forms[1].elements[15])){
					return false;
				}
			}
			if(i == 17){
				if(!validarNumero(document.forms[1].elements[17],campo[17])){
					return false;
				}
			}
			if(i == 18 && document.forms[1].elements[18].value != ''){
				if(!validarNumero(document.forms[1].elements[18],'No interior')){
					return false;
				}
			}
			if(i == 23){
				if(!isCP(document.forms[1].elements[23])){
					return false;
				}
			}
			if(i == 59 && document.forms[1].elements[59].value != ''){
				if(!validarNumero(document.forms[1].elements[59],'Lada telefono')){
					return false;
				}
			}
			if(i == 60 && document.forms[1].elements[60].value != ''){
				if(!validarNumero(document.forms[1].elements[60],'Telefono')){
					return false;
				}
			}
			if(i == 72 && document.forms[1].elements[72].value != ''){
				if(!validarNumero(document.forms[1].elements[72],'Lada telefono')){
					return false;
				}
			}
			if(i == 73 && document.forms[1].elements[73].value != ''){
				if(!validarNumero(document.forms[1].elements[73],'Telefono')){
					return false;
				}
			}
			if(i == 85 && document.forms[1].elements[85].value != ''){
				if(!validarNumero(document.forms[1].elements[85],'Lada telefono')){
					return false;
				}
			}
			if(i == 86 && document.forms[1].elements[86].value != ''){
				if(!validarNumero(document.forms[1].elements[86],'Telefono')){
					return false;
				}
			}
			if(i == 106){
				if(!validarNumero(document.forms[1].elements[106],campo[106])){
					return false;
				}
			}
			if(i == 107){
				if(!validarNumero(document.forms[1].elements[107],campo[107])){
					return false;
				}
			}
		}else if(document.forms[1].elements[i].type == 'select-one'){
			if(document.forms[1].elements[i].value == 0 && campo[i] != ''){
				alert("Debe seleccionar "+campo[i]+" ");
				document.forms[1].elements[i].focus();
				return false;
			}
		}
	}
	form.submit();
}
/************************************************************************************************/
function guardar_cv(form){
	var campo = {'0':'Titulo','1':'Especialidad','2':'el Area de interes'
				,'3':'','4':'Nombre','5':'Fecha de Nacimiento ( dia )','6':'Fecha de Nacimiento ( mes )','7':'Fecha de Nacimiento ( año )','8':'Estado Civil','9':'Genero','10':'Lada Telefono','11':'Telefono','12':'Lada Celular','13':'Celular','14':'E-mail','15':''
				,'16':'Calle','17':'No exterior','18':'','19':'el Estado','20':'Municipio','21':'Colonia','22':'Ciudad','23':'Codigo Postal'
				,'24':'Ultimo grado de estudios','25':'Escuela','26':'Periodo cursado ( de )','27':'Periodo cursado ( a )','28':'Comprobante'
				,'29':'Actividades extracurriculares'
				,'30':'','31':'','32':'','33':'','34':'','35':'','36':'','37':''
				,'38':'','39':'','40':'','41':'','42':'','43':'','44':'','45':'','46':'','47':'','48':''
				,'49':'','50':'','51':'','52':'','53':'','54':'','55':'','56':'','57':'','58':'','59':'','60':'','61':'','62':'','63':'','64':'','65':'','66':'','67':'','68':'','69':'','70':'','71':'','72':'','73':'','74':'','75':'','76':'','77':'','78':'','79':'','80':'','81':'','82':'','83':'','84':'','85':'','86':'','87':''
				,'88':'','89':'','90':'','91':'','92':'','93':''
				,'94':'','95':'','96':'','97':'','98':'','99':'','100':'','101':'','102':'','103':'','104':'','105':'','106':'Pretensiones minimas','107':'Pretensiones esperadas'
				};
	for (i=0;i<document.forms[1].elements.length;i++) {
		if(document.forms[1].elements[i].type == 'text' || document.forms[1].elements[i].type == 'textarea'){
			if(document.forms[1].elements[i].value == "" && campo[i] != ''){
				alert("El campo "+campo[i]+" es obligatorio ");
				document.forms[1].elements[i].focus();
				return false;
			}
			if(i == 10){
				if(!validarNumero(document.forms[1].elements[10],campo[10])){
					return false;
				}
			}
			if(i == 11){
				if(!validarNumero(document.forms[1].elements[11],campo[11])){
					return false;
				}
			}
			if(i == 12){
				if(!validarNumero(document.forms[1].elements[12],campo[12])){
					return false;
				}
			}
			if(i == 13){
				if(!validarNumero(document.forms[1].elements[13],campo[13])){
					return false;
				}
			}
			if(i == 14){
				if(!isEmailAddress(document.forms[1].elements[14])){
					return false;
				}
			}
			if(i == 15 && document.forms[1].elements[15].value != ''){
				if(!isNSS(document.forms[1].elements[15])){
					return false;
				}
			}
			if(i == 17){
				if(!validarNumero(document.forms[1].elements[17],campo[17])){
					return false;
				}
			}
			if(i == 18 && document.forms[1].elements[18].value != ''){
				if(!validarNumero(document.forms[1].elements[18],'No interior')){
					return false;
				}
			}
			if(i == 23){
				if(!isCP(document.forms[1].elements[23])){
					return false;
				}
			}
			if(i == 59 && document.forms[1].elements[59].value != ''){
				if(!validarNumero(document.forms[1].elements[59],'Lada telefono')){
					return false;
				}
			}
			if(i == 60 && document.forms[1].elements[60].value != ''){
				if(!validarNumero(document.forms[1].elements[60],'Telefono')){
					return false;
				}
			}
			if(i == 72 && document.forms[1].elements[72].value != ''){
				if(!validarNumero(document.forms[1].elements[72],'Lada telefono')){
					return false;
				}
			}
			if(i == 73 && document.forms[1].elements[73].value != ''){
				if(!validarNumero(document.forms[1].elements[73],'Telefono')){
					return false;
				}
			}
			if(i == 85 && document.forms[1].elements[85].value != ''){
				if(!validarNumero(document.forms[1].elements[85],'Lada telefono')){
					return false;
				}
			}
			if(i == 86 && document.forms[1].elements[86].value != ''){
				if(!validarNumero(document.forms[1].elements[86],'Telefono')){
					return false;
				}
			}
			if(i == 106){
				if(!validarNumero(document.forms[1].elements[106],campo[106])){
					return false;
				}
			}
			if(i == 107){
				if(!validarNumero(document.forms[1].elements[107],campo[107])){
					return false;
				}
			}
		}else if(document.forms[1].elements[i].type == 'select-one'){
			if(document.forms[1].elements[i].value == 0 && campo[i] != ''){
				alert("Debe seleccionar "+campo[i]+" ");
				document.forms[1].elements[i].focus();
				return false;
			}
		}
	}
	form.submit();
}
/************************************************************************************************/
function salvar_empresa(form){
	var campo = new Array(
						  "Razon Social","Giro","Nombre","Apellido","E-mail","Contraseña","Rescribir contraseña","","Telefono","","","Calle","No exterior",
						  "","Estado","Municipio","Colonia","","",""
					);
	for (i=0;i<document.forms[0].elements.length;i++) {
		if(document.forms[0].elements[i].type == 'text' || document.forms[0].elements[i].type == 'textarea'){
			if(document.forms[0].elements[i].value == "" && campo[i] != ''){
				alert("El campo "+campo[i]+" es obligatorio");
				document.forms[0].elements[i].focus();
				return false;
			}
			if(i == 4){
				if(!isEmailAddress(document.forms[0].elements[4])){
					return false;
				}
			}
			if(i == 8){
				if(!validarNumero(document.forms[0].elements[8],campo[8])){
					return false;
				}
			}
			if(i == 12){
				if(!validarNumero(document.forms[0].elements[12],campo[12])){
					return false;
				}
			}
			if(i == 18){
				if(!isCP(document.forms[0].elements[18])){
					return false;
				}
			}
		}else if(document.forms[0].elements[i].type == 'select-one'){
			if(document.forms[0].elements[i].value == 0 && campo[i] != ''){
				alert("Debe seleccionar "+campo[i]);
				document.forms[0].elements[i].focus();
				return false;
			}
		}
	}
	if(document.forms[0].elements[5].value != document.forms[0].elements[6].value){
		alert("Los compos de contraseñas no coinciden, verifique! ");
		document.forms[0].elements[5].focus();
		return false;
	}
	form.submit();
}
/************************************************************************************************/
function guardar_empresa(form){
	var campo = new Array(
						  "Razon Social","Giro","Nombre","Apellido","E-mail","Contraseña","Rescribir contraseña","","Telefono","","","Calle","No exterior",
						  "","Estado","Municipio","Colonia","","",""
					);
	for (i=0;i<document.forms[0].elements.length;i++) {
		if(document.forms[0].elements[i].type == 'text' || document.forms[0].elements[i].type == 'textarea'){
			if(document.forms[0].elements[i].value == "" && campo[i] != ''){
				alert("El campo "+campo[i]+" es obligatorio");
				document.forms[0].elements[i].focus();
				return false;
			}
			if(i == 4){
				if(!isEmailAddress(document.forms[0].elements[4])){
					return false;
				}
			}
			if(i == 8){
				if(!validarNumero(document.forms[0].elements[8],campo[8])){
					return false;
				}
			}
			if(i == 12){
				if(!validarNumero(document.forms[0].elements[12],campo[12])){
					return false;
				}
			}
			if(i == 18){
				if(!isCP(document.forms[0].elements[18])){
					return false;
				}
			}
		}else if(document.forms[0].elements[i].type == 'select-one'){
			if(document.forms[0].elements[i].value == 0 && campo[i] != ''){
				alert("Debe seleccionar "+campo[i]);
				document.forms[0].elements[i].focus();
				return false;
			}
		}
	}
	form.submit();
}
/************************************************************************************************/
function salvar_empresa2(form){
	var campo = new Array(
						  "Razon Social","Giro","Nombre","Apellido","E-mail","Contraseña","","Telefono","","Calle","No exterior",
						  "","Estado","Municipio","Colonia","","",""
					);
	for (i=0;i<document.forms[0].elements.length;i++) {
		if(document.forms[0].elements[i].type == 'text' || document.forms[0].elements[i].type == 'textarea' || document.forms[0].elements[i].type == 'password'){
			if(document.forms[0].elements[i].value == "" && campo[i] != ''){
				alert("El campo "+campo[i]+" es obligatorio");
				document.forms[0].elements[i].focus();
				return false;
			}
			if(i == 4){
				if(!isEmailAddress(document.forms[0].elements[4])){
					return false;
				}
			}
			if(i == 7){
				if(!validarNumero(document.forms[0].elements[7],campo[7])){
					return false;
				}
			}
			if(i == 10){
				if(!validarNumero(document.forms[0].elements[10],campo[10])){
					return false;
				}
			}
			if(i == 16 && document.forms[0].elements[16].value != ''){
				if(!isCP(document.forms[0].elements[16])){
					return false;
				}
			}
		}else if(document.forms[0].elements[i].type == 'select-one'){
			if(document.forms[0].elements[i].value == 0 && campo[i] != ''){
				alert("Debe seleccionar "+campo[i]);
				document.forms[0].elements[i].focus();
				return false;
			}
		}
	}
	form.submit();
}
/************************************************************************************************/
function salvar_vacante(form){
	var campo = new Array(
						  "Empresa","Nombre","","Descripcion","la Zona Laboral","el Area de Interes","Puesto","","Vigencia (dia)","Vigencia (mes)","Vigencia (año)","Urgente","Urgente","el Genero",
						  "","","el Estado civil","","","","","","","","",
						  "Propuesta econimica","Horario de trabajo","","","","","","","","","",""
					);
	for (i=0;i<document.forms[0].elements.length;i++) {
		if(document.forms[0].elements[i].type == 'text' || document.forms[0].elements[i].type == 'textarea'){
			if(document.forms[0].elements[i].value == "" && campo[i] != ''){
				alert("El campo "+campo[i]+" es obligatorio");
				document.forms[0].elements[i].focus();
				return false;
			}
			/*if(i == 35){
				if(Number(document.forms[0].elements[i].value) != 100){
					alert("El "+campo[34]);
					return false;
				}
			}*/
		}else if(document.forms[0].elements[i].type == 'select-one'){
			if(document.forms[0].elements[i].value == 0  && campo[i] != ''){
				alert("Debe seleccionar "+campo[i]);
				document.forms[0].elements[i].focus();
				return false;
			}
		}
	}
	form.submit();
}
/************************************************************************************************/
function calc_percent(){
	var total=0;
	for (i=1;i<=10;i++) {
		total += Number(document.getElementById('p_'+i).value);
	}
	document.getElementById('pretenciones').value = total;
	if(total > '100') alert('El porcentaje ha sido rebasado !');
}
/************************************************************************************************/
function init(){
	var items = document.getElementsByTagName("div");
	for (i=0; i<items.length; i++){
		if (items[i].className == "acoordion"){
			items[i].style.display = 'none';
		}
	}
}
/************************************************************************************************/
function loadCity(id){
	ajax=nuevoAjax();
	ajax.open("POST", "ciudad.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4){
			document.getElementById('ciudad').innerHTML = ajax.responseText;
		}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send("id="+id);
}
/************************************************************************************************/