// Create namespace
function FloralFrenzy() { };

// Inline AJAX shipping calculator
FloralFrenzy.doShippingCalc = function(strPostcode,iProductId) {
	var xh = GetXMLHTTP();
	var url = CMS.appRoot + 'ui.ashx?f=shop_calcshipping&p=' + parseInt(iProductId) + '&z=' + encodeURIComponent(strPostcode) + '&c=1';
	var objTarget = $('ff_shipestimate_target');

	if (xh) {
		AJAX_loadStart();
		xh.onreadystatechange = function() {
			if (xh.readyState == 4) {
				if (xh.status == 200) {
					var stHdr = xh.getResponseHeader('X-RESULT-STATUS');
					if (stHdr == 'True') {
						objTarget.innerHTML = 'Shipping is available from ' + xh.responseText;
					} else if (stHdr == 'Free') {
						objTarget.innerHTML = 'Shipping to this postcode is free!';
					} else {
						objTarget.innerHTML = 'No shipping is available to this location, or the postcode you entered was invalid.';
					}
					AJAX_loadEnd();
				}
			}
		}
		xh.open('GET',url,true);
		xh.send(null);
	} else {
		alert('Sorry, your browser does not support this feature. Please add this product to your cart for a shipping estimate.');
	}
	return false;
}

// Handle keypress in postcode textbox
FloralFrenzy.handlePostcodeKeypress = function(e) {
	var key = (window.event ? window.event.keyCode : e.which);

	if (key == 13) {
		//
		// Cancel keypress
		//
		if (!e) var e = window.event;
		e.cancelBubble = true;
		if (e.stopPropagation) e.stopPropagation();
		$('ff_shipestimate_button').click();

		return false;
	}
	else
		return true;
}




function displayHideElement(strId, strDisplayControlID, strTextElement, bDisplay) {
	if (bDisplay) {
		$(strId).style.display='block';
		$(strDisplayControlID).innerHTML = "<a href=\"#\" onclick=\"displayHideElement('" + strId +  "', '" + strDisplayControlID +  "', '" + strTextElement + "', false);return false;\">Hide " + strTextElement + "</a>";
	} else {
		$(strId).style.display='none';
		$(strDisplayControlID).innerHTML = "<a href=\"#\" onclick=\"displayHideElement('" + strId +  "', '" + strDisplayControlID +  "', '" + strTextElement+ "', true);return false;\">Show " + strTextElement + "</a>";
	}
}

// Declare namespace
function IASPCartSteps() { }

IASPCartSteps.openFirstLink = function(objDiv) {
	var aLinks = objDiv.getElementsByTagName("A");
	if (aLinks.length > 0) {
		document.location.href = aLinks[0].href;
	}
}