function AddCurrentItemToCart(frmAdd)
{
    CartValidateSize(frmAdd.txtProductID.value,frmAdd.txtCartQuantity.value,frmAdd.lstOrder,frmAdd);
}
	
function ShowWindow(strUrl,strName)
{
	var nWidth  = 650;
	var nHeight = 450;
	var strCenter = "top=" + (screen.width - nWidth) / 2 + ",left=" + (screen.height - nHeight) / 2;
	
	wndWindow = window.open(strUrl,strName,"width="+nWidth+",height=" + nHeight + "," + strCenter);
	wndWindow.focus();

}
function ChangeUrl(strUrl)
{
	bMoving = true;
	document.location.href = strUrl;
}
function AddToCart(strId,nQuantity,nWidth,nLength,strOrderBy)
{
	var strUrl = "cart_add.asp?ID=" + strId + 
							  "&Quantity=" + nQuantity + 
							  "&Width=" + nWidth + 
							  "&Length=" + nLength +
							  "&OrderBy=" + strOrderBy;
							  
	var strOrderResult = xmlPoster(strUrl);
	if(strOrderResult == "Confirm.Back.Order")
	{
	    if( confirm("This product is currently out of stock, would you like to back order?") )
	    {
	        alert(xmlPoster(strUrl + "&BackOrder=True"));
	    }
	}
	else
	{
	    alert(strOrderResult)
	}
}
function CartValidateSize(strId,nQuantity,lstToCheck,frmAdd)
{
	// Check if size selected
	if(lstToCheck.selectedIndex == 0 && lstToCheck.length > 1)
	{
		alert("Please select the product's size");
	}
	else
	{
		var nLength = frmAdd.txtLength;
		var nWidth  = frmAdd.txtWidth;
		var strOrderBy = frmAdd.lstOrderBy.value;
		
		// Check if length is entered
		if(nLength != null && nLength.value == "")
		{
			alert("Please select the product's length");
			nLength.focus();
		}
		// Check if length is entered
		else if(nWidth != null && nWidth.value == "")
		{
			alert("Please select the product's width");
			nWidth.focus();
		}
		else
		{
			if(nWidth != null && nLength != null)
				AddToCart(lstToCheck.value,nQuantity,nWidth.value,nLength.value,strOrderBy);
			else
				AddToCart(lstToCheck.value,nQuantity,0,0,strOrderBy);
		}	
	}
}
	
// XML poster
function xmlPoster(strUrl)
{	
	try
	{
		var xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP")
	}
	catch(e)
	{
		var xmlHTTP = new XMLHttpRequest();
	}

	// Show loading
	window.status = "Loading...Please wait...";
	parent.document.getElementById("fraProgress").style.display = 'block';
	
	// Get data from Url
	xmlHTTP.open("GET", strUrl, false);
	xmlHTTP.setRequestHeader('Pragma','no-cache');
    xmlHTTP.setRequestHeader('Cache-Control', 'no-cache');
	xmlHTTP.send("?Rand=" + Math.random());	

	// Remove loading
	parent.document.getElementById("fraProgress").style.display = 'none';
	window.status = "";
	return(xmlHTTP.responseText)
}
function MenuRedirect(strPageName)
{
	document.location.href = strPageName;
}	