function SimpleSwap(el,which,large){
	el.src=which;
	LargeImage=large; 

  return true;
}
function SimpleSwapSetup(){
  var x = document.getElementsByTagName("img");
  for (var i=0;i<x.length;i++){
    var oversrc = x[i].getAttribute("oversrc");
    if (!oversrc) continue;
      
    // preload image
    // comment the next two lines to disable image pre-loading
    x[i].oversrc_img = new Image();
    x[i].oversrc_img.src=oversrc;
    // set event handlers
    x[i].onmouseover = new Function("SimpleSwap(this,'oversrc');");
    x[i].onmouseout = new Function("SimpleSwap(this);");
    // save original src
    x[i].setAttribute("origsrc",x[i].src);
  }
}

function popImage(imageURL,imageTitle){
	openPopup(imageURL,imageTitle);
}

function openPopup (imageURL, caption) {

/*
This routine creates a pop-up window, and ensures that it takes focus. It is 
intended to be called from an anchor tag. The new window will resize itself to 
the optimum size, so we make it as large as the largest required window to
overcome bugs in various manifestations of various browsers.
  
Author:   John Gardner
Written:  8th November 2003
Updated:  27th January 2004

Calling sequence: <a href="a.jpg" onClick="return openLargeImage('a.jpg','Caption');">

The first parameter is the URL of the image to be opened, and the second 
parameter is the caption for the image which is displayed in the window title
and in the alt property of the image tag.

Note that the calling sequence will simply open the image in the main window if
JavaScript isn't enabled.
  
*/

  // Constants - change these to suit your requirements Note that the defaultWidth
  // and defaultHeight variables should be set to more than your largest image to
  // overcome a bug in Mozilla (at least up to Firefox 0.9).

  var windowTop = 50;                // Top position of popup
  var windowLeft = 100                // Left position of popup
  var defaultWidth = 730;             // Default width (for browsers that cannot resize)
  var defaultHeight = 532;            // Default height (for browsers that cannot resize)
  var onLoseFocusExit = true;         // Set if window to exit when it loses focus
  var undefined;

  // Set up the window open options
  var Options = "width=" + defaultWidth + ",height=" + defaultHeight + ",top=" + windowTop + ",left=" + windowLeft + ",scrollbars=yes,resizable"
  
  // Now write the HTML markup to the new window, ensuring that we insert the 
  // parameter URL of the image and the parameter description of the image in 
  // the right place.
  var myScript = "<html>\n" + 
    "<head>\n" + 
	"<title>" + caption + "\</title>\n" +
	"<link href=/css/style.css rel=StyleSheet type=text/css>\n" +     
    "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n" +
    "<meta http-equiv=\"Content-Language\" content=\"en-gb\">\n" +
    "<script language=\"JavaScript\" type=\"text/javascript\">\n" +
    "function resizewindow () {\n" +
    "  var width = document.myimage.width;\n" + 
    "  var height = document.myimage.height;\n";
  
  // Netscape  
  if (navigator.appName.indexOf("Netscape") != -1) {  
    myScript = myScript +  "  window.innerHeight = height+30;\n  window.innerWidth = width+20;\n"
  }
   
  // Opera 
  else if (navigator.appName.indexOf("Opera") != -1) {
    myScript = myScript +  "  window.resizeTo (width+20, height+60);\n"
  }
  
  // Microsoft 
  else if (navigator.appName.indexOf("Microsoft") != -1) { 
    //alert(imageURL);
	var img = new Image();
	
	img.src = imageURL;
	//alert(img.src);
	var height = img.height;
	height = img.height;
	//alert(height);
	
	if (height<=500) {
		 myScript = myScript + "  window.resizeTo (width+50, height+75);\n" 
	 } else {
		 myScript = myScript + "  window.resizeTo (width+50, height+75);\n" 
	}
	
  }
  
  // Assume a frig factor for any other browsers
  else {
    myScript = myScript + "  window.resizeTo (width+20, height+30);\n"
  }
      
  myScript = myScript + "}\n" + "window.onload = resizewindow;\n" +
    "</script>\n</head>\n" + "<body ";
    
  // If the window is required to close when it loses focus.
  if (onLoseFocusExit) {myScript = myScript + "onblur=\"self.close()\" ";}
    
  myScript = myScript + "style=\"margin: 5px; padding-right: 5px; padding-bottom: 5px; margin-bottom: 5px;\">\n" +  
	"<p align=center>\n" + 
    "<img src=\"" + imageURL + "\" alt=\"" + caption + "\" title=\"" + caption + "\" name=\"myimage\" style=\"border: solid 1px #3f3f3f\">\n" + 
    "</p></body>\n" +  "</html>\n";
        
  // Diagnostic - uncomment the next line if you wish to see the script generated.   
  //alert (myScript);
  
  // Create the popup window
  var imageWindow = window.open ("","",Options);
  //alert(myScript);
  imageWindow.document.write (myScript)
  imageWindow.document.close ();
  if (window.focus) imageWindow.focus();
  return false;
}


// Validation rounites for Advansys eCommerce with CMS

function CheckSearch(form){
	if (form.search.value.length <=1){alert('Please enter one or more keywords'); return false;}
	return true;
}

function CheckCustomerLogin(form){
	if (form.email.value=='') {alert('Please enter your email address');form.email.focus(); return false;}
	if (!CheckEmail(form.email.value)) {alert('Please enter a valid email address');form.email.focus(); return false;}
	if (form.password.value=='') {alert('Please enter your password'); form.password.focus(); return false;}
	return true;
}

function CheckCustomerLogin1(form){
    if (form.NewsletterName2.value=='') {alert('Please enter your name');form.NewsletterName2.focus(); return false;}
	if (form.email.value=='') {alert('Please enter your email address');form.email.focus(); return false;}
	if (!CheckEmail(form.email.value)) {alert('Please enter a valid email address');form.email.focus(); return false;}
	
	return true;
}




function checkTradeLogin(form){
	if (form.tradeEmail.value=='' || form.tradeEmail.value=='Name') {alert('Please enter your Email');form.tradeEmail.focus(); return false;}
	if (!CheckEmail(form.tradeEmail.value)) {alert('Please enter a valid email address');form.tradeEmail.focus(); return false;}
	if (form.tradePassword.value=='') {alert('Please enter your Password');form.tradePassword.focus(); return false;}
	
	return true;
}









function CheckCustomerData(form){
	if (form.title.value=='') {alert('Please select a title'); form.title.focus(); return false;}
	if (form.firstname.value=='') {alert('Please enter your first name'); form.firstname.focus(); return false;}
	if (form.lastname.value=='') {alert('Please enter your last name'); form.lastname.focus(); return false;}
	if (form.address1.value=='') {alert('Please enter your address'); form.address1.focus(); return false;}
	if (form.city.value=='') {alert('Please enter your town or city'); form.city.focus(); return false;}
	if (form.county.value=='') {alert('Please enter your county'); form.county.focus(); return false;}
	if (form.postcode.value=='') {alert('Please enter your postcode'); form.postcode.focus(); return false;}
	if (form.country.value=='') {alert('Please select your country of residence'); form.country.focus(); return false;}
	if (form.firstname.value=='') {alert('Please enter your first name'); form.firstname.focus(); return false;}
	if (form.telephone.value=='') {alert('Please enter a contact telephone number'); form.telephone.focus(); return false;}
	if (form.email.value=='') {alert('Please enter your email address');form.email.focus(); return false;}
	if (!CheckEmail(form.email.value)) {alert('Please enter a valid email address');form.email.focus(); return false;}
	if (form.password.value=='') {alert('Please enter a password');form.password.focus(); return false;}
	return true;
}

function CheckCardData(form, gateway){

	if (gateway == 'EPAYMENTS'){
	
		if (form.ePaymentsStreet.value=="") {alert('Please enter your street'); form.ePaymentsStreet.focus(); return false;}
		if (form.ePaymentsCity.value=="") {alert('Please enter your town or city'); form.ePaymentsCity.focus(); return false;}
		if (form.ePaymentsState.value=="") {alert('Please enter your state'); form.ePaymentsState.focus(); return false;}
		if (form.ePaymentsPostCode.value=="") {alert('Please enter your postcode'); form.ePaymentsPostCode.focus(); return false;}	
		if (form.ePaymentsEmail.value=="") {alert('Please enter your email address');form.ePaymentsEmail.focus(); return false;}
		if (!CheckEmail(form.ePaymentsEmail.value)) {alert('Please enter a valid email address');form.ePaymentsEmail.focus(); return false;}
		if (form.ePaymentsPhoneNumber.value=="") {alert('Please enter a contact telephone number'); form.ePaymentsPhoneNumber.focus(); return false;}	
		if (form.ePaymentsCardType.value==""){alert('Please select the Card Type');form.ePaymentsCardType.focus();  return false;}
		if (form.ePaymentsCardNumber.value==""){alert('Please specify the Card Number');form.ePaymentsCardNumber.focus();  return false;}
		if (form.ePaymentsCardName.value==""){alert('Please specify the Card Name'); form.ePaymentsCardName.focus(); return false;}
		if (form.ePaymentsExpiryDateMM.value==""){alert('Please specify the Expiry Date');form.ePaymentsExpiryDateMM.focus();  return false;}
		if (form.ePaymentsExpiryDateYY.value==""){alert('Please specify the Expiry Date'); form.ePaymentsExpiryDateYY.focus(); return false;}
		if (form.ePaymentsCV2.value==""){alert('Please specify the CVV (last 3 digits on the reverse of you card)');form.ePaymentsCV2.focus();  return false;}
		return true;

	}
	else if (gateway  == 'VELOCITY') {
		if (form.VPBillingStreet.value=='') {alert('Please enter your street'); form.VPBillingStreet.focus(); return false;}
		if (form.VPBillingCity.value=='') {alert('Please enter your town or city'); form.VPBillingCity.focus(); return false;}
		if (form.VPBillingState.value=='') {alert('Please enter your state'); form.VPBillingState.focus(); return false;}
		if (form.VPBillingPostCode.value=='') {alert('Please enter your postcode'); form.VPBillingPostCode.focus(); return false;}
		if (form.VPBillingPhoneNumber.value=='') {alert('Please enter a contact telephone number'); form.VPBillingPhoneNumber.focus(); return false;}
		if (form.VPBillingEmail.value=='') {alert('Please enter your email address');form.VPBillingEmail.focus(); return false;}
		if (!CheckEmail(form.VPBillingEmail.value)) {alert('Please enter a valid email address');form.VPBillingEmail.focus(); return false;}
		if (form.VPCardNumber.value==''){alert('Please specify the Card Number');form.VPCardNumber.focus();  return false;}
		if (form.VPCardName.value==''){alert('Please specify the Card Name'); form.VPCardName.focus(); return false;}
		if (form.VPStartDateMM.value==''){alert('Please specify the Start Date');form.VPStartDateMM.focus();  return false;}
		if (form.VPStartDateMM.value==''){alert('Please specify the Start Date');form.VPStartDateMM.focus();  return false;}
		if (form.VPExpiryDateMM.value==''){alert('Please specify the Expiry Date');form.VPExpiryDateMM.focus();  return false;}
		if (form.VPExpiryDateYY.value==''){alert('Please specify the Expiry Date'); form.VPExpiryDateYY.focus(); return false;}
		if (form.VPCV2.value==''){alert('Please specify the CVV (last 3 digits on the reverse of you card)');form.VPCV2.focus();  return false;}
		return true;
	
	}
	else if (gateway  == 'METACHARGE') {

		if (form.strAddress.value=='') {alert('Please enter your address'); form.strAddress.focus(); return false;}
		if (form.strCity.value=='') {alert('Please enter your town or city'); form.strCity.focus(); return false;}
		if (form.strState.value=='') {alert('Please enter your state'); form.strState.focus(); return false;}
		if (form.strPostcode.value=='') {alert('Please enter your postcode'); form.strPostcode.focus(); return false;}		
		if (form.strEmail.value=='') {alert('Please enter your email address');form.strEmail.focus(); return false;}
		if (!CheckEmail(form.strEmail.value)) {alert('Please enter a valid email address');form.strEmail.focus(); return false;}
		if (form.strTel.value=='') {alert('Please enter a contact telephone number'); form.strTel.focus(); return false;}
		if (form.strCardType.value==""){alert('Please specify the Card Type');form.strCardType.focus();  return false;}		
		if (form.strCardHolder.value==''){alert('Please specify the Card Name'); form.strCardHolder.focus(); return false;}
		if (form.strCardNumber.value==''){alert('Please specify the Card Number');form.strCardNumber.focus();  return false;}
		//if (form.MCStartDateMM.value==''){alert('Please specify the Start Date');form.MCStartDateMM.focus();  return false;}
		//if (form.MCStartDateYY.value==''){alert('Please specify the Start Date');form.MCStartDateYY.focus();  return false;}
		if (form.MCExpiryDateMM.value==''){alert('Please specify the Expiry Date');form.MCExpiryDateMM.focus();  return false;}
		if (form.MCExpiryDateYY.value==''){alert('Please specify the Expiry Date'); form.MCExpiryDateYY.focus(); return false;}
		if (form.intCV2.value==''){alert('Please specify the CVV (last 3 digits on the reverse of you card)');form.intCV2.focus();  return false;}
		return true;
	
	}
}

function CheckDeliveryData(form){
	if (form.delname.value==''){alert('Please specify the Delivery Name'); return false;}
	if (form.deladdress1.value==''){alert('Please specify the Delivery Address'); return false;}
	if (form.delcity.value==''){alert('Please specify the Delivery City'); return false;}
	if (form.delcountrycode.value==''){alert('Please specify the Delivery Country'); return false;}
	return true;
}

function CheckOrder(form){
	if (!form.termsagreed.checked){ alert('You must agree to the terms and conditions before placing an order'); return false;}
	return true;
}
	
function CheckEmail(address) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(address)){
	return (true)
	}
	return (false)
}

function CheckIntegerNow(e) {
var isNS4 = (navigator.appName=="Netscape")?1:0;
 if(!isNS4){
  if ((e.keyCode > 7 && e.keyCode < 10) || (e.keyCode > 27 && e.keyCode < 30) || (e.keyCode == 46) || e.keyCode > 47 && e.keyCode < 58)
  {
   e.returnValue = e.keyCode ;
  }
  else
  {
   e.cancelBubble = true ;
   e.returnValue = false ;
  }
 } else {
  if ((e.which > 7 && e.which < 10) || (e.which > 27 && e.which < 30) || (e.which == 46) || e.which > 47 && e.which < 58) {
   return true;
  }
  return false;
 }
}
var oldcolorid="depdesc1"
function changecolor(colorid){
	document.getElementById(oldcolorid).className="depdesc";
	document.getElementById(colorid).className="depdesc_sel";
	oldcolorid=colorid;
}


function CheckTelephone(Event) {
	  if   ((Event.keyCode > 7 && Event.keyCode < 10) || (Event.keyCode > 27 && Event.keyCode < 30) || Event.keyCode > 47 && Event.keyCode < 58)
		{
			Event.returnValue = Event.keyCode ;
		}
		else
		{
			Event.cancelBubble = true ;
			Event.returnValue = false ;
		}
 }
	
	
	
function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 32 && (charCode < 48 || charCode > 57))
            return false;

         return true;
      }	
      
      
      


function checkTradeAccountRegistration(form){
	if (form.title.value==''){alert('Please select title');form.title.focus(); return false;}
	if (form.firstname.value==''){alert('Please enter first name');form.firstname.focus(); return false;}
	if (form.lastname.value==''){alert('Please enter last name');form.lastname.focus(); return false;}
	if (form.phone.value==''){alert('Please enter phone number');form.phone.focus(); return false;}
	if (form.email.value==''){alert('Please enter email');form.email.focus(); return false;}
	if (!CheckEmail(form.email.value)) {alert('Please enter a valid email address');form.email.focus(); return false;}
	if (form.password.value==''){alert('Please enter password');form.password.focus(); return false;}
	if (form.confirmpassword.value==''){alert('Please enter confirm password');form.confirmpassword.focus(); return false;}
	if (form.address1.value==''){alert('Please enter address');form.address1.focus(); return false;}
	if (form.city.value==''){alert('Please enter Town/City');form.city.focus(); return false;}
	if (form.county.value==''){alert('Please enter county');form.county.focus(); return false;}
	if (form.postcode.value==''){alert('Please enter postcode');form.postcode.focus(); return false;}
	if (form.country.value==''){alert('Please select country');form.country.focus(); return false;}
	if (form.password.value!=form.confirmpassword.value){alert('Password fields donot match');form.confirmpassword.focus(); return false;}
	return true;
}      



