//function get element from event listener element
//ฟังชั่นสำหรับรับค่า Element ที่ทำให้เกิด event
function getObjectReference(){
	if(window.event && window.event.srcElement){ //<< event enable with in IE browser
				objectRef = window.event.srcElement;
		}else if(e && e.target){ //<< event enable with in natscape , firefox browser
				objectRef = e.target;
		}else{
				return(null); //<< if browsert unsupport 
		}
		return(objectRef);
}

//function get current form of object ;
//ฟังชั่นสำหรับรับค่า form ปัจจุบันของ object ที่กำหนด
function getCurrentForm(object){
	var currentForm;
	var tempObject = object ; 
	var unlimit = true;
	while( unlimit == true){
		tempObject = tempObject.parentNode
		if(tempObject.nodeName.toUpperCase() == "FORM"){
			currentForm = tempObject.name;
			unlimit = false;
		}else if(tempObject.nodeType == 9){ //<< node type  9: Document_Node  ...  that's mean this page don't have static form
			currentForm = false;
			unlimit = false;
		}//<< end if check tempObject
	}// << end while

	return(currentForm);
}

//function remove left space of string
//ฟังชั่นสำหรับตัดช่องว่างทางด้านซ้ายของข้อความ
function leftTrim(sString) {
		while (sString.substring(0,1) == ' '){
				sString = sString.substring(1, sString.length);
		}
		return sString;
}

//function remove right space of string
//ฟังชั่นสำหรับตัดช่องว่างทางด้านขวาของข้อความ
function rightTrim(sString) {
		while (sString.substring(sString.length-1, sString.length) == ' '){
				sString = sString.substring(0,sString.length-1);
		}
		return sString;
}

//function remove left and right space of string
//ฟังชั่นสำหรับตัดช่องว่างทางด้านซ้ายและขวาของข้อความ
function allTrim(sString) { 
		while (sString.substring(0,1) == ' '){
				sString = sString.substring(1, sString.length);
		}
		
		while (sString.substring(sString.length-1, sString.length) == ' '){
				sString = sString.substring(0,sString.length-1);
		}
		
		return sString;
}


// Virtual layer populate by div tag 
// การแสดงข้อมูลแบบ popup 
function createVirtualLayerControl(dataShow, target_width) {
		
		var object = getObjectReference();
		var mousePixelX = event.clientX;
		var mousePixelY = event.clientY;

		if( document.getElementById("virtualLayerControl") == null){
			document.body.innerHTML += "<div id='virtualLayerControl'></div>"; //<< create Div id equal 'virtualLayerControl'
		}
		virtualLayer = document.getElementById("virtualLayerControl"); //<< set virtualLayer is object('virtualLayerControl')
		virtualLayer.innerHTML = ""; 
		virtualLayer.innerHTML += ""+dataShow+""; //<< insert data into virtualLayer for show in web page
		virtualLayer.style.fontFamily = "MS Sans Serif"; //<< set  font-family style to fix font family  
		virtualLayer.style.fontSize = "9px"; //<< set  font-size style to fix size  
		virtualLayer.style.width = ""+ target_width +"px"; //<< set 'width' style to fix target width  
		virtualLayer.style.border="1px solid #444444"; //<< set 'border' style to create border line  
		virtualLayer.style.filter = "Alpha(opacity=0)"; //<< set  alpha style to tranparentcy 
		virtualLayer.style.pixelLeft = mousePixelX+3 //<< set 'pixelLeft' style to move target data from left+3 of mouseX (event.clientX)
		virtualLayer.style.pixelTop = mousePixelY + 3; //<< set 'pixelTop' style to move target data from top+3 of mouseX (event.clientX)
		virtualLayer.style.backgroundColor =  "#FFFFFF";
		virtualLayer.style.padding =  "7px";
		virtualLayer.style.position = "absolute"; 	
		virtualLayer.style.display='';
		nereidFade(virtualLayer, 80, 10, 3);

		object.onmouseout = removeVirtualLayerControl; //<< onmouseout call function removeVirtualLayerControl
}

// Virtual layer hidden 
// การซ่อนข้อมูล Virtual layer popup 
function removeVirtualLayerControl() {
		virtualLayer =  document.getElementById("virtualLayerControl"); 
		nereidFade(virtualLayer, 0, 10, 3);
}


//######################################################################################
// function Fade Alpha from siamdev.com
//การ Fade ข้อมูลให้แสดงแบบค่อย ๆ จางออกมาหรือ ค่อย ๆ จางหายไป 
//parameter description 
//destOp = Alpha value ..... 100 equal nomal ...... 0 equal tranparentcy
//rate = time millisec for setTimeout ....... 1000 equal 1 second
//delta = (Alpha value) per 1 time ... if this is 10 .. and rate  1000 .. that mean 1 second ... object + alpha value 10 until at destOp parameter
nereidFadeObjects = new Object();
nereidFadeTimers = new Object();
function nereidFade(object, destOp, rate, delta){
if (!document.all)
return;
    if (object != "[object]"){  //do this so I can take a string too
        setTimeout("nereidFade("+object+","+destOp+","+rate+","+delta+")",0);
        return;
    }
     // alert(object.sourceIndex);
    clearTimeout(nereidFadeTimers[object.sourceIndex]);
    
    diff = destOp-object.filters.alpha.opacity;
    direction = 1;
    if (object.filters.alpha.opacity > destOp){
        direction = -1;
    }
    delta=Math.min(direction*diff,delta);
    object.filters.alpha.opacity+=direction*delta;

    if (object.filters.alpha.opacity != destOp){
        nereidFadeObjects[object.sourceIndex]=object;
        nereidFadeTimers[object.sourceIndex]=setTimeout("nereidFade(nereidFadeObjects["+object.sourceIndex+"],"+destOp+","+rate+","+delta+")",rate);
    }
}

//function set highlight into rows of table
//ฟังชั่นสำหรับกำหนดค่าการ highlight สีของแถวในตาราง
function rowOverShowColor( defaultColor, changeColor){
		object = getObjectReference(); //<< call function for Listener Event from which object
		if( object != null && object.nodeName.toUpperCase() == "TABLE"){
				objectTr = object.getElementsByTagName("tr");			
				for(i=0 ; i < objectTr.length ; i++){
						objectTr[i].onmouseover = function(){
								var tempObjectTd = this.getElementsByTagName("td");
								for(i=0; i < tempObjectTd.length ;i++){
										tempObjectTd[i].bgColor = changeColor
								}				
						}
						
						objectTr[i].onmouseout = function(){
								var tempObjectTd = this.getElementsByTagName("td");
								for(i=0; i < tempObjectTd.length ;i++){
									tempObjectTd[i].bgColor = defaultColor;
								}				
						}
				}
		}else{
				return(false);
		}
}


//function set highlight into cell of table
//ฟังชั่นสำหรับกำหนดค่าการ highlight สีของเซลล์ในตาราง
function cellOverShowColor(defaultColor, hRowColor, hCellColor){
		object = getObjectReference();  //<< call function for Listener Event from which object
		//alert(object.sourceIndex);
		if( object.nodeName.toUpperCase() == "TABLE"){
				
				var objectTr = object.getElementsByTagName("tr");

				for(i=0 ; i < objectTr.length ; i++){
						objectTr[i].onmouseout = function(){
								var tempObjectTd = this.getElementsByTagName("td");
								for(i=0; i < tempObjectTd.length ;i++){
									tempObjectTd[i].bgColor = defaultColor
								}
						}
				}
				
				var objectTd = object.getElementsByTagName("td");
				for(i=0 ; i < objectTd.length ; i++){
						objectTd[i].onmouseover = function(){
								var tempObjectTd = this.parentNode.getElementsByTagName("td");
								for(i=0; i < tempObjectTd.length ;i++){
									tempObjectTd[i].bgColor = hRowColor
								}
								this.bgColor = hCellColor;
						}
				}
		}else{
				return(false);
		}
}

//function open new window <auto screen center> (if open same window ... must set windowName same opened window)
//ฟังชั่นสำหรับเปิดหน้าต่างใหม่ <อยู่กลางจออัตโนมัติ> ในกรณีที่ต้องการเปิดหน้าต่างเดียวกับที่เปิดไปแล้วให้ตั้งชื่อ windowName ให้เหมือนกัน
function newWindow(url , windowName, w, h, scroll){
	leftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	topPosition = (screen.height) ? (screen.height-h)/2 : 0;
	scroll = (scroll == "yes")?"yes":"no";
	windowSetting = "toolbar=no, scrollbars="+scroll+", resizable=no, status=no, location=no , width="+w+",height="+h+", left="+leftPosition+",top="+topPosition+"";
	myWindow = window.open(url, windowName,windowSetting );
}

function newWindowFullscreen(url , windowName){
	//leftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	//topPosition = (screen.height) ? (screen.height-h)/2 : 0;
	//scroll = (scroll == "yes")?"yes":"no";
	windowSetting = "channelmode=yes, fullscreen=yes, directories=no, menubar=no , titlebar=no, toolbar=no, scrollbars=no, resizable=no, status=no, location=no";
	myWindow = window.open(url, windowName,windowSetting );
}

//#################################################################################################
//#################################################################################################
// FORM CONTROL
//#################################################################################################

//function check event for input number (event such as onkeypress)
//ฟังชั่นสำหรับตรวจสอบ event เพื่อทำการกรอกข้อมูลให้เป็นตัวเลข
function chkNumber(){
	 if(event.keyCode < 48 || event.keyCode > 57 ){
			alert("Please Enter Number Only");
				//alert("กรุณาใส่ตัวเลขเท่านั้น");
			event.returnValue = false;
			return(false)
	}else{
		return(true);		
	}//<< end if check event.keyCode
}//<< end function

//function check event for input email character (event such as onkeypress)
//ฟังชั่นสำหรับตรวจสอบ character ที่พิมพ์ ซึ่งพิมได้เฉพาะตัวอักษรภาษาอังกฤษตัวเล็ก ตัวเลข และ  ตัวอักษรพิเศษสำหรับ email เท่านั้น
function chkEmail(){
	if ( event.keyCode != 46 && event.keyCode < 48 || (event.keyCode > 57 && event.keyCode < 64) || (event.keyCode>90 && event.keyCode<95) || (event.keyCode>95 && event.keyCode<97) || event.keyCode>122){
		//alert("กรุณาตรวจสอบรูปแบบการเขียนเมลล์ของคุณอีกครั้ง");
		alert("Please Enter Email Character Only");
		event.returnValue = false;
	}
}

//function check event for input id character (event such as onkeypress)
//ตรวจสอบ character ที่พิมพ์ ซึ่งพิมได้เฉพาะตัวอักษรภาษาอังกฤษตัวเล็กและตัวเลขเท่านั้น
function ChkID(){
	if (event.keyCode<13 || (event.keyCode>13 && event.keyCode<48) || (event.keyCode>57 && event.keyCode<97) || event.keyCode>122) {
		//alert("กรุณาใส่ตัวอักษรพิมพ์เล็กภาษาอังกฤษ หรือตัวเลขเท่านั้น");
		alert("Please Enter Lower English Character or Number Only");
		event.returnValue = false;
	}
}

//function check complete value is "email character" before onsubmit enable
//ตรวจสอบ character ที่พิมพ์ถ้าไม่มีการระบุไว้จะพิมพ์ไม่ได้  "ใช้ตรวจสอบ E-Mail"
function chk_char_email(t_email) {
	chkstr = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@-_."
	chkstr += '"';
	for (count = 0;count < t_email.length;count++) {
		chk_ok = 0
		for (count2 = 0;count2 < chkstr.length;count2++) {
			if (t_email.charAt(count) == chkstr.charAt(count2)) {
				chk_ok = 1;
				break;
			}
		}
		if (chk_ok == 0) {
			if (t_email.charCodeAt(count) != 13 && t_email.charCodeAt(count) != 10) {
				return false;
			}
		}
	}
	
	//if(t_email == "") return false;
	if(t_email.indexOf('@',0) < 1) { return false; }
	else if(t_email.indexOf('.',0) == -1 || t_email.lastIndexOf('.') == t_email.length-1 || t_email.lastIndexOf('@') != t_email.indexOf('@',0)) { return false; }
	else if(t_email.indexOf('.',0) == t_email.indexOf('@',0)+1) { return false; }
	else {
			return true;
	}

}

//function check complete value is "id character" before onsubmit enable
//ตรวจสอบ character ที่พิมพ์ถ้าไม่มีการระบุไว้จะพิมพ์ไม่ได้  "ใช้ตรวจสอบชื่อและid"
function chk_char_id(chkmsg) {
	chkstr = "0123456789abcdefghijklmnopqrstuvwxyz"
	chkstr += '"';
	for (count = 0;count < chkmsg.length;count++) {
		chk_ok = 0
		for (count2 = 0;count2 < chkstr.length;count2++) {
			if (chkmsg.charAt(count) == chkstr.charAt(count2)) {
				chk_ok = 1;
				break;
			}
		}
		if (chk_ok == 0) {
			if (chkmsg.charCodeAt(count) != 13 && chkmsg.charCodeAt(count) != 10) {
				return false;
			}
		}
	}
	return true;
}


// check rude word 
// ตรวจสอบคำที่ไมต้องการให้ใช้
function chk_rude(chkmsg){
	var rude = new Array(20);
	rude = new Array("fuck","gamemaster","gamesmaster","webmaster","wm","dq","admin","ini3","galaxy","asshole","bitch","shit","dick","kuy","kvy","yed", "gm", "GM", "hanbitsoft", "aeonsoft", "ntreev", "ntreevsoft");
	for (var i=0;i<rude.length;i++){
		chk_ok = 0;
		if (chkmsg.match(rude[i])){
			chk_ok = 1;
			//alert("in");
			return false;
			//break;
		}
	}
	//if (chk_ok == 0) {
	//	return false;
	//}
	return true;
}

function arrayAutoTabMaxLengthReached(validation) 
{
		var object = getObjectReference();
		var objectRef = object.id; //<< Reference to object by id 
		var currentForm = getCurrentForm(object);
		var objectRefCount = document.forms[currentForm].elements[objectRef].length; //<< Length of  Array
		//alert(validation);
		var tempObject = object ; 
		var tempValidation = validation.toUpperCase();

		if( (tempValidation == "NUMBER") || (tempValidation == "NUM") || (tempValidation == "N")){
			chkNumber(); //<< call to function check number  format
		}else if( (tempValidation == "E-MAIL") || (tempValidation == "EMAIL") ||  (tempValidation == "E")){
			chkEmail();  //<< call to function check email format
		}else if( (tempValidation == "CHARACTER") ||  (tempValidation == "CHAR") ||  (tempValidation == "C")){
			chkCharacter();  //<< call to function check character format
		}else if( (tempValidation == "ID") ){
			chkId();  //<< call to function check id format
		/*}else{*/

		}

		object.onkeyup = function(){ //<< this enable when onkeyup only
					tempObject = object; 
					if(object.maxLength == object.value.length && event.keyCode != 8){
							var unlimit = true;
							var numCheck = 1;
							while( unlimit == true ){
								tempObject = (tempObject.nextSibling != null)? tempObject.nextSibling : tempObject ; //<< get next node for reference 
								if(tempObject.nodeType == 3){  //<< nodeType... 1: Element_Node , 2: Attribute_Node, 3:Text_Node ....and  so on.
									//alert(tempObject.nodeValue);
									unlimit = true;
									if(numCheck > 10){
											nextTarget = object; //<< next target is original object  (same object)
											break;
									}
									numCheck++;
								}else if( (tempObject.nodeName.toUpperCase() == "INPUT")  && (tempObject.type == "text")){
									//alert("bbb");
									nextTarget = tempObject; //<< next target is next textbox  object  (new object)
									unlimit = false;
								}else{
									//alert("ccc");
									nextTarget = object; //<< next target is original object  (same object)
									unlimit = false;
								}//<< end if check tempObject
							} //<< end while
							nextTarget.focus();
					}//<< end if check maxLength
		}//<< end function enable when onkeyup



		object.onkeydown = function(){
					tempObject = object ; 
					if(object.value.length == 0 && event.keyCode == 8){
							var unlimit = true;
							var numCheck = 1;
							while( unlimit == true){
									tempObject = (tempObject.previousSibling != null)? tempObject.previousSibling : tempObject ;
									if(tempObject.nodeType == 3){  //<< nodeType... 1: Element_Node , 2: Attribute_Node, 3:Text_Node ....and  so on.
										unlimit = true;
										if(numCheck > 10){
											previousTarget = object; //<< previous target is original object  (same object)
											break;
										}
										numCheck++;
									}else if( (tempObject.nodeName.toUpperCase() == "INPUT") && (tempObject.type == "text")){
										previousTarget = tempObject; //<< next target is previous textbox  object  (new object)
										unlimit = false;
									}else{
										previousTarget = object; //<< previous target is original object  (same object)
										unlimit = false;
									}//<< end if check tempObject
							}//<< end while
							previousTarget.focus();
					}// end if check maxLength and press backspace
		}// end function enable when onkeydown




						var objectRefName = object.name + "_full";
						var tempValue = "";
						if(document.getElementById(objectRefName) == null){
							createElem = document.createElement("input");
							createElem.setAttribute("type", "hidden");
							createElem.setAttribute("name", objectRefName);
							createElem.setAttribute("id", objectRefName);
							document.forms[currentForm].appendChild(createElem);

						}
	
}//end function


function validation1Char(objectFullname, status){
		var tempName;
		if(document.getElementById(objectFullname) != null){
				var object = document.getElementById(objectFullname);
				var currentForm = getCurrentForm(object);
				//alert(object.name);
				tempName = object.name.split("_full");
				var object1Char = document.forms[currentForm].elements[tempName[0]];
				var tempValue = "";

				for (i=0; i < object1Char.length ; i++){
							tempValue += object1Char[i].value+"";
				}
				
				object.value = tempValue;
				//alert(object.value.length+" == "+object1Char.length);
				if((object.value.length == object1Char.length) ){
						return(true);
				}else if( (object.value.length == 0) && (status.toUpperCase() == "NOT REQUIRE") ){
						return(true);
				}else{
						return(false);
				}// end if check length
		}else{
				tempName = objectFullname.split("_full");
				//alert(tempName);
				//alert(document.getElementById(tempName[0]));
				var objectChk = document.getElementById(tempName[0]);
				if(objectChk != null){
						var currentForm = getCurrentForm(objectChk);
						var object1Char = document.forms[currentForm].elements[tempName[0]];
						var tempValue = "";
						
						createElem = document.createElement("input");
						createElem.setAttribute("type", "hidden");
						createElem.setAttribute("name", objectFullname);
						createElem.setAttribute("id", objectFullname);
						document.forms[currentForm].appendChild(createElem);


						for (i=0; i < object1Char.length ; i++){
									tempValue += object1Char[i].value+"";
						}

						var object = document.getElementById(objectFullname);
						object.value = tempValue;
						//alert(object.value.length+" == "+object1Char.length);
						if(object.value.length == object1Char.length){
								return(true);
						}else if(object.value.length == 0 && status.toUpperCase() == "NOT REQUIRE"){
								return(true);
						}else{
								return(false);
						}// end if check length
				}
				return(false);
		}//<< end if check object is null
}//<< end function

function validationFormENG(){
	var err="";
	var args = validationFormENG.arguments;
	var objectTarget, objectRef, currentForm, elementFocus=null;
	var validation, objectName, objectShowName, validationSpecifically, tempObjectRef, tempValidation, min, max, v1Char;
	var i , j;
	objectRef = getObjectReference();
	currentForm =  getCurrentForm(objectRef);


	for(i = 0;i < args.length; i++){ // this for loop .... check amount argument for validation
			validations = args[i].split(":");
			tempObjectRef =  validations[0].split("->");//<< split data into temp variable for specify object name and object show name
			objectName = allTrim( tempObjectRef[0]);//<< object name for assign object target
			objectShowName =  allTrim( tempObjectRef[1]);//<< show data of object  into alert
			validationSpecifically = validations.slice(1); //<< copy array since [1] to end ..... validation type for this object target
			objectTarget = document[currentForm][objectName];//<< dynamic object target;


			for(j = 0; j < validationSpecifically.length; j++){ // this for loop .... check amount validation Specifically for validation to object target
						tempValidation = allTrim( validationSpecifically[j].toUpperCase() );
						if(tempValidation == "REQ" || tempValidation == "R"){ //<< if validation object to  require
								if(objectTarget.selectedIndex == undefined){ //<< check object target isnot select (Combo box) 
											if (allTrim(objectTarget.value) == ""){
												err += "Please specify in "+objectShowName+".\n"
														if(elementFocus == null){
																elementFocus = objectName;
														}//<< end if check element focus
												break;
											}//<< end if check allTrim
								}else{//<< if object target is select (Combo box) 
											if (allTrim(objectTarget.value) == "" || allTrim(objectTarget.value) == "-"){
												err += "Please select "+objectShowName+".\n"
														if(elementFocus == null){
																elementFocus = objectName;
														}//<< end if check element focus
												break;
											}//<< end if check allTrim
								}
								
								
						}else if(tempValidation == "NUM" || tempValidation == "NUMBER"){ //<< if validation object to number
								if (isFinite(objectTarget.value) == false){ //<< check value is number or not?
									err += "Please specify number only into "+objectShowName+".\n"
									if(elementFocus == null){
											elementFocus = objectName;
									}//<< end if check element focus
									break;
								}//<< end if check isFinite
						}else if(tempValidation == "EMAIL" || tempValidation == "MAIL"){ //<< if validation object to mail format
								if(chk_char_email(objectTarget.value) == false && objectTarget.value.length != 0){
									err += "Please check value "+objectShowName+" again, because it isn't email format .\n";
									if(elementFocus == null){
											elementFocus = objectName;
									}//<< end if check element focus
									break;
								}//<< end if check chk_char_email
						}else if(tempValidation.indexOf("MIN") >= 0){ //<< if validation object to number and min value
								if(isFinite(objectTarget.value) == true){ //<< check value is number or not?
									min = tempValidation.split("->");
									if(objectTarget.value < parseInt(min[1])  && objectTarget.value.length != 0 ){
											err += "Please check value "+objectShowName+" again, because it less than "+min[1]+" .\n";
											if(elementFocus == null){
													elementFocus = objectName;
											}//<< end if check element focus
											break;
									}//<< end if check value less than minimum 
								}else{
									err += "Please specify number only into "+objectShowName+".\n";
									break;
								}//<< end if check isFinite
						}else if(tempValidation.indexOf("MAX") >= 0){ //<< if validation object to number and max value
								if(isFinite(objectTarget.value) == true){ //<< check value is number or not?
									max = tempValidation.split("->");
									if(objectTarget.value > parseInt(max[1])  && objectTarget.value.length != 0 ){
											err += "Please check value "+objectShowName+" again, because it more than "+max[1]+" .\n";
											if(elementFocus == null){
													elementFocus = objectName;
											}//<< end if check element focus
											break;
									}//<< end if check value more than maximum 
								}else{
									err += "Please specify number only into "+objectShowName+".\n";
									break;
								}//<< end if check isFinite
						}else if(tempValidation.indexOf("1CHAR") >= 0){ //<< if validation object to 1 char format
								v1Char =  tempValidation.split("->");
								if(allTrim(v1Char[1].toUpperCase()) == "R" || allTrim(v1Char[1].toUpperCase()) == "REQ" ){
									v1Char[1] = "require";
								}else{
									v1Char[1] = "not require";
								}//<< end if check 1char upper case == require

								if(validation1Char(objectName+"_full", v1Char[1]) == false){
									if(document.getElementById( objectName+"_full").value.length != 0 && document.getElementById( objectName+"_full").value.length != document[currentForm].elements[objectName].length){
											err += "You specify in "+objectShowName+" incomplete.\n";
									}else{
											err += "Please specify in "+objectShowName+".\n";
									}
									
									if(elementFocus == null){
										elementFocus = objectName;
									}//<< end if check element focus
									break;
								}//<< end if check validation1Char
						}// end if check validation type

			}//<< end for check validation length
	}//<< end for check args length

	if(err != ""){
				err = "You specify information incomplete.\n\n" + err
				alert(err);
				objectTarget = document[currentForm].elements[elementFocus];
				//alert(objectTarget.length);
				if( objectTarget.length != undefined){ //<< check .... Is object an array?
						objectTarget[0].focus();
				}else{
						objectTarget.focus();
				}
		}else{
				document[currentForm].submit(true);
	}//end if check err
}//<< end function


function validationFormTH(){
	var err="";
	var args = validationFormTH.arguments;
	var objectTarget, objectRef, currentForm, elementFocus=null;
	var validation, objectName, objectShowName, validationSpecifically, tempObjectRef, tempValidation, min, max, v1Char;
	var i , j;
	objectRef = getObjectReference();
	currentForm =  getCurrentForm(objectRef);
	
	for(i = 0;i < args.length; i++){ // this for loop .... check amount argument for validation
			validations = args[i].split(":");
			tempObjectRef =  validations[0].split("->");//<< split data into temp variable for specify object name and object show name
			objectName = allTrim( tempObjectRef[0]);//<< object name for assign object target
			objectShowName =  allTrim( tempObjectRef[1]);//<< show data of object  into alert
			validationSpecifically = validations.slice(1); //<< copy array since [1] to end ..... validation type for this object target
			objectTarget = document[currentForm][objectName];//<< dynamic object target;


			for(j = 0; j < validationSpecifically.length; j++){ // this for loop .... check amount validation Specifically for validation to object target
						tempValidation = allTrim( validationSpecifically[j].toUpperCase() );
						if(tempValidation == "REQ" || tempValidation == "R"){ //<< if validation object to  require
								if(objectTarget.selectedIndex == undefined){ //<< check object target isnot select (Combo box) 
											if (allTrim(objectTarget.value) == ""){
												err += "กรุณากรอก"+objectShowName+".\n"
														if(elementFocus == null){
																elementFocus = objectName;
														}//<< end if check element focus
												break;
											}//<< end if check allTrim
								}else{//<< if object target is select (Combo box) 
											if (allTrim(objectTarget.value) == "" || allTrim(objectTarget.value) == "-"){
												err += "กรุณาเลือก"+objectShowName+".\n"
														if(elementFocus == null){
																elementFocus = objectName;
														}//<< end if check element focus
												break;
											}//<< end if check allTrim
								}
								
								
						}else if(tempValidation == "NUM" || tempValidation == "NUMBER"){ //<< if validation object to number
								if (isFinite(objectTarget.value) == false){ //<< check value is number or not?
									err += "กรุณากรอก"+objectShowName+"เป็นตัวเลขเท่านั้น.\n"
									if(elementFocus == null){
											elementFocus = objectName;
									}//<< end if check element focus
									break;
								}//<< end if check isFinite
						}else if(tempValidation == "EMAIL" || tempValidation == "MAIL"){ //<< if validation object to mail format
								if(chk_char_email(objectTarget.value) == false && objectTarget.value.length != 0){
									err += "กรุณาตรวจสอบ"+objectShowName+"อีกครั้ง, เนื่องจากไม่อยู่ในรูปแบบของ E-mail .\n";
									if(elementFocus == null){
											elementFocus = objectName;
									}//<< end if check element focus
									break;
								}//<< end if check chk_char_email
						}else if(tempValidation.indexOf("MIN") >= 0){ //<< if validation object to number and min value
								if(isFinite(objectTarget.value) == true){ //<< check value is number or not?
									min = tempValidation.split("->");
									if(objectTarget.value < parseInt(min[1]) ){
											err += "กรุณาตรวจสอบ"+objectShowName+"อีกครั้ง, เนื่องจากค่าที่ระบุน้อยกว่า  "+min[1]+" .\n";
											if(elementFocus == null){
													elementFocus = objectName;
											}//<< end if check element focus
											break;
									}//<< end if check value less than minimum 
								}else{
									err += "กรุณากรอก"+objectShowName+"เป็นตัวเลขเท่านั้น.\n";
									break;
								}//<< end if check isFinite
						}else if(tempValidation.indexOf("MAX") >= 0){ //<< if validation object to number and max value
								if(isFinite(objectTarget.value) == true){ //<< check value is number or not?
									max = tempValidation.split("->");
									if(objectTarget.value > parseInt(max[1]) ){
											err += "กรุณาตรวจสอบ"+objectShowName+"อีกครั้ง, เนื่องจากค่าที่ระบุมากกว่า  "+max[1]+" .\n";
											if(elementFocus == null){
													elementFocus = objectName;
											}//<< end if check element focus
											break;
									}//<< end if check value more than maximum 
								}else{
									err += "กรุณากรอก"+objectShowName+"เป็นตัวเลขเท่านั้น.\n";
									break;
								}//<< end if check isFinite
						}else if(tempValidation.indexOf("1CHAR") >= 0){ //<< if validation object to 1 char format
								v1Char =  tempValidation.split("->");
								if(allTrim(v1Char[1].toUpperCase()) == "R" || allTrim(v1Char[1].toUpperCase()) == "REQ" ){
									v1Char[1] = "require";
								}else{
									v1Char[1] = "not require";
								}//<< end if check 1char upper case == require

								if(validation1Char(objectName+"_full", v1Char[1]) == false){
									if(document.getElementById( objectName+"_full").value.length != 0 && document.getElementById( objectName+"_full").value.length != document[currentForm].elements[objectName].length){
											err += "กรุณากรอก"+objectShowName+"ให้สมบูรณ์.\n";
									}else{
											err += "กรุณากรอก"+objectShowName+".\n";
									}
									
									if(elementFocus == null){
										elementFocus = objectName;
									}//<< end if check element focus
									break;
								}//<< end if check validation1Char
						}// end if check validation type

			}//<< end for check validation length
	}//<< end for check args length

	if(err != ""){
				err = "ข้อมูลไม่ครบถ้วนกรุณาตรวจสอบอีกครั้ง.\n\n" + err
				alert(err);
				objectTarget = document[currentForm].elements[elementFocus];
				//alert(objectTarget.length);
				if( objectTarget.length != undefined){ //<< check .... Is object an array?
						objectTarget[0].focus();
				}else{
						objectTarget.focus();
				}
		}else{
				document[currentForm].submit(true);
	}//end if check err
}//<< end function

//#################################################################################################
//#################################################################################################


//function reservation hotel (now, don't perfect function)
//ฟังชั่นสำหรับการจองโรงแรมเท่านั้น (ยังทำไม่ค่อยดีเท่าไร)
function checkSelectDate(){
	var myDate = new Date();
	var myYear = myDate.getYear();
	var myMonth = myDate.getMonth()+1;
	var today = "";
	today = today+myYear+"";
	today = today+myMonth+"";
	today = today+myDate.getDate()+"";
	//alert(today);
	var numDate1 =  document.forms[0].cboYear1.value+""+ document.forms[0].cboMonth1.value+""+ document.forms[0].cboDay1.value;

	var numDate2 =  document.forms[0].cboYear2.value+""+ document.forms[0].cboMonth2.value+""+ document.forms[0].cboDay2.value;
	y1 = parseInt(document.forms[0].cboYear1.value);
	y2 = parseInt(document.forms[0].cboYear2.value);
	//m1= document.forms[0].cboMonth1.value;
	//m2= document.forms[0].cboMonth2.value;
	m1= parseInt(document.forms[0].cboMonth1.value);
	m2= parseInt(document.forms[0].cboMonth2.value);
	numDate1 = parseInt(numDate1);
	numDate2 = parseInt(numDate2);

	if((numDate1 < today) && (m1 <= myMonth) && ((y1 <= myYear) ) ){
		alert("You selected date error please check 'Arrival Date'");	
	}else if((numDate2 > numDate1) || (m2 > m1) || (y2 > y1)){
		document.forms[0].submit(true);
	}else{
		alert("You selected date error please check it , then try again");		
	}
}

/*
//function list Extra Bed for Room Book .
//ฟังชั่นสำหรับการจองโรงแรมเท่านั้น 
function listExtraBed(target,shortform,oldindex) {
	monthfull = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
	monthshort = new Array("JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC");
	target.options.length = 13;
	target.options[0].text = "Month";
	target.options[0].value = "0";
	if(!shortform) {
		for(i=1;i<=12;i++) {
			target.options[i].text = monthfull[i-1];
			target.options[i].value = i;
		}	
	}else{
		for(i=1;i<=12;i++) {
			target.options[i].text = monthshort[i-1];
			target.options[i].value = i;
		}	
	}
	if(oldindex != null) {
		target.options.selectedIndex = oldindex;
	}
}*/

function validateListBooking(elmtStyleListTarget, valueFromElmt){
	var charNumber=0;
	var partValue;
	var err = "";
	elmtSelectFrom = document.getElementById(elmtStyleListTarget);
	//alert(elmtSelectFrom.options[elmtSelectFrom.selectedIndex].text);
	optionSelected = elmtSelectFrom.options[elmtSelectFrom.selectedIndex]
	if(optionSelected.text.indexOf("yyyy-mm-dd") >= 0){
		if(valueFromElmt.indexOf("-") >= 0){
				partValue = valueFromElmt.split("-")
				if(partValue.length != 3){
					err += "you specify value not match Format.\n\nEx. Format is yyyy-mm-dd : 2006-01-01.\n\n";
				} else{
					if( (partValue[0].length != 4)  ||  isNaN(partValue[0])  ){
							err += "Format  yyyy  -  incorrect.\n";
					}// end if check is Nan and length

					if( partValue[1].length != 2  ||  isNaN(partValue[1]) || parseInt(partValue[1]) > 12){
							err += "Format  mm  -  incorrect.\n";
					}// end if check is Nan and length

					if( partValue[2].length != 2  ||  isNaN(partValue[2]) || parseInt(partValue[2]) > 31){
							err += "Format  dd  -  incorrect.\n";
					}// end if check is Nan and length
					alert(err);
				}// end if check length
		}else{
			err += "you specify value not match Format.\n\nEx. Format is yyyy-mm-dd : 2006-01-01.\n\n";
		}// end if check indexof "-"
	}else if(optionSelected.text.indexOf("yyyy-mm") >= 0){
		if(valueFromElmt.indexOf("-") >= 0){
				partValue = valueFromElmt.split("-")
				if(partValue.length != 2){
					err += "you specify value not match Format.\n\nEx. Format is yyyy-mm : 2006-01.\n\n";
				}else{
					if( (partValue[0].length != 4)  ||  isNaN(partValue[0])  ){
							err += "Format  yyyy  -  incorrect.\n";
					}// end if check is Nan and length

					if( partValue[1].length != 2  ||  isNaN(partValue[1]) || parseInt(partValue[1]) > 12){
							err += "Format  mm  -  incorrect.\n";
					}// end if check is Nan and length	
				}// end if check ilength
		}else{
			err += "you specify value not match Format.\n\nEx. Format is yyyy-mm : 2006-01.\n\n";	
		}//end if check indexof "-"
	}//end if check text.indexOf (format)

	if(err != ""){
		alert(err);
		return(false);
	}else{
		return(true);
	}
}// end function


//function list Select(combobox) object.
//ฟังชั่นสำหรับจัดลำดับค่าที่แสดงค่าใน select(combobox)
function listSelectObject(target, setValue, setDefaultText, setDefaultValue, oldindex){
	if(allTrim(setValue) != ""){
			setValue = parseInt(setValue);
			target.options.length = setValue + 1;
			for(i=0 ; i <= setValue ; i++) {
				target.options[i].text = i;
				target.options[i].value = i;
			}// end for
	}else{
			target.options.length = 1;
			target.options[0].text = setDefaultText;
			target.options[0].value = setDefaultValue;
	}//end if check setValue

	if(oldindex != null) {
		target.options.selectedIndex = oldindex;
	}// end if check old index
}// end function