//función para aumentar/disminuir todas las etiquetas de texto de la página
function increaseStyles(rango)
{
	if (!document.styleSheets) return;
	for(var cs=0; cs<document.styleSheets.length;cs++)
	{
		var theRules = new Array();
		if (document.styleSheets[cs].cssRules)
			theRules = document.styleSheets[cs].cssRules
		else if (document.styleSheets[cs].rules)
			theRules = document.styleSheets[cs].rules
		else return
		
		for(var i=0; i<theRules.length;i++)
		{
			var oldTam=theRules[i].style.fontSize;
			if(oldTam!="")
			{
				var newTam=oldTam.substr(0, oldTam.indexOf("px"));
				theRules[i].style.fontSize=(parseInt(newTam, 10)+rango)+ "px";
			}
		}
	}
}

//función para aumentar/disminuir todas las etiquetas de texto de la página
function SetHourglassStyles()
{
	if (!document.styleSheets) return;
	for(var cs=0; cs<document.styleSheets.length;cs++)
	{
		var theRules = new Array();
		if (document.styleSheets[cs].cssRules)
			theRules = document.styleSheets[cs].cssRules
		else if (document.styleSheets[cs].rules)
			theRules = document.styleSheets[cs].rules
		else return
		
		for(var i=0; i<theRules.length;i++)
		{
			theRules[i].style.setAttribute( "cursor", "wait" );
		}
	}
}

function QuitarHourglassStyles()
{
	if (!document.styleSheets) return;
	for(var cs=0; cs<document.styleSheets.length;cs++)
	{
		var theRules = new Array();
		if (document.styleSheets[cs].cssRules)
			theRules = document.styleSheets[cs].cssRules
		else if (document.styleSheets[cs].rules)
			theRules = document.styleSheets[cs].rules
		else return
		
		for(var i=0; i<theRules.length;i++)
		{
			if(	theRules[i].style.getAttribute( "cursor" ) == "wait" )
				theRules[i].style.setAttribute( "cursor", "auto" );
		}
	}
}


function ConfirmOperation ( esteForm, code, message )
{
  if ( confirm ( message ) )
  {
    esteForm.ExecuteOperation.value = code;
    esteForm.submit();
  }
  return false;
}

function deleteObject ( esteForm, message )
{
	if(confirm(message))
	{
		esteForm.deletingObject.value="true";
		esteForm.submit();
	}
	return false;
}

function ChangeOnTop ( )
{
   self.focus();
}

//Añadir funciones al body onload
// es decir, funciones para que se ejecuten en el cliente cuando la página haya terminado de cargarse
var gSafeOnload = new Array();
function AddOnloadFunction(f)
{
	if  (window.onload)
	{
		if (window.onload != SafeOnload)
		{
			gSafeOnload[0] = window.onload;
			window.onload = SafeOnload;
		}		
		gSafeOnload[gSafeOnload.length] = f;
	}
	else
		window.onload = f;
}

function SafeOnload()
{
	for (var i=0;i<gSafeOnload.length;i++)
		gSafeOnload[i]();
}  

//Añadir funciones al body onfocus
// es decir, funciones para que se ejecuten en el cliente cuando la ventana coge el foco
var gSafeOnfocus = new Array();
function AddOnfocusFunction(f)
{
	if  (window.onfocus)
	{
		if (window.onfocus != SafeOnfocus)
		{
			gSafeOnfocus[0] = window.onfocus;
			window.onfocus = SafeOnfocus;
		}		
		gSafeOnfocus[gSafeOnfocus.length] = f;
	}
	else
		window.onfocus = f;
}

function SafeOnfocus()
{
	for (var i=0;i<gSafeOnfocus.length;i++)
		gSafeOnfocus[i]();
}  

//Añadir funciones al body onbeforeunload
// es decir, funciones para que se ejecuten cuando el cliente empieza a buscar la otra página
var gSafeOnbeforeunload = new Array();
function AddOnbeforeunloadFunction(f)
{
	if  (window.onbeforeunload)
	{
		if (window.onbeforeunload != SafeOnbeforeunload)
		{
			gSafeOnbeforeunload[0] = window.onbeforeunload;
			window.onbeforeunload = SafeOnbeforeunload;
		}		
		gSafeOnbeforeunload[gSafeOnbeforeunload.length] = f;
	}
	else
		window.onbeforeunload = f;
}

function SafeOnbeforeunload()
{
	for (var i=0;i<gSafeOnbeforeunload.length;i++)
		gSafeOnbeforeunload[i]();
}  

//Añadir funciones al body onunload
// es decir, funciones para que se ejecuten cuando el cliente por fin carga la siguiente página
var gSafeOnunload = new Array();
function AddOnunloadFunction(f)
{
	if  (window.onunload)
	{
		if (window.onunload != SafeOnunload)
		{
			gSafeOnunload[0] = window.onunload;
			window.onunload = SafeOnunload;
		}		
		gSafeOnunload[gSafeOnunload.length] = f;
	}
	else
		window.onunload = f;
}

function SafeOnunload()
{
	for (var i=0;i<gSafeOnunload.length;i++)
		gSafeOnunload[i]();
}  

// VENTANAS FLOTANTES
function onFocusCierraventanaFlotante()
{
	cierraVentanaFlotanteFromOpener();
}

function cierraVentanaFlotanteFromOpener()
{
	if ( window.top.ventanaFlotante != null )
	{
		if ( window.top.ventanaFlotante.closed )
		{
			window.top.ventanaFlotante = null;
			return;
		}
	}
	if ( window.top.ventanaFlotante != null )
	{
		if( confirm( MensajeAutoCierreFlotante ))
		{
			try
			{
				window.top.ventanaFlotante.close();
			}catch(er){}
			window.top.ventanaFlotante = null;
		}
		else
		{
			try
			{
				window.top.ventanaFlotante.focus();
				//Creo que es mejor que no lo haga porque la ventana se minimiza
				//window.blur();
				
			}catch(er)
			{
				window.top.ventanaFlotante = null;
			}
		}
	}
}

function cierraVentanaFlotanteFromFlotante()
{
	try
	{
		window.opener.top.ventanaFlotante = null;
	}catch(er){}
	try
	{
		window.top.close();
	}catch(er){}
	try
	{
		window.opener.focus();
	}catch(er){}
}
// FIN VENTANAS FLOTANTES


//Función para las ventanas emergentes,
// ejecuta una función en la ventana llamadora y se cierra
function actualizarYCerrarCommit(functionALlamar){
	var hecho=false;
	while (!hecho) {
		try{
			eval("window.opener."+functionALlamar+";");
			cierraVentanaFlotanteFromFlotante();
			hecho=true;
		}
		catch(er){}
	}
}

function eliminacionConfirmada(mensaje)
{
	return confirm(mensaje);
}

//Ventana Genérica
var strOptions = "location=no";
strOptions += ",toolbar=yes";
strOptions += ",menubar=yes";
strOptions += ",status=yes";
strOptions += ",scrollbars=yes";
strOptions += ",resizable=yes";
strOptions += ",top=0";
strOptions += ",left=0";
strOptions += ",width=750";
strOptions += ",height=500";

function abreVentana( strUrl, options )
{
	if( options == "" )
	{
		options = strOptions;
	}
	window.open( strUrl, "Presentacion", options );
}

//AYUDAS
var strHelpOptions = "location=no";
strHelpOptions += ",toolbar=yes";
strHelpOptions += ",menubar=yes";
strHelpOptions += ",status=yes";
strHelpOptions += ",scrollbars=yes";
strHelpOptions += ",resizable=yes";
strHelpOptions += ",top=0";
strHelpOptions += ",left=0";
strHelpOptions += ",width=750";
strHelpOptions += ",height=500";

function ShowHelp(strUrl)
{
	window.open( strUrl, "Help", strHelpOptions);
}

function Aislar( HTMLdelaCelda, textoABuscar )
{
	inicio= HTMLdelaCelda.indexOf(textoABuscar) + ( textoABuscar.length + 1 );
	comillas= HTMLdelaCelda.substring( inicio-1, inicio );
	HTMLdespues = HTMLdelaCelda.substring( inicio );

	fin= HTMLdespues.indexOf (comillas);

	return HTMLdespues.substr( 0, fin ) ;
}

function showPDF( previewURL, redirect)
{	
	window.top.ventanaFlotante=window.open( previewURL,'_blank','resizable=yes,width=800,height=600,status=no,scrollbars=yes');
	if( ( redirect != "" ) && (redirect != null) )
	{
		setTimeout( "window.top.ventanaFlotante.focus();", 100);
		window.top.ventanaFlotante.location.replace( previewURL );
		location.replace( redirect ); 
//		location.href = redirect;
	}
	//alert(1);
}

var submitcount=0;
function notSubmitted() {
	if (submitcount == 0)
	{
		submitcount++;
		return true;
	}
	else 
	{
		//alert("No se vuelve a enviar");
		return false;
	}
}

function RowSelectorColumn_SelectAll( parentCheckBox, marcar ) {
	
//   for ( var j=0; j < parentCheckBox.elements.length; j++ ) 
//   {
//		alert( parentCheckBox.elements[j].id );
//	}
    if ( typeof( document.getElementById ) == "undefined" )
    {
		return false;
	}
    
    if ( parentCheckBox == null 
		|| typeof( parentCheckBox.elements ) == "undefined" ) 
	{
        return false;
    }
    
    var controles = parentCheckBox.elements;
    
    for ( var i=0; i < controles.length; i++ ) {
        var controlid = controles[i].id;
		//alert( "Marcar " + controlid );
        if( controlid.indexOf( "CheckBox" ) != -1 )
		{
            controles[i].checked = marcar;
        }
    }
    return false;
}




