function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function SetImage(obj, im)
{
	if (document.images) {
	document.images[obj].src= im;
	}
	else
	{
	eval("document."+obj+".src='" +im +"';")
	}
}

function setCookie(name, value, expires, path, domain, secure) 
{
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function getCookie(name) 
{
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function emailCheck (emailStr) 
{
//usage: emailCheck(this.email.value)

/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */

var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */

return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {

return false;
   }
}

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid


return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {

return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
return false;
}

// If we've gotten this far, everything's valid!
return true;
}

function setLastPage(val)
{
	setCookie("fpg",val)
}

function LTrim(str)
/*
PURPOSE: Remove leading blanks from our string.
IN: str - the string we want to LTrim
*/
{
var whitespace = new String(" \t\n\r");

var s = new String(str);

if (whitespace.indexOf(s.charAt(0)) != -1) {
// We have a string with leading blank(s)...

var j=0, i = s.length;

// Iterate from the far left of string until we
// don't have any more whitespace...
while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
j++;

// Get the substring from the first non-whitespace
// character to the end of the string...
s = s.substring(j, i);
}
return s;
}

/*
==================================================================
RTrim(string) : Returns a copy of a string without trailing spaces.
==================================================================
*/
function RTrim(str)
/*
PURPOSE: Remove trailing blanks from our string.
IN: str - the string we want to RTrim

*/
{
// We don't want to trip JUST spaces, but also tabs,
// line feeds, etc. Add anything else you want to
// "trim" here in Whitespace
var whitespace = new String(" \t\n\r");

var s = new String(str);

if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
// We have a string with trailing blank(s)...

var i = s.length - 1; // Get length of string

// Iterate from the far right of string until we
// don't have any more whitespace...
while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
i--;


// Get the substring from the front of the string to
// where the last non-whitespace character is...
s = s.substring(0, i+1);
}

return s;
}

/*
=============================================================
Trim(string) : Returns a copy of a string without leading or trailing spaces
=============================================================
*/
function Trim(str)
/*
PURPOSE: Remove trailing and leading blanks from our string.
IN: str - the string we want to Trim

RETVAL: A Trimmed string!
*/
{
return RTrim(LTrim(str));
} 



function ValidateMailingList(obj)
{
	var optval;
	for (counter = 0; counter < obj.ListType.length; counter++) {
		if (obj.ListType[counter].checked) optval = Trim(obj.ListType[counter].value)
	}
		
	if (optval == "1") {
		if (emailCheck(obj.Email.value))
			{
			return true;
			}
		else
			{
			alert("Please provide a valid e-mail address.")
			obj.Email.focus();
			return false;
			}
	}
		
	else {
		if (obj.NameTitle.selectedIndex ==0 || Trim(obj.firstname.value) =="" || Trim(obj.Surname.value) =="" || Trim(obj.Address.value) ==""){
			alert("Please provide a full name and address.")
			return false;
			}
		else
			{
			return true;
			}
	}
		
}

function ValidateContact(obj)
{
	var bContinue = false;
	var optval;
	for (counter = 0; counter < obj.SubjectType.length; counter++) {
		if (obj.SubjectType[counter].checked) optval = obj.SubjectType[counter].value
	}
	if (optval=="Order Enquiry") {
		if (Trim(obj.OrderNumberEnquiry.value)!="") {
			bContinue = true
		}
		else {
			alert("Please provide your order number.")
			obj.OrderNumberEnquiry.focus();
		}
	}		
	else {
		if (optval=="Order Cancellation") {
			if (Trim(obj.OrderNumberCancel.value)!="") {
				bContinue = true
			}
			else {
				alert("Please provide your order number.")
				obj.OrderNumberEnquiry.focus();
			}
		}
		else {
			bContinue = true
		}
					
	}
	if (bContinue) {
		if (Trim(obj.Message.value)=="") {
			alert("Please provide a message.")
			obj.Message.focus();
			return false;
		}
		else {
			if (obj.NameTitle.selectedIndex==0) {
				alert("Please provide your title.")
				obj.NameTitle.focus();
				return false;
			}
			else if (Trim(obj.FirstName.value)=="") {
				alert("Please provide your first name.")
				obj.FirstName.focus();
				return false;
			}
			else if (Trim(obj.Surname.value)=="") {
				alert("Please provide your surname.")
				obj.Surname.focus();
				return false;
			}
			else if (Trim(obj.Email.value)=="") {
				alert("Please provide your e-mail.")
				obj.Email.focus();
				return false;
			}				
			else {
				if (emailCheck(obj.Email.value)) {
					return true;
				}
				else {				
				alert("Please provide a valid e-mail address.")
				obj.Email.focus();
				return false;
				}
			}
								
		}
	}
	else {
		return false;
	}
							
}

function ValidateCheque(obj)
{
	if (Trim(obj.Cheque_Firstname.value)=="") {
		alert("Please provide your first name.")
		obj.Cheque_Firstname.focus();
		return false;
	}
	else if (Trim(obj.Cheque_Surname.value)=="") {
		alert("Please provide your surname.")
		obj.Cheque_Surname.focus();
		return false;
	}
	else if (Trim(obj.Cheque_Address.value)=="") {
		alert("Please provide your address.")
		obj.Cheque_Address.focus();
		return false;
	}
	else if (Trim(obj.Cheque_Postcode.value)=="") {
		alert("Please provide your address.")
		obj.Cheque_Postcode.focus();
		return false;
	}
	else if (Trim(obj.Cheque_Email.value)=="") {
		alert("Please provide your e-mail.")
		obj.Cheque_Email.focus();
		return false;
	}
	else {
		if (emailCheck(obj.Cheque_Email.value)) {
			return true;
		}
		else {				
			alert("Please provide a valid e-mail address.")
			obj.Cheque_Email.focus();
			return false;
		}
	}		
}


function ValidateCS(obj)
{
	if (obj.Email.value!="") {
		if (emailCheck(obj.Email.value)) {
			return true;
		}
		else {
			alert("Please provide a valid e-mail address.")
			obj.Email.focus();
			return false;
		}
	}
							
	else {
		if (Trim(obj.FirstName.value) !="" &&  Trim(obj.Surname.value) !=""){
			return true;
		}
		else {
			alert("Please provide your first name and Surname.")
			return false;
		}
	}
							
}

function shipping(obj)
{
if (obj.ShippingSameAsBilling.checked)
	{
	obj.M_shipping_address.value = obj.address.value;
	obj.M_shipping_country.value = obj.country.value;
	obj.M_shipping_postcode.value = obj.postcode.value;
	}
}

function ValidateWP(obj)
{

	var e = "";

	var r = true;

	//shipping(obj);
	
	if(Trim(obj.Firstname.value) == "" && Trim(obj.Surname.value) == "")
	{

		e += "\nPlease enter a name";

		r = false;

	}
	else
	{
		obj.name.value = Trim(Trim(obj.NameTitle.value) + " " + Trim(obj.Firstname.value) + " " + Trim(obj.Surname.value));
	}

	if(Trim(obj.address.value) == "")
	{

		e += "\nPlease enter an address";

		r = false;

	}

	if(obj.country.value == "")
	{

		e += "\nPlease select a country";

		r = false;

	}

	if(Trim(obj.postcode.value) == "") 
	{

		e += "\nPlease enter a postcode";

		r = false;

	}

	if(!emailCheck(obj.email.value)) 
	{

		e += "\nPlease enter a valid email address";

		r = false;

	}
	if(obj.paymentType.value == "")
	{

		e += "\nPlease select a payment type";

		r = false;

	}
	
	if (Trim(obj.M_shipping_address.value)=="" || Trim(obj.M_shipping_postcode.value)=="" || obj.M_shipping_country.value=="")
	{
	e += "\nPlease enter a delivery address\n(Click the 'Same as billing address' checkbox if the delivery address is the same as the billing address)";

	r = false;

	}
	
	if(r == false) 
	{

		alert(e);

	}


	return r;

}

function BillingAddress(obj)
{
if (obj.ShippingSameAsBilling.checked)
	{
	if (Trim(obj.address.value) == "" || Trim(obj.postcode.value) == "" || obj.country.selectedIndex == 0)
		{
		alert("Please provide a valid billing address, postcode and country")
		}
	else
		{
		obj.M_shipping_address.value = obj.address.value;
		obj.M_shipping_postcode.value = obj.postcode.value;
		obj.M_shipping_country.selectedIndex = obj.country.selectedIndex;
		}
	}
else
	{
	obj.M_shipping_address.value = "";
	obj.M_shipping_postcode.value = "";
	obj.M_shipping_country.selectedIndex = 0;
	}

}