/************************************************************* * JavaScript functions supporting AJAX access to category and  * location tables and the building of the <select> dropdown lists */var useAJAX = true;var xmlOptions;var spanIds = {"country":"Country", "state":"State", "city":"City"};var adminPath = ""; // this is necessary for processing admin_add_img_frm/** * When the category changes this function issues an XMLHttpRequest to cat2Handler.php * which returns the HTML <select>...</select> for the appropriate subcategory. The * responseText is simply assigned to the innerHTML of a <span id="subcat"> on the page. */function categoryChange(){	var category = document.getElementById('category');	var index = category.selectedIndex;	var data = category.options[index].value;	var callback = {		success: function(respText, respXML){			var obj = document.getElementById('subcat');			obj.innerHTML = respText;		},		failure: function(status){ alert("Ajax Failure: " + status);}	};		var myhandler = new SimpleHandler();	myhandler.requestUrlEncoding('POST', adminPath + 'cat2Handler.php', callback, 'category=' + data);}/** * When there is a location change this function constructs the appropriate * URL for an XMLHttpRequest which will return the XML for an array of <options> * for the <select> that is dependent on changes in the 'loc' parameter. *  * @param loc	a string identifying the 'id' of the location <select> element *			that has changed. */function locationChange(loc){	var domain = 'http://localhost/zummin/';	var source = 'regionHandler.php';	var id = "";	var rcode = "";	// region code, from region selection	var ccode = ""; // country code, from country selection	var scode = ""; // state code, from state selection	var data;	var index; 	var query;	var selObj;		// get the id ('country', 'state' or 'city') and the code (selection value)	// also build each selection's query string	switch(loc){		case 'region':			source = 'countryHandler.php';			id = "country";						// build the query string for the region			selObj = document.getElementById(loc);			index = selObj.selectedIndex;			rcode = selObj.options[index].value;			query = loc + "=" + rcode;			break;		case 'country':			source = 'stateHandler.php';			id = "state";						// 1st get the region's code (from the previous selection)			selObj = document.getElementById('region');			index = selObj.selectedIndex;			rcode = selObj.options[index].value;						// now build the query string for the country (the current selection)			selObj = document.getElementById(loc);			index = selObj.selectedIndex;			data = selObj.options[index].value;			query = 'region=' + rcode + "&" + loc + "=" + data;			break;		case 'state':			source = 'cityHandler.php';			id = 'city';						// get the country code from the country selection			selObj = document.getElementById('country');			index = selObj.selectedIndex;			ccode = selObj.options[index].value;						// now get the current location selection and build its query string			selObj = document.getElementById(loc);			index = selObj.selectedIndex;			data = selObj.options[index].value;			query = 'country=' + ccode + "&" + loc + "=" + data;			break;		default:			break;	}	var callback = {		success: function(respText, respXML){			var obj = document.getElementById('useAjax' + spanIds[id]);			obj.innerHTML = respText;		},		failure: function(status){ alert("Ajax Failure: " + status);}	};		var myhandler = new SimpleHandler();	myhandler.requestUrlEncoding('POST', adminPath + source, callback, query);}/** * This function will build the option list for the location <select> element whose * id matches. * * @param id	a string containing the 'id' attribute of <select> element * @param obj	a json object containing pairs; where key (or prop) is value in <Option value="prop">obj[prop]</Option> */function buildSelect(id, obj){	var selectControl = document.getElementById(id);	clearSelect(selectControl);	for (var prop in obj){		var newOption = document.createElement('option');		newOption.setAttribute('value', prop);		newOption.appendChild(document.createTextNode(obj[prop]));				selectControl.appendChild(newOption);	}}function clearSelect(selControl){	if (selControl){			// remove all options except the first one (which should be '-- Select --')		for (var i = 1; i < selectControl.options.length; i++){			selectControl.removeChild(selectControl.options[i]);		}	}}function voteYes(id){	var callback = {		success: function(respText, respXML){			alert(respText);		},		failure: function(status){ alert("Ajax Failure: " + status);}	};		var myhandler = new SimpleHandler();	myhandler.requestUrlEncoding('POST', adminPath + 'voteYesOnReview.php', callback, 'id=' + id);}function voteNo(id){	var callback = {		success: function(respText, respXML){			alert(respText);		},		failure: function(status){ alert("Ajax Failure: " + status);}	};		var myhandler = new SimpleHandler();	myhandler.requestUrlEncoding('POST', adminPath + 'voteNoOnReview.php', callback, 'id=' + id);}