function cambiarIdioma(formularioIdioma, lang, url){ 
formularioIdioma.lang.value=lang; formularioIdioma.url.value=url; 
formularioIdioma.submit(); }

var isIE = (window.navigator.appName == "Microsoft Internet Explorer"); // Allow us to know if the browser is Internet Explorer.	
/*************************************************/
//Funciones utilizadas para la capa de espera
function centerWait(){
		var oBody = document.body;
		var topWindow = oBody.clientHeight;
		var leftWindow = oBody.clientWidth;
		var obj = document.getElementById("waitWindow");
		with(obj)
		{
			style.top= (topWindow/2) -40;
			style.left = (leftWindow/2)-100;		
		}		
}
function showWait() {
	var obj = top.document.getElementById("waitWindow");
	if (isIE) {
		obj.style.display="inline";
	} else {
		obj.style.visibility ="visible";
	}		
}	
function hideWait() {
	var obj = top.document.getElementById("waitWindow");
	if (isIE) {
		obj.style.display="none";
	} else {
		obj.style.visibility ="collapse";
	}		
}
// para verificar si el email es correcto
function isEmailAddr(email)
{
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)){
		return true;	
  }else{
		return false;
  }
}
//Contador de caracteres para el textarea manejado por el tinyMCE (funciona un poco distinto del anterior)
function contarTextArea(idEntrada,idSalida,texto,caracteres,htmlcode) {	
  var entradaObj=document.getElementById(idEntrada);  
  var salidaObj= document.getElementById(idSalida);  
  var longitud=caracteres - htmlcode.length;
  if(longitud <= 0) {	
  	salidaObj.className="mensajeContadorLimite";
    //alert("Ha sobrepasado el número de caracteres permitido. Por favor, intente abreviar su contenido");
    // texto tiene el valor por ejemplo: '{CHAR}caracteres (max 50)'
    entradaObj.value=entradaObj.value.substr(0,caracteres); // para el textarea que no admite un maxlength 
  } else {
  	salidaObj.className="mensajeContador";
  }
  salidaObj.innerHTML = texto.replace("{CHAR}",longitud);  
}

//Contador de caracteres.
function contar(idEntrada,idSalida,texto,caracteres) {
	// evento en el input correspondiente -> onkeyup="Contar('presidente','mensajeContador','{CHAR} caracteres de 100',100)"
  var entradaObj=document.getElementById(idEntrada);  
  var salidaObj= document.getElementById(idSalida);  
  var longitud=caracteres - entradaObj.value.length;
  if(longitud <= 0) {	
  	salidaObj.className="mensajeContadorLimite";
    //alert("Ha sobrepasado el número de caracteres permitido. Por favor, intente abreviar su contenido");
    // texto tiene el valor por ejemplo: '{CHAR}caracteres (max 50)'
    entradaObj.value=entradaObj.value.substr(0,caracteres); // para el textarea que no admite un maxlength 
  } else {
  	salidaObj.className="mensajeContador";
  }
  salidaObj.innerHTML = texto.replace("{CHAR}",longitud);  
}

function mostrarEsperaMenu(plantilla){
	showWait();
	setTimeout("window.location.href='" + plantilla + "'",1000);
}

function cambiarVista(elemento){
// se usa para cambiar la visualización de un elemento: si está oculto se desoculta y viceversa
// se basa en el uso del atributo style.display	
	var isIE = (window.navigator.appName == "Microsoft Internet Explorer"); // Allow us to know if the browser is Internet Explorer.
	if (isIE) {		
		if (elemento.style.display == 'none'){
			elemento.style.display = 'block';			
		} else {
			elemento.style.display = 'none';			
		}		
	} else { // Firefox						
			if (elemento.style.display == 'none'){ // por defecto el display está puesto a none para IE (pero esto interfiere con Firefox así que lo establecemos al valor por defecto)
				elemento.style.display= '';
			}
			if (elemento.style.visibility == ''){	// por defecto elemento.style.visibility = "" así que en el elemento html hay que ponerlo a collapse 
				elemento.style.visibility = 'collapse';
			}
			if (elemento.style.visibility == 'collapse'){				
				elemento.style.visibility= 'visible';
			} else {										
				elemento.style.visibility= 'collapse';
			}
	}
}

// funciones de validación de campos del formulario
function validate_required(field,alerttxt)
{
	with (field){
		if (value==""){
			alert(alerttxt);
			return false;
		}
			else {
				return true;
		}
	}
}
function isScriptTag(index,textValue){
	// el script problemático es <script> y tiene 8 caracteres
	var i=index;
	var end= index+8;
	var text = textValue.toLowerCase();
	if (end <= textValue.length){
		if ((textValue.charAt(i) == "<") && (textValue.charAt(i+1) == "s") && (textValue.charAt(i+2) == "c") && (textValue.charAt(i+3) == "r") && (textValue.charAt(i+4) == "i") && (textValue.charAt(i+5) == "p") && (textValue.charAt(i+6) == "t") && (textValue.charAt(i+7) == ">")){
			return true;
		}
	}
	return false; 
}

function validate_allowed(field){
	with (field){
		for (i=0; i <= value.length; i++){
			if ((value.charAt(i) == "\\") || (value.charAt(i) == "%")|| (value.charAt(i) == "*") || (value.charAt(i) == ";") || (value.charAt(i) == "$")){
				return false;
			}
			if (isScriptTag(i,value)){
				return false;
			}
		}
	}
	return true;	
}

var mensajeSeguridad = "El valor no puede contener los caracteres por razones de seguridad \\,%,*,;,$, ni sentencias <script>. Por favor, use otros caracteres";