function AddToWishlist(url,product){

	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request")
		return
	}

	var params = "product="+product+"&mode=add";

	xmlHttp.open("POST",url,true)
	//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");

	xmlHttp.onreadystatechange=stateChangedWishlist
	xmlHttp.send(params)
}

function DeleteFromWishlist(url,product){

	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request")
		return
	}

	var params = "product="+product+"&mode=delete";

	xmlHttp.open("POST",url,true)
	//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");

	xmlHttp.onreadystatechange=stateChangedWishlist
	xmlHttp.send(params)
}

function stateChangedWishlist(){

	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){

		if(document.getElementById("server")) {
			document.getElementById("server").style.display="none";
		}
		
		stringResponse = xmlHttp.responseText;

		//MESSAGES
		if(document.getElementById("wishlist_messages")) {
			start_messages = stringResponse.indexOf('<!--%START_WISHLIST_MESSAGES%-->');
			end_messages = stringResponse.indexOf('<!--%END_WISHLIST_MESSAGES%-->');
			part_messages = stringResponse.slice(start_messages, end_messages);
			document.getElementById("wishlist_messages").innerHTML=part_messages;
		}

		//PRODUCTS
		if(document.getElementById("prod_boxes")) {
			start_products = stringResponse.indexOf('<!--%START%-->');
			end_products = stringResponse.indexOf('<!--%END%-->');
			part_products = stringResponse.slice(start_products, end_products);
			document.getElementById("prod_boxes").innerHTML = part_products
		}

		// BOTTOM PAGINATION
		if(document.getElementById("pagNr")) {
			start_pg = stringResponse.indexOf('<!--%START_PG%-->');
			end_pg = stringResponse.indexOf('<!--%END_PG%-->');
			part_pg = stringResponse.slice(start_pg, end_pg);
			document.getElementById("pagNr").innerHTML = part_pg
		}

		setFade();
	}else{
		if(document.getElementById("server")) {
			document.getElementById("server").style.display="block";
		}
	}
}

function GetXmlHttpObject(){
	var xmlHttp=null;
	try{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}catch (e){
		//Internet Explorer
		try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}catch (e){
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}
