// JavaScript Document

function openEmailFriendWindow()
{
	url = "emailFriend.htm"
	w = 450;
	h = 340;
	
	// Fudge factors for window decoration space.
	 // In my tests these work well on all platforms & browsers.
	w += 32; h += 96;
	leftPos = 0;
	if(screen){
		leftPos = 100 <!-- could use screen.width -->
	}
	var win = window.open(url,
	'popup',
	'width='+ w + ', height=' + h + ', '+
	'left='+leftPos+',top=100,'+
	'location=no, menubar=no, '+
	'status=no, toolbar=no, scrollbars=yes, resizable=no');
	win.resizeTo(w, h);
	win.focus();
}
/*
function wopen(url, w, h) {
	// Fudge factors for window decoration space.
	 // In my tests these work well on all platforms & browsers.
	w += 32; h += 96;
	leftPos = 0;
	if(screen){
		leftPos = 100 <!-- could use screen.width -->
	}
	var win = window.open(url,
	'popup',
	'width='+ w + ', height=' + h + ', '+
	'left='+leftPos+',top=100,'+
	'location=no, menubar=no, '+
	'status=no, toolbar=no, scrollbars=yes, resizable=no');
	win.resizeTo(w, h);
	win.focus();
}
*/
<!-- function to clear search box -->
function clearText(thefield){
	if (thefield.defaultValue==thefield.value)
		thefield.value = ""
} 

<!-- function to validate email address  -->
function validEmail(emailAddr)
{
	invalidChars = " /:,;"

	if (emailAddr == "") {
		return false
	}
	for (i=0; i<invalidChars.length; i++) {
		badChar = invalidChars.charAt(i)
		if (emailAddr.indexOf(badChar,0) > -1) {
			return false
		}
	}
	atPos = emailAddr.indexOf("@",1)
	if (atPos == -1) {
		return false
	}
	if (emailAddr.indexOf("@",atPos+1) > -1) {
		return false
	}
	periodPos = emailAddr.indexOf(".",atPos)
	if (periodPos == -1) { 
		return false
	}
	if (periodPos+3 > emailAddr.length)	{
		return false
	}
	return true
}

/* function to check for presence of both
   email addresses and validate them  */
function validateEmailFriendForm(theForm)
{
	fromAddress = theForm.fromAddress.value
	toAddress = theForm.toAddress.value
	
	if (fromAddress == "" || toAddress == "") {
		alert("Please enter email addresses")
		return false
	}	
	if (!validEmail(fromAddress)) {
		alert("Please enter a valid email address")
		theForm.fromAddress.focus()
		theForm.fromAddress.select()
		return false
	}
	if (!validEmail(toAddress)) {
		alert("Please enter a valid email address")
		theForm.toAddress.focus()
		theForm.toAddress.select()
		return false
	}
	return true
}

/* function to check for presence of either phone no or email address
   and, if present, validate email address  */
function validateContactUsForm(theForm)
{
	phoneNo = theForm.phoneNumber.value;
	radioCheck = false;
	fromAddress = theForm.fromAddress.value;
	
	if (phoneNo == "" && fromAddress == "") {
		alert("Please enter either your phone number\nor email address or both")
		return false
	}
	if (phoneNo != "") {
		for (i=0; i<theForm.leaveMessage.length; i++) {
			if (theForm.leaveMessage[i].checked) radioCheck = true;
		}
		if (!radioCheck) {
			alert("Please select a phone message option");
			theForm.leaveMessage[0].focus();
			return false;
		}
	}
	if (phoneNo != "" && fromAddress == "") {
		//theForm.fromAddress.value = "no.from@address.supplied"
		theForm.noFromAddressSupplied.value = "none supplied"
		return true
	}
	if (!validEmail(fromAddress)) {
		alert("Please enter a valid email address or leave blank")
		theForm.fromAddress.focus()
		theForm.fromAddress.select()
		return false
	}
	return true
}
