 // JavaScript Document
 


var signup_default = "Your Email Address";
var search_default = "Search";
var j = jQuery.noConflict();

function valid_email(email)
{
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(email)) return true
	return false
}

function notify(msg)
{
	//alert(msg);	
	//j.alerts.dialogClass = "style1";
	jAlert(msg, 'Notification', function()
	{
		j.alerts.dialogClass = null; // reset to default
	});
}

/**
*
*  Javascript trim, ltrim, rtrim
*  http://www.webtoolkit.info/
*
**/
 
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

/**
*
*  URL encode / decode
*  http://www.webtoolkit.info/
*
**/
 
var Url = {
 
	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},
 
	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}

j(document).ready(function()
{
	var IE6 = (navigator.userAgent.indexOf("MSIE 6")>=0) ? true : false;
	var cIE6 = j.cookie("ie6");
	//alert(cIE6);
	if((IE6) && (cIE6!="sux0r"))
	{
		
		j("<div>")
			.css({
				'position': 'absolute',
				'top': '0px',
				'left': '0px',
				backgroundColor: 'black',
				'opacity': '0.75',
				'width': '100%',
				'height': j(window).height(),
				zIndex: 5000
			})
			.appendTo("body");
			
		j("<div><!--<img src='no-ie6.png' alt='' style='float: left;'/>--><p>We've detected that you are using Internet Explorer 6 which is an old unsupported browser. For the full user experience please update your browser to one of the following:<br/><br/><a href='http://www.mozilla-europe.org/en/firefox/'>Firefox</a><br/><a href='http://www.microsoft.com/windows/internet-explorer/ie7/'>Internet Explorer 7</a><br/><a href='http://www.microsoft.com/windows/internet-explorer/default.aspx'>Internet Explorer 8</a><br/><a href='http://www.apple.com/safari/'>Safari</a><br/><a href='http://www.opera.com/'>Opera</a><br/><br/>And many others...<br/><br/><br/></p><p style='text-align:center;'><a href='#' class='ie6-close'>CLOSE</a></p>")
			.css({
				backgroundColor: 'white',
				'top': '50%',
				'left': '50%',
				marginLeft: -210,
				marginTop: -100,
				width: 410,
				paddingRight: 10,
				height: 200,
				'position': 'absolute',
				zIndex: 6000, 
				padding: "30px"
			})
			.appendTo("body");
	}
				

	j(".ie6-close").click(function()
	{
		j.cookie("ie6", "sux0r");
		location.href = "./";
		return false;
	});


	j(document).pngFix();
	
	//j(".spinner1").jtrans();
	//j(".spinner2").jtrans2();
	
	// SET THE DEFAULT TEXT
	j("#semail").val(signup_default);
	
	// CHANGE TEXT ON CLICK
	j("#semail").focus(function()
	{
		if(j(this).val() == signup_default)
		{
			j(this).val("");
		}
	});
	
	// REVERT TEXT ON LEAVE
	j("#semail").blur(function()
	{
		if(j(this).val() == "")
		{
			j(this).val(signup_default);
		}
	});
	
	// SET THE DEFAULT TEXT
	//j("#shop-search .textbox").val(search_default);
	
	// CHANGE TEXT ON CLICK
	j("#shop-search .textbox").focus(function()
	{
		if(j(this).val() == search_default)
		{
			j(this).val("");
		}
	});
	
	// REVERT TEXT ON LEAVE
	j("#shop-search .textbox").blur(function()
	{
		if(j(this).val() == "")
		{
			j(this).val(search_default);
		}
	});
	
	if(!IE6)
	{
		j(".img-zoom").jqzoom({
				zoomWidth: 320,
				zoomHeight: 320,
				xOffset: 50,
				yOffset: -80,
				position: "right",
				title: false
		});
	}
	
	// SHOP CATEGORY CLICK
	j("#shop-categories > ul > li:not(.selected) > a").live("click", function()
	{
		var index = j("#shop-categories > ul > li > a").index(this);
		j("#shop-categories > ul > li > ul:not("+index+")").slideUp().parent().removeClass("selected");
		j("#shop-categories > ul > li > ul:eq("+index+")").parent().addClass("selected");
		j("#shop-categories > ul > li > ul:eq("+index+")").slideDown();
	});
	
	
	
	j("div.rounded-box").wrap('<div class="rounded-corners">'+
        '<div class="bd">'+
        '<div class="c">'+
        '<div class="s">'+
        '</div>'+
        '</div>'+
        '</div>'+
        '</div>');
	
	j('div.rounded-corners').prepend('<div class="hd">'+
			'<div class="c"></div>'+
			'</div>')
	.append('<div class="ft">'+
			'<div class="c"></div>'+
			'</div>');
	
	/*j(".shadow").dropShadow({left:2,top:2,opacity:0.3});*/

	
	j(".newsletter-signup-submit").click(function()
	{
		//alert("DEBUG");
		var email = j("input[name=semail]").val();
		if(valid_email(email))
		{
			j.ajax({
				type: "POST",
				url: "/oi-rpc.php",
				data: "action=newsletter-signup&semail="+email,
				dataType: "json",
				success: function(response)
				{
					notify(response.status_detail);
				}
			});
			j("input[name=semail]").val(signup_default);
		}
		else
		{
			notify("'"+email+"' is not a valid email address");
		}
		return false;
	});
		
		
	j(".brochure-form").submit(function()
	{
		var errors = [];
		var params = "";
		
		// VALIDATION
		j(".mandatory").each(function()
		{
			// CHECK FOR VALID EMAIL ADDRESS
			if(j(this).attr("class").indexOf("email") != -1)
			{
				if(!valid_email(j(this).val()))
				{
					errors.push("'"+j(this).prev().prev().text()+"' is not a valid email address");
				}
			}
			else
			{
				if(j(this).val() == "")
				{
					errors.push("Must specify '"+j(this).prev().prev().text()+"'");
				}
			}
		});
		
		if(errors.length > 0)
		{
			notify(errors.join("\n"));
			return false;
		}
		else
		{
			j(".brochure-form input,.brochure-form textarea").each(function()
			{
				params += "&"+j(this).attr("name")+"="+j(this).val();
			});
			
			j.ajax({
				type: "POST",
				url: "/oi-rpc.php",
				data: "action=brochure-request"+params,
				beforeSend : function(req)
				{
					//req.setRequestHeader('Authorization', "Basic "+j.base64Encode("oiadmin" + ':' + "offshore"));
				},
				success: function(response)
				{
					j(".brochure-form .status").fadeOut("slow").text("Thanks, we have received your request!").fadeIn("slow");
					j(".brochure-form input:not(.submit)").val("");
				}
			});
		}
		return false;
	});
	
	j(".search-form").submit(function()
	{		
		location.href = "/shop/search/?keywords="+j(".search-form input[name=keywords]").val();	
		return false;
	});
	
	j(".contact-form").submit(function()
	{
		var errors = [];
		var params = "";
		
		// VALIDATION
		j(".mandatory").each(function()
		{
			// CHECK FOR VALID EMAIL ADDRESS
			if(j(this).attr("class").indexOf("email") != -1)
			{
				if(!valid_email(j(this).val()))
				{
					errors.push("'"+j(this).prev().prev().text()+"' is not a valid email address");
				}
			}
			else
			{
				if(j(this).val() == "")
				{
					errors.push("Must specify '"+j(this).prev().prev().text()+"'");
				}
			}
		});
		
		if(errors.length > 0)
		{
			notify(errors.join("\n"));
			return false;
		}
		else
		{
			params = "";
			params += "&cname="+j("#cname").val();
			params += "&csubject="+j("#csubject").val();
			params += "&cemail="+j("#cemail").val();
			params += "&cmessage="+j("#cmessage").val();
			
			//notify(params);
			
			j.ajax({
				type: "POST",
				url: "/oi-rpc.php",
				data: "action=enquiry-submit"+params,
				beforeSend : function(req)
				{
					//req.setRequestHeader('Authorization', "Basic "+j.base64Encode("oiadmin" + ':' + "offshore"));
				},
				success: function(response)
				{
					j(".contact-form .status").fadeOut("slow").text("Thanks, we have received your enquiry!").fadeIn("slow");
					j(".contact-form input:not(.submit),.contact-form textarea").val("");
				}
			});
			
		}
		return false;
	});
	
	// REGISTER FORM USERNAME CHECK
	j(".register-form input[name=rusername]").blur(function()
	{	
		j(".register-form .status").hide().text("");
		
		var str = trim(j(this).val());
		var username_pattern = new RegExp("[^0-9a-zA-Z_]+");
		
		if(str.length < 5 || str.length > 12)
		{
			j(".register-form .status").text("Username must be between 5 and 12 characters").fadeIn();
			return false;
		}
		
		if(username_pattern.test(str))
		{
			j(".register-form .status").hide().text("Username must only contain letters, numbers and underscores").fadeIn();
			j(this).focus();
			return false;
		}
				
		params = "";
		j(".register-form input").each(function()
		{
			params += "&"+j(this).attr("name")+"="+j(this).val();
		});
		j.ajax({
			type: "POST",
			url: "/oi-rpc.php",
			data: "action=register-username-exists"+params,
			dataType: "json", 
			success: function(response)
			{
				if(response.status == "true")
				{
					// USERNAME TAKEN
					j(".register-form .status").text(response.status_detail).fadeIn();
				}
			}
		});
	});
	
	// REGISTER FORM EMAIL CHECK
	j(".register-form input[name=remail]").blur(function()
	{	
		j(".register-form .status").hide().text("");
		
		var str = trim(j(this).val());
		var email_pattern = new RegExp("^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$");
		
		if(!email_pattern.test(str))
		{
			j(".register-form .status").hide().text("Email address is invalid").fadeIn();
			j(".register-form input[name=remail]").focus();
			return false;
		}
		
		// CHECK EMAIL IS VALID
		params = "";
		j(".register-form input").each(function()
		{
			params += "&"+j(this).attr("name")+"="+j(this).val();
		});
		j.ajax({
			type: "POST",
			url: "/oi-rpc.php",
			data: "action=register-email-exists"+params,
			dataType: "json", 
			success: function(response)
			{
				if(response.status == "true")
				{
					// EMAIL TAKEN
					j(".register-form .status").addClass("error").hide().text(response.status_detail).fadeIn();
				}
			}
		});
	});
	
	j(".register-form").submit(function()
	{	
		params = "";
		j(".register-form input").each(function()
		{
			params += "&"+j(this).attr("name")+"="+j(this).val();
		});
		
		j.ajax({
			type: "POST",
			url: "/oi-rpc.php",
			data: "action=register-submit"+params,
			dataType: "json", 
			success: function(response)
			{
				notify(response.status_detail);
				j(".register-form input").val("");
				
			}
		});
		return false;
		
	});
		



	// CHECKOUT REGISTER FORM USERNAME CHECK
	j(".checkout-register-form input[name=rusername]").blur(function()
	{	
		j(".checkout-register-form .status").hide().text("");
		
		var str = trim(j(this).val());
		var username_pattern = new RegExp("[^0-9a-zA-Z_]+");
		
		if(str.length < 5 || str.length > 12)
		{
			j(".checkout-register-form .status").text("Username must be between 5 and 12 characters").fadeIn();
			return false;
		}
		
		if(username_pattern.test(str))
		{
			j(".checkout-register-form .status").hide().text("Username must only contain letters, numbers and underscores").fadeIn();
			j(this).focus();
			return false;
		}
				
		params = "";
		j(".checkout-register-form input").each(function()
		{
			params += "&"+j(this).attr("name")+"="+j(this).val();
		});
		j.ajax({
			type: "POST",
			url: "/oi-rpc.php",
			data: "action=register-username-exists"+params,
			dataType: "json", 
			success: function(response)
			{
				if(response.status == "true")
				{
					// USERNAME TAKEN
					j(".checkout-register-form .status").text(response.status_detail).fadeIn();
				}
			}
		});
	});

	
	// CHECKOUT REGISTER FORM EMAIL CHECK
	j(".checkout-register-form input[name=remail]").blur(function()
	{	
		j(".checkout-register-form .status").hide().text("");
		
		var str = trim(j(this).val());
		var email_pattern = new RegExp("^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$");
		
		if(!email_pattern.test(str))
		{
			j(".checkout-register-form .status").hide().text("Email address is invalid").fadeIn();
			j(".checkout-register-form input[name=remail]").focus();
			return false;
		}
		
		// CHECK EMAIL IS VALID
		params = "";
		j(".checkout-register-form input").each(function()
		{
			params += "&"+j(this).attr("name")+"="+j(this).val();
		});
		j.ajax({
			type: "POST",
			url: "/oi-rpc.php",
			data: "action=register-email-exists"+params,
			dataType: "json", 
			success: function(response)
			{
				if(response.status == "true")
				{
					// EMAIL TAKEN
					j(".checkout-register-form .status").addClass("error").hide().text(response.status_detail).fadeIn();
				}
			}
		});
	});
	
	// CHECKOUT REGISTER FORM SUBMIT
	j(".checkout-register-form").submit(function()
	{	
		params = "";
		j(".checkout-register-form input").each(function()
		{
			params += "&"+j(this).attr("name")+"="+j(this).val();
		});
		
		j.ajax({
			type: "POST",
			url: "/oi-rpc.php",
			data: "action=register-submit"+params,
			dataType: "json", 
			success: function(response)
			{
				notify(response.status_detail);
				j(".checkout-register-form input").val("");
				
			}
		});
		return false;
		
	});
	
	
	
	
	
	// LOGIN SUBMIT
	j(".login-form").submit(function()
	{		
		j(".login-form .status").hide().text("");
		params = "";
		j(".login-form input").each(function()
		{
			params += "&"+j(this).attr("name")+"="+j(this).val();
		});
		j.ajax({
			type: "POST",
			url: "/oi-rpc.php",
			data: "action=login-submit"+params,
			dataType: "json", 
			success: function(response)
			{
				if(response.status == "true")
				{
					alert(j("#refer_url").val());
					if(j("#refer_url").val() != "")
					{
						location.href = j("#refer_url").val();
					}
					else
					{
						location.href = "/shop/my-account/";
					}
				}
				else
				{
					j(".login-form .status").text(response.status_detail).fadeIn();
					j(".login-form input:not(.submit)").val("");
				}
				
			}
		});
		return false;
		
	});

	// CHECKOUT LOGIN SUBMIT
	j(".checkout-login-form").submit(function()
	{		
		j(".checkout-login-form .status").hide().text("");
		params = "";
		j(".checkout-login-form input").each(function()
		{
			params += "&"+j(this).attr("name")+"="+j(this).val();
		});
		j.ajax({
			type: "POST",
			url: "/oi-rpc.php",
			data: "action=login-submit"+params,
			dataType: "json", 
			success: function(response)
			{
				if(response.status == "true")
				{
					location.href = "/shop/checkout/";
				}
				else
				{
					j(".checkout-login-form .status").text(response.status_detail).fadeIn();
					j(".checkout-login-form input:not(.submit)").val("");
				}
				
			}
		});
		return false;
		
	});




	// LOGOUT BUTTON
	j(".logout-button").click(function()
	{		
		j.ajax({
			type: "POST",
			url: "/oi-rpc.php",
			data: "action=logout-submit",
			dataType: "json", 
			success: function(response)
			{
				if(response.status == "true")
				{
					location.href = "/shop/logout/";
				}
				else
				{
					notify("Failed to logout.");
				}
				
			}
		});
		return false;
		
	});



	// validate the address form when it is submitted
	j(".checkout-address-form").validate();

	// validate the payment form when it is submitted
	j(".checkout-payment-form").validate();




	j(".reminder-form").submit(function()
	{		
		j(".reminder-form .status").hide().text("");
		params = "";
		j(".reminder-form input").each(function()
		{
			params += "&"+j(this).attr("name")+"="+j(this).val();
		});
		j.ajax({
			type: "POST",
			url: "/oi-rpc.php",
			data: "action=reminder-submit"+params,
			dataType: "json", 
			success: function(response)
			{
				if(response.status == "true")
				{
					notify(response.status_detail);
					setTimeout(function(){location.href="/shop/login/"}, 2000);
					//j(".reminder-form .status").text(response.status_detail).fadeIn();
					//j(".reminder-form input:not(.submit)").val("");
				}
				else
				{
					j(".reminder-form .status").text(response.status_detail).fadeIn();
				}
				
			}
		});
		return false;
		
	});
	
	j(".account-form").submit(function()
	{		
		j(".account-form .status").hide().html("");
		
		params = "";
		j(".account-form input,.account-form textarea,.account-form select").each(function()
		{
			params += "&"+j(this).attr("name")+"="+j(this).val();
		});
		j.ajax({
			type: "POST",
			url: "/oi-rpc.php",
			data: "action=account-submit"+params,
			dataType: "json", 
			success: function(response)
			{
				if(response.status == "true")
				{
					j(".account-form .status").html(response.status_detail).fadeIn();
				}
				else
				{
					j(".account-form .status").html(response.status_detail).fadeIn();
				}
				
			}
		});
		return false;
	});
	
	j(".subscriptions-form").submit(function()
	{		
		j(".subscriptions-form .subscriptions-status").hide().text("");
		
		params = "";
		j(".subscriptions-form input:checked").each(function()
		{
			params += "&"+j(this).attr("name")+"="+j(this).val();
		});
		j.ajax({
			type: "POST",
			url: "/oi-rpc.php",
			data: "action=subscriptions-update"+params,
			dataType: "json", 
			success: function(response)
			{
				if(response.status == "true")
				{
					j(".subscriptions-form .subscriptions-status").text(response.status_detail).fadeIn();
				}
				else
				{
					j(".subscriptions-form .subscriptions-status").text(response.status_detail).fadeIn();
				}
				
			}
		});
		return false;
	});
	
	j(".add-to-cart-link").click(function()
	{
		j(this).closest("form").submit();
	});
	
	j(".product-form").submit(function()
	{
		//j(".account-form .status").hide().text("");
		var index = j(".product-form").index(this);
		params = "";
		j(".product-form:eq("+index+") input,.product-form:eq("+index+") textarea,.product-form:eq("+index+") select").each(function()
		{
			params += "&"+j(this).attr("name")+"="+j(this).val();
		});
		
		//alert(params); return false;
		j.ajax({
			type: "POST",
			url: "/oi-rpc.php",
			data: "action=add-to-cart"+params,
			dataType: "json", 
			success: function(response)
			{
				if(response.status == "true")
				{
					//j("#popup_content").css("");
					j.alerts.dialogClass = "style_1";
					j(".notify-add-to-cart-html .product-title").text(response.product_title);
					var notify_html = j(".notify-add-to-cart-html").html();
					notify(notify_html);
					update_cart();
				}
				else
				{
					//j(".account-form .status").text(response.status_detail).fadeIn();
				}
			}
		});
		return false;
	});
	
	function update_cart()
	{
		j.ajax({
			type: "POST",
			url: "/oi-rpc.php",
			data: "action=update-cart-data",
			dataType: "json", 
			success: function(response)
			{
				if(response.status == "true")
				{
					j(".shopping-cart-count").text((response.cart_count == 1)?("1 item"):(response.cart_count+" items"));
					j(".shopping-cart-total").text(response.cart_total);
				}
				else
				{
					//j(".account-form .status").text(response.status_detail).fadeIn();
				}
			}
		});
	}
	
	j(".product-form .add-to-wishlist").click(function()
	{
		//j(".account-form .status").hide().text("");
		//alert("TEST");
		params = "";
		j(".product-form input,.product-form textarea,.product-form select").each(function()
		{
			params += "&"+j(this).attr("name")+"="+j(this).val();
		});
		
		j.ajax({
			type: "POST",
			url: "/oi-rpc.php",
			data: "action=add-to-wishlist"+params,
			dataType: "json", 
			success: function(response)
			{
				if(response.status == "true")
				{
					notify("Item added to wishlist!");
				}
				else
				{
					notify(response.status_detail);
				}
			}
		});
		return false;
	});
	
	j("input[name=shipping-to-billing]").click(function()
	{
		if(j(this).attr("checked"))
		{
			j(".checkout-address-form input[name=shipping_name]").val(j(".checkout-address-form input[name=billing_name]").val());
			j(".checkout-address-form textarea[name=shipping_address_1]").val(j(".checkout-address-form textarea[name=billing_address_1]").val());
			j(".checkout-address-form input[name=shipping_city]").val(j(".checkout-address-form input[name=billing_city]").val());
			j(".checkout-address-form input[name=shipping_postcode]").val(j(".checkout-address-form input[name=billing_postcode]").val());
			j(".checkout-address-form input[name=shipping_county]").val(j(".checkout-address-form input[name=billing_county]").val());
			j(".checkout-address-form select[name=shipping_country]").val(j(".checkout-address-form select[name=billing_country]").val());
			j(".checkout-address-form input[name=shipping_telephone]").val(j(".checkout-address-form input[name=billing_telephone]").val());
			j(".checkout-address-form input[name=shipping_email]").val(j(".checkout-address-form input[name=billing_email]").val());
		}
		else
		{
			j(".checkout-address-form input[name=shipping_name]").val("");
			j(".checkout-address-form textarea[name=shipping_address_1]").val("");
			j(".checkout-address-form input[name=shipping_city]").val("");
			j(".checkout-address-form input[name=shipping_postcode]").val("");
			j(".checkout-address-form input[name=shipping_county]").val("");
			j(".checkout-address-form select[name=shipping_country]").val("");
			j(".checkout-address-form input[name=shipping_telephone]").val("");
			j(".checkout-address-form input[name=shipping_email]").val("");
		}
	});
	
	j(".shopping-bag-shipping-country").change(function()
	{
		location.href = "/shop/shopping-bag/?shipping_country="+j(this).val()+"&gift_code="+j(".shopping-bag-gift-certificate").val();
	});
	
	j(".shopping-bag-gift-certificate-redeem").click(function()
	{
		location.href = "/shop/shopping-bag/?shipping_country="+j(".shopping-bag-shipping-country").val()+"&gift_code="+j(".shopping-bag-gift-certificate").val();
	});
	
	
	j(".quantity input[name=qty]").change(function()
	{
		var basket_item_id = j(this).next().val();
		var basket_item_qty = j(this).val();
		j.ajax({
			type: "POST",
			url: "/oi-rpc.php",
			data: "action=update-basket-item-qty&basket_item_id="+basket_item_id+"&basket_item_qty="+basket_item_qty,
			dataType: "json", 
			success: function(response)
			{
				location.reload(true);
			}
		});
		
		
	});
	
	j(".bag-remove-link").click(function()
	{
		var basket_item_id = j(this).prev().prev().val();
		var basket_item_qty = 0;
		j.ajax({
			type: "POST",
			url: "/oi-rpc.php",
			data: "action=update-basket-item-qty&basket_item_id="+basket_item_id+"&basket_item_qty="+basket_item_qty,
			dataType: "json", 
			success: function(response)
			{
				location.reload(true);
			}
		});
		
		
	});
	
	j(".checkout-shipping-country").change(function()
	{
		if(j(".checkout-shipping-country").val()=="United States")
		{
			j("#checkout-shipping-state-div").removeClass("hide");
		}
		else
		{
			j("#checkout-shipping-state-div").addClass("hide");
		}
	});
	
	
	j(".checkout-billing-country").change(function()
	{
		if(j(".checkout-billing-country").val()=="United States")
		{
			j("#checkout-billing-state-div").removeClass("hide");
		}
		else
		{
			j("#checkout-billing-state-div").addClass("hide");
		}
	});
	


});