//Replaces originsl site function with custom for GWO experiments
/*

Experimental code:
<a href="javascript:;" onclick="addToReport(279,'WC2H~PostcodeOutward','Garrick Street, London, WC2E','viewing');revealViewingDate();return false;"><img id="viewing279" src="../imgs/but_viewing.jpg" width="138" height="37" border="0" /></a>
<script>utmx_section("Add Button Test")</script>
<a href="javascript:;" onclick="addToReport(279,'WC2H~PostcodeOutward','Garrick Street, London, WC2E','quote');return false;"><img id="quote279" src="../imgs/but_quote.jpg" width="122" height="37" border="0" /></a>
<a href="javascript:;" onclick="addToReport(279,'WC2H~PostcodeOutward','Garrick Street, London, WC2E','add');return false;"><img id="add279" src="../imgs/but_add.jpg" width="169" height="37" border="0" /></a></td>

set namespace to store


*/

GGWO = {
    btnAddImageSrc: '../imgs/but_add.gif',
    btnAddedImageSrc: '../imgs/but_added.gif',
    GGgetPrevious: function(el) {
	var prev=el;
	while(prev=prev.previousSibling) {
	    if(!(prev.nodeType==8||/^[\t\n\r ]+$/.test(prev.data)))
		break
	    }
	return prev
    },
    GGgetNext: function(el) {
	var next=el;
	while(next=next.nextSibling) {
	    if(!(next.nodeType==8||/^[\t\n\r ]+$/.test(next.data)))
		break
	    }
	return next
    }
    
}


function addToReportCompleted(theID,searchedLocation,officeTitle,typeOfAdd) {
	if (checkListForID(theID)==false) {
		// Add the officeTitle to the display list
		var $listItem = document.createElement('li'); // create the li
		$listItem.setAttribute('id','listItem'+theID); // Give the li an id to allow for removing again
		var $listItemText = document.createTextNode(officeTitle+' '); // write the list item text
		$listItem.appendChild($listItemText); // Put the text into the li
		var $listItemLink = document.createElement('a'); // Create the a link
		$listItemLink.setAttribute('href','javascript:;'); // give it a href
		$listItemLink.onclick = function(){removeFromReport(theID);};
		var $listItemLinkText = document.createTextNode('remove'); // create the link text
		$listItemLink.appendChild($listItemLinkText); // append the link text to the link
		$listItem.appendChild($listItemLink); // append the link to the li text
		// Now put it into the list
		var $officeList = document.getElementById('officeList'); // Get the reference to the ul
		$officeList.appendChild($listItem); // put the link into the document
	}

	// Switch the images on the page
	document.images['add'+theID].src=GWObtnAddedImageSrc; // Switch the Add to Report image
	document.images['add'+theID].blur(); // Remove the focus from it


	if (typeOfAdd=='quote') {
		document.images['quote'+theID].src='../imgs/but_quote_requested.gif'; // Switch the Add to Report image
		document.images['quote'+theID].blur(); // Remove the focus from it
	 }

	if (typeOfAdd=='viewing') {
		document.images['viewing'+theID].src='../imgs/but_viewing_requested.gif'; // Switch the Add to Report image
		document.images['viewing'+theID].blur(); // Remove the focus from it
	 }

	// Alert if its the first office to be added
//	alertMe();

}

function removeFromReport(theID) {
	// Remove the ID from all the parts of the cookie
	window["addRep"].location.href='removeFromReport.asp?ID='+theID; // Add to cookie via the iFrame

	// Switch the images on the page back to original state
	if (document.images['add'+theID] != undefined) { // If the listing is on this page, then swap the images back
		document.images['add'+theID].src=GWObtnAddImageSrc;
	}
	if (document.images['quote'+theID] != undefined) { // If the listing is on this page, then swap the images back
		document.images['quote'+theID].src='../imgs/but_quote.jpg';
	}
	if (document.images['viewing'+theID] != undefined) { // If the listing is on this page, then swap the images back
		document.images['viewing'+theID].src='../imgs/but_viewing.jpg';
	}

	// Remove from the display list
	var $liToRemove = document.getElementById('listItem'+theID);
	var $officeList = document.getElementById('officeList');
	$officeList.removeChild($liToRemove);

}
