function getQueryVariable(variable)
{
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++)
{
var pair = vars[i].split("=");
if (pair[0] == variable)
{
return pair[1];
}
}
} 

function CheckOut () {
	var theDiv = document.getElementById('new_action');
	var theDiv2 = document.getElementById('CheckOutFinalizedButton');
	
	
	if (getQueryVariable('ship')!='1') {
	alert('Please fill in the shipping information for this gift order and click CONTINUE.');
	}
	theDiv.style.display='none';
	if (divObj = document.getElementById("CheckOutFinalizedButton")) {
	theDiv2.style.display='none';
	}
	ShowShipping();
	var theBilling = document.getElementById('BillingAddress');
	var theAddress = document.getElementById('Address1');
	if (theAddress.value=='') {
		theBilling.checked = true;
	}
	document.getElementById('FirstName').focus();
}

function ShowCustomer () {
	var CustomerID = document.getElementById('CustomerID').value;
	
	if (CustomerID=='' || CustomerID=='0') {
		dojo.widget.byId("tabReturningCustomer").setUrl("customer_login.asp");
	}
	else {
		dojo.widget.byId("tabReturningCustomer").setUrl("shipping_addresses.asp");
	}
	
	dojo.widget.byId('Customer').show();
}

function HideCustomer() {
	dojo.widget.byId('Customer').hide();
}


function SelectShippingAddress(ShippingAddressID, BuyerCustomerID) {
	xmlhttpPost_copy_shipping_address ('shipping_address_get.asp',ShippingAddressID, BuyerCustomerID)
}


function xmlhttpPost_copy_shipping_address(strURL, ShippingAddressID, BuyerCustomerID) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
           
            updatepage_copy_shipping_address(self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(getquerystring_copy_shipping_address(ShippingAddressID, BuyerCustomerID));
} 	

function getquerystring_copy_shipping_address(ShippingAddressID, BuyerCustomerID) {

	var ShippingAddressID = ShippingAddressID;
	var BuyerCustomerID = BuyerCustomerID;
	
    qstr = 'ShippingAddressID=' + escape(ShippingAddressID) + '&BuyerCustomerID=' + escape(BuyerCustomerID)
	
	return qstr;
}

function updatepage_copy_shipping_address(CustomerID){
	var str = CustomerID.split("|");
	document.getElementById('FirstName').value=str[0];
	document.getElementById('LastName').value=str[1];
	document.getElementById('Prefix').value=str[2];
	document.getElementById('Address1').value=str[3];
	document.getElementById('Address2').value=str[4];
	document.getElementById('City').value=str[5];
	document.getElementById('State').value=str[6];
	document.getElementById('Zip').value=str[7];
	//document.getElementById('EmailAddress').value=str[8];
	//document.getElementById('PhoneNumber').value=str[9];
	//document.getElementById('Greeting').value=str[10];
	document.getElementById('Country').value=str[11];
	
	dojo.widget.byId('Customer').hide();
}

