﻿// requirements: mozxpath.js,ASXML.js

function updatePriceByStatusGroup(ddlMarketSG, ddlPrice, DefaultMsg) { //updates price dropdown based on market status group (i.e. "Sales" or "Lettings")

    var _objMarketSG = document.getElementById(ddlMarketSG);
    var _objPrice = document.getElementById(ddlPrice);

    //verify valid inputs
    if (_objMarketSG && _objPrice) {

        var iStatusGroup = _objMarketSG.options[_objMarketSG.selectedIndex].value;

        var remoteConnection = new ASXML();

        remoteConnection.setCallback(
		    function(loadOK) {
		        if (loadOK) {

		            var x = remoteConnection.xmlResponse();

		            //repopulate Price dropdown
		            remoteConnection.populateDDL(_objPrice, x.selectNodes("//root/price"), DefaultMsg, 0);
		        }
		    }
	    );
        remoteConnection.getXML("/ajax/generalAJAX.aspx?t=maxpricebystatusgroup&id=" + iStatusGroup);
    }
}

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);
		            }
		        }
		    }
	    );
        remoteConnection.getXML("/ajax/generalAJAX.aspx?t=county&id=" + iCountryID);
    }
}

function updateDistrict(ddlCountyID, ddlDistrictID, DefaultMsg) { //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);
    }
}

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);
    }
}
