
/****************************************************************************************/
/* Función     : isWhitespace															*/
/* Descripción : Comprueba si una cadena solo tiene blancos								*/
/* Entrada     : vjl_dato      : cadena origen.											*/
/* Salida      : cadena sin blancos														*/
/****************************************************************************************/
var whitespace = " \t\n\r";
// s es vacio
function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}
// s es vacio o solo caracteres de espacio
function isWhitespace (s)
{   var i;
    if (isEmpty(s)) return true;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        // si el caracter en que estoy no aparece en whitespace,
        // entonces retornar falso
        if (whitespace.indexOf(c) == -1) return false;
    }
    return true;
}


/****************************************************************************************/
/* Función     : fjl_quitarBlancosRep													*/
/* Descripción : Quita los blancos repetidos de una cadena								*/
/* Entrada     : vjl_dato      : cadena origen.											*/
/* Salida      : cadena sin blancos														*/
/****************************************************************************************/
function fjl_quitarBlancosRep(vjl_dato){

	cadena = vjl_dato.split(' ');
	aux = cadena[0];
	for (i=1;i<cadena.length;i++){				
		if (!(cadena[i]=="" && cadena[i-1]=="")){
			if (aux.substr(aux.length-1,1)==" ") {						
				aux = aux + cadena[i];
			}
			else{						
				aux = aux + ' ' + cadena[i];
			}
		}
	}			
	return(aux);		
}


/****************************************************************************************/
/*FUNCIONES DE TRATAMIENTO DE CAPAS (DIVS) E IMÁGENES                                   */
/****************************************************************************************/

function MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}

//AMM
//var HELPER_IFRAME_ID = "IFrmHelper";
//var topDivZIndex = 10000;
// Add dynamic div to the page

// Creating and adding dynamic iframe to the page source.

//Fin AMM

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

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 GetXY(Obj){
  var oTmp = Obj;
  var pt = new Point(0,0);
  do {
  	pt.x += oTmp.offsetLeft;
  	pt.y += oTmp.offsetTop;
  	oTmp = oTmp.offsetParent;
  } while(oTmp.tagName!="BODY");
  return pt;
}

function Point(iX, iY){
	this.x = iX;
	this.y = iY;
}

function MM_showHideLayersExplicacion(){
	var i;
	var p;
	var v;
	var objDiv;
	var objImagen;
	var args = MM_showHideLayersExplicacion.arguments;
	var	NombreDiv = "DivExplicacion";
	var NombreImagen = "ImagenExplicacion";
	var x;
	var y;
	var punto;
	
	for (i=0; i<(args.length-2); i+=3){
		if ((objDiv = MM_findObj(NombreDiv + args[i]))!=null){
			if ((objImagen = MM_findObj(NombreImagen + args[i]))!=null){
				punto = GetXY(objImagen);
				x = punto.x;
				y = punto.y;
				v = args[i + 2];
				if (objDiv.style){
					objDiv = objDiv.style;
					v = (v=='show')?'visible':(v='hide')?'hidden':v;
				}
				objDiv.left = x - 70;
				objDiv.top = y + 30;
				objDiv.visibility = v;
				
			}
		}
	}
}

/****************************************************************************************/
/*OTRAS UTILIDADES                                                                      */
/****************************************************************************************/

function DistribuyeCapasSup()
{
	var strIdsCapas;
	var strIdsTDs;
	var ArrayIdsCapas;
	var ArrayIdsTDs;
	var i;
	var objCapa;
	var objTD;
	var pos;
	
	var auxiliar;
	
	strIdsCapas = document.getElementById("capas_menus_sup");
	strIdsTDs = document.getElementById("tds_menus_sup");
	
	/*alert(window.screen.height);
	alert(window.screen.width);
	alert(window.screen.availWidth);
	alert(window.outerWidth);
	alert(window.innerWidth);*/
    
    var anchoVent=document.all?document.body.offsetWidth:window.innerWidth;	
    
    //alert(anchoVent);
    		
	auxiliar = ((anchoVent-780)>>1)-14;
	if (auxiliar < 0) {
		auxiliar = 0;
	}
	//alert('DistribuyeCapasSup');
		
	pos = 0;
	//pos = auxiliar;
	if ((strIdsCapas != null) && (strIdsTDs != null))
	{
		ArrayIdsCapas = strIdsCapas.value.split(",");
		ArrayIdsTDs = strIdsTDs.value.split(",");
				
		for (i = 0; i < ArrayIdsCapas.length; i++)
		{
			objCapa = document.getElementById(ArrayIdsCapas[i]);
			objCapaSig = document.getElementById(ArrayIdsCapas[i+1]);
			objTD = document.getElementById(ArrayIdsTDs[i]);
			
			if (objCapaSig != null && objCapa != null && objTD != null)
			{	
				if (i==0) {					
					//pos = pos + auxiliar;
					//alert(objCapa.style.left);
					//auxiliar = parseInt(objCapa.style.left) + auxiliar;
					auxiliar = 187 + auxiliar;
					objCapa.style.left = auxiliar + "px";
					//alert('A ' + pos);
				}			
				pos = parseInt(objCapa.style.left) + 7 + 20 + objTD.offsetWidth;
				//alert(i + ' ' + objCapa.style.left + ' ' + objTD.offsetWidth);							
				objCapaSig.style.left = pos + "px";
			}
	
			objCapa = null;
			objCapaSig = null;
			objTD = null;
			pos = 0;
			//pos = auxiliar;
		}
	
	}	
}

function DistribuyeCapasLat()
{
	var strIdsCapas;
	var strIdsTDs;
	var ArrayIdsCapas;
	var ArrayIdsTDs;
	var i;
	var objCapa;
	var objCapaTopo;
	var objTD;
	var pos;
	var altoCapa;
	
	strIdsCapas = document.getElementById("capas_menus_lat");
	strIdsTDs = document.getElementById("tds_menus_lat");
	
	var anchoVent=document.all?document.body.offsetWidth:window.innerWidth;	
    var auxiliar;
    var auxiliar2;
    //alert(anchoVent);
    		
	auxiliar = ((anchoVent-780)>>1)-14;
	if (auxiliar < 0) {
		auxiliar = 0;
	}
	//alert('DistribuyeCapasLat');
	//alert(window.screen.height);
	//alert(window.outerHeight);
	
	pos = 0;
	if ((strIdsCapas != null) && (strIdsTDs != null))
	{
		ArrayIdsCapas = strIdsCapas.value.split(",");
		ArrayIdsTDs = strIdsTDs.value.split(",");
		for (i = 0; i < ArrayIdsCapas.length; i++)
		{
			objCapa = document.getElementById(ArrayIdsCapas[i]);
			objCapaTopo = document.getElementById('topos_' + ArrayIdsCapas[i]);
			objTD = document.getElementById(ArrayIdsTDs[i]);
				
			if (objCapa != null && objCapaTopo != null && objTD != null)
			{	
				objCapa.style.top = "290px";
				objCapaTopo.style.top = "294px";
				
				pos = parseInt(objCapa.style.top) + objTD.offsetTop;						
				altoCapa = objCapa.scrollHeight;			
				//alert (i + ' pos: ' + pos + ' altoCapa: ' + altoCapa);						
				if (altoCapa + pos + 200 > window.screen.height) {
					pos = pos - altoCapa + 16;
					objCapa.style.top = pos + "px";
				} else {				
					objCapa.style.top = pos + "px";
				}
				pos = parseInt(objCapaTopo.style.top) + objTD.offsetTop;
				objCapaTopo.style.top = pos + "px";		
				
				auxiliar2 = 235 + auxiliar;
				objCapaTopo.style.left = auxiliar2 + "px";
				auxiliar2 = 253 + auxiliar;
				objCapa.style.left = auxiliar2 + "px";		
				
			}

			objCapa = null;
			objTD = null;
			pos = 0;
		}
	
	}	
}

function AbrirVentana(vUrl, vNombre, vAlto, vAncho, vCentrado, vEsPopPup){
	var Alto;
	var Ancho;
	var aTop;
	var aLeft;
	var Opciones;
	
	// Si es centrada calcula la posición el top y el left
	if (vCentrado == 'true'){
		Alto = screen.height;
		Ancho = screen.width;
		
		if (vAlto == '') vAlto = Alto-30;
		if (vAncho == '') vAncho = Ancho;
		
		aTop = (Alto - vAlto) / 2 - 10;
		aLeft = (Ancho - vAncho) / 2;
	}
	else{
		// Si no es centrada considera 50 y 50 las posiciones del top y el left
		aTop = 50;
		aLeft= 50;
	}
	
	Opciones = "top=" + aTop + ", left=" + aLeft + ", height=" + vAlto + ", ";
	if (vEsPopPup == 'true')
		Opciones = Opciones + "width=" + vAncho + ", resizable=0, scrollbars=1";
	else
		Opciones = Opciones + "width=" + vAncho + ", resizable=1, location=1, status=1, scrollbars=1, toolbar=1, menubar=1";
	
	return window.open(vUrl, vNombre, Opciones);
}

function FechaActual()
{
	var MonthNames = new Array(12);
	MonthNames[0] = "Enero";
	MonthNames[1] = "Febrero";
	MonthNames[2] = "Marzo";
	MonthNames[3] = "Abril";
	MonthNames[4] = "Mayo";
	MonthNames[5] = "Junio";
	MonthNames[6] = "Julio";
	MonthNames[7] = "Agosto";
	MonthNames[8] = "Septiembre";
	MonthNames[9] = "Octubre";
	MonthNames[10] = "Noviembre";
	MonthNames[11] = "Diciembre";
	var now = new Date();
	var day = now.getDate();
	var year = now.getFullYear();
	var month = now.getMonth() + 1;
	
	return(day + " de " + MonthNames[now.getMonth()] + " de " + year)	

}

function mostrarDiv(cbSelect){
	var indice;
	var valor;
	var i;
	var obj;
	
	indice = cbSelect.selectedIndex;
	valor = cbSelect[indice].value;
	
	for (i=0;i<cbSelect.length;i++){		
		if (cbSelect[i].value != cbSelect[indice].value) {
			//alert('voy a ocultar ' + i);
			//MM_showHideLayers(cbSelect[i].value,'','hide');
			//eval('document.' +  + '.style.visibility="hidden"');
			obj=document.getElementById(cbSelect[i].value);					
			if (obj != null){
				obj.style.visibility = 'hidden';	
			}
		}
		else {
			//alert('voy a mostrar ' + cbSelect[i].value);
			//MM_showHideLayers(cbSelect[i].value,'','show');
			//eval('document.' +  + '.style.visibility="visible"');
			obj=document.getElementById(cbSelect[indice].value);
			if (obj != null){		
				obj.style.visibility = 'visible';			
			}
		}
	}	

}

//Modificacion Agustin Martinez 06/03/2009
//Nueva función que centra las capas que estan en el campo que le pasamos
//por si redimensionamos la ventana
function DistribuyeCapasAdic(nomCampo)
{
	var strIdsCapas;
	var ArrayIdsCapas;
	var i;
	var objCapa;
	
	var auxiliar;
	
	strIdsCapas = document.getElementById(nomCampo);
	
	/*alert(window.screen.height);
	alert(window.screen.width);
	alert(window.screen.availWidth);
	alert(window.outerWidth);
	alert(window.innerWidth);*/
    
    var anchoVent=document.all?document.body.offsetWidth:window.innerWidth;	
    
    //alert(anchoVent);
    		
	//auxiliar = 200 + ((anchoVent-780)>>1)-14;
	auxiliar = 200 + ((anchoVent-780)>>1)-14;
	if (auxiliar < 200) {
		auxiliar = 200;
	}
	
	//alert(auxiliar);
	//alert('DistribuyeCapasAdic');
		
	if ((strIdsCapas != null))
	{
		ArrayIdsCapas = strIdsCapas.value.split(",");
						
		for (i = 0; i < ArrayIdsCapas.length; i++)
		{
			objCapa = document.getElementById(ArrayIdsCapas[i]);
			objCapa.style.left = auxiliar + "px";		
			objCapa = null;
			
		}
	
	}	
}