
function win(fileName, normwindowloc) {
	     contentWindow = window.open('','myWindow','scrollbars=yes,toolbar=1,location=1,status=no,width=760,height=550')
	     contentWindow.location.href = fileName;
		 contentWindow.focus();
		// this.location.href=normwindowloc;
		}

function replaceContent(id, str) {
	var type;
	// Determine browser stuff
	if (navigator.userAgent.indexOf("Opera")!=-1
    && document.getElementById) type="OP"; 
	if (document.all) type="IE";
	if (document.layers) type="NN";
	if (!document.all && document.getElementById) type="MO";
	
	//Replace content
	if (type=="IE") {
	    document.all[id].innerHTML = str;
	  }
	  if (type=="NN") {
	    document.layers[id].document.open();
	    document.layers[id].document.write(str);
	    document.layers[id].document.close();
	  }
	  if (type=="MO") {
	    document.getElementById(id).innerHTML = str;
	  }


}
function ChangeShipping() 
{
	//=======Submit=============
	document.form1.action ="/secure/processEComm.asp";
	document.form1.Action.value = 'UpdateShipping';
	document.form1.submit();
}
function LoadAddress(script, AddressType, userID, strMode) 
{
	//=======Submit=============
	document.form1.action ="/secure/" + script;
	document.form1.Action.value = AddressType;
	document.form1.submit();
}
function ChooseWillCallOption(checkForm, shipViaID) 
{
	//=======Submit=============
	//document.form1.action ="/secure/" + script;
	document.form1.willCallOptions.value = shipViaID;
	var pageElement = document.getElementById(checkForm);
	
	//alert(pageElement.checked);
	if (pageElement.checked){
		document.form1.Action.value = 'ChooseWillCallOption';
		
		// Clear other check boxes
		/*var theForm = document.form1, z = 0;
     	while (theForm[z].type == 'checkbox' && theForm[z].name.substring(0,21) == 'chooseWillCallOptions') {
      		alert(theForm[z].name);
			theForm[z].checked = false;
      		z++;
     	}*/
	}
	else
	{
		document.form1.Action.value = 'RestoreDefaultShippingAddress';
	}
	document.form1.submit();
}
function ChangePaymentOrderOptions(script, userID, strMode) 
{
	//=======Submit=============
	document.form1.action =script;
	document.form1.Action.value = 'ChangePaymentOrderOptions';
	document.form1.submit();
}
function AddItemsToCart()
{
	//=======Submit=============
	//alert("JavaScript - AddItemsToCart()")
	document.form1.action ="/secure/processEComm.asp";
	document.form1.Action.value = 'AddItemsToCart';
	//alert("JavaScript - AddItemsToCart() pause at end of function")
	document.form1.submit();
}
function AddToCart()
{
	//=======Submit=============
	document.form1.action ="/secure/processEComm.asp";
	document.form1.Action.value = 'AddToCart';
	document.form1.submit();
}
function UpdateCartItem(itemID) 
{
	//=======Submit=============
	document.form1.action ="/secure/processEComm.asp";
	document.form1.Action.value = "UpdateCartItem";
	document.form1.CartItemID.value = itemID
	document.form1.submit();
}
function RemoveCartItem(itemID) 
{
	//=======Submit=============
	document.form1.action ="/secure/processEComm.asp";
	document.form1.Action.value = "RemoveCartItem";
	document.form1.CartItemID.value = itemID
	document.form1.submit();
}
function UpdateAllItems() 
{
	//=======Submit=============
	document.form1.ButtonAction.value = "Update";
	document.form1.submit();
}
function ProceedToPayment(secureURL)
{
	//=======Submit=============
	document.form1.action =secureURL + "/secure/processEComm.asp";
	document.form1.Action.value = 'ProceedToPayment';
	document.form1.submit();
}
function ProceedToVerify()
{
	//=======Submit=============
	document.form1.action ="/secure/processEComm.asp";
	document.form1.Action.value = 'ProceedToVerify';
	document.form1.submit();
}

function CheckOut(strLoc)
{
	//=======Submit=============
	document.form1.action ="/secure/processEComm.asp?l="+strLoc;
	document.form1.Action.value = 'Checkout';
	document.form1.submit();
}

function Purchase()
{
	//=======Submit=============
	document.form1.action ="/secure/processEComm.asp";
	document.form1.Action.value = 'Purchase';
	document.form1.submit();
}

// Global variable
var timerID;

function submitWaitingForm(){
	document.form1.action ="processecomm.asp";
	document.form1.Action.value = 'resubmit';
	document.form1.submit();
}

//=====================================================================
	function isOrderProcessed(orid){
// 	Method is passed a purchaseOrderID and continually polls until it finds out the
// 	result of the purchase attempt
//=====================================================================
		var pageElement = document.getElementById("processingMsg");
		var URLCall = "GetOrderStatus_AJAX.asp?orid=" + orid;
		var status
		//alert(URLCall);
		var answer = ajaxCall(URLCall);
//alert(answer);
		
		status = answer.substring(answer.indexOf("<orderStatus>")+13, answer.indexOf("</orderStatus>"));
		//alert(status);
		switch (status)
		{
			case "Pending":
				//Still waiting to hear back from system
				pageElement.innerHTML = 'Please wait while we process your order';
				setTimeout("isOrderProcessed('" + orid +"')", 1000);
				break;
			case "Wish List Pending":
				//Still waiting to hear back from system

				pageElement.innerHTML = 'Please wait while we process your order';
				setTimeout("isOrderProcessed('" + orid +"')", 1000);
				break;
			case "Wish List Pending0":
				
				//If other type of order status, forward on to the receipt page
				pageElement.innerHTML = "Your order has been " + status + ".  You will now be forwarded to a receipt page.  Click <a href=\"orderreceipt.asp?id=" + orid + "&l=OR\">here</a> if you do not get forwarded automatically.";
				clearInterval(timerID);
				document.form1.action ="orderreceipt.asp?id=" + orid + "&l=OR";
				document.form1.Action.value = '';
				// Submit form
				//document.form1.submit();
				 window.location="orderreceipt.asp?id=" + orid + "&l=OR";
				break;
				
			case "Canceled":
				//Give user notice and resubmit order
				//pageElement.innerHTML = "Your order has failed.  Please click <a href=""javascript:document.form1.submit()"" >here</a> to fix any problems and resubmit";
				pageElement.innerHTML = "Your order has failed.  Please click <a href=javascript:submitWaitingForm() >here</a> to fix any problems and resubmit.";
				
				// Show button in case form does not get submitted
				//document.getElementById("submitButton").style.display="block";

				clearInterval(timerID);
				document.form1.action ="processecomm.asp";
				document.form1.Action.value = 'resubmit';

				
				
				// Submit form
				//document.form1.submit();
				

				break;
			case "":
				//Order failed either NO RECORD or BAD VALUE
				pageElement.innerHTML = "We have encountered a problem with your order.  We have cancelled the order and have not charged your card.  Please click <a href=\"orderError.asp\">here</a> and try to place your order again.";
				clearInterval(timerID);			
				break;
			default:
				//If other type of order status, forward on to the receipt page
				pageElement.innerHTML = "Your order has been " + status + ".  You will now be forwarded to a receipt page.  Click <a href=\"orderreceipt.asp?id=" + orid + "&l=OR\">here</a> if you do not get forwarded automatically.";
				clearInterval(timerID);
				document.form1.action ="orderreceipt.asp?id=" + orid + "&l=OR";
				document.form1.Action.value = '';
				// Submit form
				//document.form1.submit();
				 window.location="orderreceipt.asp?id=" + orid + "&l=OR";
				break;
		}
		return false;
	}

//=====================================================================
function startupOrderProgressPolling(orid){
//	Method polls every half second to see if the order is processed
//=====================================================================		
	
	// Begin polling every three seconds
	isOrderProcessed(orid );
	return false;
}


//********************************************************************************************************************************
// Functions used in VerifyShipping.asp
// Sub functions

function disableCheckbox(){
	document.getElementById('confirmAddress').disabled = true;
}
function disableCheckout() {
	document.getElementById('ContinueCheckoutButton').disabled = true; 
	setColor('ContinueCheckoutButton','grey');
}
function disableVerify(){
	document.getElementById('ReVerifyAddressButton').disabled = true;
	setColor('ReVerifyAddressButton','grey');
}
function enableCheckbox(){
	document.getElementById('confirmAddress').disabled = false;
}
function enableCheckout() {
	document.getElementById('ContinueCheckoutButton').disabled = false;
	setColor('ContinueCheckoutButton','#780505');
}
function enableVerify() {
	document.getElementById('ReVerifyAddressButton').disabled = false;
	setColor('ReVerifyAddressButton','#780505');
}
//Main Fuctions
function textboxChange() {
	enableCheckbox();
	disableCheckout();
	enableVerify();
}
function onCheckboxChange(){
	if (document.getElementById('confirmAddress').checked == true)
		enableCheckout()
	else if(document.getElementById('confirmAddress').checked == false)
		disableCheckout()
	//alert(document.getElementById('confirmAddress').checked);
}
