////////////////////////////////////////////////////////////
// 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
}

////////////////////////////////////////////////////////////
// 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.sendersname.value)
   {
       alert("Please type in your entire name (both first and last).  Thanks!")
       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
   }

   /////////////////////////////////////////////////////////////
   // Visitors need to specify their telephone number. 
   /////////////////////////////////////////////////////////////
   if (!isAValidPhoneNumber(document.theform.Tel_number.value)) 
   {
       alert("We can't contact you via phone unless you give us a valid phone number (make sure to include your area code).  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
}

////////////////////////////////////////////////////////////
// Performs cross-field checks that can't be performed
// until all of the data has been entered.
////////////////////////////////////////////////////////////
function validateShortForm() {

   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.sendersname.value)
   {
       alert("Please type in your entire name (both first and last).  Thanks!")
       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
   }


   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;
    
}

////////////////////////////////////////////////////////////
// Get square feet value of the item
////////////////////////////////////////////////////////////
function getSquareFeet( product )
{
  var squareFeet = 0;

  switch (product)
  {
    case "singleBed": squareFeet = 4; break;
    case "doubleBed": squareFeet = 5; break;
    case "bedsideCabinet": squareFeet = 3; break;
    case "singleWardrobe": squareFeet = 3; break;
    case "doubleWardrobe": squareFeet = 4; break;
    case "settee": squareFeet = 4; break;
    case "easyChair": squareFeet = 3; break;
    case "lamp": squareFeet = 2; break;
    case "smallTable": squareFeet = 3; break;
    case "piano": squareFeet = 4; break;
    case "TV": squareFeet = 2; break;
    case "hi-fi": squareFeet = 2; break;
    case "diningTable": squareFeet = 4; break;
    case "diningChairs": squareFeet = 2; break;
    case "desk": squareFeet = 4; break;
    case "filingCabinet": squareFeet = 2; break;
    case "largeStorageBoxes": squareFeet = 3; break;
    case "storageBoxes": squareFeet = 2; break;
    case "fileBoxes": squareFeet = 2; break;
    case "tumbleDryer": squareFeet = 2; break;
    case "washingMachine": squareFeet = 2; break;
    case "largeTable": squareFeet = 5; break;
    case "tools": squareFeet = 2; break;
    case "lawnMower": squareFeet = 2; break;
    case "gardenTools": squareFeet = 3; break;
    case "scooterJetSki": squareFeet = 4; break;
    case "motorBicycle": squareFeet = 4; break;
    case "moped": squareFeet = 3; break;
    case "bicycle": squareFeet = 3; break;
    case "skis": squareFeet = 2; break;
    case "carpetRoll": squareFeet = 2; break;
  }

  return squareFeet;
}


////////////////////////////////////////////////////////////
// Storage space calculator
////////////////////////////////////////////////////////////
function calculator()
{
  var totalSqFt = 0;
  var strUnitSize = "";
  var sqOffset = 1.0;  //Offsets to reduce totals
  var quantity, sqFt;
  var i;

  //Check all input boxes apart from first and last results input boxes
  for (i = 1; i < (document.theForm.elements.length - 1); i++)
  {  
    // Check if numbers entered are valid
    if (isANumber(document.theForm.elements[i].value))
    {
      quantity = parseFloat(document.theForm.elements[i].value);
      sqFt = getSquareFeet(document.theForm.elements[i].name);
      totalSqFt += (quantity * sqFt);
    }
    else
    {
      if (document.theForm.elements[i].value == "")
      {
        totalSqFt += 0;
      }
      else
      {
        alert("Invalid number entered.  Please try again."); 
        break;
      }
    }
  }

  totalSqFt = totalSqFt * sqOffset;

  document.theForm.sqFtVal1.value  = totalSqFt.toFixed(0);
  document.theForm.sqFtVal2.value  = document.theForm.sqFtVal1.value;
  
}

// 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;
