/*-------------LOV calling related functions - Start----------------*/
//Function to call LOV
function getLOV(oParam){
	if(oParam.lovfldchange)
		displayLOVTable(null,null,null,oParam,true);
	//This is to submit data to page
	var valueString = "lstSearchField="+oParam.lovsearchfld+"&txtSearchValue="+encode(oParam.lovsearchval)+"&txtCurrentPage="+encode(oParam.lovpage)+
										"&hdnCriteria="+escape(oParam.lovcriteria)+"&hdnSortField="+oParam.lovsortfld+"&hdnLovKey="+oParam.lovkey+
										"&hdnSortDirection="+((oParam.lovsortasc)?"A":"D");
	var arrProcess = new Array(processLOVByXML,oParam);
	return new AJAXRequest("POST", oParam.lovurl, valueString, arrProcess);
}

//Function to process and pass data to callback function
function lov_dataProcess(oParam,obj,dval){
	var sval = ((obj)?obj.value:"");
	var bchk = ((obj)?obj.checked:true);
	if(sval=="") sval=dval;
	if(sval>="0"){
		oParam.lovcallback(_arrDataTable[sval],bchk);
	}
}

function processLOVByXML( myAJAX,oParam) {
    if (myAJAX.readyState == 4) {
        if (myAJAX.status == 200) {
            var responseXML = myAJAX.responseXML;
	        processTableXML(responseXML,oParam);
        }
        else
			if(window.status) window.status = "There was a problem retrieving data:\n" + myAJAX.statusText;
		//alert("There was a problem retrieving data:\n" + myAJAX.statusText);
     }
}

//Function to set sort field
function setSortFieldColumn(oParam,field){
	var index = parseFloat(field.id.substr(6,field.id.length));
	var arrcol = _arrColTable[index];
	oParam.lovsortasc = (oParam.lovsortfld == arrcol[1])?((oParam.lovsortasc)?false:true):true;
	oParam.lovsortfld = arrcol[1];
	getLOV(oParam);
}

//create the style object
var _cssTb = new table_style();
// init the final HTML
var finishedHTML = "";
var _lovDiv = null;
var _underLovDiv = null;
var _arrDataTable;
var _arrColTable;
var _xposition=0;
var _yposition=0;
//Function to display lov
function displayLOVTable(oSearch,oData,oPage,oParam,isProcess,hasData){
	_isLov = true;
	var oForm,tbody;
	oForm = document.createElement("form");
	oForm.method = "post";
	oForm.id = "frmLOV";
	oParam.lovform = oForm;

	var points = getScreenPoint(getElById(oParam.lovcomponentId));
	if(_xposition==0)
		_xposition = 150;
	if(_yposition==0)
		_yposition = points.y + 15;
	var lovx = _xposition;//150;//points.x - 150;
	var lovy = _yposition;//points.y + 15;
	if (lovx<0) lovx=0;

	if (_lovDiv==null){
		div = createDiv("dvLOV","divLOV","absolute",lovx,lovy,"500");
		_lovDiv = div;
		document.body.appendChild(_lovDiv);
	}
	else{
		div = _lovDiv;
		div.style.left = lovx+"px";
		div.style.top = lovy+"px";
		div.style.visibility = "";
		div.innerHTML = "";
		if(_underLovDiv) _underLovDiv.removeNode(true);
	}
	tb = createTable(null,"tblLov","0","0","0",null,null);
	tbody = document.createElement("tbody");
	tb.appendChild(tbody);
	tHead = getLovHeading(oParam);
	if (tHead){
		tr = document.createElement("tr");
		tbody.appendChild(tr);
		td = createTd(null,null,null,"20","left","top","2")
		tr.appendChild(td);
		td.appendChild(tHead);
	}
	if (oSearch){
		tr = document.createElement("tr");
		tbody.appendChild(tr);
		td = createTd(null,"lovContainerTopTD",null,null,"left","top","2")
		tr.appendChild(td);
		td.appendChild(oSearch);
	}
	if (isProcess){
		tr = document.createElement("tr");
		tbody.appendChild(tr);
		td = createTd(null,"lovContainerTD",null,null,"left","top","2");
		tr.appendChild(td);
		td.appendChild(getProcessingMsg());
	}

	var oPagePassed = ((oPage)&&(hasData))?oPage:getPageNavigation(null,oParam);
	if((oPagePassed)&&(!isProcess)){
		tr = document.createElement("tr");
		tbody.appendChild(tr);
		td = createTd(null,"lovContainerTD",null,null,"left","top","2");
		tr.appendChild(td);
		td.appendChild(oPagePassed);
	}
	if (oData){
		tr = document.createElement("tr");
		tbody.appendChild(tr);
		td = createTd(null,"lovContainerTD",null,null,"left","top","2");
		tr.appendChild(td);
		divdata = createDiv("dvLOVData","divLOVData",null,null,null,"501");
		divdata.appendChild(oData);
		td.appendChild(divdata);
	}
	tr = document.createElement("tr");
	tbody.appendChild(tr);
	td = createTd(null,"lovContainerBottomTD",null,null,"left","bottom")
	tr.appendChild(td);
	td.appendChild(document.createTextNode(" "));

	td = createTd(null,"lovContainerBottomTD",null,null,"right","bottom");
	if (oParam.lovClearButtonReq){
		clr = createButton("lovClear","inputs","Clear","button");
		clr.onclick = function(){clearLOV(oParam)};
		td.appendChild(clr);
		td.appendChild(document.createTextNode(" "));
	}
	btn = createButton("lovClose","inputs","Close","button");
	btn.onclick = function(){closeLOV(oParam)};
	td.appendChild(btn);
	tr.appendChild(td);
	oForm.appendChild(tb);
	div.appendChild(oForm);
	_underLovDiv = createDivIframe(div);
	//if (getElById(div.id).focus) getElById(div.id).focus();
	if (oSearch)
		if (oParam.lovTextBox)
			if(oParam.lovTextBox.focus) oParam.lovTextBox.focus();
}


function processTableXML(oXML,oParam){
	var oXMLData = oXML;
	var oForm, oTableXML, oTHead, table, div;
	var tbody = null;
	var pageNode = null;
	var searchNode = null;
	var isMultiSelect = false;
	var iRowIndex = 0;
	var hasData = false;
	if (oXMLData.hasChildNodes()){
		oForm = document.createElement("form");
		oForm.method = "post";
		oForm.id = "frmLOV";
		oParam.lovform = oForm;
		oNodeList = oXMLData.childNodes;
		for(i=0;i<oNodeList.length;i++){
			if (oNodeList[i].nodeName=="table"){
				_arrDataTable = new Array();
				//isMultiSelect = (getAttribute("multiselect", oNodeList[i].attributes))?true:false;
				isMultiSelect = oParam.lovmultiselect;
				if (getAttribute("class",oNodeList[i].attributes)) _cssTb.cssTable = getAttribute("class",oNodeList[i].attributes);
				table = createTable("",_cssTb.cssTable,"0","0","0","","");
				if (oNodeList[i].hasChildNodes){
					oTableXML = oNodeList[i].childNodes;
					for(j=0;j<oTableXML.length;j++){
						if (oTableXML[j].nodeName=="error"){
							tr = document.createElement("tr");
							td = document.createElement("td");
							tr.appendChild(td);
							td.appendChild(document.createTextNode(oTableXML[j].firstChild.nodeValue));
							if (tbody==null){
								tbody = document.createElement("tbody");
								tbody.setAttribute("cellPadding","0");
							}
							tbody.appendChild(tr);
							table.appendChild(tbody);
						}
						if (oTableXML[j].nodeName=="page")
							pageNode = getPageNavigation(oTableXML[j], oParam);
						if (oTableXML[j].nodeName=="search")
							searchNode = getSearchFunctionality(oTableXML[j],oParam);
						var iCol=0;
						if (oTableXML[j].nodeName=="head"){
							_arrColTable = new Array();
							oTHead = oTableXML[j];
							if (oTHead.hasChildNodes){
								thead = document.createElement("thead");
								tr = document.createElement("tr");
								th = document.createElement("th");
								th.className = _cssTb.cssHead;
								th.appendChild(document.createTextNode(" "));
								tr.appendChild(th);
								var arrcol;
								iCol=0;
								for(k=0;k<oTHead.childNodes.length;k++){
									if (oTHead.childNodes[k].nodeType!=1) continue;
										sField = getAttribute("field",oTHead.childNodes[k].attributes);
										arrcol = new Array(true,sField);
										//Check for hidden fields
										if((","+oParam.lovhidecols+",").indexOf(","+iCol+",")==-1){
											thClass = (getAttribute("class",oTHead.childNodes[k].attributes))?getAttribute("class",oTHead.childNodes[k].attributes):_cssTb.cssHead;
											th = createTd(null,thClass,null,null,null,null,null,null,"nowrap","th")
											//Check for sort fields
											if((oParam.lovsortfileds+",").indexOf(iCol+",")>=0){
												//Create sort links
												lnksort = createLink("srtcol"+iCol,_cssTb.cssColumnLink,oTHead.childNodes[k].firstChild.nodeValue,_property.lovSortLinkToolTip,null);
												lnksort.onclick = function(){setSortFieldColumn(oParam,this);};
												if (oParam.lovsortfld==sField){
													img = createImage(null,((oParam.lovsortasc)?'images/arrow-up.gif':'images/arrow-down.gif'),"0",null,null);
													lnksort.appendChild(img);
												}
												th.appendChild(lnksort);
											}
											else
												th.appendChild(document.createTextNode(oTHead.childNodes[k].firstChild.nodeValue));

											tr.appendChild(th);
											_arrColTable[_arrColTable.length] = arrcol;
										}
										iCol++;
								}
								thead.appendChild(tr);
								table.appendChild(thead);
							}
						}
						if (oTableXML[j].nodeName=="row"){
							hasData = true;
							oTData = oTableXML[j];
							if (oTData.hasChildNodes){
								if (tbody==null){
									tbody = document.createElement("tbody");
									tbody.setAttribute("cellPadding","0");
								}
								iRowIndex++;
								var rowClass = (getAttribute("class",oTableXML[j].attributes))?getAttribute("class",oTableXML[j].attributes):(iRowIndex%2==0)?_cssTb.cssRowAlt:_cssTb.cssRow;
								tr = createTr(null,rowClass,null,null,null,null,null,null);
								tr.onmouseout=function(){setRowMouseOut(this)};
								tr.onmouseover=function(){setRowMouseOver(this)};
								//td = document.createElement("td");
								td = createTd(null,((iRowIndex%2==0)?_cssTb.cssRowAltData:_cssTb.cssRowData),"5",null,"cnter","top");
								//td.className = (iRowIndex%2==0)?_cssTb.cssRowAlt:_cssTb.cssRow;
								if( _bw.ie )
									control = document.createElement("<input type="+((isMultiSelect)?"checkbox":"radio")+" name="+((isMultiSelect)?"chkData":"rdoData")+" id="+((isMultiSelect)?"chkData":"rdoData")+" >");
								else{
									control = document.createElement("input");
									control.setAttribute("type",((isMultiSelect)?"checkbox":"radio"));
									control.setAttribute("name",((isMultiSelect)?"chkData":"rdoData"));
									control.setAttribute("id",((isMultiSelect)?"chkData":"rdoData"));
								}
								control.className = "lovControl";
								td.appendChild(control);
								tr.appendChild(td);
								var arrData = new Array();
								iCol=0;
								for(l=0;l<oTData.childNodes.length;l++){
									if (oTData.childNodes[l].nodeType!=1) continue;
									//Check for hidden fields
									if((","+oParam.lovhidecols+",").indexOf(","+iCol+",")==-1){
										td = createTd(null,((iRowIndex%2==0)?_cssTb.cssRowAltData:_cssTb.cssRowData),null,null,null,null,null,null,"nowrap");
										//comenting the existing code and adding new line to avoid error when oTData.childNodes[l].firstChild is null .Bug fix for Address Lov in booking and HAWB pages.
										//var data = oTData.childNodes[l].firstChild.nodeValue;
										var data = (oTData.childNodes[l].firstChild!=null)?oTData.childNodes[l].firstChild.nodeValue:"null";
										td.appendChild(document.createTextNode(((data!="null")?data:" ")));
										tr.appendChild(td);
									}
									iCol++;
									//comenting the existing code and adding new line to avoid error when oTData.childNodes[l].firstChild is null .Bug fix for Address Lov in booking and HAWB pages.
									//var dataval = oTData.childNodes[l].firstChild.nodeValue;
									var dataval = (oTData.childNodes[l].firstChild!=null)?oTData.childNodes[l].firstChild.nodeValue:"null";
									arrData[arrData.length] = (dataval=="null")?"":dataval;
								}
								control.onclick = (isMultiSelect)? function(){setSelectedRow(this);lov_dataProcess(oParam,this);}:function(){setSelectedRow(this);lov_dataProcess(oParam,this);if (oParam.lovClose) closeLOV(oParam);};
								iPos = _arrDataTable.length;
								control.setAttribute("value",iPos);
								_arrDataTable[_arrDataTable.length] = arrData;
								tbody.appendChild(tr);
							}
						}
					}
				}
				if (tbody) table.appendChild(tbody);
				if (!hasData){
					//table = getNoRecordsMessage();
				}
			}
		}
	}
	if(oParam.lovfldchange){
		if(_isLov)	{
			displayLOVTable(null,null,null,oParam,false);
			displayLOVTable(searchNode,table,pageNode,oParam,false,hasData);
		}
	}
	else{//single call
		if(_arrDataTable.length==1){
			lov_dataProcess(oParam,null,0);
		}
		else{
			if((oParam.lovdisplaySingle)&&(_arrDataTable.length>1)){
				displayLOVTable(searchNode,table,pageNode,oParam,false,hasData);
			}
			else{
				if(_arrDataTable.length==0){
					try{
						eval(oParam.lovcomponentId+"_nodataFound(oParam);");
					}catch(e){}
				}
			}
		}
	}
}

//Function to return no records message
function getNoRecordsMessage(){
	var table = createTable(null,"panelError","0","0","0","100%","100%");
	tbody = document.createElement("tbody");
	table.appendChild(tbody);
	tr = document.createElement("tr");
	tbody.appendChild(tr);
	td = createTd(null,null,"2%","10",null,null,null,null);
	tr.appendChild(td);
	td = createTd(null,null,"98%","10",null,null,null,null);
	tr.appendChild(td);
	tr = document.createElement("tr");
	tbody.appendChild(tr);
	td = createTd(null,"txtbig",null,null,null,null,null,null);
	td.appendChild(document.createTextNode(" "));
	tr.appendChild(td);
	td = createTd(null,"txtbig",null,null,"center",null,null,null);
	td.appendChild(document.createTextNode("Sorry no records found!"));
	tr.appendChild(td);
	return table;
}

//Function to get Processing message
function getProcessingMsg(){
	var table = createTable(null,null,"0","0","0","475","241");
	tbody = document.createElement("tbody");
	table.appendChild(tbody);
	tr = document.createElement("tr");
	tbody.appendChild(tr);
	td = createTd(null,"processMessage","475","241","center","middle",null,null);
	tr.appendChild(td);
	td.appendChild(document.createTextNode(_property.processingMessage));
	return table;
}

//Function to display/hide processing message
var _divProcessing = null;
var _underdivProcessing = null;
function getProcessingMessage(oParam){
	if (_divProcessing==null){
		div = createDiv("dvProcess","divProcess","absolute","200","200","600");
		_divProcessing = div;
		document.body.appendChild(_divProcessing);
		table = createTable(null,null,"0","0","0","100%","100%");
		table.onmousedown = function(event){dragStart(event,_divProcessing,_underdivProcessing);};
		tbody = document.createElement("tbody");
		table.appendChild(tbody);
		tr = document.createElement("tr");
		tbody.appendChild(tr);
		td = document.createElement("td");
		tr.appendChild(td);
		td.className = "processMessage";
		td.setAttribute("align","center");
		td.setAttribute("valign","middle");
		td.appendChild(document.createTextNode(_property.processingMessage));
		div.appendChild(table);
   	_underdivProcessing = createDivIframe(div);
	}
	else{
		if (getElById(_divProcessing.id)) document.body.removeChild(getElById(_divProcessing.id));
		_divProcessing = null;
		if(_underdivProcessing) _underdivProcessing.removeNode(true);
	}
}

//Function to close lov
function closeLOV(oParam){
	if(_lovDiv) getElById(_lovDiv.id).style.visibility = "hidden";
	if(_underLovDiv) _underLovDiv.removeNode(true);
	oParam.lovpage = 1;
	oParam.lovform = null;
	oParam.lovsortfld = "";
	oParam.lovsearchfld = null;
	oParam.lovsearchval = "";
	try{
		eval(oParam.lovcomponentId+"_onLovClose();");
	}catch(e){}
	_xposition=0;
	_yposition=0;
	_isLov = false;
}

//Function to clear assigned lov data
function clearLOV(oParam){
	try{
		eval("_"+oParam.lovcomponentId+"_clearData();");
		closeLOV(oParam);
	}catch(e){} 
}

/*-------------LOV calling related functions - End----------------*/

/*------------LOV Heading - Start-----------------------------------*/
function getLovHeading(oParam){
	var img;
	table = createTable("",_cssTb.cssTitle,"0","0","0","100%","");
	table.onmousedown = function(event){dragStart(event,_lovDiv,_underLovDiv);};
	tbody = document.createElement("tbody");
	table.appendChild(tbody);
	tr = document.createElement("tr");
	tbody.appendChild(tr);
	td = createTd(null,null,"95%",null,"left",null,null,null);
	tr.appendChild(td);
	td.appendChild(document.createTextNode(oParam.lovTitle));
	td = createTd(null,null,"5%",null,"right",null,null,null);
	tr.appendChild(td);
	img = createImage(null,'images/ico_close.gif',"0",null,null);
	/*if( _bw.ie )
		img = document.createElement("<img src='images/ico_close.gif' border='0'>");
	else{
		img = document.createElement("img");
		img.setAttribute("src","images/ico_close.gif");
		img.setAttribute("border","0");
	}*/
	link = createLink("","","",_property.lovClose + " - ("+oParam.lovTitle+")","");
	link.appendChild(img);
	link.onclick = function(){closeLOV(oParam)};
	td.appendChild(link);
	return table;
}
/*------------LOV Heading - End-----------------------------------*/

/*------------LOV Search functionality related functions - Start -------------*/
function doLovOnfocus(oParam, arrDataType){
	var sVal = replaceSpacesObject(oParam.lovform.txtSearch,true);
	if ((sVal!="")&&(oParam.lovform.lstSearch.options.selectedIndex==0)){
		oParam.lovform.lstSearch.options.selectedIndex = 1;
	}
	var sDataType = arrDataType[oParam.lovform.lstSearch.options.selectedIndex];
	onFocus_FieldClassChange(oParam.lovform.txtSearch,sDataType);
}
//Function to call when onblur happens
function doLovOnblur(oParam, arrDataType){
	var sVal = replaceSpacesObject(oParam.lovform.txtSearch,true);
	if ((sVal!="")&&(oParam.lovform.lstSearch.options.selectedIndex==0)){
		oParam.lovform.lstSearch.options.selectedIndex = 1;
	}
	var sDataType = arrDataType[oParam.lovform.lstSearch.options.selectedIndex];
	onBlur_FieldClassChange(oParam.lovform.txtSearch,sDataType);
}
//Function to do lov data entry validation
function doLovDataValidate(oParam, arrDataType){
	var sVal = replaceSpacesObject(oParam.lovform.txtSearch,true);
	if ((sVal!="")&&(oParam.lovform.lstSearch.options.selectedIndex==0)){
		oParam.lovform.lstSearch.options.selectedIndex = 1;
	}
	var sDataType = arrDataType[oParam.lovform.lstSearch.options.selectedIndex];
/*	if (!validateDataType(sDataType,sVal)){
		alert(getDataTypeDesc(sDataType));
		return;
	}*/
	oParam.lovsearchfld = oParam.lovform.lstSearch.options[oParam.lovform.lstSearch.options.selectedIndex].value;
	oParam.lovsearchval = sVal;
	getLOV(oParam);
}

//Function to create search functionality related node
function getSearchFunctionality(oNode,oParam){
	if (!oNode) return null;
	var arrDataType = new Array();
	var txt,btn,checked;
	table = document.createElement("table");
	tbody = document.createElement("tbody");
	table.appendChild(tbody);
	tr = document.createElement("tr");
	tbody.appendChild(tr);
	td = document.createElement("td");
	tr.appendChild(td);
	txt = createTextBox("txtSearch",_cssTb.cssSearchText,oParam.lovsearchval,15,null,null,_property.lovSearchTextToolTip);
	btn = createButton("btnSearch",_cssTb.cssSearchBtn,_property.lovSearchButtonValue,null);
	select = createSelect("lstSearch",_cssTb.cssSearchList,_property.lovSearchFieldTextToolTip);

	td.appendChild(select);
	opt = createOption("", _property.lovSearchFieldText);
	select.appendChild(opt);
	arrDataType[arrDataType.length] = "";
	if (oNode.hasChildNodes){
		for(i=0;i<oNode.childNodes.length;i++){
			if (oNode.childNodes[i].nodeType!=1) continue;
			if ((oParam.lovsearchfld==""||oParam.lovsearchfld==null )&& oParam.lovsearchval!="")
				oParam.lovsearchfld = getAttribute("field", oNode.childNodes[i].attributes);
			if (oParam.lovsearchfld==getAttribute("field", oNode.childNodes[i].attributes))
				checked = true;
			else checked = false;
			opt = createOption(getAttribute("field", oNode.childNodes[i].attributes), oNode.childNodes[i].firstChild.nodeValue,checked);
			select.appendChild(opt);
			arrDataType[arrDataType.length] = getAttribute("dataType", oNode.childNodes[i].attributes);
		}
	}
	txt.onblur = function(){doLovOnblur(oParam, arrDataType);};
	txt.onfocus = function(){doLovOnfocus(oParam, arrDataType);};
	td.appendChild(txt);
	td.appendChild(document.createTextNode(" "));
	btn.onclick = function(){oParam.lovpage=1;doLovDataValidate(oParam, arrDataType);};
	txt.onkeydown = function (e,btn) {
		if (e == null) e = document.parentWindow.event;
		var kc = e.keyCode != null ? e.keyCode : e.charCode;
		if(kc == 13) {
			doLovOnblur(oParam, arrDataType);
			oParam.lovpage=1;
			doLovDataValidate(oParam, arrDataType);
			return false;
		}
		return true;	
	}
	td.appendChild(btn);
	oParam.lovTextBox = txt;
	return table;
}

/*------------LOV Search functionality related functions - End -------------*/

/*------------Page Navigation related functions - Start----------------------*/
//Function to create page navigation node
function getPageNavigation(oNode,oParam){
	var iPgCount=0;
	var iCurPg=0;
	var iRecCount = 0;
	var hasData = false;
	//if (!oNode) return null;
	if (oNode){
		oParam.lovpage = parseFloat(getAttribute("currentPage", oNode.attributes));
		iPgCount = parseFloat(getAttribute("pageCount", oNode.attributes));
		iRecCount = parseFloat(getAttribute("recordCount", oNode.attributes));
		hasData = true;
		iCurPg = oParam.lovpage;
	}

		var tbl = createTable(null,"lovNavigationTable","0","0","0","476px",null,null,null);
		prnttbody = document.createElement("tbody");
		tbl.appendChild(prnttbody);
		prnttr = document.createElement("tr");
		prnttbody.appendChild(prnttr);
		prnttd = createTd(null,null,"50%",null,"left","middle",null,null,null,null);
		prnttr.appendChild(prnttd);
		prnttd.appendChild(document.createTextNode(_property.lovRecordLeftMsg+iRecCount+_property.lovRecordRightMsg));

		prntrttd = createTd(null,null,"50%",null,"right","middle",null,null,null,null);
		prnttr.appendChild(prntrttd);

		table = document.createElement("table");
		prntrttd.appendChild(table);

		tbody = document.createElement("tbody");
		table.appendChild(tbody);
		tr = document.createElement("tr");
		tbody.appendChild(tr);
		td = document.createElement("td");
		tr.appendChild(td);
		var hasLft = (iCurPg>1)?true:false;
		var hasRgt = ((iCurPg>0)&&(iCurPg<iPgCount))?true:false;
		td.appendChild(document.createTextNode(_property.lovPageLeftMsg+iCurPg+_property.lovPageMidMsg+iPgCount));
		tdimg = document.createElement("td");
		tr.appendChild(tdimg);
		var imglftLnk = (hasLft)?td.appendChild(createPageLink((iCurPg-1),oParam,true)):createPageNavImage(true);
		tdimg.appendChild(imglftLnk);
		tdimg.appendChild(document.createTextNode(" "));
		var imgRgtLnk = (hasRgt)?td.appendChild(createPageLink((iCurPg+1),oParam,false)):createPageNavImage(false);
		tdimg.appendChild(imgRgtLnk);

		tdtxt = document.createElement("td");
		tr.appendChild(tdtxt);
		var tex = createPageTextBox(iCurPg,iPgCount);
		if(!hasData) tex.readOnly = true;
		tdtxt.appendChild(tex);
		tdbtn = document.createElement("td");
		tr.appendChild(tdbtn);
		var butt = createPageButton(oParam);
		if(!hasData) butt.disabled = true;
		tdbtn.appendChild(butt);
		return tbl;

}

//Function to create the page submit button
function createPageButton(oParam){
	var btn = createButton("btnPage",_cssTb.cssPageBtn,_property.lovPageButtonValue,null,"width:68px;");
	btn.onclick = function(){doLovPageSubmit(oParam, "");};
	return btn;
}

//Function to create previous button
function createPageNavImage(isPrev){
	var imgsrc = (isPrev)?"images/bk_act.gif":"images/nxt_act.gif";
	var imgid = (isPrev)? "imgPnPre":"imgPnNxt";
	var img = createImage(imgid,imgsrc,"0","16","16",null);
	return img;
}


//Function to create the page text box
function createPageTextBox(iCurr,iPgCount){
	var txt;
	var sLen = (iPgCount+"").length;
	return createTextBox("txtPage",_cssTb.cssPageTxt,iCurr,null,sLen,"width:25px;",_property.lovPageTextToolTip);
}

//Function to create a page link
function createPageLink(iPgno,oParam,isPrev){
	var lnk = createLink("",_cssTb.cssPageLnk,null,(_property.lovPageLinkToolTip + " " + iPgno),null,createPageNavImage(isPrev));
	lnk.onclick = function(){doLovPageSubmit(oParam, iPgno);};
	return lnk;
}

//Function to do lov page submit
function doLovPageSubmit(oParam, iCurPg){
	if (iCurPg!="") oParam.lovpage = iCurPg;
	else{
		oParam.lovpage = oParam.lovform.txtPage.value;
	}
	getLOV(oParam);
}
/*------------Page Navigation related functions - End----------------------*/

//------------------------AJAX related code - Start---------------------------------//

var _ms_XMLHttpRequest_ActiveX = ""; // Holds type of ActiveX to instantiate
var _ajax;                           // Reference to a global XMLHTTPRequest object

if (!window.Node || !window.Node.ELEMENT_NODE) {
    var Node = { ELEMENT_NODE: 1, ATTRIBUTE_NODE: 2, TEXT_NODE: 3, CDATA_SECTION_NODE: 4, ENTITY_REFERENCE_NODE: 5,
                  ENTITY_NODE: 6, PROCESSING_INSTRUCTION_NODE: 7, COMMENT_NODE: 8, DOCUMENT_NODE: 9, DOCUMENT_TYPE_NODE: 10,
    		  DOCUMENT_FRAGMENT_NODE: 11, NOTATION_NODE: 12 };
}

//Function to check whether the remote script objects are available
function checkAJAX(){
	return ((window.XMLHttpRequest)||(window.ActiveXObject))?true:false;
}

// The method checks the actual # of arguments -- returns a single object or an array
function $() {
    var elements = new Array();
    for (var i = 0; i < arguments.length; i++) {
        var element = arguments[i];
        if (typeof element == 'string')
            element = document.getElementById(element);
        if (arguments.length == 1)
            return element;
        elements.push(element);
    }
    return elements;
}

// If you plan on doing anything outside of North America, then you'd better encode the things you pass back and forth
// the escape() method in Javascript is deprecated -- should use encodeURIComponent if available
function encode( uri ) {
    if (encodeURIComponent)
        return encodeURIComponent(uri);
    if (escape)
        return escape(uri);
}

function decode( uri ) {
    uri = uri.replace(/\+/g, ' ');
    if (decodeURIComponent)
        return decodeURIComponent(uri);
    if (unescape)
        return unescape(uri);
    return uri;
}

/*
 * AJAXRequest: An encapsulated AJAX request. To run, call
 * new AJAXRequest( method, url, async, process, data )
 *
 */
function AJAXRequest( method, url, data, process, async, dosend) {
    // self = this; creates a pointer to the current function
    // the pointer will be used to create a "closure". A closure
    // allows a subordinate function to contain an object reference to the
    // calling function. We can't just use "this" because in our anonymous
    // function later, "this" will refer to the object that calls the function
    // during runtime, not the AJAXRequest function that is declaring the function

    var self = this;

    // check the dom to see if this is IE or not
    if (window.XMLHttpRequest) {
	// Not IE
        self.AJAX = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
	// Hello IE!
        // Instantiate the latest MS ActiveX Objects
        if (_ms_XMLHttpRequest_ActiveX) {
            self.AJAX = new ActiveXObject(_ms_XMLHttpRequest_ActiveX);
        } else {
	    // loops through the various versions of XMLHTTP to ensure we're using the latest
	    var versions = ["Msxml2.XMLHTTP.7.0", "Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP",
                        "Microsoft.XMLHTTP"];

            for (var i = 0; i < versions.length ; i++) {
                try {
		    // try to create the object
		    // if it doesn't work, we'll try again
		    // if it does work, we'll save a reference to the proper one to speed up future instantiations
                    self.AJAX = new ActiveXObject(versions[i]);
                    if (self.AJAX) {
                        _ms_XMLHttpRequest_ActiveX = versions[i];
                        break;
                    }
                }
                catch (objException) {
                // trap; try next one
                }
            }
        }
    }

    // if no callback process is specified, then assing a default which executes the code returned by the server
    if (typeof process == 'undefined' || process == null) {
        process = new Array(executeReturn);
    }
	if (typeof process == 'object')
		self.process = process[0]; //process;
	else
		self.process = process;

    // create an anonymous function to log state changes
    self.AJAX.onreadystatechange = function( ) {
	    if (process.length==2)
				self.process(self.AJAX,process[1]);
			else
				self.process(self.AJAX);
    }

    // if no method specified, then default to POST
    if (!method) {
        method = "POST";
    }
    method = method.toUpperCase();
    if (typeof async == 'undefined' || async == null) {
        async = true;
    }
    self.AJAX.open(method, url, async);
    if (method == "POST") {
        self.AJAX.setRequestHeader("Connection", "close");
        self.AJAX.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        self.AJAX.setRequestHeader("Method", "POST " + url + "HTTP/1.1");
    }

    // if dosend is true or undefined, send the request
    // only fails is dosend is false
    // you'd do this to set special request headers
    if ( dosend || typeof dosend == 'undefined' ) {
	    self.AJAX.send(data);
    }
    return self.AJAX;
}

//Function to handle default fallback process.
function executeReturn( AJAX ) {
    if (AJAX.readyState == 4)
        if (AJAX.status == 200)
            eval(AJAX.responseText);
}

// build a string containing every field on the passed form
// skip disabled controls
function getFormValues( form ) {
    form = $(form);
    var field = "";
    var value = "";
    var valueString = "";
    var replaceID = "";
    var parentNode = form.parentNode;
    for (var i = 0; i < form.elements.length; i++) {
        var field = form.elements[i];
        if (!field.disabled) {
            filedName = encode(field.name);
            if (field.type == 'select-one') {
                if (field.selectedIndex > -1) {
                    value = field.options[field.selectedIndex].value;
                }
            } else {
                value = field.value;
            }
            valueString += ((i) ? '&' : '') + field.name + '=' + encode(value);
        }
    }
    return valueString;
}
//------------------------AJAX related code - End-----------------------------------//


function ScreenPoint(iX, iY)
{
   this.x = iX;
   this.y = iY;
}

//Function to create table style
function table_style(){
	this.cssTable = "grdLOV";
	this.cssHead = "grdHead";
	this.cssRowData = "lovgrdRow";
	this.cssRowAltData = "lovgrdRowAlt";
	this.cssRow = "lovgrdRowData";
	this.cssRowAlt = "lovgrdRowAltData";
	this.cssPageLnk = "pageLink";
	this.cssPageSelectedLnk = "pageSelectedLink";
	this.cssPageBtn = "input";
	this.cssPageTxt = "inputs";
	this.cssSearchList = "inputs";
	this.cssSearchText = "inputs";
	this.cssSearchBtn = "input";
	this.cssTitle = "lovTitle";
	this.cssColumnLink = "linklovColumn";
}