﻿function processOrder(toemail,fromemail,subject,orderid) {
	var oXMLHTTP = GetXmlHttpObject();
	var myForm		= document.Paypal_Form;
	var sURL;
	var strBillShip = document.getElementById('billshipinfo').value;  //Grabs strReview content from textarea
	
	sURL = "../store/functions.asp?t=placeorderemail&to="+toemail+"&from="+fromemail+"&subject="+subject+"&orderid="+orderid+"&billship="+strBillShip;
	oXMLHTTP.open( "GET", sURL, false );
	oXMLHTTP.send(null);
	if(oXMLHTTP.responseText=="1") {
		alert("One Moment While We Process Your Order.  You will be directed to make your payment once processing is complete.  Thank you!");
		myForm.submit()
	} else {
		alert(oXMLHTTP.responseText);													
		
		}
}

function doAuthorizationProcess(userid,authparam,email) {

	var oXMLHTTP = GetXmlHttpObject();
	var sURL;
		
	sURL = "functions.asp?t=admin-ws&userid="+userid+"&authparam="+authparam+"&email="+email;
	oXMLHTTP.open( "GET", sURL, false );
	oXMLHTTP.send(null);
	if(oXMLHTTP.responseText=="1") {
		document.getElementById('options').innerHTML='Wholesale Account Action Completed<br/><a href="../">Return to Website</a>';
		if(authparam=='no' || authparam=='yesman') {
			document.location.href='mailto:'+email+'?subject=Wholesale Account' }
		
	} else {
		alert(oXMLHTTP.responseText);													
		
		}

}
function applyCoupon(orderid,userid) {

	var oXMLHTTP = GetXmlHttpObject();
	var sURL;
	var coupon	= document.getElementById('coupon').value;	
	
	if(coupon=="NULL" || coupon=="") {
		alert('Please enter a valid coupon or Gift Card Number'); } 
	else {
		document.getElementById('coupon').style.background="../store/waiting-sm.gif";
		sURL = "../store/functions.asp?t=applycoupon&userid="+userid+"&coupon="+coupon+"&orderid="+orderid;
		oXMLHTTP.open( "GET", sURL, false );
		oXMLHTTP.send(null);
		if(oXMLHTTP.responseText=="1") {
			document.location.href="checkout-step3.asp";		
		} else {
			if(oXMLHTTP.responseText=="nocoupon") {
				alert('This coupon was entered incorrectly, has expired or has been redeemed.'); }
			if(oXMLHTTP.responseText=="expired") {
				alert('This coupon has expired or has been redeemed.'); }														
			}
	}		
}

function getPrice(pID) {
	document.body.style.cursor ="wait";
	var oXMLHTTP = GetXmlHttpObject();
	var sURL;
	var priceBlock	= "price"+pID;
	var sizeBlock	= "size"+pID;												
	var size		= document.getElementById(sizeBlock).value;
	if (size!="0|0") {
	sURL = "../store/functions.asp?t=getprice&pid="+pID+"&sizeid="+size;
	oXMLHTTP.open( "GET", sURL, false );
	oXMLHTTP.send(null);
	if(oXMLHTTP.responseText=="OOS") {
		alert("We're sorry, we are currently out of this size.  Please try a different size or contact us to find out when it will be back in stock.");
	} else {
		var str = oXMLHTTP.responseText;													
		document.getElementById(priceBlock).innerHTML= oXMLHTTP.responseText+"ea.";
		getAvailableQty(pID);
		getAccessory(pID);
		document.getElementById('addtobag'+pID+'').style.visibility='visible';
		};
		} else {
			getAvailableQty(pID);
			getAccessory(pID);


		}
	}
function getAvailableQty(pID) {
	var oXMLHTTP = GetXmlHttpObject();
	var sURL;
	var qtyBlock	= "qty" + pID;
	var sizeBlock	= "size" + pID;
	var size		= document.getElementById(sizeBlock).value;
	sURL = "../store/functions.asp?t=getqty&pid="+pID+"&sizeid="+size;
	oXMLHTTP.open( "GET", sURL, false );
	oXMLHTTP.send(null);
	if(oXMLHTTP.responseText=="OOS") {
		alert("We're sorry, we are currently out of this size.  Please try a different size or contact us to find out when it will be back in stock.");
	} else {
		var str = oXMLHTTP.responseText;													
		document.getElementById(qtyBlock).innerHTML= oXMLHTTP.responseText;
		};
	}
	function getAccessory(pID) {
		var oXMLHTTP = GetXmlHttpObject();
		var sURL;
		var accessoryBlock	= "accessory" + pID;
		var sizeBlock	= "size" + pID;
		var size		= document.getElementById(sizeBlock).value;
		sURL = "../store/functions.asp?t=getaccessories&pid="+pID+"&sizeid="+size;
		oXMLHTTP.open( "GET", sURL, false );
		oXMLHTTP.send(null);
		if(oXMLHTTP.responseText=="OOS") {
			//alert("We're sorry, we are currently out of this size.  Please try a different size or contact us to find out when it will be back in stock.");
		} else {
			var str = oXMLHTTP.responseText;													
			document.getElementById(accessoryBlock).innerHTML= oXMLHTTP.responseText;
			document.body.style.cursor ="default";
			};
	}															
		function addtobag(pID) {
			if(document.getElementById('size'+pID+'').value=='0|0') {alert('Please select a size and quantity to add this to your bag');	} 
			else {
			
				var buySize		= document.getElementById('size'+pID+'').value.replace(pID+'|','');
			
				
				var buyQty		= document.getElementById('buyqty'+pID+'').value;
				var buyAccessory= document.getElementById('buyaccessory'+pID+'').value;
				var sError		= "";
				if (buySize=="--") { sError=sError+"\nSelect a Size"; }
				if (buyQty==0) { sError=sError+"\nSelect Quantity"; }
				
				if (sError!="") {
					alert('Please fix the following:\n\n'+sError);
				//	alert('Buying Item #'+pID+'\nSize:'+buySize+'\nQty:'+buyQty+''); 
					} else {
						var oXMLHTTP = GetXmlHttpObject();
						var sURL;
						sURL = "../store/functions.asp?t=addtobag&pid="+pID+"&sizeid="+buySize+"&qty="+buyQty+"&accessory="+buyAccessory;
						oXMLHTTP.open( "GET", sURL, false );
						oXMLHTTP.send(null);
						if(oXMLHTTP.responseText!="") {
							alert(oXMLHTTP.responseText);
							} else {
								alert('Added to bag');												
								document.body.style.cursor ="default";
							};															
					}
			}
		}
	function displayCart() {
		document.body.style.cursor ="wait";
		document.getElementById('cartcontents').innerHTML='<img src="../store/loading.gif"/>';
		var oXMLHTTP = GetXmlHttpObject();
		var sURL;
		sURL = "../store/functions.asp?t=displaycart";
		oXMLHTTP.open( "GET", sURL, false );
		oXMLHTTP.send(null);
		if(oXMLHTTP.responseText=="") {
			alert("There was an error.");
		} else {
			document.getElementById('cartcontents').innerHTML= oXMLHTTP.responseText;
			document.body.style.cursor ="default";
			};
		}
		
	function removeItem(itemID) {
		if(confirm('Are you sure you want to remove this item?')) {
			document.body.style.cursor ="wait";
			document.getElementById('cartcontents').innerHTML='<img src="../store/loading.gif"/>';
			var oXMLHTTP = GetXmlHttpObject();
			var sURL;
			sURL = "../store/functions.asp?t=removeitem&itemid="+itemID;
			oXMLHTTP.open( "GET", sURL, false );
			oXMLHTTP.send(null);
			if(oXMLHTTP.responseText!="") {
				document.body.style.cursor ="default";
				alert("There was an error."+oXMLHTTP.responseText);
			} else {
				displayCart();
				};
		}
	}
	function updateItem(itemID) {
			document.body.style.cursor ="wait";

			var oXMLHTTP= GetXmlHttpObject();
			var sURL;
			var itemQty	= document.getElementById('buyqty'+itemID).value;
			document.getElementById('cartcontents').innerHTML='<img src="../store/loading.gif"/>';
			
			sURL = "../store/functions.asp?t=updateitemqty&itemid="+itemID+"&itemqty="+itemQty;
			oXMLHTTP.open( "GET", sURL, false );
			oXMLHTTP.send(null);
			if(oXMLHTTP.responseText!="") {
				document.body.style.cursor ="default";
				alert("There was an error."+oXMLHTTP.responseText);
			} else {
				displayCart();
				};


	}
