function fnameNumbers()
{
	var notOK = "0123456789";
	  var checkStr = document.theform.fname.value;
	  var allValid = false;
	  for (i = 0;  i < checkStr.length;  i++)
	  {
	    ch = checkStr.charAt(i);
	    for (j = 0;  j < notOK.length;  j++)
	      if (ch == notOK.charAt(j))
		  {
	    	alert("Enter only letters in the first name field.  No numbers, please.");
	    	document.theform.fname.focus();
	    	return true;
			}
	  }
}
function lnameNumbers()
{
	var notOK = "0123456789";
	  var checkStr = document.theform.lname.value;
	  var allValid = false;
	  for (i = 0;  i < checkStr.length;  i++)
	  {
	    ch = checkStr.charAt(i);
	    for (j = 0;  j < notOK.length;  j++)
	      if (ch == notOK.charAt(j))
		  {
	    	alert("Enter only letters in the last name field.  No numbers, please.");
	    	document.theform.lname.focus();
	    	return true;
			}
	  }
}

// Function to be used to verify address is 2 words
function alltrim(sString) 
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{	
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}
// require 2 words in address
function fixAddress()
{
var teststring = new String(document.theform.address.value);
teststring=alltrim(teststring);
if
(teststring.indexOf (' ',0) < 1)
{
alert("There appears to be a problem with your address.\nThere should be at least two words in your address.")
document.theform.address.focus();
return true;
}
else
	{
	return false;
	}
}	
//Require city length of at least 2 chars
function fixCity() 
{
var city = document.theform.city.value
	if (city.length  < 2)
	{
		alert("There appears to be a problem with your city.  \nThe city name must be at least three characters long.")
		document.theform.city.focus();
		return true;
	}
}
//disallow certain chars
function nukeCity()
{
if
	(document.theform.city.value.indexOf ('"',0) > -1 || 
	document.theform.city.value.indexOf ("'",0) > -1 || 
	document.theform.city.value.indexOf ("`",0) > -1 ||
	document.theform.city.value.indexOf (",",0) > -1 ||
	document.theform.city.value.indexOf (".",0) > -1)
	{
	
	alert("\nQuotes, apostrophes, periods or commas are not permitted in the city field.  \nPlease remove them.")
	document.theform.city.focus();
	return true;
	}
	else
	{
		return false;
	}
}
//check zip code
function zipZero()
{
	if (document.theform.zip.value == "00000")
		{
		return true
		}	
} 
function checkZip()
{
	var zipcode = document.theform.zip.value
	if ( zipcode.length  != 5)
	{
		alert("Zip code must be 5 characters.")
		document.theform.zip.focus();
		return true;
		}
	
	var zip=document.theform.zip.value
	inputStr=document.theform.zip.value.toString()
	for (var i=0; i < inputStr.length; i++)
	{
	var oneChar=inputStr.charAt(i)
	if (oneChar < "0" || oneChar > "9")
		{	
		document.theform.zip.focus()
		alert("Zip code may contain only numbers.")
			return true
		}
	}
	if (zipZero())
		{
		document.theform.zip.focus()
		alert("Please enter a valid zip code.")
		return true
		}
	return false
}

//make sure e-mail has an @ sign and a dot
function emailCheck() 
{
	if (document.theform.email.value.indexOf ('@',0) < 1 || document.theform.email.value.indexOf ('.',document.theform.email.value.indexOf ('@',0)) < 0)
	{
		alert("Please enter a valid e-mail address.\nThe e-mail field requires an \"@\" and a \".\" be used.\n\nPlease re-enter your e-mail address.")
		document.theform.email.focus();
		return true;
	}
	else
	{
		return false;
	}
}
//allow valid characters - error if character not in this list
function emailChars()
{
  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-@.-";
	  var checkStr = document.theform.email.value;
	  var allValid = true;
	  for (i = 0;  i < checkStr.length;  i++)
	  {
	    ch = checkStr.charAt(i);
	    for (j = 0;  j < checkOK.length;  j++)
	      if (ch == checkOK.charAt(j))
	        break;
	    if (j == checkOK.length)
	    {
	      allValid = false;
	      break;
	    }
	  }
	  if (!allValid)
	  {
	    alert("Please enter only letter, digit and \"@.-_\" characters in the \"email\" field.");
	    document.theform.email.focus();
	    return true;
	  }
}
//check for strings of @. and .. - error if found
function moreEmail() 
{
var emailStr=document.theform.email.value;
if (document.theform.email.value.indexOf ('@.',0) > -1 || document.theform.email.value.indexOf ('.@',0) > -1 || document.theform.email.value.indexOf ('..',0) > -1 || document.theform.email.value.charAt(emailStr.length - 1) == "." || document.theform.email.value.indexOf ('@@',0) > -1 )
	{
		alert("Please enter a valid e-mail address.")
		document.theform.email.focus();
		return true;
	}
	else
	{
		return false;
	}
}
function checkEmail()
{
	var email = document.theform.email.value
	if (email.length  >= 1)
	{
		if (emailCheck() || emailChars() || moreEmail())
		{
			return true;
		}		
		else
		{
			return false;
		}
	}
}

function checkPhoneNum()
{
	if ((document.theform.dayphone1.value != "" && document.theform.dayphone1.value != null) && (isNaN(document.theform.dayphone1.value)))
		{
			document.theform.dayphone1.focus();
			document.theform.dayphone1.select();
			alert ("Please enter only numbers in the Telephone fields.")
			return true;
		}
	if ((document.theform.dayphone2.value != "" && document.theform.dayphone2.value != null) && (isNaN(document.theform.dayphone2.value)))
		{
			document.theform.dayphone2.focus();
			document.theform.dayphone2.select();
			alert ("Please enter only numbers in the Telephone fields.")
			return true;
		}
	if ((document.theform.dayphone3.value != "" && document.theform.dayphone3.value != null) && (isNaN(document.theform.dayphone3.value)))
		{
			document.theform.dayphone3.focus();
			document.theform.dayphone3.select();
			alert ("Please enter only numbers in the Telephone fields.")
			return true;
		}
	else
		{
		return false;
		}
}

function checkPhoneLen()
{
	var ph1=document.theform.dayphone1.value
	var ph2=document.theform.dayphone2.value
	var ph3=document.theform.dayphone3.value
	if (((document.theform.dayphone1.value != "" && document.theform.dayphone1.value != null) || (document.theform.dayphone2.value != "" && document.theform.dayphone2.value != null) || (document.theform.dayphone3.value != "" && document.theform.dayphone3.value != null)) && (ph1.length != 3))
		{
			document.theform.dayphone1.focus();
			document.theform.dayphone1.select();
			alert ("Please enter 3 digits in the first Telephone field.")
			return true;
		}
	if (((document.theform.dayphone1.value != "" && document.theform.dayphone1.value != null) || (document.theform.dayphone2.value != "" && document.theform.dayphone2.value != null) || (document.theform.dayphone3.value != "" && document.theform.dayphone3.value != null)) && (ph2.length != 3))
		{
			document.theform.dayphone2.focus();
			document.theform.dayphone2.select();
			alert ("Please enter 3 digits in the second Telephone field.")
			return true;
		}
	if (((document.theform.dayphone1.value != "" && document.theform.dayphone1.value != null) || (document.theform.dayphone2.value != "" && document.theform.dayphone2.value != null) || (document.theform.dayphone3.value != "" && document.theform.dayphone3.value != null)) && (ph3.length != 4))
		{
			document.theform.dayphone3.focus();
			document.theform.dayphone3.select();
			alert ("Please enter 4 digits in the third Telephone field.")
			return true;
		}
	else
		{
		return false;
	}
}

function checkEvePhoneNum()
{
	if ((document.theform.evephone1.value != "" && document.theform.evephone1.value != null) && (isNaN(document.theform.evephone1.value)))
		{
			document.theform.evephone1.focus();
			document.theform.evephone1.select();
			alert ("Please enter only numbers in the Telephone fields.")
			return true;
		}
	if ((document.theform.evephone2.value != "" && document.theform.evephone2.value != null) && (isNaN(document.theform.evephone2.value)))
		{
			document.theform.evephone2.focus();
			document.theform.evephone2.select();
			alert ("Please enter only numbers in the Telephone fields.")
			return true;
		}
	if ((document.theform.evephone3.value != "" && document.theform.evephone3.value != null) && (isNaN(document.theform.evephone3.value)))
		{
			document.theform.evephone3.focus();
			document.theform.evephone3.select();
			alert ("Please enter only numbers in the Telephone fields.")
			return true;
		}
	else
		{
		return false;
		}
}

function checkEvePhoneLen()
{
	var ph1=document.theform.evephone1.value
	var ph2=document.theform.evephone2.value
	var ph3=document.theform.evephone3.value
	if (((document.theform.evephone1.value != "" && document.theform.evephone1.value != null) || (document.theform.evephone2.value != "" && document.theform.evephone2.value != null) || (document.theform.evephone3.value != "" && document.theform.evephone3.value != null)) && (ph1.length != 3))
		{
			document.theform.evephone1.focus();
			document.theform.evephone1.select();
			alert ("Please enter 3 digits in the first Telephone field.")
			return true;
		}
	if (((document.theform.evephone1.value != "" && document.theform.evephone1.value != null) || (document.theform.evephone2.value != "" && document.theform.evephone2.value != null) || (document.theform.evephone3.value != "" && document.theform.evephone3.value != null)) && (ph2.length != 3))
		{
			document.theform.evephone2.focus();
			document.theform.evephone2.select();
			alert ("Please enter 3 digits in the second Telephone field.")
			return true;
		}
	if (((document.theform.evephone1.value != "" && document.theform.evephone1.value != null) || (document.theform.evephone2.value != "" && document.theform.evephone2.value != null) || (document.theform.evephone3.value != "" && document.theform.evephone3.value != null)) && (ph3.length != 4))
		{
			document.theform.evephone3.focus();
			document.theform.evephone3.select();
			alert ("Please enter 4 digits in the third Telephone field.")
			return true;
		}
	else
		{
		return false;
	}
}

function checkAgree(){
	if (document.theform.agree.checked != true)
		{
		document.theform.agree.focus();
		alert ("You must agree to the official rules of this contest to proceed.")
		return true
		}
	}

// standard functions not used to validate form	
	
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=550,height=350,left = 150,top = 200');");
}
function popUp2(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=650,height=475,left = 150,top = 150');");
}
function checkcnt(field,countfield,maxlimit)
{
	
   	if(field.value.length == 0)
   	{countfield.value = 0;}	
	else
	{
		var wordcounter=1;
		var charFlag=0;
		for (x=0;x<field.value.length;x++) 
		{	
			if(field.value.charAt(x) != " " && field.value.charAt(x) != "\n" && field.value.charAt(x) != "\r")
			{
				charFlag=1;
			}
    		if ((x!=0) && (field.value.charAt(x) == " " || field.value.charAt(x) == "\n" || field.value.charAt(x) == "\r") && (field.value.charAt(x-1) != " " && field.value.charAt(x-1) != "\n" && field.value.charAt(x-1) != "\r")) {wordcounter++}  // Counts the spaces while ignoring double spaces, usually one in between each word.
    		if (wordcounter > maxlimit) 
			{
				field.value = field.value.substring(0, x);
				field.focus();
				alert("Sorry, you must keep your entry below "+maxlimit+" words")
				wordcounter--;
			}  		
		}
		if(field.value.charAt(field.value.length-1) == " " || field.value.charAt(field.value.length-1) == "\n" || field.value.charAt(field.value.length-1) == "\r")
		{
			wordcounter--;
		}
    	if(charFlag == 0)
			{countfield.value = 0;}
		else
		{countfield.value = wordcounter;}
	}
}

ns4 = (document.layers)? true:false
ie4 = (document.all)? true:false
function showtextbox(obj) 
{
	
	var obj2 
	if (ns4) 
	{
		obj2 = eval("document.layers."+obj) 
		obj2.visibility = "show"
	}
	if (ie4) 
	{
		obj2 = eval("document.all."+obj) 
		obj2.style.visibility = "visible"
		obj2.style.display = "inline"
	}
}

function hidetextbox(obj) 
	{
	
	var obj2 
	var txtbx = new String(obj).substr(0,9)
	if (ns4) 
	{
		obj2 = eval("document.layers."+obj) 
		obj2.visibility = "hidden"
		obj2.display = "none"
		
	}
	if (ie4) 
	{
		obj2 = eval("document.all."+obj) 
		obj2.style.visibility = "hidden"
		obj2.style.display = "none"
		
	}
}

//Make sure date is valid 
function validDay()
{	
	var month=parseInt(document.theform.mob.options[document.theform.mob.selectedIndex].value,10)
	var day=parseInt(document.theform.dob.options[document.theform.dob.selectedIndex].value,10)
	var year=parseInt(document.theform.yob.options[document.theform.yob.selectedIndex].value,10)
	if ((month == 4 || month == 6 || month == 9 || month == 11) && (day > 30))
		{
		document.theform.mob.focus();
		alert ("Please enter a valid day for the month selected.")
		return true;
		}
	if ((month == 2) && (year % 4 == 0) && (day > 29))
		{
		document.theform.mob.focus();
		alert ("Please enter a valid day for the month selected.")
		return true;
		}
	if ((month == 2) && (year % 4 != 0) && (day > 28))
		{
		document.theform.mob.focus();
		alert ("Please enter a valid day for the month selected.")
		return true;
		}
	else
		{
		return false;
	}
}

function setCursor()
{
	document.theform.fname.focus()
}	
	
function upperMe(x)
{
	x.value = x.value.toUpperCase();
}