/*
	1. The page content has to be included in <div id="pageContent"> ..... </div>
	   Ex: <h3>VA Chapter Electronic Abstract Form</h3>
           <div id="pageContent"> ..... </div> 
    2. The hidden files for the form have to set as below. 
	   Don't change the values of the name and id attributes. 
	   <p>
		<input type="hidden" name="store_in"  value="ABS_test" /> 
		<input type="hidden" name="save_env"  value="DateTime" /> 
		<input type="hidden" name="MaxLength" value="450" id="MaxLength" /> 
		<input type="hidden" name="verbose"   value="1" /> 
		<input type="hidden" name="required"  value="Abstract_Title,Abstract_Text,..." /> 
		<input type="hidden" name="RespondBy" id="RespondBy" value="Thu, October 1, 23:59:59 EDT 2009" />
		<input type="hidden" name="Chapter_Email" value="somebody@vachapter.org" />
		<input type="hidden" name="Chapter"   value="VA"/>
	   </p>
    3. The abstract box should be
	   <textarea name="Abstract_Text" cols="50" rows="20" 
          id="Abstract_Text" class="count[10, 450] required" ></textarea>
       the id and class are set for the validation and counting words.
    4. <form action="/cgi-bin/log_abstract_e.pl" method="post" id="theForm">
	   -- don't change the value of the id attribute

*/
$().ready(function(){   

	var now = new Date();
	var deadline = $("#RespondBy").val();
	// myDeadline is a hour late than the actual deadline
	var myDeadline = new Date(deadline);	
    myDeadline.setHours(myDeadline.getHours()+1);    
    
	if (now>myDeadline)
	{	   
       $("#pageContent").html('<h5><br />' 
			+ 'The abstract form is not available '
	        + 'because the deadline for abstract submissions was ' 
		    + deadline + '.</h5>');		    		
	   return false;
    }
    $('#theForm').validate({
      submitHandler: function(form){
 	     var maxLength = $("#MaxLength").val();
	     var numWords = jQuery.trim($("#Abstract_Text").val()).replace(/\s+/g," ").split(' ').length;
	  
	     if(numWords > maxLength){
			$("#limit").css({color: 'red'});
		    return false;
	     }else form.submit();
//		  {            
//		   jQuery('#theForm').ajaxSubmit({
//			   target: "#pageContent",
//			   url: 'http://wwwdev.acponline.org/cgi-bin/abs_test.pl'
//			});
         
//	  }
   }
  });
});