<!--

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 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;
}

// 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) >= '0' && szStr.charAt(i) <= '9') || szStr.charAt(i) == ' ' || szStr.charAt(i) == '_' || 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) != ' ' && szStr.charAt(i) != '_' && szStr.charAt(i) != '-' && 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 IsAlphaSymbol(szStr) {
	szStr = szStr.toLowerCase();
	for(var i=0; i<szStr.length; i++) {
		if(!(szStr.charCodeAt(i) >= 32 && szStr.charCodeAt(i) <= 127))
			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 IsLoginName(strLogin) {
	if (IsEmpty(strLogin) || !IsEngString(strLogin) || strLogin.length < 4 || ContainSpace(strLogin))
		return false;
	return true;
}

function IsPassword(strPassword) {
	if (IsEmpty(strPassword) || !IsAlphaSymbol(strPassword) || strPassword.length < 4 || ContainSpace(strPassword))
		return false;
	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;
}

// Because of the build-in function ".replace" cannot replace any string with the empty string
// the only way we can do is the following...
function RemoveStr(szStr, szRemove)
{
	var sztmp, i;

	while((i = szStr.indexOf(szRemove)) != -1) {
		sztmp = szStr.substring(0, i);
		sztmp += szStr.substring(i + szRemove.length, szStr.length);
		szStr = sztmp;
	}

	return szStr;
}

// 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;
}

function SwapItem(objLList, objRList, clickMode)
{
	// checking item has selected.
	if(clickMode == "1")	// click move to right
	{
		var objList1 = objLList;
		var objList2 = objRList;

		if(objLList.selectedIndex == -1)
		{
			//alert("Please select user(s) in available user list first.");
			objLList.focus();
			return false;
		}
	}
	else	 // click move to left
	{
		var objList1 = objRList;
		var objList2 = objLList;

		if(objRList.selectedIndex == -1)
		{
			//alert("Please select user(s) in user group list first.");
			objRList.focus();
			return false;
		}
	}

	// move selected item to another list
	var strUnSelect = "";
	for(var i = 0; i < objList1.length; i++)
	{
		if(objList1[i].selected)
		{
			var listindex = objList2.length;
			var newitem = Option(objList1[i].text, objList1[i].value);
			objList2[listindex] = newitem;
		}
		else
			strUnSelect += objList1[i].text + "|" + objList1[i].value + "^";
	}

	// delete all selected list 
	objList1.length = 0;
	
	// put unselect item into list
	while(1)
	{
		nPos = strUnSelect.indexOf("^") + 1;
		if(nPos < 1) break;
		strItem = Left(strUnSelect, nPos - 1);
		strUnSelect = Right(strUnSelect, strUnSelect.length - nPos);

		nPos = strItem.indexOf("|") + 1;
		strText = Left(strItem, nPos - 1);
		strValue = Right(strItem, strItem.length - nPos);

		var listindex = objList1.length;
		var newitem = Option(strText, strValue);
		objList1[listindex] = newitem;
	}
}

function SwapAllItem(objLList, objRList, clickMode)
{
	// checking item has selected.
	if(clickMode == "1")	// click move to right
	{
		var objList1 = objLList;
		var objList2 = objRList;
	}
	else	 // click move to left
	{
		var objList1 = objRList;
		var objList2 = objLList;
	}

	// move selected item to another list
	var strUnSelect = "";
	for(var i = 0; i < objList1.length; i++)
	{
		var listindex = objList2.length;
		var newitem = Option(objList1[i].text, objList1[i].value);
		objList2[listindex] = newitem;
	}

	// delete all selected list 
	objList1.length = 0;
	
	// put unselect item into list
	while(1)
	{
		nPos = strUnSelect.indexOf("^") + 1;
		if(nPos < 1) break;
		strItem = Left(strUnSelect, nPos - 1);
		strUnSelect = Right(strUnSelect, strUnSelect.length - nPos);

		nPos = strItem.indexOf("|") + 1;
		strText = Left(strItem, nPos - 1);
		strValue = Right(strItem, strItem.length - nPos);

		var listindex = objList1.length;
		var newitem = Option(strText, strValue);
		objList1[listindex] = newitem;
	}
}

function swapMonthDateValue(checkdate){

	if (checkdate != "") {
		var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
		var matchArray = checkdate.match(datePat); // is the format ok?
		if (matchArray == null) {
			err_text = "Date is not in a valid format.";
			return false;
		}
		day = matchArray[1]; // parse date into variables
		month = matchArray[3];
		year = matchArray[4];
		if(month < 10){
			month = "0" + month;
		}
		if(day < 10){
			day = "0" + day;
		}																
		
		return month + "/" + day + "/" + year;;
	}else{
		return "";
	}
}			
function ClickShowPicCurrent(file)
{
	window.open(file, "current", "width=480,height=400,scrollbars=yes");
}

function ClickShowPicPreview(file)
{
	if(file != "")
	{	
		window.open("../../include/preview.php?img=" + escape(file), "preview", "width=480,height=400,scrollbars=yes");
	}
}	

function ClickShowDocCurrent(file)
{
	window.open(file, "current", "width=800,height=600,scrollbars=yes");
}

function ClickShowDocPreview(file)
{
	if(file != "")
	{	
		window.open(file, "preview", "width=850,height=600,scrollbars=yes");
	}
}

function dateValidation(cmbDay, cmbMonth, cmbYear) {
			var nDay = cmbDay.options[cmbDay.options.selectedIndex].value;
			var nMonth = cmbMonth.options[cmbMonth.options.selectedIndex].value;
			var nYear = cmbYear.options[cmbYear.options.selectedIndex].value;
			var nMaxDay = 0;

			if(nMonth == 4 || nMonth == 6 || nMonth == 9 || nMonth == 11)
				nMaxDay = 30;
			else if(nMonth == 2) {
				if(nYear % 4 == 0 && (nYear % 100 != 0 || nYear % 400 == 0))
					nMaxDay = 29;
				else
					nMaxDay = 28;
			}
			else
				nMaxDay = 31;

			if(nDay > nMaxDay) {
				cmbDay.options.selectedIndex = nMaxDay;
			}
}

function IsValidFileType(szStr, lstFileAvailable) {
		var szStrExtension, IsValid;
		IsValid = false;
		szStrExtension = getFileExtension(szStr);						
		if( (lstFileAvailable.replace(' ','') != "") && (szStrExtension != "") ) {					
			arrFileAvailable = ListToArray(lstFileAvailable,",");
			for (i=0; i < arrFileAvailable.length; i++){							
					if (szStrExtension.toLowerCase( ) == arrFileAvailable[i].replace(' ','').toLowerCase( )){
						IsValid = true;
						break;
					}
			}
		}
		return IsValid;
	}

function ListToArray(lstStr, Delimiter){
	var szTemp, idxStr, arrayIdx=0;
	var arrayTemp = new Array();
	szTemp = lstStr;
	if (Delimiter.length == 0) Delimiter = ",";
	for(i=0;((szTemp != "") && (i<=100)); i++ ){
			idxStr = szTemp.indexOf(Delimiter);		
			//alert('Loop No. [' + i +']   idxStr = ' + idxStr + ' ; szTemp =' + szTemp + '   arrayLen = ' + arrayTemp.length);
			if (parseInt(idxStr) != -1){

					if((szTemp.substring(0, parseInt(idxStr) - 1) != "") && (szTemp.substring(0, parseInt(idxStr) - 1) != Delimiter)){
							if (arrayTemp.length != 0) arrayIdx = arrayTemp.length;
							arrayTemp[arrayIdx] = szTemp.substring(0, parseInt(idxStr));
					}
					szTemp =  szTemp.substring(parseInt(idxStr)+1 ,szTemp.length);

			}else{

					if ((szTemp != "") && (szTemp != Delimiter)){
							if (arrayTemp.length != 0) arrayIdx = arrayTemp.length;
							arrayTemp[arrayIdx] = szTemp;
					}							
					szTemp = "";								

			}						
	}
	return arrayTemp;
}

function getFileExtension(szStr){  // Definition: file extension is alls string after last dot ( dot included in return value)
			var szTemp, idxStr;
			szTemp = szStr;
			if( szTemp.replace(' ','') != "") {
				idxStr = szTemp.lastIndexOf(".");
				szTemp =  szTemp.substring(parseInt(idxStr),szTemp.length);
				return szTemp;
			}	
			return "";
}
			
function IsRadioChecked(objRadio){
		szTemp = false;
		szLen = objRadio.length;
		if (szLen > 0){
			for(i=0;i< szLen; i++){
					if (objRadio[i].checked == 1){
						szTemp = true;
						break;
					}
			}
		}
		return szTemp;
}

function isValidDate(cmbDay, cmbMonth, cmbYear) {
					var nDay = cmbDay.options.selectedIndex;
					var nMonth = cmbMonth.options.selectedIndex;
					var nYear = cmbYear.options.selectedIndex;
					 if (!(nDay && nMonth && nYear)){
					 		return false;
					 }
					 return true;
}			
//-->