// JavaScript Document
/*-----------------------Para abrir ventanas---------------------------------*/
function abrir(valor) {
  window.open(valor,'','width=500,height=400,menubar,resizable,toolbar,titlebar,status,directories,location,scrollbars=yes');
}
function abrir1(valor) {
  window.open(valor,'','width=805,height=645,menubar,resizable,toolbar,titlebar,status,directories,location,scrollbars=yes');
}
/*---------------------------------------------------------------------------*/

var button_state=0;
var over_win=false;
function Init()
{

/*--------------------  Boton para desplegar el tiempo --------------------- */

/*var obj = getObj('button');
var obj_win= getObj('window');
var obj_container= getObj('container_total');
obj_win.style.visibility="hidden";// Hide when onload
      obj.onmouseover=function() { over_win=true;   }
	   obj.onmouseout=function() { over_win=false;   }
      obj.onclick=function() {   
	        Window_W ();    
	       }//onclick function	
	 obj_container.onclick=function() {  				
          if (over_win==false )	{				  
				     obj_win.style.visibility="hidden";
					 obj.src=path + "img/btn_open.gif";
					 obj1.style.visibility="visible"; // listbox
				     button_state = 0; 
					}	
	       }//onclick function	
		   
function Window_W (){
 if (button_state==0 ) {					
				    obj_win.style.visibility="visible"; //win tiempo
					if (getObj('skin_box')) obj1.style.visibility="hidden"; // listbox
					obj.src=path + "img/btn_close.gif";
				    button_state = 1; 
					} else 	{				  
				     obj_win.style.visibility="hidden";
					 obj.src=path + "img/btn_open.gif";
					if (getObj('skin_box')) obj1.style.visibility="visible"; // listbox
				    button_state = 0; 
					}	
					
	 }    */   
/* --------------------Para el box de los temas -------------------  */
var obj1;
if (getObj('skin_box')){
	   obj1 = getObj('skin_box');
         obj1.onchange=function() {  document.temas.submit(); } 
             }
	           		  
 }//End Init
 /*-------------------PAra el mapa del sitio--------------------------*/
 var button_state1=0;
var over_win1=false;

 function Init1()
{

/*--------------------  Boton para desplegar el tiempo --------------------- */

/*var obj = getObj('button');
var obj_win1= getObj('window');
var obj_container= getObj('container_total');
obj_win1.style.visibility="hidden";// Hide when onload
      obj.onmouseover=function() { over_win=true;   }
	   obj.onmouseout=function() { over_win=false;   }
      obj.onclick=function() {   
	        Window_W1 ();    
	       }//onclick function	
	 obj_container.onclick=function() {  				
          if (over_win==false )	{				  
				     obj_win1.style.visibility="hidden";
					 obj.src=path + "img/btn_open.gif";
					 //obj1.style.visibility="visible"; // listbox
				     button_state1 = 0; 
					}	
	       }//onclick function	
		   
function Window_W1 (){
 if (button_state1==0 ) {
				    obj_win1.style.visibility="visible"; //win tiempo
					//if (getObj('skin_box')) obj1.style.visibility="hidden"; // listbox
					obj.src=path + "img/btn_close.gif";
				    button_state1 = 1; 
					} else 	{				  
				     obj_win1.style.visibility="hidden";
					 obj.src=path + "img/btn_open.gif";
					//if (getObj('skin_box')) obj1.style.visibility="visible"; // listbox
				    button_state1 = 0; 
					}	
					
	 } */      
/* --------------------Para el box de los temas -------------------  */
/*var obj1;
if (getObj('skin_box')){
	   obj1 = getObj('skin_box');
         obj1.onchange=function() {  document.temas.submit(); } 
             }*/
	           		  
 }//End Init1

/* --------------------------------------------------------------------*/
/*Get object */
function getObj(objID)
	{
	if (document.getElementById) {return document.getElementById(objID);}
	else if (document.all) {return document.all[objID];}
	else if (document.layers) {return document.layers[objID];}
	}
	
	
	// DEFINE VARIABLES

// whitespace characters
var whitespace = " \t\n\r";
var defaultEmptyOK = false

var intLimit = 15

function isEmpty(s){
// Check whether string s is empty.
	 return ((s == null) || (s.length == 0))
}

// Returns true if string s is empty or 
// whitespace characters only.

function isWhitespace(s)

{	 var i;

		// Is s empty?
		if (isEmpty(s)) return true;

		for (i = 0; i < s.length; i++)
		{	 
		// Check that current character isn't whitespace.
		var c = s.charAt(i);

		if (whitespace.indexOf(c) == -1) return false;
		}

		// All characters are whitespace.
		return true;
}

// E-mail Validation
function isEmail (s)
{	 if (isEmpty(s)) 
			 if (isEmail.arguments.length == 1) return defaultEmptyOK;
			 else return (isEmail.arguments[1] == true);
	 
		// is s whitespace?
		if (isWhitespace(s)) return false;
		
		// there must be >= 1 character before @, so we
		// start looking at character position 1 
		// (i.e. second character)
		var i = 1;
		var sLength = s.length;

		// look for @
		while ((i < sLength) && (s.charAt(i) != "@"))
		{ i++
		}

		if ((i >= sLength) || (s.charAt(i) != "@")) return false;
		else i += 2;

		// look for .
		while ((i < sLength) && (s.charAt(i) != "."))
		{ i++
		}

		// there must be at least one character after the .
		if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
		else return true;
}	


/* Efemerides*/

function UpdateMonths()
{
document.form_efemerides.submit(); 
}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

function valida_seleccion(opinionv, selection)
{
  var ok1 = false;
  //alert(selection)
  var sel = document.getElementById(selection)
  //alert(sel.options.length)
  for (var j = 0;j < sel.options.length;j++)
  {
   	if ((sel.options[j].selected)&&(sel.options[j].value!=0))
   	{ 
	   
	   ok1 = true;
	   break;
	}
  }
  return ok1;
}

function ValidaOpinion(opinionv){
	
		if (valida_seleccion(opinionv,'edad')==false) {
			alert("El grupo de edad es un dato obligatorio, por favor complete la información")
			document.forms.opinionv.edad.focus();
			return false;	
		}
		if(valida_seleccion(opinionv,'cargo')==false)
		{
			alert('La categoría laboral es un dato obligatorio, por favor complete la información')
			document.forms.opinionv.cargo.focus()
			return false	
		}
		else if(valida_seleccion(opinionv,'nivel')==false){
				alert('El nivel de escolaridad es un dato obligatorio, por favor complete la información')
				document.forms.opinionv.nivel.focus()
				return false
		}
		return true

}
function ValidaRegistro(registro){
	/*alert('entraaaaaaaa')*/
	if(trim(document.forms.registro.login.value)=="")
	  {
		alert("Introduzca su identificador de usuario.");
		document.forms.registro.login.focus();
		return (false);
	  }
	    if(trim(document.forms.registro.pass.value)=="")
	  {
		alert("Introduzca su clave de acceso.");
		document.forms.registro.pass.focus();
		return (false);
	  }
	    if(trim(document.forms.registro.newpass.value)=="")
	  {
		alert("Debe confirmar la clave.");
		document.forms.registro.newpass.focus();
		return (false);
	  }
	    if(document.forms.registro.newpass.value != document.forms.registro.pass.value)
	  {
		alert("Las claves deben coincidir, por favor rectifique su clave.");
		document.forms.registro.pass.focus();
		return (false);
	  }
		if (valida_seleccion(registro,'cateuser')==false) {
			alert("La categoría de usuario a la cual desea pertenecer es un dato obligatorio, por favor complete la información")
			document.forms.registro.cateuser.focus();
			return (false);	
		}

		if(trim(document.forms.registro.correo.value)=='')
		{
			alert('El correo electrónico es un dato obligatorio, por favor complete la información')
			document.forms.registro.correo.focus()
			return (false);	
		}
		else if(!isEmail(document.forms.registro.correo.value)){
				alert('El correo electrónico no está bien conformado, por favor rectifique la información')
				document.forms.registro.correo.focus()
				return (false);
		}
		return (true);

	}
function ValidaEmail(campo){
	var obj = document.getElementById(campo);
	var str = obj.value;

	if(trim(str)=='')
		{
			alert('El correo electrónico es un dato obligatorio, por favor complete la información')
			setTimeout("document.getElementById(campo).focus();",1);
			return (false);	
		}
		else if(!isEmail(document.forms.registro.correo.value)){
				alert('El correo electrónico no está bien conformado, por favor rectifique la información')
				setTimeout("document.getElementById(campo).focus();",1);
				return (false);
		}
		return (true);
	
	}
function ValidaLogin(){		
	var login = document.forms.registro.login.value;
	//var regexp = /\W/;
	//var regexp = new RegExp("\W");
	//var regexp = /[^A-Za-z0-9_]/;
	//alert(login.search(regexp))
	//var cad = login.value
	if(trim(login)=="")
	{
		alert("Introduzca su identificador de usuario.");
		//setTimeout("document.getElementById('login').focus();",1);
		document.forms.registro.login.focus();
		return (false);
	}
	if((login.length > 10)||(login.length < 4)){
		alert("El identificador de usuario debe estar formado por más de 4 y menos de 10 caracteres y está proporcionando: "+login.length+" caracteres.");
		setTimeout("document.getElementById('login').focus();",1);
		//document.registro.login.focus();
		return (false);	
	}
	var regexp = /\W/;
	if(login.search(regexp)!=-1){
		alert("El identificador de usuario contiene caracteres no permitidos.");
		//setTimeout("document.getElementById('login').focus();",1);
		document.forms.registro.login.focus();
		return (false);	
	}
}

function ValidaClave(){		
	var clave = document.forms.registro.pass.value;
	if(trim(clave)=="")
	{
		alert("Introduzca su clave de acceso.");
		setTimeout("document.getElementById('pass').focus();",1);
		//document.getElementById('login').focus();
		return (false);
	}
	if((clave.length > 10)||(clave.length < 4)){
		alert("La contraseña debe estar formada por más de 4 y menos de 10 caracteres y está proporcionando: "+clave.length+" caracteres.");
		setTimeout("document.getElementById('pass').focus();",1);
		//document.registro.login.focus();
		return (false);	
	}
	var regexp1 = /\W/;
	if(clave.search(regexp1)!=-1){
		alert("La clave contiene caracteres no permitidos.");
		setTimeout("document.getElementById('pass').focus();",1);
		//document.registro.login.focus();
		return (false);	
	}
}

function ValidaClave1(){
	var clave = document.forms.registro.pass.value;
	var clave1 = document.forms.registro.newpass.value;
	if(trim(clave1)=="")
	{
		alert("Introduzca su clave de acceso.");
		setTimeout("document.getElementById('newpass').focus();",1);
		//document.getElementById('login').focus();
		return (false);
	}
	if((clave1.length > 10)||(clave.length < 4)){
		alert("La contraseña debe estar formada por más de 4 y menos de 10 caracteres y está proporcionando: "+clave1.length+" caracteres.");
		setTimeout("document.getElementById('newpass').focus();",1);
		//document.registro.login.focus();
		return (false);	
	}
	if(clave!=clave1){
		alert("Las contraseñas deben coincidir");
		setTimeout("document.getElementById('newpass').focus();",1);
		//document.registro.login.focus();
		return (false);		
	}
	var regexp2 = /\W/;
	if(clave.search(regexp2)!=-1){
		alert("La contraseña de confirmación contiene caracteres no permitidos.");
		setTimeout("document.getElementById('newpass').focus();",1);
		//document.registro.login.focus();
		return (false);	
	}	}
	
	
function ValidaN(nom,maxi,mini,campo,regexp,obligatorio){
	var obj = document.getElementById(nom);
	var str = obj.value;
	if(obligatorio){
		if(trim(str)=="")
		{
			alert("Introduzca el valor del campo: "+campo+".");
			setTimeout("document.getElementById(nom).focus();",1);
			//document.getElementById('login').focus();
			return (false);
		}
	}
	if((trim(str)!='')&&((str.length > maxi)||(str.length < mini))){
		alert("El campo: "+campo+" debe estar formado por más de "+mini+" y menos de "+maxi+" caracteres y está proporcionando: "+str.length+" caracteres.");
		setTimeout("document.getElementById(nom).focus();",1);
		//document.registro.login.focus();
		return (false);	
	}
	//var regexp2 = '/[^A-Za-züÁÉÍÓÚÑÜáéíóúñ/\s/.]/';
	//alert(regexp)
	//alert(str.search(regexp))
	if(str.search(regexp)!=-1){
		//if(!(str.match(regexp)))
		alert("El campo: "+campo+" contiene caracteres no permitidos.");
		setTimeout("document.getElementById(nom).focus();",1);
		//document.registro.login.focus();
		return (false);	
	}
}
function ValidaN1(nom,maxi,mini,campo,regexp,obligatorio){
	//var obj = document.getElementById(nom);
	var str = nom.value;
	//alert(str)
	if(obligatorio){
		if(trim(str)=="")
		{
			alert("Introduzca el valor del campo: "+campo+".");
			setTimeout("document.getElementById(nom).focus();",1);
			//document.getElementById('login').focus();
			return (false);
		}
	}
	if((trim(str)!='')&&((str.length > maxi)||(str.length < mini))){
		alert("El campo: "+campo+" debe estar formado por más de "+mini+" y menos de "+maxi+" caracteres y está proporcionando: "+str.length+" caracteres.");
		setTimeout("document.getElementById(nom).focus();",1);
		//document.registro.login.focus();
		return (false);	
	}
	//var regexp2 = '/[^A-Za-züÁÉÍÓÚÑÜáéíóúñ/\s/.]/';
	//alert(regexp)
	if(str.search(regexp)!=-1){
		alert("El campo: "+campo+" contiene caracteres no permitidos.");
		setTimeout("document.getElementById(nom).focus();",1);
		//document.registro.login.focus();
		return (false);	
	}
}
