/**
 * 
 * @param {Form} frm
 */
function addToCart(frm){
	try{
		//get the form variables
		var prodId = frm.elements['product'].value;
		var qty = frm.elements['qty'].value;
		
		//submit the request to server using the iframe
		var page = "/cart/script/cart_popup.php";
		var prams = "?product=" + prodId;
		prams += "&qty=" + qty;
		
		//iframe request
		window.frames['server'].location.href = page + prams;
		
		return false;
	}catch(err){
		return true;
	}
}

/**
 * 
 * @param {Document} popup
 */
function handlePopup(doc){
	//remove any old popups that haven't been closed yet
	closePopup();
	
	//add it to the body first
	var popup = document.createElement("div"); 		//doing this becasue IE error when copying the element from page
	popup.id = "pop_cart";							//to another fails so make a new element and use innerHTML.
	popup.innerHTML = doc.getElementById('pop_cart').innerHTML;
	document.body.appendChild(popup);
	//body.appendChild(popup);
	
	//move the box to the center of the page
	
	var winMid = document.documentElement.clientWidth / 2;
	var winCenter = document.documentElement.clientHeight / 2;
	
	var	winLeft
	var	winTop
	if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)){
		winLeft = document.documentElement.scrollLeft;
		winTop = document.documentElement.scrollTop;
	}else{
		winLeft = document.body.scrollLeft;
		winTop = document.body.scrollTop;
	}


	
	var popLeft = winMid + winLeft - (popup.clientWidth / 2);
	var popTop = winTop + winCenter - (popup.clientHeight / 2);
	
	popup.style.top = popTop + "px";
	popup.style.left = popLeft + "px";

}

function closePopup(){
	var popup = document.getElementById("pop_cart");
	if(popup)
		popup.parentNode.removeChild(popup);
}

