////////////////////////////////////////////////////////////
// Creates a new pop up window
////////////////////////////////////////////////////////////
function popupWindow(docName, winWidth, winHeight)
{
  var optionString = "resizable," + "width=" + winWidth + ",height=" + winHeight + ",scrollbars=1";
  var new_window = open(docName, "secondWindow", optionString);
}


////////////////////////////////////////////////////////////
// Functions to do image rollover
////////////////////////////////////////////////////////////
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_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];}}
}

function MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.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];}
}


////////////////////////////////////////////////////////////
// Checks to see whether an input value contains "@" and
// "."
////////////////////////////////////////////////////////////
function isAValidEmail(inputValue) {

    var foundAt = false
    var foundDot = false

    // Step through the inputValue looking for
    // "@" and "."

    for (var i=0; i<=inputValue.length; i++) {
      if (inputValue.charAt(i) == "@" ) {
          foundAt = true
      }
      else if (inputValue.charAt(i) == ".") {
          foundDot = true
      }
    }
  
    // If both "@" and "." were found, assume
    // the e-mail address is valid; otherwise,
    // return false so the calling code knows
    // the e-mail address is invalid.

    if (foundAt && foundDot) {
        return true
    }
    else {
        return false
    }
}

////////////////////////////////////////////////////////////
// Checks to see if an input value contains 10 or more
// numbers.  This approach lets users type in U.S.-style
// phone formats, such as (123)456-7890,  as well as
// European-style 123.456.7890
////////////////////////////////////////////////////////////
function isAValidPhoneNumber(inputValue) {
    var digitsFound = 0
    var result = true

    // Step through the inputValue to see how
    // many digits it contains
	for (var i=0; i<inputValue.length; i++) {
           if ((inputValue.charAt(i) != "+") && (inputValue.charAt(i) != " ") && (inputValue.charAt(i) != ".") && (inputValue.charAt(i) != "-") && (inputValue.charAt(i) != "(") && (inputValue.charAt(i) != ")"))  {
             if (inputValue.charAt(i) == "0") {
                digitsFound++
               }
             else  {
               if (parseInt(inputValue.charAt(i))) {
                   digitsFound++
	         }
               else {
                   result = false
                   break
                 }
               }
	     }
	}
  
    // If inputValue contains at least 10
    // digits, assume it is a valid phone number
    if ((digitsFound >= 10) && (result == true)) {
        return true
    }
    else {
        return false
    }
}

////////////////////////////////////////////////////////////
// Checks for the existence of characters.  (Spaces aren't
// counted.)
////////////////////////////////////////////////////////////

function exists(inputValue) {

    var aCharExists = false

    // Step through the inputValue, using the charAt()
    // method to detect non-space characters.

    for (var i=0; i<=inputValue.length; i++) {
      if (inputValue.charAt(i) != " " && inputValue.charAt(i) != "") {
          aCharExists = true
          break
      }
    }

    return aCharExists
}

////////////////////////////////////////////////////////////
// Checks to see if an input value contains 10 or more
// numbers.  This approach lets users type in U.S.-style
// phone formats, such as (123)456-7890,  as well as
// European-style 123.456.7890
////////////////////////////////////////////////////////////
function isAValidFaxNumber(inputValue) {
    var digitsFound = 0
    var result = true

    // Step through the inputValue to see how
    // many digits it contains
	for (var i=0; i<inputValue.length; i++) {
           if ((inputValue.charAt(i) != "+") && (inputValue.charAt(i) != " ") && (inputValue.charAt(i) != ".") && (inputValue.charAt(i) != "-") && (inputValue.charAt(i) != "(") && (inputValue.charAt(i) != ")"))  {
             if (inputValue.charAt(i) == "0") {
                digitsFound++
               }
             else  {
               if (parseInt(inputValue.charAt(i))) {
                   digitsFound++
	         }
               else {
                   result = false
                   break
                 }
               }
	     }
	}
  
    // If inputValue contains at least 10
    // digits, assume it is a valid fax number
    if ((digitsFound >= 10) && (result == true)) {
        return true
    }
    else {
        return false
    }

}

////////////////////////////////////////////////////////////
// Performs cross-field checks that can't be performed
// until all of the data has been entered.
////////////////////////////////////////////////////////////
function validateForm() {

   var rc = true

   /////////////////////////////////////////////////////////////
   // Check all fields marked with a red asterisk are filled.
   /////////////////////////////////////////////////////////////

   /////////////////////////////////////////////////////////////
   // Visitors need to include their first and last names.
   /////////////////////////////////////////////////////////////
   if (!document.theform.Senders_name.value)
   {
       alert("Please type in your full name (both first and last).  Thanks!")
       rc = false
   }


   /////////////////////////////////////////////////////////////
   // Visitors need to specify their telephone number. 
   /////////////////////////////////////////////////////////////
   if (!isAValidPhoneNumber(document.theform.Tel_number.value)) 
   {
       alert("Invalid telephone number entered.  Please try again (make sure to include your area code).")
       rc = false
   }


   /////////////////////////////////////////////////////////////
   // Check fax number is valid. 
   /////////////////////////////////////////////////////////////
   if (exists(document.theform.Fax_number.value)) 
   {
   
   if (!isAValidFaxNumber(document.theform.Fax_number.value)) 
   {
       alert("Invalid fax number entered.  Please try again (make sure to include your area code).")
       rc = false
   }

   }

   /////////////////////////////////////////////////////////////
   // Visitors need to specify their e-mail address.
   /////////////////////////////////////////////////////////////
   if (!isAValidEmail(document.theform._sendersemail.value)) 
   {
       alert("We can't contact you via e-mail unless you give us a valid e-mail address. Thanks!")
       rc = false
   }

//   if (rc) {
       // If the rc variable is non-zero, then the form data
       // passed with flying colors!
//       alert("Thanks! We'll contact you soon regarding your enquiry.")
//   }
   return rc
}


////////////////////////////////////////////////////////////
// Check a number has been input
////////////////////////////////////////////////////////////
function isANumber(inputValue)
{
  var result = true;
  var digits = 0;
  var i;
  var testVal;

  // If parseFloat() returns false, a non-numeric 
  // character was detected in the first position.
  testVal = parseFloat(inputValue);

  if (isNaN(testVal))
  {
    result = false;
  }
  else
  {
    for (i = 0; i < inputValue.length; i++)
    {
      if (inputValue.charAt(i) != " ")
      {
        testVal = parseFloat(inputValue.charAt(i));

        if (isNaN(testVal))
        {
          result = false;
          break;
        }
        else
        {
          digits++;
        }
      }
      else
      {
        //Invalid number input if a space occurs within number eg 12 3
        if (digits > 0)
        {
          alert("Invalid spaces entered.  Please try again.")
          result = false;
          break;
        } 
      }
    }  
  }

  return result;
    
}



// copyright 1999-2001 Idocs, Inc. http://www.idocs.com/tags/
// Distribute this script freely, but keep this 
// notice with the code.
var resetRolls = new Object();

function resetimage(src)
{
this.src=src;
this.confirm=true;
this.alt="Reset";
this.write=resetimage_write;
}

function resetimage_write()
{
document.write('<A ');
if (this.rollover)
    {
    if (! this.name)
        {
        alert('to create a rollover you must give the image a name');
        return;
        }

    resetRolls[this.name] = new Object();
    resetRolls[this.name].over = new Image();
    resetRolls[this.name].over.src=this.rollover;
    resetRolls[this.name].out = new Image();
    resetRolls[this.name].out.src=this.src;
    document.write(
        ' onMouseOver="if (document.images)document.images[\'' + 
        this.name + '\'].src=resetRolls[\'' + this.name + '\'].over.src"' + 
        ' onMouseOut="if (document.images)document.images[\'' + 
        this.name + '\'].src=resetRolls[\'' + this.name + '\'].out.src"'
        );
    }
document.write(' HREF="javascript:');
//if (this.confirm)
//    document.write('if(confirm(\'Are you sure you want to reset?\'))');
document.write(
    'document.forms[' + 
    (document.forms.length - 1) + '].reset();void(0);">');
document.write('<IMG SRC="' + this.src + '" ALT="' + this.alt + '"');
document.write(' BORDER=0');
if (this.name)document.write(' NAME="' + this.name + '"');
if (this.height)document.write(' HEIGHT=' + this.height);
if (this.width)document.write(' WIDTH=' + this.width);
if (this.otheratts)document.write(' '+ this.otheratts);
document.write('></A>');
}


////////////////////////////////////////////////////////////
// Disable right click
// distributed by http://www,hypergurl.com
////////////////////////////////////////////////////////////

function right(e) 
{
if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2)) return false;
else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3)) {
alert('Sorry! Right click function disabled.');
return false;
}

return true;
}
document.onmousedown=right;
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
window.onmousedown=right;
