function fetchAddressShop() {var loc;loc = window.location.hostname;if (loc.match('everest')) loc = 'http://everest:8888/EasyVetSites/http';else loc = 'http://'+loc;return loc;}
function updatePriceAndImage(group_id, product, id) {
	
	var loc;
	var method;
	
	loc = fetchAddressShop();
	loc += "/shop/update.php?group_id=" + parseInt(group_id) + '&product=' + escape(product) + '&id=' + id;
	
	//window.open(loc);
	
	try {if (window.XMLHttpRequest) {xmlhttp = new XMLHttpRequest();method= 'GET';}else{xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");method= 'POST';}}catch (e) {}
	
	xmlhttp.onreadystatechange = triggerUpdatePriceAndImage;
	xmlhttp.open(method, loc);
	xmlhttp.send(null);
	
}


/* ----------------------------------- */


function triggerUpdatePriceAndImage() {
	if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
		
		var r = xmlhttp.responseText;
		var i = r.split('|~|');
		
		document.getElementById('VPP_price_'+i[0]).innerHTML = "<p class='VPP_Price_Tag'>Price: $"+i[2]+"</p>";
		document.getElementById('VPP_img_'+i[0]).innerHTML = "<img src='http://shop.vetnetwork.net/img/new/small/"+i[3]+"' alt='"+i[1]+"' width='100' height='100' />";
		document.getElementById('VPP_Paypal_Form_'+i[0]).innerHTML = i[4];
		
	}
}

/* ----------------------------------- */

function redeemCode( product_id, unit_price ) {
	
	var cc = document.getElementById('cck_'+product_id).value;
	var loc;
	var method;
	
	loc = fetchAddressShop();
	loc += "/shop/redeem.php?cc=" + escape(cc) + '&product_id=' + parseInt(product_id) + '&unit_price=' + escape(unit_price);
	
	//window.open(loc);return;
	
	try {if (window.XMLHttpRequest) {xmlhttp = new XMLHttpRequest();method= 'GET';}else{xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");method= 'POST';}}catch (e) {}
	
	xmlhttp.onreadystatechange = triggerRedeemCode;
	xmlhttp.open(method, loc);
	xmlhttp.send(null);
	
}


/* ----------------------------------- */


function triggerRedeemCode() {
	if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
		
		var r = xmlhttp.responseText;
		var i = r.split('|~|');
		
		// alert(i[0] + ' ' + i[1] + ' ' + i[2]);
		
		if (i[1] != 'false') {
			document.getElementById('VPP_price_'+i[0]).innerHTML = "<p class='VPP_Price_Tag'>Price: $"+i[1]+" <em>(includes "+i[2]+"% discount)</em></p>";
			document.getElementById('paypal_amount_'+i[0]).innerHTML = i[2];
			document.getElementById('VPP_Redeem_'+i[0]).style.display = 'none';
		} else {
			alert("Invalid discount code.");
			document.getElementById('cck_'+i[2]).select();
		}
	}
}


/* ----------------------------------- */
/* ----------------------------------- */
/* ----------------------------------- */
/* ----------------------------------- */
/* ----------------------------------- */