<!--
/****************************************************/
//		### Checking Function ###
//		1.   IsEmailCorrect(szEmail)
//		2.   IsEmpty(szStr)
//		3.   IsEngString(szStr)
//		4.   IsThaiString(szStr)
//		5.   IsAlphaNumeric(szStr)
//		6.   IsNumeric(szStr)
//		7.   IsInteger(szStr)
//		8.   IsDecimal(szStr, leading, decimal)
//		9.   IsOnlyNumber(szStr)
//		10.  CheckMaximumValue(szStr,dbMax)
/****************************************************/

function IsEmailCorrect(szEmail) 
{
	var i;
	var strtmp = Trim(szEmail);

	for (i=0; i<strtmp.length; i++) {
		if (strtmp.charAt(i) > 'z' || strtmp.charAt(i) < '-' || ("/:;<=>?[\\]^` ".indexOf(strtmp.charAt(i)) != -1))
			return false;
	}
	if (CountStr(strtmp, "@") != 1 || strtmp.indexOf("..") != -1)
		return false;

	if (strtmp.charAt(0) == '@' || strtmp.charAt(strtmp.length - 1) == '@')
		return false;

	while ((i = strtmp.indexOf(".")) != -1) {
		if (i <= 0 || i >= (strtmp.length - 1))
			return false;
		if (strtmp.charAt(i - 1) == '@' || strtmp.charAt(i + 1) == '@')
			return false;
		strtmp = strtmp.substring(i + 1);
	}

	return true;
}

function CountStr(strSrc, strFind) {
	var i, nCount = 0;

	while ((i = strSrc.indexOf(strFind)) != -1) {
		nCount++;
		strSrc = strSrc.substring(i + strFind.length, strSrc.length);
	}

	return nCount;
}

function Left(szStr, nChar)
{
	if(szStr.length > nChar)
		return szStr.substring(0, nChar);
	else
		return szStr
}

function Right(szStr, nChar)
{
	if(szStr.length > nChar)
		return szStr.substring(szStr.length - nChar, szStr.length);
	else
		return szStr;
}



// return true if szStr contains space or empty. Otherwise, return false
function IsEmpty(szStr) 
{
	for(var i=0; i<szStr.length; i++) {
		if(szStr.charAt(i) == ' ')
			szStr = szStr.substring(i-- + 1, szStr.length);
		else
			break;
	}
	if(szStr.length)
		return false;
	else
		return true;
}

function IsEngString(szStr) 
{
	szStr = szStr.toLowerCase();
	for(var i=0; i<szStr.length; i++) {
		if(!((szStr.charAt(i) >= 'a' && szStr.charAt(i) <= 'z') || szStr.charAt(i) == ' ' || szStr.charAt(i) == '.'))
			return false;
	}
	return true;
}

function IsThaiString(szStr) 
{
	for(var i=0; i<szStr.length; i++) {
		if(szStr.charCodeAt(i) <= 128 && szStr.charAt(i) != ' ')
			return false;
	}
	return true;
}

function IsAlphaNumeric(szStr) 
{
	szStr = szStr.toLowerCase();
	for(var i=0; i<szStr.length; i++) {
		if(!((szStr.charAt(i) >= 'a' && szStr.charAt(i) <= 'z') || (szStr.charAt(i) >= '0' && szStr.charAt(i) <= '9')))
			return false;
	}
	return true;
}

function IsNumeric(szStr) 
{
	for(var i=0; i<szStr.length; i++) {
		if("0123456789+-.,".indexOf(szStr.charAt(i)) == -1)
			return false;
	}
	return true;
}

function IsInteger(szStr) 
{
	for(var i=0; i<szStr.length; i++) {
		// dot is not allow for integer
		if("0123456789+-,".indexOf(szStr.charAt(i)) == -1)
			return false;
	}
	return true;
}

function IsDecimal(szStr, leading, decimal) 
{
	var dotCount = 0;
	for(var i=0;i<szStr.length;i++) {
		if("0123456789+-.,".indexOf(szStr.charAt(i)) == -1) {
			return false;
		}
		else { // need to check if there are more than one dot
			if(".".indexOf(szStr.charAt(i)) != -1)
				dotCount++;
		}
	}

	if(dotCount > 1)  // more than one dot
		return false;

	if(decimal < 1 && dotCount > 0)
		return false;

	var dotIndex = szStr.indexOf(".");
	if(dotIndex == -1) { // no dot, consider only leading and leght of number
		if(szStr.length > leading)
			return false;
	}
	else {
		if(dotIndex > leading)  // integer number is more than leading allow
			return false;
		if((szStr.length - (dotIndex+1)) > decimal) // decimal number is more than decimal allow
			return false;
	}

	return true;
}

function IsOnlyNumber(szStr) 
{
		for(var i=0;i<szStr.length;i++) {
			// except number, nothing is allow
			if("0123456789".indexOf(szStr.charAt(i)) == -1)
				return false;
		}
		return true;
}

function IsOnlyDecimal(szStr) 
{
		for(var i=0;i<szStr.length;i++) {
			// except number, nothing is allow
			if("0123456789.".indexOf(szStr.charAt(i)) == -1)
				return false;
		}
		return true;
}


	
function CheckNumeric(objEvent) 
{
	//browser detection
	var strUserAgent = navigator.userAgent.toLowerCase(); 
	var isIE = strUserAgent.indexOf("msie") > -1; 
	var isNS6 = strUserAgent.indexOf("netscape6") > -1; 
	var isNS4 = !isIE && !isNS6  && parseFloat(navigator.appVersion) < 5; 

	//regular expressions
	var reValidChars = /\d/;

	var iKeyCode, strKey;  

	if (isIE) 
	{
		iKeyCode = objEvent.keyCode;
	} else 
	{
		iKeyCode = objEvent.which;
	}

	strKey = String.fromCharCode(iKeyCode);

	if (!reValidChars.test(strKey)) 
	{
		return false;
	}
}


	
function CheckNumericDecimal(objEvent) 
{
	//browser detection
	var strUserAgent = navigator.userAgent.toLowerCase(); 
	var isIE = strUserAgent.indexOf("msie") > -1; 
	var isNS6 = strUserAgent.indexOf("netscape6") > -1; 
	var isNS4 = !isIE && !isNS6  && parseFloat(navigator.appVersion) < 5; 

	//regular expressions
	var reValidChars = /[*\d\.]/;

	var iKeyCode, strKey;  

	if (isIE) 
	{
		iKeyCode = objEvent.keyCode;
	} else 
	{
		iKeyCode = objEvent.which;
	}

	strKey = String.fromCharCode(iKeyCode);

	if (!reValidChars.test(strKey)) 
	{
		return false;
	}
}

function CheckMaximumValue(szStr,dbMax)
{
		var strAmount = szStr;
		strAmount = strAmount.replace(/,/gi,"");
		var dbAmount = parseFloat(strAmount);
		if ( dbAmount >= dbMax )
		{
			return false;
			
		}
		return true;
}

// Remove white space on the both side;
function Trim(szStr) {
	return TrimLeft(TrimRight(szStr));
}

// Remove white space on the left side;
function TrimLeft(szStr) {
	for(var i=0; i<szStr.length; i++) {
		if(szStr.charAt(i) == ' ')
			szStr = szStr.substring(i-- + 1, szStr.length);
		else
			break;
	}
	return szStr;
}

// Remove white space on the right side;
function TrimRight(szStr) {
	for(var i=szStr.length - 1; i>=0; i--) {
		if(szStr.charAt(i) == ' ')
			szStr = szStr.substring(0, i);
		else
			break;
	}
	return szStr;
}

// Is there the szStr contain any space ?
function ContainSpace(szStr) {
	if(szStr.indexOf(' ') != -1)
		return true;
	return false;
}

// Conver two or more space to the single space
function CompactSpace(szStr) {
	var nSpace = 0;
	var sztmp;
	for(var i=0; i<szStr.length; i++) {
		if(szStr.charAt(i) == ' ') {
			nSpace++;
		}
		else
			nSpace = 0;

		if(nSpace >= 2) {
			nSpace = 0;
			sztmp = szStr.substring(0, i);
			szStr = sztmp + szStr.substring(i + 1, szStr.length);
			i--;
		}
	}
	return szStr;
}


/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

/* check formate date dd/mm/yyyy   */
function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strDay=dtStr.substring(0,pos1 )
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : dd/mm/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}


-->