//=================================================================================
//this is needed for Educate_applyform.asp to dynamically generate the extra fields
//=================================================================================
		function generate_fields(j,placefill,placeavail,people,courseid){
		//var ttl;			

		var ttl = placefill + parseInt(document.theform.people.value) ;
		var avail = placeavail - placefill;
	
		if (ttl > placeavail)
		{
				alert ("Sorry, we only have " + avail+ " place(s) left for this course.");
			     return  false;

		}
		else {
			if (j == 1){
				alert("You are booking for " + document.theform.people.value + " people");
				document.theform.action ="educate_applyform.asp?pageid=43&courseid="+courseid;
				document.theform.submit();
				return true;
				}
			}
			return false;
		}


      // Check whether string s is empty.
      function isEmpty(s)
      { 
		if (s == null || s == "" ) {
			return true;
		}
		return false;
      }


 
      
function ValidateApplyCourse(theform,j) {
	var badChar = " ";
 	var notAllspace = false;
 	
 	switch(j)
	{
	case 1:
			if (isEmpty(document.theform.firstname1.value)) {
			     alert ("Please enter [First name]");
			     return  false;
		          } 
			notAllspace = false;
			for(var i = 0; i <= document.theform.firstname1.value.length - 1; i++) {
			
			    	if (document.theform.firstname1.value.charAt(i) != badChar) {
			    	 	notAllspace =true;
					}			
			}
			if (!notAllspace) 
			 {
			    	 	alert("Please enter a valid [first name]");
			    	 	document.theform.firstname1.focus();
			    		return false;	
			}    
			if (isEmpty(document.theform.lastname1.value)) {
			     alert ("Please enter [Last name]");
			     return false;
		          }
			 notAllspace = false;
			for(var i = 0; i <= document.theform.lastname1.value.length - 1; i++) {
			
			    	if (document.theform.lastname1.value.charAt(i) != badChar) {
			    	 	notAllspace =true;
					}	
			}	
			if (!notAllspace) 
			 {
			    	 	alert("Please enter a valid [last name]");
			    	 	document.theform.lastname1.focus();
			    		return false;	
			}

			break;
			// end of case 1
			
	case 2:
			//SECTION 1
			if (isEmpty(document.theform.firstname1.value)) {
			     alert ("Please enter [First name 1]");
			     return  false;
		          } 
			notAllspace = false;
			for(var i = 0; i <= document.theform.firstname1.value.length - 1; i++) {			
			    	if (document.theform.firstname1.value.charAt(i) != badChar) {
			    	 	notAllspace =true;
					}			
			}	
			if (!notAllspace) 
			 {
			    	 	alert("Please enter a valid [first name 1]");
			    	 	document.theform.firstname1.focus();
			    		return false;	
			}    
			if (isEmpty(document.theform.lastname1.value)) {
			     alert ("Please enter [Last name 1]");
			     return false;
		          }
			 notAllspace = false;
			for(var i = 0; i <= document.theform.lastname1.value.length - 1; i++) {
			
			    	if (document.theform.lastname1.value.charAt(i) != badChar) {
			    	 	notAllspace =true;
					}			
			}	
			if (!notAllspace) 
			 {
			    	 	alert("Please enter a valid [last name 1]");
			    	 	document.theform.lastname1.focus();
			    		return false;	
			} // end of case 2 - firstname 1
			
			//SECTION 2
			if (isEmpty(document.theform.firstname2.value)) {
			     alert ("Please enter [First name 2]");
			     return  false;
		          } 
			notAllspace = false;
			for(var i = 0; i <= document.theform.firstname2.value.length - 1; i++) {
			
			    	if (document.theform.firstname2.value.charAt(i) != badChar) {
			    	 	notAllspace =true;
					}
			}
			if (!notAllspace) 
			 {
			    	 	alert("Please enter a valid [first name 2]");
			    	 	document.theform.firstname2.focus();
			    		return false;	
			}    
			if (isEmpty(document.theform.lastname2.value)) {
			     alert ("Please enter [Last name 2]");
			     return false;
		          }
			 notAllspace = false;
			for(var i = 0; i <= document.theform.lastname2.value.length - 1; i++) {
			
			    	if (document.theform.lastname2.value.charAt(i) != badChar) {
			    	 	notAllspace =true;
					}
			}
			if (!notAllspace) 
			 {
			    	 	alert("Please enter a valid [last name 2]");
			    	 	document.theform.lastname2.focus();
			    		return false;	
			}
			break;			
			//end of case 2
			
	case 3:
			//SECTION 1
			if (isEmpty(document.theform.firstname1.value)) {
			     alert ("Please enter [First name 1]");
			     return  false;
		          } 
			notAllspace = false;
			for(var i = 0; i <= document.theform.firstname1.value.length - 1; i++) {			
			    	if (document.theform.firstname1.value.charAt(i) != badChar) {
			    	 	notAllspace =true;
					}			
			}	
			if (!notAllspace) 
			 {
			    	 	alert("Please enter a valid [first name 1]");
			    	 	document.theform.firstname1.focus();
			    		return false;	
			}    
			if (isEmpty(document.theform.lastname1.value)) {
			     alert ("Please enter [Last name 1]");
			     return false;
		          }
			 notAllspace = false;
			for(var i = 0; i <= document.theform.lastname1.value.length - 1; i++) {
			
			    	if (document.theform.lastname1.value.charAt(i) != badChar) {
			    	 	notAllspace =true;
					}			
			}	
			if (!notAllspace) 
			 {
			    	 	alert("Please enter a valid [last name 1]");
			    	 	document.theform.lastname1.focus();
			    		return false;	
			} // end of case 2 - firstname 1
			
			//SECTION 2
			if (isEmpty(document.theform.firstname2.value)) {
			     alert ("Please enter [First name 2]");
			     return  false;
		          } 
			notAllspace = false;
			for(var i = 0; i <= document.theform.firstname2.value.length - 1; i++) {
			
			    	if (document.theform.firstname2.value.charAt(i) != badChar) {
			    	 	notAllspace =true;
					}
			}
			if (!notAllspace) 
			 {
			    	 	alert("Please enter a valid [first name 2]");
			    	 	document.theform.firstname2.focus();
			    		return false;	
			}    
			if (isEmpty(document.theform.lastname2.value)) {
			     alert ("Please enter [Last name 2]");
			     return false;
		          }
			 notAllspace = false;
			for(var i = 0; i <= document.theform.lastname2.value.length - 1; i++) {
			
			    	if (document.theform.lastname2.value.charAt(i) != badChar) {
			    	 	notAllspace =true;
					}
			}
			if (!notAllspace) 
			 {
			    	 	alert("Please enter a valid [last name 2]");
			    	 	document.theform.lastname2.focus();
			    		return false;	
			}
			//SECTION 3
			if (isEmpty(document.theform.firstname3.value)) {
			     alert ("Please enter [First name 3]");
			     return  false;
		          } 
			notAllspace = false;
			for(var i = 0; i <= document.theform.firstname3.value.length - 1; i++) {
			
			    	if (document.theform.firstname3.value.charAt(i) != badChar) {
			    	 	notAllspace =true;
					}
			}
			if (!notAllspace) 
			 {
			    	 	alert("Please enter a valid [first name 3]");
			    	 	document.theform.firstname3.focus();
			    		return false;	
			}    
			if (isEmpty(document.theform.lastname3.value)) {
			     alert ("Please enter [Last name 3]");
			     return false;
		          }
			 notAllspace = false;
			for(var i = 0; i <= document.theform.lastname3.value.length - 1; i++) {
			
			    	if (document.theform.lastname3.value.charAt(i) != badChar) {
			    	 	notAllspace =true;
					}
			}
			if (!notAllspace) 
			 {
			    	 	alert("Please enter a valid [last name 3]");
			    	 	document.theform.lastname3.focus();
			    		return false;	
			}
			break;			
			//end of case 3			

	case 4:
			//SECTION 1
			if (isEmpty(document.theform.firstname1.value)) {
			     alert ("Please enter [First name 1]");
			     return  false;
		          } 
			notAllspace = false;
			for(var i = 0; i <= document.theform.firstname1.value.length - 1; i++) {			
			    	if (document.theform.firstname1.value.charAt(i) != badChar) {
			    	 	notAllspace =true;
					}			
			}	
			if (!notAllspace) 
			 {
			    	 	alert("Please enter a valid [first name 1]");
			    	 	document.theform.firstname1.focus();
			    		return false;	
			}    
			if (isEmpty(document.theform.lastname1.value)) {
			     alert ("Please enter [Last name 1]");
			     return false;
		          }
			 notAllspace = false;
			for(var i = 0; i <= document.theform.lastname1.value.length - 1; i++) {
			
			    	if (document.theform.lastname1.value.charAt(i) != badChar) {
			    	 	notAllspace =true;
					}			
			}	
			if (!notAllspace) 
			 {
			    	 	alert("Please enter a valid [last name 1]");
			    	 	document.theform.lastname1.focus();
			    		return false;	
			} // end of case 2 - firstname 1
			
			//SECTION 2
			if (isEmpty(document.theform.firstname2.value)) {
			     alert ("Please enter [First name 2]");
			     return  false;
		          } 
			notAllspace = false;
			for(var i = 0; i <= document.theform.firstname2.value.length - 1; i++) {
			
			    	if (document.theform.firstname2.value.charAt(i) != badChar) {
			    	 	notAllspace =true;
					}
			}
			if (!notAllspace) 
			 {
			    	 	alert("Please enter a valid [first name 2]");
			    	 	document.theform.firstname2.focus();
			    		return false;	
			}    
			if (isEmpty(document.theform.lastname2.value)) {
			     alert ("Please enter [Last name 2]");
			     return false;
		          }
			 notAllspace = false;
			for(var i = 0; i <= document.theform.lastname2.value.length - 1; i++) {
			
			    	if (document.theform.lastname2.value.charAt(i) != badChar) {
			    	 	notAllspace =true;
					}
			}
			if (!notAllspace) 
			 {
			    	 	alert("Please enter a valid [last name 2]");
			    	 	document.theform.lastname2.focus();
			    		return false;	
			}
			//SECTION 3
			if (isEmpty(document.theform.firstname3.value)) {
			     alert ("Please enter [First name 3]");
			     return  false;
		          } 
			notAllspace = false;
			for(var i = 0; i <= document.theform.firstname3.value.length - 1; i++) {
			
			    	if (document.theform.firstname3.value.charAt(i) != badChar) {
			    	 	notAllspace =true;
					}
			}
			if (!notAllspace) 
			 {
			    	 	alert("Please enter a valid [first name 3]");
			    	 	document.theform.firstname3.focus();
			    		return false;	
			}    
			if (isEmpty(document.theform.lastname3.value)) {
			     alert ("Please enter [Last name 3]");
			     return false;
		          }
			 notAllspace = false;
			for(var i = 0; i <= document.theform.lastname3.value.length - 1; i++) {
			
			    	if (document.theform.lastname3.value.charAt(i) != badChar) {
			    	 	notAllspace =true;
					}
			}
			if (!notAllspace) 
			 {
			    	 	alert("Please enter a valid [last name 3]");
			    	 	document.theform.lastname3.focus();
			    		return false;	
			}
			//SECTION 4
			if (isEmpty(document.theform.firstname4.value)) {
			     alert ("Please enter [First name 4]");
			     return  false;
		          } 
			notAllspace = false;
			for(var i = 0; i <= document.theform.firstname4.value.length - 1; i++) {
			
			    	if (document.theform.firstname4.value.charAt(i) != badChar) {
			    	 	notAllspace =true;
					}
			}
			if (!notAllspace) 
			 {
			    	 	alert("Please enter a valid [first name 4]");
			    	 	document.theform.firstname4.focus();
			    		return false;	
			}    
			if (isEmpty(document.theform.lastname4.value)) {
			     alert ("Please enter [Last name 4]");
			     return false;
		          }
			 notAllspace = false;
			for(var i = 0; i <= document.theform.lastname4.value.length - 1; i++) {
			
			    	if (document.theform.lastname4.value.charAt(i) != badChar) {
			    	 	notAllspace =true;
					}
			}
			if (!notAllspace) 
			 {
			    	 	alert("Please enter a valid [last name 4]");
			    	 	document.theform.lastname4.focus();
			    		return false;	
			}
			break;			
			//end of case 4
			
	case 5:
			//SECTION 1
			if (isEmpty(document.theform.firstname1.value)) {
			     alert ("Please enter [First name 1]");
			     return  false;
		          } 
			notAllspace = false;
			for(var i = 0; i <= document.theform.firstname1.value.length - 1; i++) {			
			    	if (document.theform.firstname1.value.charAt(i) != badChar) {
			    	 	notAllspace =true;
					}			
			}	
			if (!notAllspace) 
			 {
			    	 	alert("Please enter a valid [first name 1]");
			    	 	document.theform.firstname1.focus();
			    		return false;	
			}    
			if (isEmpty(document.theform.lastname1.value)) {
			     alert ("Please enter [Last name 1]");
			     return false;
		          }
			 notAllspace = false;
			for(var i = 0; i <= document.theform.lastname1.value.length - 1; i++) {
			
			    	if (document.theform.lastname1.value.charAt(i) != badChar) {
			    	 	notAllspace =true;
					}			
			}	
			if (!notAllspace) 
			 {
			    	 	alert("Please enter a valid [last name 1]");
			    	 	document.theform.lastname1.focus();
			    		return false;	
			} // end of case 2 - firstname 1
			
			//SECTION 2
			if (isEmpty(document.theform.firstname2.value)) {
			     alert ("Please enter [First name 2]");
			     return  false;
		          } 
			notAllspace = false;
			for(var i = 0; i <= document.theform.firstname2.value.length - 1; i++) {
			
			    	if (document.theform.firstname2.value.charAt(i) != badChar) {
			    	 	notAllspace =true;
					}
			}
			if (!notAllspace) 
			 {
			    	 	alert("Please enter a valid [first name 2]");
			    	 	document.theform.firstname2.focus();
			    		return false;	
			}    
			if (isEmpty(document.theform.lastname2.value)) {
			     alert ("Please enter [Last name 2]");
			     return false;
		          }
			 notAllspace = false;
			for(var i = 0; i <= document.theform.lastname2.value.length - 1; i++) {
			
			    	if (document.theform.lastname2.value.charAt(i) != badChar) {
			    	 	notAllspace =true;
					}
			}
			if (!notAllspace) 
			 {
			    	 	alert("Please enter a valid [last name 2]");
			    	 	document.theform.lastname2.focus();
			    		return false;	
			}
			//SECTION 3
			if (isEmpty(document.theform.firstname3.value)) {
			     alert ("Please enter [First name 3]");
			     return  false;
		          } 
			notAllspace = false;
			for(var i = 0; i <= document.theform.firstname3.value.length - 1; i++) {
			
			    	if (document.theform.firstname3.value.charAt(i) != badChar) {
			    	 	notAllspace =true;
					}
			}
			if (!notAllspace) 
			 {
			    	 	alert("Please enter a valid [first name 3]");
			    	 	document.theform.firstname3.focus();
			    		return false;	
			}    
			if (isEmpty(document.theform.lastname3.value)) {
			     alert ("Please enter [Last name 3]");
			     return false;
		          }
			 notAllspace = false;
			for(var i = 0; i <= document.theform.lastname3.value.length - 1; i++) {
			
			    	if (document.theform.lastname3.value.charAt(i) != badChar) {
			    	 	notAllspace =true;
					}
			}
			if (!notAllspace) 
			 {
			    	 	alert("Please enter a valid [last name 3]");
			    	 	document.theform.lastname3.focus();
			    		return false;	
			}
			//SECTION 4
			if (isEmpty(document.theform.firstname4.value)) {
			     alert ("Please enter [First name 4]");
			     return  false;
		          } 
			notAllspace = false;
			for(var i = 0; i <= document.theform.firstname4.value.length - 1; i++) {
			
			    	if (document.theform.firstname4.value.charAt(i) != badChar) {
			    	 	notAllspace =true;
					}
			}
			if (!notAllspace) 
			 {
			    	 	alert("Please enter a valid [first name 4]");
			    	 	document.theform.firstname4.focus();
			    		return false;	
			}    
			if (isEmpty(document.theform.lastname4.value)) {
			     alert ("Please enter [Last name 4]");
			     return false;
		          }
			 notAllspace = false;
			for(var i = 0; i <= document.theform.lastname4.value.length - 1; i++) {
			
			    	if (document.theform.lastname4.value.charAt(i) != badChar) {
			    	 	notAllspace =true;
					}
			}
			if (!notAllspace) 
			 {
			    	 	alert("Please enter a valid [last name 4]");
			    	 	document.theform.lastname4.focus();
			    		return false;	
			}
			
			//SECTION 5
			if (isEmpty(document.theform.firstname5.value)) {
			     alert ("Please enter [First name 5]");
			     return  false;
		          } 
			notAllspace = false;
			for(var i = 0; i <= document.theform.firstname5.value.length - 1; i++) {
			
			    	if (document.theform.firstname5.value.charAt(i) != badChar) {
			    	 	notAllspace =true;
					}
			}
			if (!notAllspace) 
			 {
			    	 	alert("Please enter a valid [first name 5]");
			    	 	document.theform.firstname5.focus();
			    		return false;	
			}    
			if (isEmpty(document.theform.lastname5.value)) {
			     alert ("Please enter [Last name 5]");
			     return false;
		          }
			 notAllspace = false;
			for(var i = 0; i <= document.theform.lastname5.value.length - 1; i++) {
			
			    	if (document.theform.lastname5.value.charAt(i) != badChar) {
			    	 	notAllspace =true;
					}
			}
			if (!notAllspace) 
			 {
			    	 	alert("Please enter a valid [last name 5]");
			    	 	document.theform.lastname5.focus();
			    		return false;	
			}
			break;			
			//end of case 5			

		
	} //end of siwtch
	
	if (isEmpty(document.theform.tel.value)) {
	     alert ("Please enter [Contact No.]");
	     return false;
          }
	if (isEmpty(document.theform.email.value)) {
	     alert ("Please enter [Email]");
	     return false;
          }       
    if (document.theform.email.value.indexOf("@") < 0) {
		    alert("Please type a valid [email address]!");
		    document.theform.email.focus();
	    	    return false;
		}


	if (isEmpty(document.theform.address1.value)) {
	     alert ("Please enter [Address]");
	     return false;
          }        
	notAllspace = false;

	for(var i = 0; i <= document.theform.address1.value.length - 1; i++) {
	
	    	if (document.theform.address1.value.charAt(i) != badChar) {
	    	 	notAllspace =true;
			}
		
	}
	
	if (!notAllspace) 
	 {
	    	 	alert("Please enter a valid [address]");
	    	 	document.theform.address1.focus();
	    		return false;	
	}    

	if (isEmpty(document.theform.suburb.value)) {
	     alert ("Please enter [Suburb]");
	     return  false;
          }
	notAllspace = false;

	for(var i = 0; i <= document.theform.suburb.value.length - 1; i++) {
	
	    	if (document.theform.suburb.value.charAt(i) != badChar) {
	    	 	notAllspace =true;
			}
		
	}
	
	if (!notAllspace) 
	 {
	    	 	alert("Please enter a valid [suburb]");
	    	 	document.theform.suburb.focus();
	    		return false;	
	}    
	if (document.theform.state.value == "Select") {
	     alert ("Please enter [State]");
	     return  false;
          }
	if (isEmpty(document.theform.postcode.value)) {
	     alert ("Please enter [Postcode]");
	     return  false;
          }
                                              
	 return true;

}     

function ValidateReqTopic(request_topic){


	if (document.request_topic.topictitle.value=="") {
	     alert ("Please select [Title]");
	 	document.request_topic.topictitle.focus();
	     return  false;
          } 
   	if (document.request_topic.topicfname.value=="") {
	     alert ("Please enter [Firstname]");
	     document.request_topic.topicfname.focus();
	     return  false;
          } 
	if (document.request_topic.topiclname.value=="") {
	     alert ("Please enter [Surname]");
	      document.request_topic.topiclname.focus();
	     return  false;
          }
	if (document.request_topic.topicemail.value=="") {
	     alert ("Please enter [email address]");
	      document.request_topic.topicemail.focus();
	     return  false;
          }

	if (document.request_topic.topicemail.value != "") 
	{
		// test if valid email address, must have @ and .
		var checkEmail = "@.";
		var checkStr = document.request_topic.topicemail.value;
		var EmailValid = false;
		var EmailAt = -1;
		var EmailPeriod = -1;
		for (i = 0;  i < checkStr.length;  i++)
		{
			ch = checkStr.charAt(i);
			if (ch == "@")
				EmailAt = i;
			if (ch == ".") 
				EmailPeriod = i;
		}
		// if both the @ and . were in the string
		if ((EmailAt > -1) && (EmailPeriod > -1) && (EmailAt < EmailPeriod))	EmailValid = true;

		if (!EmailValid)
		{
			alert("The \"email address\" field must contain an \"@\" and a \".\".");
			document.request_topic.topicemail.focus();
			return (false);
		} 
	}

	if (document.request_topic.ttopic.value=="") {
	     alert ("Please enter [Topic]");
	      document.request_topic.ttopic.focus();
	     return  false;
          }
	
	if (!document.request_topic.topicaccept.checked) {
	     alert ("Please accept the confidentiality clause.");
	      document.request_topic.topicaccept.focus();
	     return  false;
          }

	if (document.request_topic.strCAPTCHA.value == "")
	{
		alert ("Please enter the verification code");
		document.request_topic.strCAPTCHA.focus();
		return (false);
	}

	request_topic.submit();
}

function Validate(ccoptin){

	
	if (ccoptin.ea.value == "")
	{
		alert ("Please enter your email address in this field");
		ccoptin.ea.focus();
		return (false);
	}
//	if (ccoptin.ea.value.length > 1) {
//	    if ((ccoptin.ea.value.indexOf("@") == -1) ||
//		(ccoptin.ea.value.indexOf(".") == -1))
//		 {
//		    alert("Please type a valid email address!");
//		   ccoptin.ea.value.focus();
//	    return false;
//		}
//	}
		
	ccoptin.submit();

}

                                              
    