// Copyright functionality

// Handles quantity changes by altering other select box
// 
function quantityChange(select1, select2, qtyTotal) {
  select2.value=(qtyTotal - select1.value);
}//end of function


// Copyright functionality
function doCopyRight(){
  Stamp = new Date();
  var Year;

  if (navigator.appName == "Microsoft Internet Explorer")  Year =Stamp.getYear(); 
  else Year =(Stamp.getYear() +1900); 

  document.write('&nbsp;&copy;&nbsp;1999-'+ Year + '&nbsp;');
}//End of function





// Roll Over functionality
// Requires that the initial image tag is named
// eg. <IMG SRC="test.gif" name="testImage">
// The name is then used when calling the rollOver function.
// eg. 

var imgPath = 'graphics/';

function rollOver(name,state)
{
        if (document.images)
        if (state=="on") { eval("document [\'" + name + "\'].src = '" +imgPath + name + "_on.gif'");}
	else { eval("document [\'" + name + "\'].src = '" + imgPath + name + "_off.gif'");}
}//End of function

// Roll Over functionality
// Requires that the initial image tag is named
// eg. <IMG SRC="test.gif" name="testImage">
// The name is then used when calling the rollOver function.
// eg. 

var imgPath = '/graphics/';

function rollOverMulti(name,image,state)
{
        if (document.images)
        if (state=="on") { eval("document [\'" + name + "\'].src = '" +imgPath + image + "_on.gif'");}
	else { eval("document [\'" + name + "\'].src = '" + imgPath + image + "_off.gif'");}
}//End of function


// Roll Over functionality
// Does not need the object named
function rollOverButton(imageObject, imageName) {
  if (document.images){
    imageObject.src = imageName;
  }
}


function isValidEmail(str) {
   if (str == null) {
      return false;
      }
   if (str.indexOf( ' ' ) != -1 ) {
      return false;
      }
   if (str.indexOf('@') < 1) {
      return false;
      }
   if (str.indexOf('.') == -1) {
      return false;
      }
   return true;
}

function isEmpty(aTextField) {
   if ((aTextField==null) || (aTextField.value==null) || (aTextField.value.length==0) ) {
      return true;
   }
   else { return false; }
}

function isLongerThan(aTextField,minLength) {
   if ((aTextField==null) || (aTextField.value==null) || (aTextField.value.length<=minLength) ) {
      return false;
   }
   else { return true; }
}

function isNumeric(sText)
{
   var ValidChars = "0123456789.-+ ";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
	 continue;
         }
      }
   return IsNumber;
}

function isInteger(sText)
{
   var ValidChars = "0123456789-+";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
	 continue;
         }
      }
   return IsNumber;
}

function isPositiveInteger(sText)
{
   var ValidChars = "0123456789 ";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
	 continue;
         }
      }
   return IsNumber;
}

function isGreaterThanZero(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var IsLargerThanZero=false;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
	 continue;
         }
      if ( sText.charAt(i) > '0') {
         IsLargerThanZero=true;
         }
      }

   if ( IsNumber == false ) {
      return false;
   }

   return IsLargerThanZero;
   }

/* Login Details checker */
function ITCLoginValidate(form)
{
   if(isEmpty(form.Email))
   { 
      alert('You must enter an e-mail address to login') ;
      form.Email.focus(); 
      return false; 
   }

   if (isValidEmail(form.Email.value) == false)
   {
      alert('You must enter a valid e-mail address to login') ;
      form.Email.focus();
      return false;
   }

   if(isEmpty(form.password))
   { 
      alert('You must enter your password') ;
      form.password.focus(); 
      return false; 
   }

   return true;
}

function isDate(sText)
{

if ((sText.value==null) || (sText.value.length==0) ) {
   alert( "You must enter a date into the space provided" ) ;
   return false;
   }

if (sText.value.length!=10) {
   alert( "1) The date must be in the form DD/MM/YYYY" ) ;
   return false;
   }

   var ValidChars = "0123456789";
   var Char;

   for (i = 0; i < sText.value.length ; i++) 
      { 
      Char = sText.value.charAt(i); 

      if ( i == 2 || i == 5 )
         {
         if ( Char != '/') {
            alert ( "2) The date must be in the form DD/MM/YYYY" );
            return false;
            }
         }
      else if (ValidChars.indexOf(Char) == -1) 
         {
         alert ( "3) The date must be in the form DD/MM/YYYY" );
         return false;
         }
      }
   return true;
}


function isValidDate(sText)
{

if ((sText.value==null) || (sText.value.length==0) ) {
   alert( "You must enter a date into the space provided" ) ;
   return false;
   }

if (sText.value.length!=10) {
   alert( "1) The date must be in the form DD/MM/YYYY" ) ;
   return false;
   }

   var ValidChars = "0123456789";
   var Char;

   for (i = 0; i < sText.value.length ; i++) 
      { 
      Char = sText.value.charAt(i); 

      if ( i == 2 || i == 5 )
         {
         if ( Char != '/') {
            alert ( "2) The date must be in the form DD/MM/YYYY" );
            return false;
            }
         }
      else if (ValidChars.indexOf(Char) == -1) 
         {
         alert ( "3) The date must be in the form DD/MM/YYYY" );
         return false;
         }
      }

	// I do not go as far as checking for leap years!
	 if (sText.value.substring(0,2) < 1 || sText.value.substring(0,2) > 31)
	 {
         alert ( "4) Unfortunately, you have entered an incorrect date. The date must be in the form DD/MM/YYY" );
         return false;
	 }

	 if (sText.value.substring(3,5) < 1 || sText.value.substring(3,5) > 12)
	 {
         alert ( "5) Unfortunately, you have entered an incorrect date. The date must be in the form DD/MM/YYY" );
         return false;
	 }

	 if (sText.value.substring(3,5) == 2 && sText.value.substring(0,2) > 29)
	 {
         alert ( "6) Unfortunately, you have entered an incorrect date. The date must be in the form DD/MM/YYY" );
         return false;
	 }

	 if (sText.value.substring(0,2) > 30 && (sText.value.substring(3,5) == 9 || sText.value.substring(3,5) == 4 || sText.value.substring(3,5) == 6 || sText.value.substring(3,5) == 11) )
	 {
         alert ( "7) Unfortunately, you have entered an incorrect date. The date must be in the form DD/MM/YYY" );
         return false;
	 }	
   return true;
}

function popUp(URL) {
id = new Date().getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=450,height=400,left = 100,top = 100');");
}


function popUpHook(URL) {
var newWindow = window.open(URL, "Perscription2", "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=400,left = 100,top = 100");
newWindow.opener = self;
if (window.focus) {newWindow.focus()}
}




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) { //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_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];}}
}

