// function to change images when mouse over
function ChangeImageOver(img) {
	if (document.images)
		document.images[img].src = eval(img + "_on.src")
}

// function to change images when mouse out
function ChangeImageOut(img) {
	if (document.images)
		document.images[img].src = eval(img + "_off.src")
}

function trim(str)
{
	var strlen = str.length;
	for (var i=strlen-1; i>=0; i--)
	{
		 if ((str.substring(i,i+1) <= " "))
		 { 
		 	str = str.substring(0,i); 
		 }
		 else {
		 	break;
		 }
	}
	return str;
}

function isBlank(objname, obj)
{
	if (trim(obj.value) == "")
	{
		return "- " + objname + "\n";		
	}
	else
	{
		return "";
	}
}

function isBlankwithspace(objname, obj)
{
	if (trim(obj.value) == "")
	{
		return "- " + objname + "\n";		
	}
	else
	{
		for(var i=0;i<obj.value.length;i++){
			if (!((obj.value.charAt(i)!=' ')&&(obj.value.charAt(i)!="\t")&&(obj.value.charAt(i)!="\n")&&(obj.value.charAt(i)!="\r"))){
				return "- " + objname + "\n";
			}
		}
		return "";
	}
}

function isRadioSelected(objname, obj)
{
	for(var i=0;i<obj.length;i++)
	if (obj[i].checked)
	{
		return "";
	}
	return "- " + objname + "\n";
}

function isSelected(objname, obj)
{
	if (obj.options[obj.selectedIndex].value == "")
	{
		return "- " + objname + "\n";
	}
	else
	{
		return "";
	}
}

function chkEmail(objname, obj)
{
	var pos1, pos2;
	var theLen = obj.value.length;

	pos1 = obj.value.indexOf("@");
	pos2 = obj.value.indexOf(".");

	if ((pos1 > 0) && (pos2 > 0))
	{
		if (pos2 < theLen - 1)
		{
			return "";
		}
	}
	return "- " + objname + "\n";
}

function validatensfrm(theForm){
	valid_form = true;
	str_errmsg = "";

	str_errmsg = str_errmsg + isBlank("First Name", theForm.firstname);
	str_errmsg = str_errmsg + isBlank("Last Name", theForm.lastname);
	str_errmsg = str_errmsg + isBlank("Email Address", theForm.email);

	if (str_errmsg != "")
	{ 
		alert("INCOMPLETE INFORMATION\n\n" + 
		      "Please go back and complete the following fields:\n" + 
		      str_errmsg + "\n");
		valid_form = false;
	}
	else {
		str_errmsg = str_errmsg + chkEmail("Email address", theForm.email);
		if (str_errmsg != "")
		{ 
			alert("INCORRECT FIELD FORMAT\n\n" + 
			      "Please go back and correct the following fields:\n" + 
			      str_errmsg + "\n");
			valid_form = false;
		}
	}
	return valid_form;
}

function validatesffrm(theForm){
	valid_form = true;
	str_errmsg = "";

	str_errmsg = str_errmsg + isBlank("Your Name", theForm.fn);
	str_errmsg = str_errmsg + isBlank("Your e-mail address", theForm.fe);
	str_errmsg = str_errmsg + isBlank("Friend's Name", theForm.tn1);
	str_errmsg = str_errmsg + isBlank("Friend's e-mail address", theForm.te1);
	if (isBlank("Friend's e-mail address", theForm.te2) == ""){
		str_errmsg = str_errmsg + isBlank("2nd Friend's Name", theForm.tn2);
	}
	if (isBlank("Friend's e-mail address", theForm.te3) == ""){
		str_errmsg = str_errmsg + isBlank("3rd Friend's Name", theForm.tn3);
	}
	if (isBlank("Friend's e-mail address", theForm.te4) == ""){
		str_errmsg = str_errmsg + isBlank("4th Friend's Name", theForm.tn4);
	}
	if (isBlank("Friend's e-mail address", theForm.te5) == ""){
		str_errmsg = str_errmsg + isBlank("5th Friend's Name", theForm.tn5);
	}
		
	if (str_errmsg != "")
	{
		alert("INCOMPLETE INFORMATION\n\n" + 
		      "Please go back and complete the following fields:\n" + 
		      str_errmsg + "\n");
		valid_form = false;
	}
	else {
		str_errmsg = str_errmsg + chkEmail("Your e-mail address", theForm.fe);
		str_errmsg = str_errmsg + chkEmail("Friend's e-mail address", theForm.te1);
		if (isBlank("Friend's Name", theForm.tn2) == ""){
			str_errmsg = str_errmsg + chkEmail("2nd Friend's e-mail address", theForm.te2);
		}
		if (isBlank("Friend's Name", theForm.tn3) == ""){
			str_errmsg = str_errmsg + chkEmail("3rd Friend's e-mail address", theForm.te3);
		}
		if (isBlank("Friend's Name", theForm.tn4) == ""){
			str_errmsg = str_errmsg + chkEmail("4th Friend's e-mail address", theForm.te4);
		}
		if (isBlank("Friend's Name", theForm.tn5) == ""){
			str_errmsg = str_errmsg + chkEmail("5th Friend's e-mail address", theForm.te5);
		}
		if (str_errmsg != "")
		{ 
			alert("INCORRECT FIELD FORMAT\n\n" + 
			      "Please go back and correct the following fields:\n" + 
			      str_errmsg + "\n");
			valid_form = false;
		}
	}
	return valid_form;

}

function validateusfrm(theForm){
	valid_form = true;
	str_errmsg = "";

	str_errmsg = str_errmsg + isBlank("Email Address", theForm.email);

	if (str_errmsg != "")
	{ 
		alert("INCOMPLETE INFORMATION\n\n" + 
		      "Please go back and complete the following fields:\n" + 
		      str_errmsg + "\n");
		valid_form = false;
	}
	else {
		str_errmsg = str_errmsg + chkEmail("Email address", theForm.email);
		if (str_errmsg != "")
		{ 
			alert("INCORRECT FIELD FORMAT\n\n" + 
			      "Please go back and correct the following fields:\n" + 
			      str_errmsg + "\n");
			valid_form = false;
		}
	}
	return valid_form;
}
