var whitespace = " \t\n\r";
var vEmpty = " could not be blank!";
var vLetter = " format error! please input english letter.";
var vDigit = " format error! please input the digit.";
var vDigitChi = "隻能輸入數字";
var vDigitDot = " format error!";
var vEmail = " format error!";
var vDate = " format error! The date format is 'YYYY-MM-DD'";
var vDateChi = "日期格式錯誤";
var vAfter = " should be after ";
var vLength = " is too long."
var vValue  = " is too large."
var vMoreThan = " should be more than the sum of ";
var str = "";
var vZero =" could not be zero!"
var vDateFormat="The date format : YYYY-MM-DD";
var vNotShowMessage = "false";

function dayDif(inDate1, inDate2)
{
	var inDate1Year = inDate1.substring(0, 4);
	var i=0;
	var j=0;
	 if(inDate1.indexOf("-")>0){
	   i = inDate1.indexOf("-");
	 }else if(inDate1.indexOf("/")>0){
	   i = inDate1.indexOf("/");
	 }if(inDate1.indexOf(".")>0){
	   i = inDate1.indexOf("-");
	 }
	 
	 if(inDate1.lastIndexOf("-")>0){
	   j = inDate1.lastIndexOf("-");
	 }else if(inDate1.lastIndexOf("/")>0){
	   j = inDate1.lastIndexOf("/");
	 }if(inDate1.lastIndexOf(".")>0){
	   j = inDate1.lastIndexOf("-");
	 }
	var inDate1Month = inDate1.substring(i+1, j);	
	var inDate1Day = inDate1.substring(j+1, 10);
	var m = 0;
	var n = 0;
	if(inDate2.indexOf("-")>0){
	   m = inDate2.indexOf("-");
	 }else if(inDate2.indexOf("/")>0){
	   m = inDate2.indexOf("/");
	 }if(inDate2.indexOf(".")>0){
	   m = inDate2.indexOf("-");
	 }
	 
	 if(inDate2.lastIndexOf("-")>0){
	   n = inDate2.lastIndexOf("-");
	 }else if(inDate2.lastIndexOf("/")>0){
	   n = inDate2.lastIndexOf("/");
	 }if(inDate2.lastIndexOf(".")>0){
	   n = inDate2.lastIndexOf("-");
	 }
	var inDate2Year = inDate2.substring(0, 4);
	var inDate2Month = inDate2.substring(m+1, n);
	var inDate2Day = inDate2.substring(n+1, 10);
	var date1 = new Date(inDate1Year, inDate1Month-1, inDate1Day, 0, 0, 0, 0);
	var date2 = new Date(inDate2Year, inDate2Month-1, inDate2Day, 0, 0, 0, 0);
	var dayDiff = (Date.parse(date1) - Date.parse(date2)) / 86400000;
	return dayDiff;
}


function monthDif(inDate1, inDate2)
{
	var inDate1Year = inDate1.substring(0, 4);
	var inDate1Month = inDate1.substring(5, 7);
	var inDate1Day = inDate1.substring(8, 10);
	var inDate2Year = inDate2.substring(0, 4);
	var inDate2Month = inDate2.substring(5, 7);
	var inDate2Day = inDate2.substring(8, 10);
	var monthDiff = (parseInt(inDate1Year, 10) * 12 + parseInt(inDate1Month, 10)) - (parseInt(inDate2Year, 10) * 12 + parseInt(inDate2Month, 10));
	return monthDiff;
}


function checkEmpty(theObject,message)
{
	var s = theObject.value;
	if ((s == null) || (s.length == 0 ))
	{
		alert(message + vEmpty);
		theObject.focus();
		return false;
	}else{
		if(isWhitespace(s)){
			alert(message + vEmpty);
			theObject.focus();
			return false;
		}
	}
	return true;
}

function checkEmptyNoMsg(theObject)
{
	var s = theObject.value;
	if ((s == null) || (s.length == 0 ))
	{
		theObject.focus();
		return false;
	}else{
		if(isWhitespace(s)){
			theObject.focus();
			return false;
		}
	}
	return true;
}

function checkLength(theObject,sLength,message)
{
	var s = theObject.value;
	var l = parseInt(sLength);
	if (s.length > l)
	{
		alert(message + vLength);
		theObject.focus();
		theObject.select();
		return false;
	}
	return true;
}

function checkInteger(theObject,message)
{   
	var i;
	var s = theObject.value;
	if (isEmpty(s)) return true;

	for (i=0; i<s.length; i++)
	{
		var c = s.charAt(i);
		if (!isDigit(c)) 
		{
			alert(message + vDigit);
			theObject.select();
			theObject.focus();
			return false;
		}
	}
	
	return true;
}

function checkIntegerNoMsg(theObject)
{   
	var i;
	var s = theObject.value;
	if (isEmpty(s)) return true;

	for (i=0; i<s.length; i++)
	{
		var c = s.charAt(i);
		if (!isDigit(c)) 
		{
			theObject.select();
			theObject.focus();
			return false;
		}
	}
	
	return true;
}

function checkHexagonAmount(theObject,message)
{   
	var i=0;
	var j=0;
	var vSubAmount;
	var s = theObject.value;

	if (isEmpty(s)) {
			alert(message + vEmpty);
			theObject.select();
			theObject.focus();			
			return false;
	}	
	
	if(s.substring(0,1)=="," || s.substring(s.length-1,s.length)==","){
				alert(message+vDigitDot);
				theObject.focus();
				return false;	
	}
	var c;
	var index;
	for (i=0; i<s.length; i++)
	{
		c = s.charAt(i);				
		if(c==","){		
			index = s.indexOf(c);	
			vSubAmount = s.substring(0,index);				
			s = s.substring(index+1);				
			i=0;
			if(!isInteger(vSubAmount)&&!isDouble(vSubAmount))
			{				
				alert(message+vDigitDot);
				theObject.focus();
				return false;
        		}		
		} 
	}	
	if(!isInteger(s)&&!isDouble(s)){				
		alert(message+vDigitDot);
		theObject.focus();
		return false;
       	}	

	return true;
}
function checkFloat(theObject,message)
{
	var i;
	var s = theObject.value;
	var seenDecimalPoint = false;

	if (isEmpty(s)) return true;

	if (s == ".")
	{
		alert(message + vDigitDot);
		theObject.select();
		theObject.focus();
		return false;
	}

	for (i=0; i>s.length; i++)
	{
        // Check that current character is number.
		var c = s.charAt(i);

		if ((c == ".") && !seenDecimalPoint) seenDecimalPoint = true;
		else if (!isDigit(c)) 
		{
			alert(message + vDigitDot);
			theObject.select();
			theObject.focus();
			return false;
		}
	}

	return true;
}

function checkSignedDouble(theObject,message)
{
	var s = theObject.value;
	var startPos = 0;
	if (isEmpty(s)) return true;

	if ((s.charAt(0) == "-") || (s.charAt(0) == "+"))
		startPos = 1;

	if(!isDouble(s.substring(startPos, s.length))){
		alert(message + vDigitDot);
		theObject.select();
		theObject.focus();
		return false;
	}
	return true;
}

function checkInterestDouble(theObject,message,canNull)
{
	var s = theObject.value;
	if (theObject == null || isEmpty(s)){
		if (canNull)
			return true;
		else{
			alert (message + " could not be blank!");
			theObject.select();
			theObject.focus();
			return false;
		}
	}
	

	if(!isDouble(s)){
		alert(message + " must be a number with at most 2 decimal!");
		theObject.select();
		theObject.focus();
		return false;
	}
	return true;
}

function checkDouble(theObject,message)
{
	var i;
	var s = theObject.value;
	var seenDecimalPoint = false;

	if (isEmpty(s)) return true;

	if (s == ".") 
	{
		alert(message + vDigitDot);
		theObject.select();
		theObject.focus();
		return false;
	}

	for (i=0; i<s.length; i++)
	{
        // Check that current character is number.
		var c = s.charAt(i);

		if ((c == ".") && !seenDecimalPoint) seenDecimalPoint = true;
		else if (!isDigit(c))
		{
			alert(message + vDigitDot);
			theObject.select();
			theObject.focus();
			return false;
		}
	}
	
	//var p = s.charAt(s.length - 2);
        //if (p != ".") return false;
        
        var iSep = s.indexOf(".");
	
	if(seenDecimalPoint) {
		var sSlen = s.substring(iSep+1);
		if(sSlen.length >2 || sSlen.length < 1)
		{
			alert(message + vDigitDot);
			theObject.select();
			theObject.focus();
			return false;
		}
	}
	
	return true;	
}


function checkDoubleValue(theObject,message)
{

	var s = theObject.value;

	if (isEmpty(s)) return true;
	if (s >= 1000000000)
	{
		alert(message + vValue);
		theObject.select();
		theObject.focus();
		return false;
	}
	return true;	
}


function checkDate(theObject,message)
{
	var inStr = theObject.value;
	if (inStr=='' || inStr==null)
		return true;
		
	var dateString = '0123456789./-';
	var slash=0, dot=0, dash=0;
	var oneChar='', delimeter='';
	for (var i=0; i<inStr.length; i++)
	{
		oneChar = inStr.charAt(i);
		if (oneChar == '.')
			dot ++;
		else if (oneChar == '/')
			slash ++;
		else if (oneChar == '-')
			dash ++;
			
		if (dateString.indexOf(oneChar) == -1)
		{
			alert(message + vDate);
			theObject.select();
			theObject.focus();
			return false;
		}
	}
	
	/*
	if (inStr.length != 10)
	{
		alert(message + vDate);
		theObject.select();
		theObject.focus();
		return false;
	}
	*/
	if(inStr.length > 10 && inStr.length <8){
		alert(message + vDate);
		theObject.select();
		theObject.focus();
		return false;
	}
	
		
	if ((!dot==2 && !slash==2 && !dash==2) || (dot==2 && (slash>0 || dash>0)) || (slash==2 && (dot>0 || dash>0)) || (dash==2 && (slash>0 || dot>0)))
	{
		alert(message + vDate);
		theObject.select();
		theObject.focus();
		return false;
	}
	
	if (dot > 0)
		delimeter = '.';
	else if (slash > 0)
		delimeter = '/';
	else
		delimeter = '-';



	var del1st = inStr.indexOf(delimeter);
	var del2nd = inStr.lastIndexOf(delimeter);
	var year = parseInt(inStr.substring(0, del1st), 10);
	var month = parseInt(inStr.substring(del1st+1, del2nd), 10);
	var day = parseInt(inStr.substring(del2nd+1), 10);
	
	var tempDate = new Date(year, month-1, day, 0, 0, 0, 0);
	
	if (tempDate.getFullYear() != year || tempDate.getMonth() != month-1 || tempDate.getDate() != day)
	{
		alert(message + vDate);
		theObject.select();
		theObject.focus();
		return false;
	}
	
	return true;
}

function checkVerifyDate(theObject,format,message)
{
	var s = theObject.value;
	var chars="./-";
	var num = 0;
	var chr = null;
	var day = null;
	var month = null;
	var year = null;
	var firstdate = null;
	var lastdate = null;
	var vdate = null;

	if (!isEmpty(s))
	{
		for (j = 0; j < chars.length; j++ )
		{
			found = s.indexOf(chars.charAt(j));
			if (found > -1)
			{
				num = j;
				break;
			}
		
		}
		if (num == 0) chr = ".";
		else if (num == 1) chr = "/";
		else if (num == 2) chr = "-";
	
		if ((format.charAt(0) == "D") || (format.charAt(0) == "d"))
		{
			day = subStringFirst(s,chr,str);
			firstdate = subStringLast(s,chr,str);
			month = subStringFirst(firstdate,chr,str);
			year = subStringLast(firstdate,chr,str);
		}
		if ((format.charAt(0) == "M") || (format.charAt(0) == "m"))
		{
			month = subStringFirst(s,chr,str);
			firstdate = subStringLast(s,chr,str);
			day = subStringFirst(firstdate,chr,str);
			year = subStringLast(firstdate,chr,str);
		}
		if ((format.charAt(0) == "Y") || (format.charAt(0) == "y"))
		{
			year = subStringFirst(s,chr,str);
			firstdate = subStringLast(s,chr,str);
			month = subStringFirst(firstdate,chr,str);
			day = subStringLast(firstdate,chr,str);
		}
		vdate = year + "-" + month + "-" + day;
		obj=eval(theObject);
	
		if (!verifyDate(vdate))
		{ 
			if(message!=vNotShowMessage){
				alert(message + vDate);
			}
			obj.value = s;
			obj.select();
			obj.focus();
			return false;
		}
		obj.value = vdate;
	}
	return true;
	
}
//Add by Robin on 2002/1/8 to check the date format is : YYYY-MM
function checkVerifyPartDate(theObject,format,message)
{
	var s = theObject.value;
	var chars="./-";
	var num = 0;
	var chr = null;
	var month = null;
	var year = null;
	var firstdate = null;
	var lastdate = null;
	var vdate = null;

	if (!isEmpty(s))
	{
		for (j = 0; j < chars.length; j++ )
		{
			found = s.indexOf(chars.charAt(j));
			if (found > -1)
			{
				num = j;
				break;
			}
		
		}
		if (num == 0) chr = ".";
		else if (num == 1) chr = "/";
		else if (num == 2) chr = "-";
		
		if ((format.charAt(0) == "Y") || (format.charAt(0) == "y"))
		{
			year = subStringFirst(s,chr,str);
			month = subStringLast(s,chr,str);
		}
		
		vdate = year + "-" + month ;

		obj=eval(theObject);
	
		if (!verifyDate(vdate+"-01"))
		{ 
			alert(message + vDate);
			obj.value = s;
			obj.select();
			obj.focus();
			return false;
		}
		obj.value = vdate;
	}
	return true;
	
}
function subStringFirst(s,c,str)
{
	for (i = 0; i < s.length; i++)
	{
		found = c.indexOf(s.charAt(i));
		if (found > -1) 
		{
			if (i >= 1) str = s.substring(0,i);
			break;
		}
		
	}
	return str;
}
function subStringLast(s,c,str)
{
	for (i = 0; i < s.length; i++)
	{
		found = c.indexOf(s.charAt(i));
		if (found > -1) 
		{
			if (i >= 1) str = s.substring(i+1,s.length);
			break;
		}
		
	}
	return str;
}

function checkEmail(theObject,message)
{
	var s = theObject.value;
	if (isEmpty(s))
		return true;

    	if (isWhitespace(s))
		{
			alert(message + vEmail);
			theObject.focus();
			return false;
		}
    	if (!isValidEmailChar(s)) 
		{
			alert(message + vEmail);
			theObject.focus();
			return false;
		}

    	atOffset = s.lastIndexOf('@');

    	if ( atOffset < 1 )
        {
			alert(message + vEmail);
			theObject.focus();
			return false;
		}else
    	{
 			dotOffset = s.indexOf('.', atOffset);

			if ( dotOffset < atOffset + 2 || dotOffset > s.length - 2 )
			{
				alert(message + vEmail);
				theObject.focus();
				return false;
			}
		}
	return true;
}
function checkCurrencyIntegerCanNegative(theObject,message)
{   
	var i;
	var s = theObject.value;
	if (isEmpty(s)) return true;
	if(s.charAt(0)=='-'){
		s = s.substring(1);
	}
	for (i=0; i<s.length; i++)
	{
		var c = s.charAt(i);
		
		if (!isDigit(c)) 
		{
			alert(message + " must be a number without decimal!");
			theObject.select();
			theObject.focus();
			return false;
		}
	}
	
	return true;
}

function DefaultLoanID(theObject){
	today = new Date();
	var Year = today.getFullYear().toString();
	if (theObject.value=="")
	{
		theObject.value = "L" + Year.substring(Year.length-2,Year.length) + "00000";
	}
	
}

function DefaultDate(theObject){
	today = new Date();
//alert(today.getFullYear());
	if(theObject.value==""){
		//if ((today.getMonth()+1)<10)
		//{
		//	theObject.value=today.getFullYear()+"-0"+(today.getMonth()+1)+"-"+today.getDate();
		//}
		//else   theObject.value=today.getFullYear()+"-"+(today.getMonth()+1)+"-"+today.getDate();
		var Vday;
		var Vmonth;
		if ((today.getMonth()+1)<10)
		{
			Vmonth="0"+(today.getMonth()+1)
		}else 	Vmonth=(today.getMonth()+1)
		if ((today.getDate()+1)<10){
			Vday="0"+today.getDate();
		}else Vday=today.getDate();
	   theObject.value=today.getFullYear()+"-"+Vmonth+"-"+Vday;
	}   
}

function DefaultYear(theObject){
	today = new Date();
	if(theObject.value=="")
	   theObject.value=today.getFullYear();
}

function DefaultYearMonth(theObject){
	today = new Date();
	if(theObject.value=="")
		if ((today.getMonth()+1)<10)   theObject.value=today.getFullYear()+"-0"+(today.getMonth()+1);
	    else theObject.value=today.getFullYear()+"-"+(today.getMonth()+1);
}

function checkYearMonth(strDate)
{
	var myArray;
	if (strDate.indexOf("-") != -1)
	{
		myArray = strDate.split("-") ;
	}
	else  myArray = 0;
	
	
	if (myArray.length != 2) return false ;
	if (!isInteger(myArray[0]) || "") return false ;
	year = parseInt(leftTrimZero(myArray[0])) ;
	if (!isInteger(myArray[1]) || "") return false ;
	month = parseInt(leftTrimZero(myArray[1])) ;
	

	if (year <= 0 || year > 9999 || month <=0 || month > 12) return false ;
	
	switch(month)
	{
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
		case 2:
		case 4:
		case 6:
		case 9:
		case 11:
			break ;
		default :
			return false;
	}
	
	return true ;
}


function checkCurrencyInteger(theObject,message)
{   
	var i;
	var s = theObject.value;
	if (isEmpty(s)) return true;
	if (s.charAt(0)=='-'){
		alert(message + " must be a positive number!");
		theObject.select();
		theObject.focus();
		return false;
	}
	for (i=0; i<s.length; i++)
	{
		var c = s.charAt(i);
		if (!isDigit(c)) 
		{
			alert(message + " must be a number without decimal!");
			theObject.select();
			theObject.focus();
			return false;
		}
	}
	
	return true;
}
function checkCurrency(theObject, msg, canNull){
	var s = theObject.value;
	if (theObject == null || isEmpty(s)){
		if (canNull)
			return true;
		else{
			alert (msg + " could not be blank!");
			theObject.select();
			theObject.focus();
			return false;
		}
	}
		
	if (checkCurrencyInteger(theObject,msg)){
		if (s.length > 8){
			alert(msg + " length could not larger 8!");
			theObject.select();
			theObject.focus();
			return false;
		}
		return true;
	}else{
		return false;
	}
}

function checkCurrencyNoMsg(theObject, canNull){
	var s = theObject.value;
	if (theObject == null || isEmpty(s)){
		if (canNull)
			return true;
		else{
			theObject.select();
			theObject.focus();
			return false;
		}
	}
		
	if (checkCurrencyInteger(theObject,canNull)){
		if (s.length > 8){
			theObject.select();
			theObject.focus();
			return false;
		}
		return true;
	}else{
		return false;
	}
}

function checkCurrencyByPrecise(theObject, msg, canNull,precise){
	var s = theObject.value;
	if (theObject == null || isEmpty(s)){
		if (canNull)
			return true;
		else{
			alert (msg + " could not be blank!");
			theObject.select();
			theObject.focus();
			return false;
		}
	}
	if(s.charAt(0)=='-' || s.charAt(0)=='+'){
		alert(msg + " must be a positive number!");
		theObject.select();
		theObject.focus();
		return false;
	}
	if(!isCheckByPrecise(s,precise)){
		alert(msg + vDigitDot);
		theObject.select();
		theObject.focus();
		return false;
	}
	return true;
}
function checkCurrencyCanNegative(theObject, msg, canNull){
	var s = theObject.value;
	if (theObject == null || isEmpty(s)){
		if (canNull)
			return true;
		else{
			alert (msg + " could not be blank!");
			theObject.select();
			theObject.focus();
			return false;
		}
	}
	
	if (checkCurrencyIntegerCanNegative(theObject,msg)){
		if (s.length > 8){
			alert(msg + " length could not larger 8!");
			theObject.select();
			theObject.focus();
			return false;
		}
		return true;
	}else{
		return false;
	}

}
function checkCurrencyCanNegativeByPrecise(theObject, msg, canNull,precise){
	var s = theObject.value;
	if (theObject == null || isEmpty(s)){
		if (canNull)
			return true;
		else{
			alert (msg + " could not be blank!");
			theObject.select();
			theObject.focus();
			return false;
		}
	}
	
	if(s.charAt(0)=='-' || s.charAt(0)=='+'){
		s = s.substring(1);
	}
	if(!isCheckByPrecise(s,precise)){
		alert(msg + vDigitDot);
		theObject.select();
		theObject.focus();
		return false;
	}
	return true;
}
function checkTwoDate(FromDate, Todate){
	
	if(FromDate.value!="" && Todate.value!="") {
		if(monthDif(FromDate.value,Todate.value)>0){
			//alert("Date To"+vAfter+"  Date From");
			alert("Invalid Start Date");
			FromDate.focus();
			return false;
	    }
		if(dayDif(FromDate.value,Todate.value)>0){
			//alert("Date To"+vAfter+"  Date From");
			alert("Invalid Start Date");
			FromDate.focus();
			return false;
    	}
	}
	return true;
}
function isOkWithOutOrLastPayDate(obj, outObj, lastObj, msg){
	var outDate = outObj.value;
	var lastDate = lastObj.value;
	var thisDate = obj.value;
	var i = dayDif(outDate,thisDate);
	if (i > 0){
		alert(msg+" should be after \"Loan Out Date\"!");
		obj.select();
		obj.focus();
		return false;
	}
	if (lastDate == null || lastDate == ""){
		return true;
	}
	var j = dayDif(lastDate,thisDate);
	if (j > 0){
		alert(msg+" should be after \"Last Pay Date\"!");
		obj.select();
		obj.focus();
		return false;
	}
	return true;
}

// add by simon on 2001/11/06 
function checkODCurrency(theObject,message,canNull,canZero)
{
	var i;
	var s = theObject.value;
	var seenDecimalPoint = false;
	var decimalNum = 0;
	var intNum = 0;
	var isZero = true;
	
	if (isEmpty(s)){
		if (canNull){
			return true;
		}else{
			alert(message + " can not be null!");
			theObject.select();
			theObject.focus();
			return false;
		}
	}
	
	if (s == "."){
		alert(message + vDigitDot);
		theObject.select();
		theObject.focus();
		return false;
	}
	for (i=0; i<s.length; i++){
		var c = s.charAt(i);

		if ((c == ".") && !seenDecimalPoint){
			seenDecimalPoint = true;
		}else if (isDigit(c)) {
			if (c > "0") isZero = false;
			if (seenDecimalPoint){ 
				decimalNum++;
			}else{
				intNum++;
			}
		}else {
			alert(message + " must be a positive number!");
			theObject.select();
			theObject.focus();
			return false;
		}
	}
	if (decimalNum > 2) {
		alert(message + " has 2 decimal at most!");
		theObject.select();
		theObject.focus();
		return false;
	}
	if (intNum > 8){
		alert(message + " must between 0 and 99999999.99 !");
		theObject.select();
		theObject.focus();
		return false;
	}

	if (isZero && (!canZero)){
		alert(message + " can not be 0!");
		theObject.select();
		theObject.focus();
		return false;
	}
	return true;
}
function checkODCurrencyByPrecise(theObject,message,canNull,canZero,precise)
{
	var i;
	var s = theObject.value;
	var seenDecimalPoint = false;
	var decimalNum = 0;
	var intNum = 0;
	var isZero = true;
	
	if (isEmpty(s)){
		if (canNull){
			return true;
		}else{
			alert(message + " can not be null!");
			theObject.select();
			theObject.focus();
			return false;
		}
	}
	if (s == 0){
		if (canZero){
			return true;
		}else{
			alert(message + " can not be 0!");
			theObject.select();
			theObject.focus();
			return false;
		}
	}
	if (s == "."){
		alert(message + vDigitDot);
		theObject.select();
		theObject.focus();
		return false;
	}
	if(!isCheckByPrecise(s,precise)){
		alert(message + vDigitDot);
		theObject.select();
		theObject.focus();
		return false;
	}
	return true;
}
// add by simon on 2001/11/23 
function checkODCurrencyCanNegative(theObject,message,canNull,canZero)
{
	var i;
	var s = theObject.value;
	var seenDecimalPoint = false;
	var decimalNum = 0;
	var intNum = 0;
	var isZero = true;
	
	if (isEmpty(s)){
		if (canNull){
			return true;
		}else{
			alert(message + " can not be null!");
			theObject.select();
			theObject.focus();
			return false;
		}
	}
	
	if (s == "."){
		alert(message + vDigitDot);
		theObject.select();
		theObject.focus();
		return false;
	}
	for (i=0; i<s.length; i++){
		var c = s.charAt(i);
		if ((c == "-") && (i==0)){
			continue;
		}else if ((c == ".") && !seenDecimalPoint){
			seenDecimalPoint = true;
		}else if (isDigit(c)) {
			if (c > "0") isZero = false;
			if (seenDecimalPoint){ 
				decimalNum++;
			}else{
				intNum++;
			}
		}else {
			alert(message + " must be a number!");
			theObject.select();
			theObject.focus();
			return false;
		}
	}
	if (decimalNum > 2) {
		alert(message + " has 2 decimal at most!");
		theObject.select();
		theObject.focus();
		return false;
	}
	if (intNum > 8){
		alert(message + " must between 0 and 99999999.99 !");
		theObject.select();
		theObject.focus();
		return false;
	}

	if (isZero && (!canZero)){
		alert(message + " can not be 0!");
		theObject.select();
		theObject.focus();
		return false;
	}
	return true;
}
function checkODCurrencyCanNegativeByPrecise(theObject,message,canNull,canZero,precise)
{
	var i;
	var s = theObject.value;
	var seenDecimalPoint = false;
	var decimalNum = 0;
	var intNum = 0;
	var isZero = true;
	
	if (isEmpty(s)){
		if (canNull){
			return true;
		}else{
			alert(message + " can not be null!");
			theObject.select();
			theObject.focus();
			return false;
		}
	}
	if (s == 0){
		if (canZero){
			return true;
		}else{
			alert(message + " can not be 0!");
			theObject.select();
			theObject.focus();
			return false;
		}
	}
	if (s == "."){
		alert(message + vDigitDot);
		theObject.select();
		theObject.focus();
		return false;
	}
	if(s.charAt(0)=='-' || s.charAt(0)=='+'){
		s = s.substring(1);
	}
	if(!isCheckByPrecise(s,precise)){
		alert(message + vDigitDot);
		theObject.select();
		theObject.focus();
		return false;
	}
	return true;
}
// add by simon on 2002/02/04
function checkDoubleWith4Decimals(theObject,message,canNull,canZero)
{
	var i;
	var s = theObject.value;
	var seenDecimalPoint = false;
	var decimalNum = 0;
	var intNum = 0;
	var isZero = true;
	
	if (isEmpty(s)){
		if (canNull){
			return true;
		}else{
			alert(message + " can not be null!");
			theObject.select();
			theObject.focus();
			return false;
		}
	}
	
	if (s == "."){
		alert(message + vDigitDot);
		theObject.select();
		theObject.focus();
		return false;
	}
	for (i=0; i<s.length; i++){
		var c = s.charAt(i);

		if ((c == ".") && !seenDecimalPoint){
			seenDecimalPoint = true;
		}else if (isDigit(c)) {
			if (c > "0") isZero = false;
			if (seenDecimalPoint){ 
				decimalNum++;
			}else{
				intNum++;
			}
		}else {
			alert(message + " must be a positive number!");
			theObject.select();
			theObject.focus();
			return false;
		}
	}
	if (decimalNum > 4) {
		alert(message + " has 4 decimals at most!");
		theObject.select();
		theObject.focus();
		return false;
	}
	if (intNum > 8){
		alert(message + " must between 0 and 99999999.9999 !");
		theObject.select();
		theObject.focus();
		return false;
	}

	if (isZero && (!canZero)){
		alert(message + " can not be 0!");
		theObject.select();
		theObject.focus();
		return false;
	}
	return true;
}

//add by andrew li
function showDateFormat(){
	window.status=vDateFormat;
}

//add by andrew li
//check the phone number
function checkPhoneEng(theObject,msg){
	
	var s = theObject.value;
	//if is empty then return true
	if (isEmpty(s)) return true;
	//if the length < 8 then return false
	if(s.length < 8) {
		alert(msg + "must have more than or equal to 8 digits");
		theObject.select();
		theObject.focus();
		return false;		
	}
	var i;
	for (i=0; i<s.length; i++)
	{
		var c = s.charAt(i);
		if (!isDigit(c)) {
			
			alert(msg + "must have more than or equal to 8 digits");
			theObject.select();
			theObject.focus();
			return false;		
		}
	}	
	return;
}

//check the phone number
function checkPhoneNoMsg(theObject){
	
	var s = theObject.value;
	//if is empty then return true
	if (isEmpty(s)) return true;
	//if the length < 8 then return false
	if(s.length < 8) {
		theObject.select();
		theObject.focus();
		return false;		
	}
	var i;
	for (i=0; i<s.length; i++)
	{
		var c = s.charAt(i);
		if (!isDigit(c)) {
			theObject.select();
			theObject.focus();
			return false;		
		}
	}

	return true;	
}