function msfocus(fld_id) {
	var fld;
	try {
		// alert("Run (msfocus) ...");
		fld = document.getElementById(fld_id);
		// fld = eval("document." + frm + "." + fld);
		if (fld.value != null) {
			// fld.style.backgroundColor = "yellow";
			if (fld.value == "") {
				fld.focus();
			}
		}
		else {
			alert("Field not found ...(" + fld_id + ")");
		}
	}
	catch (errMsg) {
		// alert(errMsg.message);
	}
}

function msetfocus(frm, fld) {
	var fld;
	try {
		// alert("Run (msetfocus) ...");
		fld = eval("document." + frm + "." + fld);
		if (fld.value != null) {
			fld.style.backgroundColor = "yellow";
			if (fld.value == "") {
				fld.focus();
			}
		}
	}
	catch (errMsg) {
		// alert(errMsg.message);
	}
}

function getlastcard(frm, cardno) {
	var fld;
	fld = eval("document." + frm + ".cardno");
	fld.value = cardno;
	// value="<% echo ($cardno=="") ? $_SESSION["s_cardno"] : "" %>" 	
}

function hlight(fld) {
	fld.style.backgroundColor = "#FFFF6F";
}

function wlight(fld) {
	fld.style.backgroundColor = "window";
}

function scorevalid(fld) {
	var res;
	res = true;
	
	fld.style.backgroundColor = "window";
	
	if (fld.value != 0) {
		if ((fld.value < 50) || (fld.value > 999)) {
			emes = "Valid Score range is (Blank) or 50 - 999 ! ";
			if (emes != "") {
				alert(emes);
				fld.style.backgroundColor = "red";
				// fld.setfocus();
				res = false;
			}
		}
	}
	return res;
}

function gotmerchant(frm) {
	var fld, res;
	fld = eval( "document." + frm + ".MERCHANT_BOX");
	res = true;
	
	// alert(fld.value);
	
	if (fld.value == "9999") {
		emes = "Please select the merchant first ..... ";
		if (emes != "") {
			alert(emes);
			fld.focus();
			res = false;
		}
	}
	return res;
}

function cell_valid() {

	var fld = document.getElementById("cell");
	var vmode = document.getElementById("cellvmode");
	var cell = fld.value;
	var result = true;
	
	// alert("Validate Cell");
	
	if (cell != "") {
	
		if (vmode != "") {
			// alert(vmode.value);
			re = /[0-9]{7,15}$/
		 	if (!(re.test(cell))) {
				alert("Invalid Cell No ...");
				fld.focus();
				fld.style.backgroundColor = "yellow";
				result = false;
			}
		}
		
		else {
			re = /^[0]{1,10}$/
			if (re.test(cell)) {
				// alert("Valid 1");
			}
			else {
				re = /^[0]{1}[7-8]{1}[1-9]{1}[0-9]{7}$/;
			 	if (!(re.test(cell))) {
					alert("Invalid Cell No ...");
					fld.focus();
					fld.style.backgroundColor = "yellow";		 		
				 	result = false;
				}
			}
		}
	}

	return (result)
}

function email_valid() {
	
	var fld = document.getElementById("email");
	var email = fld.value;
	var result = true;

	// alert("Validate eMail");
	
	if (fld.value != "") {
		var emes = "";
		if ( fld.value.indexOf("@")== -1 )
			emes = "eMail Address: No '@' present in address";
		else {
			var adr = fld.value.split("@");
			if ( adr[0].length < 1 ) emes = "eMail Address: User address absent";
			else if (adr[1].indexOf(".")== -1) emes = "eMail Address: No dot ";
			else if (adr[1].length < 3) emes = "eMail Address: Domain incorrect";
		}
		if (emes != "") {
			alert(emes);
			fld.focus();
			fld.style.backgroundColor = "yellow";
			result = false;
		}
		else
			fld.style.backgroundColor = "window";
	}
		

	if ((fld.value != "") && (result == true)) {
		re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	 	if (!(re.test(email))) {
	 		alert("Invalid eMail Address ...");
			fld.focus();
			fld.style.backgroundColor = "yellow";		 		
	 		result = false;
		}
	}

	
	return (result);
}

function btncheck(whichbutton) {
	// alert(whichbutton);
	document.f.umode.value = whichbutton;
}