function popup(mylink, windowname, width, height, scroll)
{
        if (! window.focus)return true;
        var href;
        if (typeof(mylink) == 'string')
        href=mylink;
        else
        href=mylink.href;
        if (scroll==1)
        window.open(href, windowname, 'scrollbars=yes,status=no,width='+width+',height='+height);
        else
        window.open(href, windowname, 'scrollbars=no,status=no,width='+width+',height='+height);
        return false;
} 
// Add bookmark for both browser engines...
function addBookmark(title,url) {
  if (window.sidebar) {
    window.sidebar.addPanel(title, url,"");
  } else if( document.all ) {
    window.external.AddFavorite( url, title);
  } else if( window.opera && window.print ) {
    return true;
  }
} 

//check all the field on the enquiry form have been completed
function checkContactAndSubmit(){
	
	var myret=true;	
	myret = emailCheck (document.getElementById('ctl00_ContentPlaceHolder_enquiryEmail').value);
	
	if(myret) {
        document.getElementById('errenquiryEmail').style.display = "none";
        document.getElementById('ctl00_ContentPlaceHolder_enquiryEmail').className="";

        if (!checkfield("enquiryName")) myret=false;
        if (!checkfield("enquiryComments")) myret=false;

        if (myret)
        {
            document.aspnetForm.submit();
        }
	}
	else {
        document.getElementById('errenquiryEmail').style.display = "block";
        document.getElementById('ctl00_ContentPlaceHolder_enquiryEmail').className="enqFieldError";	
	}
}

function checkfield(fld)
{
    var myret=true;
    if (document.getElementById('ctl00_ContentPlaceHolder_' + fld).value == '')
        {
            document.getElementById('err' + fld).style.display = "block";
            document.getElementById('ctl00_ContentPlaceHolder_' + fld).className="enqFieldError";
            myret=false;
        }
    else
        {
            document.getElementById('err' + fld).style.display = "none";
            document.getElementById('ctl00_ContentPlaceHolder_' + fld).className="";
            myret=true;
        }    
    return myret;
}

//validate and submit email address
function checkEmailAndSubmit(form,email,name){
	emailAddress = document.getElementById(email).value;
	
	emailName = document.getElementById(name).value;
	
	emailValid = emailCheck (emailAddress);

	if(emailValid == true && emailName != "") {
		//document.form.submit();
		document.getElementById(form).submit();
	}
	else if (emailValid == false) {
		alert("The email address you entered is not valid, please try again");
	}
	else if (emailName == "") {
		alert("Please enter your name");
	}
}

//validate and submit login details
function checkLoginAndSubmit(form,email,pass){
	emailAddress = document.getElementById(email).value;
	password = document.getElementById(pass).value;
	
	emailValid = emailCheck (emailAddress);

	passwordLength = 5;
	
	if(emailValid == true && password.length>=passwordLength) {
		//document.form.submit();
		document.getElementById(form).submit();
	}
	else {
		alert("The email address you entered is not valid or your password is not long enough, please try again.");
	}
}



// Changes:  Sandeep V. Tamhankar (stamhankar@hotmail.com)

/* 1.1.2: Fixed a bug where trailing . in e-mail address was passing
            (the bug is actually in the weak regexp engine of the browser; I
            simplified the regexps to make it work).
   1.1.1: Removed restriction that countries must be preceded by a domain,
            so abc@host.uk is now legal.  However, there's still the 
            restriction that an address must end in a two or three letter
            word.
     1.1: Rewrote most of the function to conform more closely to RFC 822.
     1.0: Original  */

// This script and many more are available free online at 
// The JavaScript Source!! http://javascript.internet.com

<!-- Begin
function emailCheck (emailStr) {
/* 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. */
	//alert("Email address seems incorrect (check @ and .'s)")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    //alert("The username doesn't seem to be 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) {
	        //alert("Destination IP address is invalid!")
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	//alert("The domain name doesn't seem to be valid.")
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   //alert("The address must end in a three-letter domain, or two letter country.")
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!"
   //alert(errStr)
   return false
}

// If we've gotten this far, everything's valid!
return true;
}
//  End -->

function checkTelephone(fld,msg)
{ 
    var tel = document.getElementById("ctl00_ContentPlaceHolder_" + fld).value;
    tel = tel.replace(/[^\d\+]/g, "");

    if(tel.length < 6)
    {
        document.getElementById("divError" + fld).innerHTML=msg;
        document.getElementById("divError" + fld).className="errorMsg";
        document.getElementById("div" + fld).className="checkoutField fieldError";
        myret=false;
    }
    else
    {
        //Set the cleaned tel number:
        document.getElementById("ctl00_ContentPlaceHolder_" + fld).value = tel;
        //Set the display
        document.getElementById("divError" + fld).innerHTML="";
        document.getElementById("divError" + fld).className="";
        document.getElementById("div" + fld).className="checkoutField";
        myret=true;
    }
    return myret;
}

function checkfield(fld,msg)
{
if ($('ctl00_ContentPlaceHolder_' + fld).value=='')
    {
    document.getElementById("divError" + fld).innerHTML=msg;
    document.getElementById("divError" + fld).className="errorMsg";
    document.getElementById("div" + fld).className="checkoutField fieldError";
    myret=false;
    }
else
    {
    document.getElementById("divError" + fld).innerHTML="";
    document.getElementById("divError" + fld).className="";
    document.getElementById("div" + fld).className="checkoutField";
    myret=true;
    }
return myret;
}


function checkPostCode(fld,country, msg)
{
//First check the country - if it's uK we need to do the check  ctl00_ContentPlaceHolder_Billing_Country

var CountryDD = document.getElementById(country)

var countryID = CountryDD.options[CountryDD.selectedIndex].value
//alert(countryID);

var postcode = document.getElementById('ctl00_ContentPlaceHolder_' + fld).value;

//check to see if a postcode is entered
if (postcode.length == 0) {
    document.getElementById("divError" + fld).innerHTML="Postcode/Zip is required";
    document.getElementById("divError" + fld).className="errorMsg";
    document.getElementById("div" + fld).className="checkoutField fieldError";
    myret=false;
    return myret;
}
//alert('postcode b4' + postcode);

switch (countryID) {
case "211": //United Kingdom
    postcode = validatePostCode(postcode);
    break 
case "212": //UK Isle of Man
    postcode = validatePostCode(postcode);
    break
case "213": //UK Mainland
    postcode = validatePostCode(postcode);
    break
case "214": //UK Northern Ireland
    postcode = validatePostCode(postcode);
    break   
case "215": //UK Scottish Islands
    postcode = validatePostCode(postcode);
    break   
case "230": //United Kingdom
    postcode = validatePostCode(postcode);
    break   
}//switch

//alert('postcode after' + postcode);

if (postcode==false)
    {
    document.getElementById("divError" + fld).innerHTML=msg;
    document.getElementById("divError" + fld).className="errorMsg";
    document.getElementById("div" + fld).className="checkoutField fieldError";
    myret=false;
    }
else
    {
    document.getElementById('ctl00_ContentPlaceHolder_' + fld).value = postcode;
    document.getElementById("divError" + fld).innerHTML="";
    document.getElementById("divError" + fld).className="";
    document.getElementById("div" + fld).className="checkoutField";
    myret=true;
    }
    
//alert('post: ' + myret + postcode)    
return myret;
}

function validatePostCode(toCheck) {
  // Permitted letters depend upon their position in the postcode.
  var alpha1 = "[abcdefghijklmnoprstuwyz]";                       // Character 1
  var alpha2 = "[abcdefghklmnopqrstuvwxy]";                       // Character 2
  var alpha3 = "[abcdefghjkstuw]";                                // Character 3
  var alpha4 = "[abehmnprvwxy]";                                  // Character 4
  var alpha5 = "[abdefghjlnpqrstuwxyz]";                          // Character 5
  
//alert('validatePostCode');
  // Array holds the regular expressions for the valid postcodes
  var pcexp = new Array ();

  // Expression for postcodes: AN NAA, ANN NAA, AAN NAA, and AANN NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1,2})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  
  // Expression for postcodes: ANA NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}[0-9]{1}" + alpha3 + "{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));

  // Expression for postcodes: AANA  NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1}" + alpha4 +"{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  
  // Exception for the special postcode GIR 0AA
  pcexp.push (/^(GIR)(\s*)(0AA)$/i);
  
  // Standard BFPO numbers
  pcexp.push (/^(bfpo)(\s*)([0-9]{1,4})$/i);
  
  // c/o BFPO numbers
  pcexp.push (/^(bfpo)(\s*)(c\/o\s*[0-9]{1,3})$/i);

  // Load up the string to check
  var postCode = toCheck;

  // Assume we're not going to find a valid postcode
  var valid = false;
  
  // Check the string against the types of post codes
  for ( var i=0; i<pcexp.length; i++) {
    if (pcexp[i].test(postCode)) {
    
      // The post code is valid - split the post code into component parts
      pcexp[i].exec(postCode);
      
      // Copy it back into the original string, converting it to uppercase and
      // inserting a space between the inward and outward codes
      postCode = RegExp.$1.toUpperCase() + " " + RegExp.$3.toUpperCase();
      
      // If it is a BFPO c/o type postcode, tidy up the "c/o" part
      postCode = postCode.replace (/C\/O\s*/,"c/o ");
      
      // Load new postcode back into the form element
      valid = true;
      
      // Remember that we have found that the code is valid and break from loop
      break;
    }
  }
  
  // Return with either the reformatted valid postcode or the original invalid 
  // postcode
  if (valid) {return postCode;} else return false;
}