// 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 = '/opencms/export/getlenses/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) The date must be in the form DD/MM/YYYY" );
         return false;
	 }

	 if (sText.value.substring(3,5) < 1 || sText.value.substring(3,5) > 12)
	 {
         alert ( "5) The date must be in the form DD/MM/YYYY" );
         return false;
	 }

	 if (sText.value.substring(3,5) == 2 && sText.value.substring(0,2) > 29)
	 {
         alert ( "6) The date must be in the form DD/MM/YYYY" );
         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) The date must be in the form DD/MM/YYYY" );
         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=1,width=500,height=400,left = 100,top = 100");
newWindow.opener = self;
if (window.focus) {newWindow.focus()}
}

function validateAndSubmit(frm, objToDisable)
{
	if( ITCvalidate($(frm)) )
	{
		if(objToDisable != null)
		{
			if(objToDisable.hasClassName('validateAndSubmitDisabled'))
				return false;
			objToDisable.addClassName('validateAndSubmitDisabled');
			objToDisable.src = 'ASDAimages/ASDAheader/next_disabled.jpg';
		}
		$(frm).submit();
	}
}

