
//-->

//###############################################################
//###
//### @project name : PWAS Project [Private Web Application]
//### @libraly name : main
//### @libraly type : JavaScript
//### @author : Prachaya Chotchoung 
//### @email : oddparity@hotmail.com
//### @copyright : Prachaya Chotchoung (c)2005
//### @site :
//### @version : 0.1
//### @last modify : 2005/09/22 13:30
//###																																		###
//###############################################################


// Default SwapImage from Dreamweaver generator
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}

function windowClose(){
window.close();
}





//*********************************************************
// Private Function
//*********************************************************
//////////////////////////////////////////////////////////////////
// Function : changeDateFormat();
//--------------------------------------------------
// Parameter : date(string),thai year(boolean)
//--------------------------------------------------
// Return : 
//--------------------------------------------------
// Example : - 
//////////////////////////////////////////////////////////////////
function changeDateFormat(dateStr,thaiYear){	
    var temp = dateStr.value;  	 
	var strlen = temp.length;
	var ret = "";
	var now=new Date();	
//	var	tyear=now.getYear();	
	tyear = "2500";	
	var strtmp = "00";	
	var bool = true;
	
    if (strlen <= 0 ){
		return ret;
	}else{
		if(strlen<6){
			bool = false;
		}else{		
			var position1 = temp.indexOf("/");
			if (position1 == -1) {										
				date = temp.substring(0,2);
				month = temp.substring(2,4);				
				year = temp.substring(4,temp.length);				
			}else{			
				if(position1<=2){
					date = temp.substring(0,position1);												
					temp = temp.substring(position1+1,temp.length);																	
					var position2 = temp.indexOf("/");
					if(position2<=2){
						month = temp.substring(0,position2);												
						temp = temp.substring(position2+1,temp.length);																	
						var position2 = temp.indexOf("/");
						var year = temp.substring(position2 + 1,temp.length);												
					}else{
						bool = false;
					}
				}else{
					bool = false;
				}				
			}			
			if(date.length<2){
				date = strtmp.substring(0,(2 - date.length))+date;
			}
			if(month.length<2){
				month = strtmp.substring(0,(2 - month.length))+month;
			}			
			if(year.length<4){
				year = tyear.substring(0,(4 - year.length))+year;
			}

			ret = date+"/"+month+"/"+year;	
			if(checkDateFormat(ret,true)&&bool){				
				dateStr.value = ret;  					
			}else{
				alert('ระบุวันเดือนปีไม่ถูกต้อง');
				dateStr.value = "";	
			}

		}
	}
}

//////////////////////////////////////////////////////////////////
// Function : checkDigit();
//--------------------------------------------------
// Parameter : none
//--------------------------------------------------
// Return : number 0-9
//--------------------------------------------------
// Example : - 
//////////////////////////////////////////////////////////////////
function isDigitByCode(code){
	return code >= 48 && code <= 57;
}

function checkDigit(){
	var key = event.keyCode;
	if(!isDigitByCode(key)){
		event.returnValue = false;
	}
}

//////////////////////////////////////////////////////////////////
// Function : replaceString(oldStr, newStr, tempStr)
//--------------------------------------------------
// Parameter :
// oldStr >> text that you want to be replace
// newStr >> text that you want to replace
// tempStr >> text that you want to seacrh oldStr and replace with newStr
//--------------------------------------------------
// Return : String result that already replace oldStr with newStr
//--------------------------------------------------
// Example :
// replaceString("/", " ", "19/08/2548") = "19 08 2548"
//////////////////////////////////////////////////////////////////
function replaceString( tempStr,oldStr, newStr) {
	var result = tempStr;
	var position = result.indexOf(oldStr);
	while (position  >= 0) {
		if (position == 0) {
			result = newStr + result.substring(position + 1, result.length);
		} else if (position == result.length - 1) {
			result = result.substring(0, position - 1) + newStr;
		} else {
			result = result.substring(0, position) + newStr + result.substring(position + 1, result.length);
		}
		position = result.indexOf(oldStr);
	}
	return result;
}

//////////////////////////////////////////////////////////////////
// Function : removeSpace(text, mode)
//--------------------------------------------------
// Parameter :
// text >> text that you want to cut space
// mode >>
// "1" trim left space only
// "2" trim right space only
// "3" trim both left and right space
//--------------------------------------------------
// Return : String result that already cut space
//--------------------------------------------------
// Example :
// removeSpace("  Yeah Yeah      ", "1") =  "Yeah Yeah      "
// removeSpace("  Yeah Yeah      ", "2") =  "  Yeah Yeah"
// removeSpace("  Yeah Yeah      ", "3") =  "Yeah Yeah"
//////////////////////////////////////////////////////////////////
function removeSpace(text, mode) {
	var result = text;
	var spacepos = 0;
	if (mode == "1" || mode == "3") {
		spacepos = result.indexOf(" ");
		while (spacepos == 0 && result.length > 1) {
			result = result.substring(1, result.length);
			spacepos = result.indexOf(" ");
		}
	}
	if (mode == "2" || mode == "3") {
		spacepos = result.lastIndexOf(" ");
		while (spacepos == result.length - 1 && result.length > 1) {
			result = result.substring(0, result.length - 1);
			spacepos = result.lastIndexOf(" ");
		}
	}
	if (result == " ") {
		result = "";
	}
	return result;
}

//////////////////////////////////////////////////////////////////
// Function : checkDateFormat(dateStr, thaiYear)
//--------------------------------------------------
// Parameter :
// dateStr >> text that you want to check
// thaiYear >> True if it Thai Year, False for Europe Year
//--------------------------------------------------
// Return :
// true when input is correct format
// false if it not correct
//--------------------------------------------------
// Example : 
// checkDateFormat("12/abc/2548", true) = false
// checkDateFormat("31/4/2548", true) = false
// checkDateFormat("29/2/2548", true) = false
// checkDateFormat("29/2/2004", false) = true
// checkDateFormat("29/2/2547", true) = true
// checkDateFormat("26/07/2548", true) = true
//////////////////////////////////////////////////////////////////
function checkDateFormat(dateStr, thaiYear) {
//	alert (dateStr);
    var temp = dateStr;
    var position = temp.indexOf("/");
    if (position == -1) {return false;}
    var date = temp.substring(0, position);
    temp = temp.substring(position + 1, temp.length);
    position = temp.indexOf("/");
    if (position == -1) {return false;}
    var month = temp.substring(0, position);
    var year = temp.substring(position + 1, position + 5);

    if (!(month >= 1 && month <= 12)) {
		return false;
    }
    if (!(year >= 1000 && year <= 9999)) {
        return false;
    }
    // For Europe Year
	var oddity = 0;
	if (thaiYear) {
		// For Thai Year
		oddity = 3;
	}
    if (((year % 4) == oddity)&&(month == 2)) {
	    if (!(date >= 1 && date <= 29)) {
		    return false;
	    }
    } else {
	    var lastDay = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	    if (!(date >= 1 && date <= lastDay[month - 1])) {
		    return false;
	    }
    }
    return true;
}

//////////////////////////////////////////////////////////////////
// Function : checkDateBetween(dateStr1,dateStr2)
// --------------------------------------------------
// Parameter :
// dateStr1 >> text that you want check
// dateStr2 >> text that you want check
//--------------------------------------------------
// Return :
// true when dateStr1 <= dateStr2
// false when dateStr1 > dateStr2
//--------------------------------------------------
// Example : 
// checkDateBetween("01/02/2548","10/02/2548") return true
// checkDateBetween("10/02/2548","01/02/2548") return false
//--------------------------------------------------
// Caution :
//////////////////////////////////////////////////////////////////
function checkDateBetween(date1, date2){
	if(removeSpace(date1)!="" && removeSpace(date2)!=""){
		date1=translateDateToNumber(date1);
		date2=translateDateToNumber(date2);
		if(date1 > date2){
		    value=false;
		}else{
		    value=true;
		}
	}
	else{
		value=true;
	}

	return value;
}

//////////////////////////////////////////////////////////////////
// Function : translateDateToNumber(dateStr)
// Change to number for doing date comparation
//--------------------------------------------------
// Parameter :
// dateStr >> text that you want to translate to number
//--------------------------------------------------
// Return :
// Number that calculate from date
//--------------------------------------------------
// Example : 
// translateDateToNumber("31/4/2548") = 25480431
// translateDateToNumber("19/08/2550") = 25500819
//--------------------------------------------------
// Caution :
// This function don't have process to check format.
// So you should use checkDateFormat() (function above)
// for check format before call this function.
//////////////////////////////////////////////////////////////////
function translateDateToNumber(dateStr) {
	var temp = dateStr;
//	var charSpec = temp.indexOf("/");
	if(temp.indexOf("/")> 0){
	    var position = temp.indexOf("/");
	    var text1 = temp.substring(0, position);
	    temp = temp.substring(position + 1, temp.length);
	    position = temp.indexOf("/");
	    var text2 = temp.substring(0, position);
	    var text3 = temp.substring(position + 1, position + 5);
    }else if(temp.indexOf(".")>0){
	    var position = temp.indexOf(".");
	    var text1 = temp.substring(0, position);
	    temp = temp.substring(position + 1, temp.length);
	    position = temp.indexOf(".");
	    var text2 = temp.substring(0, position);
	    var text3 = temp.substring(position + 1, position + 5);
    }

	var date = text1 * 1;
	var month = text2 * 100;
	var year = text3 * 10000;

	return date + month + year;
}

function setDateFormat(dateStr,from) {
    var ddd = from.indexOf('ddd');
    var dd = from.indexOf('dd');    
    var mmm = from.indexOf('MMM');
    var mm = from.indexOf('MM');
    var yyyy = from.indexOf('yyyy');
    var yy = from.indexOf('yy');
    var mL = 0;

    if(mmm>=0){
    
        if(dateStr.indexOf('Jan')>=0){
            month = '01';
            mL=7;
        }else if(dateStr.indexOf('Feb')>=0){
            month = '02';
            mL=8;
        }else if(dateStr.indexOf('Mar')>=0){
            month = '03';
            mL=5;
        }else if(dateStr.indexOf('Apr')>=0){
            month = '04';
            mL=5;
        }else if(dateStr.indexOf('May')>=0){
            month = '05';
            mL=3;
        }else if(dateStr.indexOf('Jun')>=0){
            month = '06';
            mL=4;
        }else if(dateStr.indexOf('Jul')>=0){
            month = '07';
            mL=4;
        }else if(dateStr.indexOf('Aug')>=0){
            month = '08';
            mL=6;
        }else if(dateStr.indexOf('Sep')>=0){
            month = '09';
            mL=9;
        }else if(dateStr.indexOf('Oct')>=0){
            month = '10';
            mL=7;
        }else if(dateStr.indexOf('Nov')>=0){
            month = '11';
            mL=8;
        }else if(dateStr.indexOf('Dec')>=0){
            month = '12';
            mL=8;
        }
        
        

/**
        var month = dateStr.substring(mmm,mmm+3);
        if(month=='January'){
            month = '01';
        }else if(month=='February'){
            month = '02';
        }else if(month=='March'){
            month = '03';
        }else if(month=='April'){
            month = '04';
        }else if(month=='May'){
            month = '05';
        }else if(month=='June'){
            month = '06';
        }else if(month=='July'){
            month = '07';
        }else if(month=='August'){
            month = '08';
        }else if(month=='September'){
            month = '09';
        }else if(month=='October'){
            month = '10';
        }else if(month=='November'){
            month = '11';
        }else if(month=='December'){
            month = '12';
        }     
/**/  
    }else if(mm>=0){
        var month = dateStr.substring(mm,mm+2);
    } 
     
    mL=mL+1;
    if(dd>=0){                    
        var date = dateStr.substring(mL,mL+2);        
    }
 
    mL=mL+4;
    if(yyyy>=0){
        var year = dateStr.substring(mL,mL+4);
    }else if(yy>=0){
        var year = dateStr.substring(mL,mL+2);
    }
    
	return (date+'/'+month+'/'+year);
}

//////////////////////////////////////////////////////////////////
// Function : getRadioValue(obj)
//--------------------------------------------------
// Parameter :
// obj >> radionbutton object
//--------------------------------------------------
// Return : The Value of that radio button or null
//--------------------------------------------------
// Example : 
// getRadioValue(document.form1.result) = "7"
//////////////////////////////////////////////////////////////////
function getRadioValue(obj) {
	for (i = 0; i < obj.length; i++) {
		if (obj[i].checked) {
			return obj[i].value;
		}
	}
	return null;
}



//**********************************************************
// MY Private Function
//**********************************************************

//----------------------
// Window Level 
//----------------------
function initOrder() {
var objnum =document.forms[0].elements;
	for (var i=0;i<objnum.length;i++) {
		orderItem[i]=objnum[i].name;
	}
	for (var i=0;i<objnum.length;i++) {
		var obj = document.forms[0].elements[i];
		if (obj!=null) {
			obj.onkeypress = new Function("autoFocus(this);");
			if (i==0) obj.focus();
		}
	} // end for
	document.forms[0].elements[0].focus();
}

function autoFocus(text) {
var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;	
	if (keycode == 13) {
		for (var i=0;i<orderItem.length;i++) {
			if (orderItem[i].toUpperCase()==text.name.toUpperCase()) {
//				for (var j=i;j<orderItem.length;j++) {				
					var nextOrder = i+1;
					var obj = document.forms[0].elements[orderItem[nextOrder]];
					if (obj!=null && obj.focus && obj.type!='hidden')obj.focus();
					else document.forms[0].elements[orderItem[nextOrder+1]].focus();
					break;
			} // end if check name
		} // end for
	} // end if check Enter Code (#13)
}
/**
function openDialog(pagename,redirectpage){
	   var data = new Array();
		var props = "dialogHeight:500px;dialogWidth:606px;center:yes;help:no;scroll:yes;status:no;";
//		var w = window.open(lovname , data, props);
//window.open (lovname ,"mywindow","menubar=0,resizable=01,width=800,height=350"); 
		var w = window.showModalDialog(pagename , data, props);
		if(redirectpage!=""){
			document.location.replace(redirectpage);
		}
		return data;
}	
/**/
function popCalendar(strForm,strName) {	
	window.open("../utility/class/popup_calendar.php?strForm="+strForm+"&strName="+strName,"calendar","width=215,height=213,top=260,left=70,menubar=no,resizeable=no,toolbar=no,scrollbar=yes"); 
}

function openWindow(theURL,winName,features) { 
	window.open(theURL,winName,features);
}
 
 /**
function popupDialog(lovpage,obj,hid,props=''){
  	var retData = new Array(); 
  	if(props!=''){  	
	    var promt = props;
	}else
	    var promt = "dialogHeight:585px;dialogWidth:505px;center:yes;help:no;scroll:yes;status:no;";
	}
	var retValue = window.showModalDialog(lovpage, retData, promt);	
	if(retValue){
        return(retData);
	}
}
/**/
function popupDialog(lovpage,obj,hid){
  	var retData = new Array(); 
    var promt = "dialogHeight:585px;dialogWidth:505px;center:yes;help:no;scroll:yes;status:no;";
	var retValue = window.showModalDialog(lovpage, retData, promt);	
	if(retValue){
        return(retData);
	}
}
/**/
function openDialog(lovpage,obj,hid){
  	var retData = new Array();
  	var screenW = screen.width-100;
  	//var screenH = screen.Height-100;
  	var screenH = 700;
  	var screenX = (screen.width-screenW)/2;
  	var screenY = (screen.Height-screenH)/2;
  	
  	var screenW = screen.width;
    var screenH = screen.Height;
    window.resizeTo(screenW,screenH);    
    window.moveTo(0,0);

    var promt = "dialogHeight:" + screenH + "px;dialogWidth:" + screenW + "px;dialogLeft:" + screenX + ";dialogTop:" + screenY + ";center:yes;help:no;scroll:yes;status:no;";
	var retValue = window.showModalDialog(lovpage, retData, promt);	
	if(retValue){
        return(retData);
	}
}
/**/
function popupCalendar(lovpage){
  	var retData = new Array(); 
	var props = "dialogHeight:285px;dialogWidth:505px;center:yes;help:no;scroll:yes;status:no;";
	var retValue = window.showModalDialog(lovpage, retData, props);		
	if(retValue){
        return(retValue);
	}
}

//function popDialog(pagename,redirectpage){
function popDialog(lovpage,obj,hid){
    
  	var retData = new Array(); 
	var props = "dialogHeight:585px;dialogWidth:505px;center:yes;help:no;scroll:yes;status:no;";
	var retValue = window.showModalDialog(lovpage, retData, props);	
	if(retValue){
	    document.getElementById(hid).value = retData[0];
	    document.getElementById(obj).value = retData[1];
		//obj.value = retData[1];
	}
}

function popAppDialog(lovpage,obj,hid){
	var retData = new Array();	
	var props = "dialogHeight:500px;dialogWidth:500px;center:yes;help:no;scroll:yes;status:no;";
	var w = window.showModalDialog(lovpage+'.php' , retData, props);
	if(retData[0]){
		hid.value = retData[1];	
		if(obj.value!=''){obj.value = obj.value+','+retData[2];}
		else{obj.value = retData[2];}
	}
//	return retData;
}	

function popAppendDialog(lovpage,obj,hid){
	var retData = new Array();	
	var props = "dialogHeight:500px;dialogWidth:500px;center:yes;help:no;scroll:yes;status:no;";
	var w = window.showModalDialog(lovpage+'.php' , retData, props);
	if(retData[0]){
		hid.value = retData[1];
		if(obj.value!='')obj.value = obj.value+',';
		obj.value = obj.value+retData[2];
	}
//	return retData;
}	

function popConditionDialog(lovpage,obj,hid,condi){
	var retData = new Array();	
	var props = "dialogHeight:500px;dialogWidth:500px;center:yes;help:no;scroll:yes;status:no;";
	var w = window.showModalDialog(lovpage+'.php'+condi , retData, props);
	if(retData[0]){
		hid.value = retData[1];
		obj.value = retData[2];
	}
//	return retData;
}	

//----------------------
// Object Level 
//----------------------
function upperCase(obj){
	obj.value = obj.value.toUpperCase();
}

function lowerCase(obj){
	obj.value = obj.value.toLowerCase();
}

function clrObj(objName){
//	var  obj=document.getElementById(objName);
	objName.value = "";
}

function isEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}


//----------------------
// Function Level 
//----------------------

function getDateNow(){
	var now=new Date();

	day='0'+now.getDate();
	day=day.substr(day.length-2,2);
	month='0'+(now.getMonth()+1);
	month=month.substr(month.length-2,2);
	year=now.getYear();
	year > 2500 ? year=year : year=year+543;

	return day+'/'+month+'/'+year;
}

function Trim(TRIM_VALUE){
	if(TRIM_VALUE.length < 1)return"";
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE=="")return "";
	else return TRIM_VALUE;
}

function LTrim(VALUE){
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";	
	var iTemp = 0;
	
	if(v_length < 1)return"";	
	while(iTemp < v_length){
	  if(VALUE.charAt(iTemp) == w_space){}
	  else{
		strTemp = VALUE.substring(iTemp,v_length);
		break;
	  }
	  iTemp = iTemp + 1;
	} //End While
	return strTemp;
} //End Function

function RTrim(VALUE){
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	var iTemp = v_length -1;
	
	if(v_length < 0)return"";	
	while(iTemp > -1){
	  if(VALUE.charAt(iTemp) == w_space){}
	  else{
		strTemp = VALUE.substring(0,iTemp +1);
		break;
	 }
	  iTemp = iTemp-1;	
	} //End While
	return strTemp;
} //End Function


function checkCombo(obj,msg){
	if(obj.value==0){
		alert(msg);
		obj.focus();
		obj.select();
		return(true);
	}else{
		return(false);
	}
}

function checkItem(obj,msg){
	if(obj=='[object]'){
		if(obj.value==''){
			alert(msg);
			obj.focus();
			obj.select();
			return(true);
		}else{
			return(false);
		}	
	}else{
		if(obj){
			alert(msg);
			obj.focus();
			obj.select();
			return(true);
		}else{
			return(false);
		}			
	}
}

function checkItemDD(obj,msg){
	if((obj.value=="")||(obj.value<1)||(obj.value>31)){
		alert(msg);
		obj.focus();
		obj.select();
		return(true);
	}else{
		return(false);
	}
}
function checkItemMM(obj,msg){
	if((obj.value=="")||(obj.value<1)||(obj.value>12)){
		alert(msg);
		obj.focus();
		obj.select();
		return(true);
	}else{
		return(false);
	}
}

function checkItemEN(obj,msg){
var charENupper = /[A-Z]/
var charENlower = /[a-z]/
var charNumber = /[0-9]/
	if((!charENupper.test(obj.value))&&(!charENlower.test(obj.value))) {
		alert(msg);
		obj.focus();
		obj.select();
		return(true);
	}
}

function checkItemNumber(obj,msg){
var charNumber = /[0-9]/
	if(!charNumber.test(obj.value)){
		alert(msg);
		obj.focus();
		obj.select();
		return(true);
	}

}

function setPointerByID(tabID,className) { 
	var currTabElem = document.getElementById(tabID); 
	currTabElem.className=className;
}

function showBranch(branch) {
      var objBranch = document.getElementById(branch).style;  		
	  	if(objBranch.display=="block"){
			objBranch.display="none";
		}else{
			objBranch.display="block";
		}
}

function setPointer(obj,className) { 
	obj.className=className;
}


function showBranchX(branch) {
      var objBranch = document.getElementById(branch).style;		
	  	if(objBranch.visibility=="visible"){
			objBranch.visibility="hidden";
		}else{
			objBranch.visibility="visible";
		}
}

function showLOV(LOVID,L,T,W,H){
    if(LOVID!=''){    
    
        var LOV = document.getElementById(LOVID).style;
        if(LOV.visibility=='hidden'){             
            LOV.left=L+'px'; 
            LOV.top=T+'px';
            LOV.width=W+'px';
            LOV.height=H+'px';         
            LOV.visibility = 'visible';
        }else{
            LOV.visibility = 'hidden';
        }
    }
}

function validateTextbox(obj,msg){
    if(obj.value == ''){
        alert(msg);
        obj.focus();
        return(false);
    }else{
        return(true);
    }
}

function validateTextboxNoFocus(obj,msg){
    if(obj.value == ''){
        alert(msg);        
        return(false);
    }else{
        return(true);
    }
}

function validateHiddenField(obj,msg){
    if(obj.value == ''){
        alert(msg);        
        return(false);
    }else{
        return(true);
    }
}

function validateDropDownList(obj,msg){    
	if(obj.value==0){
		alert(msg);
		obj.focus();		
		return(false);
	}else if(obj.value==''){
		alert(msg);
		obj.focus();		
		return(false);
	}else{
		return(true);
	}
}

function validateDropDownListNoFocus(obj,msg){    
	if(obj.value==0){
		alert(msg);
		return(false);
	}else if(obj.value==''){
		alert(msg);
		return(false);
	}else{
		return(true);
	}
}

function isEMailAddr(elem) {
    var str = elem.value;
    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (!str.match(re)) {
        alert("Verify the e-mail address format.");
        //setTimeout("focusElement('" + elem.form.name + "', '" + elem.name + "')", 0);
        return(false);
    } else {
        return(true);
    }
}

//**************************************************************
// Site Function
//**************************************************************
function loadFrames(frame1,page1) {
	eval("parent."+frame1+".location='"+page1+"'");
}

function delRecord(directPage){
	if(confirm("Delete this record?")){
		var secur = prompt("Enter security password [For adminintrator only]",'Security password!');
		if(secur =='0909'){
			location.replace(directPage);
		}else if(secur!=null){
			alert('Security password incorrect!!!');
		}	
	}
}

function delRecordTH(directPage){
	if(confirm("ลบข้อมูลรายการนี้หรือไม่?")){	
		var secur = prompt("Enter security password [For adminintrator only]",'Security password!');
		if(secur =='0909'){
			location.replace(directPage);
		}else if(secur!=null){
			alert('Security password incorrect!!!');
		}			
	}	
}

function checkSubmit() {
	if (checkEachValue()) {
		document.search_form.submit();
	}
}

function retValue(value){
		if(value!=""){
			alert(window.opener.form1.txtreqname.value);
		}
}
	
function openReport(page){
	if(page!=''){
		window.open(page,"ReportWindow","height=700px,width=1020px,top=0,left=0,scrollbars=yes,menubar=no,resizeable=no,toolbar=no"); 
	}
}

function msgbox(_prompt){
    if (_prompt==""){_prompt = "Message Box Prompt";}
    alert(_prompt);
    return false;
}
function confirmbox(_prompt){       
    if(confirm(_prompt)==true){
        return true;
    }else{    
        return false;
    }
}

function chkNumber(){ //alias checkNumber(){
    checkNumber();
}
function checkNumber(){     
    if (((event.keyCode >= 48) && (event.keyCode <= 57))|| (event.keyCode == 13) ){
	    return true;
    }else{
        event.returnValue = false;
        window.alert ("Please fill numeric input !");
        return false;
    } 
    
}

function checkCurrency(){     
    if (((event.keyCode >= 48) && (event.keyCode <= 57))||(event.keyCode == 13)||(event.keyCode == 46)){
	    return true;
    }else{
        event.returnValue = false;
        window.alert ("Please fill currency type !");
        return false;
    } 
    
}
function changformat(obj) {
 numvalue=obj.value;
 if (numvalue != '')
 {
  document.getElementById(obj.id).value=FormatCurrency(numvalue);
 }
}

function FormatCurrency(num) 
{ 
 var sign, cents; 
 num = num.toString().replace(/\$|\,/g,''); 
 if(isNaN(num)) 
  num = "0"; 
  sign = (num == (num = Math.abs(num))); 
  num = Math.floor(num*100+0.50000000001); 
  cents = num%100; 
  num = Math.floor(num/100).toString(); 
 if(cents<10) 
  cents = "0" + cents; 
  for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) 
  num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3)); 
  return (((sign)?'':'-') + num + '.' + cents); 
}
function onFocus(obj){
    var val = obj.value.replace('.','');
    val = val.replace(',','');
    if(val<=0){
       obj.value='';
    }
}

function onUnFocus(obj){    
    if(obj.value==''){
       obj.value='0';
    }
}

function setfocus(obj){

obj.focus();
}

function checkSubmit() {
	if (submitcount == 0) {
		submitcount++;
		//return true;
		
	}else{
		//return false;
		
	}
	alert('xxx');
}
function OpenCenterWindow(popW,popH,sLink){
    var leftPos = (screen.availWidth-popW)/2, topPos = (screen.availHeight-popH)/2;
    window.open(sLink,'Page','toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=Yes,resizable=No,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);
}
function clearText(obj) {
    obj.value='';
}
function PopupCountryMGT(){
var retData = new Array();	
var props = 'dialogHeight:250px;dialogWidth:600px;center:yes;help:no;scroll:yes;status:no;';
window.showModalDialog('../RegistrationForm/CountryMGT.aspx',retData,props); 
}
function PopupNationalityMGT(){
var retData = new Array();	
var props = 'dialogHeight:250px;dialogWidth:600px;center:yes;help:no;scroll:yes;status:no;';
window.showModalDialog('../RegistrationForm/NationalityMGT.aspx',retData,props); 
}
function PopupGroupTelephoneMGT(){
var retData = new Array();	
var props = 'dialogHeight:250px;dialogWidth:600px;center:yes;help:no;scroll:yes;status:no;';
window.showModalDialog('../Telephonebook/GroupTelephoneMGT.aspx',retData,props); 
}
function PopupUploadFloorPlan(){
var retData = new Array();	
var props = 'dialogHeight:250px;dialogWidth:600px;center:yes;help:no;scroll:yes;status:no;';
window.showModalDialog('../Filing/UploadFloor.aspx',retData,props); 
}
function PopupSasinGroupMGT(){
var retData = new Array();	
var props = 'dialogHeight:250px;dialogWidth:600px;center:yes;help:no;scroll:yes;status:no;';
window.showModalDialog('../Sasin_Executive/SasinGroupMGT.aspx',retData,props); 
}
