
function onLoadOpen (URL,name,width,height,toolbar) 
{ 				window.open(URL,name,'toolbar='+toolbar+',scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width='+width+',height='+height +''); 
}

	
function SearchForm(theForm) 
{ 				
	if (theForm.SearchTerm.value=='')
	{
		alert("You need to enter a search term.");
		return false;
	}
		
	theForm.submit();
	
}
	
	

function goLite(FRM,BTN)
{
   window.document.forms[FRM].elements[BTN].style.color = "#330000";
  // window.document.forms[FRM].elements[BTN].style.backgroundColor = "#66CCFF";
}

function goDim(FRM,BTN)
{
   window.document.forms[FRM].elements[BTN].style.color = "#666666";
   //window.document.forms[FRM].elements[BTN].style.backgroundColor = "#e2e6f1";
}


function CustomerDetailsForm(theForm)
{
	if (!isEmailAddr(theForm.Customer_Email.value))
	{
		alert("Please enter a valid email address");
		return (false);	
	}

	theForm.submit();
}


function ContactUs(theForm)
{

	if (!isEmailAddr(theForm.Email.value))
	{
		alert("Please enter a valid email address");
		return (false);	
	}
	
	if (theForm.Feedback_text.value.length==0)
	{
		alert("Please enter message.");
		return (false);	
	}
		
	theForm.submit();
}




	function isEmailAddr(email)
	{
	  var result = false
	  var theStr = new String(email)
	  var index = theStr.indexOf("@");
	  if (index > 0)
	  {
    	var pindex = theStr.indexOf(".",index);
	    if ((pindex > index+1) && (theStr.length > pindex+1))
		result = true;
	  }
	  return result;
	}
	

function ValidateDeliveryAddress(theForm)
{
	
	// check email
	if (!isEmailAddr(theForm.Email.value))
	{
		alert("Please enter a valid email address");
		return (false);	
	}

	if (!(theForm.Email.value==theForm.ConfirmEmail.value))
	{
		alert("Please check your email address and try again");
		return (false);	
	}

	// check names
	if (theForm.Firstname.value.length==0)
	{
		alert("Please enter a valid firstname in the delivery form.");
		return (false);		
	}

	if (theForm.Lastname.value.length==0)
	{
		alert("Please enter a valid lastname in the delivery form.");
		return (false);		
	}

	
	// check address
	if (theForm.Address1.value.length==0)
	{
		alert("Please enter a valid delivery address - update Address 1 in the delivery form.");
		return (false);		
	}
	if (theForm.Town.value.length==0)
	{
		alert("Please enter a valid delivery address - update Town/City in the delivery form.");
		return (false);			
	}
	if (theForm.Postcode.value.length==0)
	{
		alert("Please enter a valid delivery address - update the postcode/zip field in the delivery form.");
		return (false);			
	}

	if ((theForm.Country.value!="United Kingdom") && (theForm.Country.value!="United States") )
	{
		alert("Please enter a valid country in the delivery form.");
		return (false);			
	}
		
	theForm.submit();
}



function ProceedToPurchase(theForm,Domain)
{

	if (Domain=="localhost/magnets")
	{
		url = "http://" +Domain +"/paypal.php";	
	}
	else
	{
		url = "http://" +Domain +"/paypal.htm";	
	}
	theForm.action = url;
	
	// now validate the form
	if (!ValidateDeliveryAddress(theForm))
	{
		if (Domain=="localhost/magnets")
		{
			url = "http://" +Domain +"/checkout.php";	
		}
		else
		{
			url = "http://" +Domain +"/checkout.htm";	
		}				
		theForm.action = url;		
	}
}




	function GetExpiry()
	{
		// returns a date 20 days ahead
		
		// set time, it's in milliseconds
		var today = new Date();
		today.setTime( today.getTime() );
		
		var expires = 20 * 1000 * 60 * 60 * 24;
		var expires_date = new Date( today.getTime() + (expires) );		
		return expires_date;	
	}


	function SetCurrency(Currency)
	{	
		var curCookie = 'currency=' + escape(Currency);
		var expires_date = GetExpiry();
		curCookie = curCookie + ";expires=" + expires_date.toGMTString();				
		document.cookie = curCookie;
		//alert (curCookie);		
		//alert('This search has been saved. To use it in future, use the Saved Search option in the left hand menu');
	}

