
/*************************************************************************/
/*COLLECTION OF JAVASCRIPT FUNCTIONS USED IN MAINTAINING THE IGEN WEBSITE*/
/*Copyright 2000 INSULAR HIH GEN					 */
/*Last Updated: 26-NOV-2002 -boa-						 */ 
/*************************************************************************/


//!!!!!!!

/*****************
Browsercheck:
******************/
ie=document.all?1:0
n=document.layers?1:0

// whitespace characters
var whitespace = " \t\n\r";


function BrowserCheck()
{
	var x, y 
	/* x = 1 then netscape */
	/* y = 1 then explorer */
	x=document.layers?1:0;
	y=document.all?1:0;
	if (x!=0)
	{
		return(false);
	} 
	else
	{
		return(true);
	}
	/*if BrowserCheck = false then it's netscape*/
	/*if BrowserCheck = true then it's ie*/
}



/*************************************************************************/
/*	FUNCTION THAT CHECKS IF THE ENTERED VALUE IS A VALID EMAIL ADDRESS   */
/*************************************************************************/
function checkEmail(checkString)
{
    var newstr = "";
    var at = false;
    var dot = false;
    var AtSym    = checkString.indexOf('@');
    var AAtSym    = checkString.lastIndexOf('@');
	var Period   = checkString.lastIndexOf('.');
	var Space    = checkString.indexOf(' ');
	var Length   = checkString.length - 1  ;
    
    // check the data
    
    if(AtSym!=AAtSym){return(false)}	
	
    if ((AtSym < 1) ||                 // '@' cannot be in first position
    (Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
    (Period == Length ) ||             // Must be atleast one valid char after '.'
    (Space  != -1)){
		dot =  false;
		at = false;
    }else {
       dot = true;
       at = true;
    }        
    // parse the remainder of the string
    for (var i = 0; i < checkString.length; i++) {
        ch = checkString.substring(i, i + 1)
        if ((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z")
                || (ch == "@") || (ch == ".") || (ch == "_")
                || (ch == "-") || (ch >= "0" && ch <= "9")) {
                newstr += ch;
        }
    }
    if ((at == true) && (dot == true)) {
        /*return newstr;*/
        return(true);
    }
    else {
      // prompt for an error
      /*alert ("Please enter a valid email address.");
      return checkString;*/
      return(false);
      
    }
}





/*function IsEmail(valEmail)
{
	var sEmail="";
	var iFound, f = "@"; 
	sEmail += valEmail;
	if (Trim$(sEmail)=="")
	{
		return(false);
	}

	iFound = sEmail.indexOf(f)
	if (iFound >= 0)
	{
		return (true);
	}
	else
		return (false);
}*/


/****************************************************************
***********		Check whether string s is empty. ****************
****************************************************************/
function IsEmpty(s)
{
	return ((s == null) || (s.length == 0))
}



/****************************************************************************************
***********		REMOVE ALL LEADING AND TRAILING SPACES IN A STRING INPUT ****************
****************************************************************************************/
function Trim$(s)
{

	var indx1=0;
	var indx2=s.length-1;
	var m=0;

	for (var m=0;(m < s.length) && (s.charAt(m) == " ");m++,indx1=m);

	if (indx1 != s.length)
		for (var m=s.length-1; (m>=0) && (s.charAt(m) == " ");m--,indx2=m);

	if (indx1 == s.length)
	{
		return "";
	}

	var i;
    // Is s empty?
    if (IsEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {
         // Check that current character isn't whitespace.
         var c = s.charAt(i);

         if (whitespace.indexOf(c) == -1) return s;
    }
    // All characters are whitespace.
    //return true;
    return "";
}


/********************************************************************************
*****	FUNCTION THAT WILL CHECK IF THE DATA ENTERED IS A VALID DATE ENTRY 
******
********************************************************************************/
 function IsDate(DateVal)

{
	var newDate,sDate="",s=""
	sDate += DateVal
	newDate = new Date(DateVal)
	s += newDate
	if (s == "NaN")
	{
		return (false);
	}
	else
	{
		var Mo,Yr,Dy,iFound, f = "/", f1 = "-"
		iFound = sDate.indexOf(f)
		if (iFound >= 0)
		{
			Mo = sDate.slice(0,iFound);
			sDate = sDate.slice(iFound+1);
		iFound = sDate.indexOf(f);
			if (iFound >=0)
			{
				Dy = sDate.slice(0,iFound);
				sDate = sDate.slice(iFound+1);
				Yr = sDate
			}
	}
		else
		{
			iFound = sDate.indexOf(f1)
			if (iFound >=0)
			{
				Mo = sDate.slice(0,iFound);
				sDate = sDate.slice(iFound+1);
				iFound = sDate.indexOf(f1);
				if (iFound >= 0)
				{
					Dy = sDate.slice(0, iFound);
				sDAte = sDate.slice(iFound+1)
					Yr = sDate
				}
		}
		}
		var nYr = new Number(Yr), iYr, sYr
		var m1 = 30, m2 = 31, v1 = 28, v2 = 29
		var nMo = new Number(Mo)
		var nDy = new Number(Dy)		
		
		if (nYr < 999)
		{
			nYr = nYr + 2000;
		}

		if (nYr < 1800)
		{
			nYr = nYr - 1800 + 2000;
			/*return (false);*/
		}
		if (nMo < 1)
		{
			return (false);
		}

		if (nMo > 12)
		{
			return (false);
		}
		if (nMo == 1)/** JANUARY **/
		{
			if (nDy > m2)
			{
				return (false);
			}
		}
		if (nMo == 3) /** MARCH **/
		{
			if (nDy > m2)
			{
				return (false);
			}
		}
		if (nMo == 5) /** MAY **/
		{
			if (nDy > m2)
			{
				return (false);
			}
		}
		if (nMo == 7) /** JULY **/
		{
			if (nDy > m2)
		{
				return (false);
	}
		}

		if (nMo == 8) /** AUGUST **/
		{
			if (nDy > m2)
			{
				return (false);
			}
		}
		if (nMo == 10) /** OCTOBER **/
		{
			if (nDy > m2)
			{
				return (false);
			}
		}
		if (nMo == 12) /** DECEMBER **/
	{
		if (nDy > m2)
		{
				return (false);
			}
		}
		if (nMo == 2) /** FEBRUARY **/
		{
			/**var nYr = new Number(Yr), iYr, sYr**/
			iYr = nYr%4;
			if (iYr > 0)
			{
				if (nDy > v1)
				{
					return (false);
				}
			}
			else
			{
				if (nDy > v2)
				{
					return (false);
				}
			}
		}
		if (nMo == 4) /** APRIL **/
		{
			if (nDy > m1)
			{
				return (false);
			}
		}
		if (nMo == 6) /** JUNE **/
		{
			if (nDy > m1)
			{
				return (false);
			}
		}

		if (nMo == 9) /** SEPTEMBER **/
		{
			if (nDy > m1)
			{
				return (false);
			}
		}
		if (nMo == 11) /** NOVEMBER **/
		{
			if (nDy > m1)
			{
				return (false);
			}
		}
	}
 return (true); 



} 


/******************************************************************************************
*****	FUNCTION THAT WILL CHECK IF THE DATE IS LESS THAN OR EQUAL THAN TODAY  	      *****
******************************************************************************************/
function IsLessThanToday(valDate, valNow)
{
	var strNow, strDate
	strNow = new Date(valNow)
	strDate = new Date(valDate)

	if (Date.UTC(strDate) > Date.UTC(strNow))
	{
		return (false);
	}
}

/******************************************************************************************
*****	FUNCTION THAT WILL CHECK IF THE DATA ENTERED IS A VALID TIME ENTRY			 
******
******************************************************************************************/
function IsTime(valTime)
{	var newTime,sTime="",t="",f1=":"
	var iFound, hh, mm, nhh,nmm, shh="", smm=""
	sTime += valTime
	iFound = sTime.indexOf(f1)
	if (iFound <= 0)
	{
//		alert('false1' + sTime);		
		hh = sTime
		nhh = new Number(hh)
		shh += nhh
//		alert('val = ' + shh);		
		if (shh == "NaN")
			{
			return false;
			}
		else
		{
			if (nhh > 12 || nhh < 1)
			{				
				return (false);
			}
			else
			{
				return (true);				
			}
		}
	}
	else
	{	
		hh = sTime.slice(0,iFound)
		mm = sTime.slice(iFound+1)		
		nhh = new Number(hh)
		shh += nhh
//		alert('hh = ' + hh + ' / mm = ' + mm + ' = ' + shh + ' ' + nhh);		
		if (shh == "NaN")
		{		
//			alert('NAN!');			
			return (false);
		}
		else
		{
			if (nhh > 12 || nhh < 1)
			{			
				return (false);
			}
		}
		nmm = new Number(mm)
		smm += nmm
//		alert(smm + ' = ' + nmm);		
		if (smm == "NaN")
		{		
//			alert('NAN!');			
			return (false)
		}
		else
		{
			if (nmm > 59 || nmm < 0)
				{ 			
//					alert('gt = ' + nmm);					
					return (false);
				}
			else
				{
					return (true);			
				}			
		}
//		alert('gt2 = ' + nmm);
	}

}


function IsTime1(valTime)
{	var newTime,sTime="",t="",f1=":"
	var iFound, hh, mm, nhh,nmm, shh="", smm=""
	sTime += valTime
	iFound = sTime.indexOf(f1)
	if (iFound <= 0)
	{
		return (false);
	}
	else
	{
		hh = sTime.slice(0,iFound)
		mm = sTime.slice(iFound+1)
		nhh = new Number(hh)
		shh += nhh
		if (shh == "NaN")
		{
			return (false);
		}
		else
		{
			if (nhh > 12 || nhh < 1)
			{
				return (false);
			}
		}
		nmm = new Number(mm)
		smm += nmm
		if (smm == "NaN")
		{
			return (false)
		}
		else
		{
			if (nmm > 59 || nmm < 0)
				{ return
			(false);
			}
		}
	}

}


/******************************************************************************************
*****	FUNCTION THAT WILL CHECK IF THE DATA ENTERED IS A VALID AMOUNT				 
******
******************************************************************************************/
function IsAmount(valAmount)
{
  var checkOK = "0123456789.,";
  var checkStr = valAmount;
  var allValid = true;
  var decPoints = 0;
  var numDiv = 0;
  var allNum = "";

  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    if (ch == ".")
    {
      if (ch.length > 15)
      {
		allValid = false;
      }
      else
      {
		allNum += ".";
		decPoints++;
	  }
    }
    else if (ch != ",")
      allNum += ch;
  }

  if (checkStr.slice(0,1) == ",")
  {
	numDiv++;
  }

  if (!allValid)
  {
    return (false);
  }

  if (decPoints > 1)
  {
    return (false);
  }

  if (numDiv > 0)
  {
	return (false);
  }
  return (true);
}


/***********************************************************************************
*****	FUNCTION THAT WILL CHECK IF THE DATA ENTERED IS A VALID NUMERIC ENTRY 
******
***********************************************************************************/
function IsNumber(valNumber)
{
	
	 if(isNaN(valNumber))
		return false;
	else
		return true;
	

/*	var checkOK = "0123456789.";
	var checkStr = valNumber;
	var allValid = true;
	var decPoints = 0;
	var allNum = "";
	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		if (ch == checkOK.charAt(j))
		break;
		if (j == checkOK.length)
		{
			allValid = false;
			break;
		}
		allNum += ch;
	}
	if (!allValid)
	{
		return (false);
	}
	return (true); */
}


/***********************************************************************************
*****	FUNCTION THAT WILL CHECK IF THE DATA ENTERED IS A VALID WHOLE NUMBER ENTRY 
******
***********************************************************************************/
function IsWholeNumber(valNumber)
{
	
	if(isNaN(valNumber))
		return false;
	else
	{	
	var checkOK = "0123456789";
	var checkStr = valNumber;
	var allValid = true;
	var decPoints = 0;
	var allNum = "";
	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		if (ch == checkOK.charAt(j))
		break;
		if (j == checkOK.length)
		{
			allValid = false;
			break;
		}
		allNum += ch;
	}
	if (!allValid)
	{
		return (false);
	}
	return (true); 
	}
}

/***********************************************************************************
*****	FUNCTION THAT WILL CHECK IF THE DATA ENTERED IS A VALID RATE ENTRY	  
******
***********************************************************************************/
function IsRate(valRate)
{
  	var checkOK = "0123456789-.";
  	var checkStr = valRate
  	var allValid = true;
  	var decPoints = 0;
  	var allNum = "";
  	for (i = 0;  i < checkStr.length;  i++)
  	{
    	ch = checkStr.charAt(i);
    	for (j = 0;  j < checkOK.length;  j++)
    	if (ch == checkOK.charAt(j))
    	break;
    	if (j == checkOK.length)
    	{
    		allValid = false;
    		break;
    	}
    	if (ch == ".")
    	{
    		allNum += ".";
    		decPoints++;
    	}
    	else
    		allNum += ch;
  	}

	if (!allValid)
	{
		return (false);
	}

  	if (decPoints > 1)
  	{
    	return (false);
  	}
	return (true);
}

/***********************************************************************************
*****	FUNCTION THAT WILL CHECK IF THE DATA ENTERED IS A VALID DATE ENTRY 
******
***********************************************************************************/
function CheckDate()
{
	if (window.event.keyCode==13)
	{
		return true
	}
	if ((window.event.keyCode >=47) && (window.event.keyCode<=57))
		return true;
	else
		return false;
}


/***********************************************************************************
*****	FUNCTION THAT WILL CHECK IF THE DATA ENTERED IS A VALID AMOUNT ENTRY 
******
***********************************************************************************/
function CheckAmount()
{
	if (window.event.keyCode==13)
	{
		return true
	}

	if ((window.event.keyCode == 44) || (window.event.keyCode == 46))
	{
		return true
	}

	if ((window.event.keyCode >=48) && (window.event.keyCode<=57))
		return true;
	else
		return false;
}


/***********************************************************************************
*****	FUNCTION THAT WILL CHECK IF THE DATA ENTERED IS A VALID NUMERIC ENTRY 
******
***********************************************************************************/
function CheckNumber()
{
	if (window.event.keyCode==13)
	{
		return true
	}

	if ((window.event.keyCode >=48) && (window.event.keyCode<=57))
		return true;
	else
		return false;
}


/***********************************************************************************
*****	FUNCTION THAT WILL CHECK IF THE DATA ENTERED IS A VALID RATE/DECIMAL 
ENTRY *
***********************************************************************************/
function CheckRate()
{
	if (window.event.keyCode==13)
	{
		return true
	}

	if (window.event.keyCode == 46)
	{
		return true
	}

	if ((window.event.keyCode >=48) && (window.event.keyCode<=57))
		return true;
	else
		return false;
}


/***********************************************************************************
*****	FUNCTION THAT WILL CHECK IF THE DATA ENTERED IS A VALID TIME ENTRY 
*********
***********************************************************************************/
function CheckTime()
{
	if (window.event.keyCode==13)
	{
		return true
	}

	if (window.event.keyCode==58)
	{
		return true
	}

	if ((window.event.keyCode >=47) && (window.event.keyCode<=57))
		return true;
	else
		return false;
}


/***********************************************************************************
*****	FUNCTION THAT WILL CHECK IF THE STRING IS A VALID USERNAME
*****   THAT IS WITHOUT SPECIAL ASCII CHARACTERS
*****	VALID CHARACTERS ARE A-Z, a-z, 0-9 and underscore, no spaces	
***********************************************************************************/
function ValidUserName(strUserName)
{
	if (Trim$(strUserName)=="")
	{
		return(false);
	}

  	var checkOK = "0123456789_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWZYZ";
  	var notOK = "0123456789";
  	var checkStr = strUserName
  	var allValid = true;
  	var blankspace = 0;
  	var allChar = "";
  		
  	ch = checkStr.charAt(0)
  	for (j = 0; j < notOK.length; j++)
  	if (ch == notOK.charAt(j))
  	{
  		return(false);
  	}
  	
  	for (i = 0;  i < checkStr.length;  i++)
  	{
    	ch = checkStr.charAt(i);
    	for (j = 0;  j < checkOK.length;  j++)
    	if (ch == checkOK.charAt(j))
    	break;
    	if (j == checkOK.length)
    	{
    		allValid = false;
    		break;
    	}
    	if (ch == " ")
    	{
    		allChar += " ";
    		blankspace++;
    	}
    	else
    		allChar += ch;
  	}

	if (!allValid)
	{
		return (false);
	}

  	if (blankspace > 1)
  	{
    	return (false);
  	}
	return (true);
}


/***********************************************************************************
*****	FUNCTION THAT WILL CHECK IF THE STRING IS A VALID PASSWORD ENTRY
*****   THAT IS WITHOUT SPECIAL ASCII CHARACTERS
*****	VALID CHARACTERS ARE A-Z, a-z, 0-9 and underscore, no spaces	
***********************************************************************************/
function ValidPassword(strPassword)
{
	if (Trim$(strPassword)=="")
	{
		return(false);
	}

  	var checkOK = "0123456789_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWZYZ";
  	var notOK = "0123456789";
  	var checkStr = strPassword
  	var allValid = true;
  	var blankspace = 0;
  	var allChar = "";
  		
  	for (i = 0;  i < checkStr.length;  i++)
  	{
    	ch = checkStr.charAt(i);
    	for (j = 0;  j < checkOK.length;  j++)
    	if (ch == checkOK.charAt(j))
    	break;
    	if (j == checkOK.length)
    	{
    		allValid = false;
    		break;
    	}
    	if (ch == " ")
    	{
    		allChar += " ";
    		blankspace++;
    	}
    	else
    		allChar += ch;
  	}

	if (!allValid)
	{
		return (false);
	}

  	if (blankspace > 1)
  	{
    	return (false);
  	}
	return (true);
}


/***********************************************************************************
*****	FUNCTION THAT WILL Compute for date difference  *****
*****	would return no of days	*****
***********************************************************************************/

//function dateDiff(dateform,StartDate,EndDate) {
function dateDiff(StartDate,EndDate) {
date1 = new Date();
date2 = new Date();
diff  = new Date();
var firsttime,secondtime
firsttime = "0:00:00 AM"
secondtime = "0:00:00 AM"
//date1temp = new Date(dateform.StartDate.value + " " + firsttime);
date1temp = new Date(StartDate + " " + firsttime);
date1.setTime(date1temp.getTime());

//date2temp = new Date(dateform.EndDate.value + " " + secondtime);
date2temp = new Date(EndDate + " " + secondtime);
date2.setTime(date2temp.getTime());
// sets difference date to difference of first date and second date

diff.setTime(Math.abs(date1.getTime() - date2.getTime()));
timediff = diff.getTime();

days = Math.floor(timediff / (1000 * 60 * 60 * 24)); 
timediff -= days * (1000 * 60 * 60 * 24);

r =  days 

return (r); // form should never submit, returns false
}


//***************************************
//********* Date Validation *************
//***************************************

function checkValidDate(dateStr) {
// dateStr must be of format month day year with either slashes
// or dashes separating the parts. Some minor changes would have
// to be made to use day month year or another format.
// This function returns True if the date is valid.
var slash1 = dateStr.indexOf("/");
if (slash1==-1) { slash1 = dateStr.indexOf("-") }
// if no slashes or dashes, invalid date
if (slash1==-1) { return false }
var dateMonth = dateStr.substring(0, slash1)
var dateMonthAndYear = dateStr.substring(slash1+1, dateStr.length)
var slash2 = dateMonthAndYear.indexOf("/")
if (slash2==-1) { slash2 = dateMonthAndYear.indexOf("-") }
// if not a second slash or dash, invalid date
if (slash2==-1) { return false }
var dateDay = dateMonthAndYear.substring(0, slash2)
var dateYear = dateMonthAndYear.substring(slash2+1, dateMonthAndYear.length)
// if any non-digits in the month, invalid date
for (var x=0; x<dateMonth.length; x++) {
var digit = dateMonth.substring(x, x+1)
if ((digit < "0") || (digit > "9")) { return false }
}
// convert the text month to a number
var numMonth = 0;
for (var x=0; x<dateMonth.length; x++) {
digit = dateMonth.substring(x, x+1)
numMonth *= 10;
numMonth += parseInt(digit);
}
if ((numMonth <= 0) || (numMonth > 12)) { return false }
// if any non-digits in the day, invalid date
for (var x=0; x<dateDay.length; x++) {
digit = dateDay.substring(x, x+1)
if ((digit < "0") || (digit > "9")) { return false }
}
// convert the text day to a number
var numDay = 0;
for (var x=0; x<dateDay.length; x++) {
digit = dateDay.substring(x, x+1)
numDay *= 10;
numDay += parseInt(digit);
}
if ((numDay <= 0) || (numDay > 31)) { return false }
// February can't be greater than 29 (leap year calculation comes later)
if ((numMonth==2) && (numDay>29)) { return false }
// check for months with only 30 days
if ((numMonth==4) || (numMonth==6) || (numMonth==9) || (numMonth==11)) { if (numDay>30) { return false } }
// if any non-digits in the year, invalid date

if(dateYear.length<4 || dateYear.length>4){return false}
if(dateYear<1940){return false}
for (var x=0; x<dateYear.length; x++) {
digit = dateYear.substring(x, x+1)
if ((digit < "0") || (digit > "9")) { return false }
}
// convert the text year to a number
var numYear = 0;
for (var x=0; x<dateYear.length; x++) {
digit = dateYear.substring(x, x+1)
numYear *= 10;
numYear += parseInt(digit);
}
// if 2-digit year, use 50 as a pivot date
if (numYear < 50) { numYear = numYear + 2000 }
if (numYear < 100) { numYear = numYear + 1900 }
if ((numYear <= 0) || (numYear > 9999)) { return false }
// check for leap year if the month and day is Feb 29
if ((numMonth==2) && (numDay==29)) {
var div4 = numYear%4
var div100 = numYear%100
var div400 = numYear%400
// if not divisible by 4, then not a leap year so Feb 29 is invalid
if (div4!=0) { return false }
// at this point, year is divisible by 4. So if year is divisible by
// 100 and not 400, then it's not a leap year so Feb 29 is invalid
if ((div100==0) && (div400!=0)) { return false }
}
// date is valid
return true
}

/****************************************************************
****************		Formats Number			 ****************
****************************************************************/

   function FormatNumbers(num, decimalNum, bolLeadingZero, bolParens)
   /* IN - num:            the number to be formatted
           decimalNum:     the number of decimals after the digit
           bolLeadingZero: true / false to use leading zero
           bolParens:      true / false to use parenthesis for - num

      RETVAL - formatted number
   */
  {		  
       var tmpNum = num;

       // Return the right number of decimal places
       tmpNum *= Math.pow(10,decimalNum);       
       //alert(tmpNum)
       tmpNum = Math.floor(tmpNum);      
       //alert(tmpNum)
       tmpNum = Number(tmpNum) / Math.pow(10,decimalNum);       
       
       //alert(tmpNum)
		
       var tmpStr = new String(tmpNum);
		
	   //alert("tmpStr = " + String(tmpStr))	
		
	   if(tmpStr.indexOf("\.")==-1)
	   {	
			num = Math.pow(10,decimalNum)
			var xnum = new String(num)
			//alert("xnum = " + xnum)
			var de_zeros = xnum.replace(/1/gi,".")
			//alert(de_zeros)
			tmpStr = tmpStr + String(de_zeros)	   
			//alert(tmpStr)
	   }else{
			//alert(tmpStr)
			//alert(Left(tmpStr,1))
			//if(tmpStr.indexOf("\.") == 0)
			if(Number(Left(tmpStr,1)) == 0)
			{
				tmpStr = "0" + tmpStr
			}
			
			var decpart = new String(tmpStr.slice(tmpStr.indexOf("\.")+1))
			//alert(decpart.length)
			if(decpart.length < decimalNum)
			{
				for(zad=1;zad<=(decimalNum-decpart.length);zad++)
				{
					tmpStr = tmpStr + "0"
				}
			}	   
	   }

       // See if we need to hack off a leading zero or not
       if (!bolLeadingZero && num < 1 && num > -1 && num !=0)
           if (num > 0)
               tmpStr = tmpStr.substring(1,tmpStr.length);
           else
               // Take out the minus sign out (start at 2)
               tmpStr = "-" + tmpStr.substring(2,tmpStr.length);                        


       // See if we need to put parenthesis around the number
       if (bolParens && num < 0)
           tmpStr = "(" + tmpStr.substring(1,tmpStr.length) + ")";
				
       return tmpStr;
   } 

//*******************************************************
//		Limits Amount to 999999999999.99
//*******************************************************

function checkNum(Amt){	

	if(Trim$(Amt)!=""){
		var Amnt = new Number(Amt)

		if(Amnt>999999999999.99 || Amnt<=0){return(false)}	
	}else{return false}

	return true;
}



function FormatNumber(num,decimalNum,bolCommas,bolLeadingZero,bolParens)
/**********************************************************************
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.
 
	RETVAL:
		The formatted number!
 **********************************************************************/
{ 
        if (isNaN(parseInt(num))) return "NaN";

	var tmpNum = num;
	var iSign = num < 0 ? -1 : 1;		// Get sign of number
	
	// Adjust number so only the specified number of numbers after
	// the decimal point are shown.
	tmpNum *= Math.pow(10,decimalNum);
	tmpNum = Math.round(Math.abs(tmpNum))
	tmpNum /= Math.pow(10,decimalNum);
	tmpNum *= iSign;					// Readjust for sign
	
	
	// Create a string object to do our formatting on
	var tmpNumStr = new String(tmpNum);
	
	if(tmpNumStr.indexOf("\.")==-1)
	   {
			tmpNumStr = tmpNumStr + ".00"	   
	   }

	// See if we need to strip out the leading zero or not.
	if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
		if (num > 0)
			tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
		else
			tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);
		
	// See if we need to put in the commas
	if (bolCommas && (num >= 1000 || num <= -1000)) {
		var iStart = tmpNumStr.indexOf(".");
		if (iStart < 0)
			iStart = tmpNumStr.length;

		iStart -= 3;
		while (iStart >= 1) {
			tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart,tmpNumStr.length)
			iStart -= 3;
		}		
	}

	// See if we need to use parenthesis
	if (bolParens && num < 0)
		tmpNumStr = "(" + tmpNumStr.substring(1,tmpNumStr.length) + ")";

	return tmpNumStr;		// Return our formatted string!
}


function FormatPercent(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
/**********************************************************************
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.										
 
	RETVAL:
		The formatted number!		
 **********************************************************************/
{
	var tmpStr = new String(FormatNumber(num*100,decimalNum,bolLeadingZero,bolParens,bolCommas));

	if (tmpStr.indexOf(")") != -1) {
		// We know we have a negative number, so place '%' inside of ')'
		tmpStr = tmpStr.substring(0,tmpStr.length - 1) + "%)";
		return tmpStr;
	}
	else
		return tmpStr + "%";			// Return formatted string!
}


function FormatCurrency(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
/**********************************************************************
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.										
 
	RETVAL:
		The formatted number!		
 **********************************************************************/
{
	var tmpStr = new String(FormatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas));

	if (tmpStr.indexOf("(") != -1 || tmpStr.indexOf("-") != -1) {
		// We know we have a negative number, so place '$' inside of '(' / after '-'
		if (tmpStr.charAt(0) == "(")
			tmpStr = "($"  + tmpStr.substring(1,tmpStr.length);
		else if (tmpStr.charAt(0) == "-")
			tmpStr = "-$" + tmpStr.substring(1,tmpStr.length);
			
		return tmpStr;
	}
	else
		return "$" + tmpStr;		// Return formatted string!
}

function FormatDateTime(datetime, FormatType)
/*
	 FomatType takes the following values
		1 - General Date = Friday, October 30, 1998
		2 - Typical Date = 10/30/98
		3 - Standard Time = 6:31 PM
		4 - Military Time = 18:31
*/
{
	var strDate = new String(datetime);

	if (strDate.toUpperCase() == "NOW") {
		var myDate = new Date();
		strDate = String(myDate);
	} else {
		var myDate = new Date(datetime);
		strDate = String(myDate);
	}


	// Get the date variable parts
	var Day = new String(strDate.substring(0,3));
	if (Day == "Sun") Day = "Sunday";
	if (Day == "Mon") Day = "Monday";
	if (Day == "Tue") Day = "Tuesday";
	if (Day == "Wed") Day = "Wednesday";
	if (Day == "Thu") Day = "Thursday";
	if (Day == "Fri") Day = "Friday";
	if (Day == "Sat") Day = "Saturday";	
	
	var Month = new String(strDate.substring(4,7)), MonthNumber = 0;
	if (Month == "Jan") { Month = "January"; MonthNumber = 1; }
	if (Month == "Feb") { Month = "February"; MonthNumber = 2; }
	if (Month == "Mar") { Month = "March"; MonthNumber = 3; }
	if (Month == "Apr") { Month = "April"; MonthNumber = 4; }
	if (Month == "May") { Month = "May"; MonthNumber = 5; }
	if (Month == "Jun") { Month = "June"; MonthNumber = 6; }
	if (Month == "Jul") { Month = "July"; MonthNumber = 7; }
	if (Month == "Aug") { Month = "August"; MonthNumber = 8; }
	if (Month == "Sep") { Month = "September"; MonthNumber = 9; }
	if (Month == "Oct") { Month = "October"; MonthNumber = 10; }
	if (Month == "Nov") { Month = "November"; MonthNumber = 11; }
	if (Month == "Dec") { Month = "December"; MonthNumber = 12; }
	
	var curPos = 11;
	var MonthDay = new String(strDate.substring(8,10));
	if (MonthDay.charAt(1) == " ") {
		MonthDay = "0" + MonthDay.charAt(0);
		curPos--;
	}	
	
	var MilitaryTime = new String(strDate.substring(curPos,curPos + 5));
	
	var Year = new String(strDate.substring(strDate.length - 4, strDate.length));	
	
	document.write(strDate + "");	

	// Format Type decision time!
	if (FormatType == 1)
		strDate = Day + ", " + Month + " " + MonthDay + ", " + Year;
	else if (FormatType == 2)
		strDate = MonthNumber + "/" + MonthDay + "/" + Year.substring(2,4);
	else if (FormatType == 3) {
		var AMPM = MilitaryTime.substring(0,2) >= 12 && MilitaryTime.substring(0,2) != "24" ? " PM" : " AM";
		if (MilitaryTime.substring(0,2) > 12)
			strDate = (MilitaryTime.substring(0,2) - 12) + ":" + MilitaryTime.substring(3,MilitaryTime.length) + AMPM;
		else {
			if (MilitaryTime.substring(0,2) < 10)
				strDate = MilitaryTime.substring(1,MilitaryTime.length) + AMPM;
			else
				strDate = MilitaryTime + AMPM;
		}
	}	
	else if (FormatType == 4)
		strDate = MilitaryTime;


	return strDate;
}


//LTrim(string) : Returns a copy of a string without leading spaces.
//==================================================================
        function LTrim(str)
        /***
                PURPOSE: Remove leading blanks from our string.
                IN: str - the string we want to LTrim

                RETVAL: An LTrimmed string!
        ***/
        {
                var whitespace = new String(" \t\n\r");

                var s = new String(str);

                if (whitespace.indexOf(s.charAt(0)) != -1) {
                    // We have a string with leading blank(s)...

                    var j=0, i = s.length;

                    // Iterate from the far left of string until we
                    // don't have any more whitespace...
                    while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
                        j++;


                    // Get the substring from the first non-whitespace
                    // character to the end of the string...
                    s = s.substring(j, i);
                }

                return s;
        }


//RTrim(string) : Returns a copy of a string without trailing spaces.
//==================================================================
        function RTrim(str)
        /***
                PURPOSE: Remove trailing blanks from our string.
                IN: str - the string we want to RTrim

                RETVAL: An RTrimmed string!
        ***/
        {
                // We don't want to trip JUST spaces, but also tabs,
                // line feeds, etc.  Add anything else you want to
                // "trim" here in Whitespace
                var whitespace = new String(" \t\n\r");

                var s = new String(str);

                if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
                    // We have a string with trailing blank(s)...

                    var i = s.length - 1;       // Get length of string

                    // Iterate from the far right of string until we
                    // don't have any more whitespace...
                    while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
                        i--;


                    // Get the substring from the front of the string to
                    // where the last non-whitespace character is...
                    s = s.substring(0, i+1);
                }

                return s;
        }



//Trim(string) : Returns a copy of a string without leading or
//               trailing spaces
//=============================================================
        function Trim(str)
        /***
                PURPOSE: Remove trailing and leading blanks from our string.
                IN: str - the string we want to Trim

                RETVAL: A Trimmed string!
        ***/
        {
                return RTrim(LTrim(str));
        }


//Len(String) : Returns the number of characters in a string
//===========================================================

        function Len(str)
        /***
                IN: str - the string whose length we are interested in

                RETVAL: The number of characters in the string
        ***/
        {  return String(str).length;  }



//Left(string, length): Returns a specified number of characters from the
//                      left side of a string
//========================================================================

        function Left(str, n)
        /***
                IN: str - the string we are LEFTing
                    n - the number of characters we want to return

                RETVAL: n characters from the left side of the string
        ***/
        {
                if (n <= 0)     // Invalid bound, return blank string
                        return "";
                else if (n > String(str).length)   // Invalid bound, return
                        return str;                // entire string
                else // Valid bound, return appropriate substring
                        return String(str).substring(0,n);
        }



//Right(string, length): Returns a specified number of characters from the
//                       right side of a string
//========================================================================

        function Right(str, n)
        /***
                IN: str - the string we are RIGHTing
                    n - the number of characters we want to return

                RETVAL: n characters from the right side of the string
        ***/
        {
                if (n <= 0)     // Invalid bound, return blank string
                   return "";
                else if (n > String(str).length)   // Invalid bound, return
                   return str;                     // entire string
                else { // Valid bound, return appropriate substring
                   var iLen = String(str).length;
                   return String(str).substring(iLen, iLen - n);
                }
        }

//Mid(string, start, length): Returns a specified number of characters from a
//                            string
//============================================================================

        function Mid(str, start, len)
        /***
                IN: str - the string we are LEFTing
                    start - our string's starting position (0 based!!)
                    len - how many characters from start we want to get

                RETVAL: The substring from start to start+len
        ***/
        {
                // Make sure start and len are within proper bounds
                if (start < 0 || len < 0) return "";

                var iEnd, iLen = String(str).length;
                if (start + len > iLen)
                        iEnd = iLen;
                else
                        iEnd = start + len;

                return String(str).substring(start,iEnd);
        }


// Keep in mind that strings in JavaScript are zero-based, so if you ask
// for Mid("Hello",1,1), you will get "e", not "H".  To get "H", you would
// simply type in Mid("Hello",0,1)

// You can alter the above function so that the string is one-based.  Just
// check to make sure start is not <= 0, alter the iEnd = start + len to
// iEnd = (start - 1) + len, and in your final return statement, just
// return ...substring(start-1,iEnd)


//InStr(str, SearchForStr) : Returns the location a character (charSearchFor)
//                           was found in the string str
//========================================================================

function InStr(strSearch, charSearchFor)
/*
InStr(strSearch, charSearchFor) : Returns the first location a substring (SearchForStr)
                           was found in the string str.  (If the character is not
                           found, -1 is returned.)
                           
Requires use of:
	Mid function
	Len function
*/
{
	for (i=0; i < Len(strSearch); i++)
	{
	    if (charSearchFor == Mid(strSearch, i, 1))
	    {
			return i;
	    }
	}
	return -1;
}

//*****************************************************************
//Date functions

var mSep = "/";
var g_msPerDay = 1000*60*60*24;
//var g_aMonths = new Array( "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul","Aug", "Sep", "Oct", "Nov", "Dec" );
var g_aMonths = new Array( "1", "2", "3", "4", "5", "6", "7","8", "9", "10", "11", "12" );

// Add method (Month day, year)
function DateAdd( sDate, nDays )  {

  d1 = new Date( sDate );   
  ms1 = d1.getTime();
  ms2 = nDays * g_msPerDay;
    
  d2 = new Date( ms1 + ms2 );
  s = g_aMonths[d2.getMonth()] + "/" + d2.getDate() + "/";

  nYear = d2.getYear();
  if( nYear < 2000 )
    nYear += 1900;

  return  s + nYear;
}

// Diff method
function DteDiff( sDate1, sDate2 )  {
  
  d1 = new Date( sDate1 );   
  d2 = new Date( sDate2 );   
  ms1 = d1.getTime();
  ms2 = d2.getTime();  
  
  if( ms2 > ms1 )
    return -1;

  ms = (ms1 - ms2);
  nDays = ms/g_msPerDay;
  x = parseInt( nDays, 10 );
  if( nDays > x ) 
    nDays = x+1;

  return nDays;
}

// IsGreaterThan method
function IsGreaterThan( sDate1, sDate2 ) {

  d1 = new Date( sDate1 );   
  d2 = new Date( sDate2 );   

  ms1 = d1.getTime();
  ms2 = d2.getTime();  
  
  return (ms1 > ms2);
}

// DateAsDDMMYYYY method
function DateAsDDMMYYYY() {

  d = new Date(); 
  nMonth = 1 + d.getMonth();
  nYear = d.getYear();
  if( nYear < 2000 )
    nYear += 1900;

  return d.getDate() + mSep + nMonth + mSep + nYear;
}

//********************************************************
// Checks if a number is within given precision range for wholenumber&decimal part
// EX:  PrecisionCheck("123456.1234",6,4)
//		result: returns 123456.1234
//		* Limits/Checks if within 999999.9999 based on example
// Ex:  PrecisionCheck("123456.1234",6,5)
//      result: returns 123456.12340
// Ex:  PrecisionCheck("123456.1234",6,2)
//		result: returns FALSE

//   parameters: n - number to be evaluated
//				 intprec - no of digits for wholenumber part
//				 decprec - no of digits for decimal part

function PrecisionCheck(n,intprec,decprec)
{
	
	var precw_disp = ""
	var precd_disp = ""
	
	//alert(intprec)
	//alert(decprec)
	
	for(pdw=1;pdw<=intprec;pdw++)
	{
		precw_disp += "9"	
	} 
	
	for(pdd=1;pdd<=decprec;pdd++)
	{
		precd_disp += "9"	
	}
	
	var pres_disp = String(precw_disp) + "\." + String(precd_disp)
	
	if(Trim(n) == ""){return false}
	
	if(isNaN(n) || n < 0)
	{
		return false;
	}
	
	var newDotAry = n.match(/\./gi)
	//alert(newDotAry)
	//alert(n.match("\."))	
	
	if(newDotAry != null)
	{	
		//alert("1")
	
		if(newDotAry.length > 1)
		{
			return false
		}else{	
		//	  alert(n.indexOf("\."))
	
			  n = FormatNumbers(n,decprec)	
			  //alert(n)
	
			  var dotindex = n.indexOf("\.")
			  var intpart = n.slice(0,dotindex)
		//	  alert(intpart)
		//	  alert(intpart.length)
			  if(intpart.length > Number(intprec))
			  {	
		//		alert("int part sobra")
				alert("Amount out of precision.\n(Value should be within \"1\" to \"" + String(pres_disp) + "\")")
				return false
			  }
			  
		//	  alert(n.slice(dotindex+1))
			  var decpart = n.slice(dotindex+1)
			  
			  //alert(decprec)
			  //alert(FormatNumbers(n,decprec))
			  return FormatNumbers(n,decprec)
		}
	}else{	
		//alert("2")
	
		//	  alert(n.indexOf("\."))
	
			  n = FormatNumbers(n,decprec)	
			  //alert("n = "  + n)
	
			  var dotindex = n.indexOf("\.")
			  var intpart = n.slice(0,dotindex)
		//	  alert(intpart)
		//	  alert(intpart.length)
			  if(intpart.length > Number(intprec))
			  {	
		//		alert("int part sobra")
				alert("Amount out of precision.\n(Value should be within \"1\" to \"" + String(pres_disp) + "\")")
				return false
			  }
			  
		//	  alert(n.slice(dotindex+1))
			  var decpart = n.slice(dotindex+1)
			  
			  //alert(decprec)
			  //alert(FormatNumbers(n,decprec))
			  return FormatNumbers(n,decprec)
		}
}


//
// ******************************************boa
//
function isValidCode(objCode) {
	var constMAX_CODE = 3;
	
	var sNumbers = new String("0123456789");
	var strCode  = new String(objCode.value);
	var retVal = false;
	
	if (strCode.length == constMAX_CODE) {		
		retVal = true;
		for (var i=0;i <strCode.length;i++) {
			if (sNumbers.indexOf(strCode.charAt(i)) == -1) {
				retVal = false;
				break;
			}	
		}
	}
	
	if (retVal) ;
	else {
		alert("Invalid Code.  Please enter a valid Code format!");
		objCode.focus();
	}
	return( retVal );
}

function isValidCurrency(txtObj, bBlank) {	
		var bRetVal = true;
		var sFieldAtt;
						
		if (bBlank && (txtObj.value == ""));
		else {		
			sFieldAtt = txtObj.getAttribute("DisplayName");
			if (sFieldAtt==null || sFieldAtt=="")
				sFieldAtt="Field";
			
			bRetVal = (isPositiveCurrency(txtObj.value ));
		}
			
		if (bRetVal);
		else {
			alert(sFieldAtt +" should have a positive Currency!");			
			txtObj.focus();
		}
		return (bRetVal);
}

function isFloat(sText) {
	var bOneDecimal = false;
	var s = new String(sText.toString());
	var bRetVal = true;
	
	for (ii=0;ii <s.length;ii++) {
		var c =s.charAt(ii);
		if ((ii == 0) && (c == '-'));			
		else if ((c == '.') && (!bOneDecimal))
			bOneDecimal = true;
		else if ((c < '0') || (c >'9'))  {
			bRetVal = false;
			break;
		}
	}						
	return(bRetVal);
}

function isPositiveFloat(sText) {
	return(isFloat(sText) && !(sText.charAt(0) == "-")); 
}

function isInteger(sText) {
	return (!(isNaN(parseInt(sText,10))) && (sText == parseInt(sText,10).toString()));
}

function isPositiveInteger(sText) {
	return(isInteger(sText) && !(sText.charAt(0) == "-")); 
}

function isCurrency(sText) {	
	var bRetVal = false;
	var ii = sText.indexOf(".");
	if (isFloat(sText)) {		
		if (ii == -1)
			bRetVal = true;
		else 
			bRetVal = ((sText.length - (ii+1)) == 2);		
	} 
	return (bRetVal);
}

function isPositiveCurrency(sText) {
	return(isCurrency(sText) && (sText.charAt(0) != "-"));
}

function isValidAlphaNum(objTxt) {
	var validStr = new String("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
	
	objTxt.value = Trim(objTxt.value);
	for(var ii=0;ii < objTxt.value.length;ii++) {
		if (validStr.indexOf(objTxt.value.charAt(ii)) == -1) {
			alert("Only uppercase Alpha Numeric is allowed on this field!");
			objTxt.focus();
			return (false);
		}	
	}
	return (true);
}
//
// *******************************************boa
//


/*************************************************************************/
/*	FUNCTION THAT CHECKS IF THE ENTERED VALUE IS A VALID code   */
/*************************************************************************/
function checkGLCODE(checkString)
{
var ch
 
   for (var i = 0; i < checkString.length; i++) {
        ch = checkString.substring(i, i + 1)
        if (ch=="-")
		return false;
	}
	return true;

}	