


function NumbersSpaceOnly(myfield, e)
{
	//onkeypress="return NumbersSpaceOnly(this, event);"
	var key;
	var keychar;

	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;
	
	keychar = String.fromCharCode(key);

	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
	   return true;
	else if ((("0123456789 ").indexOf(keychar) > -1))
	   return true;
	else
		return false;
};


function NumbersOnly(myfield, e)
{
	var key;
	var keychar;

	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;
	
	keychar = String.fromCharCode(key);

	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
	   return true;
	else if ((("0123456789").indexOf(keychar) > -1))
	   return true;
	else
		return false;
};


function ChangeQtyBasket(TRFProduct)
{


	var Newqty = (isNaN($("#Quantity_"+TRFProduct).val()) || parseInt($("#Quantity_"+TRFProduct).val()) < 0) ? 0 : parseInt($("#Quantity_"+TRFProduct).val());
	
	
	
	$.get( '/wp-content/php/ajax_scripts.php', { cart_function: "modify", product: TRFProduct,qty: Newqty}, function(data) {
		window.location.reload();
		});
	
		

};



function DeleteProduct (product_)
{
	var conf = confirm("Do you really want to remove this product from the basket?");
	if (conf == true)
	{
	
	
	 $.get( '/wp-content/php/ajax_scripts.php', { cart_function: "delete", product: product_.replace("Remove_", "") }, function(data) {
			window.location.reload();
			});
	
	}
	
};

function isIMEI (s) {
	var etal = /^[0-9]{15}$/;
	  if (!etal.test(s))
	    return false;
	  sum = 0; mul = 2; l = 14;
	  for (i = 0; i < l; i++) {
	    digit = s.substring(l-i-1,l-i);
	    tp = parseInt(digit,10)*mul;
	    if (tp >= 10)
	         sum += (tp % 10) +1;
	    else
	         sum += tp;
	    if (mul == 1)
	         mul++;
	    else
	         mul--;
	    }
	  chk = ((10 - (sum % 10)) % 10);
	  if (chk != parseInt(s.substring(14,15),10))
	    return false;
	  return true;
	}


function AddSingleToCart(product_, description_, type_, price_,checkout_,NonVirgin_)
{
	var IMEI_='';
if ((type_=='PHONE')&&( description_.indexOf("ipad") == -1))

	{
	IMEI_=$("#IMEINumber").val();
	
	
	
	if (isIMEI(IMEI_)==false)
		{
		alert('Please enter valid IMEI code.');
		return
		
		}
	}
	
	$.get( '/wp-content/php/ajax_scripts.php', { cart_function: "add", product: product_, descr: description_, qty: 1, type: type_, price: price_, NV: NonVirgin_, IMEI: IMEI_}, function(data) {
		$('#SidebarcartInner').html( "<a href=\"/view-basket\"><img width=\"54\" height=\"56\" align=\"left\" alt=\"checkout\" src=\"../wp-content/themes/trf2011/images/checkout_30.jpg\"></a> <p style=\"color:#80ca01;\">Shopping Basket Totals:</p> <p style=\"color:#80ca01;\"><span style=\"color:#80ca01; font-weight:bold; font-size:14px;\">  &pound  "+data+" </p> ");
		if (type_=='PHONE')
		{
		 
		
		
			$("#IMEINumber").val("");
			
			window.location = "/view-basket";
			
			
			
			
		}
			
		});
	
};





function Destroy()
{
	
	$.get( '/wp-content/php/ajax_scripts.php', { cart_function: "deleteAll"}, function(data) {
		window.location.reload();
		});
	
	
};









