
function getJSONKeys(input)
{
	//if re is a regular expression
	//the form value will only be placed in the object if its name matches the regular expression
	//if remap_fieldnames is undefined, or true, the fieldnames will have the matching part of the re
	//removed
	//e.g. getForm(/billing_/) and a form which has billing_address defined
	//will return an object with .address set (NOT billing_address)
	//getForm(/billing_/, false)
	//will return an object with .billing_address set 
	var JSON = new Object();
	var arr = String(input).split("&");
	var x;
	for(var f in arr)
	{
		x = String(arr[f]).split("=");
		JSON[String(x[0]).toLowerCase()] = String(x[1]);
	}
	return JSON;
}

function updateCartSummary(){
	$.post("ajaxFn.asp?r="+Math.random(),{act:"cartsummary"},function(data){
		//var results = getJSONKeys(data);
		//$("#summ_itemcount").html(results.itemcount);
		//$("#summ_ordertotal").html(results.ordertotal);
		$("#summ_itemcount").html($("itemcount",data).text());
		$("#summ_ordertotal").html($("ordertotal",data).text());
	});
}

// REmove item - use by CartDetails.
function removeCartItem(id){
	$.post("removeitem.asp",{id: id}, function(data){
		var results = getJSONKeys(data);
		if(results.status == "success")
			updateCartSummary();
//			tb_remove();
//			tb_show("Cart Details","<%=HTTP%>cartdetails.asp?v=<%=ver%>&amp;height=500&amp;width=730&amp;modal=false");
			$.facebox.settings.opacity=0.5;
			$.facebox({ ajax: 'cartdetails.asp' });
	});
}

function deliveryInfo(){
	location.href='privacypolicy.asp';
}

function blank(str)
{
	if( typeof(str) == "object" ) {
		try {
			var val = String(str).trim();
			if( val.toLowerCase() == "null" )
				val = "";
			return val;
		} catch ( e ) {
			return "";
		}
	}
	if( typeof(str) == "undefined" || String(str).toLowerCase() == "null" ) {
		return "";
	} else
		return String(str).trim();
}

function trim(str)
{
	str = ltrim(str);
	str = rtrim(str);
	return str;
}

String.prototype.trim = function () {
  return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
};


function isValidEmail(value)
{
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,4})(\\]?)$");
	value = String(value);
	return !(!r1.test(value) && !r2.test(value));
}

function changeCurrency(currCode){
	if( currCode == "" )
			return; //don't change on Select Currency option
	$.post("ajaxfn.asp",{
		act:"change_currency",
		currency:$("#pageCurrency").val()
		},
		function(response){
			if($("result",response).text() == "OK") // Reload Page if Currency Update OK;
				window.location.reload();
		}
	);
}


function changeCountry(country){
	$.post("ajaxfn.asp",{
		act:"change_country",
		country:country
		},
		function(response){
			if($("result",response).text() == "OK") // Reload Page if Currency Update OK;
				updateCartSummary();
		}
	);
}

function signup(){
	$.facebox({ajax: "signupnewsletter.asp"});
}