/*	=======================================================================	*/
/// <remarks>
/// Version:
///		- number:	5.3.5
///		- build:	20051102
///		- status:	live
/// </remarks>
/*	=======================================================================	*/
/// <remarks>
/// Global Variables
/// </remarks>
	try {
		var nm_frm = new ClassNM_Form(nm_debug);
		var nm_val = new ClassNM_Valid(nm_debug);
		var nm_grp = new ClassNM_Group(nm_debug, nm_pge);	// nm_pge defined in 'nm_ver5.js'
	} catch(e) {
		alert("loading error(nm_form): "+e.description);	
	}
	
/*	=======================================================================	*/
/// <remarks>
/// Class: ClassNM_Form
/// The ClassNM_Form object class has the following purpose/function:
///	- supplies client-side properties and methods for 'form' objects
/// </remarks>
/*	-----------------------------------------------------------------------	*/
/// <summary>
/// The ClassNM_Form object class is constructed as follows:
///		var thisobj = new ClassNM_Form(dbg);
/// - where:
///		- dbg:	debugging switch
/// </summary>
function ClassNM_Form(dbg) {
	/*	-------------------------------------------	*/
	/// <remarks>Properties: Public</remarks>
	/*	-------------------------------------------	*/
	this.parameter = "";
	/*	-------------------------------------------	*/
	/// <remarks>Properties: Private</remarks>
	/*	-------------------------------------------	*/
	var _self = this;	// self allows for a method/property to be called internally
	var _debug = (dbg)? dbg : false;
	var _id = "ClassNM_Form";
	var _frm;
	/*	-------------------------------------------	*/
	/// <remarks>Region: Accessor methods</remarks>
	/*	-------------------------------------------	*/
	this.GetForm = function() { return(_frm); }
	/*	-------------------------------------------	*/
	/// <remarks>Region: Public methods</remarks>
	/*	-------------------------------------------	*/
	this.KeyPress = _KeyPress;
	this.Check = _Check;
	this.CheckPop = _CheckPop;
	this.Validate = _Validate;
	this.Submit = _Submit;
	this.Previous = _Previous;
	this.ShowHint = _ShowHint;
	this.Clear = _Clear;
	this.SetEmailConfirm = _SetEmailConfirm;
	this.SetSmsRemain = _SetSmsRemain;
	this.CalcDate = _CalcDate;
	this.CalcTime = _CalcTime;
	this.SelectCheck = _SelectCheck;
	this.SetDrop = _SetDrop;
	this.InitDrop = _InitDrop;
	this.ShowBox = _ShowBox;
	this.SetCheck = _SetCheck;
	this.SetCheckBtwse = _SetCheckBtwse;
	this.SetCheckBtwseAll = _SetCheckBtwseAll;
	this.BtwsComp = _BtwsComp;
	this.UpdateValue = _UpdateValue;
	this.Compare = _Compare;
	this.SubmitOnce = _SubmitOnce;
	this.EnableButton = _EnableButton;
	this.SetVisibility = _SetVisibility;
	this.SetHidden = _SetHidden;
	this.SetVisibile = _SetVisibile;
	this.GetInsurance = _GetInsurance;
	this.SetHiddenSubmit = _SetHiddenSubmit;
	this.GetLinkField = _GetLinkField;
	this.SetPPAmounts = _SetPPAmounts;
	this.UpdateItemBillValue = _UpdateItemBillValue;
	this.UpdateBillRegValue = _UpdateBillRegValue;
	this.GetChecks = _GetChecks;
	/// <summary>Method:_SetHiddenSubmit</summary>
	function _SetHiddenSubmit(frm, fl, vl){//form obj field id value 
		_Debug("_Set:", "fm", frm, "fl", fl, "vl", vl);
		if (typeof(frm)=="string") {
			_frm = _getFormByName(frm);
		} else{//assume frm is object of type form 
			_frm = frm;	
			frm = _frm.name;
		}
		var fld = document.getElementById(fl);
		if (fld)
			fld.value = vl;
		_frm.submit();
	}
	/// <summary>Method:_KeyPress</summary>
	function _KeyPress(frm) {
		var ky;
		if (window.event) {
			ky = window.event.keyCode;
			if (window.event.srcElement.type == "textarea")
				return true;
		} else if (!frm.name)
			return false;
		else 
			return true;
			
		if (ky == 13) {
			switch(frm.name) {
				case "nm_logon_form":		_Check(frm, "login");		break;
				case "nm_contact_form":		_Check(frm, "contact");		break;
				case "nm_reg_form":			frm.submit();				break;
				case "nm_feedback_form":	_Check(frm, "feedback");	break;
				case "nm_sms_form":			_Check(frm, "sms");			break;
				case "nm_smslogon_form":	_Check(frm, "login");		break;
				default:					_Check(frm, "default", validateForm);	break;
			}
		}
		return true 
	}
	/// <summary>Method:_Check</summary>
	function _Check(frm, typ, func){
		_Debug("_Check", "frm", frm);				
		if(typeof(frm)=="string"){
			_frm = _getFormByName(frm);
		}else{//assume frm is object of type form 
			_frm = frm;	
			frm = _frm.name;
		}
		_Debug("_Check", "name", _frm.name, " type", typ, " function", typeof(func));
		switch (typ) {
			case "login":		if (_ValidateLogin())		{_SubmitOnce(frm); _frm.submit(); }	break;
			case "email":		if (_ValidateEmail())		_SendEmail();	break;
			case "reportemail":	if (_ValidateEmail())		_SendReportEmail();	break;
			case "faqs":		if (_ValidateFaqs())		_frm.submit();	break;
			case "intfaqs":		if (_ValidateIntranetFaqs())_frm.submit();	break;
			case "contact":		if (_ValidateContact())		{_SubmitOnce(frm); _frm.submit(); }	break;
			case "search":		if (_ValidateSearch())		_frm.submit();	break;
			case "intranet_feedback":
			case "feedback":	if (_ValidateFeedback())	{_SubmitOnce(frm); _frm.submit(); }	break;
			case "sms":			if (_ValidateSms())			{_SubmitOnce(frm); _frm.submit(); }	break;
			case "select":		_frm.submit();	break;
			case "back":		_Previous();	break;
			case "clear":		_Clear();		break;
			case "xed": 		_SubmitOnce(frm); self.Validate = func;if (self.Validate(_frm, self)){_frm.submit(); } break;
			case "valid":
			default:			if (typeof(func) != "function")
									_frm.submit(); 	// submit if validate function does not exist
								else {
									_Debug("_Check", "func", func);
									self.Validate = func;
									if (self.Validate(_frm, self)) {
										_Debug("_Check", "OK", true);
										_frm.submit();
									} else {
										_Debug("_Check", "OK", false);
									}
								}
								break;
		}
	}
	/// <summary>Method:_Check</summary>
	function _CheckPop(frm, typ, func, pgObj, wid, hgt){
		_frm = _getFormByName(frm);
		self.Validate = func;
		if (self.Validate(_frm, self)) {
			var elm,act = _frm.action;
		    for (var i=0; i<_frm.length; i++) {
				elm = _frm.elements[i];
				if (elm.type == "button")
					continue;
				if (elm.type == "radio") {
					if(elm.checked) {
						act = act.concat("&", elm.name, "=", elm.value);
						// special cases 'pdf'...
						if (elm.value == "pdf" || elm.value == "csv")
							act = act.concat("&device=", elm.value); 
					}
				} else if (elm.type == "checkbox")
					act = act.concat("&", elm.name, "=", (elm.checked)? "yes" : "no");
				else
					act = act.concat("&", elm.name, "=", elm.value);
			}
			pgObj.PopReport(act, wid, hgt);
		}
	}
	/// <summary>Method:_Submit</summary>
	function _Submit(frm, url, chk, typ, nme, prc, id, param) {
		_Debug("_Submit", frm.name, " url:", url);
		_frm = frm;
		var thisurl = url;
		if (typ) {
			thisurl += "&type=" + typ;
			thisurl += "&name=" + nme;
			thisurl += "&process=" + prc;
		}
		if (id)
			thisurl += "&id=" + id;
		if (param)
			thisurl += "&" + param;
		_frm.action = thisurl;
		if (chk)
			_Check(frm, typ);
		else
			_frm.submit();
	}
	/// <summary>Method:_Validate</summary>
	function _Validate(frm) {
		_Debug("_Validate", "frm", frm.name);
	}
	/// <summary>Method:_ValidateSearch</summary>
	function _ValidateSearch() {
		return (nm_val.Text(_frm.Keywords, "Please enter a search word"));
	}
	/// <summary>Method:_ValidateFeedback</summary>
	function _ValidateFeedback() {
		return (nm_val.Radio(_frm.Feedback, "Please select an option"));
	}
	/// <summary>Method:_ValidateLogin</summary>
	function _ValidateLogin(){
		_Debug("_ValidateLogin");
		if (!nm_val.Text(_frm.Username, "Please enter your username"))
			return false;
		if (!nm_val.Text(_frm.Pin, "Please enter your password"))
			return false;
		return true;
	}
	/// <summary>Method:_ValidateEmail</summary>
	function _ValidateEmail(){
		if (!nm_val.Email(_frm.Email_Addr_To, "Please enter the recipients email address"))
			return false;
		if (!nm_val.Text(_frm.Email_From, "Please enter your name or email address"))
			return false;
		if (!nm_val.Text(_frm.Email_Subject, "Please enter the subject of the email"))
			return false;
		return true;
	}
	/// <summary>Method:_ValidateFaqs</summary>
	function _ValidateFaqs(){
		if (!nm_val.Text(_frm.Name, "Please enter your name"))
			return false;
		if (!nm_val.Email(_frm.Email, "Please enter your email address"))
			return false;
		if (!nm_val.Text(_frm.Cell_No, "Please enter your contact number"))
			return false;
		return true;
	}
	/// <summary>Method:_ValidateIntranetFaqs</summary>
	function _ValidateIntranetFaqs(){
		//alert(typeof(_frm.Name) + ", " + _frm.name);
		if (!nm_val.Text(_frm.Name, "Please enter your name"))
			return false;
		if (!nm_val.Cell(_frm.Cell_No, "Please enter your contact number"))
			return false;
		return true;
	}
	/// <summary>Method:_ValidateContact</summary>
	function _ValidateContact(){
		if (!nm_val.Text(_frm.Name, "Please enter your name"))
			return false;
		if (!nm_val.Email(_frm.Email, "Please enter your email address"))
			return false;
		if (!nm_val.Text(_frm.Cell_No, "Please enter your contact number"))
			return false;
		return true;
	}
	/// <summary>Method:_ValidateSms</summary>
	function _ValidateSms(){
		if (!nm_val.Cell(_frm.Refno, "Sorry, we do not have a valid number to bill"))
			return false;
		if (!nm_val.Cell(_frm.Phoneno, "Please enter the destination number"))
			return false;
		if (!nm_val.Text(_frm.Message, "Please enter the text of your SMS"))
			return false;
		return true;
	}
	/// <summary>Method:_SendEmail</summary>
	function _SendEmail() {
		var act = "nm_email.asp" + document.location.search;
		act = act.replace("siteid=ver5_email", "siteid=ver5_print");
		act = act.replace("device=email", "device=print");
		_frm.action = act;
		_frm.submit();
	}
	/// <summary>Method:_SendReportEmail</summary>
	function _SendReportEmail() {
		var act = "nm_html2email.asp" + document.location.search;
		act = act.replace("device=email", "device=print");
		_frm.action = act;
		_frm.submit();
	}
	/// <summary>Method:_Previous</summary>
	function _Previous() {
		window.history.back();
	}
	/// <summary>Method:_ShowHint</summary>
	function _ShowHint(hintelem, hinttext) {
		var thishint = document.getElementById(hintelem);
		if (thishint)
			thishint.innerHTML = hinttext;
	}
	/// <summary>Method:_Previous</summary>
	function _Clear(frm) {
		if (frm)
			_frm = frm;
		_frm.reset();
	}
	/// <summary>Method:_SetEmailConfirm</summary>
	function _SetEmailConfirm(fldnme, thischk) {
		var thisfld = document.getElementById(fldnme);
		if (thischk.checked == true) {
			thisfld.disabled = false;
			thisfld.focus();
		} else
			thisfld.disabled = true;
	}
	/// <summary>Method:_SetSmsRemain</summary>
	function _SetSmsRemain(thistxt, thishint) {
		var thiscnt = document.getElementById(thistxt.id + "_count");
		var thismsg = thistxt.value;
		var thislen = thismsg.length;
		if (thislen > 160)
			alert(thishint);
		else
			thiscnt.value = 160 - thislen;
	}
	/// <summary>Method:_CalcDate</summary>
	function _CalcDate(fldid) {
		thisid = fldid.id;
		var thisdd = document.getElementById(thisid + "_day");
		var thismm = document.getElementById(thisid + "_month");
		var thisyy = document.getElementById(thisid + "_year");
		
		var dd = (thisdd.value == "Date")? "" : thisdd.value;
		var mm = (thismm.value == "Month")? "" : thismm.value;
		var yy = (thisyy.value == "Year")? "" : thisyy.value;
		
		fldid.value = yy + "-" + mm + "-" + dd;
		_Debug("_CalcDate", "fldid", fldid.value);
	}
	/// <summary>Method:_CalcTime</summary>
	function _CalcTime(fldid) {
		thisid = fldid.id;
		var thismin = document.getElementById(thisid + "_minutes");
		var thishr = document.getElementById(thisid + "_hours");
		var mn = (thismin.value == "Minutes")? "0" : thismin.value;
		var hr = (thishr.value == "Hours")? "" : thishr.value;
		fldid.value = parseFloat(hr) + parseFloat(mn/60);
		_Debug("_CalcTime", "fldid", fldid.value);
	}
	/// <summary>Method:_SelectCheck</summary>
	function _SelectCheck(thisfld, ischeckbox) {
		if (ischeckbox == true) {
			if (thisfld.checked == false) {
				var re = /_check/i;	//	regular expression pattern.
				var fldname = thisfld.name;
				var thisdrop = document.getElementById(fldname.substr(0, fldname.search(re)));
				thisdrop.value = 0;
			}
		} else {
			var thischeck = document.getElementById(thisfld.id + "_check");
			thischeck.checked = (thisfld.value == 0)? false : true;
		}
	}
	/// <summary>Method:_SetDrop</summary>
	function _SetDrop(val, sel, i_arr, s_ord, s_arr, t_ord, t_arr) {
		_Debug("_SetDrop", "val", val, "t_ord", t_ord);
		var i, t_val, t, cnt;
		for (i=0; i<s_arr.length; i++) {
			if(s_arr[i][1] == val) {
				t_val = s_arr[i][0];
				_Debug("Testing", "t_val", t_val, "t_ord", t_ord);
				break;
			}
		}
		for (i=0, cnt=1; i<i_arr.length; i++) {
			if(i_arr[i][s_ord] == t_val) {
				t = setTarget(i_arr[i][t_ord]);
				if (t) {
					sel.options[cnt] = t;
					cnt++;
				}
			}
		}
		sel.options.length = cnt;
		function setTarget(val) {
			for(var i=0; i<t_arr.length; i++) {
				if(t_arr[i][0] == val) {
					//_Debug("setTarget", "2", t_arr[i][2], "1", t_arr[i][1]);
					return (new Option(t_arr[i][2], t_arr[i][1]))
				}
			}
			return(null);
		}
	}
	/// <summary>Method:_InitDrop</summary>
	function _InitDrop(val, sel, i_arr, s_ord, s_arr, t_ord, t_arr) {
		var org = (sel.value != 0)? sel.value : false;
		_SetDrop(val, sel, i_arr, s_ord, s_arr, t_ord, t_arr);
		sel.value = org;
	}
	/// <summary>Method:_ShowBox</summary>
	function _ShowBox(obj, thisid, thisval) {
		var root = (document.all)? document.all : document;
		var val = (thisval)? obj.value : obj.selectedIndex;
		if (!thisval && val <= 4) {
			root[thisid][0].style.display = 'block';
		} else if (thisval && val == thisval) {
			root[thisid][0].style.display = 'block';
		} else {
			root[thisid][0].style.display = 'none';
		}
	}/// <summary>Method:_getCheckBoxGroupById</summary>
	function _getCheckBoxGroupById(chkBx) {
		var retArr = new Array();
		var el = document.getElementById(chkBx);
		if(!el) return false;
		var els = document.documentElement.getElementsByTagName(el.tagName);
		//_Debug("_SetCheck::_getCheckBoxGroupById", "el.tagName", el.tagName);
		for(i=els.length-1;i>=0;i--){
			var tmpEl = els[i];
			if(tmpEl.id == chkBx){
				retArr.push(tmpEl);
				_Debug("_SetCheck::_getCheckBoxGroupById", "retArr", retArr[retArr.length-1]);
			}
		}
		return retArr.reverse();
	}
	/// <summary>Method:_GetChecks</summary>
	function _GetChecks(chkName) {
		var ckEls = document.getElementsByName(chkName);// * SS20070614: chkName refers to @id of <input>: IE doesn't comply to standard and returns on @id or @name 
		_Debug("_SetCheck", "ckEls", ckEls);
		if(ckEls.length==0)// SS20070614: FireFox complies and returns empty array for * above
			ckEls = _getCheckBoxGroupById(chkName);
		return ckEls;
	}
	
	/// <summary>Method:_SetCheckBtwseAll</summary>
	function _SetCheckBtwseAll(chkName, chElAll) {
		_SetCheckBtwse(chkName, chElAll.name, chElAll.checked);
	}
	
	/// <summary>Method:_SetCheckBtwse</summary>
	function _SetCheckBtwse(chkName, allName, setall) {
		_Debug("_SetCheckBtwse", "chkName", chkName);
		var ck = 0, ckFld, ckEl, cntAll = 0;
		var ckEls = _self.GetChecks(chkName);
		for (var i=0; i<ckEls.length; i++) {
			_Debug("_SetCheckBtwse", "ckEls.item", ckEls.item);
			ckEl = (ckEls.item) ? ckEls.item(i) : ckEls[i];
			if (ckEl.type == "hidden")
				ckFld = ckEl;
			else {
				if(setall===true){					
					ckEl.checked = true;
				}else if(setall===false){
					ckEl.checked = false;
				}
				if(ckEl.checked)
					cntAll++;
				ck += (ckEl.checked)? Math.pow(2, (parseInt(ckEl.value)-1)) : 0;
				_Debug("_SetCheckBtwse", "ck", ck);
			}
		}
		_Debug("_SetCheckBtwse", "ck", ck);
		if(_self.GetChecks(allName) && cntAll==(ckEls.length - 1))
			_self.GetChecks(allName).item(0).checked = true;
		if (ckFld)
			ckFld.value = (ck==0) ? "" : ck;
	}
	
   function _BtwsComp(chkName, num1, num2) {
		_Debug("_BtwsComp", "chkName", chkName, "num1", num1, "num2", num2);
		var ckEls = _self.GetChecks(chkName);
		if((num1 & Math.pow(2, num2-1)) > 0)
			ckEls.item(0).checked = true;
	}
	/// <summary>Method:_SetCheck</summary>
	function _SetCheck(chkName, wantval, setall) {
		var ck = "", ckFld, ckEl;
		var ckEls = _self.GetChecks(chkName);
		for (var i=0; i<ckEls.length; i++) {
			_Debug("_SetCheck", "ckEls.item", ckEls.item);
			ckEl = (ckEls.item) ? ckEls.item(i) : ckEls[i];
			if (ckEl.type == "hidden")
				ckFld = ckEl;
			else {
				if(setall===true){
					ckEl.checked = true;
				}else if(setall===false){
					ckEl.checked = false;
				}
				if (wantval)
					ck += (ckEl.checked)? ckEl.value + " " : "-";
				else
					ck += (ckEl.checked)? "yes" : "no";
				if (i!=ckEls.length-1)
					ck+= (wantval)? "" : "|";
			}
		}
		_Debug("_SetCheck", "ck", ck);
		if (ckFld)
			ckFld.value = ck;
	}
	/// <summary>Method:_UpdateValue</summary>
	function _UpdateValue(chkObj, chkName, chkValue) {
		var val = chkName.value.substr(1) * 1;
		val = (chkObj.checked) ? val + chkValue * 1 + .0001 : val - chkValue * 1 + .0001;
		var str = "R" + val.toString();
		var i = str.indexOf(".");
		chkName.value = str.substr(0, i + 3);
	}
	
	/// <summary>Method:_UpdateItemBillValue</summary>
	function _UpdateItemBillValue(chkObj, chkName, chkValue) {
		nm_pge.ToggleAll("itm", "p-tx ind");
		_UpdateValue(chkObj, chkName, chkValue);
	}
	/// <summary>Method:_UpdateBillRegValue</summary>
	function _UpdateBillRegValue(chkObj, chkName, chkValue, uncheck) {
		var total = chkName.value.substr(1) * 1;
		var val = 0;
		var chkdFld = document.getElementsByName("OB_" + chkValue + "_YN");
		var OB_eml_YN = document.getElementsByName("OB_eml_YN");
		var OB_ppr_YN = document.getElementsByName("OB_ppr_YN");
		if(uncheck)
			chkObj.checked = false;
		
		if(chkObj.checked){
			chkdFld.value = "Y";
			if(total==26 || total == 5)
				val = 25;
			if(total==31 || total == 10)
				val = 20;
			if(total==41 || total == 20)
				val = 10;
			if(total==21 || total == 0){
				switch(chkValue){
					case "web" : 
							val = (OB_ppr_YN.value == "Y" || !OB_ppr_YN) ? 20 : 5; break;
					case "eml" : val = (OB_ppr_YN.value=="Y" || !OB_ppr_YN) ? 10 : 5; break;
					case "ppr" : val = (OB_eml_YN.value =="Y" || !OB_eml_YN) ? 10 : 20; break;
				}
			}
		}else if(total==21 || total == 0){
			if(chkValue == "web"){
				chkObj.checked = true;
				_UpdateValue(chkObj, chkName, val);
				alert("You have to select at least one method of notification.");
				return;
			}else{
				chkdFld.value = "N";
				var OB_web = document.getElementsByName("OB_WebsiteYN_Yes").item(0);
				nm_pge.ToggleAll(chkValue, "p-tx ind");
				nm_pge.ToggleAll("web", "p-tx ind");
				_UpdateBillRegValue(OB_web, chkName, "web");
				return;
			}
		}else {
			chkdFld.value = "N";
			if(total==41|| total==20)
				val = 20;
			if(total==31 || total==10)
				val = 10;
			if(total==26 || total==5)
				val = 5;
			if(total==51 || total==30){
				switch(chkValue){
					case "web" : val = 20; break;
					case "eml" : val = 10; break;
					case "ppr" : val = 25; break;
				}
			}
		}
		nm_pge.ToggleAll(chkValue, "p-tx ind");
		//alert(val);
		_UpdateValue(chkObj, chkName, val);
	}
	
	/// <summary>Method:_Compare</summary>
	function _Compare(frmName, fldNames, minsel, maxsel) {
		var frm = _getFormByName(frmName);
		var fld = frm.elements[fldNames];
		var cnt = 0;
		for (i=0;i<fld.length;i++) {
			if (fld[i].checked) cnt++;
		}
		if (cnt<minsel) {
			alert("Please select at least " + minsel + " items to compare");
		} else if (cnt>maxsel) {
			alert("Please select up to " + maxsel + " items to compare");
		} else {
			frm.submit();
		}
	}	

	/// <summary>Method:_SubmitOnce - disable the submit button after validation.</summary>
	function _SubmitOnce(frmName) {
		var frm = _getFormByName(frmName);
		for (var i=0; i<frm.length; i++) {
			var obj = frm.elements[i];
			if(obj.type.toLowerCase()=="button") {
				obj.disabled = true;
				if (obj.style.cursor)	// need this test because of problems with IE5.x
					obj.style.cursor = "not-allowed";
				var found = true;
			}
		}
		if (found)
			window.setTimeout("nm_frm.EnableButton(nm_frm.GetForm());", 10000); // need to send global variable nm_frm.GetForm due to settimeout context
		return false;
	}
	
	/// <summary>Method: _EnableButton - re-enables the submit button after a period of time.</summary>
	function _EnableButton(frm) {
		for (var i=0; i<frm.length; i++) {
			var obj = frm.elements[i];
			if(obj.type.toLowerCase()=="button") {
				obj.disabled = false;
				obj.style.cursor = "default";
			}
		}
	}
	/// <summary>Method: _SetVisibility</summary>
	function _SetVisibility(vis, elt, fld, nos) { 
		_Debug("_SetVisibility", "vis", vis, "fld", fld, "elt", elt);
		if (vis)
			_SetVisibile(elt, nos);
		else
			_SetHidden(elt, nos);
		var fl = document.getElementById(fld);
		if (fl) {
			fl.value = (fl && !vis)? "n/a" : "";
			_Debug("_SetVisibility", "value", fl.value);
		}
	}
	/// <summary>Method: _SetHidden - .</summary>
	function _SetHidden(elt, nospace) { 
		_Debug("_SetHidden", "elt", elt, "nospace", nospace);
		var el = document.getElementById(elt);
		if (el)
			(nospace && (el.style.display))? el.style.display = 'none' : el.style.visibility = "hidden";
	}
	/// <summary>Method: _SetVisibile - .</summary>
	function _SetVisibile(elt, nospace) { 
		_Debug("_SetVisibile", "elt", elt, "nospace", nospace);
		var el = document.getElementById(elt);
		if (el)
			(nospace && (el.style.display))? el.style.display = 'block' : el.style.visibility = "visible";
	}
	/// <summary>Method: _GetInsurance - retrieves the insurance value for a particular phone.</summary>
	function _GetInsurance(fld, val, arr) {
		var ret = "R0.00 per month";
		for (var i=0; i<arr.length; i++) {
			if (arr[i][0] == val) {
				ret = arr[i][1];
				break;
			}
		}
		ret = (ret == "Not available") ? "Not available (Contact us using the above link)" : ret;
		fld.value = ret;
	}
	/// <summary>Method: _SetPPAmounts 
	function _SetPPAmounts(chosen, recharge) {
		var cellc = new Array('35', '50', '70', '150');
		var mtn = new Array('30', '60', '180');
		var vodacom = new Array('29', '55', '110', '275', '1000');
		var selbox = recharge;
		if (chosen == "082" || chosen == "072" || chosen == "076" || chosen == "079") {
			for (var i=0; i<vodacom.length; i++) {
			  	selbox.options[i+1] = new Option('R' + vodacom[i] ,vodacom[i]);
			  	}
			selbox.options.length = vodacom.length+1;
		}
		else if (chosen == "083" || chosen == "073") {
			for (var i=0; i<mtn.length; i++) {
				selbox.options[i+1] = new Option('R' + mtn[i] ,mtn[i]);
				}
			selbox.options.length = mtn.length+1;
		}
		else if (chosen == "084") {
		 for (var i=0; i<cellc.length; i++) {
			  	selbox.options[i+1] = new Option('R' + cellc[i] ,cellc[i]);
			  	}
			selbox.options.length = cellc.length+1;
		}
		else 
			selbox.options.length = 1;
	}
	/// <summary>Method: _getFormByName - retrieves the form object based on a reference passed.
	function _getFormByName(frmName) {
		_Debug("_getFormByName");
		var frm = document.getElementById(frmName);
		if (!frm)	// used if the form has a name instead of id
			frm = document.forms[frmName];
		_Debug("_getFormByName", "frm", frm);
		return frm;
	}
	
	/// <summary>Method:_GetDropLinkURL - replaces 'link' parameter in the url with fdLnk value</summary>
	function _GetLinkField(url, formName, fdLnk) {
		_Debug("_GetDropLinkURL");
		var ul = url;
		var now = new Date();
		ul = ul.replace("link=", "invalid_link=");
		ul = ul.concat("&link=", fdLnk.value, "&cache=", Date.parse(now.toString()));
		return(ul);
	}
	/// <summary>Method:_Debug - write debugging message. First param is the method label, followed by name, value pairs</summary>
	function _Debug(arg) {
		if (_debug) {
			s = "<!-- ClassNM_Form::"
			s = s.concat(arguments[0], ":");
			var argn = arguments.length;
			for(var i=1; i<argn; i=i+2)
				s = s.concat(arguments[i], ":", arguments[i+1], " ");
			alert(s.concat("-->\n"));
		}
	}
}
/*	=======================================================================	*/
/// <remarks>
/// Class: ClassNM_Valid
/// The ClassNM_Valid object class has the following purpose/function:
///	- supplies client-side properties and methods for 'form' objects
/// </remarks>
/*	-----------------------------------------------------------------------	*/
/// <summary>
/// The ClassNM_Valid object class is constructed as follows:
///		var thisobj = new ClassNM_Valid(dbg);
/// - where:
///		- dbg:	debugging switch
/// </summary>
function ClassNM_Valid(dbg) {
	/*	-------------------------------------------	*/
	/// <remarks>Properties: Private</remarks>
	/*	-------------------------------------------	*/
	var _self = this;	// self allows for a method/property to be called internally
	var _debug = (dbg)? dbg : false;
	/*	-------------------------------------------	*/
	/// <remarks>Region: Public methods</remarks>
	/*	-------------------------------------------	*/
	this.Test = _Test;
	this.Text = _Text;
	this.Date = _Date;
	this.Password = _Password;
	this.Email = _Email;
	this.Check = _Check;
	this.Radio = _Radio;
	this.Drop = _Drop;
	this.Number = _Number;
	this.StripCell = _StripCell;
	this.Cell = _Cell;
	this.Telephone = _Telephone;
	this.IntCell = _IntCell;
	this.DateRange = _DateRange;
	this.PostalCode = _PostalCode;
	this.ID = _ID;
	this.TextDrop = _TextDrop;
	this.NumDrop = _NumDrop;
	this.Checks = _Checks;
	this.Expiry = _Expiry;
	this.Compare = _Compare;
	this.Time = _Time;
	this.Debug = _Debug;
	
	/// <summary>Method:_Date</summary>
	function _Test(thisfld, thishint) {
		alert("_Test::" + thisfld.name + ":" + thisfld.value);
	}
	/// <summary>Method:_Text</summary>
	function _Text(thisfld, thishint, minlen, maxlen) {
		_Debug("_Text", "thishint", thishint, "thisfld", thisfld.name, "minlen", minlen, "maxlen", maxlen);
		if (!thisfld.value || (minlen && thisfld.value.length < minlen) || (maxlen && thisfld.value.length > maxlen))// || thisfld.value.length <= 0)
			return _Notify(thishint, thisfld, true);
		return true;
	}
	/// <summary>Method:_Compare</summary>
	function _Compare(thisfld, thishint, compfld) {
		_Debug("_Compare", "thishint", thishint, "thisfld", thisfld.name, "compfld", compfld.name);
		if (thisfld.value != compfld.value)
			return _Notify(thishint, thisfld, true);
		return true;
	}
	/// <summary>Method:_Date</summary>
	function _Date(thisfld, thishint) {
		_Debug("_Date", "thisfld", thisfld.name);
		if (!thisfld.value)
			return _Notify(thishint, thisfld, false);
		return true;
	}
	/// <summary>Method:_Time</summary>
	function _Time(thisfld, thishint) {
		_Debug("_Time", "thisfld", thisfld.name);
		if (!thisfld.value || thisfld.value == 0)
			return _Notify(thishint, thisfld, false);
		return true;
	}
	/// <summary>Method:_Password</summary>
	function _Password(thisfld, confirmfld, thishint) {
		_Debug("_Password", "thisfld", thisfld.name);
		if (thisfld.value.length < 6)	//at least 6
			return _Notify(thishint, thisfld, true);
		// check if both password fields are the same
		if (thisfld.value != confirmfld.value) {
			return _Notify("The two passwords are not the same.", thisfld, true);
		}
		return (true);
	}
	/// <summary>Method:_Email</summary>
	function _Email(thisfld, thishint){
		_Debug("_Email", "thisfld", thisfld.name);
		validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
		strEmail = thisfld.value;
		if (strEmail) {
			// search email text for regular exp matches
			if (strEmail.search(validRegExp) == -1)
				return _Notify(thishint, thisfld, true);
			return true; 
		}
		else alert(thishint);
	}
	/// <summary>Method:_Check</summary>
	function _Check(thisfld, thishint) {
		_Debug("_Check", "thisfld", thisfld.name);
		if (!thisfld.checked)
			return _Notify(thishint, thisfld, true);
		return true;
	}
	/// <summary>Method:_Radio</summary>
	function _Radio(thisfld, thishint) {
		_Debug("_Radio", "thishint", thishint);
		var bChecked = false;
		for (i=0;i<thisfld.length;i++) {
			if (thisfld[i].checked)
			   return true;
		}
		alert(thishint);
		window.navigate("#" + thisfld.id);
		return false;
	}
	/// <summary>Method:_Drop</summary>
	function _Drop(thisfld, thishint) {
		_Debug("_Drop", "thisfld", thisfld.name);
		if (thisfld.selectedIndex==0)
			return _Notify(thishint, thisfld, true);
		return true;
	}
	
	/// <summary>Method:_TextDrop</summary>
	function _TextDrop(thisfld, thishint) {
		var thisdrop = document.getElementById(thisfld.id + "_drop");
		if (_Text(thisfld, thishint) && _Drop(thisdrop, thishint))
			return true;
		else
			return false;
	}
	
	/// <summary>Method:_NumDrop</summary>
	function _NumDrop(thisfld, thishint) {
		_Debug("_NumDrop", "thishint", thishint, "thisfld", thisfld.name);
		if(_TextDrop(thisfld, thishint) && _Number(thisfld, thishint))
			return true;
		else
			return false;
	}
	/// <summary>Method:_Number</summary>
	function _Number(thisfld, thishint, checkfld, checktype) {
		_Debug("_Number", "thisfld", thisfld.name);
		var validRegExp = /(^-*\d+$)|(^-*\d+\.\d+$)/i;///^[0-9]{1,}.{0,}[0-9]{0,}$/i;
		var strVal = thisfld.value;
		var isvalid = true;
		if (strVal) {
			//var arrMatch = strVal.match(validRegExp);
			//_Debug("_Number", "arrMatch", arrMatch.length);
			if (strVal.search(validRegExp) == -1)// || strVal.split(validRegExp).length > 1) 
				isvalid = false;
			else if (checkfld) {
				var thisval = parseFloat(strVal);
				var chckval = parseFloat(checkfld.value);
				if (isNaN(thisval) || isNaN(thisval)) 
					isvalid = false;
				else {
					// use checktype (later..)
					if (thisval < chckval)
						isvalid = false;
				}
			}
		}
		else 
			isvalid = false;
		
		if (isvalid)
			return true;
		else
			return _Notify(thishint, thisfld, true);
	}
	/// <summary>Method:_StripCell - strips characters, then calls _Cell validation</summary>
	function _StripCell(thisfld, thishint){
		var stripexp = /[()\- ]/g;
		thisfld.value = thisfld.value.replace(stripexp, "");
		return _Cell(thisfld, thishint);
	}
	/// <summary>Method:_Cell</summary>
	/*	==========================================	
		Check for a valid cell number: 				
		-	Check 1: They begin "0[7/8/9][2/3/4]";	
		-	Check 2: only 0-9						
		-	Check 3: must be 10 digits				
		========================================	*/
	function _Cell(thisfld, thishint) {
		_Debug("_Cell", "thisfld", thisfld.name);
		var retval = (thisfld.value)? 0 : 1;
		//alert(retval + ", " +  thisfld.value);
		if (!retval) {
			var val = thisfld.value;
			var cellexp = /[0-9]{10}/;		// NB this will accept more than 10 digits!
			var strtexp = /0[789][123467890]/ ;
			if (cellexp.test(val) && val.length==10) {
				retval = (strtexp.test(val)) ? 0 : 1;
				if (retval)
					thishint = thishint.concat(" (must start 07, 08 or 09)");
			} else {
				thishint = thishint.concat(" (must be 10 digits)");
				retval = 1;
			}
		}
		if (retval)
			return _Notify(thishint, thisfld, false);
		else
			return true;
	}
	/// <summary>Method:_Telephone</summary>
	/*	==========================================	
		Check for a valid phone number: 				
		-	Check 1: only 0-9						
		-	Check 2: must be 10 digits				
		========================================	*/
	function _Telephone(thisfld, thishint) {
		_Debug("_Telephone", "thisfld", thisfld.name);
		var retval = (thisfld.value)? 0 : 1;
		if (!retval) {
			var val = thisfld.value;
			var cellexp = /[0-9]{10}/;
			if (cellexp.test(val) && val.length==10) 
				retval = 0;
			else {
				thishint = thishint.concat(" (must be 10 digits)");
				retval = 1;
			}
		}
		if (retval)
			return _Notify(thishint, thisfld, false);
		else
			return true;
	}
	/// <summary>Method:_IntCell</summary>
	function _IntCell(thisfld, thishint){
		_Debug("_IntCell", "thisfld", thisfld.name);
		var retval = (thisfld.value)? 0 : 1;
		if (!retval) {
			var val = thisfld.value;
			var cellexp = /\d{11}/;		// NB this will accept more than 10 digits!
			var strtexp = /27[789][234689]/ ;
			if (cellexp.test(val) && val.length==11)
				retval = (strtexp.test(val)) ? 0 : 1;
			else
				retval = 1;
			}
		if (retval)
			return _Notify(thishint, thisfld, true);
		else
			return true;
	}
	/// <summary>Method:_DateRange</summary>
	function _DateRange(thisfld, thishint){
		_Debug("_DateRange", "thisfld", thisfld.length);
		if (_Radio(thisfld, thishint)) {
			var thischk = "";
			var thisid = "";
			for (i=0;i<thisfld.length;i++) {
				if (thisfld[i].checked) {
				   thischk = thisfld[i].value;
				   thisid = thisfld[i].id;
				   break;
			   }
			}
			if (thischk == "Date") {
				var thisdate = document.getElementById(thisid + "_date");
				if (_Drop(thisdate, thishint)) {
					var thismnth = document.getElementById(thisid + "_month");
					return(_Drop(thismnth, thishint));
				}
				else
					return false;
			}
			return true;
		}
		else
			return false;
	}
	/// <summary>Method:_PostalCode</summary>
	function _PostalCode(thisfld, thishint) {
		_Debug("_PostalCode", "thisfld", thisfld.name);
		var validRegExp = /[0-9]{4,4}/;
		var strVal = thisfld.value;
		var isvalid = true;
		if (strVal && validRegExp.test(strVal) && strVal.length==4)
			isvalid = true;
		else 
			isvalid = false;
		
		if (isvalid)
			return true;
		else
			return _Notify(thishint, thisfld, true);
	}
	/// <summary>Method:_ID</summary>
	function _ID(thisfld, thishint) {
		var stripexp = /[()\- ]/g;
		thisfld.value = thisfld.value.replace(stripexp, "");
		return _validID(thisfld, thishint);
	}
	/// <summary>Method:_validID</summary>
	function _validID(thisfld, thishint) {
		_Debug("_ID", "thisfld", thisfld.name);
		var validRegExp = /[0-9]{13,13}/;
		var strVal = thisfld.value;
		var isvalid = true;
		if (strVal) {
			if (strVal.search(validRegExp) == -1)
				isvalid = false;
			else
				isvalid = (strVal.length == 13);
		}
		else 
			isvalid = false;
		
		if (isvalid)
			return true;
		else
			return _Notify(thishint, thisfld, true);
	}
	/// <summary>Method:_Checks</summary>
	function _Checks(thisfld, thishint) {
		_Debug("_Checks", "thisfld", thisfld.length);
		var fld;
		for (var i=0; i<thisfld.length; i++) {
			fld = thisfld.item(i);
			if (fld.checked)
				return true;
		}
		return _Notify(thishint, thisfld, false);
	}
	/// <summary>Method:_Expiry</summary>
	function _Expiry(thisfld, thishint) {
		_Debug("_Expiry", "thisfld", thisfld.name);
		var validRegExp = /[0-9]{2,2}-[0-9]{2,2}/;
		var strVal = thisfld.value;
		var isvalid = true;
		if (strVal) {
			if (strVal.search(validRegExp) == -1)
				isvalid = false;
			else
				isvalid = (strVal.length == 5);
		}
		else 
			isvalid = false;
		
		if (isvalid)
			return true;
		else
			return _Notify(thishint, thisfld, true);
	}
	/// <summary>Method:_Notify - show validation message, select, set focus.</summary>
	function _Notify(hnt, fld, sel) {
		alert(hnt);
		sel = (typeof(sel)!="undefined")? sel : true;
		if (sel && fld.style.visibility == "visible") {
			fld.select();
			fld.focus();
		}
		return false;
	}
	
	/// <summary>Method:_Debug - write debugging message.</summary>
	function _Debug(arg) {
		if (_debug) {
			s = "<!-- ClassNM_Valid::"
			s = s.concat(arguments[0], ":");
			var argn = arguments.length;
			for(var i=1; i<argn; i=i+2)
				s = s.concat(arguments[i], ":", arguments[i+1], " ");
			alert(s.concat("-->\n"));
		}
	}
}
/*	=======================================================================	*/
/// <remarks>
/// Class: ClassNM_Group
/// The ClassNM_Group object class has the following purpose/function:
///	- supplies client-side properties and methods for 'group' objects
/// </remarks>
/*	-----------------------------------------------------------------------	*/
/// <summary>
/// The ClassNM_Group object class is constructed as follows:
///		var thisobj = new ClassNM_Group(dbg);
/// - where:
///		- dbg:	debugging switch
/// </summary>
function ClassNM_Group(dbg, pge) {
	/*	-------------------------------------------	*/
	/// <remarks>Properties: Private</remarks>
	/*	-------------------------------------------	*/
	var _self = this;	// self allows for a method/property to be called internally
	var _debug = (dbg)? dbg : false;
	var _id = "ClassNM_Xxx";
	var _page = pge;
	/*	-------------------------------------------	*/
	/// <remarks>Region: Public methods</remarks>
	/*	-------------------------------------------	*/
	this.Set = _Set;
	this.Submit = _Submit;
	this.ValidChks = _ValidChks;
	this.Send = _Send;
	this.Sort = _Sort;
	this.SortOrder = _SortOrder;
	this.ChangeValue = _ChangeValue;
	this.GoValue = _GoValue;
	this.GoDrop = _GoDrop;
	this.GoDropDoc = _GoDropDoc;
	this.GoPage = _GoPage;
	this.GoVcr = _GoVcr;
	/// <summary>Method:_Set</summary>
	function _Set(fm, fl, vl) {
		var frm = (typeof(fm)==="string") ? document.getElementsByName(fm).item(0) : fm;
		_Debug("_Set:", "fm", fm, "fl", fl, "vl", vl);
		var fld = document.getElementById(fl);
		if (fld)
			fld.value = vl;
		frm.submit();
	}
	/// <summary>Method:_Submit</summary>
	// was:groupForm()
	function _Submit(fm, url, id, param) {
		var thisurl = url;
		if (id!='')
			thisurl += "&id=" + id;
		if (param) {
			thisurl += "&" + param;
		}
		_Debug("_Submit", "thisurl", thisurl);
		fm.action = thisurl;
		fm.submit();
	}
	/// <summary>Method:_ValidChks</summary>
	// was: validateGroupChkBxs()
	function _ValidChks(fm, url, id, param) {
		if (fm.elements.length < 1) {
			_Submit(fm, url, id, param);
		} else {
			var nchk = 0, ntot = 0;
			for (var e=0; e<fm.elements.length; e++) {
		    	var el = fm.elements[e];
		    	if (el.type == 'checkbox' && el.type != 'hidden') {
					ntot++;
					if (el.checked)
						nchk++;
				}
			}
			if (ntot == 0) {
				_Submit(fm, url, id, param);
			} else if (nchk > 0) {
				_Submit(fm, url, id, param);
			} else {
				alert('Please check at least one checkbox.');             
				return false;
			}
		}
	}
	/// <summary>Method:_Send</summary>
	// was: sendGroupForm()
	function _Send(fm, ck, pt) {
		var ok = (ck)? _Check(fm, pt) : true;
		if (ok)
			fm.submit();
	}
	/// <summary>Method:_Check</summary>
	// was: checkGroupForm()
	function _Check(fm, pt) {
		var el, nm, ch, sl;
		for (var i=0; i<fm.elements.length; i++) {
	    	el = fm.elements[i];
			nm = el.name
			ch = nm.substr(0, 7);
	    	if (ch == 'select_') {
				if (el.value > 0) {
					sl = document.getElementsByName('editcheck_' + nm.substr(7));
					if (sl[0].value == "") {
						alert(pt);
						return(false);
					}
				}
			}
		}
		return(true);
	}
	/// <summary>Method:_Sort</summary>
	// was: nm_group_sort()
	function _Sort(st, fm) {
		fm.Sort_Col.value = st;
		fm.Page_No.value = "1";
		fm.submit();
	}
	/// <summary>Method:_SortOrder</summary>
	// was: nm_group_sortorder()
	function _SortOrder(st, fm, href) {
		fm.Order_Col.value = st;
		fm.action = (href)? href : _page.Href;
		fm.submit();
	}
	/// <summary>Method:_ChangeValue</summary>
	// was: nm_group_change()
	function _ChangeValue(fd, vl) {
		fd.value = vl;
	}
	/// <summary>Method:_GoValue</summary>
	// was: nm_getfieldvalue()
	function _GoValue(fd, url) {
		document.location = url + fd.value; 
	}
	/// <summary>Method:_GoDrop</summary>
	function _GoDrop(url, fd, id, pop) {
		_Debug("GoDrop", "pop", pop);
		var ul = url.concat(fd.value, "&id=", id);
		if (pop)
			pge.PopDrop(ul); 
		else 
			document.location = ul;
	}
	/// <summary>Method:_GoDropDoc</summary>
	function _GoDropDoc(fd, id, pop) {
		if (!fd.value)
			return;
		var url = fd.value + "&id=" + id;
		_Debug("_GoDropDoc", "url", url);
		if (pop)
			pge.PopDown(url); 
		else 
			document.location = url;
	}
	/// <summary>Method:_GoPage</summary>
	// was: nm_goto_grpform()
	function _GoPage(pg, fm) {
		if (pg='' || isNaN(parseInt(pg)))
			fm.Page_No.value = 1;
		else {
			fm.Page_No.value = parseInt(pg);
			fm.submit();
		}
	}
	/// <summary>Method:_GoVcr</summary>
	// was: nm_goto_grpform()
	function _GoVcr(pg, fm) {
		fm.Page_No.value = pg;
		fm.submit();
	}
	/*	-------------------------------------------	*/
	/// <remarks>Region: Private methods</remarks>
	/*	-------------------------------------------	*/
	/// <summary>Method:_RaiseError</summary>
	function _RaiseError(thiserr) {
		_Debug("RaiseError:", "thiserr", thiserr);
		throw (thiserr);
	}
	/// <summary>Method:_Debug - write debugging message. First param is the method label, followed by name, value pairs</summary>
	function _Debug(arg) {
		if (_debug) {
			s = "<!-- ClassNM_Group::"
			s = s.concat(arguments[0], ":");
			var argn = arguments.length;
			for(var i=1; i<argn; i=i+2)
				s = s.concat(arguments[i], ":", arguments[i+1], " ");
			alert(s.concat("-->\n"));
		}
	}
}

