
// // 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/2/'+menuImage[i]+'-0.gif';
//  menuMode1[i]=new Image(); menuMode1[i].src='/_gfx/menu/2/'+menuImage[i]+'-1.gif';
// }
$('.success img, .warning img, .attention img, .information img').live('click', function() {
	$(this).parent().fadeOut('slow', function() {
		$(this).remove();
	});
});

function addToCart(product_id, quantity) {
	$.ajax({
		url: '/cart.add.php',
		type: 'post',
		data: 'prod=' + product_id + '&quan=' + quantity,
		dataType: 'json',
		success: function(json) {
			if (json['success']) {
    	$('#notification').html('<div class="attention" style="display: none;">Success: You have added ' + json['name'] + ' to your shopping cart.<img src="/images/close.png" alt="" class="close" /></div>');
		$('.attention').fadeIn('slow');
		$('#cart_total').html('<span id="cart_total">' + json['count'] + '&nbsp;item(s) - £' + json['total'] + '</span>');
  			}		
		}
    });
}

 // 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; }
 }


 //// position the menus
// function menuPositions() {
//  for(i=0; i<11; i++) {
//	 var m=document.getElementById('menuEntry'+i);
//	 if(m) {
//	  var p=findPos(m);
//		var o=document.getElementById('menuHook'+i);
//		if(o) {
//		 o.style.left=p[0]+'px';
//		 o.style.top =p[1]+'px';
//		}
//	 }
//	}
//	setTimeout('menuPositions()',50);
// }
//
// // 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) {
//  var i=parseInt(objMenu.id.substr(9,2));
//	var p=findPos(objMenu);
//  var m=document.getElementById('menuBorder'+i);
//	m.style.left=p[0];
//	m.style.top =p[1];
//	m.style.visibility='visible';
// }
//
// function hideMenu(objMenu) {
//  objMenu.style.visibility='hidden';
// } 
//
// function hideMenus() {
//  for(m=1; m<9; m++) {
//	 var mb=document.getElementById('menuBorder'+m);
//	 if(mb) {
//	  mb.style.top='0px';
//	  mb.style.visibility='hidden';
//	 }
//	}
// }
 
// function hlItem( objItem, hlMode ) {
//  var itemFill=new Array('#ccf1ed', '#ccf1ed');
//  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(); }
 }
 

 // 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();
  }
 }

