ns4 = (document.layers) ? 1 : 0;
ie = (document.all) ? 1 : 0;

function showLayer(layerName) {
	if (ie)
		document.all[layerName].style.visibility = 'visible';
	else 
		document.layers[layerName].visibility = 'show';
}

function hideLayer(layerName) {
	if (ie)
		document.all[layerName].style.visibility = 'hidden';
	else 
		document.layers[layerName].visibility = 'hide';
}

function centerLayer(layerName) {
	if (ie) {
		layertocenter=document.all[layerName];
		layertocenter.style.left=document.body.scrollLeft+document.body.clientWidth/2-layertocenter.offsetWidth/2;
		layertocenter.style.top=document.body.scrollTop+document.body.clientHeight/2-layertocenter.offsetHeight/2;
	} else {
		layertocenter=document.layers[layerName];
		layertocenter.left=pageXOffset+window.innerWidth/2-layertocenter.document.width/2;
		layertocenter.top=pageYOffset+window.innerHeight/2-layertocenter.document.height/2;
	}
}

function centerAndShowLayer(layerName) {
	var el = cbeGetElementById(layerName);
	if (el) {
		var theLayer = el.cbe;
		if (theLayer) {
			theLayer.moveTo('center');	
			return theLayer;
		}
	}
}

function centerLayerAndMoveToY(layerName, y) {
	var centeredCBELayer = centerAndShowLayer(layerName);
	if (centeredCBELayer) {
		centeredCBELayer.moveTo('n', y);
		return centeredCBELayer;
	}
}

String.prototype.trim = function (){
	return this.ltrim().rtrim();
}

String.prototype.ltrim = function (){
	var i = 0;
	for(i = 0; i < this.length; i++){
		if(this.charAt(i) != ' ')
			break;
	}
	return this.substring(i, this.length);
}

String.prototype.rtrim = function (){
	var i = 0;
	for(i = this.length; i > 0; i--){
		if(this.charAt(i) != ' ')
			break;
	}
	return this.substring(0, i);
}

function isnumbetween (s, min, max)
{
	expression1 = (s >= (min != null ? min : Number.MIN_VALUE));
	expression2 = (s <= (max != null ? max : Number.MAX_VALUE));
	return (expression1 && expression2);
}

function islenbetween (s, min, max)
{
	return (isnumbetween(s.length, (min != null ? min : 0), max));
}

function HowManyCBChecked(f)
{
	var CBChecked = 0;
	for (var i = 0; i < f.elements.length; i++)
	{
		var e = f.elements[i];
		if ((e.type == 'checkbox') && (e.name != 'allbox') && (e.checked))
	    	CBChecked++;
	}
	return CBChecked;
}

/* Highlights the parent TR Element of the TD ROW from where this function is called (Change the className to "selected" */
function TR_hL(E) {
	if (E.tagName && E.tagName != "TR" && (E.parentElement || E.parentNode)) {
		if (ie)
			while (E.tagName != "TR")
				E = E.parentElement;
		else
			while (E.tagName != "TR")
				E = E.parentNode;
		/*for use "TR.selected" start */
		E.className = "selected";
		/*for use "TR.selected" end*/

		/* for unse TD.selected  Start 	
		if (E.getElementsByTagName) {
			var tdTags = E.getElementsByTagName("TD");	
			for (var i = 0; i < tdTags.length; i++) {
				if (i>0 && i<tdTags.length-1)
					tdTags.item(i).className = "selected";
			}
		}
		 for unse TD.selected  end */	
	}
}

/* Downlights the parent TR Element of the TD ROW from where this function is called (Clears the className) */
function TR_dL(E) {
	if (E.tagName && E.tagName != "TR" && (E.parentElement || E.parentNode)) {
		if (ie)
			while (E.tagName != "TR")
				E = E.parentElement;
		else
			while (E.tagName != "TR")
				E = E.parentNode;
		/*for use "TR.selected" start*/
		E.className = "";
		/*for use "TR.selected" end*/	
				
		/* for unse TD.selected  Start 
		if (E.getElementsByTagName) {
			var tdTags = E.getElementsByTagName("TD");		
			for (var i = 0; i < tdTags.length; i++) {
				if (i>0 && i<tdTags.length-1)
					tdTags.item(i).className = "";
			}
		}
		for unse TD.selected  end */		
	}
}

function setfocusonfirstformelement(frm) {		
	if (frm) {
		var e = frm.fieldToFocus;		
		var existsFieldToFocus = (e);
		existsFieldToFocus = (existsFieldToFocus && (e.value != ''));
		existsFieldToFocus = (existsFieldToFocus && frm.elements[e.value]);		
		if (existsFieldToFocus) {
			var f = frm.elements[e.value];			
			if (f.type == 'hidden')
				return;
			else if (f.type) {		
				f.focus();
//				if (f.type=='text')
//					f.select();				
			}else
				if (f.length)
					f[0].focus();
			e.value = '';
		} else {
			var qelements = frm.elements.length;
			if (qelements > 0)
				for (var i = 0; i < qelements; i++) {
					var f = frm.elements[i];
					// hidden elements can't get focus;
					if (f.type && f.type!='hidden') {						
						f.focus();
//						if (f.type=='text')
//							f.select();
						break;
					} else
						if (f.length) {
							f[0].focus();
							break;
						}
				}
		}
	}
}



//inicializa las variables de navegador y S.O.
function setBrowserVars(){
	NS4 = (document.layers) ? true : false;
	IE4 = (document.all);
	ver4 = (NS4 || IE4);
	IE5 = (IE4 && navigator.appVersion.indexOf("5.") != -1);
	NS6 = (document.getElementById && !document.all) ? true : false;
	isMac = (navigator.appVersion.indexOf("Mac") != -1);
	isMenu = (NS4 || (IE4 && !isMac) || (IE5 && isMac));
	isNav = (NS4 || NS6);

	if (!ver4)
		event = null;
}

/* Selecciona estilos de acuerdo al navegador y S.O. */
function setStyleSheets(){
	if (isNav)
		document.write('<link rel="stylesheet" type="text/css" href="./styles/generalNN47.css">')
	else{
		if (isMac)
			document.write('<link rel="stylesheet" type="text/css" href="./styles/generalMac.css">') 
		else
			document.write('<link rel="stylesheet" type="text/css" href="./styles/general.css">') 
	}
}

setBrowserVars();
setStyleSheets();

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function spanishDate(){
                mes = new Array();
                mes[0] = "ENE";
                mes[1] = "FEB";
                mes[2] = "MAR";
                mes[3] = "ABR";
                mes[4] = "MAY";
                mes[5] = "JUN";
                mes[6] = "JUL";
                mes[7] = "AGO";
                mes[8] = "SEP";
                mes[9] = "OCT";
                mes[10] = "NOV";
                mes[11] = "DIC";
                x = new Date();
                d = x.getDate();
                m = x.getMonth();
                a = x.getFullYear();
                document.write(d + " " + mes[m] + " " + a);
}

function RandInt(n) {
	var resnum = (Math.round(Math.random() * (n - 1)) + 1);
 	return resnum.toString();
}


function MM_showHideLayers() {
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) { 
	 obj=MM_findObj(args[i]);
     if (obj != null) {
	     v=args[i+2];
    	 if (obj.style) { obj = obj.style; v = (v=='show')?'visible':(v='hide')?'hidden':v; }
	     obj.visibility=v;
     }
  }	 
}
function getInsideWindowWidth() {
	if (NS4 || NS6) {
		return window.innerWidth
	} else {
		return document.body.clientWidth
	}
}

function getInsideWindowHeight() {
	if (NS4 || NS6) {
		return window.innerHeight
	} else {
		return document.body.clientHeight
	}
}

function AdjustLeft(l,designresw,minx) {
	var w = getInsideWindowWidth();
	if (l > w) {
		return l;
	} else {
		var delta = Math.round((w - designresw) / 2);
	    if (w <= designresw) {
			if (delta < -minx) {
				delta = -minx
			}
		}
		l = l + delta;
		return l
	}
}

function AdjustTop(t,designresh,miny) {
	var h = getInsideWindowHeight();
	if (t > h) {
		return t;
	} else {
		var delta = Math.round((h - designresh) / 2);
	    if (h <= designresh) {
			if (delta < -miny) {
				delta = -miny
			}
		}
		t = t + delta;
		if (NS6) {
			document.getElementById(obj).style.top = t;
		}
		return t;
	}
}

