﻿// requirements: mozxpath.js,ASXML.js

function updateCounty(ddlCountryID, ddlCountyID, ddlDistrictID, DefaultMsg, DefaultMsg_district) { //updates County dropdown based on input Country
                                                                                                   //also updates the District dd if specified
    var _objCountry = document.getElementById(ddlCountryID);
    var _objCounty = document.getElementById(ddlCountyID);
    var _objDistrict = document.getElementById(ddlDistrictID);

    //verify valid inputs (district is optional)
    if (_objCountry && _objCounty) {

        var iCountryID = _objCountry.options[_objCountry.selectedIndex].value;

        var remoteConnection = new ASXML();

        remoteConnection.setCallback(
		    function(loadOK) {
		        if (loadOK) {

		            var x = remoteConnection.xmlResponse();

		            //repopulate County dropdown
		            remoteConnection.populateDDL(_objCounty, x.selectNodes("//root/county"), DefaultMsg, 0);

		            //populate District dropdown (if it exists)
		            if (_objDistrict) {
		                updateDistrict(ddlCountyID, ddlDistrictID, DefaultMsg_district, 0);
		            }
		        }
		    }
	    );
        remoteConnection.getXML("/ajax/generalAJAX.aspx?t=county&id=" + iCountryID);
    }
}

function updateDistrict(ddlCountyID, ddlDistrictID, DefaultMsg, bWithDistrictGroups) { //updates district dropdown based on input county

    var _objCounty = document.getElementById(ddlCountyID);
    var _objDistrict = document.getElementById(ddlDistrictID);

    //verify valid inputs
    if (_objCounty && _objDistrict) {

        var iCountyID = _objCounty.options[_objCounty.selectedIndex].value;

        var remoteConnection = new ASXML();

        remoteConnection.setCallback(
		    function(loadOK) {
		        if (loadOK) {

		            var x = remoteConnection.xmlResponse();

		            //repopulate District dropdown
		            remoteConnection.populateDDL(_objDistrict, x.selectNodes("//root/district"), DefaultMsg, 0);
		        }
		    }
	    );
        remoteConnection.getXML("/ajax/generalAJAX.aspx?t=district&id=" + iCountyID + "&usedg=" + bWithDistrictGroups);
    }
}

function updateDistrict_Report(ddlCountyID, ddlDistrictID, DefaultMsg) { //updates district dropdown based on input county (Report version)

    var _objCounty = document.getElementById(ddlCountyID);
    var _objDistrict = document.getElementById(ddlDistrictID);

    //verify valid inputs
    if (_objCounty && _objDistrict) {

        var iCountyID = _objCounty.options[_objCounty.selectedIndex].value;

        var remoteConnection = new ASXML();

        remoteConnection.setCallback(
		    function(loadOK) {
		        if (loadOK) {

		            var x = remoteConnection.xmlResponse();

		            //repopulate District dropdown
		            remoteConnection.populateDDL(_objDistrict, x.selectNodes("//root/district"), DefaultMsg, 0);
		        }
		    }
	    );
        remoteConnection.getXML("/ajax/generalAJAX.aspx?t=district_report&id=" + iCountyID);
    }
}

function updateLType(ddlPTypeID, ddlLTypeID, DefaultMsg) { //updates living type dropdown based on input property type

    var _objPType = document.getElementById(ddlPTypeID);
    var _objLType = document.getElementById(ddlLTypeID);

    //verify valid inputs
    if (_objPType && _objLType) {

        var iPTypeID = _objPType.options[_objPType.selectedIndex].value;

        var remoteConnection = new ASXML();

        remoteConnection.setCallback(
		    function(loadOK) {
		        if (loadOK) {

		            var x = remoteConnection.xmlResponse();

		            //repopulate living type dropdown
		            remoteConnection.populateDDL(_objLType, x.selectNodes("//root/type"), DefaultMsg, 0);
		        }
		    }
	    );
        remoteConnection.getXML("/ajax/generalAJAX.aspx?t=livingtype&id=" + iPTypeID);
    }
}


