/* 
---------------------------------------------------------------------------------------------           
FUNCTION NAME: 	Trim
       AUTHOR:	WTS Web
  CREATE DATE: 	6/08/2001 
  DESCRIPTION: 	Remove blank spaces
---------------------------------------------------------------------------------------------
*/

function Trim(string)
{
  var i, resultado = "";
  if (string.length > 0)
  {
    i = 0;
    while (string.charAt(i) == " ") i++;
    resultado = string.substring(i);

    i = resultado.length - 1;
    if (i > -1)
    {
      while (resultado.charAt(i) == " ") i--;
      resultado = resultado.substring(0, i + 1);
    }
  }
  return (resultado);
}

/* 
<---------------------------------------------------------------------------------------------           
FUNCTION NAME:  ValidaEmpties
       AUTHOR:	Cynthia Muņoz
  CREATE DATE: 	6/08/2001 
  DESCRIPTION: 	
---------------------------------------------------------------------------------------------
*/
function ValidaEmpties(cadena, ObjectName, objecto)
{

  if (Trim(cadena)=="")
  {
    alert("No puede ser vacio el campo "+ ObjectName );
	objecto.focus();
  }  
}

/* 
<---------------------------------------------------------------------------------------------           
FUNCTION NAME:  Valida
       AUTHOR:	WTS Web
  CREATE DATE: 	6/08/2001 
  DESCRIPTION: 	Validates that mandatory fields have been entered. If you want to call this
				function write Valida(document), besides in any field you must write:
				'required valueDifferent="" caption=""'. Example:
				<input type="text" required valueDifferent="" caption="First Name"/> 
				
				To call the function:
				if (Valida(document)){			  
				}
				
---------------------------------------------------------------------------------------------
*/

function Valida(objDocument)
{
  var 
    objComp, 
	sStrMessage = "";
  for(i=0; i < objDocument.all.length; i++)    
  {
    objComp = objDocument.all[i];
    if(objComp.required != null)
	{
	  if(Trim(objComp.value) == objComp.valueDifferent)
	  {
	    sStrMessage += "\n     - " + objComp.caption ;
		}
    }
  }
  if(sStrMessage != "")
  {
    alert("Fields missing:" + sStrMessage);
	return false;
   }
  else
    return true;	
}

/* 
<---------------------------------------------------------------------------------------------           
FUNCTION NAME:  DisableComponents
       AUTHOR:	Cynthia Muņoz
  CREATE DATE: 	6/08/2001 
  DESCRIPTION: 	Enable or Disable all the components according to the parameter it receives 
				(TRUE o FALSE)
---------------------------------------------------------------------------------------------
*/

function DisableComponents(B_value)
{  
   for (var o=0; o<document.all.length; o++ ) 
    { 
       document.all[o].readOnly = B_value;        
      } 
   DisableOtherComponents(B_value);	  
}

/* 
<---------------------------------------------------------------------------------------------           
FUNCTION NAME:  Bisiesto
       AUTHOR:	WTS Web
  CREATE DATE: 	6/08/2001 
  DESCRIPTION: 	Verify if it is leaptyear (Bisiesto) or not                
---------------------------------------------------------------------------------------------
*/

function Bisiesto(year)
{
  return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
}

/* 
<---------------------------------------------------------------------------------------------           
FUNCTION NAME:  VerifyDate
       AUTHOR:	WTS Web
  CREATE DATE: 	6/08/2001 
  DESCRIPTION: 	Verify if the date has the right format               
---------------------------------------------------------------------------------------------
*/

function VerifyDate(sStrFecha)
{
  if (sStrFecha == "") return (true);
  var fecha = sStrFecha.split("/");
  if (fecha.length != 3) return (false);
  if (isNaN(fecha[0]) || isNaN(fecha[1]) || isNaN(fecha[2])) return (false);
  if (fecha[0].length > 2 || fecha[0].length < 1 ||
      fecha[1].length > 2 || fecha[1].length < 1 ||
      fecha[2].length != 4)
    return (false);

  var d = parseInt(fecha[0], 10),
      m = parseInt(fecha[1], 10),
      y = parseInt(fecha[2], 10);

  if (y < 1900 || m > 12 || m < 1 || d < 1) ;return (false);
  switch (m)
  {
    case 1: case 3: case 5: case 7: case 8: case 10: case 12:
	  if (d > 31) return (false)
	  break;
	case 2:
	  if (Bisiesto(y))
	  { if (d > 29) return (false) }
	  else if (d > 28)
	    return (false)
	  break;
	case 4: case 6: case 9: case 11:
	  if (d > 30) return (false)	  
	  break;
  }
  
  return (true);
}

/* 
<---------------------------------------------------------------------------------------------           
FUNCTION NAME:  CheckDate
       AUTHOR:	WTS Web
  CREATE DATE: 	6/08/2001 
  DESCRIPTION: 	Call the VerifyDate function and send a message if the date format is wrong 
  				It receives the date entered as parameter.
---------------------------------------------------------------------------------------------
*/
function CheckDate(sStrFecha)
{
  if (!VerifyDate(sStrFecha))
  {
    alert("The date you have enter was wrong! The format is Month/Day/Year and Year should be later than 1900.");
	if (event.srcElement != null)
	  event.srcElement.focus();
	return (false);
  }
  else
    return (true);
}

/*
<---------------------------------------------------------------------------------------------           
FUNCTION NAME:  VerifyTime
       AUTHOR:	WTS Web
  CREATE DATE: 	6/08/2001 
  DESCRIPTION: 	Verify if the time has the right format
---------------------------------------------------------------------------------------------
*/
function VerifyTime(strTime)
{
  if (strTime == "") return (true);
  var time = strTime.split(":");
  if (time.length < 2 || time.length > 3) return (false);
  if (time.length < 3) time[2] = "00";
  if (isNaN(time[0]) || isNaN(time[1]) || isNaN(time[2])) return (false);
  if (time[0].length > 2 || time[0].length < 1 ||
      time[1].length > 2 || time[1].length < 1 ||
      time[2].length > 2 || time[2].length < 1)
    return (false);

  var h = parseInt(time[0], 10),
      m = parseInt(time[1], 10),
      s = parseInt(time[2], 10);

  if (h < 0 || h > 23 || m < 0 || m > 59 || s < 0 || s > 59) return (false);
  return (true);
}


/* 
<---------------------------------------------------------------------------------------------           
FUNCTION NAME:  CheckTime
       AUTHOR:	WTS Web
  CREATE DATE: 	6/08/2001 
  DESCRIPTION: 	Call the VerifyTime function and send a message if the time format is wrong 
  				It receives the time entered as parameter.
---------------------------------------------------------------------------------------------
*/
function CheckTime(strTime)
{
  if (!VerifyTime(strTime))
  {
    alert("The time you have enter was wrong! The format is Hours:Minutes[:Seconds].");
    if (event.srcElement != null)
      event.srcElement.focus();
    return (false);
  }
  else
    return (true);
}

/*
<---------------------------------------------------------------------------------------------           
FUNCTION NAME:  VerifyDateTime
       AUTHOR:	WTS Web
  CREATE DATE: 	6/08/2001 
  DESCRIPTION: 	Verify if the datetime has the right format
---------------------------------------------------------------------------------------------
*/
function VerifyDateTime(strDateTime)
{
  if (strDateTime == "") return (true);
  if (strDateTime.indexOf(" ") == -1) return (false);
  var fecha = strDateTime.substring(0, strDateTime.indexOf(" ")),
      time = strDateTime.substring(strDateTime.indexOf(" ") + 1);
  return (VerifyDate(fecha) && VerifyTime(time));
}

/* 
<---------------------------------------------------------------------------------------------           
FUNCTION NAME:  CheckDateTime
       AUTHOR:	WTS Web
  CREATE DATE: 	6/08/2001 
  DESCRIPTION: 	Call the VerifyDateTime function and send a message if the time format is wrong 
  				It receives the DateTime entered as parameter.
---------------------------------------------------------------------------------------------
*/
function CheckDateTime(strDateTime)
{
  if (!VerifyDateTime(strDateTime))
  {
    alert("The date and time you have enter was wrong! The format is Month/Day/Year Hours:Minutes[:Seconds].");
    if (event.srcElement != null)
      event.srcElement.focus();
    return (false);
  }
  else 
    return (true);  
}


/* 
---------------------------------------------------------------------------------------------           
FUNCTION NAME: 	ValidateDateRange
       AUTHOR:	Cynthia Muņoz
  CREATE DATE: 	08/23/2001 
  DESCRIPTION: 	Validate Date Range returns True if the range is correct and 
                if it is not makes an alert and returns false
                
FUNCTION CALL:  ValidateDateRange("field name 1", date1 in string, "field name 2", date2 in string)
                if (!ValidateDateRange("DA From Date", document.all.Edt_FromDate.value, "DA To Date", document.all.Edt_ToDate.value))  
				  do something
---------------------------------------------------------------------------------------------
*/

function ValidateDateRange(sDateName1, sDate1, sDateName2, sDate2)
{
   if (Trim(sDate1) =="" || Trim(sDate2) =="")
     return true;
   	 
    var day1= sDate1.split("/");
    var day2= sDate2.split("/");
   /* var d1 = parseInt(day1[0], 10);
	var m1 = parseInt(day1[1], 10);
	var a1 = parseInt(day1[2], 10);
    var d2 = parseInt(day2[0], 10);
	var m2 = parseInt(day2[1], 10);
	var a2 = parseInt(day2[2], 10);*/
	//Debe recibir la fecha en formato de mes dia aņo
	var m1 = parseInt(day1[0], 10);
	var d1 = parseInt(day1[1], 10);
	var a1 = parseInt(day1[2], 10);
    var m2 = parseInt(day2[0], 10);
	var d2 = parseInt(day2[1], 10);
	var a2 = parseInt(day2[2], 10);
	
	if (a1 > a2)
	   {	    
      alert(sDateName1 + " cannot be greater than " + sDateName2);	  
		 return false;
	   }
	else if (a1 < a2 )
	  return true;
	else if (m1 > m2)  //si es el mismo aņo	  
	  {
	      alert(sDateName1 + " cannot be greater than " + sDateName2);	  
		  return false;
	}
	else if (m1 < m2) 
  return true;
	else if (d1 > d2)  
	  {
	      alert(sDateName1 + " cannot be greater than " + sDateName2);	  
		  return false;
      }
	else
	  return true; // si es el mismo dia o dias despues
}


/*--------------------------- Key Validations ------------------------------------------*/

/* 
<---------------------------------------------------------------------------------------------           
FUNCTION NAME:  ValidateKey
       AUTHOR:	Margarita Carbajal
  CREATE DATE: 	15/08/2001 
  DESCRIPTION: 	Validates the key characters according to the type of information you need.
                The parameter is the type of input you want to validate, it could be:
				INTEGER, REALNEG, INTEGERNEG, REAL, DATE, TIME, DATETIME
				For example: in the input write onkeypress="ValidateKey('INTEGER')  
---------------------------------------------------------------------------------------------
*/

function ValidateKey(sType) 
{
	if (sType == "PHONEFAX") {
		if ( (( window.event.keyCode < 48) || (window.event.keyCode > 57)) &&
		     (window.event.keyCode != 40) && (window.event.keyCode != 41) &&
			 (window.event.keyCode != 45) )
			window.event.keyCode = 0; 
	}

  //Katlim Ruiz 05/Feb/2002
  if (sType == "ALPHANUMERIC_WITH_SYMBOLS") {
    if ((( window.event.keyCode < 48) || (window.event.keyCode > 57)) &&
        (( window.event.keyCode < 97) || (window.event.keyCode > 122)) &&
        (( window.event.keyCode < 65) || (window.event.keyCode > 90)) &&
        //espacio & . - '
      ( window.event.keyCode != 32) && ( window.event.keyCode != 38) &&
      ( window.event.keyCode != 46) && ( window.event.keyCode != 45) &&
      ( window.event.keyCode != 39))
      window.event.keyCode = 0;
  }

    if (sType == "ALPHANUMERIC_WITH_DASH") {
    if ((( window.event.keyCode < 48) || (window.event.keyCode > 57)) &&
        (( window.event.keyCode < 97) || (window.event.keyCode > 122)) &&
        (( window.event.keyCode < 65) || (window.event.keyCode > 90)) &&
        //- 
        ( window.event.keyCode != 45)) 
      window.event.keyCode = 0;
  }

	if (sType == "ALFANUMERICO") { 
		if ((( window.event.keyCode < 48) || (window.event.keyCode > 57)) &&
		    (( window.event.keyCode < 97) || (window.event.keyCode > 122)) &&				
		    (( window.event.keyCode < 65) || (window.event.keyCode > 90)))
			window.event.keyCode = 0; 		
	}
	
	if (sType == "ALFANUMERICO_WITH_BLANKS") { 
		if ((( window.event.keyCode < 48) || (window.event.keyCode > 57)) &&
		    (( window.event.keyCode < 97) || (window.event.keyCode > 122)) &&				
		    (( window.event.keyCode < 65) || (window.event.keyCode > 90)) &&
			( window.event.keyCode != 32))
			window.event.keyCode = 0; 		
	}
		
	if (sType == "INTEGER") {
		if (( window.event.keyCode < 48) || (window.event.keyCode > 57))
			window.event.keyCode = 0; 
	}

	if (sType == "REALNEG")
	{
		var sStr = window.event.srcElement.value,
		pd = sStr.indexOf("."),
		sMenos = sStr.indexOf("-"),
		key = window.event.keyCode;

		if (key == 46)
        {
			if ((pd > -1) || (ssStr.length == (sMenos + 1)))
				window.event.keyCode = 0;
		}
		else if (key == 45)
		{
		if ((sMenos > -1) || (sStr.length > 0))
			window.event.keyCode = 0;
		}
		else if (( key < 48) || (key > 57))
			window.event.keyCode = 0;
	} 
	
	if (sType == "INTEGERNEG")
	{
		var sStr = window.event.srcElement.value,
		sMenos = sStr.indexOf("-"),
		key = window.event.keyCode;

		if (key == 45)
		{
			if ((sMenos > -1) || (sStr.length > 0))
				window.event.keyCode = 0;
		}
  		else if (( key < 48) || (key > 57))
    		window.event.keyCode = 0;	
	}
	
    if (sType == "REAL")
	{
		var pd = window.event.srcElement.value.indexOf("."),
		key = window.event.keyCode;

		if (key == 46)
		{
			if ((pd > -1) || (window.event.srcElement.value.length == 0))
				window.event.keyCode = 0;
		}
	else if (( key < 48) || (key > 57))
		window.event.keyCode = 0;
	}
	 
	if (sType == "DATE") 
	{
		if (((window.event.keyCode < 48) || (window.event.keyCode > 57)) && (window.event.keyCode != 47))
			window.event.keyCode = 0
	}     

	if (sType == "TIME")
	{
		if (((window.event.keyCode < 48) || (window.event.keyCode > 57)) && (window.event.keyCode != 58))
			window.event.keyCode = 0
	} 

	if (sType == "DATETIME")
	{
		if (((window.event.keyCode < 48) || (window.event.keyCode > 57)) &&
			(window.event.keyCode != 47) && (window.event.keyCode != 58) && (window.event.keyCode != 32))
			window.event.keyCode = 0   
	}

}


/* 
<---------------------------------------------------------------------------------------------           
FUNCTION NAME:  KeyUpperCase
       AUTHOR:	WTS Web
  CREATE DATE: 	6/08/2001 
  DESCRIPTION: 	Change to Upper Case
---------------------------------------------------------------------------------------------
*/
function KeyUpperCase()
{
  if ((window.event.keyCode >= 97) && (window.event.keyCode <= 122))
    window.event.keyCode = window.event.keyCode - 32;
  if (window.event.keyCode >= 209)
    window.event.keyCode = 241;
}


/*--------------------------- onBlur Validations ------------------------------------------
<---------------------------------------------------------------------------------------------           
FUNCTION NAME:  CheckNumber
       AUTHOR:	WTS Web
  CREATE DATE: 	16/08/2001 
  DESCRIPTION: 	Verifies if the numbers are correct. This function is called by the other ones.
---------------------------------------------------------------------------------------------
*/


function CheckNumber(str,valid,msg)
{
  if (Trim(str) != "")
  {
    for (var i=0; i < str.length; i++)
      if (valid.indexOf(str.charAt(i)) == -1)
      {
        alert(msg);
        //window.event.srcElement.value = "";
        window.event.srcElement.focus();
        return (false);
      }
  }
  return (true);
}

/*
<---------------------------------------------------------------------------------------------           
FUNCTION NAME:  CheckInteger
       AUTHOR:	WTS Web
  CREATE DATE: 	16/08/2001 
  DESCRIPTION: 	Verifies if the number you entered is integer
---------------------------------------------------------------------------------------------
*/
function CheckInteger(string)
{
  var valid = "0123456789",
  msg = "The value you have enter is not a positive integer number!";
  return (CheckNumber(string,valid,msg));
}


/*
<---------------------------------------------------------------------------------------------           
FUNCTION NAME:  CheckIntegerNeg
       AUTHOR:	WTS Web
  CREATE DATE: 	16/08/2001 
  DESCRIPTION: 	Verifies if the number you entered is integer negative
---------------------------------------------------------------------------------------------
*/
function CheckIntegerNeg(string)
{
  var valid = "0123456789-",
  msg = "The value you have enter is not a integer number!";
  return (CheckNumber(string,valid,msg));
}

/*
<---------------------------------------------------------------------------------------------           
FUNCTION NAME:  CheckReal
       AUTHOR:	WTS Web
  CREATE DATE: 	16/08/2001 
  DESCRIPTION: 	Verifies if the number you entered is real
---------------------------------------------------------------------------------------------
*/
function CheckReal(string)
{
  var valid = "0123456789.",
  msg = "The value you have enter is not a positive real number!";
  return (CheckNumber(string,valid,msg));
}

/*
<---------------------------------------------------------------------------------------------           
FUNCTION NAME:  CheckRealNeg
       AUTHOR:	WTS Web
  CREATE DATE: 	16/08/2001 
  DESCRIPTION: 	Verifies if the number you entered is real negative
---------------------------------------------------------------------------------------------
*/
function CheckRealNeg(string)
{
  var valid = "0123456789.-",
  msg = "The value you have enter is not a real number!";
  return (CheckNumber(string,valid,msg));
}

/* 
<---------------------------------------------------------------------------------------------           
FUNCTION NAME:  IsEmail
       AUTHOR:	Yehuda Shiran, Ph.D.  -  http://webreference.com/js/tips/990928.html
  CREATE DATE: 	16/08/2001 
  DESCRIPTION: 	Verify if it is a valid email address. It receives the string you entered
---------------------------------------------------------------------------------------------
*/
function IsEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.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(str) && r2.test(str));
}


/*
<---------------------------------------------------------------------------------------------           
FUNCTION NAME:  WriteHeader
       AUTHOR:	Neil Revilla
  CREATE DATE: 	21/08/2001 
  DESCRIPTION: 	Write header
---------------------------------------------------------------------------------------------
*/

function WriteHeader()
{
// primer parametro debe ser el titulo
// de ahi debe venir en pares el nombre del link y el link
	var arg = WriteHeader.arguments; 
	var sRoot = arg[2];
	var i;
	document.write("<table width='1004px' border='0' cellspacing='0' cellpadding='0'>");
//links aqui
	document.write("<tr class='titulo1'>");
	document.write("<td width='354'><img src='"+sRoot+"DW_IMAGES/tit01_02.gif'></td>");
	//document.write("<td bgcolor='#2F4C88' align='right' class='titulo1'>");
    document.write("<td  align='right'>");
	if (arg.length > 4 && (arg.length-1) % 2 == 0)
	{
		for (i=3; i < (arg.length - 1); i=i+2)
		{
			if (i!=3) {document.write("&nbsp;&nbsp;|&nbsp;&nbsp;")}
			document.write("<a target='_self' href='"+arg[i+1] + "?Date=" + (new Date()).valueOf() +"'>");
			document.write("<span class='titulo1'>"+arg[i]+"</span>");
			document.write("</a>");			
		}
	}	
	else
		document.write("&nbsp;");		
//    document.write("&nbsp;&nbsp;");
	document.write("</td>");
	document.write("</tr>");
//mensajes aqui
	document.write("<tr>");
	if (arg.length > 1)
	{	
		if (arg[1] != "")		
			document.write("<td><img src='"+sRoot+"DW_IMAGES/" + arg[1] +"'  ></td>")
		else
			document.write("<td bgcolor='#00ADEF'>&nbsp;</td>");	
	}	
	document.write("<td bgcolor='#00ADEF' align='right' class='titulo2'>");

	if (arg.length > 0)
		document.write(arg[0]+"&nbsp;&nbsp;")
	else
		document.write("&nbsp;");
	document.write("</td>");
	document.write("</tr>");
//linea dorada
	document.write("<tr style='height: 5px' bgcolor='#F9F402' >");
	document.write("<td colspan='2'></td>");
	document.write("</tr>");
	document.write("</table>");
}

function Send_Option(objName, CboName)
{ 
	Send_Security(objName, document.all(CboName).options[document.all(CboName).options.selectedIndex].value);
	
}                        
/*
<---------------------------------------------------------------------------------------------           
FUNCTION NAME:  PassAllSelectOptions
       AUTHOR:	Neil Revilla
  CREATE DATE: 	17/10/2001 
  DESCRIPTION: 	Function to pass all options from a Select to another Select.
---------------------------------------------------------------------------------------------
*/

function PassAllSelectOptions(obj1,obj2)
{ 
   for (var i=0;i<obj1.options.length;i++) 
     {
	   var oOption = document.createElement("OPTION");
	   obj2.options.add(oOption);
	   oOption.text = obj1.options[i].text;	   
	   oOption.value = obj1.options[i].value;		   	   	
	 }	
}

/*
<---------------------------------------------------------------------------------------------           
FUNCTION NAME:  Send_Security.
       AUTHOR:	Neil Revilla
  CREATE DATE: 	17/10/2001 
  DESCRIPTION: 	Function to be use width the Writeheader2 
---------------------------------------------------------------------------------------------
*/

function Send_Security(objName, Url)
{
	if (Url!="")
	{
	document.all(objName).action = Url;
	document.all(objName).submit();	
	}
	else
	{
	document.all("Cbo_SelectOpt").selectedIndex = 0;
	//options[0].selected = 1;
	}
}


/*
<---------------------------------------------------------------------------------------------           
FUNCTION NAME:  WriteHeader2
       AUTHOR:	Neil Revilla
  CREATE DATE: 	16/10/2001 
  DESCRIPTION: 	Write header
---------------------------------------------------------------------------------------------
*/

function WriteHeader2()
{
// primer parametro debe ser el titulo
// de ahi debe venir en pares el nombre del link y el link
	var arg = WriteHeader2.arguments; 
	var sRoot = arg[2];
	var i;
	var Security;
	document.write("<table width='1004px' border='0' cellspacing='0' cellpadding='0'>");
//links aqui
	document.write("<tr class='titulo1'>");
	document.write("<td width='354'><img src='"+sRoot+"DW_IMAGES/tit01_02.gif'></td>");
    document.write("<td  align='right'>");
	
	//ComboBox Options		
	document.write("<select class='fondo1' name=\""+"Cbo_SelectOpt"+"\" style=\""+"display:none"+"\" onchange='"+"Send_Option(\"" +arg[3]+ "\",\""+"Cbo_SelectOpt"+"\")"+"' style=\""+"width:160"+"\">");	
	document.write("</select>&nbsp;&nbsp;&nbsp;&nbsp;");
	
	//ReplaceOptions(document.all(arg[3]).Cbo_SelectOptions);	
	if (arg[4] == "options")
	  {
	  PassAllSelectOptions(document.all(arg[3]).Cbo_SelectOptions,Cbo_SelectOpt);
	  document.all("Cbo_SelectOpt").style.display = "";
	  }
	  
	if (arg.length > 6 && (arg.length-1) % 2 == 0)
	{
		for (i=5; i < (arg.length - 1); i=i+2)
		{   
			Security = arg[i+1];
			if (i!=5) {document.write("&nbsp;&nbsp;|&nbsp;&nbsp;")}			
			document.write("<a  href='"+"javascript: Send_Security(\"" +arg[3]+ "\",\""+ Security+"\")'>");			
			document.write("<span class='titulo1'>"+arg[i]+"</span>");
			document.write("</a>");			
		}
	}	
	else
		document.write("&nbsp;");		
//    document.write("&nbsp;&nbsp;");
	document.write("</td>");
	document.write("</tr>");
//mensajes aqui
	document.write("<tr>");
	if (arg.length > 1)
	{	
		if (arg[1] != "")		
			document.write("<td><img src='"+sRoot+"DW_IMAGES/" + arg[1] +"'  ></td>")
		else
			document.write("<td bgcolor='#00ADEF'>&nbsp;</td>");	
	}	
	document.write("<td bgcolor='#00ADEF' align='right' class='titulo2'>");

	if (arg.length > 0)
		document.write(arg[0]+"&nbsp;&nbsp;")
	else
		document.write("&nbsp;");
	document.write("</td>");
	document.write("</tr>");
//linea dorada
	document.write("<tr style='height: 5px' bgcolor='#F9F402' >");
	document.write("<td colspan='2'></td>");
	document.write("</tr>");
	document.write("</table>");
}





/*
<---------------------------------------------------------------------------------------------           
FUNCTION NAME:  Send_Security New.
       AUTHOR:	Neil Revilla
  CREATE DATE: 	19/12/2001 
  DESCRIPTION: 	Function to be use width the Writeheader3
---------------------------------------------------------------------------------------------
*/

function Send_Security_new(objName, Url, pMethod, pTaget)
{
	if (Url!="")
	{	
	document.all(objName).method = pMethod;
	document.all(objName).target = pTaget;
	
	document.all(objName).action = Url;
	document.all(objName).submit();	
	}
	else
	{
	document.all("Cbo_SelectOpt").selectedIndex = 0;
	}
}


/*
<---------------------------------------------------------------------------------------------           
FUNCTION NAME:  WriteHeader3
       AUTHOR:	Neil Revilla
  CREATE DATE: 	19/12/2001 
  DESCRIPTION: 	Write header
---------------------------------------------------------------------------------------------
*/

function WriteHeader3()
{
// primer parametro debe ser el titulo
// de ahi debe venir en pares el nombre del link y el link
	var arg = WriteHeader3.arguments; 
	var sRoot = arg[2];
	var i;
	var Security;
	document.write("<table width='1004px' border='0' cellspacing='0' cellpadding='0'>");
//links aqui
	document.write("<tr class='titulo1'>");
	document.write("<td width='354'><img src='"+sRoot+"DW_IMAGES/tit01_02.gif'></td>");
    document.write("<td  align='right'>");
	
	//ComboBox Options		
	document.write("<select class='fondo1' name=\""+"Cbo_SelectOpt"+"\" style=\""+"display:none"+"\" onchange='"+"Send_Option(\"" +arg[3]+ "\",\""+"Cbo_SelectOpt"+"\")"+"' style=\""+"width:160"+"\">");	
	document.write("</select>&nbsp;&nbsp;&nbsp;&nbsp;");
	
	//ReplaceOptions(document.all(arg[3]).Cbo_SelectOptions);	
	if (arg[4] == "options")
	  {
	  PassAllSelectOptions(document.all(arg[3]).Cbo_SelectOptions,Cbo_SelectOpt);
	  document.all("Cbo_SelectOpt").style.display = "";
	  }
	  
	if (arg.length > 6 && (arg.length-1) % 2 == 0)
	{
		for (i=5; i < (arg.length - 1); i=i+4)
		{   
			Security = arg[i+1];
			if (i!=5) {document.write("&nbsp;&nbsp;|&nbsp;&nbsp;")}			
			document.write("<a  href='"+"javascript: Send_Security_new(\"" +arg[3]+ "\",\""+ Security+"\",\""+ arg[i+2]+"\",\""+arg[i+3]+"\")'>");			
			document.write("<span class='titulo1'>"+arg[i]+"</span>");
			document.write("</a>");			
		}
	}	
	else
		document.write("&nbsp;");		
//    document.write("&nbsp;&nbsp;");
	document.write("</td>");
	document.write("</tr>");
//mensajes aqui
	document.write("<tr>");
	if (arg.length > 1)
	{	
		if (arg[1] != "")		
			document.write("<td><img src='"+sRoot+"DW_IMAGES/" + arg[1] +"'  ></td>")
		else
			document.write("<td bgcolor='#00ADEF'>&nbsp;</td>");	
	}	
	document.write("<td bgcolor='#00ADEF' align='right' class='titulo2'>");

	if (arg.length > 0)
		document.write(arg[0]+"&nbsp;&nbsp;")
	else
		document.write("&nbsp;");
	document.write("</td>");
	document.write("</tr>");
//linea dorada
	document.write("<tr style='height: 5px' bgcolor='#F9F402' >");
	document.write("<td colspan='2'></td>");
	document.write("</tr>");
	document.write("</table>");
}


/*
<---------------------------------------------------------------------------------------------           
FUNCTION NAME:  ReplaceText
       AUTHOR:	WTS Web
  CREATE DATE: 	23/08/2001 
  DESCRIPTION:  Replace text in the URL.
---------------------------------------------------------------------------------------------
*/

function ReplaceText(string)
{
  var result = "";
  for (var i=0; i < string.length; i++)
  {
    if (string.charAt(i) == " ") result += "%20"
    else if (string.charAt(i) == "!") result += "%21"
    else if (string.charAt(i) == "\"") result += "%22"
    else if (string.charAt(i) == "#") result += "%23"
    else if (string.charAt(i) == "%") result += "%24"
    else if (string.charAt(i) == "&") result += "%26"
    else if (string.charAt(i) == "@") result += "%40"
    else result += string.charAt(i);
  }
  return (result);
}

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_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_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;
}

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 NAME:  SelectCombo
       AUTHOR:	Cynthia Muņoz
  CREATE DATE: 	15/09/2001 
  DESCRIPTION:  Seleccionar una opcion segun un valor
---------------------------------------------------------------------------------------------
*/

function SelectCombo(oCombo, sValue)
{
  for (var i=0; i< oCombo.options.length;i++)
    {
	  if (oCombo.options(i).value==sValue)
	    {
		  oCombo.options(i).selected = 1;
		  return;
		}
	}
}


function FindTypeDelimiter(sRoot)
{ 
		sUrl = sRoot + "dw_finance/reports/rpt_0004//Delimiter.html"
		Ventana = window.showModalDialog(sUrl,window,"dialogHeight:180px;dialogWidth:160px;dialogTop:230px;dialogLeft:350px;status:1;help:0");
		document.all.Hdn_Delimiter.value = TypeDelimiter;
		if (TypeDelimiter == "")
		{
		    //alert("You should select a delimiter");
		    return false;
		}	
		return true;	
}	


function getDatetoSend()
{
	var currentDate = new Date();
	with(currentDate)
	  {  return getDate()+"/"+(getMonth()+1)+"/"+getYear()+" "+getHours()+":"+getMinutes()+":"+getSeconds();
	  }
}

/**
<---------------------------------------------------------------------------------------------           
FUNCTION NAME:  checkNumeric
       AUTHORS:	Nannette Thacker (http://www.shiningstar.net/articles/articles/javascript/checkNumeric.asp?ID=ROLLA)
	            Christian Morales   
  CREATE DATE: 	15/09/2001 
  DESCRIPTION:  Seleccionar una opcion segun un valor
---------------------------------------------------------------------------------------------
*/
function checkNumeric(objName, maxDec)
{
	var numberfield = objName;
	if (chkNumeric(objName, maxDec) == false)
	{
		numberfield.select();
		numberfield.focus();
		return false;
	}
	else
	{
		return true;
	}
}

/**
<---------------------------------------------------------------------------------------------           
FUNCTION NAME:  chkNumeric
       AUTHORS:	Nannette Thacker (http://www.shiningstar.net/articles/articles/javascript/checkNumeric.asp?ID=ROLLA)
	            Christian Morales   
  CREATE DATE: 	15/09/2001 
  DESCRIPTION:  Seleccionar una opcion segun un valor
---------------------------------------------------------------------------------------------
*/

function chkNumeric(objName, maxDec)
{
     // minval,maxval,(Was extracted by Christian Morales)
	// only allow 0-9 be entered, plus any values passed
	// (can be in any order, and don't have to be comma, period, or hyphen)
	// if all numbers allow commas, periods, hyphens or whatever,
	// just hard code it here and take out the passed parameters
	var checkOK = "-0123456789";
	var checkStr = objName;
	var allValid = true;
	var allNum = "";
	var negPos = 0;
	var isDecimal = false;
	
	for (i = 0;  i < checkStr.value.length;  i++)
	{
	  ch = checkStr.value.charAt(i);
	  for (j = 0;  j < checkOK.length;  j++)
	  {
		if (ch == checkOK.charAt(j))
		 break;
	  }	 
 	  if (ch == "-")
	  {
	    negPos = i;  
	  }
  	  if (j == checkOK.length) 
	  {
		allValid = false;
		break;
	  }
	  if (ch != ",")
		allNum += ch;
	}
	
	if (!allValid || negPos != 0)
	{	
		alertsay = "Please enter a valid number.";
		alert(alertsay);
		return false;
	}
/**	
 // set the minimum and maximum
	var chkVal = allNum;
	var prsVal = parseInt(allNum);
	if (chkVal != "" && !(prsVal >= minval && prsVal <= maxval))
	{
		alertsay = "Please enter a value greater than or "
		alertsay = alertsay + "equal to \"" + minval + "\" and less than or "
		alertsay = alertsay + "equal to \"" + maxval + "\" in the \"" + checkStr.name + "\" field."
		alert(alertsay);
		return (false);
	}
*/
}

/*function WriteSimpleISSHeader(pRoot,pTitle)
{
document.write("<table width='100%' border='0' cellspacing='0' cellpadding='0'>");
document.write("<tr>");
document.write("<td height='2'></td>");
document.write("<td rowspan='3' width='101'>");
document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0' width='101' height='89'>");
document.write("<param name='movie' value='"+pRoot+"DW_IMAGES/DW_ANIM/tangrams_cycle.swf'>");
document.write("<param name='quality' value='high'>");
document.write("<embed src='"+pRoot+"DW_IMAGES/DW_ANIM/tangrams_cycle.swf' quality='high' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width='101' height='89'>");
document.write("</embed>");
document.write("</object>");
document.write("</td>");
document.write("</tr>");
document.write("<tr>");
document.write("<td>");
document.write("<table border='0' cellspacing='0' cellpadding='0' width='100%'>");
document.write("<tr>");
document.write("<td width='93'><img src='"+pRoot+"DW_Images/yiss_01.gif' width='93' height='78'></td>");
document.write("<td background='"+pRoot+"DW_Images/yiss_04.gif'>");
document.write("<table width='100%' border='0' cellspacing='3' cellpadding='0'>");
document.write("<tr>");
document.write("<td><img src='"+pRoot+"DW_Images/yiss_05.gif' width='103' height='26'></td>");
document.write("</tr>");
document.write("<tr>");
document.write("<td class='titleISS'>"+pTitle+"</td>");
document.write("</tr>");
document.write("</table>");
document.write("</td>");
document.write("<td width='119'><img src='"+pRoot+"DW_Images/yiss_02.gif' width='119' height='78'></td>");
document.write("<td width='150' background='"+pRoot+"DW_Images/yiss_10.gif'>&nbsp;</td>");
document.write("</tr>");
document.write("</table>");
document.write("</td>");
document.write("</tr>");
document.write("<tr>");
document.write("<td height='4'></td>");
document.write("</tr>");
document.write("</table>");
}*/

function WriteSimpleISSHeader(pRoot,pTitle)
{
document.write("<table width='100%' border='0' cellspacing='0' cellpadding='0'>");
document.write("<tr>"); 
document.write("<td width='93'><img src='"+pRoot+"DW_Images/yiss_01.gif' width='93' height='78'></td>");
document.write("<td background='"+pRoot+"DW_Images/yiss_04.gif'>"); 
document.write("<table width='100%' border='0' cellspacing='3' cellpadding='0'>");
document.write("<tr>");
document.write("<td><img src='"+pRoot+"DW_Images/yiss_05.gif' width='103' height='26'></td>");
document.write("</tr>");
document.write("<tr>");
document.write("<td class='titleISS'>"+pTitle+"</td>");
document.write("</tr>");
document.write("</table>");
document.write("</td>");
document.write("<td width='119'><img src='"+pRoot+"DW_Images/yiss_02.gif' width='119' height='78'></td>");
document.write("<td width='125' background='"+pRoot+"DW_Images/yiss_10.gif'>&nbsp;</td>");
document.write("<td width='97'><img src='"+pRoot+"DW_Images/yiss_03.gif' width='97' height='78'></td>");
document.write("</tr>");
document.write("</table>");
}

function WriteDashBoardISSHeader(pRoot,pName,pSecurityFrmName)
{
document.write("<table width='100%' border='0' cellspacing='0' cellpadding='0'>");
document.write("<tr>"); 
document.write("<td width='93'><img src='"+pRoot+"DW_Images/yiss_01.gif' width='93' height='78'></td>");
document.write("<td background='"+pRoot+"DW_Images/yiss_04.gif'>"); 
document.write("<table width='100%' border='0' cellspacing='3' cellpadding='0'>");
document.write("<tr>");
document.write("<td><img src='"+pRoot+"DW_Images/yiss_05.gif' width='103' height='26'></td>");
document.write("</tr>");
document.write("<tr>");
document.write("<td class='titleISS'>Dashboard</td>");
document.write("</tr>");
document.write("</table>");
document.write("</td>");
document.write("<td width='119'><img src='"+pRoot+"DW_Images/yiss_02.gif' width='119' height='78'></td>");
document.write("<td width='125' background='"+pRoot+"DW_Images/yiss_10.gif' valign='top'>"); 
document.write("<table width='100%' border='0' cellspacing='0' cellpadding='0'>");
document.write("<tr>");
document.write("<td height='5'></td>");
document.write("</tr>");
document.write("<tr>");
document.write("<td>");
document.write("<div align='right'><a href='javascript: Send_Security_new(\""+pSecurityFrmName+"\",\""+pRoot+"dw_help/index.html\",\"get\",\"_blank\")' onMouseOut='MM_swapImgRestore()' onMouseOver='MM_swapImage(\"Help\",\"\",\""+pRoot+"DW_Images/yiss_06on.gif\",1)'><img name='Help' border='0' src='"+pRoot+"DW_Images/yiss_06.gif' width='59' height='14'></a></div>");
document.write("</td>");
document.write("</tr>");
document.write("<tr>");
document.write("<td>");
document.write("<div align='right'><a href='javascript: Send_Security_new(\""+pSecurityFrmName+"\",\""+pRoot+"dw_help/glossary.html\",\"get\",\"_blank\")' onMouseOut='MM_swapImgRestore()' onMouseOver='MM_swapImage(\"Glossary\",\"\",\""+pRoot+"DW_Images/yiss_07on.gif\",1)'><img name='Glossary' border='0' src='"+pRoot+"DW_Images/yiss_07.gif' width='59' height='14'></a></div>");
document.write("</td>");
document.write("</tr>");
document.write("<tr>");
document.write("<td>");
document.write("<div align='right'><a href='javascript: Send_Security_new(\""+pSecurityFrmName+"\",\""+pRoot+"dw_security/login_0001.dll/logout\",\"post\",\"_self\")' onMouseOut='MM_swapImgRestore()' onMouseOver='MM_swapImage(\"Logout\",\"\",\""+pRoot+"DW_Images/yiss_08on.gif\",1)'><img name='Logout' border='0' src='"+pRoot+"DW_Images/yiss_08.gif' width='59' height='14'></a></div>");
document.write("</td>");
document.write("</tr>");
document.write("<tr valign='bottom'>"); 
document.write("<td height='20'>"); 
document.write("<div align='right' class='welcomeISS' style='height:30px; overflow:hidden'><b>Welcome:</b> "+pName+"</div>");
document.write("</td>");
document.write("</tr>");
document.write("</table>");
document.write("</td>");
document.write("<td width='97'><img src='"+pRoot+"DW_Images/yiss_03.gif' width='97' height='78'></td>");
document.write("</tr>");
document.write("</table>");
}

function WritePagesISSHeader(pRoot,pTitle,pSecurityFrmName)
{
document.write("<table width='100%' border='0' cellspacing='0' cellpadding='0'>");
document.write("<tr>"); 
document.write("<td width='93'><img src='"+pRoot+"DW_Images/yiss_01.gif' width='93' height='78'></td>");
document.write("<td background='"+pRoot+"DW_Images/yiss_04.gif'>"); 
document.write("<table width='100%' border='0' cellspacing='3' cellpadding='0'>");
document.write("<tr>");
document.write("<td><img src='"+pRoot+"DW_Images/yiss_05.gif' width='103' height='26'></td>");
document.write("</tr>");
document.write("<tr>");
document.write("<td class='titleISS'>"+pTitle+"</td>");
document.write("</tr>");
document.write("</table>");
document.write("</td>");
document.write("<td width='119'><img src='"+pRoot+"DW_Images/yiss_02.gif' width='119' height='78'></td>");
document.write("<td width='125' background='"+pRoot+"DW_Images/yiss_10.gif' valign='top'>"); 
document.write("<table width='100%' border='0' cellspacing='0' cellpadding='0'>");
document.write("<tr>");
document.write("<td height='5'></td>");
document.write("</tr>");
document.write("<tr>");
document.write("<td>");
document.write("<div align='right'><a href='javascript: Send_Security_new(\""+pSecurityFrmName+"\",\""+pRoot+"dw_help/index.html\",\"get\",\"_blank\")' onMouseOut='MM_swapImgRestore()' onMouseOver='MM_swapImage(\"Help\",\"\",\""+pRoot+"DW_Images/yiss_06on.gif\",1)'><img name='Help' border='0' src='"+pRoot+"DW_Images/yiss_06.gif' width='59' height='14'></a></div>");
document.write("</td>");
document.write("</tr>");
document.write("<tr>");
document.write("<td>");
document.write("<div align='right'><a href='javascript: Send_Security_new(\""+pSecurityFrmName+"\",\""+pRoot+"dw_help/glossary.html\",\"get\",\"_blank\")' onMouseOut='MM_swapImgRestore()' onMouseOver='MM_swapImage(\"Glossary\",\"\",\""+pRoot+"DW_Images/yiss_07on.gif\",1)'><img name='Glossary' border='0' src='"+pRoot+"DW_Images/yiss_07.gif' width='59' height='14'></a></div>");
document.write("</td>");
document.write("</tr>");
document.write("<tr>");
document.write("<td>");
document.write("<div align='right'><a href='javascript: Send_Security_new(\""+pSecurityFrmName+"\",\""+pRoot+"dw_security/login_0001.dll/logout\",\"post\",\"_self\")' onMouseOut='MM_swapImgRestore()' onMouseOver='MM_swapImage(\"Logout\",\"\",\""+pRoot+"DW_Images/yiss_08on.gif\",1)'><img name='Logout' border='0' src='"+pRoot+"DW_Images/yiss_08.gif' width='59' height='14'></a></div>");
document.write("</td>");
document.write("</tr>");
document.write("<tr>");
document.write("<td>");
document.write("<div align='right'><a href='javascript: Send_Security_new(\""+pSecurityFrmName+"\",\""+pRoot+"dw_security/login_0001.dll/home\",\"post\",\"_self\")' onMouseOut='MM_swapImgRestore()' onMouseOver='MM_swapImage(\"youriss\",\"\",\""+pRoot+"DW_Images/yiss_09on.gif\",1)'><img name='youriss' border='0' src='"+pRoot+"DW_Images/yiss_09.gif' width='59' height='14'></a></div>");
document.write("</td>");
document.write("</tr>");
document.write("</table>");
document.write("</td>");
document.write("<td width='97'><img src='"+pRoot+"DW_Images/yiss_03.gif' width='97' height='78'></td>");
document.write("</tr>");
document.write("</table>");
}


/**
<---------------------------------------------------------------------------------------------           
FUNCTION NAME:  PassSelectedOption, getValuesFromOptions, SetDreams
       AUTHORS:	Neil Revilla  
  CREATE DATE: 	20/07/2002 
  DESCRIPTION:  Funciones para Uso de Dreams en los Reportes de Finanzas
---------------------------------------------------------------------------------------------
*/

	function PassSelectedOption(obj1,obj2)
    { 
     for (var i=0;i<obj1.options.length;i++) 
       if (obj1.options[i].selected)
	   	  {var oOption = document.createElement("OPTION");
	   	   obj2.options.add(oOption);
	       oOption.text = obj1.options[i].text;	   
	       oOption.value = obj1.options[i].value;		   	   	
		   }	
		   		   
	  for (var i=obj1.options.length-1;i>=0;i--) 
        if (obj1.options[i].selected) 
          obj1.remove(i);	    
    }
	
	function getValuesFromOptions(obj, cad, type)
    { var valor;
      var SelectedList; 
      SelectedList="";
	  valor="";  
	  
      if (obj.options.length > 0)
       {	    
        for (var i=0;i<obj.options.length;i++) 		      
	     {
           if (type=="text")
		     valor = obj.options[i].text
		   else
		     if (type=="value")
			   valor = obj.options[i].value; 
	       SelectedList = SelectedList + "*,*" + valor;	   
	     }
	   cad.value = SelectedList.substring(3);   		
	   return(true);
       }	 
       else
      return(false);	 
    }
		
   function SetDreams(Cb1, Cb2, Edt_Text, Edt_Value)
	{var cad;
      if (document.all.Cb_DreamSelected.options.length > 0) 
	  {
	    getValuesFromOptions(Cb2, Edt_Text,"text");
		getValuesFromOptions(Cb2, Edt_Value,"value");
	  }	
	  else  
	  {
	    getValuesFromOptions(Cb1, Edt_Text,"text");			
		getValuesFromOptions(Cb1, Edt_Value,"value");			
	  }	
	  
	  return;	
	}

	/*Call this function to format an string as the currency format*/
function formatValue(argvalue, format) 
{
 //recibe en string o numerico, sale en string 
  var numOfDecimal = 0;
  argvalue = DeleteCommas(argvalue);
  if (format.indexOf(".") != -1) 
  {
    if (isFieldWithValue(argvalue))
	  {
		  var firstChar = argvalue.substring(0, 1);  
		  if (firstChar == "-")
		     argvalue = argvalue.substring(1, argvalue.length);
       }
    numOfDecimal = format.substring(format.indexOf(".") + 1, format.length).length;
  argvalue = formatDecimal(argvalue, true, numOfDecimal);
  argvalueBeforeDot = argvalue.substring(0, argvalue.indexOf("."));
  retValue = argvalue.substring(argvalue.indexOf("."), argvalue.length);
    strBeforeDot = format.substring(0, format.indexOf(".")); //parte del formato antes del punto

	for (var n = strBeforeDot.length - 1; n >= 0; n--) 
	  {
    oneformatchar = strBeforeDot.substring(n, n + 1);
    if (oneformatchar == "#") {
      if (argvalueBeforeDot.length > 0) {
        argvalueonechar = argvalueBeforeDot.substring(argvalueBeforeDot.length - 1, argvalueBeforeDot.length);
        retValue = argvalueonechar + retValue;
        argvalueBeforeDot = argvalueBeforeDot.substring(0, argvalueBeforeDot.length - 1);
      }
    }
	    else if (argvalueBeforeDot.length > 0 || n == 0) 
        retValue = oneformatchar + retValue;
    }
    if (isFieldWithValue(argvalue))
	  {
         if (firstChar == "-")
         retValue = "-" + retValue;	  
	   }
  }
 else retValue = argvalue;
 

 return retValue;
}

function DeleteCommas(argvalue)
{  
  var j;
  var argvalueSinComma = argvalue;
  if (isFieldWithValue(argvalue))
    {
	var argvalue2 = String(argvalue);
	argvalueSinComma="";
    for(j=0; j<argvalue2.length; j++)
	    {
		  if (argvalue2.charAt(j) != ",")
		    argvalueSinComma = argvalueSinComma +  argvalue2.charAt(j);
		}
	}	
  return argvalueSinComma;	
}

function formatDecimal(argvalue, addzero, decimaln) 
{
 //Especifica un formato para la cadena
  var numOfDecimal = (decimaln == null) ? 2 : decimaln;
  var number = 1;
  number = Math.pow(10, numOfDecimal);
  argvalue = Math.round(parseFloat(argvalue) * number) / number;
  
  argvalue = "" + argvalue;

  if (argvalue.indexOf(".") == 0)
    argvalue = "0" + argvalue;

  if (addzero == true) {
    if (argvalue.indexOf(".") == -1)
      argvalue = argvalue + ".";

    while ((argvalue.indexOf(".") + 1) > (argvalue.length - numOfDecimal))
      argvalue = argvalue + "0";
  }

  return argvalue;
}

function isFieldWithValue(valor)
{
  return (valor!=null && valor!='' && valor!='\n' && valor!='null'); 
}


/*
** Check if the current browser is compatible
**  browserName - browser name
**  browserVersion - version number (if 0 don't check version)
** e.g. isBrowser("Microsoft","6.0");
**      isBrowser("Netscape","5.0");
** returns true if browser equals and version equals or greater
*/
function isBrowser(browserName,browserVersion) {
  var browserOk = false;
  var versionOk = false;
  var idx1 = navigator.appVersion.indexOf(";")+1;
  var idx2 = navigator.appVersion.indexOf(";",idx1);
  var navigatorName = Trim(navigator.appVersion.substring(idx1,idx2));

  browserOk = (navigator.appName.indexOf(browserName) != -1);
  if (parseInt(browserVersion) == 0) versionOk = true;
     else versionOk = (navigatorName.indexOf(browserVersion) != -1);
  return (browserOk && versionOk);
}



/*
 FUNCTION NAME:  CheckDateTimeFormat
   CREATE DATE:  05/28/2002 
   DESCRIPTION:  Verify DateTime with the Format parameter and send a message 
     if the date format is wrong. 
     It receives the datetime entered and format as parameters.
     Formats:
       d  - Verify the day as a number without a leading zero (1-31). 
       dd - Verify the day as a number with a leading zero (01-31). 
       m  - Verify the month as a number without a leading zero (1-12).
       mm - Verify the month as a number with a leading zero (01-12).
       yy - Verify the year as a two-digit number (00-99).
     yyyy - Verify the year as a four-digit number (0000-9999).
       h - Verify the hour without a leading zero (0-23).
       hh - Verify the hour with a leading zero (00-23).
       n - Verify the minute without a leading zero (0-59).
       nn - Verify the minute without a leading zero (00-59).  
       s - Verify the second without a leading zero (0-59).
       ss - Verify the second without a leading zero (00-59). 
      am/pm - Uses the 12-hour clock for the preceding h or hh specifier, 
        and verify 'am' for any hour before noon, and 'pm' for any 
        hour after noon. The am/pm specifier can use lower, upper, 
        or mixed case, and the result is verified accordingly.
 */
 function CheckDateTimeFormat(pDateTime, pFormat)
 {
   if (pDateTime == "" ||
    pFormat == "")
  return (true);
     
   var
  Format = pFormat.toLowerCase(),
  DateTime = pDateTime.toLowerCase(),
  VerifyIndex = -1,
  ArrayFormats = new Array("am/pm", "dd", "d", "mm", "m", "yyyy", "yy", "hh", "h", "nn", "n", "ss", "s"),
  ArrayVerify = new Array(),
  i = 0, Pos, day = 1, month = 1, year = 2000, hour = 0, minute = 0, second = 0, 
  ampm = "",
  FormatError = "",
  error = false;
        
   while (i < ArrayFormats.length)
   {
  Pos = Format.indexOf(ArrayFormats[i]); 
  if (Pos > -1)
  {   
    ArrayVerify[++VerifyIndex] = ArrayFormats[i];
    Format = Format.substring(0, Pos) + "~" + VerifyIndex + "~" + 
      Format.substring(Pos + ArrayFormats[i].length, Format.length);
  }
  else
    i++;
   }
        
   IndexDT = 0;
   IndexFormat = 0;
   while ((IndexFormat < Format.length ||
     IndexDT < DateTime.length) &&
   !error)
   {
  if (IndexFormat >= Format.length ||
   IndexDT >= DateTime.length)
  {
    error = true;
    FormatError = "\nDifferent extensions.";
  }
  else if (Format.charAt(IndexFormat) != "~")
  {
    error = Format.charAt(IndexFormat++) != DateTime.charAt(IndexDT++);
    if (error)
   FormatError = "\nCharacter " + IndexDT + " is invalid.";
  }
  else
  {
    var
   Pos = Format.indexOf("~", IndexFormat + 1),
   Index = parseInt(Format.substring(IndexFormat + 1, Pos), 10),
   Text = ArrayVerify[Index],
   TextEval, number = "";  
 
    if (Text != "am/pm")
    {
   if (Text != "yyyy")
   {
     var c1, c2 = "";
        
     c1 = DateTime.charAt(IndexDT);
     if (IndexDT + 1 < DateTime.length &&
      DateTime.charAt(IndexDT + 1) != Format.charAt(Pos + 1) &&
      DateTime.charAt(IndexDT + 1) != " ")
    c2 = DateTime.charAt(IndexDT + 1);
        
        error = (isNaN(c1)) || (Text.length == 2 && IndexDT + 1 >= DateTime.length) || 
       (Text.length == 2 && (c2 == "" || isNaN(c2)));
           
     if (!error)
     {
    number += c1;
    if (c2 != "")
      number += c2;
       
    if (Text == "d" || Text == "dd")
      day = parseInt(number, 10)
    else if (Text == "m" || Text == "mm")
      month = parseInt(number, 10)
    else if (Text == "yy")
      year = parseInt(number, 10)
    else if (Text == "h" || Text == "hh")
      hour = parseInt(number, 10)
    else if (Text == "n" || Text == "nn")
      minute = parseInt(number, 10)
    else if (Text == "s" || Text == "ss")
      second = parseInt(number, 10)
         
    IndexFormat = Pos + 1;
    IndexDT += number.length;
     } 
     else
    FormatError = "\nValue for " + Text.toUpperCase() + " is invalid.";  
   }
   else
   {
     error = IndexDT + 3 >= DateTime.length || 
       isNaN(DateTime.substring(IndexDT, IndexDT + 4));
     if (!error)
     {
    year = parseInt(DateTime.substring(IndexDT, IndexDT + 4), 10);
    IndexFormat = Pos + 1;
    IndexDT += 4;
     }
     else
    FormatError = "\nValue for " + Text.toUpperCase() + " is invalid.";  
   } 
    }
    else
    {
   error = IndexDT + 1 >= DateTime.length ||
     (DateTime.substring(IndexDT, IndexDT + 2) != "am" &&
     DateTime.substring(IndexDT, IndexDT + 2) != "pm");
        
   if (!error)
   {
     ampm = DateTime.substring(IndexDT, IndexDT + 2);
     IndexFormat = Pos + 1;
     IndexDT += 2;
   }
   else
     FormatError = "\nValue for " + Text.toUpperCase() + " is invalid.";  
    }
  }  
   }  
      
   if (!error)
   {
  if (month > 12 || month < 1)
    FormatError = "\nMonth out of range [1..12].";  
     
  if (day < 1 || day > 31)
    FormatError += "\nDay out of range [1..31].";  
     
  if ((hour < 0 || hour > 23) && ampm == "")
    FormatError += "\nHour out of range [0..23].";  
 
  if (hour > 12 && ampm == "pm")
    FormatError += "\nHour out of range [0..12] for PM.";  
     
  if (hour > 11 && ampm == "am")
    FormatError += "\nHour out of range [0..11] for AM.";  
       
  if (minute < 0 || minute > 59)
    FormatError += "\nMinutes out of range [0..59].";  
      
    if (second < 0 || second > 59)
    FormatError += "\nSeconds out of range [0..59].";  
     
  if (month > 12 || month < 1 || day < 1 || day > 31 || hour < 0 ||
   hour > 23 || (hour > 12 && ampm != "") || (hour > 11 && ampm == "am") || 
   minute < 0 || minute > 59 || second < 0 || second > 59) 
    error = true;
     
  if (!error)
  switch (month)
  {
    case 2:
   if (Bisiesto(year))
   { 
     if (day > 29) 
     {
    error = true;
    FormatError += "\nDay out of range [1..29] for Month " + month + 
         " for leap Year " + year + ".";  
     }
   }
   else if (day > 28)
   {
     error = true;
     FormatError += "\nDay out of range [1..28] for Month " + month + ".";  
   }
   break;
    case 4: case 6: case 9: case 11:
   if (day > 30) 
   {
     error = true;
     FormatError += "\nDay out of range [1..30] for Month " + month + ".";  
   }
   break;
  }
   }
            
   if (error)
   { 
     //cvlDesde.ErrorMessage = "Desde: " + FormatError;
     //alert(cvlDesde.ErrorMessage);
  //alert("Invalid date time format " + pFormat.toUpperCase() + "." + FormatError);
  /*if (event.srcElement != null)
    event.srcElement.focus();*/
  return (false);
   }
   else
  return (true);
 }
 