/*
* Copyright (C) 2006 Kaleidoscope Information Services, Inc.
* AjaxSelectedAds.js
* This is the client-side AJAX for the Selected Ads 
* it simply adds or subtracts an ad from the session array which tracks them.
* $_SESSION['selected_ads'] is the array which tracks the selected ads
*/
var req;
////////////////////////////////////////////////////
// SAFE GET VALUE
// gets an XML value
// traps errors if the var not there
////////////////////////////////////////////////////
function safeGetValue(req,tagName) {
	try {
		var nodeValue		= req.responseXML.getElementsByTagName(tagName)[0].firstChild.nodeValue;
	}
	catch (e) {
		if(e['name']== 'TypeError') {
			nodeValue='';
		}
	}
	return nodeValue;
}
////////////////////////////////////////////////////
// MANAGE SELECTE ADS
// sends a request to AjaxSelectedAds.xml (AjaxSelectedAds.inc.php)
////////////////////////////////////////////////////
function manageSelecteAds(item_id) {
	// Browser specific code
	if (window.XMLHttpRequest) {
		// Non-IE
		req = new XMLHttpRequest();
		if (!req) {
			alert('XMLHttpRequest object error');
			return;
		}
	} else if (window.ActiveXObject) {
		// IE
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (!req) {
			alert('activex error');
			return;
		}
	}
	obj = document.getElementById(item_id);
	// Get the values to send
	if(obj.className=='ad') {
		var action = 'ADD';
		obj.className='ad highlight';
	} else {
		var action = 'DEL';
		obj.className='ad';
	}

	// Setup the response function(below)
	req.onreadystatechange = manageSelecteAdsResponse;
	req.open("POST", '../a/AjaxSelectedAds.xml', true);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	// These are the POST variable in n1=v1&n2=v2 format
	var args='action=' + action + '&item_id=' + item_id;
	//alert(args);
	req.send(args);
}
////////////////////////////////////////////////////
// MANAGE SELECTE ADS RESPONSE
// Handles the response from the request sent by manageSelecteAds()
////////////////////////////////////////////////////
function manageSelecteAdsResponse() {
	// nothing to do
}

// --></script>}
