﻿// ajax utility script
// requirements: mozxpath.js,ASXML.js
// Copyright (c) Peter Foran 2008

function updateDay(hdnDay,ddlDay,ddlMonth,ddlYear) { //updates the day dropdown based on the input month and year

    var cntDay = document.getElementById(hdnDay);
    var dayVal = document.getElementById(ddlDay).value;
    var mthVal = document.getElementById(ddlMonth).value;
    var yrVal = document.getElementById(ddlYear).value;

    var remoteConnection = new ASXML();

	remoteConnection.setCallback(
		function (loadOK){
		if(loadOK)	{

			var x = remoteConnection.xmlResponse();

			//repopulate Day dropdown
			remoteConnection.populateDDL(ddlDay, x.selectNodes("//root/day"), "", dayVal);

			if(cntDay){cntDay.value = dayVal;} //store day value in hidden variable (if one exists) to overcome day-number problem (where dropdownlist in viewstate doesn't hold new list of numbers on postback)
			}
		}
	);
    remoteConnection.getXML("/ajax/generalAJAX.aspx?t=updateday&mth=" + mthVal + "&yr=" + yrVal);
}

function updateCounty(ddlCountryID, ddlCountyID, DefaultMsg) { //updates County dropdown based on input Country

    var _objCountry = document.getElementById(ddlCountryID);
    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(ddlCountyID, x.selectNodes("//root/county"), DefaultMsg, 0);
	        }
	    }
    );
    remoteConnection.getXML("/ajax/generalAJAX.aspx?t=county&id=" + iCountryID);

}

// sets the value of a specified field (if it exists)
// params: (id of element, value)
function setFieldVal(id, val) {

    var obj = document.getElementById(id);

    if (obj) { if (!obj.isDisabled) { obj.value = val; } }
}

