var whitespace = " \t\n\r";

function isWhitespace(space) {
	   var i;
  	   // Search through string's characters one by one
   	// until we find a non-whitespace character.
	   // When we do, return false; if we don't, return true.
  		for (i = 0; i < space.length; i++){   
       // Check that current character isn't whitespace.
		 // use -1 use as "false" condition of non character, which means it 
		 // it contains character, therefore return false
         var current = space.charAt(i);
  	      if (whitespace.indexOf(current) == -1) return false;
     	}
      // All characters are whitespace.
  	   return true;
 }

 
 function tagChk(formName){
 	var tagValidate = ["<script","<applet","<body","<embed","<frame","<iframe","<htm","<style","<layer","<ilayer","<meta","<object"];
	var msg = "";
	//var a = "loginForm";
	//alert(document.forms[0].elements.length);	
 	// validate invalidate in form fields
 	for(i=0; i<document.forms[formName].elements.length; i++)
		{
		//alert ("The field name is: " + document.profileForm.elements[i].name + " and it's value is: " + document.profileForm.elements[i].value + ".<br />");
			if (!isWhitespace(document.forms[formName].elements[i].value)) 
			{	
				for (var m in tagValidate)
				{
				    if (document.forms[formName].elements[i].value.indexOf(tagValidate[m]) != -1)
					{
						msg = msg + "This" + tagValidate[m] + " tag is not allowed in the content." +"\n";
						break;
					
					}
				} 
			}
			if (msg != ""){
				break;
			}
		}
		/*
		if (msg != ""){
			alert(msg);			
			return false;
		}
 		*/
		return (msg);
 }
  
function chk(fields){
	 if (isWhitespace(fields.memail.value)) 
			{
			alert("Please enter an email address.");
			return false;
						
		}
		check_amp = fields.memail.value.indexOf('@',1)
		
 		if (check_amp == -1){
			alert ("Please enter a valid email.")
			return false
		}
 
}
 
function chk_login(fields){
	 if (isWhitespace(fields.username.value)) 
			{
			alert("Please enter an email address.");
			return false;
						
		}
		check_amp = fields.username.value.indexOf('@',1)
		
 	if (check_amp == -1){
			alert ("Please enter a valid email address.")
			return false
		}
	 if (isWhitespace(fields.passwd.value)) 
			{
			alert("Please enter a password.");
			return false;
						
		}
	var msg = tagChk('loginForm');
	if (msg != "")
	{
		alert (msg);
		return false;
	}
} 

function chk_forgot(fields){
	 if (isWhitespace(fields.username.value)) 
			{
			alert("Please enter an email address.");
			return false;
						
		}
		check_amp = fields.username.value.indexOf('@',1)
		
 	if (check_amp == -1){
			alert ("Please enter a valid email address.")
			return false
		}
	document.goForgot.email.value = fields.username.value
	document.goForgot.submit()
 
} 

function chk_freset(fields){
	 if (isWhitespace(fields.hintanswer.value) || isWhitespace(fields.mpass.value) ) 
			{
			alert("Please enter all the required fields.");
			return false;						
		}
		
	//password at least 8 character/digits	
		if (fields.mpass.value.length < 8){		
			alert("Password need to be with the minimum of 8 characters plus digits")
			return false
		
		}	
		
 
} 

 
function chk_new(fields){
 	 if (isWhitespace(fields.fname.value) || isWhitespace(fields.lname.value) ||
	 	isWhitespace(fields.memail.value) || isWhitespace(fields.mpass.value) || 
		isWhitespace(fields.mconpass.value) || isWhitespace(fields.fpassclue.value) || isWhitespace(fields.fclueanswer.value)) 
			{
			alert("Please enter all the required fields.");
			return false;
						
		}			 
	
		check_amp = fields.memail.value.indexOf('@',1)
		
 		if (check_amp == -1){
			alert ("Please enter a valid email.")
			return false
		}
		//supervisor email
		if (!isWhitespace(fields.supemail.value)){
			check_amp2 = fields.supemail.value.indexOf('@',1)
		
 			if (check_amp2 == -1){
			alert ("Please enter a valid supervisor email.")
			return false
			}
		
		}	
		//password at least 8 character/digits	
		if (fields.mpass.value.length < 8 || fields.mconpass.value.length < 8){		
			alert("Password and confirm password need to be with the minimum of 8 characters plus digits")
			return false
		
		}//password and confirm password is same
		if (fields.mpass.value != fields.mconpass.value){		
			alert("The confirm password and the password don't match.  Please reenter.")
			return false
		
		}
		
		
		if (fields.cme[0].checked){
			ind = fields.selstate.selectedIndex
			if (isWhitespace(fields.agenaddr.value) || isWhitespace(fields.city.value) || isWhitespace(fields.zip.value)
				|| fields.selstate.options[ind].value == "")
			{
			 alert ("To obtain CME credit, please specify the address, city, state, and zip information")
			 return false
			}
			
			if (fields.selstate.options[ind].value != "NV" && 
					fields.selstate.options[ind].value != "AZ" &&
					fields.selstate.options[ind].value != "CA" &&
					fields.selstate.options[ind].value != "OR")
			{
				 alert("We apologize that the Department of Public Health's accreditation by CMA-IMQ limits the provision of credit to residents of CA and bordering states (AZ, NV and OR).")		
			}		
		}//check if zip code is a number
		if	(!isWhitespace(fields.zip.value) && isNaN(fields.zip.value)== true){
			alert("Please enter a valid zip.")
			return false		
		}
		if (fields.county[0].checked && isWhitespace(fields.empno.value)){
			alert("Please enter the Employee ID.")
			return false		
		
		
		}
		var msg = tagChk('profileForm');
		if (msg != "")
		{
			alert (msg);
			return false;
		}
		
		
		
		
 }
 
  

 
function showmenu(elmnt)
	{   //block means show the section 
		if (document.getElementById(elmnt).style.display == "block"){
			hidemenu(elmnt)
		}
		else{
		document.getElementById(elmnt).style.display="block"
		}
}
	
function hidemenu(elmnt)
	{
     document.getElementById(elmnt).style.display="none"
}	 

function chk_key(v)
{
 	if (isWhitespace(v.keyword.value)) 
			{
			alert("To Sign up for this course, please enter the keyword.");
			return false;
						
		}

}

function chkcredit(fields)
	{
		if (fields.cre_ans[0].checked == false && fields.cre_ans[1].checked == false &&
			fields.cre_ans[2].checked == false && fields.cre_ans[3].checked == false ){
			alert ("Please answer the question.")
			return false
		}	
} 
