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];}}
}

//Empties out the names
function emptyNames() {
  if (confirm('Are you sure you wish to empty your favourite list?\n\nClick \'OK\' to empty\nClick \'Cancel\' to keep your list.')) {
    self.location.replace('empty.asp');
  }    
  else {
    return void(0);
  }	
}

//trim spacess
function trim(strText) { 
    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
} 

//Is valid email address?
function isEmail(obj,msg) {
  if (obj.value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
    return true;
  else
    obj.focus();
    alert('You must supply ' + msg + ' before this form can be completed');
    return false;
}

//Is str valid [a..z][A..Z][0..9]
function isValid(str) {
  var Chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
  for (var i = 0; i < str.length; i++) {
    if (Chars.indexOf(str.charAt(i)) == -1)
      return false;
  }
  return true;
}

//Is Empty
function isEmpty(obj,msg) {
  if (obj.value == "") {
    obj.focus();
    alert ('You must supply ' + msg + ' before you this form can be completed.');
    return false;
  }  
  return true;      
}

//validates find form
function validateFind(obj) {
  obj.name.value=trim(obj.name.value);
  if (obj.name.value == '') {
    obj.name.focus();
    alert('Please enter a name.\n\nClick the help button for help on searching.');
    return false;
  }
  return true
}

function validateEmailForm(obj) {
  obj.fromName.value=trim(obj.fromName.value);
  obj.fromEmail.value=trim(obj.fromEmail.value);
  obj.toName.value=trim(obj.toName.value);
  obj.toEmail.value=trim(obj.toEmail.value);

  if (!isEmpty(obj.fromName,'your name')){return false;}    
  if (!isEmail(obj.fromEmail,'your email address')){return false;}    
  if (!isEmpty(obj.toName,'your friends name')){return false;}
  if (!isEmail(obj.toEmail,'your email address')){return false;}      

  return true;  
}
