function checkForm(frm) 
{
    var why = "";
	theForm = document.getElementById(frm)
    why += checkFName(theForm.fname.value);
	why += checkLName(theForm.lname.value);
	why += checkCity(theForm.city.value);	
	why += checkEmail(theForm.email.value);
   why += checkPhone(theForm.phone.value);
   why +=checkCaptcha(theForm.captcha.value);
   
	for (i=0, n=theForm.intr.length; i<n; i++) 
	{
			if (theForm.intr[i].checked) 
			{
				var checkvalue = theForm.intr[i].value;
				break;
			} 
    }
    why += checkCountry(theForm.country.selectedIndex);
	why += checkIndustry(theForm.industry.selectedIndex);
	if (why != "") 
		{
		   alert(why);
		   return false;
		}
return true;
}

// First Name - 
function checkFName (strng) 
{
var error = "";
if (strng == "") 
{
   error = "You didn't enter your First Name.\n";
}
return error;
}
//Last Name - 
function checkLName (strng) 
{
var error = "";
if (strng == "") 
	{
	   error = "You didn't enter your Last Name.\n";
	}
return error;	
}
//City - 
function checkCity (strng) 
{
var error = "";
if (strng == "") 
	{
	   error = "You didn't enter your City.\n";
	}
return error;	
}
//Email 
function checkEmail (strng) 
{
var error="";
if (strng == "") 
{
   error = "You didn't enter an email address.\n";
}
	var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) 
	{ 
       error = "Please enter a valid email address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) 
		 {
          error = "The email address contains illegal characters.\n";
       }
    }
return error;    
}

// phone number - strip out delimiters and check for 10 digits

function checkPhone (strng) 
{
var error = "";
if (strng == "") 
	{
	   error = "You didn't enter a phone number.\n";
	}else {
		
		var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
		if (isNaN(parseInt(stripped))) 
		{
		   error = "The phone number contains illegal characters.\n";
		}
	}
//    if (!(stripped.length == 14)) 
//	{
//	error = "The phone number is the wrong length. Make sure you included an area code.\n";
//    } 
return error;
}
//Check Country
function checkCountry(choice) 
{
var error = "";
    if (choice == 0) 
	{
    error = "You didn't choose an option from the Country list.\n";
    }    
return error;
}    

//Check Industry
function checkIndustry(choice) 
{
var error = "";
    if (choice == 0) 
	{
    error = "You didn't choose an option from the Industry list.\n";
    }    
return error;
}    

// exactly one radio button is chosen
function checkRadio(checkvalue) 
{
var error = "";
   if (!(checkvalue)) 
   {
       error = "Please check a radio button.\n";
    }
return error;
}
function checkCaptcha(strng)
{
var error = "";
	if (strng == "") 
	{
	   error = "You didn't enter validation code.\n";
	}else 
	{
		if (strng != captvar) 
		{
		   error = "Validation code is not same as the image given.\n";
		}
	}
return error;	
}


