// JavaScript Document
function NoHTML(sText)
{
   var InvalidChars = "><";
   var HTMLcheck =true;
   var Char;

 
   for (i = 0; i < sText.length && HTMLcheck == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (InvalidChars.indexOf(Char) != -1) //if items are found 
         {
         HTMLcheck = false;
         }
      }
   return HTMLcheck;
   
}


function IsEmail(sText)
{

var whereisAT = sText.indexOf('@');

if(whereisAT == -1)
{
	return false;
}
   
var whereisDOT = sText.indexOf('.');  

if(whereisDOT == -1)
{
	return false;
}
   
   
   return true;
}
   

function checkform ( form )

{

  // ** START **
if (form.name.value == "") {

    alert( "Please enter a valid name." );

    form.name.focus();

    return false ;

  }
  
  
  if (form.phone.value == "") {

    alert( "Please enter a valid phone number." );

    form.phone.focus();

    return false ;

  }
  


  if (form.email.value == "") {

    alert( "Please enter a valid email." );

    form.email.focus();

    return false ;

  }
  else
  {
	var theTest = IsEmail(form.email.value);  
	
	if(theTest == false)
	{
	alert("Please enter a valid email.");
	form.email.focus();
	return false;
	}
	
  }


if (form.adsize.value == "") {

    alert( "Please select a valid ad size." );

    form.adsize.focus();

    return false ;

  }
 
	if(form.comments.value != "")
	{
	var theTest = NoHTML(form.comments.value);
	
		if(theTest == false)
		{
		alert("> and < are invalid characters.");
		form.comments.focus();
		return false;
		}	
	}
 
populateKey();
}


//Contact Form

function checkform_contact ( form )
{
var count = 0;

populateKey();

if(document.contactFORM.who[0].checked == true)
count++;
else if(document.contactFORM.who[1].checked == true)
count++;

	if(count == 0)
	{
	alert( "Please select a valid contact." );
    return false ;
	}

if (form.name.value == "") {

    alert( "Please enter a valid name." );

    form.name.focus();

    return false ;

  }

  if (form.email.value == "") {

    alert( "Please enter a valid email." );

    form.email.focus();

    return false ;

  }
  else
  {
	var theTest = IsEmail(form.email.value);  
	
	if(theTest == false)
	{
	alert("Please enter a valid email.");
	form.email.focus();
	return false;
	}
	
  }

if (form.comments.value == "") 
{

    alert( "Please write a valid comment." );

    form.comments.focus();

    return false;

  }
  else
	{
	var theTest = NoHTML(form.comments.value);
	
		if(theTest == false)
		{
		alert("> and < are invalid characters.");
		form.comments.focus();
		return false;
		}	
	
	}


}


function checkform_survey(form)
{
	if(form.Gender.value == "")
	{
	alert( "Please select a gender." );
    form.Gender.focus();
    return false;
	}

	if(form.Ethnicity.value == "")
	{
	alert( "Please select an ethnicity." );
    form.Ethnicity.focus();
    return false;
	}
	
	if(form.Income.value == "")
	{
	alert( "Please select an income." );
    form.Income.focus();
    return false;
	}	

	if(form.age.value == "")
	{
	alert( "Please enter an age." );
    form.age.focus();
    return false;
	}	


pattern = /^\d+$/;
 
 if (form.age.value != "" ) 
    {
    if ( pattern.test(form.age.value)==false )
        {
        alert ("Error, must enter a valid age with no special characters. Example: 18");
        form.age.focus();
		return false;
        }

    }
	
	
	
	if(form.occupation.value == "")
	{
	alert( "Please enter an occupation." );
    form.occupation.focus();
    return false;
	}	

}




