/**
 * For updating quantity
 * @name //modules/blockcart/cart.js
 * @author Marghoob Suleman - http://marghoobsuleman.com
 * @version 0.1
 * @date January 07, 2009
 * @category Prestashop cart common function
 * @copyright (c) 2009 Marghoob Suleman (giftlelo.com)
 */

Cart = {
	//for product page
	oldValue:1,
	update: function(target, locUp, locDown) {
		var target_txt = target;
		var sValue = parseInt(target_txt.value);
		//alert("init sValue " + sValue + " this.oldValue " + this.oldValue);
		if(sValue != this.oldValue) { //if not updated
			if(sValue > this.oldValue) {
				//up
				sValue = sValue - this.oldValue;
				//alert("up sValue " + sValue);
				window.location = locUp+"&qnty="+sValue;
			} else {
				//down
				sValue = this.oldValue - sValue;
				//alert("down sValue " + sValue);
				window.location = locDown+"&qnty="+sValue;
			}
		}
	},
	keepHistory: function(sValue) {
		if(this.oldValue.toString() != sValue.toString()) {
			this.oldValue = parseInt(sValue);
		}
	},
	proceedToCheckout: function() {
		var currencyCode = $("#currency_id").val();
		//alert("currencyCode " + currencyCode);
		if(currencyCode.toString() == "4") {
			//alert("We are sorry, Paypal does not accepts Indian Rupees. Please change the currency from the top.")
			$("#paypalError").slideDown("fast");
		} else {
			$('#paypal_form').submit();
		}
	},
	checkQuantity: function() {
		var quntity = $("#quantity_wanted").val().toString() //new RegExp("az","gi");
		if(parseInt(quntity) <= 0) {
			$("#quantity_wanted").focus();
			alert("Please enter quantity");
			return false;
		} else if((quntity.match(new RegExp(/[A-Za-z]/))!=null)==true) {
			$("#quantity_wanted").focus();
			alert("Please enter digits only");
			return false;
		}
		//console.debug("quntity " + quntity)
		return true;
	},
	//for shopping-cart.tpl;
	deleteProduct: function(url) {
		var sURL = url;
		var sure = confirm("Are you sure?");
		if(sure) window.location = sURL;
	}
}