/** Revision History.
 */
function chkMaxLength(objName, stringLength, labelName) {
	if(objName.value.length > stringLength) {
		alert("ความยาวภายใน \"" + labelName + "\" จะต้องไม่เกิน "+ stringLength +" ตัวอักษร.");
		vartemp = objName.value.substring(0, stringLength);
		objName.value = vartemp;
  	}
}
 
function chkLength(objSend, objReceive, stringLength) {
	if(objSend.value.length == stringLength) {  
		objReceive.focus();
	}
}
 
function chkNum(objName, labelName) {
	var digits = "0123456789.," ;
	var vartemp ;
	for (var i=0; i<objName.value.length; i++) { 
 		vartemp = objName.value.substring(i, i+1);
		if (digits.indexOf(vartemp) == -1) {
 			alert("ประเภทของ \"" + labelName + "\" ต้องเป็น ตัวเลข.");
 			objName.value = objName.value.substring(0, (objName.value.length-1));		
			objName.select();
		}
	}
}

function checkInput(objName, objDesc, objfrm, datasuccess) {
	check = 1;
	errorMsg = "";
	objNamelength = objName.length;
	for(var i=0; i<objNamelength; i++) {
		index1 = objName.indexOf("|", 0);
		temp1 = objName.substring(0, index1);
		objName = objName.substring(index1+1, objName.length);	
		index2 = objDesc.indexOf("|", 0);
		temp2 = objDesc.substring(0, index2);
		objDesc = objDesc.substring(index2+1, objDesc.length);
		if(objfrm.elements(temp1).value == "") {
			errorMsg = errorMsg+"- "+temp2+"\n";
			check = 0;
		}			
		if(objName.length == 0) {
			i = objNamelength;
		}
	}
	if(check == 1) {
		datasuccess.value = "1";
			//ask = confirm("ต้องการทำรายการต่อไป.");
		//if(ask == 1) {
			//objfrm.method = "post";
			//<!--objfrm.submit();-->
		//}
		
	} else {
		alert("กรุณากรอกข้อมูลต่อไปนี้. \n"+errorMsg);
		datasuccess.value = "0";
	}
}

function checkAll(objbox) {
	chkLength = objbox.length;
	chkStatus = objbox[0].checked;
	for(i=1; i<chkLength; i++) {
		objbox[i].checked = chkStatus;
	}
}

function replaceAll(stringItem, stringFrom, stringTo) {
	try {
		while (stringItem.indexOf(stringFrom) >= 0) {
			stringItem = stringItem.replace(stringFrom, stringTo);
		}
	} catch (e) {}
	return stringItem;
}
 
tempMoney="";
function formatMoney(mItem, money, format) {
	if(tempMoney != money) {
		temp1 = replaceAll(money, ",", "");
		temp2 = "";
		temp3 = "";
		if(temp1.indexOf(".") >= 0) {
			temp3 = temp1.substring(temp1.indexOf(".")+1, temp1.length);
			temp3 = replaceAll(temp3, ".", "");
			try {
				temp3 = temp3.substring(0, 2);
			} catch(e) {}
			temp3 = "."+temp3;
			temp1 = temp1.substr(0,temp1.indexOf("."));
			temp1 = replaceAll(temp1, ",", "");
		}
		if(temp1.length > 3) {
			for(i=0; i<=temp1.length; i++) {
				if(temp1.length > 3) {
					temp2 = temp1.substr(temp1.length-3, temp1.length);
					temp1 = temp1.substr(0, temp1.length-3);
					temp3 = format+temp2+temp3;
				}
			}
		} 

		temp3 = temp1+temp3;
		tempMoney = temp3;
		mItem.value = temp3;
	}
}

function copyText(objOne, objTwo) {
	objTwo.value = objOne.value;
}

function funcShowhide(n1, n2) {
	if(n1.style.display == "none") {
		n1.style.display = "";
		n2.style.display = "none";
	} else {
		n1.style.display = "none";
		n2.style.display = "";
	}
}

function approveWorkflow(lableLink) {
	frm.action = lableLink;
	frm.method = "post";

	ask = confirm("ลาก่อน.");
	if(ask == 1) {
		frm.submit();
	}
}


