var activeImageID = '';

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_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_findObj(n, d) { //v3.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); 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 newPreloadImages() {
  MM_preloadImages('/24store/image.pl?image_data_id=2','/24store/image.pl?image_data_id=3','/24store/image.pl?image_data_id=4','/24store/image.pl?image_data_id=5','/24store/image.pl?image_data_id=9','/24store/image.pl?image_data_id=11','/24store/image.pl?image_data_id=13','/24store/image.pl?image_data_id=15','/24store/image.pl?image_data_id=17','/24store/image.pl?image_data_id=19','/24store/image.pl?image_data_id=21','/24store/image.pl?image_data_id=23');
}

function setActiveImage(varActiveImageID) {
  activeImageID = varActiveImageID;
}

function newSwapImgRestore(varImageName) {
  if (varImageName != activeImageID) {
    MM_swapImgRestore();
  }
}

function newSwapImage(varImageName, varImageURL) {
  if (varImageName != activeImageID) {
    MM_swapImage(varImageName,'',varImageURL,1);
  }
}

function updateCurrency() {
  string1 = "" + document.location;
  if (string1.substring(string1.length - 13, string1.length - 2) == "currency_id") {
    string1 = string1.substring(0, string1.length - 14);
  }  
  string2 = document.currencyform.currency_id.options[document.currencyform.currency_id.selectedIndex].value;
  document.location.replace(string1 + "&currency_id=" + string2);
}

function openHelp(theURL,winName,features) { //v2.0
  //find centre of screen less half the width and height of instruction window, to centre window
  var vCentreX = (screen.width/2)-280;
  var vCentreY = (screen.height/2)-210;
  features = features + ",left="+vCentreX+",top="+vCentreY;
  window.open(theURL,winName,features);
}

function openMoreInfoView(link_url) {
  moreInfoView = window.open( link_url, "moreInfoView", "location=0,menubar=0,toolbar=0,personalbar=0,status=0,scrollbars=1,width=600,height=500,left=" + (screen.width - 100 - 600) + ",top=100")
}

function validateEmail() {
  var invalidChar = " ";
  var validChar1 = "@";
  var validChar2 = ".";
  var email1 = document.newform.customer_email.value;
  var email2 = document.newform.customer_email2.value;
  if (email1 == '' || email2 == '') {
    alert('You have not filled in both email fields.');
    return false;
  }
  if ((document.newform.customer_email.value.indexOf(validChar1) < 0) || (document.newform.customer_email.value.indexOf(validChar2) < 0)) {
    alert('You have not entered a valid email address. Please re-enter it and try again.');
    return false;
  }
  if (document.newform.customer_email.value.indexOf(invalidChar) > -1) {
    alert('You have not entered a valid email address. Please re-enter it and try again.');
    return false;
  }
  else {
    if (email1 != email2) {
      alert ("You have not entered the same email address twice. Please re-enter it and try again.");
      return false;
    }
    else {
      return true;
    }
  }
}

function validatePassword() {
  var invalidChar = " ";
  var minLength = 6;
  var login1 = document.newform.customer_login.value;
  var password1 = document.newform.customer_password.value;
  var password2 = document.newform.customer_password2.value;
  if (login1 == '' && password1 == '' && password2 == '') {
    return true;
  }
  else {
    if (password1 == '' || password2 == '') {
      alert('You have not filled in both password fields.');
      return false;
    }
    if (document.newform.customer_password.value.length < minLength) {
      alert('Your password must be at least ' + minLength + ' characters long. Please re-enter it and try again.');
      return false;
    }
    if (document.newform.customer_password.value.indexOf(invalidChar) > -1) {
      alert("Your password can not contain spaces. Please re-enter it and try again");
      return false;
    }
    else {
      if (password1 != password2) {
        alert ("You have not entered the same password twice. Please re-enter it and try again.");
        return false;
      }
      else {
        return true;
      }
    }
  }
}

function validateCreate() {
  if (validateEmail() && validatePassword()) {
    return true;
  }
}

function validateUpdate() {
  if (validateEmail()) {
    return true;
  }
}

function enterKeyPressed() {
  if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {
    return true;
  }
}

