function tmpGetNameOrIds(nameOrId) {
	var allFrmEls = (nameOrId=='name') ? (new Object(eval("document."+gFrmName+".elements"))) : document.all;
	var length = allFrmEls.length;
	var ary = new Array();

	for (var i=0; i<length; i++) {
		var currentEl = eval('allFrmEls[i].'+nameOrId);
		if (i!=0) var prevEl = eval('allFrmEls[i-1].'+nameOrId);
		if ( currentEl.substr(0,gFrmName.length)==gFrmName //ensure el name has gFrmName prefix, to reduce chance of fetching wrong el
		&& (i==0 || currentEl!=prevEl) ) //get all unique elements esp in case of RB/CB groups (first el or current el != prev el)
			ary.push('<br />'+currentEl+'&nbsp;');
	}
	if (ary.length==0) return false;
	else document.write(ary);
}
/*-----------------------------------------------------*/

var gFrmName = "frm"; //standard prefix across all forms to reduce chance of clashing element names.
//this is same across all forms so that we will not have to prefix each form's element names/cell ids with different prefix.
//make sure all forms have this name
var gAryCookieEl = new Array();
var gAryCookieVal = new Array();

//the starting function
//called in <body onload="initFrm(1);" ... >
//if form page, call initFrm(1), will check for existing cookies for that step and populate form
//if confirm/complete page, call initFrm('c'), will check for existing cookies for all preceeding steps and populate page
function initFrm(stepNum) {
	if (!chkCookies()) return; //check that cookies are accepted
	var stepNumLowerCase=stepNum.toString().toLowerCase();
	if (stepNumLowerCase.charAt(0)=='c') { //indicator of confirm/complete page
		for (var i=1; i<=gMaxSteps; i++) {
			if (getArysFrCookie(i)) {
				popFrm('id'); //check for each step's cookie and populate those values into confirm/complete pg
				chkShowSection(); //check which optional sections to hide
			}
		}
		if (stepNumLowerCase=='complete') populateFooter();
	}
	else if (getArysFrCookie(stepNum)) {
		popFrm('name'); //cookies are present, populate values into page
		chkShowSection();
	}
}
//called on every page body onload, to check if optional sections should be collapsed.
//if first time accessing, dont collapse regardless of CB status
//else user is editing form, collapse if CB unchecked
function chkShowSection() { //eg. tblId = 'tblCBrewardsFfp', the CB we need to check = 'frmCBrewardsFfp'
	var aryTR = document.getElementsByTagName('tr');
	for (var i=0; i<aryTR.length; i++) { //look for rows with class='tblHidden'
		if (aryTR[i].getAttributeNode('class') && aryTR[i].getAttributeNode('class').value=='tblHidden') { //get the value of the class attribute in the current row
			var tblId = aryTR[i].getAttributeNode('id').value; //get the value of the id attribute in the current row
			//var cbId = tblId.replace('tbl', 'frm');
			var cbId = 'frmCB'+tblId.substr(3,1).toLowerCase()+tblId.substr(4,tblId.length); //alter tblId to find the respective CB to check
			for (var j=0; j<gAryCookieEl.length; j++) { //checking for existence of cbId in the cookie's form elements (precaution in case tbl vs CB naming format is wrong)
				if (gAryCookieEl[j]==cbId && gAryCookieVal[j]=='false') { 
					toggleTbl(tblId,'hide'); //if can find the resp CB & it is not checked, toggle the table to hide it
				}
			}
		}
	}
}
//called in <form onsubmit="return processFrm(1);" action="step2.html" method="post" ... >
function processFrm(stepNum) {
	if (validate(stepNum)) {
		writeArysToCookie(stepNum,'name'); //if validation ok, write data to cookie
		return true;
	}
	else return false;
}

/*-----------------------------------------------------*/
//populates entire form/confirm/complete page with stored cookie values
//gets all form element names/document ids and matches against those in the global var gAryCookieEl
//if match, populates the el name/doc id of gAryCookieEl[i] with gAryCookieVal[i]
function popFrm(nameOrId) {	
	var aryFrmEl = new Array();
	aryFrmEl = getFrmElAry(nameOrId); //get all el names/document ids
	var lblContent = null;

	for (var i=0; i<gAryCookieEl.length; i++) { //for each el name stored in cookie
		for (var j=0; j<aryFrmEl.length; j++) { //check against each el name of this form
			if (gAryCookieEl[i]==aryFrmEl[j]) {
				//alert(gAryCookieEl[i]+' - '+gAryCookieVal[i]);
				if (nameOrId=='name') {
					if (gAryCookieVal[i]!='false') setFrmVal

(gAryCookieEl[i],gAryCookieVal[i]); //put cookie value into form element
					else setFrmVal(gAryCookieEl[i],''); //put empty value into form element
				}
				else if (gAryCookieVal[i]!='false') {
					lblContent = document.createElement("span");  //AAV - 12102008 - Updated the script to work with the current platform
					lblContent.innerHTML = unescape(gAryCookieVal[i]);
					while (document.getElementById(gAryCookieEl[i]).firstChild) {
						document.getElementById(gAryCookieEl[i]).removeChild(document.getElementById(gAryCookieEl[i]).firstChild);
					}
					document.getElementById(gAryCookieEl[i]).appendChild(lblContent); //.innerHTML=unescape(gAryCookieVal[i]);
				}//if value was found, put cookie value into confirmation/complete page
				aryFrmEl.splice(j,1); //remove matched element from aryFrmEl, so less elements to search against next round
			}
		}
	}
}
/*-----------------------------------------------------*/
//called after validation is ok
//gets arys of form element names & their respective values, and writes to cookie
function writeArysToCookie(stepNum,nameOrId) {
	var aryFrmEl = new Array();
	aryFrmEl = getFrmElAry('name'); //get ary of all unique element names with gFrmName prefix
	var aryFrmValue = new Array();
	aryFrmValue = getFrmValueAry(getFrmElAry('name')); //get ary of all unique element values
//alert('writing cookie\n\n' + aryFrmEl.length + '\n\n' + aryFrmValue.length + '\n\n' + aryFrmEl + '\n\n' + aryFrmValue);
//alert('writing cookie\n\n' + 'frmNamesCookie'+gFrmDescrp+stepNum);
	setCookie('frmNamesCookie'+gFrmDescrp+stepNum,aryFrmEl,0); //eg. cookie name could be 'frmNamesCookieKrisflyer2'
	setCookie('frmValuesCookie'+gFrmDescrp+stepNum,aryFrmValue,0); //trash cookie when browser is closed*/
	//alert('wrote cookie');
}
//called on each page after checking that cookies are accepted
//gets arys of form element names & their respective values from cookie
//stores data in global vars gAryCookieEl and gAryCookieVal
function getArysFrCookie(stepNum) {
	//alert('retrieving cookie\n\n' + 'frmNamesCookie'+gFrmDescrp+stepNum);
	var cookieEls = getCookie('frmNamesCookie'+gFrmDescrp+stepNum);
	var cookieVals = getCookie('frmValuesCookie'+gFrmDescrp+stepNum);

	if (cookieEls && cookieVals) {
		gAryCookieEl = cookieEls.split(",");
		gAryCookieVal = cookieVals.split(",");
//alert('retrieving cookie\n\n' + gAryCookieEl.length + '\n\n' + gAryCookieVal.length + '\n\n' + gAryCookieEl + '\n\n' + gAryCookieVal);	
		return true;
	}
	//else {alert('no cookie found');return false;}
	else return false; //no cookie found, do nothing (first time form is loaded)
}
/*-----------------------------------------------------*/
//collect all form elements/document ids
//returns a sorted ary of all element names/document ids with the gFrmName prefix
//returns false if none found
function getFrmElAry(nameOrId) {
	//if getting name of form elements, check all form elements in document
	//else if getting id of table cells, check all td cells in document
	var allFrmEls = (nameOrId=='name') ? (new Object(eval("document."+gFrmName+".elements"))) : document.getElementsByTagName("td");
	var length = allFrmEls.length;

	var ary = new Array();
	for (var i=0; i<length; i++) {
		var currentEl = eval('allFrmEls[i].'+nameOrId);
		if (i!=0) var prevEl = eval('allFrmEls[i-1].'+nameOrId);
		if ( currentEl.substr(0,gFrmName.length)==gFrmName //ensure el name has gFrmName prefix, to reduce chance of fetching wrong el
		&& (i==0 || currentEl!=prevEl) ) //get all unique elements esp in case of RB/CB groups (first el or current el != prev el)
			ary.push(currentEl);
	}
	if (ary.length==0) return false;
	else return ary.sort();
}
//returns an ary of each element value found in arySrc (an ary of all unique form element names)
//returns false if no values found
//each value is individually escaped and must be individually unescaped
function getFrmValueAry(arySrc) {
	var ary = new Array();
	for (var i=0; i<arySrc.length; i++) {
		switch (getFrmElType(arySrc[i])) {
			case 'TF':
				ary.push(escape(getTFValue(gFrmName, arySrc[i])));
				break;
			case 'RB':
				ary.push(escape(getRBValue(gFrmName, arySrc[i])));
				break;				
			case 'DL':
				ary.push(escape(getDLValue(gFrmName, arySrc[i])));
				break;
			case 'CB':
				ary.push(escape(getCBValue(gFrmName, arySrc[i])));
				break;
		}
	}
	if (ary.length==0) return false;
	else return ary;
}
/*-----------------------------------------------------*/
//sets the value of each fldName with fldValue
//unescapes each value individually 
function setFrmVal(fldName, fldValue) {
	switch (getFrmElType(fldName)) {
		case 'TF':
			setTFValue(gFrmName,fldName,fldValue);
			break;
		case 'RB':
			setRBValue(gFrmName,fldName,fldValue);
			break;				
		case 'DL':
			setDLValue(gFrmName,fldName,fldValue);
			break;
		case 'CB':
			setCBValue(gFrmName,fldName,fldValue);
			break;
	}
}
//returns the form element type occuring after gFrmName prefix
//fldName should have already been verified to contain gFrmName prefix
function getFrmElType(fldName) {
	return fldName.substr(gFrmName.length,2); //eg. RB, CB, DL, TF
}