var NN4 = document.layers? true : false;
var IE4 = document.all? true : false;


function rollOverImg(butId)
{
	curImg   = document.getElementById(butId).src;
	
	var reOff = /_off/;
	var reOn  = /_on/;
	
	
	var result = reOff.test(curImg);
	
	if (result) {
		
		newImg = curImg.replace(reOff,'_on');
		
		document.getElementById(butId).src = newImg;
	} else {
		
		newImg = curImg.replace(reOn,'_off');
		
		document.getElementById(butId).src = newImg;
	}
}

function rollOverTxt(butId)
{
	curClass   = document.getElementById(butId).className;
	
	var reOff = /1/;
	var reOn  = /2/;
	
	
	var result = reOff.test(curClass);
	
	if (result) {
		newClass = curClass.replace(reOff,'2');
	} else {
		newClass = curClass.replace(reOn,'1');
	}
	
	changeClass(butId,newClass);
}

function changeClass(itemId,newClass)
{
	document.getElementById(itemId).className = newClass;
}

function openAWindow(URL,winName,features)
{
	window.open(URL,winName,features);
}


function resetForm(theForm)
{
	theForm.reset();
}

function submitForm(theForm)
{
	theForm.submit();
}



function checkInquiryForm(theForm) {
	var why = "";

	why+= isEmpty(theForm.firstname.value, "FIRST NAME");
	if (why != "") {
		alert(why);
		theForm.firstname.focus();
       		return false;
	}

	why+= isEmpty(theForm.lastname.value, "LAST NAME");
	if (why != "") {
		alert(why);
		theForm.lastname.focus();
       		return false;
	}

	why+= checkPhone(theForm.homephone.value);
	if (why != "") {
		alert(why);
		theForm.homephone.focus();
       		return false;
	}

	why+= checkEmail(theForm.email.value, "EMAIL");
	if (why != "") {
		alert(why);
		theForm.Email.focus();
       		return false;
	}

	why+= isEmpty(theForm.currentadd.value, "CURRENT ADDRESS");
	if (why != "") {
		alert(why);
		theForm.Current_Address.focus();
       		return false;
	}

	return true;
}

function checkEmail (strng)
{
	
	var error="";
	
	if (strng == "") {
		error = "You didn't enter an email address.\n";
	}
	
	var emailFilter=/^.+@.+\..{2,3}$/;
	
	if (!(emailFilter.test(strng))) { 
		error = "Please enter a valid email address.\n";
	}
	else {
		//test email for illegal characters
		var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
		
		if (strng.match(illegalChars)) {
			error = "The email address contains illegal characters.\n";
		}
	}

	return error;    
}

function isEmpty(strng, fldName)
{
	var error = "";
	
	if (strng.length == 0) {
		error = "The " + fldName + " field has not been filled in.\n"
	}

	return error;	  
}
	
	
function checkPhone (strng)
{
	var error = "";
	
	if (strng == "") {
		error = "You didn't enter a phone number.\n";
		return error;
	}

	var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters

	if (isNaN(parseInt(stripped))) {
		error = "The phone number contains illegal characters.";

	}

	return error;
}
