/* 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 */



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 NoQuotationMarks(){
	if (event.keyCode == 39){
		//event.returnValue = false;
		event.keyCode = 180
	}
}

function cambiarPagina(val,tipo){
	e = window.event;
	if (e.keyCode == 13){
		var total = eval("document.forms[0].totalp" + tipo + ".value");
		var pag = eval("document.forms[0].pagina" + tipo + ".value");
		if (parseInt(pag) > 0 && parseInt(pag) <= parseInt(total)){
			document.forms[0].pag.value = val;
			document.forms[0].submit();
		}else{
			var pagObj = eval("document.forms[0].pagina" + tipo);
			pagObj.value = document.forms[0].pag.value;
		}
	}
}