function abreventana(pagina){
  window.open(pagina,"Aviso");
  return false;
}

function abreventana_chica(pagina){
  window.open(pagina,"Usuario",'width=600, height=500, resizable=1, scrollbars = 1');
  return false;
}

function abreventana_mediana(pagina){
  window.open(pagina,"Usuario",'width=750, height=500, resizable=1, scrollbars = 1');
  return false;
}

function ventana_usuario(pagina){
  window.open(pagina,"Usuario",'width=500, height=500, resizable=1, scrollbars = 1');
  return false;
}

function ventana_consultoras(pagina){
  window.open(pagina,"Usuario",'width=500, height=500, resizable=1, scrollbars = 1');
  return false;
}

function validar_oferta(){
	var string = "Se han detectado los siguientes errores en en formulario: \n";
	error = 0;
	if (document.getElementById('cargo').value == "" || 
		document.getElementById('cargo').value == "Ingrese cargo") {
		string = string + "Ingrese el cargo.\n";
		error = 1;
	}
	if (document.getElementById('cantidad_puestos').value == "" || 
		document.getElementById('cantidad_puestos').value == "Cantidad de puestos") {
		string = string + "Ingrese cantidad de puestos.\n";
		error = 1;
	}else{
		if (!EsNumerico(document.getElementById('cantidad_puestos'),0)){
			string = string + "Ingrese una cantidad de puestos valida.\n";
			error = 1;
		}	
	}
	
	var elementos = document.getElementsByName('tipo_servicio');
	for (var i=0;  i<elementos.length; i++){
		if (elementos[i].value == 'calif' && elementos[i].checked){
			var cons = 0;
			var elementos = document.getElementsByName('consultora');
			for (var i=0;  i<elementos.length; i++){
				if (elementos[i].checked) {cons = 1;}
			}
			if (!cons) {
				string = string + "Ingrese consultora.\n";
				error = 1;
			}
		}//fin if servicio calif
	}//fin for tipo_servicio
	

	if (error) {alert(string); return false;}
}//fin validar_oferta

function validar_contacto(){
	var string = "Se han detectado los siguientes errores en en formulario: \n";
	error = 0;
	if (vacio('nombre')) {
		string = string + "Ingrese el nombre.\n";
		error = 1;
	}
	if (vacio('email')) {
		string = string + "Ingrese el email.\n";
		error = 1;
	}else{
		if (!EsMail(document.getElementById('email'),0)){
			string = string + "Ingrese un email valido.\n";
			error = 1;
		}		
	}
	
	if (error) {alert(string); return false;}
	else return true;
}//fin validar_contacto

function validar_empresa(){
	var string = "Se han detectado los siguientes errores en en formulario: \n";
	error = 0;
	if (document.getElementById('nombre').value == "" || 
		document.getElementById('nombre').value == "Ingrese el nombre") {
		string = string + "Ingrese el nombre.\n";
		error = 1;
	}
	if (document.getElementById('usuario').value == "" || 
		document.getElementById('usuario').value == "Ingrese el usuario") {
		string = string + "Ingrese el usuario.\n";
		error = 1;
	}
	if (document.getElementById('contrasena').value == "") {
		string = string + "Ingrese la contrasena.\n";
		error = 1;
	}
	if (!vacio('ruc')) {
		if (!EsNumerico(document.getElementById('ruc'),0)){
			string = string + "Ingrese un RUC valido.\n";
			error = 1;
		}	
	}
	if (document.getElementById('contacto').value == "" || 
		document.getElementById('contacto').value == "Ingrese el contacto") {
		string = string + "Ingrese el contacto.\n";
		error = 1;
	}
	if (document.getElementById('telefono').value == ""|| 
		document.getElementById('telefono').value == "Ingrese el telefono") {
		string = string + "Ingrese el telefono.\n";
		error = 1;
	}else{
		if (!EsNumerico(document.getElementById('telefono'),0)){
			string = string + "Ingrese un telefono valido.\n";
			error = 1;
		}	
	}
	if (document.getElementById('email').value == ""|| 
		document.getElementById('email').value == "Ingrese el email") {
		string = string + "Ingrese el email.\n";
		error = 1;
	}else{
		if (!EsMail(document.getElementById('email'),0)){
			string = string + "Ingrese un email valido.\n";
			error = 1;
		}		
	}
	if (!document.getElementById('acepto_reglamento').checked) {
		string = string + "\n Debe aceptar los terminos del reglamento.\n";
		error = 1;
	}
	if (error) {alert(string); return false;}
}//fin validar_empresa()

function validar_empresa_edit(){
	var string = "Se han detectado los siguientes errores en en formulario: \n";
	error = 0;
	if (document.getElementById('nombre').value == "") {
		string = string + "Ingrese el nombre.\n";
		error = 1;
	}
	if (document.getElementById('contrasena_cambiar').value == "1"){
		if (document.getElementById('contrasena').value == "") {
			string = string + "Ingrese la contrasena.\n";
			error = 1;
		}	
	}	
	if (!vacio('ruc')) {
		if (!EsNumerico(document.getElementById('ruc'),0)){
			string = string + "Ingrese un RUC valido.\n";
			error = 1;
		}	
	}
	if (document.getElementById('contacto').value == "")  {
		string = string + "Ingrese el contacto.\n";
		error = 1;
	}
	if (document.getElementById('telefono').value == "") {
		string = string + "Ingrese el telefono.\n";
		error = 1;
	}else{
		if (!EsNumerico(document.getElementById('telefono'),0)){
			string = string + "Ingrese un telefono valido.\n";
			error = 1;
		}	
	}
	if (document.getElementById('email').value == "") {
		string = string + "Ingrese el email.\n";
		error = 1;
	}else{
		if (!EsMail(document.getElementById('email'),0)){
			string = string + "Ingrese un email valido.\n";
			error = 1;
		}		
	}
	if (error) {alert(string); return false;}	
}//fin validar_empresa_edit

function validar_datos_personales(){
	var string = "Se han detectado los siguientes errores en en formulario: \n";
	error = 0;
	if (document.getElementById('direccion').value == "") {
		string = string + "Ingrese la dirección.\n";
		error = 1;
	}
	if (document.getElementById('telefono').value == "") {
		string = string + "Ingrese el telefono.\n";
		error = 1;
	}else{
		if (!EsNumerico(document.getElementById('telefono'),0)){
			string = string + "Ingrese un telefono valido.\n";
			error = 1;
		}	
	}
	if (document.getElementById('email').value == "") {
		string = string + "Ingrese el email.\n";
		error = 1;
	}else{
		if (!EsMail(document.getElementById('email'),0)){
			string = string + "Ingrese un email valido.\n";
			error = 1;
		}		
	}
	
	var i=0;var cCheck=0;
  	var objInput = document.form_datos_personales.getElementsByTagName("input");
  	var lObj = (objInput!=null)? objInput.length : 0;
 	for(i=0;i<lObj;i++){   
    	if ((objInput[i].type=="checkbox")&&(objInput[i].checked)) cCheck++;  
	}
 	if (cCheck > 3){
		string = string + "Seleccione como máximo 3 perfiles.\n";
		error = 1;
	}
	if (error) {alert(string); return false;}
}//fin validar_datos_personales

function validar_formacion(){
	var string = "Se han detectado los siguientes errores en en formulario: \n";
	error = 0;
	if (document.getElementById('centro').value == "Ingrese centro" || document.getElementById('centro').value == "") 	{
		string = string + "Ingrese el centro.\n";
		error = 1;
	}

	if (document.getElementById('tipo').value!='Curso/Seminario'){
		if (document.getElementById('facultad').selectedIndex  == "0") 	{
			string = string + "Ingrese facultad y carrera.\n";
			error = 1;
		}	
	}
	
	if (error) {alert(string); return false;}
}//fin validar_formacion

function validar_experiencia(){
	cls_defaultvalue();
	return true;
}//fin validar_experiencia

function cls_defaultvalue(){
	var frm = document.form;
	for (i=0;i<frm.elements.length;i++){
		if(frm.elements[i].value==frm.elements[i].defaultValue)
			if (frm.elements[i].name.substr(0,1) != "_")
	        	cls(frm.elements[i].name);
	}
   return true
}//cls_defaultvalue

function validar_usuario(){
	var string = "Se han detectado los siguientes errores en en formulario: \n";
	error = 0;
	if (document.getElementById('email').value == "") {
		string = string + "Ingrese el email.\n";
		error = 1;
	}
	if (vacio('contrasenia')||vacio('contrasenia2')) {
		string = string + "Ingrese contrasena y repita la contrasena.\n";
		error = 1;
	}else{
		if (document.getElementById('contrasenia').value != document.getElementById('contrasenia2').value){
			string = string + "La contrasena y repetir la contrasena deben coincidir.\n";
			error = 1;
		}
	}
	if (vacio('nombre')) {
		string = string + "Ingrese el nombre.\n";
		error = 1;
	}
	if (vacio('apellido')) {
		string = string + "Ingrese el apellido.\n";
		error = 1;
	}
	if (nosel('id_pais')) {
		string = string + "Ingrese el pais.\n";
		error = 1;
	}
	if (error) {alert(string); return false;}
	else return true;
}

function change_visibility(campo){
	if (document.getElementById(campo).style.visibility == "visible" ||
		document.getElementById(campo).style.display == "block")
		hide(campo);
	else show(campo);
}//fin change_visibility

function hide(campo){
	document.getElementById(campo).style.visibility = "hidden"
	document.getElementById(campo).style.display = "none"
}//fin change_visibility

function show(campo){
		document.getElementById(campo).style.visibility = "visible";
		document.getElementById(campo).style.display = "block";
}//fin change_visibility

function vacio(campo){
	valor = document.getElementById(campo).value;
	if (valor == "" || valor == document.getElementById(campo).defaultValue)
		return 1;
	else return 0;
} // vacio

function nosel(campo){
	valor = document.getElementById(campo).selectedIndex;
	if (valor == 0) return 1; else return 0;
}//fin nosel

function cls(e){
 	document.getElementById(e).value='';
}// cls

function wopen(thislink){
  window.open(thislink,"w");
  return false;
}// wopen

