function LoadTheUrls(theForm)
{
	d = document;
	theForm.currUrl.value = d.URL;
	theForm.prevUrl.value = d.referrer;
}


function ValidateInfoForm(theForm)
{
   var error = ""; //initialize cascading error message

   //////////////////Check for blanks.

   if (theForm.firstName.value == "+")
	 {
     return true;
	 }

   if (theForm.firstName.value == "") 
   { 
      error += "Please enter your first name.\n";
      theForm.firstName.focus();
      alert(error);
      return false;
   }

   if (theForm.lastName.value == "") 
   { 
      error += "Pleas enter your last name.\n";
      theForm.lastName.focus();
      alert(error);
      return false;
   }

   if (theForm.country.value == "--select your country--") 
   { 
      error += "Please tell us what country you're from.\n";
      theForm.country.focus();
      alert(error);
      return false;
   }

   if (theForm.email.value == "") 
   { 
	    if(theForm.emailConfirm) {error += 'You must enter your e-mail address twice, once in the "E-mail address" box and again in the "Type e-mail address again to confirm" box. You left the first "E-mail address" box empty.\n';}
			else {error += 'Please enter your e-mail address.';}
      theForm.email.focus();
      alert(error);
      return false;
   }

   if(theForm.emailConfirm)
	 {
		 if (theForm.emailConfirm.value == "") 
		 { 
				error += 'You must enter your e-mail address twice, once in the "E-mail address" box and again in the "Type e-mail address again to confirm" box. You left this confirmation box empty.\n';
				theForm.emailConfirm.focus();
				alert(error);
				return false;
		 }

		 if (!(/^[a-zA-Z0-9._-]+@([a-zA-Z0-9._-]+\.)+[a-zA-Z.]{2,5}$/.test(theForm.email.value))) 
		 {////////////////////check format of email string
				error += '"' + theForm.email.value + '" is not a valid e-mail address. Your e-mail address should be formatted like this: yourname@companyname.com\n';
				theForm.email.focus();
				theForm.email.select();
				alert(error);
				return false;
		 }
		 else
		 {////////////////////Case insensitive comparison between e-mail address fields

				theForm.email.value = theForm.email.value.toLowerCase();
				theForm.emailConfirm.value = theForm.emailConfirm.value.toLowerCase();

				if (theForm.email.value != theForm.emailConfirm.value) 
				{ 
					 error += "The e-mail addresses do not match.\n";
					 theForm.emailConfirm.focus();
					 theForm.emailConfirm.select();
					 alert(error);
					 return false;
				}
		 }
	 }
  
	 if(theForm.interestLevel)
	 {
     if( ! IsRadioChoice(theForm.interestLevel) )
		 {
		   theForm.interestLevel[0].focus();
       alert("Please indicate your level of interest in the software that you're downloading.");
			 return false;
		 }
	 }

	 if(theForm.implementationTimeFrame)
	 {
     if( ! IsRadioChoice(theForm.implementationTimeFrame) )
		 {
		   theForm.implementationTimeFrame[0].focus();
       alert("Please indicate when you are planning to start using the software or to start implementing a solution that includes the software.");
			 return false;
		 }
	 }

   if (theForm.businessType.value == "--select from this list--") 
   { 
      error += "Please select the description that most closely matches your company or organization.\n";
      theForm.businessType.focus();
      alert(error);
      return false;
   } 

   if (theForm.sourceText.value == "--select from this list--") 
   { 
      error += "Please tell us how you found out about this web site.\n";
      theForm.sourceText.focus();
      alert(error);
      return false;
   } 

   if (error != "")
   {//This is here in case anyone feels like using a single message full of errors
    //instead of messages one by one. Just remove the alerts and returns above.
 
      alert(error);
      return (false);
   }
   else
   {
      LoadTheUrls(theForm);
      return (true);
   }
}


function IsRadioChoice(radioArray)
{
	var radioChoice = false;

	// Loop from zero to the one minus the number of radio button selections
	for (counter = 0; counter < radioArray.length; counter++)
	{
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (radioArray[counter].checked)
		radioChoice = true; 
	}
	return radioChoice;
}
