// JavaScript Document
//Checks Radio Buttons on the assessment page
function checkit(theForm) {
var done = "true";
var checked = "no";
var qnum ="";

for (i=0; i<theForm.q1.length; i++) { if(theForm.q1[i].checked) { checked = "yes";  } }
if (checked != "yes") { done = "false"; }
checked = "no";
for (i=0; i<theForm.q2.length; i++) { if(theForm.q2[i].checked) { checked = "yes";  } }
if (checked != "yes") { done = "false"; }
checked = "no";
for (i=0; i<theForm.q3.length; i++) { if(theForm.q3[i].checked) { checked = "yes";  } }
if (checked != "yes") { done = "false"; }
checked = "no";
for (i=0; i<theForm.q4.length; i++) { if(theForm.q4[i].checked) { checked = "yes";  } }
if (checked != "yes") { done = "false"; }
checked = "no";
for (i=0; i<theForm.q5.length; i++) { if(theForm.q5[i].checked) { checked = "yes";  } }
if (checked != "yes") { done = "false"; }
checked = "no";
for (i=0; i<theForm.q6.length; i++) { if(theForm.q6[i].checked) { checked = "yes";  } }
if (checked != "yes") { done = "false"; }
checked = "no";
for (i=0; i<theForm.q7.length; i++) { if(theForm.q7[i].checked) { checked = "yes";  } }
if (checked != "yes") { done = "false"; }
if (done == "false") { alert("You must answer all the questions."); }
else { theForm.submit();}
}

//Error Checking on the Contact Page
function checkContact(theForm) {
    var errormsg = "";
    errormsg += checkBlank(theForm.firstName.value,"First Name");
    errormsg += checkEmail(theForm.Email.value);
	errormsg += checkBlank(theForm.Comments.value, "Comments");
    if (errormsg != "") {
       alert(errormsg);
    }
	else {
		theForm.submit();
	}
}

//Error Checking on the Feedback Page
function checkFeedback(theForm) {
    var errormsg = "";
    errormsg += checkBlank(theForm.firstName.value,"First Name");
    errormsg += checkEmail(theForm.Email.value);
	errormsg += checkBlank(theForm.Observations.value, "Observations");
    if (errormsg != "") {
       alert(errormsg);
    }
	else {
		theForm.submit();
	}
}


//Check Registration
function checkReg(theForm) {
    var errormsg = "";
    errormsg += checkBlank(theForm.firstName.value,"First Name");
    errormsg += checkBlank(theForm.lastName.value,"Last Name");
	errormsg += checkMatch(theForm.Email.value,theForm.Email2.value);
    errormsg += checkEmail(theForm.Email.value);
	errormsg += checkBlank(theForm.City.value, "City");
    if (errormsg != "") {
       alert(errormsg);
    }
	else {
		theForm.submit();
	}
}

//Check Feature
function checkFeat(theForm) {
    var errormsg = "";
    errormsg += checkBlank(theForm.firstName.value,"First Name");
    errormsg += checkEmail(theForm.Email.value);
    errormsg += checkBlank(theForm.MyIdea.value,"product feature");
    if (errormsg != "") {
       alert(errormsg);
    }
	else {
		theForm.submit();
	}
}

//Check Live Demo
function checkLiveD(theForm) {
    var errormsg = "";
    errormsg += checkBlank(theForm.FirstName.value,"First Name");
    errormsg += checkBlank(theForm.LastName.value,"Last Name");
    errormsg += checkEmail(theForm.Email.value);
    errormsg += checkBlank(theForm.StateProvince.value,"State/Province");
	errormsg += checkBlank(theForm.Phone.value,"Phone Number");
    if (errormsg != "") {
       alert(errormsg);
    }
	else {
		theForm.submit();
	}
}

function checkBlank (value,what) { //value = contents of field what = Name of Field.
	 var error = "";
	 if (value == "") {
		error = "Please enter your " + what + ".\n";
	 }
	 return error;
 }
 
 function checkMatch (email, email2) {
		var error = "";
		if (email != email2) {
			error = "The email addresses do not match. \n";
		}
		return error;
 }

function checkEmail (emailadd) {
	var error="";
	if (emailadd == "") {
	   error = "Please enter an email address.\n";
	}
	
		var emailFilter=/^.+@.+\..{2,3}$/;
		if (!(emailFilter.test(emailadd))) { 
		   error = "Please enter a valid email address.\n";
		}
		else {
	//test email for illegal characters
		   var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
			 if (emailadd.match(illegalChars)) {
			  error = "The email address contains illegal characters.\n";
		   }
		}
	return error;    
}
