//Allow Prototype library
$j = jQuery.noConflict(true);

    $j(document).ready(function() {
		
		
		
		$j(".volunteerBtn").click(function(){
			
			var id=$j(this).attr('id');
			$j(".volunteerForm").hide();
			$j(".volunteerBtn").show();
			$j(this).hide();
			//refresh captcha image preventing image caching
			$j("#captcha_"+id).attr('src','/CaptchaSecurityImages.php?width=90&amp;height=30&amp;characters=5&' + new Date().getTime());
			$j('#volunteerForm_'+id).show();
			});
			
			
		$j(".btnVolSubmit").click(function(){
			$j(".error_trigger").html("");
			var attrArr=$j(this).attr('id').split("_");
			var id=attrArr[1];
			var valid=true;
		if ($j("#firstname_"+id).val()==''){
			$j("#firstname_"+id+"_error").html('Please enter your first name');
			valid=false;
		}
		if($j("#lastname_"+id).val()==''){
			$j("#lastname_"+id+"_error").html('Please enter your last name');
			valid=false;
		}
		if($j("#email_"+id).val()==''){
			$j("#email_"+id+"_error").html('Please enter your email');
			valid=false;
		}
		if($j("#securitycode_"+id).val()==''){
			$j("#securitycode_"+id+"_error").html('Please enter security code');
			valid=false;
		}
			if (valid == true){
				//do the captcha chaching first
				$j.post('/post.php',{action : 'captchaAction', 
									security_code: $j("#securitycode_"+id).val()},function(data){
										if (data !=""){
											$j("#securitycode_"+id+"_error").html('Please enter a valid security code');
										}else{
											//submit the request
											$j.post("/post.php",{action:'volunteerNonUser',
													id:id,
													firstname: $j("#firstname_" + id).val(),
													lastname: $j("#lastname_" + id).val(),
													email: $j("#email_" + id).val(),
													phone: $j("#phone_" + id).val(),
													message_sent: $j("#message_" + id).val()}, function(data){
														$j('#volunteerForm_'+id).html('<span class="bodytext_red">Thank you, your availability has been received. ' + 
														'The captain will be notified and contact you confirming this event.</span>');
													}, function(data){
														$j('#volunteerForm_'+id).html('Sorry, we are unable to proceed with your request. Please try again later.');
													});
										}
				});
			}
		});
		
	
	
	});// JavaScript Document
