// JavaScript Document
$(function() {
	if($("#leftslide").length) {
		$("#leftslide").cycle({fx:'scrollDown'});
		$("#rightslide").cycle({delay: 1000,fx:'scrollRight'});
	}
	
	if($("#contact").length) {
		$("#contact").submit(function() {
			$this = $(this);
			$this.append('<input type="hidden" name="ajax" value="true" />');
			$("#showErrors").html("");
			$("#showErrors").addClass("progressbar");
			submitForm();
			return false;
		});
	}	
	
	if( $('a[href="#Definition"]').length) {
		$('a[href="#Definition"]').click(function() {
			window.open('http://www.env.gov.bc.ca/fw/fish/licences/definitions.html',"Definition","width=480xp,height=360px");
		});
	}

});

function submitForm() {
		$.ajax({
		  type: 'post',
		  url: 'cgi-bin/s_contact.php',
		  data: $("#contact").serialize(),
		  dataType: 'json',
		  success: function(data) {
			  if(data.answer == 'true') {
				$("#showErrors").removeClass("progressbar");
				 $("#showErrors").html('<h2>Message Has Been Sent!</h2>');
				 setTimeout(function() {
					 window.location = $("#zsite").val(); 
				 },2000);
			  }
			  else {
				  se = $("#showErrors");
				  se.removeClass("progressbar");
				  se.html('');
				  se.append('<ul id="showeror"></ul>');
				  $.each(data,function(index,val) {
					$('input[name='+index+']').css('background-color','#ff9');
					$('#showeror').append('<li>'+val+'</li>');
				  });
			  }
		  },
		  error: function(msg) {
				alert('Error: '+msg.error); 
		  }
		});
	}
