// for email a friend
function flickerControlDisplay(div_id) 
{
	document.getElementById(div_id).style.display = "block";
}

function fillDeliveryAddress() {	
	var $address1 = document.getElementById("address1_billing").value;
	document.getElementById("address1").value = $address1;
	var $address2 = document.getElementById("address2_billing").value;
	document.getElementById("address2").value = $address2;
	var $town = document.getElementById("town_billing").value;
	document.getElementById("town").value = $town;
	var $country_id = document.getElementById("country_id_billing").value;
	document.getElementById("country_id").value = $country_id;
	var $postcode = document.getElementById("postcode_billing").value;
	document.getElementById("postcode").value = $postcode;
}

function clearTextField(field_name) 
{	
	if(document.getElementById(field_name).value == 'Enter a product name')
	{
		document.getElementById(field_name).value = '';
	}
	return true;
}

function checkStockLevel(tt,stock_level,phone_number)
{
   if(stock_level < 1)
   {
     if(phone_number != '')
	 {
	 	alert('Sorry, this product is temporarily out of stock. Please contact us on '+ phone_number + ' regarding availability.');
	 }
	 else
	 {
	  	alert("Sorry, this product is temporarily out of stock.");
	 }
      tt.quantity.focus();
      return false;
   }
   else if(tt.quantity.value > stock_level)
   {
     if(phone_number != '')
	 {
	  	alert('Sorry, but the quantity you entered exceeds the level of stock ('+stock_level+') available for this product, Please contact us on '+ phone_number + ' regarding availability or use a quantity no greater than '+stock_level+'.');
	 }
	 else
	 {
	  	alert('Sorry, but the quantity you entered exceeds the level of stock ('+stock_level+') available for this product, please use a quantity no greater than '+stock_level+'.');
	 }
      tt.quantity.focus();
      return false;
   }
   else if(tt.quantity.value == '')
   {
      alert("Sorry, you have not entered a quantity, please enter a quantity before adding this product to your basket.");
      tt.quantity.focus();
      return false;
   }
}

function checkTerms() { // Check T & C box is ticked before proceding to paypal
	missinginfo = '';
	if (!document.agreement_form.agreement.checked) 
	{
		missinginfo += '\n - You must agree to the Terms and Conditions';
	}
	
	if (missinginfo != '') 
	{
		missinginfo ='Required information is missing: \n' +
		missinginfo + '\n' + '';
		alert(missinginfo);
		/*return false;*/
	}
	else 
	{
		document.checkout.submit();
		return true;
	}

}

function doNothing() {
}

function MM_openBrWindow(theURL,winName,features) { // Used to open new window
  window.open(theURL,winName,features);
}

function checkEnter(e) // Enable forms to be submitted with 'enter' even if the buttons a graphic
{ //e is event object passed from function invocation
	var characterCode
	if(e && e.which)
	{ //if which property of event object is supported (NN4)
		e = e
		characterCode = e.which //character code is contained in NN4's which property
	}
	else
	{
		e = event
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}
	
	if(characterCode == 13)
	{ //if generated character code is equal to ascii 13 (if enter key)
		document.forms[0].submit() //submit the form
		return false 
	}
	else
	{
		return true 
	}
}