
function leftTrimZero(str)
{
	var end = false;
	var ch;
	while(!end){
		if (str.length == 0) break;
		ch = str.charAt(0);
		if (ch == '0')	str = str.substring(1,str.length);
		else end = true;
	}
	return str;
}

function isDate(strDate)
{
	if (strDate.indexOf("/") != -1)
	{
		myArray = strDate.split("/") ;
	}	
	else
	{
		myArray = strDate.split("-") ;		
	}
	if (myArray.length != 3) return false ;
	if (!isNumeric(myArray[0]) || "" == leftTrimZero(myArray[0])) return false ;
	year = parseInt(leftTrimZero(myArray[0])) ;
	if (!isNumeric(myArray[1]) || "" == leftTrimZero(myArray[1])) return false ;
	month = parseInt(leftTrimZero(myArray[1])) ;
	if (!isNumeric(myArray[2]) || "" == leftTrimZero(myArray[2])) return false ;
	day = parseInt(leftTrimZero(myArray[2])) ;

	bLeap = false ;
	bBigMonth = false ;
	
	if (year <= 0 || year > 9999 || month <=0 || month > 12 || day > 31 || day <=0) return false ;
	if (year%4 == 0) 	
	{
		if ((year%100 != 0) || (year%400 == 0))
			bLeap = true ; 
	}
	switch(month)
	{
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			bBigMonth = true ;
			break ;
		case 2:
		case 4:
		case 6:
		case 9:
		case 11:
			break ;
		default :
			return false;
	}
	if (day == 29 && month == 2 && !bLeap) return false ;
	if (day > 30 && !bBigMonth) return false ;
	return true ;
}

function isPhone(strPhone)
{
	if (strPhone.indexOf("-") != -1)
	{
		myPhone = strPhone.split("-") ;
	}	
	else
	{
		return false;
	}	
	if (myPhone.length != 3) return false ;
	if (!isNumeric(myPhone[0]) || myTrim(myPhone[0])=="0") return false ;
	if (!isNumeric(myPhone[1])) return false ;
	if (!isNumeric(myPhone[2]) || myTrim(myPhone[2])=="0") return false ;
	return true ;
}

function myTrim(str)
{
	var end = false;
	var ch;
	while(!end){
		if (str.length == 0) break;
		ch = str.charAt(0);
		if (ch == ' ')	str = str.substring(1,str.length);
		else end = true;
	}
	end = false;
	while(!end){
		if (str.length == 0) break;
		ch = str.charAt(str.length-1);
		if (ch == ' ')	str = str.substring(0,str.length-1);
		else end = true;
	}
	return str;
}

function isEmail(str)
{
	if (-1 != str.indexOf("@"))
		return true ;
	else 
		return false ;
}

function isNumeric(strNum)
{	
	if (myTrim(strNum)=="") return false;
	var i;
	for(i = 0; i < strNum.length; i++)
	{
		var ch = strNum.charAt(i);
		if (ch < '0' || ch > '9') return false;
	}
	return true;
}

function isID(str)
{
	if (str.length < 4 || str.length > 20) return false ;
	var i;
	for(i = 0; i < str.length; i++)
	{
		var ch = str.charAt(i);
		if ( (ch < 'A' || ch > 'Z') && (ch < 'a' || ch > 'z') && (ch < '0' || ch > '9')) return false;
	}
	return true;
}

function isPwd(str)
{
	if (str.length < 4 || str.length > 20) return false ;
	var i;
	for(i = 0; i < str.length; i++)
	{
		var ch = str.charAt(i);
		if ( (ch < 'A' || ch > 'Z') && (ch < 'a' || ch > 'z') && (ch < '0' || ch > '9')) return false;
	}
	return true;
}

function isPager(strPager)
{
	var i;
	for(i = 0; i < strPager.length; i++)
	{
		var ch = strPager.charAt(i);
		if ((ch < '0' || ch > '9') && ch != '-') return false;
	}
	return true;
}
function isPostCode(strCode)
{
	if (strCode.length != 6 || !isNumeric(strCode)) return false ;
	return true ;
}	