function funDisplay(xml)
{
	if (style.parseError.errorCode != 0) {
    error = style.parseError;
    alert('Error parsing XSLT file:\n' + error.reason + '[' + error.url + 
          ': line ' + error.line + ', col ' + error.linepos + ']');
    }
    else
		xslTarget.innerHTML = xml.transformNode(style.XMLDocument);
}	

function funClearCombo(combo)
{
	if (combo.length > 0)
	{
		for (i=combo.length-1; i>=0; i--)
		{
			combo.remove(i)
		}
	}
}

function funLoadComboFromXML(objXML, strSearch, objCombo, strAttribute, strValueAttr, strEmptyValue)
{
	var lst = objXML.selectNodes(strSearch); 
	funClearCombo(objCombo);
	//Add empty row

	if (strEmptyValue != null)
	{
		var oOption = window.document.createElement("OPTION");
		oOption.value = "";
		oOption.text = strEmptyValue;
		objCombo.add(oOption);
	}		
	
	for(ctr=0;ctr!=lst.length;ctr++)
	{
		var strText = lst[ctr].getAttribute(strAttribute);
		if (strValueAttr != null)
			var strValue = lst[ctr].getAttribute(strValueAttr);
		else
			strValue = strText;
			
		var oOption = window.document.createElement("OPTION");
		oOption.value = strValue;
		oOption.text = strText;
		objCombo.add(oOption);		
	}
}
function funNetscapeLoadComboFromXML(xml, strSearch, objCombo, strAttribute, strValueAttr, strEmptyValue)
{
	//Populate States
	var id = xml.getAttribute("id");
	var nodes = xml.getElementsByTagName(strSearch)
	funClearCombo(objCombo);
	
	// add empty row
	var oOption = new Option(strEmptyValue, "");
	objCombo.options[0] = oOption;		

	//Add each node
	for (i=0;i<nodes.length;i++)
	{
		var strText = nodes[i].getAttribute(strAttribute);
			strValue = strText;
		if (strValueAttr != null)
			var strValue = nodes[i].getAttribute(strValueAttr);
		else
			strValue = strText;
			
		var oOption = new Option(strText, strValue);
		objCombo.options[i+1] = oOption;
	}
}

function funLoadAgencyTown(xml)
{
	var nodes = xml.getElementsByTagName("Location");
	var strState = document.Form1.AgencyState.value;
	// add empty row
	var objCombo = document.Form1.AgencyTown;
	funClearCombo(objCombo);
	var oOption = new Option("Choose Agency", "");
	objCombo.options[0] = oOption;		

	//Add each node
	var count = 1;
	for (i=0;i<nodes.length;i++)
	{
		var strNodeState = nodes[i].getAttribute("STATE");
		if (strNodeState == strState)
		{
			var strText = nodes[i].getAttribute("CITY");
			var strValue = strText;
			var oOption = new Option(strText, strValue);
			objCombo.options[count] = oOption;
			var count = count + 1;
		}
		
	}

}

function funChangeAgencyState()
{
	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("msie") != -1)
	{
		var str = "Locations/Location[@STATE='" + document.Form1.AgencyState.value + "']";
		funLoadComboFromXML(AgencyCityXML, str, this.Form1.AgencyTown, "CITY", null, "Choose Town");
	}
	else
	{
		var xmlNodes = document.getElementsByTagName("xml");
		funLoadAgencyTown(xmlNodes[0]);
	}
}
function funLoadAgencyLocator()
{
	var agt=navigator.userAgent.toLowerCase();

	//If IE
	if (agt.indexOf("msie") != -1)
	{
		funLoadComboFromXML(AgencyStateXML, 'States/State_Name', this.Form1.AgencyState, 'STATE', null, 'Choose State');
		funChangeAgencyState();
	}
	else
	{
		var xmlNodes = document.getElementsByTagName("xml");
		funNetscapeLoadComboFromXML(xmlNodes[1], "State_Name", document.Form1.AgencyState, "STATE", null, "Choose State");
		funLoadAgencyTown(xmlNodes[0]);
	}
}

/////////////////////////////////////////
//Adjustor functions 
/////////////////////////////////////////
function funLoadAdjustorLocator()
{
	var agt=navigator.userAgent.toLowerCase();

	//If IE
	if (agt.indexOf("msie") != -1)
	{
		funLoadComboFromXML(AdjustorStateXML, 'States/State_Name', this.Form1.AgencyState, 'STATE', null, 'Choose State');
		funChangeAdjustorState();
		Form1.AdjustorName.focus();
	}
	else
	{
		var xmlNodes = document.getElementsByTagName("xml");
		funNetscapeLoadComboFromXML(xmlNodes[1], "State_Name", document.Form1.AgencyState, "STATE", null, "Choose State");
		funLoadAgencyTown(xmlNodes[0]);
	}
}
function funChangeAdjustorState()
{
	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("msie") != -1)
	{
		var str = "Locations/Location[@STATE='" + document.Form1.AgencyState.value + "']";
		funLoadComboFromXML(AdjustorCityXML, str, this.Form1.AgencyTown, "CITY", null, "Choose Town");
	}
	else
	{
		var xmlNodes = document.getElementsByTagName("xml");
		funLoadAgencyTown(xmlNodes[0]);
	}
}


function funSubmitForm()
{
	//TODO : Change this to https:
	var strURL = new String(Form1.ownerDocument.URLUnencoded);
	var strNewURL = strURL.replace("http://", "http://");
	
	Form1.action=strNewURL;
	Form1.submit;
}

function funModifyAgencyAssociation(strPage, agencyId, associatedId)
{
	Form1.hdnID.value = agencyId;
	Form1.hdnAssocID.value = associatedId;
	Form1.hdnPage.value=strPage;
	Form1.submit();
}


