function CheckForm(prodnum) {

var prodtotal = CountProd(prodnum);
var reqtotal = CountReq();

var name 		= document.getElementById("name");
var email 		= document.getElementById("email");
var company 	= document.getElementById("company");
var title 		= document.getElementById("title");
var phone 		= document.getElementById("phone");
var comments 	= document.getElementById("comments");

if (reqtotal == 0) {
alert("You must select at least one request type.");
return false;
}

if (prodtotal == 0) {
alert("You must select at least one product.");
return false;
}

if (name.value == '') {
 alert("You must enter your name.");
 return false;
} else {
 if (name.value.match(/[^-a-zA-Z0-9 ._@�\']/)) {
  alert("You may only use alpha-numeric characters and the characters .-_'");
  return false;
 }
}


if (email.value == '') {
	alert("You must enter your email address.");
	return false;
} else {

	if (email.value.match(/[^-a-zA-Z0-9@_.]/)) {
		alert("Your email address may only use valid email characters (alphanumeric and _-@.)");
		return false;
	} else {

		if (isValidEmail(email.value) === false) {
		alert("You have entered an invalid email address. Please enter your email in the standard user@domain.com format.");
		return false;
	}
}
}


if (company.value == '') {
  alert("You must enter a company name.");
  return false;
} else {
 if (company.value.match(/[^-a-zA-Z0-9 ._@�\']/)) {
  alert("You may only use alpha-numeric characters and the characters .-_'");
  return false;
 }
}


if (title.value.match(/[^-a-zA-Z0-9 ._@�\']/)) {
alert("Your Title may only use alpha-numeric characters and the characters .-_'");
return false;
}


if (phone.value == '') {
alert("You must enter a telephone number.");
return false;
} else {
if (phone.value.match(/[^-0-9 .\(\)\+]/)) {
alert("For telephone numbers you may only use numbers and the characters ()-+.");
return false;
}
}


if (phone.value.match(/[^-0-9 .\(\)\+]/)) {
alert("For telephone numbers you may only use numbers and the characters ()-+.");
return false;
}

if (company.value.match(/[^-a-zA-Z0-9 ._@�&\']/)) {
alert("The company name field may only use alpha-numeric characters and the characters .-_&'");
return false;
}

if (comments.value.match(/[^-a-zA-Z0-9 ,?;:%/&�+!._@\'//]/)) {
alert("Your comments may only use alpha-numeric characters and the characters .-_'");
return false;
}


}


function isValidEmail(str)
{
  // trim starting / ending whitespace
  str = str.replace(/^\s*/, "");
  str = str.replace(/\s*$/, "");

  var at="@"
  var dot="."
  var lat=str.indexOf(at)
  var lstr=str.length
  var ldot=str.indexOf(dot)

  if (str.indexOf(at)==-1)
    return false

  if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
    return false

  if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
    return false

  if (str.indexOf(at,(lat+1))!=-1)
    return false

  if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
    return false

  if (str.indexOf(dot,(lat+2))==-1)
    return false

  if (str.indexOf(" ")!=-1)
    return false

  return true;
}




function CountProd(prodnum) {
var prodtotal = 0;
for (var idx = 0; idx < prodnum; idx++) {
if (document.getElementById("product["+ idx +"]").checked == true) {
    prodtotal += 1;
   }
}
return prodtotal;
}

function CountReq() {
var reqtotal = 0;
for (var idx = 0; idx <= 2; idx++) {
if (document.getElementById("request["+ idx +"]").checked == true) {
    reqtotal += 1;
   }
}
return reqtotal;
}

