
 // pre-load the menu mouseovers
 var menuImage=new Array('bangles', 'bracelets', 'brooches', 'earrings', 'necklaces', 'pendants', 'gifts', 'accessories');
 var menuMode0=new Array();
 var menuMode1=new Array();
 for(i=0; i<menuImage.length; i++) {
  menuMode0[i]=new Image(); menuMode0[i].src='/_gfx/menu/'+menuImage[i]+'-0.gif';
  menuMode1[i]=new Image(); menuMode1[i].src='/_gfx/menu/'+menuImage[i]+'-1.gif';
 }


 // quick and dirty redirect
 function go2( destUrl ) {
  document.location.href=destUrl;
 }

 
 // validate the contact form
 function checkContactForm() {
  var cf=document.getElementById('contactform');
  var de=0;
  if((de==0)&&(cf.name.value.length<4))     { de=1; alert('Please Enter your Full Name'); cf.name.focus(); }
  if((de==0)&&(!isMail(cf.email.value)))    { de=2; alert('Please Enter a Valid Email Address'); cf.email.focus(); }
  if((de==0)&&(cf.comment.value.length<10)) { de=3; alert('Please Enter a Longer Comment'); cf.comment.focus(); }
  if(de==0) { cf.submit(); }
 }

 // output some debug text
 function debug( strOutput ) {
  var df=document.getElementById('debugform');
  if(df) { df.output.value=strOutput; }
 }


 // highlight a main menu item under the mouse
 function hlMenu( objMenu, hlMode ) {
  var i=objMenu.id.substr(2,1); 
  if(hlMode==1) { objMenu.src=menuMode1[i-1].src; showMenu(objMenu, 1); }
  else          { objMenu.src=menuMode0[i-1].src; }
 }
 

 // Track Mouse Pointer
 var mouseX  =0;
 var mouseY  =0;
 
 function mouseCoords(e) {
  var posx = 0;
  var posy = 0;
  if (!e) { var e = window.event; }
  if (e.pageX || e.pageY) {
   posx = e.pageX;
   posy = e.pageY;
  } else if (e.clientX || e.clientY) 	{
   posx = e.clientX + document.body.scrollLeft;
   posy = e.clientY + document.body.scrollTop;
  }
  mouseX=posx;
  mouseY=posy;
 }


 // find object position
 function findPos(obj) {
  var curleft=0;
  var curtop =0;
  if(obj.offsetParent) {
   curleft=obj.offsetLeft;
   curtop =obj.offsetTop;
   while(obj=obj.offsetParent) {
    curleft+=obj.offsetLeft;
    curtop +=obj.offsetTop;
   }
  }
  return [curleft,curtop];
 }

 
 // display the drop-down menu list
 function showMenu( objMenu, hlMode ) {
  var pos=findPos(objMenu);
  var id =objMenu.id.substr(2,1);
  var mo ='';
  // hide all menus but the specified one
  for(m=1; m<9; m++) {
   mo=document.getElementById('menuList'+m); // Menu List Object
   if(mo) {
    if(m==id) {
	 mo.style.left   =(pos[0])+'px';
	 mo.style.top    =(pos[1]+35)+'px';
	 mo.style.display='block';
	} else {
	 mo.style.display='none';
	}
   }
  }
 }

 function hideMenus() {
  for(m=1; m<9; m++) {
   mo=document.getElementById('menuList'+m); // Menu List Object
   mo.style.display='none';
  }
 } 
 
 function hlItem( objItem, hlMode ) {
  var itemFill=new Array('#E0F2F1', '#ffffff');
  objItem.style.backgroundColor=itemFill[hlMode];
 }

 // popup functions
 function popShow( strText ) {
  var pb=document.getElementById('popbox');
  var pp=document.getElementById('popup');
  pp.innerHTML='<p>'+strText+'</p>\n<p><input type="button" class="btn" value="Okay" onclick="popHide();"/></p>\n';
  pb.style.display='block';
 }
 function popHide() { document.getElementById('popbox').style.display='none'; }


 // highlight a row in a table
 function hlRow( objRow, hlMode ) {
  var tdList=objRow.getElementsByTagName('td');
  var tdCol='#ffffff'; if(hlMode==1) { tdCol='#eeeeee'; }
  for(td=0; td<tdList.length; td++) { tdList[td].style.backgroundColor=tdCol; }
 }


 // log out of the /Account/ area
 function logout() {
  if(confirm('Are you sure you want to log out of your account?')) {
   go2('/Account/logout.php');
  }
 }


 // validate a string as an email address
 function isMail(email) {
  return email.search(/^[\.\w_'-]+@[\w_'-]+\.[\w_-]+(\.[\w_-]+)*$/)==-1 ? false : true;
 }
 

 // check the join form - used for joiing and editing details.
 function joinformCheck( fMode ) {
  var jf=document.getElementById('joinform');
  var de=0;
  if((de==0)&&(jf.forename.value.length<2))      { de=1; alert('Please Enter your Forename'); jf.forename.focus(); }
  if((de==0)&&(jf.surname.value.length<2))       { de=1; alert('Please Enter your Surname'); jf.surname.focus(); }
  if((de==0)&&(!isMail(jf.email.value)))         { de=2; alert('Please Enter a Valid Email Address'); jf.email.focus(); }
  if((de==0)&&(jf.email.value!=jf.email2.value)) { de=2; alert('Email Addresses do not Match!'); jf.email.focus(); }
  if((de==0)&&(jf.chaddr1.value==''))            { de=3; alert('Please Complete the First Line of the Cardholder\'s Address'); jf.chaddr1.focus(); } 
  if((de==0)&&(jf.chaddr2.value==''))            { de=3; alert('Please Complete the Second Line of the Cardholder\'s Address'); jf.chaddr2.focus(); } 
  if((de==0)&&(jf.chpostcode.value==''))         { de=3; alert('Please Enter the Cardholder\'s Postcode'); jf.chpostcode.focus(); }
  if(fMode==1) { // extra fields for delivery address as part of protx checkout process
   if((de==0)&&(jf.addr1.value==''))              { de=4; alert('Please Complete the First Line of the Delivery Address'); jf.addr1.focus(); } 
   if((de==0)&&(jf.addr2.value==''))              { de=4; alert('Please Complete the Second Line of the Delivery Address'); jf.addr2.focus(); } 
   if((de==0)&&(jf.postcode.value==''))           { de=4; alert('Please Enter the Delivery Postcode'); jf.postcode.focus(); }
  } // end of extra fields
  if(de==0) { jf.submit(); }
 }


 function creditOrderCheck() {
  var jf=document.getElementById('joinform');
  var de=0;
  if((de==0)&&(jf.addr1.value==''))              { de=4; alert('Please Complete the First Line of the Delivery Address'); jf.addr1.focus(); } 
  if((de==0)&&(jf.addr2.value==''))              { de=4; alert('Please Complete the Second Line of the Delivery Address'); jf.addr2.focus(); } 
  if((de==0)&&(jf.postcode.value==''))           { de=4; alert('Please Enter the Delivery Postcode'); jf.postcode.focus(); }
  if(de==0) { jf.submit(); }
 } 


 // check the passwords on the 'Change Password' form
 function checkPass() {
  var pf=document.getElementById('passwordform');
  var de=0;
  if((de==0)&&(pf.p1.value.length<6))      { de=1; alert('Passwords must be 6-32 characters long.'); pf.p1.focus(); }
  if((de==0)&&(pf.p1.value!=pf.p2.value)) { de=2; alert('Passwords do not match!'); pf.p1.focus(); }
  if(de==0) {
   if(confirm('Are you sure you want to set this new password?')) {
    pf.submit();
   }
  }
 }


 // copy the Cardholder's Address to the Delivery Address
 function addrCopy() {
  var jf=document.getElementById('joinform');
  jf.addr1.value=jf.chaddr1.value;
  jf.addr2.value=jf.chaddr2.value;
  jf.addr3.value=jf.chaddr3.value;
  jf.addr4.value=jf.chaddr4.value;
  jf.postcode.value=jf.chpostcode.value;
  jf.country.value=jf.chcountry.value;
 }

 // delete a line from the shopping basket 
 function lineDel( lineId ) {
  if(confirm('Are you sure you want to remove this line?')) {
   var lineForm=document.getElementById('line'+lineId);
   lineForm.quan.value=0;
   lineForm.submit();
  }
 }

 function cardformcheck() {
  var cf=document.getElementById('cardinfoform');
  var de=0;
/*
  cf.cardnum.value =makenum(cf.cardnum.value);
  cf.valfrom1.value=makenum(cf.valfrom1.value);
  cf.valfrom2.value=makenum(cf.valfrom2.value);
  cf.valtill1.value=makenum(cf.valtill1.value);
  cf.valtill2.value=makenum(cf.valtill2.value);
  cf.secureno.value=makenum(cf.secureno.value);
*/
  if((de==0)&&(cf.cardtype.value==0)) { de=1; alert('Please Choose a Card Type'); cf.cardtype.focus(); }
  if((de==0)&&(cf.cardnum.value.length<16))  { de=2; alert('Please Check your Card Number'); cf.cardnum.focus(); }
  if((de==0)&&(cf.cardname.value.length<4))  { de=3; alert('Please Check the Cardholder Name'); cf.cardname.focus(); }
  if((de==0)&&(cf.valtill1.value.length!=2)) { de=4; alert('Please Check this Date'); cf.valtill1.focus(); }
  if((de==0)&&(cf.valtill2.value.length!=2)) { de=4; alert('Please Check this Date'); cf.valtill2.focus(); }
  if((de==0)&&(cf.secureno.value.length!=3)) { de=4; alert('Please Check the Security Code'); cf.secureno.focus(); }
  if(de==0) {
   if(confirm('Are you sure you want to submit these details?\n(Your card will not be charged at this time.)')) {
    cf.submit();
   }
  }
 }
