/* 
---------------------------------------------------------------------------------------------           
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: 	TrimPOP
       AUTHOR:	WTS Web
  CREATE DATE: 	6/08/2001 
  DESCRIPTION: 	Remove blank spaces
---------------------------------------------------------------------------------------------
*/

function TrimPOP(pString)
{
var i, resultado = "";
 if (pString == null)
   return (resultado);
     
  pString = String(pString);
  if (pString.length > 0)
  {
    i = 0;
    while (pString.charAt(i) == " ") i++;
    resultado = pString.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,format)
{
  var FormatDate;
  if (arguments.length > 1)
    FormatDate = Trim(format).substring(0,10).toUpperCase()
  else  
    FormatDate = "";
  
  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);
	
if (FormatDate == "MM/DD/YYYY")
  {
  var d = parseInt(fecha[1], 10),
      m = parseInt(fecha[0], 10),
      y = parseInt(fecha[2], 10);

  }
 else
   {

  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(sStrFechat)
{ var FormatDate;
  if (arguments.length > 1)
    FormatDate = Trim(arguments[1]).substring(0,10).toUpperCase()
  else  
    FormatDate = "";
    
  if (!VerifyDate(sStrFechat, FormatDate))
  {
    if (FormatDate == "MM/DD/YYYY")
      alert("The date you have entered was wrong! The format is Month/Day/Year and Year should be later than 1900.")
    else  
      alert("The date you have entered was wrong! The format is Day/Month/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);
	
	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 == "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 == "PHONE_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 != 32) &&
      ( window.event.keyCode != 35) &&
      ( window.event.keyCode != 40) &&
      ( window.event.keyCode != 41) &&
      ( window.event.keyCode != 43) &&
      ( window.event.keyCode != 45))
			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) || (sStr.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 != 46))
			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 Send_Security_new2(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();	
	}

}

/*
<---------------------------------------------------------------------------------------------           
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 += "%27"
    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);
	}
*/
}

/* WO 17831 LOGO Change Start*/

function WriteSimpleISSHeader(pRoot,pTitle)
{
if (pRoot == '<#DW_ROOT>') 
  pRoot = '';

	document.write("<table width='100%' border='0' cellspacing='0' cellpadding='0' background='"+pRoot+"DW_Images/header_bg.gif'>");
	document.write("<tr align='left' valign='top'>"); 
	document.write("<td width='11'><img src='"+pRoot+"DW_Images/left_corner.gif' width='11' height='90'></td>");
 document.write("<td><img src='"+pRoot+"DW_Images/iss_logo.gif' width='187' height='90'></td>");
 document.write("<td align='right' valign='middle'>");
 document.write("<table width='200' border='0' cellspacing='0' cellpadding='0'>");
document.write("<tr>");
	document.write("<td align='left' valign='top'>");
	document.write("<img src='"+pRoot+"DW_Images/YourISS_title.gif' width='91' height='19'></td>");
document.write("</tr>");
document.write("<tr>");
	document.write("<td align='left' valign='top' class='titleISS'>"+pTitle+"</td>");
document.write("</tr>");
document.write("</table>");
document.write("</td>");
	document.write("<td width='161'align='right'><img src='"+pRoot+"DW_Images/map.gif' width='161' height='90'></td>");
	document.write("<td width='11'align='right'><img src='"+pRoot+"DW_Images/right_corner.gif' width='11' height='90'></td>");
document.write("</tr>");
document.write("</table>");
}

function WriteDashBoardISSHeader(pRoot,pName,pSecurityFrmName)
{
if (pRoot == '<#DW_ROOT>') 
  pRoot = '';
  
document.write(" <table width='100%' border='0' cellspacing='0' cellpadding='0' background='"+pRoot+"DW_Images/header_bg.gif'>");
document.write("	<tr align='left' valign='top'>");
	document.write("<td width='11'><img src='"+pRoot+"DW_Images/left_corner.gif' width='11' height='90'></td>");
	document.write("<td><img src='"+pRoot+"DW_Images/iss_logo.gif' width='187' height='90'></td>");
document.write("		<td width='200' align='right' valign='middle'>");
document.write("			<table width='200' border='0' cellspacing='0' cellpadding='0'>");
document.write("				<tr>");
document.write("					<td align='left' valign='top'>");
	document.write("<img src='"+pRoot+"DW_Images/YourISS_title.gif' width='91' height='19'></td>");
document.write("				</tr>");
document.write("				<tr>");
	document.write("<td align='left' valign='top' class='titleISS'>"+'Dashboard'+"</td>");
document.write("				</tr>");
document.write("			</table>");
document.write("		</td>");
document.write("		<td width='260' valign='middle'>");
document.write("			<table width='100%' height='90'  border='0' cellspacing='0' cellpadding='0'>");
document.write("				<tr>");
document.write("					<td align='right' valign='middle'>");
document.write("						<table width='100%'  border='0' cellspacing='0' cellpadding='0' class='mapbg' height='90'>");
document.write("							<tr>");
document.write("								<td align='right' valign='middle'>");
document.write("									<table width='100' border='0' cellspacing='0' cellpadding='0'>");
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'></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'></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;'><b>Welcome:</b> "+pName+"</div> ");
document.write("											</td> ");
document.write("										</tr> ");
document.write("									</table> ");
document.write("								</td> ");
 document.write("<td width='11'align='right'><img src='"+pRoot+"DW_Images/right_corner.gif' width='11' height='90'></td>");
document.write("							</tr> ");
document.write("						</table> ");
document.write("					</td> ");
document.write("				</tr> ");
document.write("			</table> ");
document.write("		</td> ");
document.write("	</tr> ");
document.write("</table>");
}

function WritePagesISSHeader(pRoot,pTitle,pSecurityFrmName)
{
if (pRoot == '<#DW_ROOT>') 
  pRoot = '';
  
	document.write("<table width='100%' border='0' cellspacing='0' cellpadding='0' background='"+pRoot+"DW_Images/header_bg.gif'>");
	document.write("<tr align='left' valign='top'>"); 
	document.write("<td width='11'><img src='"+pRoot+"DW_Images/left_corner.gif' width='11' height='90'></td>");
	document.write("<td><img src='"+pRoot+"DW_Images/iss_logo.gif' width='187' height='90'></td>");
	document.write("<td width='300' align='right' valign='middle'>");
document.write("<table width='100%' border='0' cellspacing='0' cellpadding='0'>");
document.write("<tr>"); 
	document.write("<td align='left' valign='top'>");
	document.write("<img src='"+pRoot+"DW_Images/YourISS_title.gif' width='91' height='19'></td>");
document.write("</tr>");
document.write("<tr>");
	document.write("<td align='left' valign='top' class='titleISS'>"+pTitle+"</td>");
document.write("</tr>");
document.write("</table>");
document.write("</td>");
	document.write("<td width='220' valign='middle'>");
	document.write("<table width='100%' height='90'  border='0' cellspacing='0' cellpadding='0'>");
document.write("<tr>");
	document.write("<td align='right' valign='middle'>");
	document.write("<table width='100%'  border='0' cellspacing='0' cellpadding='0' class='mapbg' height='90'>");
 document.write("<tr>");
 document.write("<td align='right' valign='middle'>");
	document.write("<table width='100%' border='0' cellspacing='0' cellpadding='0'>");
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'></a></div>");
document.write("</td>");
document.write("</tr>");
document.write("<tr>");
document.write("<td>");
if (pTitle == "Central Code - Terminal/Berth Report")
  document.write("<div align='right'><a href='javascript: Send_Security_new2(\""+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'></a></div>");
else  
  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'></a></div>");
document.write("</td>");
document.write("</tr>");
 document.write("<tr valign='bottom'>"); 
 document.write("<td height='20'>"); 
if (pTitle == "Central Code - Terminal/Berth Report") 
  document.write("<div align='right'><a href='javascript: Send_Security_new2(\""+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'></a></div>");
else
  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'></a></div>");
document.write("</td>");
document.write("</tr>");
document.write("</table>");
document.write("</td>");
 document.write("<td width='11'align='right'><img src='"+pRoot+"DW_Images/right_corner.gif' width='11' height='90'></td>");
 document.write("</tr>");
 document.write("</table>");
	document.write("</td>");
document.write("</tr>");
document.write("</table>");
	document.write("</td>");
 document.write("</tr>");
 document.write("</table>");
	document.write("</td>");	
}

/* WO 17831 LOGO Change End*/

/**
<---------------------------------------------------------------------------------------------           
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'); 
}



/*  
<---------------------------------------------------------------------------------------------           
FUNCTION NAME:  VALUE IS NULL
       AUTHOR:	Raúl Angulo.
	   MODIFIED:jhigaki 
---------------------------------------------------------------------------------------------
*/
  function ValueIsNull(pValue) 
  {
    try
    {
      var result = (pValue == null);
      if (!result)
      {
        pValue = Trim(pValue);
        result = (pValue == "") || (pValue == '') || (pValue == "\n") || (pValue == "null") || (pValue == 'null');
      }
      return result;
    } 
    catch(e){return true}
  }




/*
<---------------------------------------------------------------------------------------------           
FUNCTION NAME:  blockBackSpace
       AUTHOR:	CPSP Web
  CREATE DATE: 	27/10/2001
  DESCRIPTION:  Block Back effect when pressing Backspace over select.
---------------------------------------------------------------------------------------------
*/

function blockBackSpace(){
  if (event.keyCode==8)
    event.returnValue = false;
}


function validMandatoryCurrentRecord(pXML, strMandatoryComponents, pShowMessage)
{  
  if (pXML.childNodes(0).childNodes.length <= 0 ) 
  {
    return (pShowMessage ? true: ""  );      
  }
  var strResult = "";  
  var Components, oComponent, nameField, descField, nC;
  var  ENTER="\r\n\t - ";
  Components = strMandatoryComponents.split("||");
  
  nC = Components.length;
  for (var i=0; i < nC; i++) 
  {
    oComponent = Components[i].split("|");
    if ( ValueIsNull(oComponent[0]) )break;    
    nameField = document.all(oComponent[0]).dataFld;
    descField = oComponent[1];
    
    if (pXML.childNodes(0).childNodes(pXML.recordset.AbsolutePosition-1).getAttributeNode(nameField)!=null )   
    {
      if ( ValueIsNull(pXML.childNodes(0).childNodes(pXML.recordset.AbsolutePosition-1).getAttributeNode(nameField).value) ) 
        strResult += ENTER + descField;
    }else
        strResult += ENTER + descField;
  }
  if ( (pShowMessage) && (strResult!="") )
    alert("The following information is mandatory: " + strResult);
  return (pShowMessage ? (strResult=="") : strResult  ); 
}

function CallBinoculars()
{
  srcEl = event.srcElement
  if ((event.keyCode==13) &&( srcEl!= null))
   srcEl.parentNode.getElementsByTagName("img")[0].click();
}
/*
<---------------------------------------------------------------------------------------------           
FUNCTION NAME:  TransformDate
       AUTHOR:	Miguel Angel Goicochea de Benito
  CREATE DATE: 	19/09/2006 
  DESCRIPTION: 	Changes YY to YYYY,  it assumes that it is receiving Day,  Month and Year separated by the same caracter              
---------------------------------------------------------------------------------------------
*/

function TransformDate(date,car)
{
	//Changes YY to YYYY,  it assumes that it is receiving Day,  Month and Year separated by the same caracter
	var arrDate = date.split(car);
	if (arrDate.length != 3) return; //not a valid input
	if (arrDate[2].length == 2) // YY is being used, transform to YYYY
	{
		var intYear = arrDate[2]*1;
		if (intYear > 50) intYear += 1900;
		else intYear += 2000;
		arrDate[2] = intYear;
	}
	return arrDate[0] + '/' + arrDate[1] + '/' + arrDate[2];
}

/* 
<---------------------------------------------------------------------------------------------           
  FUNCTION NAME:  ValidateDateTime
  AUTHOR:	   	      Miguel Angel Goicochea de Benito
  CREATION DATE:    19/09/2006 
  DESCRIPTION: 	     Transforms the date string so dates are separated
			     by "/" and hours by ":" then validates datetime format
---------------------------------------------------------------------------------------------
*/

function ValidateDateTime(obj,dateFormat)
{
	var bolEuropean =true;
	var strValidator = "";

	if (typeof(dateFormat) == "undefined") 
		var bolEuropean = true //means dd/mm/yyyy
	else 
	{
		var bolEuropean = (dateFormat.indexOf('d') < dateFormat.indexOf('m'))
		strValidator = dateFormat;
	}
	
	var strDateTime = TrimPOP(obj.value)
	if (strDateTime == "") return;
	
	//Separates date from time
	var arrDateTime = strDateTime.split(" ")
	var strDate = null;
	var strTime = null;
	var bolDate = false;
	var bolTime = false;
	
	if(arrDateTime.length == 2)
	{
		strDate = arrDateTime[0];
		strTime = arrDateTime[1];
	}
	else
	{
		if (arrDateTime[0].length <= 5) strTime = arrDateTime[0];
		else strDate = arrDateTime[0];
	}
	
	strDateTime = "";
	
	//Transforming Date
	if(strDate != null)
	{
		if(strDate.indexOf('.') > 0 ) //Separation by '.'
			strDate = TransformDate(strDate,'.');
		else if(strDate.indexOf('/') > 0) //Separation by '/'
			strDate = TransformDate(strDate,'/');
		else //Doesn't have any separator
		{
			var arrDate = strDate.split("");
			strDate = arrDate[0] + arrDate[1] + '/' + arrDate[2] + arrDate[3] + '/';
			if (arrDate.length == 6) 
				strDate += arrDate[4] + arrDate[5];
			else
				strDate += arrDate[4] + arrDate[5] + arrDate[6] + arrDate[7]; 
			strDate = TransformDate(strDate,'/');
		}
		strDateTime += strDate + " ";
		bolDate = true;
	}
	
	//Transforming Time
	if(strTime != null)
	{
		if(strTime.indexOf('.') > 0) // Separation by '.'
		{
			var arrTime = strTime.split('.')
			strTime = arrTime[0] + ':' + arrTime[1]
		}
		else if(strTime.indexOf('/') > 0) //Separation by '/'
		{
			var arrTime = strTime.split('/')
			strTime = arrTime[0] + ':' + arrTime[1]
		}
		else if(strTime.indexOf(':') < 0) //doesn't have any valid separator, HHMM format is assummed
		{
			var arrTime = strTime.split("");
			strTime = arrTime[0] + arrTime[1] + ':' + arrTime[2] + arrTime[3];
		}
		strDateTime += strTime
		bolTime = true;
	}
	
	//Depending of the input we received we form our validator string
	if (strValidator == "")
	{
		if (bolDate)
		{
			if (bolEuropean) strValidator += 'DD/MM/YYYY ';
			else strValidator += 'MM/DD/YYYY ';
		}
		if (bolTime) strValidator += 'HH:NN';
	}
	
	//Trimming any white spaces
	strDateTime = TrimPOP(strDateTime);
	strValidator = TrimPOP(strValidator);
	
	//Finally modify the value if the format is valid or else we send an alert message (VerifyDate() does this)
	if (VerifyDate(strDateTime,strValidator)) 
	{ 
		obj.value = strDateTime;
		return true;
	}
	return false;
}

function ValidateDateFieldFin(field)
{
	if (!ValidateDateTime(field)) 
	{ 
		CheckDate(field.value)
		field.value = "";
	}
}
/* 
<---------------------------------------------------------------------------------------------           
  FUNCTION NAME:  escapeXML
  AUTHOR:	   	      Miguel Angel Goicochea de Benito
  CREATION DATE:    28/12/2006 
  DESCRIPTION: 	     Replaces XML illegal characters for their correct
			     representation
---------------------------------------------------------------------------------------------
*/

function escapeXML(string)
{
	var result = "", i, c;
	for(i =0;i <string.length;i++)
	{
		c =string.charAt(i);
		if(c =='<')
			result +="&lt;";
		else if(c =='&')
			result +="&amp;";
		else if(c == '>')
			result +="&gt;"
		else if(c == '"')
			result +="&quot;"
		else
			result +=c;
	}
	return result;
}

/*WO 5270*/
function blockSearchInvalidChars()
{
  if ((event.keyCode==34) || (event.keyCode==44) || (event.keyCode==37) || (event.keyCode==39) || (event.keyCode==95))
    event.returnValue = false;
}
/*WO 5270*/

