	function CheckNumeric()
	{
   		// Get ASCII value of key that user pressed
   		var key = window.event.keyCode;
		// Was key that was pressed a numeric character (0-9)?
   		if ( key > 47 && key < 58 )
      		return; // if so, do nothing
   		else
      		window.event.returnValue = null; // otherwise discard character
	}

	function checkrequired(which) 
	{
		var pass=true;
		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.value=='Type here'||tempobj.value=='0000')||(tempobj.type.toString().charAt(0)=="s"&&
tempobj.selectedIndex==0)) 
					{
						pass=false;
						break;
         				}
      				}
   			}
		}
		if (!pass) 
		{
			shortFieldName=tempobj.name.substring(8,30).toUpperCase();
			alert("Please make sure the "+shortFieldName+" field was properly completed.");
			return false;
		}
		else
		return checkRadios(which);
	}

	function checkRadios(which) 
	{
 		var el = document.forms[0].elements;
 		for(var i = 0 ; i < el.length ; ++i) 
		{
  			if(el[i].type == "radio") 
			{
   				var radiogroup = el[el[i].name]; // get the whole set of radio buttons.
   				var itemchecked = false;
   				for(var j = 0 ; j < radiogroup.length ; ++j) 
				{
    					if(radiogroup[j].checked) 
					{
	 					itemchecked = true;
	 					break;
					}
   				}
   				if(!itemchecked) 
				{ 
    					alert("Please choose an answer for "+el[i].name+".");
    					if(el[i].focus)
     					el[i].focus();
					return false;
   				}
  			}
 		}
 		return checkShowing(which); 
	}

	function checkShowing(which)
	{
		if (Em.style.visibility=='visible')
		{
			return validEmail();
		}
		else if (WS.style.visibility=='visible')
		{
			return validBiz(which);
		}
		else if (AZ.style.visibility=='visible')
		{
			return validAddy(which);
		}		
	}

	function validBiz(which)
	{
		if (Registration.BusinessorSchool.value=="")
		{
			alert("You must enter your business or school name.")
			return false;
		}
		else
		return validAddy(which);
	}

	function validAddy(which)
	{
		if (Registration.TulsaAddress.value=="")
		{
			alert("You must enter your Tulsa address.")
			return false;
		}
		return validateTulsaZIP(document.Registration.TulsaZip.value);

	}
	
	function validateZIP(field) 
	{
		var valid = "0123456789-";
		var hyphencount = 0;

		if (field.length!=5 && field.length!=10) 
		{
			alert("You must enter your 5 or 5+4 digit zip code using yyyyy or yyyyy-zzzz.");
    			document.Registration.requiredZip.select()
    			document.Registration.requiredZip.focus()
			return false;
		}
		for (var i=0; i < field.length; i++) 
		{
			temp = "" + field.substring(i, i+1);
			if (temp == "-") hyphencount++;
			if (valid.indexOf(temp) == "-1") 
			{
				alert("Invalid characters in your zip code.  Please try again.");
				document.Registration.requiredZip.select()
				document.Registration.requiredZip.focus()
				return false;
			}
			if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-")) 
			{
				alert("Please use a hyphen and the format yyyyy-zzzz");
    				document.Registration.requiredZip.select()
    				document.Registration.requiredZip.focus()
				return false;
   			}
		}
		return true;
	}

	function validateTulsaZIP(field) 
	{
		var valid = "0123456789-";
		var hyphencount = 0;

		if (field.length!=5 && field.length!=10) 
		{
			alert("You must enter your 5 or 5+4 digit zip code using yyyyy or yyyyy-zzzz.");
    			document.Registration.TulsaZip.select()
    			document.Registration.TulsaZip.focus()
			return false;
		}
		for (var i=0; i < field.length; i++) 
		{
			temp = "" + field.substring(i, i+1);
			if (temp == "-") hyphencount++;
			if (valid.indexOf(temp) == "-1") 
			{
				alert("Invalid characters in your zip code.  Please try again.");
				document.Registration.TulsaZip.select()
				document.Registration.Zip.Tulsafocus()
				return false;
			}
			if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-")) 
			{
				alert("Please use a hyphen and the format yyyyy-zzzz");
    				document.Registration.TulsaZip.select()
    				document.Registration.TulsaZip.focus()
				return false;
   			}
		}
		return true;
	}
	
	function validEmail(which)
	{
		if (Registration.EmailAddress.value.indexOf('@',0)==-1 ||
       			Registration.EmailAddress.value.indexOf('@',0)== 0 ||
       			Registration.EmailAddress.value.indexOf('.',0)==-1) 
		{
    			alert("Invalid email address.")
    			Registration.EmailAddress.select()
    			return false
    		}
		else if  (WS.style.visibility=='visible')
		{
			return validBiz(which);
		}
		else if (AZ.style.visibility=='visible')
		{
			return validAddy(which);
		}
	}

	function Email() 
	{
		Em.style.visibility='visible';
		Registration.EmailAddress.focus();
	}

	function notEmail() 
	{
		Em.style.visibility='hidden';
		Registration.EmailAddress.value="";
	}

	function Live() 
	{
		WS.style.visibility='hidden';
		AZ.style.visibility='hidden';
	}

	function WorkSchool() 
	{
		WS.style.visibility='visible'; 
		AZ.style.visibility='visible';
		alert("If you work/attend school AND live in Tulsa county, please select 'Live'");		
	}

	function Property() 
	{
		WS.style.visibility='hidden';
		AZ.style.visibility='visible';
		alert("If you own property AND live in Tulsa county, please select 'Live'");
		Registration.TulsaAddress.focus();
	}

	function ValidatePhone(elem) {
	var pn = elem.value;
	if (pn == "") return;
	pn = pn.replace(/\D/g,"");

	if (pn.length == 7)
		elem.value = pn.replace(/(\d{3})(\d{4})/,"$1-$2");
	else if (pn.length == 10)
		elem.value = pn.replace(/(\d{3})(\d{3})(\d{4})/,"($1) $2-$3");
	else {
		alert('The '+elem.name+' must be a 7 or 10 digit phone number');
		elem.focus();
		return false;
		}
	}
