jQuery.noConflict();
var Cart = {
	ToggleShippingEstimation: function()
	{
		jQuery('.EstimatedShippingMethods').hide();
		jQuery('.EstimateShipping').toggle();
		jQuery('.EstimateShippingLink').toggle();
		jQuery('.EstimateShipping select:eq(0)').focus();
	},

	EstimateShipping: function()
	{
		jQuery('.EstimatedShippingMethods').hide();
		jQuery('.EstimateShipping .EstimateShippingButtons span').hide();
		jQuery('.EstimateShipping .EstimateShippingButtons span input').val(lang.Calculating);
		jQuery('.EstimateShipping .EstimateShippingButtons span input').attr('disabled', true);
		jQuery.ajax({
			url: 'remote.php',
			type: 'post',
			data: {
				w: 'getShippingQuotes',
				countryId: jQuery('#shippingZoneCountry').val(),
				stateId: jQuery('#shippingZoneState').val(),
				stateName: escape(jQuery('#shippingZoneStateName').val()),
				zipCode: jQuery('#shippingZoneZip').val()
			},
			success: function(data)
			{
				jQuery('.EstimatedShippingMethods .ShippingMethodList').html(data);
				jQuery('.EstimatedShippingMethods').show();
				jQuery('.EstimateShipping .EstimateShippingButtons span').show();
				jQuery('.EstimateShipping .EstimateShippingButtons span input').val(lang.CalculateShipping);
				jQuery('.EstimateShipping .EstimateShippingButtons span input').attr('disabled', false);
			}
		});
	},

	ToggleShippingEstimateCountry: function()
	{
		var countryId = jQuery('#shippingZoneCountry').val();
		jQuery.ajax({
			url: 'remote.php',
			type: 'post',
			data: 'w=countryStates&c='+countryId,
			success: function(data)
			{
				jQuery('#shippingZoneState option:gt(0)').remove();
				var states = data.split('~');
				var numStates = 0;
				for(var i =0; i < states.length; ++i) {
					vals = states[i].split('|');
					if(!vals[0]) {
						continue;
					}
					jQuery('#shippingZoneState').append('<option value="'+vals[1]+'">'+vals[0]+'</option>');
					++numStates;
				}

				if(numStates == 0) {
					jQuery('#shippingZoneState').hide();
					jQuery('#shippingZoneStateName').show();
				}
				else {
					jQuery('#shippingZoneState').show();
					jQuery('#shippingZoneStateName').hide();
				}
				jQuery('#shippingZoneState').val('0');
			}
		});
	},

	UpdateShippingCost: function()
	{
		var method = jQuery('.EstimatedShippingMethods input[type=radio]:checked').val();
		if(typeof(method) == 'undefined' || method == '') {
			alert(lang.ChooseShippingMethod);
			jQuery('.EstimatedShippingMethods input[type=radio]:eq(0)').focus();
			return false;
		}
		jQuery('#cartForm').submit();
	},

	RemoveItem: function(itemId,redirect,HomePage,Redirect)
	{
		if(confirm("Are you sure you want to remove this item from your cart?")) {
			if(redirect==0){
			document.location.href = HomePage+"/cart.php?action=remove&item="+itemId+'&redirect='+Redirect;
			}
			else{
				document.location.href = HomePage+"/cart.php?action=remove1&item="+itemId;
			}
			
		}
	},

	UpdateQuantity: function(qty)
	{
		if(qty == 0) {
			if(confirm(lang.CartRemoveConfirm)) {
				jQuery('#cartForm').submit();
			}
			else {
				return false;
			}
		}
		else {
			jQuery('#cartForm').submit();
		}
	},

UpdateQuantity1: function(cnt)
	{  
		if(cnt == 1) {
		
				return false;
			}
		
		else {
			jQuery('#cartForm').submit();
		}
	},

	ValidateQuantityForm: function(form)
	{
		var valid = true;
		var qtyInputs = jQuery(form).find('input.qtyInput');
		qtyInputs.each(function() {
			if(isNaN(jQuery(this).val()) || jQuery(this).val() < 0) {
				alert(lang.InvalidQuantity);
				this.focus();
				this.select();
				valid = false;
				return false;
			}
		});
		if(valid == false) {
			return false;
		}

		return true;
	},

	CheckCouponCode: function()
	{
		if(jQuery('#couponcode').val() == '') {
			alert(lang.EnterCouponCode);
			jQuery('#couponcode').focus();
			return false;
		}
	},
    
	CheckCouponCodeSideBox: function()
	{
		if(jQuery('#couponcodeSideBox').val() == '') {
			alert(lang.EnterCouponCode);
			jQuery('#couponcodeSideBox').focus();
			return false;
		}
	},
    


	CheckGiftCertificateCode: function()
	{
		if(jQuery('#giftcertificatecode').val() == '') {
			alert(lang.EnterGiftCertificateCode);
			jQuery('#giftcertificatecode').focus();
			return false;
		}
	},

	ManageGiftWrapping: function(itemId)
	{
		jQuery.iModal({
			type: 'ajax',
			url: 'remote.php?w=selectGiftWrapping&itemId='+itemId
		});
	},

	ToggleGiftWrappingType: function(option)
	{
		if(jQuery(option).hasClass('HasPreview')) {
			jQuery('.GiftWrappingPreviewLinks').hide();
			jQuery('#GiftWrappingPreviewLink'+jQuery(option).val()).show();
		}
		else {
			jQuery('.GiftWrappingPreviewLinks').hide();
		}
		
		if(jQuery(option).hasClass('AllowComments')) {
			jQuery(option).parents('.WrappingOption').find('.WrapComments').show();
		}
		else {
			jQuery(option).parents('.WrappingOption').find('.WrapComments').hide();
		}
	},

	ToggleMultiWrapping: function(value)
	{
		if(value == 'same') {
			jQuery('.WrappingOptionsSingle').show();
			jQuery('.WrappingOptionsMultiple').hide();
		}
		else {
			jQuery('.WrappingOptionsSingle').hide();
			jQuery('.WrappingOptionsMultiple').show();
		}
	},
	
	RemoveGiftWrapping: function(itemId)
	{
		if(confirm(lang.ConfirmRemoveGiftWrapping)) {
			return true;
		}
		else {
			return false;
		}
	},

	ShowEditOptionsInCartForm: function(itemId)
	{
		jQuery.iModal({
			type: 'ajax',
			url: 'remote.php?w=editconfigurablefieldsincart&itemid='+itemId
		});
	},

	DeleteUploadedFile: function(fieldid, itemid)
	{
		if(confirm(lang.DeleteProductFieldFileConfirmation)) {
			jQuery.ajax({
				url: 'remote.php',
				type: 'post',
				data: 'w=deleteuploadedfileincart&field='+fieldid+'&item='+itemid,
				success: function(data) {
					document.getElementById('CurrentProductFile_'+fieldid).value = '';
					jQuery('#CartFileName_'+fieldid).hide();
				}
			});
		}
		return;
	},

	ReloadCart: function()
	{
		window.location = "cart.php";
	}

};
