var searchReq = getXmlHttpRequestObject();
var globalSitename = '';


function addToCart(str_site,str_id,str_title,str_image){
	showSupaLayers('#cartLoad');
	globalSitename = str_site;
	if (searchReq.readyState == 4 || searchReq.readyState == 0) {	
		searchReq.open("GET", '/' + str_site + '/utils/addToCart.cfm?id=' + str_id + '&title='+str_title+ '&image='+str_image, true);
		searchReq.send(null);
		searchReq.onreadystatechange = getCartAfterAction;
	}	
	
}


function hideCart(){
	hideSupaLayers('#cartLoad');
	hideSupaLayers('#cartDetail');		
}

function deleteCartItem(id){
	$("#cartDetail").hide();
	showSupaLayers('#cartLoad');
		
	if (searchReq.readyState == 4 || searchReq.readyState == 0) {	
		searchReq.open("GET", '/' + globalSitename + '/utils/deleteCartItem.cfm?id='+id, true);
		searchReq.send(null);
		searchReq.onreadystatechange = getCartAfterAction;
	}	
	
}

function clearCart(){
	$("#cartDetail").hide();
	showSupaLayers('#cartLoad');
		
	if (searchReq.readyState == 4 || searchReq.readyState == 0) {	
		searchReq.open("GET", '/' + globalSitename + '/utils/clearCart.cfm', true);
		searchReq.send(null);
		searchReq.onreadystatechange = getCartAfterAction;
	}	
	
}

function getCartAfterAction(){
	
	if (searchReq.readyState == 4 ) {
		searchReq = getXmlHttpRequestObject();
		
		if (searchReq.readyState == 4 || searchReq.readyState == 0) {	
			searchReq.open("GET", '/' + globalSitename + '/utils/getCart.cfm', true);
			searchReq.send(null);
			searchReq.onreadystatechange = showCart;
		}	
	}
	
}

function showCart(){
	
	if (searchReq.readyState == 4) {
		
		if(searchReq.status == 200){
			document.getElementById('cartContent').innerHTML = searchReq.responseText;
			$("#cartLoad").hide();
			$("#cartDetail").show();
		}else{
			$("#cartLoad").hide();
			alert('ERROR');
		}
		
	
	}
	
}

function addToMySpace(str_site,str_id,str_title,str_image){
	showSupaLayers('#cartLoad');
	globalSitename = str_site;
	if (searchReq.readyState == 4 || searchReq.readyState == 0) {	
		searchReq.open("GET", '/' + str_site + '/utils/addToMyspace.cfm?id=' + str_id + '&title='+str_title+ '&image='+str_image, true);
		searchReq.send(null);
		searchReq.onreadystatechange = goToMySpace;
	}	
	
}

function goToMySpace(){
	$("#cartLoad").hide();
	goToMySpaceOrNot();
}

