
// START Email to friend

var EmailFriendTimerRunning = false;
var EmailFriendTimer = null;

function emailFriend(){	
	document.getElementById('emailToContainerFlashHide').style.visibility = 'visible';
	document.getElementById('emailToContainer').style.visibility = 'visible';	
}

function closeEmailFriend(){		

		if (EmailFriendTimerRunning) {
			EmailFriendTimerRunning = false;
			clearTimeout(EmailFriendTimer); 
		}		
		
		document.getElementById('emailToContainerFlashHide').style.visibility = 'hidden';
		document.getElementById('emailToContainer').style.visibility = 'hidden';		
		document.getElementById("emailFormConfMsg").style.display = 'none';
		document.getElementById("emailFormHolder").style.display = 'block';					
		document.emailFriendForm.reset();
		return false;
}

function confirmEmailFriend(){		
		document.getElementById("emailFormHolder").style.display = 'none';			
		document.getElementById("emailFormConfMsg").style.display = 'block';				
		EmailFriendTimer = setTimeout('closeEmailFriend()',4000); // EmailFriendTimer holds the id of the timer
		EmailFriendTimerRunning = true;
}

// END Email to friend



// START Form Validation

function checkrequired(which) {
var pass=true;
var haveEmail=false;
var theEmail=null;

if (document.images) {
for (i=0;i<which.length;i++) {
var tempobj=which.elements[i];
if (tempobj.name.substring(0,8)=="required") {
if (((tempobj.type=="text"||tempobj.type=="textarea")&&
tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
tempobj.selectedIndex==0)) {
pass=false;
break;
         }
      }
   }
}

// see if we have an email address field called "requiredEmail" or "requiredFriends-Email-Address"
if (document.images) {
for (i=0;i<which.length;i++) {
var tempobjB=which.elements[i].name;
if (tempobjB=="requiredEmail" || tempobjB=="requiredFriends-Email-Address") {
theEmail=tempobjB; 	
haveEmail=true;
break;
	 }
  }
}

// Alert on any empty fields
if (!pass) {
shortFieldName=tempobj.name.substring(8,30).toUpperCase();
alert("Please make sure the "+shortFieldName+" field was properly completed");
return false;
}
else { // if all fields are complete check valid email and validate if necessary

	if (haveEmail) {
	
				if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(which.elements[theEmail].value)){
				return true;
				}
				else {
				alert("Please enter a valid email address")
				return false;
				}
	
			}
		else {
		return true;
		}
		
	}
	
}

// END Form Validation



// Preload the rollover images

image1 = new Image();
image1.src = "images/leftnav_bg_on.gif";

image2 = new Image();
image2.src = "images/leftnav_bg_brochures_on.gif";
