// JavaScript Document
var xmlHttp;
var now = new Date();
var hour = now.getHours();
var minute = now.getMinutes();
var second = now.getSeconds();


function subLookup(fldcat, fldsub,url) {	
	//if (trim(zip).length != 5 || !checkChars(zip, "0123456789")) return false;

	catfld = document.getElementById(fldcat);
	catid = catfld.options[catfld.selectedIndex].value;
	
	//alert(catfld.options[catfld.selectedIndex].value);
	
	if(catid > 0){
		if (window.ActiveXObject)
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		else if (window.XMLHttpRequest)
			xmlHttp = new XMLHttpRequest();

		if (xmlHttp != null) {
			xmlHttp.onreadystatechange = function(){processsubChange(fldcat, fldsub)};
			//alert(url + catid);
			xmlHttp.open("GET", url + catid + '&nocache=' + hour + '-' + minute + '-' +  second, true);
			xmlHttp.send(null);
		} else {
//			alert('Your browser does not support XMLHTTP.');
		}
	} else { document.getElementById(fldsub).disabled = true; }
}   
   
function processsubChange(fldcat, fldsub) {
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
			//alert(xmlHttp.responseText);
			/*var response = xmlHttp.responseXML;
			var cy = response.getElementsByTagName('subcatname');
			var st = response.getElementsByTagName('subcatid');
			var scsel = document.getElementById(fldsub);
			
			scsel.options.length = cy.length;
			
			alert('cy.length = ' + cy.length);
			
			for (i=0;i<cy.length;i++){
				//alert(cy[i].childNodes[0].nodeValue);
				document.getElementById(fldsub).options[i].value = st[i].childNodes[0].nodeValue;
				document.getElementById(fldsub).options[i].text = cy[i].childNodes[0].nodeValue;
				
				//alert(cy[i].childNodes[0].nodeValue);
			}
			document.getElementById(fldsub).disabled = false;*/
			
			document.getElementById(fldsub).innerHTML = xmlHttp.responseText;
		} else {
			alert('There was a problem retrieving the XML data:\n' + xmlHttp.statusText);
		}
	}
}

function disable_element(fld){
	document.getElementById(fld).disabled = true;
}