
//EVENTS
//function onLoad() {
//	var wishlist = "";
//	if(document.getElementById('wishlist')){
//		document.getElementById('wishlist').innerHTML = wishlist;
//	}
//}


//AJAX REMOTE REQUEST
/**
** The basic approach is to call this function sndReq('foo') 'foo' is the ID of the html tag where you want the inner content replaced.
** e.g.  <div id="foo"> </div>
**/
function createRequestObject() {
    var ro; var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){ro = new ActiveXObject("Microsoft.XMLHTTP");}else{ro = new XMLHttpRequest();}//ends if else
    return ro;
	}

var http = createRequestObject();

function sndReq(id) {
    //alert("sndReq(id) called");
    http.open('GET', '/fileadmin/templates/final/wishlist/addremove.php?id=' + id);
    http.onreadystatechange = handleResponse;
    http.send(null); //used for POST vars
	}//ends function

function handleResponse() {
    if(http.readyState == 4){
        var response = http.responseText;
        var update = new Array();
		// me|hide|show|data|wishlist
        if(response.indexOf('|' != -1)) {
            update = response.split('|');
	
	//alert("handleResponse called: " + update[0] + " : " + update[1]);
	//GET VARS FROM RESPONSE STRING
	var clicked = update[0];
	var message = update[1];
	var wishlistHTML = update[2];

	if (document.getElementById("m"+update[0])) {
		//update the new div
		//document.getElementById("m"+update[0]).innerHTML = " <b>" + message + "</b>";
		if(message=='Added!'){
			document.getElementById(update[0]).innerHTML = "<img src='/fileadmin/removefromlist.gif'>";
		}else{
			document.getElementById(update[0]).innerHTML = "<img src='/fileadmin/addtowishlist.gif'>";
		}
		} else {
		//create the new div
		var newDiv = null;
		var reference = document.getElementById(update[0]);
		newDiv = document.createElement("b");
		newDiv.id="m"+update[0];
		//newDiv.innerHTML = " <b>" + message + "</b>";
		if(message=='Added!'){
			document.getElementById(update[0]).innerHTML = "<img src='/fileadmin/removefromlist.gif'>";
		}else{
			document.getElementById(update[0]).innerHTML = "<img src='/fileadmin/addtowishlist.gif'>";
		}
		reference.parentNode.insertBefore(newDiv,reference.nextSibling);
			}
			//now update the wishlist total div with the new values
			//document.getElementById("wishlistitems").innerHTML = "<p>" + wishlistHTML + "</p><br>";
			document.getElementById("wishlistitems").innerHTML = "<div id=wishlistitems><p><b>Wishlist items:</b><br>" + wishlistHTML + "</p><p>Items added to your wishlist are remembered until you visit the contact page where they are listed to help you ask us for more information...</p></div>";
        }//ends if
    }//ends if
}//ends function

//file data.html

