
// ROLLOVERS

var imgz = new Array

function rollinit() {
  if (document.getElementsByTagName) { var x = document.getElementsByTagName('*'); }
  else if (document.all.tags) { var x = document.all.tags('*'); }
  else { return false; }
  for (var i=0; i<x.length; i++) {
    if (x[i].className.substring(0,5) == 'roll:') {
      rollsrc = x[i].className.substring(5,x[i].className.length);
      if ( rollsrc > '' )  {
        imgz[i]=new Image; imgz[i].src = rollsrc;
        x[i].onmouseover = function () { origSrc=this.src; this.src=this.className.substring(5,this.className.length); }
        x[i].onmouseout  = function () { if(typeof(origSrc)!='undefined') {this.src=origSrc} }
      }
    }
  }
}


// GENERIC ADD EVENT FUNCTION

function addEvent(obj, evType, fn) {
 if (obj.addEventListener) { obj.addEventListener(evType, fn, false);  return true; }
 else if (obj.attachEvent) { var r = obj.attachEvent("on"+evType, fn); return r;    }
 else                      { return false; }
}



// FORM VALIDATION

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_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}


function clearDefault(o) {
  if (!o || !o.defaultValue || !o.value) { return false; }
  if ( o.value == o.defaultValue ) { o.value = "" }
  //o.select()
}

function clearDefault2(o,theText) {
  if (!o || !theText || !o.value) { return false; }
  if ( o.value == theText ) { o.value = "" }
  //o.select()
}

function checkSearch(fieldId){
  o=document.getElementById(fieldId);
  if (!o) {return false;}
  if (o.value=='' || o.value==o.defaultValue) { alert('Please enter something to search for!'); return false;  }
}

function validateEnqForm() {
  o = document.getElementById('firstname'); if ( !o || o.value == '' ) { alert('Please complete First Name.');  return false; }
  o = document.getElementById('surname');   if ( !o || o.value == '' ) { alert('Please complete Surname.');  return false; }
  o = document.getElementById('company');   if ( !o || o.value == '' ) { alert('Please complete Company Name.');  return false; }
  o = document.getElementById('email');     if ( !o || o.value == '' ) { alert('Please complete email address.');  return false; }
  if ( !(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.((\w{2,3})|(aero|coop|info|museum|name)))+$/.test(o.value)) )
    { alert('Invalid email address!');  return false; }
}

function validateLandingForm() {
  o = document.getElementById('name');  if ( !o || o.value == '' ) { alert('Please complete name.');  return false; }
  o = document.getElementById('tel');   if ( !o || o.value == '' ) { alert('Please complete telephone number.');  return false; }
  o = document.getElementById('email'); if ( !o || o.value == '' ) { alert('Please complete email address.');  return false; }
  if ( !(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.((\w{2,3})|(aero|coop|info|museum|name)))+$/.test(o.value)) )
    { alert('Invalid email address!');  return false; }
}

function validateRecommForm() {
  o = document.getElementById('toname');  if ( !o || o.value == '' ) { alert('Please complete your friend\'s name.');  return false; }
  o = document.getElementById('toemail'); if ( !o || o.value == '' ) { alert('Please complete your friend\'s email address.');  return false; }
  if ( !(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.((\w{2,3})|(aero|coop|info|museum|name)))+$/.test(o.value)) )
    { alert('The email address you have entered for your friend is invalid!');  return false; }
  o = document.getElementById('fromname');  if ( !o || o.value == '' ) { alert('Please complete your name.');  return false; }
  o = document.getElementById('fromemail'); if ( !o || o.value == '' ) { alert('Please complete your email address.');  return false; }
  if ( !(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.((\w{2,3})|(aero|coop|info|museum|name)))+$/.test(o.value)) )
    { alert('The email address you have entered for yourself is invalid!');  return false; }
}

function validatePFlogin() {
  o = document.getElementById('email');     if ( !o || o.value == '' ) { alert('Please enter email address.');  return false; }
  if ( !(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.((\w{2,3})|(aero|coop|info|museum|name)))+$/.test(o.value)) )
    { alert('Invalid email address!');  return false; }
  o = document.getElementById('pass'); if ( !o || o.value == '' )   { alert('Please enter password.');  return false; }
  if ( o.value.length < 4 || o.value.length > 10 ) { alert('The password should be between 4 and 10 characters long.');  return false; }
}

function validatePFremind() {
  o = document.getElementById('email');     if ( !o || o.value == '' ) { alert('Please enter email address.');  return false; }
  if ( !(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.((\w{2,3})|(aero|coop|info|museum|name)))+$/.test(o.value)) )
    { alert('Invalid email address!');  return false; }
}

function AddToFavorites() {
 if (window.external) { window.external.AddFavorite('http://www.bournefurn.com/', 'Bourne Furniture');  }
 else { alert('Sorry, your browser doesn\'t support this function.');  }
}

