//***********************************************************************************
//- Oculta o no un elemento 
//***********************************************************************************
function ShowOrHide(oSource)
{
	if (document.getElementById(oSource).style.display == 'none')
		document.getElementById(oSource).style.display = "";
	else
		document.getElementById(oSource).style.display = "none";
}


//***********************************************************************************
//- Expandir objeto a un tamaño especificado
//***********************************************************************************
function SetObjectHeight(objeto, altura)
{
	if (altura != document.getElementById(objeto).style.height)
		document.getElementById(objeto).style.height = altura;
}
	
	
//***********************************************************************************
//	Suma los elementos de un XML
//		oDomSrc =  Objeto o Dom donde aplico el XPath
//		pstrXPathExp = "sum(Acreditaciones/Acreditacion/Pagos/Pago/Total/text())"
//***********************************************************************************
function XPath(oDomSrc, pstrXPathExp)
{
	try {
		var oDomSum = new ActiveXObject("MSXML2.DomDocument")

		strSum = "<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>" +
					"<xsl:template match='/'>"+
						"<xsl:value-of select='" + Trim(pstrXPathExp) + "'/>"+
					"</xsl:template>"+
				 "</xsl:stylesheet>"

		oDomSum.loadXML(strSum)			//-- Cargo Xsl a aplicar
				
		var strRes = new String();
		var strReturnValue = new String();
				 
		strRes = oDomSrc.transformNode(oDomSum.documentElement)		//-- Aplico XSL

		strReturnValue = strRes.replace('<?xml version="1.0" encoding="UTF-16"?>',"");
		oDomSum = null;
		return strReturnValue;
	} catch(e)
	  {
		e.description = " XPath(oDomSrc, pstrXPathExp) - " + e.description ;
		throw e;
	  }
}


//*****************************************************************
//-- Limpio Proxy
//*****************************************************************
function ClearProxy() 
{	try { 
		xmlProxy.loadXML(xmlProxyBlank.xml); 
	} catch(e)
	  {
		e.description = " ClearProxy() - " + e.description ;
		throw e;
	  }
}


//*****************************************************************
// Retorna true o false dependiendo si la Fecha Desde es MAYOR
// a la Fecha Hasta.
//
// Parametros:
//		1) Fecha Desde en Formato String DD/MM/YYYY
//		2) Fecha Hasta en Formato String DD/MM/YYYY
//
// Martin Melchior - Junio 2003.
//*****************************************************************
function ValidDate(fecDesde, fecHasta)
{
	if (!(IsDate(fecDesde) && IsDate(fecHasta)))
	{
		alert("Alguna de las fechas no es válida !!!");
		return false;
	}
		
	var strFecDesde = new String(fecDesde);
	diaFecDesde		= strFecDesde.substr(0,2);
	mesFecDesde		= strFecDesde.substr(3,2); 
	anioFecDesde	= strFecDesde.substr(6,4);
			
	var strFecHasta = new String(fecHasta);
	diaFecHasta		= strFecHasta.substr(0,2);
	mesFecHasta		= strFecHasta.substr(3,2); 
	anioFecHasta	= strFecHasta.substr(6,4);

	nDifAños  = anioFecHasta - anioFecDesde;
	nDifMeses = mesFecHasta - mesFecDesde;
	nDifDias  = diaFecHasta - diaFecDesde;

		
	if (nDifAños >= 0)
		if (nDifAños == 0)
			if (nDifMeses >= 0)
				if (nDifMeses == 0)
					if (nDifDias >= 0)
						return true;
					else
						return false;
				else
					return true;
			else
				return false;
		else
			return true;
	else
		return false;				
}


//*****************************************************************
// Retorna Diferencia en Meses entre dos Fechas
// Parametros:
//		1) Fecha en Formato String DD/MM/YYYY
//		2) Fecha en Formato String DD/MM/YYYY
//
// Martin Melchior - Junio 2003.
//*****************************************************************
function DateDiffMonth(Date1, Date2)
{
	try {
		if (ValidDate(Date1, Date1))
		{
			var strDate1 = new String(Date1);
			Date1 = strDate1.substr(3,2) + '/' + strDate1.substr(0,2) + '/' + strDate1.substr(6,4)  
					
			var strDate2 = new String(Date2);
			Date2 = strDate2.substr(3,2) + '/' + strDate2.substr(0,2) + '/' + strDate2.substr(6,4)

			date1 = new Date();
			date2 = new Date();
			diff  = new Date();

			date1temp = new Date(Date1);
			date1.setTime(date1temp.getTime());
			date2temp = new Date(Date2);
			date2.setTime(date2temp.getTime());

			diff.setTime(Math.abs(date1.getTime() - date2.getTime()));
			timediff = diff.getTime();
					
			weeks = Math.floor(timediff / (1000 * 60 * 60 * 24 * 7));
			timediff -= weeks * (1000 * 60 * 60 * 24 * 7);

			days = Math.floor(timediff / (1000 * 60 * 60 * 24)); 
			timediff -= days * (1000 * 60 * 60 * 24);

			hours = Math.floor(timediff / (1000 * 60 * 60)); 
			timediff -= hours * (1000 * 60 * 60);

			mins = Math.floor(timediff / (1000 * 60)); 
			timediff -= mins * (1000 * 60);

			secs = Math.floor(timediff / 1000); 
			timediff -= secs * 1000;

			var nDiffMonth = 0;
	
			if (weeks > 0) { nDiffMonth = nDiffMonth + (weeks * 7); }
			if (days  > 0) { nDiffMonth = nDiffMonth + days; }

			var nMeses = (nDiffMonth / 30);
			nMeses = Math.floor(nMeses);
			return (nMeses);
		} else
			return false;
	} catch(e)
	  {
		e.description = " DateDiffMonth() - " + e.description ;
		throw e;
	  }		
}


//*****************************************************************
// Retorna el Día de Hoy en formato DD/MM/YYYY
// Martin Melchior - Mayo 2003.
//
//*****************************************************************
function Now()
{
	try {
		var oDia = new Date();
		
		strFecha = new String(oDia);
		strFecha = strFecha.toUpperCase()
		aFecha   = Split(strFecha," ")
		strMes	 = "";
	
		strDia   = Right("0"+aFecha[2],2);
			
		switch (aFecha[1]){
		case "JAN":	strMes = "01";	break;	
		case "FEB":	strMes = "02";	break;	
		case "MAR":	strMes = "03";	break;	
		case "APR":	strMes = "04";	break;	
		case "MAY":	strMes = "05";	break;	
		case "JUN":	strMes = "06";	break;	
		case "JUL":	strMes = "07";	break;	
		case "AUG":	strMes = "08";	break;	
		case "SEP":	strMes = "09";	break;	
		case "OCT":	strMes = "10";	break;	
		case "NOV":	strMes = "11";	break;
		case "DEC":	strMes = "12";	break;		
		default: strMes = ""; }
		return (strDia + "/" + strMes + "/" + aFecha[5]);
	} catch(e)
	  {
		e.description = " Now() - " + e.description ;
		throw e;
	  }
}
	

//*****************************************************************
// Setea una propiedad de una coleccion con el valor pasado
// Martin Melchior - Mayo 2003.
//
//*****************************************************************
function SetPropertyCollection(strNameCollection, strNameProperty, strNameValue, strPropertyCondition, strValueCondition)
{
	try 
	{
		var strLargo = "window.document.getElementsByName('" + Trim(strNameCollection) + "').length";
		var nLargo	 = eval(strLargo);
		
		for (var i=0; i < nLargo; i++)
		{
			strSetProperty = "document.getElementsByName('" + Trim(strNameCollection) + "').item(i)." + Trim(strNameProperty) + "='" + Trim(strNameValue) + "'";
			strCondition   = "document.getElementsByName('" + Trim(strNameCollection) + "').item(i)." + Trim(strPropertyCondition) + "=" + Trim(strValueCondition)
		
			alert(eval(strCondition))
			
			if (eval(strCondition))
				eval(strSetProperty);
		}
	} catch(e)
  	  {
		e.description = " SetPropertyCollection() - " + e.description ;
		throw e;
	  }
}


//*****************************************************************
// Crea un objeto FORM lo agrega al DOCUMENT y hace submit
// Martin Melchior - Mayo 2003.
//
//*****************************************************************
function CreateForm(strId, strName, strAction)
{
	try 
	{
		var oForm    = document.createElement("FORM");
		oForm.id	 = strId;
		oForm.name	 = strName;
		oForm.action = strAction;
		document.appendChild(oForm);
		oForm.submit();		
	} catch(e)
	  {
		e.description = " CreateForm() - " + e.description ;
		throw e;
	  }
}


//*****************************************************************
// Esta función retorna el índice del PRIMER TR que encuentra
// OJO: El primer Row es 0 y no 1 !!!!
// Martin Melchior - Mayo 2003.
//
//*****************************************************************
function GetIndexRow(oSource, MostrarIndex)
{	
	var strObjeto
	var strParentNode
	var strNivel
	var strRowIndex
	var strSumaParent
	var nReturnValue

	try 
	{
		nReturnValue  = 0;
		strParentNode = "parentNode.";
		strObjeto	  = "oSource.tagName;";
		strNivel	  = "";
		strSumaParent = "";

		
		for (var nivel=1; nivel<=10; nivel++)
		{
			strNivel = StrConv(Trim(eval(strObjeto)),1);
			if (strNivel == "TR")
				nivel = 10;
			else	
			{	
				strSumaParent = Replicate(nivel, strParentNode);
				strObjeto = "oSource." + strSumaParent + "tagName;"
				strNivel  = eval(strObjeto);
			}		
		}

		strRowIndex  = "window.event.srcElement." + strSumaParent + "rowIndex";
		nReturnValue = eval(strRowIndex); 
		
		nReturnValue = nReturnValue - 1;
		
		if (MostrarIndex != null)
			alert("Indice del Row: " + nReturnValue)
			
		return (nReturnValue);
			
	} catch(e)
	  {
		e.description = " GetIndexRow() - " + e.description ;
		throw e;
	  }
}


//*****************************************************************
// Replica un caracter la cantidad de veces que quiero
// 
// Martin Melchior - Mayo 2003.
//
//******************************************************************
function Replicate(nVeces, cCaracter)
{
	try
	{
		var sReturn
		sReturn = '';

		if ((nVeces == null) || (cCaracter == null))
			return (sReturn);
		
		for (var i=1; i<=nVeces; i++)
			sReturn = sReturn + cCaracter;

		return (sReturn);
		
	} catch(e)
	  {
		e.description = " Replicate() - " + e.description ;
		throw e;
	  }
}

function CreateCDataNode(NodeName,NodeValue)
{
var oDom;  
var oNodoAux;
var oCData;    
oDom = new ActiveXObject("MSXML2.DOMDocument");
oCData = oDom.createCDATASection(NodeValue);
oNodoAux = oDom.createElement(NodeName);
oNodoAux.appendChild (oCData);
return oNodoAux;
}



/**************************************************************
 DetectBrowser: Return a string that contains the current 
                browser name and version used.
 Parameters:
 Returns: String
***************************************************************/
function DetectBrowser()
{
	var temp = navigator.appName;
	temp = temp.toLowerCase();

	if (temp == 'microsoft internet explorer')
		return 'IE' + navigator.appVersion
	else
		return 'NS' + navigator.appVersion;
}



/**************************************************************
 OpenURL: Return a concatenated string with all the 'objects
          values' contained in a FORM HTML in the format:
          page_to_redirect.html/asp?object1=xxxx&object2=yyyyy&...

 Parameters:
      URL  = URL to redirect
      Form = Form name (be sure not to use QUOTES when passing
             the Form name)

 Returns: URL

 Example: var redirect = OpenURL('mytest.asp', frmMyForm)
          alert(redirect)
          window.nagivate(redirect)
***************************************************************/
function OpenURL(URL, Form)
{
	if (URL.length == 0 || URL == null)
		return (false);

	var form_length = Form.elements.length;
	var myform = Form;
	var mytype = '';
	var temp = URL + '?';

	for (var i = 0; i < form_length; i++)
	{
		mytype = myform.elements[i].type
		mytype = mytype.toLowerCase();
		if (mytype == 'text' || mytype == 'hidden' || mytype == 'select-one' ||
		    mytype == 'checkbox' || mytype == 'radio' || mytype == 'select-multiple')
		{
			var t = myform.elements[i].name
			if (t == null || t == '')
				t = myform.elements[i].id
			if (mytype == 'text' || mytype == 'hidden')
				temp = temp + t + "=" + escape(myform.elements[i].value);
			else if (mytype == 'checkbox' || mytype == 'radio')
				temp = temp + t + "=" + escape(myform.elements[i].checked);
			else if (mytype == 'select-one' || mytype == 'select-multiple')
				temp = temp + t + "=" + escape(myform.elements[i][myform.elements[i].selectedIndex].value);
			if (i < form_length - 1)
				temp = temp + "&";
		}
	}
	temp = temp.substring(temp, temp.length - 1)

	return temp;
} 



/**************************************************************
 DaysInMonth: Return number of days in a month.
 Parameters:
      dDate = Date to process. If date is null, false is
              returned.
 Returns: Integer
***************************************************************/
function DaysInMonth(dDate)
{
	if (dDate == null)
		return (false);

	dDate = new Date(dDate)

	var dt1, cmn1, cmn2, dtt, lflag, dycnt
	var temp1 = dDate.getMonth() + 1;
	var temp2 = dDate.getYear();
	dt1 = new Date(temp2, temp1 - 1, 1)
	cmn1 = dt1.getMonth()
	dtt = dt1.getTime() + 2332800000
	lflag = true
	dycnt = 28
	while (lflag)
	{
		dtt = dtt + 86400000
		dt1.setTime(dtt)
		cmn2 = dt1.getMonth()
		if (cmn1 != cmn2)
			lflag = false
		else
			dycnt = dycnt + 1;
	}
	if (dycnt > 31)
		dycnt = 31;

    return dycnt;
}



/**************************************************************
 Abs: Returns a value of the same type that is passed to it 
      specifying the absolute value of a number.

 Parameters:
      Number = The required number argument can be any valid 
               numeric expression. If number contains Null, 
               false is returned; if it is an uninitialized 
               variable, false is returned.
 Returns: Long
***************************************************************/
function Abs(Number)
{
	Number = Number.toLowerCase();
	RefString = "0123456789.-";

	if (Number.length < 1) 
		return (false);

	for (var i = 0; i < Number.length; i++) 
	{
		var ch = Number.substr(i, 1)
		var a = RefString.indexOf(ch, 0)
		if (a == -1)
			return (false);
	}

	if (Number < 0)
		return (Number * -1)

	return Number;
}



/**************************************************************
 Len: Returns a Long containing the number of characters in a 
      string or the number of bytes required to store a 
      variable.
 Parameters:
      string = Any valid string expression. If string contains 
               null, false is returned.
 Returns: Long
***************************************************************/
function Len(string)
{
	if (string == null)
		return (false);

	return String(string).length;
}



/**************************************************************
 Chr: Returns a String containing the character associated 
      with the specified character code.
 Parameters:
      CharCode = Long that identifies a character.
 Returns: String
***************************************************************/
function Chr(CharCode)
{
	return String.fromCharCode(CharCode);
}



/**************************************************************
 Asc: Returns an Integer representing the character code 
      corresponding to the first letter in a string
 Parameters:
      String = The required string argument is any valid 
               string expression. If the string if not in 
               the range 32-126, the function return ZERO

 Returns: Integer
***************************************************************/
function Asc(string)
{
	var symbols = " !\"#$%&'()*+'-./0123456789:;<=>?@";
	var loAZ = "abcdefghijklmnopqrstuvwxyz";
	symbols += loAZ.toUpperCase();
	symbols += "[\\]^_`";
	symbols += loAZ;
	symbols += "{|}~";
	var loc;
	loc = symbols.indexOf(string);
	if (loc > -1)
	{ 
		Ascii_Decimal = 32 + loc;
		return (32 + loc);
	}
	return (0);
}



/**************************************************************
 LTrim: Returns a String containing a copy of a specified 
        string without leading spaces 
 Parameters:
      String = The required string argument is any valid 
               string expression. If string contains null, 
               false is returned
 Returns: String
***************************************************************/
function LTrim(String)
{
	var i = 0;
	var j = String.length - 1;

	if (String == null)
		return (false);

	for (i = 0; i < String.length; i++)
	{
		if (String.substr(i, 1) != ' ' &&
		    String.substr(i, 1) != '\t')
			break;
	}

	if (i <= j)
		return (String.substr(i, (j+1)-i));
	else
		return ('');
}



/**************************************************************
 RTrim: Returns a String containing a copy of a specified 
        string without trailing spaces 
 Parameters:
      String = The required string argument is any valid 
               string expression. If string contains null, 
               false is returned
 Returns: String
***************************************************************/
function RTrim(String)
{
	var i = 0;
	var j = String.length - 1;

	if (String == null)
		return (false);

	for(j = String.length - 1; j >= 0; j--)
	{
		if (String.substr(j, 1) != ' ' &&
			String.substr(j, 1) != '\t')
		break;
	}

	if (i <= j)
		return (String.substr(i, (j+1)-i));
	else
		return ('');
}



/**************************************************************
 RTrim: Returns a String containing a copy of a specified 
        string without both leading and trailing spaces 
 Parameters:
      String = The required string argument is any valid 
               string expression. If string contains null, 
               false is returned
 Returns: String
***************************************************************/
function Trim(String)
{
	if (String == null)
		return (false);

	return RTrim(LTrim(String));
}



/**************************************************************
 Left: Returns a String containing a specified number of 
       characters from the left side of a string.
 Parameters:
      String = String expression from which the leftmost 
               characters are returned. If string contains null, 
               false is returned.
      Length = Numeric expression indicating how many characters 
               to return. If 0, a zero-length string ("") is 
               returned. If greater than or equal to the number 
               of characters in string, the entire string is 
               returned. 
 Returns: String
***************************************************************/
function Left(String, Length)
{
	if (String == null)
		return (false);

	return String.substr(0, Length);
}



/**************************************************************
 Right: Returns a String containing a specified number of 
        characters from the right side of a string.
 Parameters:
      String = String expression from which the leftmost 
               characters are returned. If string contains null, 
               false is returned.
      Length = Numeric expression indicating how many characters 
               to return. If 0, a zero-length string ("") is 
               returned. If greater than or equal to the number 
               of characters in string, the entire string is 
               returned. 
 Returns: String
***************************************************************/
function Right(String, Length)
{
	if (String == null)
		return (false);

    var dest = '';
    for (var i = (String.length - 1); i >= 0; i--)
		dest = dest + String.charAt(i);

	String = dest;
	String = String.substr(0, Length);
	dest = '';

    for (var i = (String.length - 1); i >= 0; i--)
		dest = dest + String.charAt(i);

	return dest;
}



/**************************************************************
 Mid: Returns a String containing a specified number of 
      characters from a string
 Parameters:
      String = String expression from which characters are 
               returned. If string contains null, false is 
               returned.
      Start  = Number. Character position in string at which 
               the part to be taken begins. If Start is 
               greater than the number of characters in 
               string, Mid returns a zero-length string ("").
      Length = Number of characters to return. If omitted 
               false is returned. 
 Returns: String
***************************************************************/
function Mid(String, Start, Length)
{
	if (String == null)
		return (false);

	if (Start > String.length)
		return '';

	if (Length == null || Length.length == 0)
		return (false);

	return String.substr((Start - 1), Length);
}



/**************************************************************
 InStr: Returns a Long specifying the position of the first 
        occurrence of one string within another. Is String1
        or String2 are null, false is returned.
 Parameters:
      String1 = String expression being searched.
      String2 = String expression sought
 Returns: Integer
***************************************************************/
function InStr(String1, String2)
{
	var a = 0;

	if (String1 == null || String2 == null)
		return (false);

	String1 = String1.toLowerCase();
	String2 = String2.toLowerCase();

	a = String1.indexOf(String2);
	if (a == -1)
		return 0;
	else
		return a + 1;
}

/**************************************************************
 Sgn: Returns an Integer indicating the sign of a number. If
      Integer is not a number the functions return false.

 Parameters:
      Integer = The number argument can be any valid numeric 
                expression.

 Returns: Integer       -1 If Integer < 0
                         0 If Integer = 0
                         1 If Integer > 0
                     false If Parameter IS NOT NUMERIC
***************************************************************/
function Sgn(Integer)
{
	Number = Integer.toLowerCase();
	RefString = "0123456789-";

	if (Number.length < 1) 
		return (false);

	for (var i = 0; i < Number.length; i++) 
	{
		var ch = Number.substr(i, 1)
		var a = RefString.indexOf(ch, 0)
		if (a == -1)
			return (false);
	}
	if (Integer < 0)
		return (-1);
	else if (Integer == 0)
		return (0);
	else
		return (1);
}

/**************************************************************
 LBound: Returns a Long containing the smallest available 
         subscript for the indicated dimension of an array

 Parameters:
      array = Array to verify

 Returns: Integer       (-1 if Array does not contain
                            any subscript)
***************************************************************/
function LBound(array)
{
	var i = 0;
	var temp = '';

	if (array.length == 0)
		return (-1);

	for (i = 0; i < array.length; i++)
	{
		temp = array[i]
		if (temp != null)
		{
			var temp = i;
			return temp;
		}
	}
	return (-1);
}

/**************************************************************
 UBound: Returns a Long containing the largest available 
         subscript for the indicated dimension of an array

 Parameters:
      array = Array to verify

 Returns: Integer       (-1 if Array does not contain
                            any subscript)
***************************************************************/
function UBound(array)
{
	return (array.length - 1);
}

/**************************************************************
 Join: Returns a string created by joining a number of 
       substrings contained in an array.

 Parameters:
      array     = One-dimensional array containing substrings 
                  to be joined
      Delimiter = String character used to separate the 
                  substrings in the returned string. 
                  If delimiter is a zero-length string (""), 
                  all items in the list are concatenated 
                  with no delimiters. 

 Returns: String
***************************************************************/
function Join(array, Delimiter)
{
	var temp = '';

	if (array.length == 0)
		return '';

	if (Delimiter.length == 0)
		Delimiter = ' ';

	for (var i = 0; i < array.length; i++)
	{
		temp = temp + array[i]
		if (i < array.length - 1)
			temp = temp + Delimiter;
	}
	return temp;
}

/**************************************************************
 ReturnString: Returns a String containing a repeating 
               character string of the length specified

 Parameters:
      Number    = Length of the returned string. If number 
                  is less than 1, false is returned.
      Character = Character code specifying the character or 
                  string expression whose first character is 
                  used to build the return string. If character 
                  contains null, false is returned. 

 Returns: String
***************************************************************/
function ReturnString(Number, Character)
{
	var temp = '';

	if (Number < 1)
		return (false);

	if (Character.length == 0)
		return (false);

	if (Character.length > 1)
		Character = Character.charAt(0);

	for (var i = 0; i < Number; i++)
	{
		temp = temp + Character
	}

	return temp;
}

/**************************************************************
 Split: Returns a zero-based, one-dimensional array containing 
        a specified number of substrings

 Parameters:
      Expression = String expression containing substrings and 
                   delimiters. If expression is a zero-length 
                   string(""), Split returns an empty array, 
                   that is, an array with no elements and no 
                   data.
      Delimiter  = String character used to identify substring 
                   limits. If delimiter is a zero-length 
                   string (""), a single-element array 
                   containing the entire expression string 
                   is returned.

 Returns: String
***************************************************************/
function Split(Expression, Delimiter)
{
	var temp = Expression;
	var a, b = 0;
	var array = new Array();

	if (Delimiter.length == 0)
	{
		array[0] = Expression;
		return (array);
	}

	if (Expression.length == '')
	{
		array[0] = Expression;
		return (array);
	}

	Delimiter = Delimiter.charAt(0);

	for (var i = 0; i < Expression.length; i++) 
	{
		a = temp.indexOf(Delimiter);
		if (a == -1)
		{
			array[i] = temp;
			break;
		}
		else
		{
			b = (b + a) + 1;
			var temp2 = temp.substring(0, a);
			array[i] = temp2;
			temp = Expression.substr(b, Expression.length - temp2.length);
		}
	}

	return (array);
}

/**************************************************************
 Space: Returns a String consisting of the specified number 
        of spaces

 Parameters:
      Number = Number of spaces you want in the string.

 Returns: String
***************************************************************/
function Space(Number)
{
	var temp = '';

	if (Number < 1)
		return '';

	for (var i = 0; i < Number; i++)
	{
		temp = temp + ' ';
	}
	return temp;
}

/**************************************************************
 Replace: Returns a string in which a specified substring has 
          been replaced with another substring a specified 
          number of times.

 Parameters:
      Expression = String expression containing substring to 
                   replace
      Find       = Substring being searched for.
      Replace    = Replacement substring.

 Returns: String
***************************************************************/
function Replace(Expression, Find, Replace)
{
	var temp = Expression;
	var a = 0;

	for (var i = 0; i < Expression.length; i++) 
	{
		a = temp.indexOf(Find);
		if (a == -1)
			break
		else
			temp = temp.substring(0, a) + Replace + temp.substring((a + Find.length));
	}

	return temp;
}

/**************************************************************
 IsChar: Returns a Boolean value indicating whether an 
         expression can be evaluated as a character (this 
         not only includes alpha chars but all symbols such as
         @#$%^&|\_+-/*="!?,.:;'(){}<>[]

 Parameters:
    - Expression = Variant containing a numeric expression or 
                   string expression.

 Returns: Boolean
***************************************************************/
function IsChar(Expression)
{
	Expression = Expression.toLowerCase();
	RefString = "0123456789";

	if (Expression.length < 1) 
		return (false);

	for (var i = 0; i < Expression.length; i++) 
	{
		var ch = Expression.substr(i, 1)
		var a = RefString.indexOf(ch, 0)
		if (a != -1)
			return (false);
	}
	return(true);
}

/**************************************************************
 IsNumber: Returns a Boolean value indicating whether an 
           expression can be evaluated as a number (this
           includes values like $15,656.00)

 Parameters:
      Expression = Variant containing a numeric expression or 
                   string expression.

 Returns: Boolean
***************************************************************/
function IsNumber(Expression)
{
	Expression = Expression.toLowerCase();
	RefString = "0123456789.-";
	
	if (Expression.length < 1) 
		return (false);

	for (var i = 0; i < Expression.length; i++) 
	{
		var ch = Expression.substr(i, 1)
		var a = RefString.indexOf(ch, 0)
		if (a == -1)
			return (false);
	}
	return(true);
}

/**************************************************************
 IsAlphanumeric: Returns a Boolean value indicating whether an 
                 expression can be evaluated as a number or
                 char.

 Parameters:
      Expression = Variant containing a numeric expression or 
                   string expression.

 Returns: Boolean
***************************************************************/
function IsAlphanumeric(Expression)
{
	Expression = Expression.toLowerCase();
	RefString = "abcdefghijklmnopqrstuvwxyz0123456789 ";

	if (Expression.length < 1) 
		return (false);

	for (var i = 0; i < Expression.length; i++) 
	{
		var ch = Expression.substr(i, 1)
		var a = RefString.indexOf(ch, 0)
		if (a == -1)
			return (false);
	}
	return(true);
}

/**************************************************************
 ReverseString: Returns a string in which the character order 
                of a specified string is reversed

 Parameters:
      Expression = The expression argument is the string whose 
                   characters are to be reversed. If expression 
                   is a zero-length string (""), a zero-length 
                   string is returned. If expression is null,
                   false is returned.

 Returns: String
***************************************************************/
function ReverseString(Expression)
{
	if (Expression == null)
		return (false);

    var dest = '';
    for (var i = (Expression.length - 1); i >= 0; i--)
		dest = dest + Expression.charAt(i);
    return dest;
}

/**************************************************************
 StrConv: Returns a String converted as specified in the
          Parameters Section.

 Parameters:
      String     = String expression to be converted.
      Conversion = Number specifying the type of conversion 
                   to perform.
                   1 = TO UPPER CASE
                   2 = to lower case
                   3 = To Proper Case
                   If Conversion is null or not specified 1
                   is set as default.

 Returns: String
***************************************************************/
function StrConv(String, Conversion)
{
	var index;
	var tmpStr;
	var tmpChar;
	var preString;
	var postString;
	var strlen;

	if (Conversion == null || Conversion.length == 0)
		Conversion = '1';

	if (Conversion != '1' && Conversion != '2' && Conversion != '3')
		Conversion = '1';

	if (Conversion == '1')
		return String.toUpperCase();

	if (Conversion == '2')
		return String.toLowerCase();

	//Proper Case
	tmpStr = String.toLowerCase();
	strLen = tmpStr.length;
	if (strLen > 0)
	{
		for (index = 0; index < strLen; index++)
		{
			if (index == 0)
			{
				tmpChar = tmpStr.substring(0, 1).toUpperCase();
				postString = tmpStr.substring(1, strLen);
				tmpStr = tmpChar + postString;
			}
			else
			{
				tmpChar = tmpStr.substring(index, index + 1);
				if (tmpChar == " " && index < (strLen - 1))
				{
					tmpChar = tmpStr.substring(index + 1, index + 2).toUpperCase();
					preString = tmpStr.substring(0, index + 1);
					postString = tmpStr.substring(index + 2,strLen);
					tmpStr = preString + tmpChar + postString;
				}
			}
		}
	}
	return tmpStr;
}

/**************************************************************
 ComboAdd: Add a new item to a SELECT HTML object at runtime.

 Parameters:
      Object = SELECT Object ID
      Value  = Value of the String ... <option VALUE="?????">....</option>
      String = String to add.

 Returns: None
***************************************************************/
function ComboAdd(Object, Value, String)
{
	Value = Trim(Value)
	String = Trim(String)

	if (Value.length < 1 || String.length < 1)
		return false

	Object[Object.length] = new Option(String, Value);
	Object.selectedIndex = Object.length;
}

/**************************************************************
 ComboDel: Delete the current/selected item from a SELECT 
           HTML object at runtime.

 Parameters:
      Object = SELECT Object ID

 Returns: None
***************************************************************/
function ComboDel(Object)
{
	var selected_index = Object.selectedIndex
	if (selected_index >= 0)
	{
		Object.options[Object.selectedIndex] = null;
		if (selected_index > 0)
			Object.selectedIndex = selected_index
		else
			Object.selectedIndex = 0;
	}
}


/**************************************************************
 Borra TODAS las opciones de un COMBO y agregar una 
 -Sin Selección-
***************************************************************/
function ComboDelAll(Object)
{
	try {
		nHijos = Object.children.length
		for (var i=0; i < nHijos; i++)
		{	
			Object.selectedIndex = 0;
			nIndex = Object.selectedIndex;
			Object.options[nIndex] = null;	
		}
		Object.innerHTML = "";
		Object.innerText = "";
		ComboAdd(Object, "0","-Sin Seleccion-");
	} catch(e)
	  {
		e.description = " ComboDelAll() - " + e.description ;
		throw e;
	  }	
}


/**************************************************************
 FormatNumber: Returns an expression formatted as a number.

 Parameters:
      Expression            = Expression to be formatted.
      NumDigitsAfterDecimal = Numeric value indicating how
                              many places to the right of the
                              decimal are displayed.

 Returns: String
***************************************************************/
function FormatNumber(Expression, NumDigitsAfterDecimal)
{
	var iNumDecimals = NumDigitsAfterDecimal;
	var dbInVal = Expression;
	var bNegative = false;
	var iInVal = 0;
	var strInVal
	var strWhole = "", strDec = "";
	var strTemp = "", strOut = "";
	var iLen = 0;

	if (dbInVal < 0)
	{
		bNegative = true;
		dbInVal *= -1;
	}

	dbInVal = dbInVal * Math.pow(10, iNumDecimals)
	iInVal = parseInt(dbInVal);
	if ((dbInVal - iInVal) >= .5)
	{
		iInVal++;
	}
	strInVal = iInVal + "";
	strWhole = strInVal.substring(0, (strInVal.length - iNumDecimals));
	strDec = strInVal.substring((strInVal.length - iNumDecimals), strInVal.length);
	while (strDec.length < iNumDecimals)
	{
		strDec = "0" + strDec;
	}
	iLen = strWhole.length;
	if (iLen >= 3)
	{
		while (iLen > 0)
		{
			strTemp = strWhole.substring(iLen - 3, iLen);
			if (strTemp.length == 3)
			{
				strOut = "," + strTemp + strOut;
				iLen -= 3;
			}
			else
			{
				strOut = strTemp + strOut;
				iLen = 0;
			}
		}
		if (strOut.substring(0, 1) == ",")
		{
			strWhole = strOut.substring(1, strOut.length);
		}
		else
		{
			strWhole = strOut;
		}
	}
	if (bNegative)
	{
		return "-" + strWhole + "." + strDec;
	}
	else
	{
		return strWhole + "." + strDec;
	}
}

/**************************************************************
 FormatCurrency: Returns an expression formatted as a currency 
                 value using the currency symbol $.

 Parameters:
      Expression = Expression to be formatted.

 Returns: String
***************************************************************/
function FormatCurrency(Expression)
{
	var iNumDecimals = 2;
	var dbInVal = Expression;
	var bNegative = false;
	var iInVal = 0;
	var strInVal
	var strWhole = "", strDec = "";
	var strTemp = "", strOut = "";
	var iLen = 0;

	if (dbInVal < 0)
	{
		bNegative = true;
		dbInVal *= -1;
	}

	dbInVal = dbInVal * Math.pow(10, iNumDecimals)
	iInVal = parseInt(dbInVal);
	if ((dbInVal - iInVal) >= .5)
	{
		iInVal++;
	}
	strInVal = iInVal + "";
	strWhole = strInVal.substring(0, (strInVal.length - iNumDecimals));
	strDec = strInVal.substring((strInVal.length - iNumDecimals), strInVal.length);
	while (strDec.length < iNumDecimals)
	{
		strDec = "0" + strDec;
	}
	iLen = strWhole.length;
	if (iLen >= 3)
	{
		while (iLen > 0)
		{
			strTemp = strWhole.substring(iLen - 3, iLen);
			if (strTemp.length == 3)
			{
				strOut = "," + strTemp + strOut;
				iLen -= 3;
			}
			else
			{
				strOut = strTemp + strOut;
				iLen = 0;
			}
		}
		if (strOut.substring(0, 1) == ",")
		{
			strWhole = strOut.substring(1, strOut.length);
		}
		else
		{
			strWhole = strOut;
		}
	}
	if (bNegative)
	{
		return "-$" + strWhole + "." + strDec;
	}
	else
	{
		return "$" + strWhole + "." + strDec;
	}
}

/**************************************************************
 FormatPercent: Returns an expression formatted as a 
                percentage (multipled by 100) with a 
                trailing % character

 Parameters:
      Expression = Expression to be formatted.

 Returns: String
***************************************************************/
function FormatPercent(Expression, NumDigitsAfterDecimal)
{
	var iNumDecimals = NumDigitsAfterDecimal;
	var dbInVal = Expression * 100;
	var bNegative = false;
	var iInVal = 0;
	var strInVal
	var strWhole = "", strDec = "";
	var strTemp = "", strOut = "";
	var iLen = 0;

	if (dbInVal < 0)
	{
		bNegative = true;
		dbInVal *= -1;
	}

	dbInVal = dbInVal * Math.pow(10, iNumDecimals)
	iInVal = parseInt(dbInVal);
	if ((dbInVal - iInVal) >= .5)
	{
		iInVal++;
	}
	strInVal = iInVal + "";
	strWhole = strInVal.substring(0, (strInVal.length - iNumDecimals));
	strDec = strInVal.substring((strInVal.length - iNumDecimals), strInVal.length);
	while (strDec.length < iNumDecimals)
	{
		strDec = "0" + strDec;
	}
	iLen = strWhole.length;
	if (iLen >= 3)
	{
		while (iLen > 0)
		{
			strTemp = strWhole.substring(iLen - 3, iLen);
			if (strTemp.length == 3)
			{
				strOut = "," + strTemp + strOut;
				iLen -= 3;
			}
			else
			{
				strOut = strTemp + strOut;
				iLen = 0;
			}
		}
		if (strOut.substring(0, 1) == ",")
		{
			strWhole = strOut.substring(1, strOut.length);
		}
		else
		{
			strWhole = strOut;
		}
	}
	if (bNegative)
	{
		return "-" + strWhole + "." + strDec + "%";
	}
	else
	{
		return strWhole + "." + strDec + "%";
	}
}

/**************************************************************
 FormatDateTime: Returns an expression formatted as a date or 
                 time. If DateTime is null then false is
                 returned.

 Parameters:
      DateTime   = Date/Time expression to be formatted
      FormatType = Numeric value that indicates the date/time 
                   format used. If omitted, GeneralDate is used
                   0 = Very Long Date/Time Format (Mon Jul 10, 12:02:30 am EDT 2000)
                   1 = Long Date/Time Format (Monday, July 10, 2000)
                   2 = Short Date (1/10/00)
                   3 = Long Time (4:20 PM)
                   4 = Military Time (14:43)

 Returns: String
***************************************************************/
function FormatDateTime(DateTime, FormatType)
{
	if (DateTime == null)
		return (false);

	if (FormatType < 0)
		FormatType = 1;

	if (FormatType > 4)
		FormatType = 1;

	var strDate = new String(DateTime);

	if (strDate.toUpperCase() == "NOW")
	{
		var myDate = new Date();
		strDate = String(myDate);
	}
	else
	{
		var myDate = new Date(DateTime);
		strDate = String(myDate);
	}

	var Day = new String(strDate.substring(0, 3));
	if (Day == "Sun") Day = "Sunday";
	if (Day == "Mon") Day = "Monday";
	if (Day == "Tue") Day = "Tuesday";
	if (Day == "Wed") Day = "Wednesday";
	if (Day == "Thu") Day = "Thursday";
	if (Day == "Fri") Day = "Friday";
	if (Day == "Sat") Day = "Saturday";	

	var Month = new String(strDate.substring(4, 7)), MonthNumber = 0;
	if (Month == "Jan") { Month = "January"; MonthNumber = 1; }
	if (Month == "Feb") { Month = "February"; MonthNumber = 1; }
	if (Month == "Mar") { Month = "March"; MonthNumber = 1; }
	if (Month == "Apr") { Month = "April"; MonthNumber = 1; }
	if (Month == "May") { Month = "May"; MonthNumber = 1; }
	if (Month == "Jun") { Month = "June"; MonthNumber = 1; }
	if (Month == "Jul") { Month = "July"; MonthNumber = 1; }
	if (Month == "Aug") { Month = "August"; MonthNumber = 1; }
	if (Month == "Sep") { Month = "September"; MonthNumber = 1; }
	if (Month == "Oct") { Month = "October"; MonthNumber = 1; }
	if (Month == "Nov") { Month = "November"; MonthNumber = 1; }
	if (Month == "Dec") { Month = "December"; MonthNumber = 1; }

	var curPos = 11;
	var MonthDay = new String(strDate.substring(8, 10));
	if (MonthDay.charAt(1) == " ")
	{
		MonthDay = "0" + MonthDay.charAt(0);
		curPos--;
	}	

	var MilitaryTime = new String(strDate.substring(curPos, curPos + 5));
	var Year = new String(strDate.substring(strDate.length - 4, strDate.length));

	// Format Type decision time!
	if (FormatType == 1)
		strDate = Day + ", " + Month + " " + MonthDay + ", " + Year;
	else if (FormatType == 2)
		strDate = MonthNumber + "/" + MonthDay + "/" + Year.substring(2,4);
	else if (FormatType == 3)
	{
		var AMPM = MilitaryTime.substring(0,2) >= 12 && MilitaryTime.substring(0,2) != "24" ? " PM" : " AM";
		if (MilitaryTime.substring(0,2) > 12)
			strDate = (MilitaryTime.substring(0,2) - 12) + ":" + MilitaryTime.substring(3,MilitaryTime.length) + AMPM;
		else
		{
			if (MilitaryTime.substring(0,2) < 10)
				strDate = MilitaryTime.substring(1,MilitaryTime.length) + AMPM;
			else
			strDate = MilitaryTime + AMPM;
		}
	}	
	else if (FormatType == 4)
		strDate = MilitaryTime;

	return strDate;
}

/**************************************************************
 Mask: Returns a Boolean if the specified Expression match
       the specified Mask.

 Parameters:
      Expression = String to validate
      Mask       = String that can contain the following
                   options:
                   9 = only numbers (0..9)
                   X = only letters (a..z or A..Z)
                   * = Anything...
 Example: alert(Mask("(954) 572-4419", "(999) 999-9999")); => TRUE
          alert(Mask("33351-820", "99999-9999"));          => FALSE
          alert(Mask("This is a test", "XXXXXX"));         => FALSE
          alert(Mask("This 34 a test", "**************")); => TRUE

 Returns: Boolean
***************************************************************/
function Mask(Expression, Mask)
{
	Mask = Mask.toUpperCase();
	LenStr = Expression.length;
	LenMsk = Mask.length;
	if ((LenStr == 0) || (LenMsk == 0))
		return (false);
	if (LenStr != LenMsk)
		return (false);
	TempString = '';
	for (Count = 0; Count <= Expression.length; Count++)
	{
		StrChar = Expression.substring(Count, Count + 1);
		MskChar = Mask.substring(Count, Count + 1);
		if (MskChar == '9')
		{
			if(!IsNumber(StrChar))
				return (false);
		}
		else if (MskChar == 'X')
		{
			if(!IsChar(StrChar))
				return (false);
		}
		else if (MskChar == '*')
		{
			if(!IsAlphanumeric(StrChar))
				return (false);
		}
		else
		{
			if (MskChar != StrChar) 
				return (false);
		}
	}
	return (true);
}

/**************************************************************
 IsEmail: Returns a Boolean if the specified Expression is a
          valid e-mail address. If Expression is null, false
          is returned.

 Parameters:
      Expression = e-mail to validate.

 Returns: Boolean
***************************************************************/
function IsEmail(Expression)
{
	if (Expression == null)
		return (false);

	var supported = 0;
	if (window.RegExp)
	{
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
	}
	if (!supported) 
		return (Expression.indexOf(".") > 2) && (Expression.indexOf("@") > 0);
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(Expression) && r2.test(Expression));
}

/**************************************************************
 DayOfWeek: Returns a String specifying a name of the day
            for a given date.

 Parameters:
      dDate = Date to evaluate. The Date can be one of the
              following formats: '7/6/2000' or 'July 4, 1830'

 Returns: String
***************************************************************/
function DayOfWeek(dDate)
{
	var ar = new Array();
	ar[0] = "Domingo";   ar[1] = "Lunes"; ar[2] = "Martes";  ar[3] = "Miercoles";
	ar[4] = "Jueves";	ar[5] = "Viernes"; ar[6] = "Sabado";
	var dow = new Date(dDate);
	var day = dow.getDay();
	return ar[day];
}

/**************************************************************
 AddDays: Returns a Date containing a date to which a 
          specified days interval has been added to the
          current date.

 Parameters:
      DaysToAdd = Numeric expression that is the interval of 
                  days you want to add to the actual date.

 Returns: Date/String
***************************************************************/
function AddDays(DaysToAdd)
{
	var newdate = new Date();
	var newtimems = newdate.getTime() + (DaysToAdd * 24 * 60 * 60 * 1000);
	newdate.setTime(newtimems);
	return newdate.toLocaleString();
}

/**************************************************************
 AllowOnly: This function allow entering just the specified
            Expression to a textbox or textarea control.

 Parameters:
      Expression = Allowed characters.
                   a..z => ONLY LETTERS
                   0..9 => ONLY NUMBERS
                   other symbols...

 Example: use the onKeyPress event to make this function work:
          //Allows only from A to Z
          onKeyPress="AllowOnly('a..z');"

          //Allows only from 0 to 9
          onKeyPress="AllowOnly('0..9');"

          //Allows only A,B,C,1,2 and 3
          onKeyPress="AllowOnly('abc123');"

          //Allows only A TO Z,@,#,$ and %
          onKeyPress="AllowOnly('a..z|@#$%');"

		  //Allows only A,B,C,0 TO 9,.,,,+ and -
          onKeyPress="AllowOnly('ABC|0..9|.,+-');"

 Remarks: Use the pipe "|" symbol to separate a..z from 0..9 and symbols

 Returns: None
***************************************************************/
function AllowOnly(Expression)
{
	Expression = Expression.toLowerCase();
	Expression = Replace(Expression, 'a..z', 'abcdefghijklmnopqrstuvwxyz');
	Expression = Replace(Expression, '0..9', '0123456789');
	Expression = Replace(Expression, '|', '');

	var ch = String.fromCharCode(window.event.keyCode);
	ch = ch.toLowerCase();
	Expression = Expression.toLowerCase();
	var a = Expression.indexOf(ch);
	if (a == -1) 
		window.event.keyCode = 0;
}

/**************************************************************
 LeapYear: Return a Boolean if the speficied Year is a Leap
           Year

 Parameters:
      Year = Numeric expression that represents the Year.

 Returns: Boolean
***************************************************************/
function LeapYear(Year)
{    
	if(Year % 4 == 0 && Year % 100 != 0 || Year % 400 ==0)
		return true;
	return false;
}

/**************************************************************
 GeneratePopupMenu: Defines a new MENU for the right-click
                    event. The arrMenu 'array' must have the
                    following syntax:
                    arrMenu('<tool_tip>'|'<function_to_call OR javascript_code>'|'<menu_string'>)

 Parameters:
      arrMenu  = Array containing the NEW menu
      FontFace = The font name (ie: Tahoma, Times New, Helvetica, etc).
                 If FontFace is blank ('') or ('default') Tahoma
                 font will be used
      FontSize = The font size (8, 9, 12, 24, etc). If FontSize
	             is blank ('') or ('default') font size 8
	             will be used

 Returns: Nothing

 Remarks: - This menu works only with IE 4.01+
          - Use <HR> to separate items in the menu

 Example:
 [body]
	[script language=javascript]
	var arrM = new Array()
	arrM[0] = 'Cancel the current Order|btnCancelOrder_OnClick()|Cancel Order'
	arrM[1] = 'Refresh the Current page|window.location.reload()|Refresh Order'
	arrM[2] = '<hr>'
	arrM[3] = 'Search Products by Category|SearchProducts()|Search Products'
	arrM[4] = '<hr>'
	arrM[5] = 'Display the Agency Order History|AgencyOrderHistory()|Order History'
	arrM[6] = 'Shows the Agency Information|AgencyInfo()|Show Agency Info'
	arrM[7] = 'Add a new Agent to the Database|AddNewAgent()|Add New Agent'
	arrM[8] = '<hr>'
	arrM[9] = 'Enter your Name|var a=prompt("Enter your Name:");showName(a)|Enter Name'
	arrM[10] = '<hr>'
	arrM[11] = 'Close this menu...|alert("This menu will be closed")|Close this Menu'

	GeneratePopupMenu(arrM, '', '')

	function showName(a)
	{
		//This function will be called from the Popup menu//
		alert('Hello' + a);
	}
	[/script]
 [/body]
***************************************************************/
function GeneratePopupMenu(arrMenu, FontFace, FontSize)
{
	var strTemp = ''
	var A = new Array()

	if (FontFace.length == 0 || FontFace == '' || FontFace.toLowerCase() == 'default')
		FontFace = "Tahoma"

	if (FontSize.length == 0 || FontSize == 0 || FontSize == '' || FontSize.toLowerCase() == 'default')
		FontSize = "8"

	var line_step = ((FontSize * 16) / 8)

	document.write('<style>')
	document.write('#MainMenu {border-top: 1px solid #D4D0C8; border-left: 1px solid LightGrey; border-right: 1px solid Black; border-bottom: 1px solid Black; position: absolute; visibility: hidden}')
	document.write('.MenuItem {border-top: 1px solid White; border-left: 1px solid White; border-right: 1px solid Gray; border-bottom: 1px solid Gray; line-height: ' + line_step + 'px; padding-left: 15px; padding-right: 15px; font-family: ' + FontFace + '; font-size: ' + FontSize + 'pt; background-color: #D4D0C8}')
	document.write('</style>')

	strTemp = "<div id='MainMenu' bgcolor='#D4D0C8'>"
	strTemp = strTemp + "<table border='0' bgcolor='#D4D0C8' cellpadding='0' cellspacing='0' class='MenuItem' valign='top'>"

	for (var I = 0; I <= UBound(arrMenu); I++)
	{
		A = Split(arrMenu[I], "|")
		if (A[0].toLowerCase() != "<hr>")
		{
			strTemp = strTemp + "<tr><td valign='top' onmouseover='highlight()' onmouseout='lowlight()' style='cursor: hand' "
			strTemp = strTemp + " toolTip='" + A[0] + "'"
			strTemp = strTemp + " onClick='javascript:{HideMenu();" + A[1] + "}'>"
			strTemp = strTemp + A[2] + ""
			strTemp = strTemp + "</td></tr>"
		}
		else
		{
			strTemp = strTemp + "<tr><td style='height: 3px; cursor: normal'></td></tr>"
			strTemp = strTemp + "<tr><td bgcolor=gray style='height: 1px; cursor: normal'></td></tr>"
			strTemp = strTemp + "<tr><td bgcolor=white style='height: 1px; cursor: normal'></td></tr>"
			strTemp = strTemp + "<tr><td style='height: 3px; cursor: normal'></td></tr>"
		}
	}

	strTemp = strTemp + "</table></div>"

	document.write(strTemp)

	document.oncontextmenu = DisplayMenu
	if (document.all && window.print)
		document.body.onclick = HideMenu

	return true
}

function highlight()
{
	event.srcElement.style.background = "Navy" //<= change value to change background color
	event.srcElement.style.color = "White"     //<= change value to change fore color
	if (event.srcElement.toolTip != '')
		window.status = event.srcElement.toolTip
}

function lowlight()
{
	event.srcElement.style.backgroundColor = "#D4D0C8"
	event.srcElement.style.color = "Black"
	window.status = ''
}

function DisplayMenu()
{
	var rightedge = document.body.clientWidth - event.clientX
	var bottomedge = document.body.clientHeight - event.clientY

	if (rightedge < MainMenu.offsetWidth)
		MainMenu.style.left = document.body.scrollLeft + event.clientX - MainMenu.offsetWidth
	else
		MainMenu.style.left = document.body.scrollLeft + event.clientX

	if (bottomedge < MainMenu.offsetHeight)
		MainMenu.style.top = document.body.scrollTop + event.clientY - MainMenu.offsetHeight
	else
		MainMenu.style.top = document.body.scrollTop + event.clientY

	MainMenu.style.visibility = "visible"
	return false
}

function HideMenu()
{
	MainMenu.style.visibility = "hidden"
}

/**************************************************************
 IsDate: Returns a Boolean (true) if the date is true, false
         is not

 Parameters:
	- DateStr: String date in format (DD/MM/YYYY)

 Returns: Boolean
***************************************************************/
function IsDate(dateStr)
{
	// Checks for the following valid date formats:
	// DD/MM/YYYY   DD-MM-YYYY

	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

	var matchArray = dateStr.match(datePat)
	
	if (matchArray == null)
		return false

	month = matchArray[3]
	day = matchArray[1]
	year = matchArray[4]
	if (month < 1 || month > 12)
		return false

	if (day < 1 || day > 31)
		return false

	if ((month==4 || month==6 || month==9 || month==11) && day==31)
		return false

	if (month == 2)
	{
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))
		if (day>29 || (day==29 && !isleap))
			return false;
	}
	return true;
}

/**************************************************************
 CheckBoxes: Checks, unchecks or switch the values of the
             checkboxes in a form.

 Parameters:
    - f_form: String. Name of the Form <FORM...>
    - Start : Number: Checkbox to start with (0 to start from 
              the first one
    - Length: Number: How many checkboxes after the Start 
              you want to check, uncheck or switch
    - Method: Strign: c = Check, u = Uncheck, s = Switch

 Returns: None
***************************************************************/
function CheckBoxes(f_form, Start, Length, Method)
{
	var s_type = ''

	Method = Method.toLowerCase()

	if (Start == 0) {Start = 0} else {Start = Start - 1}
	if (Length == 0) {Length = f_form.elements.length}

	for (var i = Start; i < Start + Length; i++)
	{
		s_type = f_form.elements[i]
		if (s_type.type == 'checkbox')
		{
			if (Method == 'c')
				s_type.checked = true
			if (Method == 'u')
				s_type.checked = false
			if (Method == 's')
				s_type.checked = !s_type.checked
		}
	}

	return
}

/**************************************************************
 DateDiff: Returns the Difference between two dates in weeks,
           days, hours, minutes & seconds

 Parameters:
    - Date1: First Date
    - Date2: Second Data

 Returns: String containing the weeks, days, hours, minutes &
          seconds between the two dates.
***************************************************************/
function DateDiff(Date1, Date2)
{
	date1 = new Date();
	date2 = new Date();
	diff  = new Date();

	date1temp = new Date(Date1);
	date1.setTime(date1temp.getTime());
	date2temp = new Date(Date2);
	date2.setTime(date2temp.getTime());

	diff.setTime(Math.abs(date1.getTime() - date2.getTime()));
	timediff = diff.getTime();

	weeks = Math.floor(timediff / (1000 * 60 * 60 * 24 * 7));
	timediff -= weeks * (1000 * 60 * 60 * 24 * 7);

	days = Math.floor(timediff / (1000 * 60 * 60 * 24)); 
	timediff -= days * (1000 * 60 * 60 * 24);

	hours = Math.floor(timediff / (1000 * 60 * 60)); 
	timediff -= hours * (1000 * 60 * 60);

	mins = Math.floor(timediff / (1000 * 60)); 
	timediff -= mins * (1000 * 60);

	secs = Math.floor(timediff / 1000); 
	timediff -= secs * 1000;

	return (weeks + " weeks, " + days + " days, " + hours + " hours, " + mins + " minutes, and " + secs + " seconds");
}

/**************************************************************
 MinutesDiff: Returns the number of minutes between two dates.

 Parameters:
    - Date1: First date
    - Date2: Second data

 Returns: Number
***************************************************************/
function MinutesDiff(Date1, Date2)
{
	date1 = new Date();
	date2 = new Date();
	diff  = new Date();

	date1temp = new Date(Date1);
	date1.setTime(date1temp.getTime());

	date2temp = new Date(Date2);
	date2.setTime(date2temp.getTime());

	diff.setTime(Math.abs(date1.getTime() - date2.getTime()));
	timediff = diff.getTime();

	weeks = Math.floor(timediff / (1000 * 60 * 60 * 24 * 7));
	timediff -= weeks * (1000 * 60 * 60 * 24 * 7);

	days = Math.floor(timediff / (1000 * 60 * 60 * 24)); 
	timediff -= days * (1000 * 60 * 60 * 24);

	hours = Math.floor(timediff / (1000 * 60 * 60)); 
	timediff -= hours * (1000 * 60 * 60);

	mins = Math.floor(timediff / (1000 * 60)); 
	timediff -= mins * (1000 * 60);

	secs = Math.floor(timediff / 1000); 
	timediff -= secs * 1000;

	return (mins + (hours * 60) + (days * 24 * 60) + (weeks * 7 * 24 * 60))
}

function EnableDisable(strControlName)
	//'**************************************************************************************************************************
	//'Procedure: EnableDisable
	//'--------------------------------------------------------------------------------------------------------------------------
	//'Description:   Habilita o deshabilita un control Html
	//'--------------------------------------------------------------------------------------------------------------------------
	//'Parameters:
	//'				strControlName	(Nombre del control HTML a habilitar/deshabilitar)	 - Type:String
	//'--------------------------------------------------------------------------------------------------------------------------
	//'Return Type:   None
	//'--------------------------------------------------------------------------------------------------------------------------
	//'Author:        Ing. Mariano Surghy
	//'Date:          18-May-2001
	//'**************************************************************************************************************************

	
	{
		if (document.all.item(strControlName).disabled == true)
			document.all.item(strControlName).disabled = false;
		else
			document.all.item(strControlName).disabled = true;
	}
	
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//Floating

var dragswitch=0
var nsx
var nsy
var nstemp

function drag_dropns(strDivName){
temp=eval(strDivName)
temp.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP)
temp.onmousedown=gons
temp.onmousemove=dragns
temp.onmouseup=stopns
}

function gons(e){
temp.captureEvents(Event.MOUSEMOVE)
nsx=e.x
nsy=e.y
}
function dragns(e){
if (dragswitch==1){
temp.moveBy(e.x-nsx,e.y-nsy)
return false
}
}

function stopns(){
temp.releaseEvents(Event.MOUSEMOVE)
}


//drag drop function for IE 4+////
/////////////////////////////////

var dragapproved=false
var elementName
var global = window.document
global.top_shadows = new Array

function drag_dropie(){
if (dragapproved==true){
document.all.item(elementName).style.pixelLeft=tempx+event.clientX-iex
document.all.item(elementName).style.pixelTop=tempy+event.clientY-iey

return false
}
}

function initializedragie(strDivName){
iex=event.clientX
iey=event.clientY
tempx=document.all.item(strDivName).style.pixelLeft
tempy=document.all.item(strDivName).style.pixelTop

dragapproved=true
elementName=strDivName
document.onmousemove=drag_dropie

}


if (document.all){
document.onmouseup=new Function("dragapproved=false")
}


function makeRectangularShadow(el,color, size)
{
	
	var i;
	for (i=size; i>0; i--)
	{
		var rect = document.createElement('div');
		var elId=el.id;
		
		rect.name=elId + "Shadow"
		rect.id=elId + "Shadow"
		var rs = rect.style
		rs.position = 'absolute';
		rect.style.position="absolute";
		rs.left = (el.style.posLeft + i) + 'px';
		rs.top = (el.style.posTop + i) + 'px';
		rs.width = el.offsetWidth + 'px';
		rs.height = el.offsetHeight + 'px';
		el.style.zIndex=1;
		rs.zIndex = el.style.zIndex - 1;
		rs.backgroundColor = color;
		var opacity = 1 - i / (i + 1);
		rs.filter = 'alpha(opacity=' + (100 * opacity) + ')';
		el.insertAdjacentElement('afterEnd', rect);
		global.top_shadows[global.top_shadows.length] = rect;
	}
}

function removeShadow()
{
		var i
		for (i=0; i<global.top_shadows.length; i++)
			global.top_shadows[i].removeNode(true);
		global.top_shadows = new Array();
	
}


/*=================================================================
Function: ShowTooltip
Purpose:  position, draw, and display tooltip element 
Input:    fArg - indexes text array to display
Returns:  undefined
==================================================================*/
function ShowTooltip(fArg)
{

var tooltipOBJ = eval("document.all['tt" + fArg + "']");
var tooltipOffsetTop = tooltipOBJ.scrollHeight + 35;
var testTop = (document.body.scrollTop + event.clientY) - tooltipOffsetTop;
var testLeft = event.clientX - 250;
var tooltipAbsLft = (testLeft < 0) ? 10 : testLeft;
var tooltipAbsTop = (testTop < document.body.scrollTop) ? document.body.scrollTop + 10 : testTop;
tooltipOBJ.style.posLeft = tooltipAbsLft;
tooltipOBJ.style.posTop = tooltipAbsTop;
tooltipOBJ.style.visibility = "visible";
}
/*=================================================================
Function: HideTooltip
Purpose:  set visibility attribute of tooltip to hidden
Input:    none
Returns:  undefined
==================================================================*/
function HideTooltip(fArg)
{
var tooltipOBJ = eval("document.all['tt" + fArg + "']");
tooltipOBJ.style.visibility = "hidden";
}
	

/*=================================================================
Function: ShowTooltip
Purpose:  position, draw, and display tooltip element 
Input:    fArg - indexes text array to display
			strParams: Lista de parametros separadas por -|-
Returns:  undefined
==================================================================*/
function ShowHelpTooltip(fArg)
{
var tooltipOBJ = eval("document.all['Helptt" + fArg + "']");
var tooltipOffsetTop = tooltipOBJ.scrollHeight + 5;
var testTop = (document.body.scrollTop + event.clientY) - tooltipOffsetTop;
var testLeft = event.clientX- 200;
var tooltipAbsLft = (testLeft < 0) ? 10 : testLeft;
var tooltipAbsTop = (testTop < document.body.scrollTop) ? document.body.scrollTop + 10 : testTop;
tooltipOBJ.style.posLeft = tooltipAbsLft;
tooltipOBJ.style.posTop = tooltipAbsTop;
tooltipOBJ.style.visibility = "visible";
}
/*=================================================================
Function: HideHelpTooltip
Purpose:  set visibility attribute of tooltip to hidden
Input:    none
Returns:  undefined
==================================================================*/
function HideHelpTooltip(fArg)
{
var tooltipOBJ = eval("document.all['Helptt" + fArg + "']");
tooltipOBJ.style.visibility = "hidden";
}



//---------------------------------------------------------------
//-- Verifica si un valor tiene X decimales 
//---------------------------------------------------------------
function IsDecimal(strValue, strCantDeDecimales)
{
	if (strValue == null || strCantDeDecimales == null)
	{	alert('Falta especificar algúno de los parámetros !!!');
		return false;
	}	

	intPositionComa = InStr(Trim(strValue),",");
	
	if (intPositionComa > 0)
	{	alert("El valor pasado como parámetro debe contener el (.) como separador decimal.\nPor favor no pase (,) en el valor a validar !!!");
		return false;
	}

	//-------------------------------------------------------
	// posicion del punto decimal de izquierda a derecha
	//-------------------------------------------------------
	intPositionPoint = InStr(ReverseString(Trim(strValue)),".")-1
	
	//-------------------------------------------------------
	// No tiene punto decimal, lo valido como un entero
	//-------------------------------------------------------
	if (intPositionPoint < 0)													
	{	
		if (!IsInt(strValue) || !IsNumber(strValue))
		{	alert("El valor pasado como parámetro no tiene formato numérico !!!");
			return false;
		}
	}
	else
	{	if (intPositionPoint > strCantDeDecimales)
		{	alert("El valor pasado como parámetro tiene mas de [" + strCantDeDecimales + "] decimales !!!");
			return false;
		}
	}
	return true;	
}



///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function IsNatural(Expression)
{
	Expression = Expression.toLowerCase();
	RefString = "0123456789";
		
	if (Expression.length < 1) 
		return (false);

	for (var i = 0; i < Expression.length; i++) 
	{
		var ch = Expression.substr(i, 1)
		var a = RefString.indexOf(ch, 0)
		if (a == -1)
			return (false);
	}
	return(true);
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function IsCodigoProductoEsencias(Expression)
{
	Expression = Expression.toLowerCase();
	RefString = "0123456789/";
		
	if (Expression.length < 1) 
		return (false);

	for (var i = 0; i < Expression.length; i++) 
	{
		var ch = Expression.substr(i, 1)
		var a = RefString.indexOf(ch, 0)
		if (a == -1)
			return (false);
	}
	return(true);
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Pasamos un valor y redondea con la cantidad de decimales que tambien pasamos como parametro
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function Redondear(pnumber,decimals) 
{
  var strNumber = new String(pnumber);
  var arrParts = strNumber.split('.');
  var intWholePart = parseInt(arrParts[0],10);
  var strResult = '';
  if (isNaN(intWholePart))
    intWholePart = '0';
  if(arrParts.length > 1)
  {
    var decDecimalPart = new String(arrParts[1]);
    var i = 0;
    var intZeroCount = 0;
     while ( i < String(arrParts[1]).length )
     {
       if( parseInt(String(arrParts[1]).charAt(i),10) == 0 )
       {
         intZeroCount += 1;
         i += 1;
       }
       else
         break;
    }
    decDecimalPart = parseInt(decDecimalPart,10)/Math.pow(10,parseInt(decDecimalPart.length-decimals-1)); 
    Math.round(decDecimalPart); 
    decDecimalPart = parseInt(decDecimalPart)/10; 
    decDecimalPart = Math.round(decDecimalPart); 

    //If the number was rounded up from 9 to 10, and it was for 1 'decimal' 
    //then we need to add 1 to the 'intWholePart' and set the decDecimalPart to 0. 

    if(decDecimalPart==Math.pow(10, parseInt(decimals)))
    { 
      intWholePart+=1; 
      decDecimalPart="0"; 
    } 
    var stringOfZeros = new String('');
    i=0;
    if( decDecimalPart > 0 )
    {
      while( i < intZeroCount)
      {
        stringOfZeros += '0';
        i += 1;
      }
    }
    decDecimalPart = String(intWholePart) + "." + stringOfZeros + String(decDecimalPart); 
    var dot = decDecimalPart.indexOf('.');
    if(dot == -1)
    {
      decDecimalPart += '.'; 
      dot = decDecimalPart.indexOf('.'); 
    } 
    var l=parseInt(dot)+parseInt(decimals); 
    while(decDecimalPart.length <= l) 
    {
      decDecimalPart += '0'; 
    }
    strResult = decDecimalPart;
  }
  else
  {
    var dot; 
    var decDecimalPart = new String(intWholePart); 

    decDecimalPart += '.'; 
    dot = decDecimalPart.indexOf('.'); 
    var l=parseInt(dot)+parseInt(decimals); 
    while(decDecimalPart.length <= l) 
    {
      decDecimalPart += '0'; 
    }
    strResult = decDecimalPart;
  }
  return strResult;
}



function SetearImagen(oSource, strNameObjeto)
{
	var strNuevoSrc		= "";
	var strNuevoTitle	= "";
	var strObjetoDisplay= "document.getElementById('" + Trim(strNameObjeto) + "')"
	
	var miObjeto = eval(strObjetoDisplay)
	
	if (InStr(StrConv(Trim(oSource.src),1),"ARRIBA.GIF") > 0)
	{	strNuevoSrc   = Replace(StrConv(Trim(oSource.src),1), "ARRIBA.GIF", "ABAJO.GIF")
		strNuevoTitle = "Expandir la sección.";
		miObjeto.style.display = "none";
	}
	else
	{	strNuevoSrc	  = Replace(StrConv(Trim(oSource.src),1), "ABAJO.GIF", "ARRIBA.GIF");
		strNuevoTitle = "Contraer la sección.";
		miObjeto.style.display = "";
	}
		
	oSource.src		= strNuevoSrc;
	oSource.title	= strNuevoTitle;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function IsInt(Expression)
{
	Expression = Expression.toLowerCase();
	RefString = "0123456789-";
	
	if (Expression.length < 1) 
		return (false);

	for (var i = 0; i < Expression.length; i++) 
	{
		var ch = Expression.substr(i, 1)
		var a = RefString.indexOf(ch, 0)
		if (a == -1)
			return (false);
	}
	return(true);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function ValidarHora(oSource)
{
	var intHora = new Number(oSource.value);
	
	if (isNaN(intHora))
	{	alert("La hora debe ser un valor numérico !!!")
		oSource.focus();
		return false;
	}
	if (!(intHora >= 0 && intHora <= 23))
	{	alert("El valor para la hora debe estar comprendido entre las [00-23] hs !!!")
		oSource.focus();
		return false;
	}
	return true;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function ValidarMinutos(oSource)
{
	var intMinutos = new Number(oSource.value);
	
	if (isNaN(intMinutos))
	{	alert("El valor para los minutos deben ser numérico !!!")
		oSource.focus();
		return false;
	}
	  
	if (!(intMinutos >= 0 && intMinutos <= 59))
	{	alert("El valor para los minutos debe estar comprendido entre [00-59]  !!!")
		oSource.focus();
		return false;
	}
	return true;
}
