swappableSectionIDGlobal = "";
valueGlobal = "";

function xmlOpen(method, url, toSend, responseHandler)
 { 	 	
     if (window.XMLHttpRequest)
     {
         // browser has native support for XMLHttpRequest object
         req = new XMLHttpRequest();
     }
     else if (window.ActiveXObject)
     {
         // try XMLHTTP ActiveX (Internet Explorer) version
         req = new ActiveXObject("Microsoft.XMLHTTP");
     }
     
     if(req)
     {	 	
         req.onreadystatechange = responseHandler;
         req.open(method, url, true);
         req.setRequestHeader("content-type","application/x-www-form-urlencoded");
         req.send(toSend);
     }
     else
     {
         alert('Your browser does not seem to support XMLHttpRequest.');
     }
 } 

function addCookieDestinationPortal(value,swappableSectionID){
	swappableSectionIDGlobal = swappableSectionID;
	valueGlobal = value;

	var strFullURL = 'cookieHandler.cfm?action=Add&value='+value;
	xmlOpen('GET',strFullURL,'', addCookieResponseHandler);				
}

function removeCookieDestinationPortal(value,swappableSectionID){
	swappableSectionIDGlobal = swappableSectionID;
	valueGlobal = value;

	var strFullURL = 'cookieHandler.cfm?action=Remove&value='+value;	
	xmlOpen('GET',strFullURL,'', removeCookieResponseHandler);				
}

function addCookieResponseHandler(){
	// Make sure the request is loaded (readyState = 4)
     if (req.readyState == 4)
     {
         // Make sure the status is "OK"
         if (req.status == 200)
         {
		 	// alert(req.responseXML);		 	
		 	var ajaxresponse = req.responseXML.getElementsByTagName('returnMessage');
		 	if (ajaxresponse.item(0).firstChild.nodeValue != 'Failure')
		 		var swappableSection = document.getElementById(swappableSectionIDGlobal);
		 		str = '<a href="javascript:removeCookieDestinationPortal(\'' + valueGlobal +'\',\'' + swappableSectionIDGlobal +'\');"><img src="images/btn_remove.png" alt="Remove" width="55" height="14" align="absmiddle" border="0"></a>';
		 		swappableSection.innerHTML = str;		 	
		 		
		 		var ActivitySearchID = document.getElementById('ActivitySearchID');	
		 		//ActivitySearchID.innerHTML = ajaxresponse.item(0).firstChild.nodeValue;
				ActivitySearchID.value = ajaxresponse.item(0).firstChild.nodeValue;
         }
         else
         {
             alert("There was a problem retrieving the XML data:\n" +
                     req.statusText);
         }
     }	
}

function removeCookieResponseHandler(){
	// Make sure the request is loaded (readyState = 4)
     if (req.readyState == 4)
     {
         // Make sure the status is "OK"
         if (req.status == 200)
         {
		 	// alert(req.responseXML);		 	
		 	var ajaxresponse = req.responseXML.getElementsByTagName('returnMessage');
		 	
		 	if (!ajaxresponse.item(0).hasChildNodes()){
		 		newtext=req.responseXML.createTextNode("");
		 		ajaxresponse.item(0).appendChild(newtext);
		 	}
		 		
		 	if (ajaxresponse.item(0).firstChild.nodeValue != 'Failure')
		 		var swappableSection = document.getElementById(swappableSectionIDGlobal);
		 		str = '<a href="javascript:addCookieDestinationPortal(\'' + valueGlobal +'\',\'' + swappableSectionIDGlobal +'\');"><img src="images/btn_add.png" alt="Add" width="35" height="14" align="absmiddle" border="0"></a>';
		 		swappableSection.innerHTML = str;		 	
		 		
		 		var ActivitySearchID = document.getElementById('ActivitySearchID');	
		 		//ActivitySearchID.innerHTML = ajaxresponse.item(0).firstChild.nodeValue;
				ActivitySearchID.value = ajaxresponse.item(0).firstChild.nodeValue;
         }
         else
         {
             alert("There was a problem retrieving the XML data:\n" +
                     req.statusText);
         }
     }	
}
