<!--

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.01
  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 && d.getElementById) x=d.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 MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
    } else if (test!='R') { num = parseFloat(val);
      if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
      if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
        min=test.substring(8,p); max=test.substring(p+1);
        if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function confirmLink(data) {
  if (confirm(data)) { return true; }
  return false;
  }

function popup(width,height,location,needscroll) {
  var options,top=(screen.availHeight-height)/2,left=(screen.availWidth-width)/2;
  options = "top="+top+",left="+left+",location=0,status=0,";
  options = options+"toolbar=0,menubar=0,directories=0,width=";
  if (width <= screen.availWidth) { options = options + width; }
    else { value = screen.availWidth-12; options = options + value; needscroll = true; }
  options = options + ",height=";
  if (height <= screen.availHeight) { options = options + height; }
    else { value = screen.availHeight-30; options = options + value; needscroll = true; }
  if (needscroll == true) { options = "scrollbars,resizable," + options; }
    else { options = "scrollbars=0,resizable=0," + options; }
  if (window.cwin) cwin.close();
  cwin=window.open(location,"",options);
}

var orderSubmitted = false;

function checkorder(frm)
    {

    if (frm.forename.value.length < 2)
        {
        alert('You must provide your forename');
        frm.forename.focus();
        frm.forename.select();
        return false;
        }

    if (frm.surname.value.length < 2)
        {
        alert('You must provide your surname');
        frm.surname.focus();
        frm.surname.select();
        return false;
        }

    if (frm.address1.value == "")
        {
        alert('You must provide the first line of your address');
        frm.address1.focus();
        frm.address1.select();
        return false;
        }

    if (frm.address2.value == "")
        {
        alert('You must provide the second line of your address');
        frm.address2.focus();
        frm.address2.select();
        return false;
        }

    if (frm.postcode.value == "")
        {
        alert('You must provide your postcode');
        frm.postcode.focus();
        frm.postcode.select();
        return false;
        }

    if (frm.country.value == "")
        {
        alert('You must provide your country');
        frm.country.focus();
        frm.country.select();
        return false;
        }

    var error = checkEmail(frm.email.value);
    if (error != "")
        {
        alert(error);
        frm.email.focus();
        frm.email.select();
        return false;
        }

    if (frm.telephone.value.length < 7)
        {
        alert('You must provide a valid telephone number');
        frm.telephone.focus();
        frm.telephone.select();
        return false;
        }

    var cardtype = "";
    for (var i=0;i<frm.cardtype.length;i++)
        {
        if (frm.cardtype[i].checked)
            {
            cardtype = frm.cardtype[i].value;
            }
        }

    if (cardtype == "")
        {
        alert('You must choose a payment type');
        return false;
        }

    if (cardtype != "cheque")
        {

        var panRegExp = "";
        switch(cardtype)
            {
            case "electron": // Electron, 16, 45/48/49
                panRegExp = /^(45|48|49)\d{14}$/;
                break;
            case "jcb": // JCB, 15, 2131/1800, 16, 30/31/33/35
                panRegExp = /^((2131|1800)\d{11}|3[0135]\d{14})$/;
                break;
            case "solo": // Solo, 16/18/19, 63/67
                panRegExp = /^(63|67)\d{14}(\d{2,3})?$/;
                break;
            case "switch": // Switch, 16/18/19, 49/56/63/67
                panRegExp = /^(49|56|63|67)\d{14}(\d{2,3})?$/;
                break;
            case "amex": // AMEX, 15, 34/37
                panRegExp = /^(34|37)\d{13}$/;
                break;
            case "laser": // Laser, 16/18/19, 6304
                panRegExp = /^6304\d{12}(\d{2,3})?$/;
                break;
            case "eurocard": // Eurocard, as per Mastercard
            case "mastercard": // Mastercard, 16, 51-55
                panRegExp = /^5[1-5]\d{14}$/;
                break;
            case "visa": // VISA, 13/16, 4
                panRegExp = /^4\d{12}(\d{3})?$/;
                break;
            case "delta": // Delta, 16, 41/44/45/46/49
                panRegExp = /^(41|44|45|46|49)\d{14}$/;
                break;
            case "maestro": // Maestro, any, 50/56/57/58/6
                panRegExp = /^(50|56|57|58|6)/;
                break;
            case "dccb": // Diners Club + Carte Blanche, 14, 30/36/38
                panRegExp = /^(30|36|38)\d{12}$/;
                break;
            case "discover": // Discover, 16, 6011
                panRegExp = /^6011\d{12}$/;
                break;
            case "enroute": // Enroute, 15, 2014/2149
                panRegExp = /^(2014|2149)\d{11}$/;
                break;
            }

        if (panRegExp == "")
            {
            alert('You must select a payment type');
            return false;
            }

        if (frm.cardname.value.length < 4)
            {
            alert('You must provide the card holder name');
            frm.cardname.focus();
            frm.cardname.select();
            return false;
            }

        if (frm.cardnumber.value.length < 11)
            {
            alert('You must provide the card number');
            frm.cardnumber.focus();
            frm.cardnumber.select();
            return false;
            }

        var ccRegExp = /[^\d -]/;

        var isValid = !ccRegExp.test(frm.cardnumber.value);

        if (!isValid)
            {
            alert('Your card number must only contains the numbers 0-9');
            frm.cardnumber.focus();
            frm.cardnumber.select();
            return false;
            }

        var panOnly = frm.cardnumber.value.replace(/[^0-9]/g,'');
        isValid = panRegExp.test(panOnly);

        if (!isValid)
            {
            alert('There is a problem with your card details, please check the card type and card number');
            frm.cardnumber.focus();
            frm.cardnumber.select();
            return false;
            }

        var numberProduct, numberProductDigitIndex, checkSumTotal = 0;
        for (digitCounter = (panOnly.length - 1); digitCounter >= 0; digitCounter--)
            {
            checkSumTotal += parseInt (panOnly.charAt(digitCounter));
            digitCounter--;
            numberProduct = String((panOnly.charAt(digitCounter) * 2));
            for (var productDigitCounter = 0; productDigitCounter < numberProduct.length; productDigitCounter++)
                {
                checkSumTotal += parseInt(numberProduct.charAt(productDigitCounter));
                }
            }

        isValid = (checkSumTotal % 10 == 0);

        if (!isValid)
            {
            alert('There is a problem with your card details, please check the card number');
            frm.cardnumber.focus();
            frm.cardnumber.select();
            return false;
            }

        if (frm.cardexpirymonth.value.length < 1)
            {
            alert('You must provide the card expiry date');
            frm.cardexpirymonth.focus();
            frm.cardexpirymonth.select();
            return false;
            }

        if (frm.cardexpiryyear.value.length < 1)
            {
            alert('You must provide the card expiry date');
            frm.cardexpiryyear.focus();
            frm.cardexpiryyear.select();
            return false;
            }

        var cardExpiry = parseInt ('1' + pad(frm.cardexpiryyear.value,2) + pad(frm.cardexpirymonth.value,2));
        var thisMonth = parseInt ('1' + frm.thismonth.value);

        if (cardExpiry < thisMonth)
            {
            alert('Your card expiry date is invalid');
            frm.cardexpirymonth.focus();
            return false;
            }

        if ((cardtype == 'visa') && (frm.cardcvv.value.length != 3))
            {
            alert('You need to enter the three digit security code found on your VISA card');
            frm.cardcvv.focus();
            frm.cardcvv.select();
            return false;
            }

        if ((cardtype == 'mastercard') && (frm.cardcvv.value.length != 3))
            {
            alert('You need to enter the three digit security code found on your MasterCard');
            frm.cardcvv.focus();
            frm.cardcvv.select();
            return false;
            }

        if ((cardtype == 'amex') && (frm.cardcvv.value.length != 4))
            {
            alert('You need to enter the four digit security code found on your American Express card');
            frm.cardcvv.focus();
            frm.cardcvv.select();
            return false;
            }

        }

    if (orderSubmitted)
        {
        alert('You have already submitted your order, please wait...');
        return false;
        }

    orderSubmitted = true;
    return true;
    }

function pad(number,length)
    {
    var str = '' + number;
    while (str.length < length) { str = '0' + str; }
    return str;
    }

function checkEmail(strng)
    {
    var error = "";
    if (strng == "") { error = "You must provide an email address"; }
    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng)))
        {
        error = "You must provide a valid email address";
        }
    else
        {
        var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/;
        if (strng.match(illegalChars))
            {
            error = "The email address contains illegal characters";
            }
        }
    return error;
    }


//-->
