$(document).ready(function(){



$('#target').load('quiz.inc');  
     



//	submit


 

	$('#submitbutton').click(function() {
		
		$('#quiz').submit();
		return false;
	}) 

 





 
//	accordian


 

	$('a.special').mouseover(function() {
		$('ul.special').slideDown('slow');
		
		return false;
	}) 

	$('li.me').mouseover(function() {
	$('ul.special').slideUp('slow');
	
		return false;
	}) 
	
 









//	make .right and .left buttons work as next/previous


	$('a.right').click(function() {
	 $('img.right').click();			
	}) 

	$('a.left').click(function() {
	 $('img.left').click();			
	}) 




//	make click on 'unhide' show the .hidden button

	$('.unhide').click(function() {
	$(this).parents('div.panel').find('.hidden').show( );			
	}) 




	
	
	
//	is this an email field and is it invalid?
		
$('input.email').change(function() {
	
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var address = $(this).val(); 


if (	$(this).hasClass("email") &        
   		reg.test(address) == false) 
   			{
      		alert('Invalid Email Address'); 
      		$(this).removeClass('error');  
      		$(this).removeClass('ok');  
      		$(this).addClass('error');  
   			}  


else
{$(this).removeClass('error');$(this).removeClass('ok'); $(this).addClass('ok'); }
	
	}) 
 
 
 	


//	is this a required field and is it not filled?
		

$('input.required').change(function() {

	if (	$(this).hasClass("required")  )       
   			 
   			{
   			if (
   				$(this).val()==""||
   				$(this).val()==" "
   				)
   					{
      				alert('This field is required'); 
      				$(this).removeClass('error'); 
      				$(this).removeClass('ok');  
      				$(this).addClass('error');  
      				}
      		
      		else
{$(this).removeClass('error');$(this).removeClass('ok'); $(this).addClass('ok'); }
   			}  
	

	
	}) 
 
 
 
 
 
 
 

//	are any in this panel required? if so, add to report on input change

$('input').change(function() {
	
	var lw = $(this).parents('div.panel').find('.required').attr('class');	
	  if ( lw.match('required')){
	  $('#messages').append('<br><br>some in panel required');
	  }




 
//	report on all panels
 
 	var allInputs = $("#quiz :input");
    var formRequired = $("form .required");
    var formError = $("form .error");
    var formEmail = $("form .email");
    var formOk = $("form .ok");
    
    $("#messages").text("Found " + 
    		allInputs.length + " inputs, " +
            formRequired.length + " required, " + 
            formEmail.length + " email, " +
            formOk.length + " ok, " +
            formError.length + " error. ")
  
  
     ;
     
//	then show next button if more oks than required			
if(formOk.length==formRequired.length){$(this).parents('div.panel').find('.hidden').show( );}


})  
 
















});







 
function validate(){

if 

((document.Simple.name.value=="")|


(document.Simple.email.value=="")|

(document.Simple.telephone=="")){
alert ("Please fill in the required fields")

return false

}

else

return true

}


