<!--

function openWin(width, height, url, winname, showScrollbar){
	if(!showScrollbar) scrollStatus = "no" 
	else scrollStatus="yes";
	
	if (document.all)
		var xMax = screen.width, yMax = screen.height;
	else
		if (document.layers)
			var xMax = window.outerWidth, yMax = window.outerHeight;
		else
			var xMax = 640, yMax=480;
	var winWidth = width;
	var winHeight = height;
	var xOffset = (xMax-winWidth)/2, yOffset = ((yMax - winHeight)/2);
	
	popWin = window.open(url,winname,"width="+winWidth+",height="+winHeight+",screenX="+xOffset+",screenY="+yOffset+",top="+yOffset+",left="+xOffset+",scrollbars="+ scrollStatus +",toolbar=no");
	popWin.focus();
}
function showPic(objFile)
{
	if(!isEmpty(objFile.value))
		document.imgShow.src = objFile.value;
}
function showPic1(objFile)
{
	if(!isEmpty(objFile.value))
		document.imgShow1.src = objFile.value;
}
function showPic2(objFile)
{
	if(!isEmpty(objFile.value))
		document.imgShow2.src = objFile.value;
}
function showPic3(objFile)
{
	if(!isEmpty(objFile.value))
		document.imgShow3.src = objFile.value;
}
function showPic4(objFile)
{
	if(!isEmpty(objFile.value))
		document.imgShow4.src = objFile.value;
}
function showPic5(objFile)
{
	if(!isEmpty(objFile.value))
		document.imgShow5.src = objFile.value;
}
function showPic6(objFile)
{
	if(!isEmpty(objFile.value))
		document.imgShow6.src = objFile.value;
}
function showPic7(objFile)
{
	if(!isEmpty(objFile.value))
		document.imgShow7.src = objFile.value;
}
function showPic8(objFile)
{
	if(!isEmpty(objFile.value))
		document.imgShow8.src = objFile.value;
}
function showPic9(objFile)
{
	if(!isEmpty(objFile.value))
		document.imgShow9.src = objFile.value;
}
function showPic10(objFile)
{
	if(!isEmpty(objFile.value))
		document.imgShow10.src = objFile.value;
}
/*function showPics(objFile, objImg)
{
	if(!isEmpty(objFile.value))
		objImg.src = objFile.value;
}
function showPic(objFile)
{
	if(!isEmpty(objFile.value))
		document.imgShow.src = objFile.value;
}*/
function verifyEmail(strEmail, obj, objForm)
{
	var spaceExp = /^\s+$/;
	//var emailExp = /^[^\=\|\~\'\"!@#$%\^\&\*()\\\/\[\]{}\?<>:\;\-,]+\@[^\'\"!@#$%\^\&\*()\\\/\[\]{}\?<>:\;\-,]+\.[^\'\"!@#$%\^\&\*()\\\/\[\]{}\?<>:\;\-,]+$/; 
	var emailExp = /^[^\=\|\~\'\"!@#$%\^\&\*()\\\/\[\]{}\?<>:\;,]+\@[^\'\"!@#$%\^\&\*()\\\/\[\]{}\?<>:\;\-,]+\.[^\'\"!@#$%\^\&\*()\\\/\[\]{}\?<>:\;\-,]+$/; 
	var spaceInExp = /\s+/;
	var errMsg = "";
	var objFocus;
	var maxEmail = 200;
	
	if(strEmail == "" || isValid(spaceExp, strEmail))
	{
		errMsg += "กรุณากรอก email ผู้รับ\n";
		objFocus = (objFocus)? objFocus : obj;
	}
	else
	{
		arrEmail = strEmail.split(";");
		if(arrEmail.length > maxEmail)
		{
			errMsg += "ระบบสามารถส่งได้จำกัด "+maxEmail+" คนในหนึ่งครั้ง.\n";
			objFocus = (objFocus)? objFocus : obj;
		}
		else
		{
			var intCountEmail = 0;
			for(var intI=0; intI<arrEmail.length; intI++)
			{
				if(arrEmail[intI] != "" && !isValid(spaceExp, arrEmail[intI]))
				{
					if(arrEmail[intI] == "" || !isValid(emailExp, arrEmail[intI]))
					{
						errMsg += "กรุณากรอก email ให้ถูกต้อง รายการ #"+(intI+1)+"\n";
						objFocus = (objFocus)? objFocus : obj;
					}
					else
						if( isValid(spaceInExp, trimAll(arrEmail[intI])) )
						{
							errMsg += "Email ต้องไม่มีช่องว่าง รายการ #"+(intI+1)+"\n";
							objFocus = (objFocus)? objFocus : obj;
						}
						else
						{
							intCountEmail++;
						}
				} //==== if(arrEmail[intI] != "" && !isValid(spaceExp, arrEmail[intI]))
			} //==== for
			
		} //==== if(arrEmail.length > maxEmail)
	}
	return errMsg;
}

function setDecimal(val, point)
{
	val = val.toString();
	var posDot = val.indexOf(".");
			
	if(posDot != -1)
	{
		var posDotDecimal = posDot + point;
		
		if ((val.length - 1) <= posDotDecimal)
		{
			return (val);
		}
		else
		{
			//return (posDotDecimal+ val.substring(0, (posDotDecimal+1)));
			return (val.substring(0, (posDotDecimal+1)));
		}
	}
	else
		return (val);
}

function chkDate(objFrom, objTo)
{
	sdate = new Date(objFrom.value);
	edate = new Date(objTo.value);
	
	if (edate < sdate)
	{
		return false;
	}
	return true;
}

function chkDateVal(strSDate, strEDate)
{
	sdate = new Date(strSDate);
	edate = new Date(strEDate);
	
	if (edate < sdate)
	{
		return false;
	}
	return true;
}
		
function isValid(pattern, str)
{
	return pattern.test(str);
}

function isFolderName(txt)
{
	var charExp = /^[^\\\/\:\*\?\"\<\>\|]+$/;
	return charExp.test(txt);
}

function isSpace(txt)
{
	var spaceExp = /^\s+$/;
	if(spaceExp.test(txt)) 
		return true;
	else
		return false;
}

function isEmpty(txt)
{
	return (txt == "");
}

function spaceIn(txt)
{
	var spaceInExp = /\s+/;
	return spaceInExp.test(txt);
}

function isEmail(txt)
{
	//var emailExp = /^[^\=\|\~\'\"!@#$%\^\&\*()\\\/\[\]{}\?<>:\;\-,]+\@[^\'\"!@#$%\^\&\*()\\\/\[\]{}\?<>:\;,]+\.[^\'\"!@#$%\^\&\*()\\\/\[\]{}\?<>:\;\-,]+$/; 
	var emailExp = /^[^\=\|\~\'\"!@#$%\^\&\*()\\\/\[\]{}\?<>:\;,]+\@[^\'\"!@#$%\^\&\*()\\\/\[\]{}\?<>:\;,]+\.[^\'\"!@#$%\^\&\*()\\\/\[\]{}\?<>:\;\-,]+$/; 
	
	if(isEmpty(txt) || isSpace(txt))
		return false;
	else if(!emailExp.test(txt))
			return false;
		else if(spaceIn(trimAll(txt)))
			return false;
		else
			return true;
}

function isNumber(txt)
{
	var numberExp = /^[0-9]+$/;
	return numberExp.test(trimAll(txt))
}	

function isCurrency(val)
{
	var currencyExp = /^[0-9,.]+$/;
	return currencyExp.test(val);
}

function isMoney(val)
{
	if(isCurrency(trimAll(val)))
		return true;
	else
		//==== case else
		return false;
	 /*if(!isCurrency(trimAll(val)))
	{
		if( twoDecimal(trimAll(val)))
		//==== is two decimal with no more than maxValue
			return true;
		else
		//==== case else
			return false;
	}
	else //==== is number
		return true;*/
}

function isPrice(val, minVal, maxVal)
{
	var minValue = minVal;
	var maxValue = maxVal;
	
	if(isEmpty(val) || isSpace(val))
		return false;
	else if(!isNumber(trimAll(val)) || val > maxValue || val < minValue)
		{
			if( twoDecimal(trimAll(val)) && val <= maxValue && val >= minValue)
			//==== is two decimal with no more than maxValue
				return true;
			else
			//==== case else
				return false;
		}
		else //==== is number
			return true;
}

function isDecimal(txt)
{
	var pointExp = /^[0-9]+\.[0-9]*$/;
	return pointExp.test(txt);
}

function twoDecimal(txt)
{
	var decimalExp = /^[0-9]+\.[0-9]{0,2}$/;
	var decimalExp1 = /^[0-9]+\.0*$/;
	return decimalExp.test(txt) || decimalExp1.test(txt);
}


function trimLeft(s)
{
 i=0;
 n= s.length;
  while((i<n)&&(s.charAt(i)==' ')) i++;
	s = s.substring(i);
  return(s);
} 

function trimRight(s)
{
 n= s.length;
 i= s.length-1;
 while((i>=0)&&(s.charAt(i)==' ')) i--;
	s = s.substring(0,i+1);
 return(s);
}

function trimAll(s)
{
 s = trimLeft(s);
 s = trimRight(s);
 return(s);
} 