function initialize() {
	doAction = document.getElementById("doAction");
	form = document.getElementById("cartForm");
	updateButton = document.getElementById("updateButton");
	if (updateButton != null) {
		updateButton.disabled = false;
		updateButton.onclick = updateCart;
	}
	googleButton = document.getElementById("googleButton");
	if (googleButton != null) {
		googleButton.disabled = false;
		googleButton.onclick = postToGoogle;
	}
	paypalButton = document.getElementById("paypalButton");
	if (paypalButton != null) {
		paypalButton.disabled = false;
		paypalButton.onclick = postToPaypal;
	}
	continueButton = document.getElementById("continueButton");
	if (continueButton != null) {
		continueButton.disabled = false;
		continueButton.onclick = continueShopping;
	}
	checkoutButton = document.getElementById('checkoutButton');
	if (checkoutButton != null){
		checkoutButton.disabled = false;
		checkoutButton.onclick = postToIDPShops;
	}
	applyCouponButton = document.getElementById('applyCouponButton');
	if (applyCouponButton != null){
		applyCouponButton.disabled = false;
		applyCouponButton.onclick = applyCoupon;
	}
	host = window.location.host;
}

function continueShopping() {
	continueButton.disabled = true;
	location = lastVisitedPageUrl;
	return false;
}

function postToPaypal() {
	paypalButton.innerHTML = "<span style='color:red;'>Please Wait ....</span>";
	paypalButton.disabled = true;
	form.action = "https://www.paypal.com/cgi-bin/webscr";
	form.submit();
	return false;
}

function postToIDPShops() {
	checkoutButton.innerHTML = "<span style='color:red;'>Please Wait ....</span>";
	checkoutButton.disabled = true;
	googleButton.disabled = true;
	
	if (host == 'www.testsite247.com') {
		form.action = "http://www.testsite247.com/inc/CheckoutNew.php";
	} else {
		form.action = "https://www.idpshops.com/inc/CheckoutNew.php";
	}
	pageTracker._linkByPost(form);
	form.submit();
	return false;
}

function updateCart() {
	updateButton.disabled = true;
	doAction.value = "UPDATE";
	form.action = "/ViewCart";
	form.submit();
	return false;
}

function applyCoupon() {
	applyCouponButton.disabled = true;
	doAction.value = "APPLY_COUPON";
	form.action = "/ViewCart";
	form.submit();
	return false;
}

function postToGoogle() {
	googleButton.disabled = true;
	doAction.value = "POST_TO_GOOGLE";
	if (location.host == 'www.testsite247.com'){
		form.action = "https://sandbox.google.com/checkout/api/checkout/v2/checkout/Merchant/278087332899945";
	} else {
		form.action = "https://checkout.google.com/cws/v2/Merchant/754815211436552/checkout";
	}
	form.submit();
	return false;
}

var applyCouponButton, form, doAction, updateButton, googleButton, paypalButton, continueButton, checkoutButton, host;
window.onload = initialize;