/* menu cabecera */

	var itemSelected = null;
	var itemOpened = null;
	
	function openMnu(idName)
	{
		var lastSelected = null;
		if (itemSelected != null){
			itemSelected.className = 'mnuObject';
			if (itemOpened != null){
				itemOpened.className = 'noVisible';
			}
			lastSelected = itemSelected;
			itemSelected = null;
			itemOpened = null;
		}
		var objMnu = document.getElementById(idName);
		if (objMnu != lastSelected){
			objMnu.className = 'mnuObject MenuSelected';
			itemSelected = objMnu;
			var objSubMnu = document.getElementById(idName + 'Sub');
			if (objSubMnu != null){
				objSubMnu.className = 'visible';
				itemOpened = objSubMnu;
			}
		}
	}

/* fin menu cabecera */

/********************************************************/
/** NOQUOTATIONMARKS									*/
/**		Deja escribir solamente caracteres numéricos	*/
/**  	Se llama desde el onKeyPress()					*/
/** S: true or false									*/
/********************************************************/
 
function NoQuotationMarks(){
	if (event.keyCode == 39){
		//event.returnValue = false;
		event.keyCode = 180
	}
}


function changeClass(objName, newClass)
{
	var obj = document.getElementById(objName);
	obj.className = newClass;
}

function OpenWindow(url, w, h, sc)
{
	if (sc!="1") sc="no"; else sc="yes";
	var l = parseInt((screen.width - w)/2);
	var t = parseInt((screen.height - h)/2);
	var n = parseInt(Math.random() * 1000);
	var nw = window.open(url, "NewWindow" + n, "width=" + w + "px,height=" + h + "px,left=" + l + "px,top=" + t + "px,scrollbars="+sc);
}

function MaxLongField(field, max){
	var num = "" + field.value;
	var llarg = num.length;
	if (llarg <= max){
	   return true;
	}else{
	   alert("el maximo de caracteres establecidos para este campo es de " + max);
	   field.value = field.value.substring(0, max);
	}
}



//replaceSubstring("hellothere", "l", "x") = "hexxothere"
function replaceSubstring(inputString, fromString, toString) {
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function

function selIdioma(idioma,pag) {
	document.location.href=pag + "?idioma=" + idioma;
}

/*Funcin email check que comprueba si el email escrito es correcto*/
function emailCheck (elem) {
   
   var emailStr=elem.value
   var emailPat=/^(.+)@(.+)$/
   var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
   var validChars="\[^\\s" + specialChars + "\]"
   var quotedUser="(\"[^\"]*\")"
   var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
   var atom=validChars + '+'
   var word="(" + atom + "|" + quotedUser + ")"
   var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
   var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
   
   var matchArray=emailStr.match(emailPat)
   if (matchArray==null) {
   	alert("La entrada de e-mail parece ser incorrecta (chequee @ y .'s)")
   	return false
   }
   var user=matchArray[1]
   var domain=matchArray[2]
   
   if (user.match(userPat)==null) {
       alert("El nombre de usuario parace no ser correcto.")
       return false
   }
   
   var IPArray=domain.match(ipDomainPat)
   if (IPArray!=null) {
   	  for (var i=1;i<=4;i++) {
   	    if (IPArray[i]>255) {
   	        alert("Direccion IP no valida!")
   		return false
   	    }
       }
       return true
   }
   
   var domainArray=domain.match(domainPat)
   if (domainArray==null) {
   	alert("El nombre de dominio parace no ser correcto.")
       return false;
   }
   
   var atomPat=new RegExp(atom,"g")
   var domArr=domain.match(atomPat)
   var len=domArr.length
   if (domArr[domArr.length-1].length<2 || 
       domArr[domArr.length-1].length>3) {
      alert("La direccion de correo debe acabar en 3 letras de dominio o 2 de un pais.");
      return false;
   }
   
   if (len<2) {
      var errStr="Esta direccion es desconocida como IP!"
      alert(errStr);
	  return false;
   }

}