// JavaScript Function Library

// Reset input field color when changed
function fldReset() { this.style.backgroundColor=''; this.style.borderColor='#bbbbbb'; }

// display error message, color error field, set 
function setErm(f,m) {
  alert(m);
  f.onchange = fldReset;
  f.style.backgroundColor="#ff9"; 
  f.style.borderColor="#f00"; 
  f.focus(); 
  return false;
}

// Return true if node a contains node b.
function contains(a, b) { if (b==null) return;
  while (b.parentNode) {
	b = b.parentNode;
	if (b.id == a) return true;
  }
  return false;
}

function chkMemberSignup(s) {
   if (s.fname.value=='')		return setErm(s['fname'],	'You must enter your first name to continue.');
   if (s.lname.value=='')		return setErm(s['lname'],	'You must enter your last name to continue.');
   if (s.email.value=='')		return setErm(s['email'],	'You must enter your email, this will also be used as your username for the site.');
   if ((s.phone.value!='') && (s.phone.value.search(/\d{3}\-\d{3}\-\d{4}/)==-1)) {
     return setErm(s['phone'],	'Your phone # must be in the format xxx-xxx-xxxx.');
   }
   if (s.email.value.indexOf('@')==-1)	return setErm(s['email'],'Your E-mail address appears to be invalid. Please check!');
   if (s.email.value.indexOf('.')==-1)	return setErm(s['email'],'Your E-mail address appears to be invalid. Please check!');
   if (s.pass1.value=='')	return setErm(s['pass1'],	'You must enter a password.');
   if (s.pass2.value=='')	return setErm(s['pass2'],	'You must re-enter your chosen password.');
   if (s.pass1.value!=s.pass2.value)	return setErm(s['pass1'],	'Your re-entered password does not match your password. please ensure they are the same.');
   return true;
}

function chkContact(s) {
   if (s.phone.value=='')		return setErm(s['phone'],	'Please enter your Phone Number');
   if ((s.phone.value!='') && (s.phone.value.search(/\d{3}\-\d{3}\-\d{4}/)==-1)) {
     return setErm(s['phone'],	'Your phone # must be in the format xxx-xxx-xxxx.');
   }
   if (s.message.value=='')		return setErm(s['message'],	'Please type a Message');
  
   return true;
}

function verifyDelete(s) { return(confirm("Are you sure you want to delete " + s + "?")); }


function setVis(event,nid,oid,s) {
  if ( (!s) && (contains(nid,((window.event)?window.event.toElement:event.relatedTarget))) ) return;
  document.getElementById(oid).style.visibility = ((s)?'visible':'hidden');
}


