///Módulo: FuncionesGUI.js
///Descripción: Contiene funciones comunes para el manejo de componentes de interfaz 
///gráfica de usuario.
///Todas las funciones contenidas en este archivo están prefijadas por la cadena GUI; de
///esta forma, las estas funciones se identifican claramente en el código cliente.

	//<BUG IE5.5 textArea>
		//Solución a Bug IE5.5 (SP2). Los textareas solo muestran una línea (en algunas ocasiones)
		//aún cuando el contenido tiene varias.
		function BUG_IE55_Textos()
		{
			var i, j;
			var objElement;
			if(document.readyState == "complete")
			{
				for(i=0, j=document.all.length; i<j; i++)
				{
					objElement = document.all(i);
					if(objElement.type=="textarea" || objElement.type=="text")
					{
						objElement.value = objElement.value;
					}
				}
			}
			else
			{
				window.setTimeout(BUG_IE55_Textos,500);
			}
		}
	
		window.setTimeout(BUG_IE55_Textos,500);
	//</BUG IE5.5 textarea>
	
	
	/// Realiza un alert avisando que se grabaron OK los datos.
	/// Es invocada en todos los formularios al grabar
	function GUIAvisarGraboOK()
	{
		alert ("Los datos se grabaron correctamente.");
	}
	
	/// Realiza un alert avisando que no se produjeron cambios en la pantalla
	/// Retorna: Booleano. El mismo Flag que recibe como parametro
	function GUIAvisarNoHayCambios(blnFlagModificado)
	{
		if (!blnFlagModificado)
		{
			alert ("No se produjeron cambios: no es necesario grabar.");
		}	
		return blnFlagModificado;
	}
	
	/// Realiza un pedido de confirmacion para para saber si se quieren perder las modificaciones
	/// antes de cerrar la ventana
	/// Es invocada en todos los formularios al hacer close
	function GUICerrarSiNoHayModificacionesPendientes(blnModificado)
	{
		if (blnModificado)
		{
			if (confirm("Esta acción perdera los cambios no grabados. ¿Continua?"))	
			{
				window.history.back();
			}
		}
		else
		{
			window.history.back();
		}
	}
	
	function GUICerrarVentanaSiNoHayModificacionesPendientes(blnModificado)
	{
		if (blnModificado)
		{
			if (confirm("Esta acción perdera los cambios no grabados. ¿Continua?"))	
			{
				window.close();
			}
		}
		else
		{
			window.history.back();
		}
	}
	
	
	/// Chequea la longitud de una propiedad, para ser usada con
	/// el Evento (onbeforepaste, onkeypress). 
	function GUICheckMaxLength()
	{
		var objEvent = window.event;
		var objProperty = objEvent.srcElement;
		var intPropertyLength = objProperty.value.length;
		switch(objEvent.type.toLowerCase())
		{
			case "beforepaste":
				var objWinClipBoardData = window.clipboardData;
				var varData = objWinClipBoardData.getData("Text");
				if(varData==null)
				{
					varData = "";
				}
				intPropertyLength += varData.length;
				if(intPropertyLength>objProperty.maxlength)
				{
					objWinClipBoardData.clearData("Text");
				}
				objWinClipBoardData = null;
				break;
			case "keypress":
				if(++intPropertyLength>objProperty.maxlength)
				{
					objEvent.returnValue = false;
				}
				break;
		}
		objEvent = null;
		objProperty = null;
	}

	/// Devuelve valores cacheados en el "top-frame"
	/// Parametros:
	///	 - strVarName: String. Nombre de la variable como String (entre "")	
	function GUIGetCacheValue(strVarName)
	{
		var retVal;
		retVal = eval("GUIGetTopWindow().frames('frmMenu')." + strVarName + ";");
		return retVal;
	}
	
	function NewWindow( url, w, h) {
		var strFeatures, strURL;
		strURL = url;
		strFeatures = 'dialogHeight:' + h + 'px;dialogWidth:' + w + 'px;status:no;help:no;resizable:no;scroll:no';
		window.showModalDialog( strURL, window, strFeatures );
		return null;
	}

	// Funcion para abrir una ventana popup sin scrollbars, barra de estado, ni menues
	function NewWindow_old( mypage, myname, w, h, pos, infocus ) {
	
		 var win=null;
	     if (pos=="random") {
	        myleft=(screen.width) ? Math.floor(Math.random()*(screen.width-w)):100;mytop=(screen.height) ? Math.floor(Math.random()*((screen.height-h)-75)):100;
	     }
	     if (pos=="center") {
	        myleft=(screen.width) ? (screen.width-w)/2:100;
	        mytop=(screen.height) ? (screen.height-h)/2:100;
	     }
	     else if ((pos!='center' && pos!="random") || pos==null) {
	        myleft=0;
	        mytop=20;
	     }
	     settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";
	     win=window.open(mypage,myname,settings);
	     win.focus();
	     return win;
	}

	function NewNormalWindow(mypage,myname,w,h,pos) {
	   
	     if (pos=="random") {
	        myleft=(screen.width) ? Math.floor(Math.random()*(screen.width-w)):100;mytop=(screen.height) ? Math.floor(Math.random()*((screen.height-h)-75)):100;
	     }
	     if (pos=="center") {
	        myleft=(screen.width) ? (screen.width-w)/2:100;
	        mytop=(screen.height) ? (screen.height-h)/2:100;
	     }
	     else if ((pos!='center' && pos!="random") || pos==null) {
	        myleft=0;
	        mytop=20;
	     }
	     settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";
	     win=window.open(mypage,myname,settings);
	     win.focus();
	}

	function GUIValidarCampos(objValidators) {
		var blnValid = true;
		var objPrimerValidador = null;
		if(objValidators != null)
		for(var i=0; i<objValidators.length; i++)
		{
			blnValid = (objValidators[i].validate() && blnValid);
			if(!blnValid && (objPrimerValidador == null))
			{
				objPrimerValidador = objValidators[i];
			}
		}
		objValidators = null;
		if(!blnValid)
		{
			alert("Los datos introducidos no son correctos, \npor favor verifíquelos y vuelva a intentar.");
			//objPrimerValidador.scrollIntoView(true);
			//objPrimerValidador = null;
		}
		return blnValid;
	}


	function GUIResizeIfrSlaveEntity(sNameIFR) {
		var iPixels = 28;
		var iTableRowCount = eval(sNameIFR + '.m_TableRowCount');
		var iTablePageSise = eval(sNameIFR + '.m_TablePageSize');
		if((iTableRowCount>0)&&(iTableRowCount < (iTablePageSise+1))) {
			iPixels = 60 + (iPixels * iTableRowCount);
			eval('document.all.' + sNameIFR + '.height="' + iPixels + 'px"');
		} else {
			if(iTableRowCount==0) {
				eval('document.all.' + sNameIFR + '.height="20px"');
			} else {
				if(iTableRowCount >= (iTablePageSise+1) ) {
					iPixels = 60 + (iPixels * iTablePageSise);
					eval('document.all.' + sNameIFR + '.height="' + iPixels + 'px";');
				} 
			}
		}
		return;
	}


	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_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 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];
	   }
	}
	
	
	
		
		
		
