	function getCookie(c_name) {
		if (document.cookie.length>0) {
			c_start=document.cookie.indexOf(c_name + "=");
			if (c_start!=-1) { 
				c_start=c_start + c_name.length+1;
				c_end=document.cookie.indexOf(";",c_start);
				if (c_end==-1) c_end=document.cookie.length;
				var c_val = unescape(document.cookie.substring(c_start,c_end));
				return c_val;
			} 
		}
		return "";
	}
	
	function isMalay() {
		if (getCookie('lang') == 'bm') return true;
		return false;
	}
	
	function isEnglish() {
		if (getCookie('lang') == 'en') return true;
		return false;
	}

	var form_submitted = false;

	function submit_form(errmsg) {
		if ( form_submitted ) {
			alert (errmsg);
			return false;
		} else {
			form_submitted = true;
			return true;
		}
	}

	function checkchars_currency(obj, str_usermessage, errorplaceid) {
		var validChars = "0123456789.";
		var isCurrency=true;
		var val = obj.value;
		var Char;
		var str = '';
		for (i = 0; i < val.length && isCurrency == true; i++) {
			Char = val.charAt(i);
			if (validChars.indexOf(Char) == -1) {
				isCurrency = false;
			} else str += Char;
		}
		if (isCurrency == false) {
			obj.focus();
			obj.value = str;
			writeErrorMsg(str_usermessage, errorplaceid);
		} else if (val.length == 0) {
			writeErrorMsg('', errorplaceid);
		} else {
			writeErrorMsg('', errorplaceid);
		}
	}

	function check_decimalplace(obj, alloweddecimalplaces, str_usermessage, errorplaceid) {
		var val = obj.value;
		var Char;
		var str = '';
		var decimalplace = 0;
		var isDecimalValid = true;
		for (i = 0; i < val.length && isDecimalValid == true; i++) {
			Char = val.charAt(i);
			if (decimalplace > 0) decimalplace++;
			if (decimalplace > alloweddecimalplaces+1) {
				isDecimalValid = false;
			} else str += Char;
			if (Char == '.') {
				decimalplace++;
			}
		}
		if (isDecimalValid == false) {
			obj.focus();
			obj.value = str;
			writeErrorMsg(str_usermessage, errorplaceid);
		} else {
			writeErrorMsg('', errorplaceid);
		}
	}

	function checkchars_name (obj, str_usermessage, errorplaceid) {
		var validChars = "abcdefghijklmnopqrstuvwxyz";
		validChars += validChars.toUpperCase() + "' @/.-()";
		var isAlphabet = true;
		var val = obj.value;
		var currentchar;
		var str = '';
		for (i = 0; i < val.length && isAlphabet == true; i++) {
			currentchar = val.charAt(i);
			if (validChars.indexOf(currentchar) == -1) {
				isAlphabet = false;
			} else str += currentchar;
		}
		if (isAlphabet == false) {
			obj.focus();
			obj.value = str;
//			alert(str_usermessage);
			writeErrorMsg(str_usermessage, errorplaceid);
		} else if (val.length == 0) {
			writeErrorMsg('', errorplaceid);
		} else {
			writeErrorMsg('', errorplaceid);
		}
	}

	function setElementValue(elementId, value) {
		document.getElementById(elementId).value = value;
	}

	function jumpNext (theEvent, upTargetId, downTargetId, leftTargetId, rightTargetId) {
		var keynum;
		var targetId = false;
		if(window.event) {// IE
			keynum = theEvent.keyCode;
		} else if(theEvent.which) {// Netscape/Firefox/Opera
			keynum = theEvent.which;
		}
		//alert (keynum)
		if (keynum == 40) {
			targetId = upTargetId;
		} else if (keynum == 40) {
			targetId = upTargetId;
		} else if (keynum == 40) {
			targetId = upTargetId;
		} else if (keynum == 40) {
			targetId = upTargetId;
		}
		if (targetId) document.getElementById(targetId).focus();
	}

	function jumpByKeyCode (theEvent, theKeyCode, targetId) {
		var keynum;
		if(window.event) {// IE
			keynum = theEvent.keyCode;
		} else if(theEvent.which) {// Netscape/Firefox/Opera
			keynum = theEvent.which;
		}
		if (keynum == theKeyCode)  document.getElementById(targetId).focus();
	}

	function checkAll(controlchkboxobj, startno, endno, name) {
		var checkTheBox = false;
		if (controlchkboxobj.checked == true) checkTheBox = true;

		for (var i=startno; i<endno; i++) {
			try {
				document.getElementById(name+i).checked = checkTheBox;
			} catch (e) {
			}
		}
	}

	function sumValues (targetobjid, start, end, name) {
		var total = 0;
		var bUseInnerHtml = false;
		if (name.substring(0,4)=='col_') bUseInnerHtml = true;

		for (var i=start; i<end; i++) {
			if (!bUseInnerHtml) {
				var fieldval = document.getElementById(name+i).value;
			} else {
				var fieldval = document.getElementById(name+i).innerHTML;
			}
			//alert (name+i)
			//alert (fieldval);
			if (!isNaN(fieldval)) {
				total = (fieldval * 1) + (total * 1);
			}
		}
		document.getElementById(targetobjid).value = (total * 1);
	}


	function sumTwoFieldVals(fieldId1, fieldId2, targetFieldId){
		var fieldval1 = document.getElementById(fieldId1).value;
		var fieldval2 = document.getElementById(fieldId2).value;
		var total = 0;
		if (!isNaN(fieldval1)) total = (fieldval1 * 1) + (total * 1);
		if (!isNaN(fieldval2)) total = (fieldval2 * 1) + (total * 1);
		document.getElementById(targetFieldId).value = total;
	}

	function wopen(url, name, w, h) {
		w += 12;
		h += 25;
	 	var win = window.open(url, name, 'width=' + w + ', height=' + h + ', ' + 'location=no, menubar=no, ' + 'status=no, toolbar=no, scrollbars=yes, resizable=yes');
	 	win.resizeTo(w, h);
	 	win.focus();
	}

	//display / hide page based on id
	function getPage(pageNo, totalPage) {
		var i;
		var disPage = document.getElementById(pageName+pageNo);
		for(i = 1; i <= totalPage; i++ ) {
			var displayMode = "none";
			var tes = "&nbsp;"+i+"&nbsp;";
			if(i == pageNo) {
				displayMode = "block";
				tes = "<b>[page "+pageNo+" ]</b>";
				document.getElementById("ref"+i).style.color = 'red';
				document.getElementById("ref"+i).innerHTML = tes;
			} else {
				document.getElementById("ref"+i).style.color = 'blue';
			}
			document.getElementById("ref"+i).innerHTML = tes;
			document.getElementById(pageName+i).style.display = displayMode;
		}
	}

// calculate the ASCII code of the given character
	function CalcKeyCode(aChar) {
		var character = aChar.substring(0,1);
		var code = aChar.charCodeAt(0);
		return code;
	}

//  
//	function checkNumber(val) {
//		var strPass = val.value;
//		var strLength = strPass.length;
//		var lchar = val.value.charAt((strLength) - 1);
//		var cCode = CalcKeyCode(lchar);
//
//		/* Check if the keyed in character is a number
//		 do you want alphabetic UPPERCASE only ?
//		 or lower case only just check their respective
//		 codes and replace the 48 and 57 */
//
//		if (cCode == 46 || cCode < 48 || cCode > 57 ) {
//			var myNumber = val.value.substring(0, (strLength) - 1);
//			val.value = myNumber;
//		}
//		return false;
//	}

	function checkNumber(obj) {
		var strPass = obj.value;
		var strLength = strPass.length;
		var lchar = obj.value.charAt((strLength) - 1);
		var cCode = CalcKeyCode(lchar);
		if (cCode == 46 || cCode < 48 || cCode > 57 ) {
			var myNumber = obj.value.substring(0, (strLength) - 1);
			obj.value = myNumber;
		}
		return false;
	}

	function getObj (id) {
		try {
			if (document.getElementById(id)) return document.getElementById(id);
		} catch (e) {
			alert ('Could not get object by id "'+id+'"');
		}
	}

	function disable (id) {
		getObj(id).disabled = true;
	}

	function enable (id) {
		getObj(id).disabled = false;
	}
	
	function isDisplayed (id) {
		if (getObj(id).style.display == 'block' || getObj(id).style.display == 'inline' || getObj(id).style.display == '') return true;
		else return false;
	} 
	
	function isHidden(id) {
		if (!isDisplayed(id)) return true;
		else return false;
	}
	
	function hide (id) {
		getObj(id).style.display = 'none';
	}
	
	function displayBlock(id) {
		getObj(id).style.display = 'block';
	}
	
	function displayInline(id) {
		getObj(id).style.display = 'inline';
	}
	
	function docheck(id) {
		getObj(id).checked = true;
	}
	
	function doEncodeURL(plaintext) {
		// The Javascript escape and unescape functions do not correspond
		// with what browsers actually do...
		var SAFECHARS = "0123456789" +	// Numeric
			"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
			"abcdefghijklmnopqrstuvwxyz" +
			"-_.!~*'()";					// RFC2396 Mark characters
		var HEX = "0123456789ABCDEF";
		
		//var plaintext = document.URLForm.F1.value;
		var encoded = "";
		for (var i = 0; i < plaintext.length; i++ ) {
			var ch = plaintext.charAt(i);
			if (ch == " ") {
				encoded += "+";				// x-www-urlencoded, rather than %20
			} else if (SAFECHARS.indexOf(ch) != -1) {
				encoded += ch;
			} else {
				var charCode = ch.charCodeAt(0);
				if (charCode > 255) {
					alert( "Unicode Character '" 
					        + ch 
					        + "' cannot be encoded using standard URL encoding.\n" +
					          "(URL encoding only supports 8-bit characters.)\n" +
							  "A space (+) will be substituted." );
					encoded += "+";
				} else {
					encoded += "%";
					encoded += HEX.charAt((charCode >> 4) & 0xF);
					encoded += HEX.charAt(charCode & 0xF);
				}
			}
		} // for
		
		//document.URLForm.F2.value = encoded;
		//return false;
		return encoded;
	}
	
	function doDecodeURL(encoded) {
		// Replace + with ' '
		// Replace %xx with equivalent character
		// Put [ERROR] in output if %xx is invalid.
		var HEXCHARS = "0123456789ABCDEFabcdef"; 
		var encoded = document.URLForm.F2.value;
		var plaintext = "";
		var i = 0;
		while (i < encoded.length) {
			var ch = encoded.charAt(i);
			if (ch == "+") {
				plaintext += " ";
				i++;
			} else if (ch == "%") {
				if (i < (encoded.length-2) 
				&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
				&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
					plaintext += unescape( encoded.substr(i,3) );
					i += 3;
				} else {
					alert( 'Bad escape combination near ...' + encoded.substr(i) );
					plaintext += "%[ERROR]";
					i++;
				}
			} else {
				plaintext += ch;
				i++;
			}
		} // while
//		document.URLForm.F1.value = plaintext;
//		return false;
		return plaintext;
	}
	
	function getNav(pageNo, totalPage, pageName, navfnName) {
		var i;
		var disPage = document.getElementById(pageName+pageNo);
		var refid = 'ref'+pageName;
		for(i = 1; i <= totalPage; i++ ) {
			var displayMode = "none";
			var tes = "&nbsp;"+i+"&nbsp;";
			if(i == pageNo) {
				displayMode = "block";
				tes = "<b>[ "+i+" ]</b>";
				document.getElementById(refid+i).className = 'currentpage';
			} else {
				tes = "[ "+i+" ]";
				document.getElementById(refid+i).className = 'otherpage';
				if (navfnName == 'undefined') navfnName = 'getNav';
				document.getElementById(refid+i).href = "javascript:"+navfnName+"("+i+", "+totalPage+", '"+pageName+"', '"+navfnName +"')";
			}
			document.getElementById(refid+i).innerHTML = tes;
			document.getElementById(pageName+i).style.display = displayMode;
		}
	}
//	function limitText(limitField, limitCount, limitNum) {
//    	if (limitField.value.length > limitNum) {
//    		limitField.value = limitField.value.substring(0, limitNum);
//    	} else {
//    		limitCount.value = limitNum - limitField.value.length;
//    	}
//    }
