


var g_formPath = ""

function showAttachmentWindow(formName,index)
{
	var height = 500
	var width = 650
	var top = (screen.height-height)/2;
	var left = (screen.width-width)/2;
	var theWin = (!window.opener) ? window.top.title : window.opener.top.title
	window.g_myNewWin = window.open(theWin.g_app_path+"1101_attachmentPopup.asp?index="+index+"&formName="+formName,'','height=' + height + ',width=' + width + ',top=' + top + ',left=' + left + ',scrollbars=1,resizable=no,status=no,toolbar=no,menubar=no,location=no')

}

function fml_getWebsiteMode(thisType)
{
	var s = document.all.OfflineFormPath
	//var inputObj = s.all[0]
	var inputObj = document.all.id_338_tp_7
	
	if (thisType.value=='Online')
	{
		s.style.display = "none"
		g_formPath = inputObj.value
		inputObj.value=""
		inputObj.onblur()
	}	else
	{
		s.style.display = "inline"
		inputObj.value=g_formPath
		inputObj.onblur()
	}	
	if (inputObj.value.indexOf("\\")!=-1)
	{
		inputObj.value = inputObj.value.replace(/\\/ig,"/")
	}

}

function loadScriptXSL(xObj, xmlname)
{
	df_loadXML(xObj, xmlname);
	mergeXML(xObj, window.top.frames.title.g_dfScripts_xsl, "xsl:stylesheet", "/xsl:stylesheet/msxsl:script", false);
	mergeXML(xObj, window.top.frames.title.g_dfTemplates_xsl, "xsl:stylesheet", "/xsl:stylesheet/xsl:decimal-format", false);
	mergeXML(xObj, window.top.frames.title.g_dfTemplates_xsl, "xsl:stylesheet", "/xsl:stylesheet/xsl:template", false);
	mergeXML(xObj, window.top.frames.title.g_dfTemplates_xsl, "xsl:stylesheet", "/xsl:stylesheet/xsl:variable", false);
}

/********************
Merge XML functions
********************/
function mergeClientXML()
{
	var tmp_xml = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
	var tmp_xml_str = window.top.frames.title.g_cln_xml.xml;
	tmp_xml_str = tmp_xml_str.replace(/<r k=/g, "<r_cln k=");
	tmp_xml_str = tmp_xml_str.replace(/<\/r>/g, "</r_cln>");
	df_loadXML(tmp_xml, tmp_xml_str);
	mergeXML(g_my_xml, tmp_xml, "/d", "/d/r_cln", true);
}

function mergeAgentXML()
{
	var tmp_xml = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
	var tmp_xml_str = window.top.frames.title.g_user_xml.xml;
	tmp_xml_str = tmp_xml_str.replace(/<r k=/g, "<r_agt k=");
	tmp_xml_str = tmp_xml_str.replace(/<\/r>/g, "</r_agt>");
	df_loadXML(tmp_xml, tmp_xml_str);
	mergeXML(g_my_xml, tmp_xml, "/d", "/d/r_agt", true);
//	window.top.frames.title.EmailFooter.innerHTML = df_transform(g_my_xml, window.top.frames.title.g_emailfooter_xsl);
}

function mergePDFMapXML()
{
	var tmp_xml = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
	df_loadXML(tmp_xml, window.top.frames.title.g_app_path + "dataFloat/dfDatabases/"+window.top.frames.title.g_dbname+"/pdfmap.xml");
	mergeXML(g_my_xml, tmp_xml, "/d", "/d/pdf", true);
}

/********************
Window functions
********************/
function document.onclick()
{
	if (document.all.CalFrame) document.all.CalFrame.style.display="none";
}

function highlight(checked,trId){
	var n = parseInt(trId.split("_")[1])% 2
	var theClassName = (n==1) ? "trOdd" : "trEven"
	if (checked) document.all(trId).className = "trHighLight"
	else document.all(trId).className = theClassName
}

function openHelp(target)
{
	window.open(target, 'asd','menubar=yes, resizable=yes, width=800, height=500, scrollbars=yes')
}

function maxWin(theWin)
{
	if (theWin==null || theWin=='') theWin = window;
	theWin.moveTo(0,0);
	theWin.resizeTo(screen.availWidth, screen.availHeight);
}

function openPDFForms(target)
{
	maxWin(window.open(target, null, 'location=no,titlebar=no,status=no,menubar=no,resizable=no,scrollbars=no'));
}

function StartPage_continue()
{
	var R1 = document.all("R1")
	for(var i=0;i<R1.length;i++)
	{
		if (R1[i].checked == true)
		{
			document.location = R1[i].value;
			return;
		}
	}
}

function popup_processed()
{

	var processed_win_url = window.top.frames.title.g_app_path + "FMLS_processed.htm";
	var height = 210;
	var width = 420;
	showModalDialog(processed_win_url,
		window, "help:no;edge:sunken;scroll:no;center:1;status:0;dialogWidth:" + width + "px;dialogHeight:" + height + "px");
}

function initTitle()
{
	if (!window.g_dbname) return;
		df_loadXML(g_meta_xml, "dataFloat/dfDatabases/" + g_dbname + "/meta_" + g_locale +".xml");
		
		g_meta_xml.selectSingleNode("/d/fld[@key='274']").setAttribute("req", "0");

		var param_xml = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
		df_loadXML(param_xml, "<param loc_host='" + window.top.location.host + "' app_path='" + g_app_path 
			+ "' masterdbname='" + g_masterdbname + "' dbname='" + g_dbname 
			+ "' agt_rtype='" + g_agt_rtype + "' cln_rtype='" + g_cln_rtype + "' lst_rtype='" + g_lst_rtype 
			+ "' trn_rtype='" + g_trn_rtype + "' trs_key='" + g_trs_key
			+ "' locale='" + g_locale + "' userkey='" + g_userkey + "' username='" + g_username + "'/>");
		mergeXML(g_meta_xml, param_xml, "/d", "/param", true);

		var xf_xml = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");				
		df_loadXML(xf_xml, "dataFloat/dfDatabases/" + g_dbname + "/xslfilelist.xml");				
		
		mergeXML(g_meta_xml, xf_xml, "/d", "/d/xf", true);
		mergeXML(g_meta_xml, xf_xml, "/d", "/d/xf_grp", true);
		
		
		//alert(window.top.frames.title.g_customFORMS)
		if(window.top.frames.title.g_customFORMS!='')
		{
			var xf_xml_custom = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
			df_loadXML(xf_xml_custom, "dataFloat/dfDatabases/" + g_dbname + "/"+window.top.frames.title.g_customFORMS+"_xslfilelist.xml");
			mergeXML(g_meta_xml, xf_xml_custom, "/d", "/d/xf_grp", true);
		}
		
		
		df_loadXML(g_email_xml, "dataFloat/dfDatabases/" + g_dbname + "/email.xml");
		mergeXML(g_meta_xml, g_email_xml, "/d", "/d/email", true);
	

		//df_loadXML(g_user_xml, "dataFloat/xmlcache/u_" + g_userkey + "_" + g_locale + ".xml");
		//df_loadXML(g_cln_xml, "dataFloat/xmlcache/" + g_userkey + "_" + g_dbname + "_cln_" + g_locale + ".xml");
		//df_loadXML(g_cfg_xml, "dataFloat/xmlcache/" + g_userkey + "_" + g_dbname + "_cfg.xml");
		df_loadXML(g_user_xml, "dataFloat/xmlcache/" + g_XMLCacheSubfolder + "u_" + g_userkey + "_" + g_locale + ".xml");
		df_loadXML(g_cln_xml, "dataFloat/xmlcache/" + g_XMLCacheSubfolder + g_userkey + "_" + g_dbname + "_cln_" + g_locale + ".xml");
		df_loadXML(g_cfg_xml, "dataFloat/xmlcache/" + g_XMLCacheSubfolder + g_userkey + "_" + g_dbname + "_cfg.xml");
		
		var tmp_xml = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
		//df_loadXML(tmp_xml, "dataFloat/xmlcache/" + g_userkey + "_ts.xml");
		df_loadXML(tmp_xml, "dataFloat/xmlcache/" + g_XMLCacheSubfolder + g_userkey + "_ts.xml");		
		g_cfg_ts = tmp_xml.selectSingleNode('/d').getAttribute('ts');

}

function initStart()
{
	var xObjs = document.all("R1");
	for (var i = 0; i < xObjs.length; i++)
		xObjs[i].checked = false;
}

function initAgent()
{
	df_loadXML(g_my_xml, window.top.frames.title.g_meta_xml.xml);
	mergeXML(g_my_xml, window.top.frames.title.g_user_xml, "/d", "/d/r", true);
	is_staticsql= (g_my_xml.selectSingleNode("/d/rt[@key='"+g_rtype+"']").getAttribute("stc")=='1')
	g_my_xml.selectSingleNode("/d/param").setAttribute("rtype", g_rtype);
	g_my_xml.selectSingleNode("/d/param").setAttribute("stype", g_stype);
	g_my_xml.selectSingleNode("/d/param").setAttribute("userkey", g_userkey);
	loadScriptXSL(g_agt_xsl, "appStylesheets/0801_agent_edit.xsl");
	AgentDiv.innerHTML = df_transform(g_my_xml, g_agt_xsl);
	loadData(DataEntryForm);
}

function ProcessCheckingPassword()
{
		if (document.all("password").value != document.all("password2").value)
		{
			document.all("password2").style.backgroundColor = "red"	
			g_redField["password"] = "true"
		}
		else 	
		{
			g_redField["password"] = "false"
		}	
	
		if (g_userkey == "-1"){
			if (document.all("password").value=='')
			{
				document.all("password").style.backgroundColor = "red"	
				g_redField["password"] = "true"
			}
		}
}
function generateUserPasswordSQL()
{
	var str = ''
	if (document.all('password').value!='') str = "update fusers set password = '"+document.all("password").value+"' where userkey ="+g_userkey
	return str
}

function changeBackGroundColor(thisType)
{
	thisType.style.backgroundColor = "white"
}

function initClient()
{
	df_loadXML(g_my_xml, window.top.frames.title.g_meta_xml.xml);
	mergeXML(g_my_xml, window.top.frames.title.g_cln_xml, "/d", "/d/r", true);
	mergeXML(g_my_xml, window.top.frames.title.g_cfg_xml, "/d", "/d/cfg[@k='" + window.top.frames.title.g_trs_key + "']", true);
	is_staticsql= (g_my_xml.selectSingleNode("/d/rt[@key='"+g_rtype+"']").getAttribute("stc")=='1')
	g_my_xml.selectSingleNode("/d/param").setAttribute("rtype", g_rtype);
	g_my_xml.selectSingleNode("/d/param").setAttribute("stype", g_stype);
	loadScriptXSL(g_sch_cln_xsl, "appStylesheets/0401_clients_sch.xsl");	
	loadScriptXSL(g_cln_xsl, "appStylesheets/0401_clients.xsl");	
	SchClnDiv.innerHTML = df_transform(g_my_xml, g_sch_cln_xsl);	
	ClientDiv.innerHTML = df_transform(g_my_xml, g_cln_xsl);	
	if (g_newclnkey != '') newTransaction(g_newclnkey);
}

function showClient(xpath)
{
	if (xpath != "") xpath = "[" + xpath + "]";
	g_cln_xsl.selectSingleNode("//xsl:variable[@name='TheClients']").setAttribute("select", "/d/r" + xpath);
	ClientDiv.innerHTML = df_transform(g_my_xml, g_cln_xsl);
}

function initClientEdit()
{
	df_loadXML(g_my_xml, window.top.frames.title.g_meta_xml.xml);
	g_my_xml.selectSingleNode("/d/param").setAttribute("rtype", g_rtype);
	g_my_xml.selectSingleNode("/d/param").setAttribute("stype", g_stype);
	if (g_clnkey == "")
		g_my_xml.selectSingleNode("/d/param").setAttribute("clnkey", g_new_guid);
	else
		g_my_xml.selectSingleNode("/d/param").setAttribute("clnkey", "");

	mergeXML(g_my_xml, window.top.frames.title.g_cln_xml, "/d", "/d/r[@k='" + g_clnkey + "']", true);

	loadScriptXSL(g_cln_edt_xsl, "appStylesheets/0403_client_edit.xsl");
	ClientEditDiv.innerHTML = df_transform(g_my_xml, g_cln_edt_xsl);
	loadData(DataEntryForm);
	
}

function processClientContract(action,configValue,nameInput,rec_key)
{
	if (!window.confirm("'" + nameInput + "' will be deleted, continue?")) return;
	//********ConfigForm.SQLQuery.value = "delete fconfigs where userkey=" + window.top.frames.title.g_userkey + " and ConfigKEY = " + window.top.frames.title.g_trs_key + " and ConfigValue=" + configValue
	//ConfigForm.SQLQuery.value = "delete fconfigs3 where userkey=" + window.top.frames.title.g_userkey + " and ConfigKEY = " + window.top.frames.title.g_trs_key + " and ConfigValue=" + configValue
	ConfigForm.SQLQuery.value = "update fconfigs3 set deleted = 1 where userkey=" + window.top.frames.title.g_userkey + " and ConfigKEY = " + window.top.frames.title.g_trs_key + " and ConfigValue=" + configValue
	ConfigForm.submit();
}

function initTransaction()
{
	df_loadXML(g_my_xml, window.top.frames.title.g_meta_xml.xml);
	mergeXML(g_my_xml, window.top.frames.title.g_cln_xml, "/d", "/d/r", true); ////**********************
	mergeXML(g_my_xml, window.top.frames.title.g_cfg_xml, "/d", "/d/cfg[@k='" + window.top.frames.title.g_trs_key + "']", true);
	mergeAgentXML();
	mergeClientXML();
	g_my_xml.selectSingleNode("/d/param").setAttribute("clnkey", g_clnkey);
	loadScriptXSL(g_sch_trn_xsl, "appStylesheets/1101_transc_sch.xsl");
	loadScriptXSL(g_trn_xsl, "appStylesheets/1101_transactions.xsl");
	TransFilterDiv.innerHTML = df_transform(g_my_xml, g_sch_trn_xsl);
	TransactionDiv.innerHTML = df_transform(g_my_xml, g_trn_xsl);
}

function getTransXpath()
{
	var xPath = ""
	var t = document.all.TransInput;
	if (t.value	== "") return xPath;
	xPath = "contains(translate(d/r/@nam, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'),'" + t.value.toUpperCase() + "')"
	return xPath
}

function showTrans(xpath)
{
	if (xpath != "") xpath = "[" + xpath + "]";
	//alert("/d/cfg[@k=" + window.top.frames.title.g_trs_key + "]" + xpath);
	g_trn_xsl.selectSingleNode("//xsl:variable[@name='Transcations']").setAttribute("select", "/d/cfg[@k=" + window.top.frames.title.g_trs_key + "]" + xpath);
	TransactionDiv.innerHTML = df_transform(g_my_xml, g_trn_xsl);
}

function newTransaction(clnkey)
{
	g_clnrole = "";	
	var cln_name = g_my_xml.selectSingleNode("/d/r[@k='" + clnkey + "']").getAttribute("nam");
	showModalDialog(window.top.title.g_app_path + "chooseClnRole.asp?clnname=" + cln_name,window,"resizable:no;status:no;dialogWidth:500px;dialogHeight:250px");	
	if (g_clnrole == "") return;
	window.top.title.g_xmlquery = ""
	window.top.title.g_clnkey = clnkey;
 	window.top.title.g_clnrole = g_clnrole;
	window.location.href = window.top.title.g_app_path + '1102_transaction_edit.asp';
}

function getSavePDFs()
{
	if (g_configValue!=''){
		var cNode = window.top.frames.title.g_cfg_xml.selectSingleNode("/d/cfg[@k='" + window.top.frames.title.g_trs_key + "' and @v='" + g_configValue + "']")
		if (cNode != null)
		{
			var fNodes = cNode.selectNodes("d/pdf")
			if (fNodes!=null)
			{
				for (var i=0;i<fNodes.length;i++)
					g_saveForms+= ","+fNodes[i].getAttribute("nam")+","
			}
		}
	}	
}
function initTransactionEdit()
{
	//alert('xxx'+addForm);
	df_loadXML(g_my_xml, window.top.frames.title.g_meta_xml.xml);
	mergeXML(g_my_xml, window.top.frames.title.g_cfg_xml, "/d", "/d/cfg[@k='" + window.top.frames.title.g_trs_key + "']", true);
	mergeClientXML();
	mergePDFMapXML();
	getSavePDFs()

	g_my_xml.selectSingleNode("/d/param").setAttribute("clnkey", g_clnkey);
	g_my_xml.selectSingleNode("/d/param").setAttribute("clnrole", g_clnrole);
	g_my_xml.selectSingleNode("/d/param").setAttribute("configvalue", g_configValue);
	
	/*KEVINS MODIFICATION*/
	if(g_configValue!='') 
	{
	//	alert(g_my_xml.selectSingleNode("/d/cfg[@k='" + window.top.frames.title.g_trs_key + "' and (@nam='"+g_new_guid+"' or @v='"+g_configValue+"')]"))
	//	alert("/d/cfg[@k='" + top.frames.title.g_trs_key + "' and @v='"+g_configValue+"']")
//	alert(g_configValue)
		var transcName=g_my_xml.selectSingleNode("/d/cfg[@k='" + top.frames.title.g_trs_key + "' and @v='"+g_configValue+"']").getAttribute("nam");			
		g_my_xml.selectSingleNode("/d/param").setAttribute("trans_nam", transcName);
	}else
	
		g_my_xml.selectSingleNode("/d/param").setAttribute("trans_nam", g_new_guid);

	var tNodes = g_my_xml.selectNodes("/d/fld")
	for (var i=0;i<tNodes.length;i++)
	{
		if (tNodes[i].getAttribute("tp") != 9) tNodes[i].setAttribute ("tp",7);
		tNodes[i].setAttribute ("tp",7);
		tNodes[i].setAttribute ("ide", 0);
		tNodes[i].setAttribute ("req", 0);
	}

	loadScriptXSL(g_trn_xsl, "appStylesheets/1102_transaction_edit.xsl");
	TransactionEditDiv.innerHTML = df_transform(g_my_xml, g_trn_xsl);
	if (g_configValue !='')
	{
		if (document.all("selectGrp"))
		{
			document.all("selectGrp").selectedIndex = 1;
			selectGrp.onchange();
		}
	}	
//	alert(window.top.frames.title.g_addForm)
	if(window.top.frames.title.g_addForm=='ADDForm')	
	{		
	//	document.all.transaction.style.display="none";		
	//	waitforFormChoose();	
		document.all.transaction.style.display = "none"
		document.all.FormChoose.style.display = "inline"
		window.top.frames.title.g_addForm=""
		waitforFormChoose()
		
	}
}

function waitforFormChoose()
{
	//window.setTimeout("if (document.all.FormChoose==null || window.frames.ListingClientEditFrame==null) waitforFormChoose(); else toggleDiv(document.all.FormChoose);",50)
	window.setTimeout("if (!window.frames.ListingClientEditFrame.g_my_xml) waitforFormChoose(); else {window.frames.ListingClientEditFrame.getFrameListingXML();}",100)
}

function initFrameForm()
{

	if (g_xslName != "0601_agent_edit.xsl")
	{
		g_my_xml = parent.g_my_xml;		
	}
	else
	{
		g_my_xml = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
		df_loadXML(g_my_xml, window.top.frames.title.g_meta_xml.xml);
		mergeXML(g_my_xml, window.top.frames.title.g_cfg_xml, "/d", "/d/cfg", true);
		mergeAgentXML();
		mergePDFMapXML();
		//alert(parent.g_my_xml.xml)
	}
	parent.loadScriptXSL(g_my_xsl, window.top.frames.title.g_app_path + "appStylesheets/"+g_xslName);
	FrameDiv.innerHTML = df_transform(g_my_xml, g_my_xsl);
	
	if (parent.g_configValue!='' || parent.g_clnkey!='')
	{	
		
		if (g_xslName=='0601_buyer_edit.xsl'){
			FetchBuyerData();
			if (parent.g_default_tab == "BuyerTBODY_Link") parent.document.all("BuyerTBODY_Link").click();
		}	
		else if(g_xslName=='0601_seller_edit.xsl'){	
			FetchSellerData();
			if (parent.g_default_tab == "SellerTBODY_Link") parent.document.all("SellerTBODY_Link").click();
		}	
		else if(g_xslName=='0601_agent_edit.xsl'){	
			if (g_configValue != '')
				loadDataForfields('','',"/d/cfg[@k='" + window.top.frames.title.g_trs_key + "' and @v='" + g_configValue + "']/d/r_A")
			else
			{
				document.all.AgentName.value = g_my_xml.selectSingleNode("/d/r_agt").getAttribute("nam");
				loadDataForfields('','',"/d/r_agt")
			}
		}
		else if(g_xslName=='0601_listing_edit.xsl'){	
			
			if (parent.g_rec_key != '')
			{
			//	parent.document.all.RecordName.value = parent.g_rec_nam;				
				FetchListingData();
			}
			else
			{
				
				loadDataForfields('','',"/d/cfg[@k='" + window.top.frames.title.g_trs_key + "' and @v='" + g_configValue + "']/d/r")
			}
			if (parent.g_default_tab == "ListingTBODY_Link") parent.document.all("ListingTBODY_Link").click();
		}
		else if(g_xslName=='0601_transInfo_edit.xsl'){	
			FetchTransInfoData();
		}
	}
	
	resizeThisIFrame()
}

function resizeThisIFrame()
{
	if (g_xslName=='0601_buyer_edit.xsl')
		parent.document.all.BuyerClientEditFrame.style.height = document.all.FrameDiv.offsetHeight
	else if (g_xslName=='0601_listing_edit.xsl')
		parent.document.all.ListingClientEditFrame.style.height = document.all.FrameDiv.offsetHeight
	else if (g_xslName=='0601_seller_edit.xsl')
		parent.document.all.SellerClientEditFrame.style.height = document.all.FrameDiv.offsetHeight
	else if (g_xslName=='0601_transInfo_edit.xsl')
		parent.document.all.TransInfoClientEditFrame.style.height = document.all.FrameDiv.offsetHeight

}

function getContractFromContractArray()
{
	var names = ""
	for (var i in g_contractArray)
	{
		if (g_contractArray[i]!='')	
		{
			names += ","+i+","
		}	
	}
	return names
}

function showAgentContractPDF(val)
{
	var checkContractNames = getContractFromContractArray() + g_saveForms
	var nam = document.all('searchContractName').value
	var contractXSL = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
	df_loadXML(contractXSL, "appStylesheets/0601_forms.xsl");
	g_my_xml.selectSingleNode("/d/param").setAttribute("groupName",val.split("_")[0])
	g_my_xml.selectSingleNode("/d/param").setAttribute("filterName",nam)
	g_my_xml.selectSingleNode("/d/param").setAttribute("checkContractNames",checkContractNames)
		
	//g_my_xml.selectSingleNode("/d/param").setAttribute("configValue",window.top.title.global_configValue)	
	//alert ('window.top.title.global_configValue='+window.top.title.global_configValue)
	
	if (val.indexOf("customized_")!=-1) // agent customized group
	{
		g_my_xml.selectSingleNode("/d/param").setAttribute("customizedGroupValue",val.split("_")[2])
		contractXSL.selectSingleNode("//xsl:for-each").setAttribute("select","$customizedfiles")
	}
	else if (val=='all') contractXSL.selectSingleNode("//xsl:for-each").setAttribute("select","$allfiles")
	else contractXSL.selectSingleNode("//xsl:for-each").setAttribute("select","$grpfiles")
	FormDiv.innerHTML = df_transform(g_my_xml, contractXSL);
	if (g_saveForms!='')
	{
		var a = g_saveForms.split(",")
		
		for (var i=0;i<a.length;i++)
		{
			if (a[i]!=null && a[i]!='')
			{
				var s = document.all(a[i])
				if (s) 
				{
					if (s.length==null)	s.onclick()
					else
					{
						for (var j=0;j<s.length;j++)
						{
							s[j].onclick()
						}
					}
				}	
			}
		}
	}
	

	g_saveForms = ""
}

function checkAllContracts(checked)
{
	var s = document.all("checkone")
	for (var i=0;i<s.length;i++)
	{
		checkOneContract(s[i],checked)
	}
}

function checkOneContract(thisType,checked)
{
	thisType.checked = checked
	highlight(checked,thisType.parentNode.parentNode.id)
	if (checked){
		addToContractArray(thisType.id)
	}	
	else 
	{
		removeFromContractArray(thisType.id)
	}	
	refreshSavedTransaction()
}

function removeFromContractArray(id)
{
	g_contractArray[id] = ""
}

function addToContractArray(id)
{
	g_contractArray[id] = id
}







function FetchListingData()
{
	if (parent.document.all.RecordName.value=='') return;
	//*******var sql = "select " + window.top.frames.title.g_dbname + "." + window.top.frames.title.g_dbname + ".GetXMLById('"+parent.document.all.RecordName.value+"')"
	var sql = "select " + window.top.frames.title.g_dbname + "." + window.top.frames.title.g_dbname + ".GetXMLByIdFullLabel('"+parent.document.all.RecordName.value+"')"
	//var sql = "select idc_fls.idc_fls.GetXMLByIdFullLabel('"+parent.document.all.RecordName.value+"')"
	FetchDataForm.FetchSQL.value = sql
	FetchDataForm.submit();
}
function loadFetchDataXML()
{
	mergeXML(g_my_xml,g_ListingDataXMLObj,"/d","/d/r_lst",true)
	var xNodes = g_my_xml.selectNodes("/d/r_lst")
	if (xNodes.length==0) return alert("MLS number not found");
	resetArrayValues()
	FetchDataForm.reset()
	loadDataForfields('','',"/d/r_lst")
}
function RollBackListingData()
{
	parent.document.all.RecordName.value = ''
	resetArrayValues()
	FetchDataForm.reset()
	if (g_configValue !='')
		loadDataForfields('','',"/d/cfg[@k='" + window.top.frames.title.g_trs_key + "' and @v='" + g_configValue + "']/d/r")
}

function RollBackTransInfoData()
{
	document.all.TransInfoName.value = ''
	resetArrayValues();
	FetchTransInfoDataForm.reset();
	if (g_configValue !='')
		loadDataForfields('','',"/d/cfg[@k='" + window.top.frames.title.g_trs_key + "' and @v='" + g_configValue + "']/d/r_T")
	
}

function FetchBuyerData()
{
	var thekey = ""
	if (document.all.BuyerKEY.value!='') thekey = document.all.BuyerKEY.value
	resetArrayValues()
	FetchBuyerDataForm.reset()
	if (thekey!="" && parent.g_clnrole =='buyer')
	{
		loadDataForfields('','',"/d/r_cln[@k='"+thekey+"']")
	}else if (g_configValue!='')
		{
			loadDataForfields('','',"/d/cfg[@k='" + window.top.frames.title.g_trs_key + "' and @v='" + g_configValue + "']/d/r_B")
		}	
}

function FetchSellerData()
{
	var thekey = ""
	if (document.all.SellerKEY.value!='') thekey = document.all.SellerKEY.value
	resetArrayValues()
	FetchSellerDataForm.reset()
	if (thekey!="" && parent.g_clnrole =='seller')
	{
		loadDataForfields('',"","/d/r_cln[@k='"+thekey+"']")	
	}else if (g_configValue!='')
		{
			loadDataForfields('','',"/d/cfg[@k='" + window.top.frames.title.g_trs_key + "' and @v='" + g_configValue + "']/d/r_S")
		}	
	
	
}

function FetchTransInfoData()
{
	var thekey = ""
	resetArrayValues()
	FetchTransInfoDataForm.reset()
	loadDataForfields('','',"/d/cfg[@k='" + window.top.frames.title.g_trs_key + "' and @v='" + g_configValue + "']/d/r_T")
}

function loadFetchTransInfoDataXML()
{
	mergeXML(g_my_xml,g_transInfoXMLObj,"/d","/d/r_T",true)
	var xNodes = g_my_xml.selectNodes("/d/r_T")
	if (xNodes.length==0) return alert("trans info not found");
	resetArrayValues()
	FetchTransInfoDataForm.reset()
	loadDataForfields('','',"/d/r_T")
}

function RollBackAgentData()
{
	document.all.AgentName.value = ''
	resetArrayValues();
	FetchAgentDataForm.reset();
	if (g_configValue !='')
		loadDataForfields('','',"/d/cfg[@k='" + window.top.frames.title.g_trs_key + "' and @v='" + g_configValue + "']/d/r_A")
	
}

function RollSellerData()
{
	resetArrayValues()
	FetchSellerDataForm.reset()
	document.all.SellerKEY.selectedIndex = 0
	if (g_configValue !='')
		loadDataForfields('','',"/d/cfg[@k='" + window.top.frames.title.g_trs_key + "' and @v='" + g_configValue + "']/d/r_S")
}

function RollBuyerData()
{
	resetArrayValues()
	FetchBuyerDataForm.reset()
	document.all.BuyerKEY.selectedIndex = 0
	if (g_configValue !='')
		loadDataForfields('','',"/d/cfg[@k='" + window.top.frames.title.g_trs_key + "' and @v='" + g_configValue + "']/d/r_B")
}
function getFrameAgentXML()
{
	
	var xml = getAllXMLs()
	xml = xml.substring(xml.indexOf("<v"),xml.indexOf("</r>"))
	var s = (document.all.AgentName!=null) ? document.all.AgentName.value : ""	
	xml = "<r_A nam='"+ s +"'>" + xml + "</r_A>"
	return xml
	
}
function getFrameListingXML()
{
	var xml = getAllXMLs()
	xml = xml.substring(xml.indexOf("<v"),xml.indexOf("</r>"))
//	var s = (document.all.ide!=null) ? document.all.ide.value : ""	
	var tNodes = g_my_xml.selectNodes("/d/pdf[@ide='1']")
	var s = ""
	for (var i=0;i<tNodes.length;i++)
	{
		if (s!='')s+=" "
		if (document.all('id_'+tNodes[i].getAttribute("k")+'_tp_7').value=='') return false
		s += document.all('id_'+tNodes[i].getAttribute("k")+'_tp_7').value	
	}
	
	xml = "<r nam='"+HTMLEncode(s) +"'>" + xml + "</r>"
	return xml
}

function getFrameBuyerXML()
{
	var xml = getAllXMLs()
	xml = xml.substring(xml.indexOf("<v"),xml.indexOf("</r>"))
//	var s = (document.all.ide!=null) ? document.all.ide.value : ""	
	var s = "";
	if (document.all.ide)
	{
		if (!document.all.ide.length) s = document.all.ide.value;
		else for (var i = 0; i < document.all.ide.length; i++)
			s += document.all.ide[i].value + " ";
	}
	xml = "<r_B nam='"+HTMLEncode(s) +"'>" + xml + "</r_B>"
	return xml
}

function getFrameSellerXML()
{
	var xml = getAllXMLs()
	xml = xml.substring(xml.indexOf("<v"),xml.indexOf("</r>"))
//	var s = (document.all.ide!=null) ? document.all.ide.value : ""	
	var s = "";
	if (document.all.ide)
	{
		if (!document.all.ide.length) s = document.all.ide.value;
		else for (var i = 0; i < document.all.ide.length; i++)
			s += document.all.ide[i].value + " ";
	}
	xml = "<r_S nam='"+HTMLEncode(s) +"'>" + xml + "</r_S>"
	return xml
}
function getFrameTransInfoXML()
{
	
	var xml = getAllXMLs()
	xml = xml.substring(xml.indexOf("<v"),xml.indexOf("</r>"))
	var s = (document.all.AgentName!=null) ? document.all.AgentName.value : ""	
	xml = "<r_T nam='"+ HTMLEncode(s) +"'>" + xml + "</r_T>"
	return xml
	
}

function getAllPDFXMLQuery()
{
	var xml = ""
	for (i in g_contractArray)
	{
		if (g_contractArray[i]!='')	
		{
			if (g_configValue!='')
			{
				var tNode = window.top.frames.title.g_cfg_xml.selectSingleNode("/d/cfg[@k='" + window.top.frames.title.g_trs_key + "' and @v='" + g_configValue + "']/d/pdf[@nam='"+g_contractArray[i]+"']")
				if (tNode != null) xml += tNode.xml
				//else xml += "<pdf nam='"+g_contractArray[i]+ "'/>"
				else xml += "<pdf nam='"+g_contractArray[i]+ "' lab='" + HTMLEncode(g_my_xml.selectSingleNode("/d//xf[@nam='"+g_contractArray[i]+"']").getAttribute("lbl")) + "'/>"
			}
			else
				//xml += "<pdf nam='"+g_contractArray[i]+ "'/>"
				xml += "<pdf nam='"+g_contractArray[i]+ "' lab='" + HTMLEncode(g_my_xml.selectSingleNode("/d//xf[@nam='"+g_contractArray[i]+"']").getAttribute("lbl")) + "'/>"

		}	
	}
	if (xml == "") return xml;
	

	//DEJANs Modificaition
	//xml += "<fdf nam='"+window.top.frames.title.g_app_path+"appStylesheets/idc_fls/fdf/"+window.top.frames.title.g_userkey+'_'+g_new_guid+".fdf'/>"
	var transcName = '';	
						
	if(g_configValue!='') 	
	{
	//	alert("/d/cfg[@k='" + top.frames.title.g_trs_key + "' and @v='"+g_configValue+"']")
		var transcName=g_my_xml.selectSingleNode("/d/cfg[@k='" + top.frames.title.g_trs_key + "' and @v='"+g_configValue+"']").getAttribute("nam");		
		
	}
	else	
		var transcName = g_new_guid;

	xml += "<fdf nam='"+window.top.frames.title.g_app_path+"appStylesheets/idc_fls/fdf/"+window.top.frames.title.g_userkey+'_'+transcName+".fdf'/>"		
	//END ***************
	
	//alert(xml)
	
	return xml
}

function toggleDiv(thisDiv)
{
	if (thisDiv.id=="transaction")
		document.all.FormChoose.style.display = "none"
	else
	{
		if (!window.frames.ListingClientEditFrame.getFrameListingXML())
			return alert('Please fill in the require field')
		document.all.transaction.style.display = "none"
	}
	thisDiv.style.display = "inline"
}

function processSaveTranscation()
{
	var TheTransName = ProcessForm.TransName.value;
	var pdfXML = getAllPDFXMLQuery()
	if (pdfXML=='') return alert('Please choose some forms')
	var buyerXML = (document.all.BuyerClientEditFrame.src) ? window.frames.BuyerClientEditFrame.getFrameBuyerXML() : ""
	var sellerXML = (document.all.SellerClientEditFrame.src) ? window.frames.SellerClientEditFrame.getFrameSellerXML() : ""
	var listingXML = (document.all.ListingClientEditFrame.src) ? window.frames.ListingClientEditFrame.getFrameListingXML() : ""
	if (!listingXML) return alert('Please fill in the required field')
	var transInfoXML = (document.all.TransInfoClientEditFrame.src) ? window.frames.TransInfoClientEditFrame.getFrameTransInfoXML() : ""
	var agentXML = (document.all.AgentClientEditFrame.src) ? window.frames.AgentClientEditFrame.getFrameAgentXML() : ""

	var pNode = g_my_xml.selectSingleNode("/d/cfg[@k='" + window.top.frames.title.g_trs_key + "' and @v='" + g_configValue + "']/d/pros");
	var prosStr = (g_clnkey != '') ? "<pros id='" + g_clnrole
		+ "'>" + g_clnkey + "</pros>" : ((pNode!=null) ? "<pros>"+pNode.text+"</pros>" : "");
	var KeyValue = "<d>" + prosStr + listingXML + buyerXML+sellerXML+agentXML+transInfoXML+pdfXML+"</d>";
	var fdfStr = generateFDFStr(KeyValue,TheTransName)
//	return alert(fdfStr);

	KeyValue = KeyValue.replace(/'/ig,"''");

	var TheSQL = "";
	if (g_configValue != "")
	{
	//	TheSQL += "delete fConfigs where UserKEY = " +window.top.frames.title.g_userkey+" and ConfigKEY = " + window.top.frames.title.g_trs_key + " and ConfigValue = " + g_configValue + "\n" 
	//	TheSQL += "insert into fConfigs(UserKEY, ConfigKEY, ConfigValue, KeyName, KeyValue, WhenModified) select " +window.top.frames.title.g_userkey+", " + window.top.frames.title.g_trs_key + ", "+g_configValue+", '" + 
	//	TheTransName + "', '"+KeyValue+"', getdate() from fConfigs where UserKEY = " +window.top.frames.title.g_userkey+" and ConfigKEY = " + window.top.frames.title.g_trs_key;

		//********TheSQL += "update fconfigs set KeyValue='"+KeyValue+"' where UserKEY = " +window.top.frames.title.g_userkey+" and ConfigKEY = " + window.top.frames.title.g_trs_key + " and ConfigValue = " + g_configValue
		TheSQL += "update fconfigs3 set KeyValue='"+KeyValue+"' where UserKEY = " +window.top.frames.title.g_userkey+" and ConfigKEY = " + window.top.frames.title.g_trs_key + " and ConfigValue = " + g_configValue

	}
	else
	{
//		TheSQL += "delete fConfigs where UserKEY = " +window.top.frames.title.g_userkey+" and ConfigKEY = " + window.top.frames.title.g_trs_key + " and ConfigValue = " + g_configValue + "#$$#" 

		//********TheSQL += "insert into fConfigs(UserKEY, ConfigKEY, ConfigValue, KeyName, KeyValue, WhenModified) select " +window.top.frames.title.g_userkey+", " + window.top.frames.title.g_trs_key + ", isnull(max(ConfigValue), 0) + 1, '" +
		TheSQL += "insert into fConfigs3(UserKEY, ConfigKEY, ConfigValue, KeyName, KeyValue, WhenModified) select " +window.top.frames.title.g_userkey+", " + window.top.frames.title.g_trs_key + ", isnull(max(ConfigValue), 0) + 1, '" +  

		//********TheTransName + "', '"+KeyValue+"', getdate() from fConfigs where UserKEY = " +window.top.frames.title.g_userkey+" and ConfigKEY = " + window.top.frames.title.g_trs_key;
		TheTransName + "', '"+KeyValue+"', getdate() from fConfigs3 where UserKEY = " +window.top.frames.title.g_userkey+" and ConfigKEY = " + window.top.frames.title.g_trs_key;

	}
//	return alert(TheSQL);
	
	ProcessForm.SQLQuery.value = TheSQL;
	ProcessForm.FDFStr.value = fdfStr;
	//return alert(ProcessForm.SQLQuery.value)
//	ProcessForm.target="_blank";
	ProcessForm.submit();
}

function generateFDFStr(KeyValue,TheTransName)
{
	var tmp_xml = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
	df_loadXML(tmp_xml, KeyValue);

	var tmp_pdf_xml = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
	df_loadXML(tmp_pdf_xml, window.top.frames.title.g_app_path + "dataFloat/dfDatabases/"+window.top.frames.title.g_dbname+"/pdfmap.xml");
	mergeXML(tmp_xml, tmp_pdf_xml, "/d", "/d/pdf", true);
	var param_xml = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
	df_loadXML(param_xml, "<param transname=\"" + TheTransName + "\" url_path='"+ window.top.location.host + window.top.frames.title.g_app_path + "'/>");
	mergeXML(tmp_xml, param_xml, "/d", "/param", true);
	
	var tmp_xsl = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
	df_loadXML(tmp_xsl, window.top.frames.title.g_app_path + "dataFloat/dfScripts/dfXML2FDF.xsl");

	
	var fdfStr = "";
	fdfStr += "%FDF-1.2\n";
	fdfStr += "%âãÏÓ\n";

	fdfStr += tmp_xml.transformNode(tmp_xsl);
	return fdfStr;
	
}

function editTransaction(configvalue,clnkey,clnrole)
{
//	alert(configvalue)
//	alert(clnkey)
//	alert(clnrole)	
	//if(addForm==undefined) addForm = '';	 
	window.top.title.g_clnkey = clnkey
	window.top.title.g_clnrole = clnrole
	window.location.href = window.top.title.g_app_path+"1102_transaction_edit.asp?cfgval="+configvalue
//	alert(window.location.href)
}

function refreshSavedTransaction()
{
//	alert(refreshSavedTransaction.caller)
	var str = ""
	var n = 0;


//	alert("/d/cfg[@k='" + window.top.frames.title.g_trs_key + "' and (@nam='"+g_new_guid+"' or @v='"+g_configValue+"')]");
	var tNode = g_my_xml.selectSingleNode("/d/cfg[@k='" + window.top.frames.title.g_trs_key + "' and (@nam='"+g_new_guid+"' or @v='"+g_configValue+"')]")

	if (tNode!=null) {				
		if(tNode.selectSingleNode("d/fdf"))
			var FDFLink = tNode.selectSingleNode("d/fdf").getAttribute("nam");
		else
			var FDFLink = '';		
		
		var tNodes = tNode.selectNodes("d/pdf")
		for (i in g_contractArray)
		{
			if (g_contractArray[i]!='')
			{
				if (tNode.selectSingleNode("d/pdf[@nam='"+g_contractArray[i]+"']")==null)
				{
					str += g_my_xml.selectSingleNode("/d//xf[@nam='"+g_contractArray[i]+"']").getAttribute("lbl")+"</br>"
					
				}else
				{																											
					//DEJAN COMMENT
					var transcName = '';					
					//if(g_MAXconfigValue!='') transcName=g_my_xml.selectSingleNode("/d/cfg[@k='" + top.frames.title.g_trs_key + "' and @v='"+g_MAXconfigValue+"']").getAttribute("nam");					
					if(g_configValue!='') 	
						var transcName=g_my_xml.selectSingleNode("/d/cfg[@k='" + top.frames.title.g_trs_key + "' and @v='"+g_configValue+"']").getAttribute("nam");		
					else	
						var transcName = g_new_guid;
															
					
					PDFFileName = g_my_xml.selectSingleNode("/d//xf[@nam='"+g_contractArray[i]+"']").getAttribute("fn")
					//alert(PDFFileName)
					if(PDFFileName==null) PDFFileName=g_contractArray[i]
					
					str += "<a href='javascript:void(0)' onclick=\"fs_fdf.location.href='dataFloat/processXFDFOpen.asp?transcName="+ transcName + "&PDFName=" + g_contractArray[i] + "&PDFFileName=" + PDFFileName + "&FDFLink="+FDFLink+"'\">"
					str += g_my_xml.selectSingleNode("/d//xf[@nam='"+g_contractArray[i]+"']").getAttribute("lbl")+" (Saved)</a></br>"
					document.all('btnComplete').disabled = false;
					//str += g_my_xml.selectSingleNode("/d//xf[@nam='"+g_contractArray[i]+"']").getAttribute("lbl")+" (Saved)</br>"
					//end DEJAN COMMENT
				}	
				n++;	
			}
		}
		var s = document.all.newTitle
		if (s)
		{
			if (s.length!=null)
			{
				for (var i=0;i<s.length;i++)
				{
					s[i].innerHTML = "<h3>Manage Transaction For "+g_my_xml.selectSingleNode("/d/r_cln[@k='"+g_clnkey+"']").getAttribute("nam")+" (" + tNode.selectSingleNode("d/pros").getAttribute("id") + "): "+ tNode.selectSingleNode("d/r").getAttribute("nam") + "</h3>"	
				}
			}else
			{
				s.innerHTML = "<h3>Manage Transaction For "+g_my_xml.selectSingleNode("/d/r_cln[@k='"+g_clnkey+"']").getAttribute("nam")+" (" + tNode.selectSingleNode("d/pros").getAttribute("id") + "): "+ tNode.selectSingleNode("d/r").getAttribute("nam") + "</h3>"
			}
		}
		g_configValue = tNode.getAttribute("v")
		

	}else
	{
		for (i in g_contractArray)
		{
			if (g_contractArray[i]!='')
			{
				str += g_my_xml.selectSingleNode("/d//xf[@nam='"+g_contractArray[i]+"']").getAttribute("lbl")+"</br>"
				n++;
			}
		}
	}	
	formLbls.innerHTML = "<p><b>" + n + " forms selected</b></p>" + str


	
}

function openPrintPDFDialog(url)
{
	var height = 200;
	var width = 450;
	var top = (screen.height-height)/2;
	var left = (screen.width-width)/2;
	window.open(url, null, 'height=' + height + ',width=' + width + ',top=' + top + ',left=' + left + ',resizable=yes,status=no,toolbar=no,menubar=yes,location=no,scrollbars=yes');
}
function sendPDFtoPrint()
{	
	var PDFNames = setEmailPDF();
	if (PDFNames=='') return alert('please check some forms!')
	var link = window.opener.g_emailLink+PDFNames	
	//return alert(link)
	if(document.all('tblChooseForms')) document.all('tblChooseForms').style.display='none'
	if(document.all('TBLprocessing')) document.all('TBLprocessing').style.display='block'
	window.location.href = link;
	window.resizeTo(800,600);
	window.moveTo((screen.width-800)/2,(screen.height-600)/2)			
}


function openEmailDialog(url)
{
	var height = 400;
	var width = 540;
	var top = (screen.height-height)/2;
	var left = (screen.width-width)/2;
	window.open(url, null, 'height=' + height + ',width=' + width + ',top=' + top + ',left=' + left + ',resizable=no,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes');
}

function sendPDFByEmail()
{
	if (EmailTo.value == "") return;
	var PDFNames = setEmailPDF();
	if (PDFNames=='') return alert('please check some forms!')
	
	PDFNames = PDFNames.replace("&amp;PDFName=", "&PDFName="); 
	
	var link = window.opener.g_emailLink + PDFNames
	link += "&EmailTo=" + EmailTo.value;
	if(mergeForms.checked) link += "&mergeForms=true";
	var emailcmnt = document.all.mailbody.value;
	emailcmnt = emailcmnt.replace(/\r\n/ig,"<br>"); 	
	
	link += "&EmailSubject=" + EmailSubject.value //+ "&EmailBody=" + escape(emailcmnt);
	window.opener.document.getElementById("txt_EmailBody").value = emailcmnt;
	//alert(window.opener.document.getElementById("EmailBody1").value);
	window.opener.document.forms("tmpEmail").action=link;
	window.opener.document.forms("tmpEmail").submit();		
	//return alert(link);
	//window.opener.fs_fdf.location.href = link;
	window.close();
}

function sendPDFByEmailXX()
{
	if (EmailTo.value == "") return;
	var PDFNames = setEmailPDF();
	if (PDFNames=='') return alert('please check some forms!')
	var link = window.opener.g_emailLink+PDFNames
	link += "&EmailTo=" + EmailTo.value;
	if(mergeForms.checked) link += "&mergeForms=true";
	var emailcmnt = document.all.mailbody.value;
	emailcmnt = emailcmnt.replace(/\r\n/ig,"<br>"); 	
	
	link += "&EmailSubject=" + EmailSubject.value + "&EmailBody=" + escape(emailcmnt);
	//return alert(link);
	window.opener.fs_fdf.location.href = link;
	window.close();
}

function setEmailPDF()
{
	var str = ""
	var a = ""
	var s = document.all.PDFs
	if (s)
	{
		if (s.length==null)
		{
			if (s.checked) str += s.value
		}
		else
		{
			for(var i=0;i<s.length;i++)
			{
				if (s[i].checked)
				{
					if (str !='') str+=","
					str += s[i].value
				}	
			}
		}		
	}
	if (str !='') a += "&amp;PDFName=" + str;
	return a
}

function getAttachedForms()
{
	var str = ""
	var tNodes = window.opener.g_my_xml.selectNodes("/d/cfg[@k='" + window.opener.top.frames.title.g_trs_key + "' and @v='"+window.opener.g_email_configVal+"']/d/pdf")	
	for(var i=0;i<tNodes.length;i++)
	{
		if (i>1 && i % 6 == 1) str += "<br/>"
		str += "<input type='checkbox' id=PDFs value='"+tNodes[i].getAttribute("nam")+"' checked='true'></input>"
		//str += "<b>"+tNodes[i].getAttribute("nam")+"</b>&#160;&#160;&#160;"
		str += "<b>"+  window.opener.g_my_xml.selectSingleNode("/d//xf[@nam='" + tNodes[i].getAttribute("nam") + "']").getAttribute("lbl")  +"</b><br/>"
		/*
		if(tNodes[i].getAttribute("lab"))
			str += "<b>"+tNodes[i].getAttribute("lab")+"</b><br/>"
		else
			str += "<b>"+tNodes[i].getAttribute("nam")+"</b><br/>"		
		*/
		
	}
	return str
}
