// JavaScript Document

function submitForm()
{
	$("#contactform").ajaxSubmit(
										  {
											  target : '#response',
											  clearForm : false
										  }
										);
}
function contactusInit()
{
	 
	 //$("#contactform").ajaxForm();
	 $("#contactform").validate( 
										  {
											  rules: {
													  name: "required",													  
													  returnemail: {
														 required: true,
														 email: true
													  },
													  zipcode: {
														  required: true,
														  digits: true
													  }
													},
											  messages: {
												  name: "Please enter your name",
												  returnemail : {
													 required: "We need your email address to respond",
													 email: "Your email address must be in the format of name@domain.com"
												  },
												  zipcode: {
													  required: "Please enter your zip code",
													  digits: "Please enter only numbers"
												  }
												},
											   errorClass: "invalid",
												submitHandler: function(form) {
													submitForm();
													return false;
												}
										  }
										);
}

function showEvent( elem )
{
	 var param;
	 var filename = elem.attr("href");
	 if ( filename == "#") {  // this means there is no file for this event information so we'll build it with the secret embedded html
	    var p = elem.parent().parent(); // should be table row
	    var sib = elem.next();  // this should be a hidden div
		 var description = sib.html();
		 var when = $(".when", p).html();
		 var what = $(".what", p).html();
		 param = {
			 'when' : when,
			 'what' : what,
			 'description' : description
		 }
	 }
	 else
	    param = "events/"+filename;
	 parent.showFrameDialog( param );
	 return false;
}

function seminarInit()
{
	contactusInit();
	$("table.events a.more").unbind("click").click( function() { showEvent ( $(this) ); return false; } );
}

$contentReady.add( seminarInit );