
String.prototype.RTrim = function() {return this.replace(/\s+$/, "");}
String.prototype.LTrim = function() {return this.replace(/^\s+/, "");}
String.prototype.Trim  = function() {return this.RTrim().LTrim();}

function SubmitToBasket(strProdId, strProdCode, strProdPrice, strProdDesc, iProdQty, strProdWeight, iProdType, pos, basketDivId) {
	if ((strProdCode.Trim() == "") || (strProdPrice.Trim() == "") || (strProdDesc.Trim() == "")) {
		alert("Error: Could not Add Item To Basket");
	} else {
		urlToPost = "../cart/addToBasketInline.asp";
		urlToPost += "?hfProdId=" + strProdId;
		urlToPost += "&hfProdCode=" + escape(strProdCode.Trim());
		urlToPost += "&hfProdPrice=" + escape(strProdPrice.Trim());
		urlToPost += "&hfProdDesc=" + escape(strProdDesc.Trim());
		urlToPost += "&hfProdQty=" + iProdQty;
		urlToPost += "&hfProdType=" + iProdType;

		msg = postAjax(urlToPost);
		document.getElementById("errorDiv").innerHTML = msg;

		if (Left(msg,7) == "Success") {
			document.getElementById("basket_summary").innerHTML = Right(msg,((msg.length)-8));
			
			notifyEle = document.getElementById("basket_notify_" + basketDivId);
			if(pos == 'tl') {
				htmlString = '<div class="basket_notify_inner tl">';
			} else {
				htmlString = '<div class="basket_notify_inner tr">';
			}
			htmlString += '  <div class="qb_top">';
			htmlString += '    <img src="../content/layout/basket_notify_icon.gif" width="40" height="30" alt="" title="" class="basket_notify_icon" >';
			htmlString += '    This item has been <br />added to your basket.';
			htmlString += '  </div>';
			htmlString += '  <div class="qb_middle">';
			htmlString += '    <b>' + iProdQty + 'x ' + strProdDesc + '</b>';
			//<br /><b class="red">£' + strProdPrice + '</b>
			htmlString += '  </div>';
			htmlString += '  <div class="qb_bottom">';
			htmlString += '    <a href="javascript: qb_hide(\'' + basketDivId + '\');">continue shopping</a> | <a href="javascript: qb_hide(\'' + basketDivId + '\'); qb_checkout();">view basket</a>';
			
			if (iProdType == 4) {
				htmlString += '  <br /><a href="javascript: qb_nextAction(\'' + basketDivId + '\',\'search/index.asp\')">add rivets to this order</a>';
			}
			
			htmlString += '  </div>';
			htmlString += '</div>';
			notifyEle.innerHTML = htmlString
			notifyEle.style.display = 'block';
			
		} else {
			alert("There has been a problem adding this item to the basket, \nPlease wait a moment and try again.\nIf the problem persists please contact us.")
		}
	}
}

function BuyNow() {
	document.AddToBasket.submit();
}

function ShoppingAction(PageName) {
	oEle = document.frmNavigation;
	if (PageName != undefined) {
		if (PageName == "Home") {
			oEle.action = oEle.Normal.value + "index.asp";
		} else if (PageName == "Shopping") {
			if (oEle.Continue.value != "") {
				//If we have a contiunue shopping url
				oEle.action = oEle.Continue.value;
			} else {
				oEle.action = oEle.Normal.value + "productrange/index.asp";
			}
		} else if (PageName == "Basket") {
			oEle.action = oEle.Normal.value + "cart/basket.asp";
		} else if (PageName == "GoogleCheckout") {
			oEle.action = oEle.Secure.value + "cart/include/google/googleprocess.asp";
		} else if (PageName == "Details") {
			oEle.action = oEle.Secure.value + "cart/personal.asp";
		} else if (PageName == "Payment") {
			oEle.action = oEle.Secure.value + "cart/payment.asp";
		} else if (PageName == "Confirm") {
			oEle.action = oEle.Secure.value + "cart/confirm.asp";
		}
		oEle.submit();
	} else {
		oEle.action = oEle.Home.value; 
		oEle.method = "";
		oEle.submit();
	}
}


function limitText(limitField, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
		alert("You can only enter a maximum of " + limitNum + " characters in this field");
	} 
}




function qb_hide(prodId) {
	notifyEle = document.getElementById("basket_notify_" + prodId);
	notifyEle.style.display = 'none';
	notifyEle.innerHTML = '';
}

function qb_checkout() {
	window.location = relPath +'cart/basket.asp' ;
}

function qb_nextAction(prodId, nextPage) {
	qb_hide(prodId);
	window.location = relPath + nextPage;
}

function postAjax(urlToPost) {
	var xmlhttp = GetXmlHttpObject();
	if (xmlhttp == null) {
		// Check if browser is compatable
		alert ("Sorry, your browser does not support HTTP Request...");
		return;
	} else {
		xmlhttp.open("GET",urlToPost,false);
		xmlhttp.send(null);
		return xmlhttp.responseText;
	}
}

function GetXmlHttpObject() { 
	var objXMLHttp=null;
	if (window.XMLHttpRequest) {
		objXMLHttp=new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp;
}


function setCurrency(currency) {
	var myURL = relPath + "cart/setCurrency.asp?currency=" + currency;
	msg = postAjax(myURL);

	if (Left(msg,7) != "Success") {
		alert("There has been a problem setting your currency, \nPlease wait a moment and try again.\nIf the problem persists please contact us.")
	} else {
		//Reload the page to refresh displayed prices
		window.location.reload();
	}
}