// Font resizing functions, using jquery
$(document).ready(function(){
  // Reset Font Size
  var originalFontSize = $('html').css('font-size');
  $(".resetFont").click(function(){
    $('html').css('font-size', originalFontSize);
	return false;
  });
  // Increase Font Size
  $(".increaseFont").click(function(){
    var currentFontSize = $('html').css('font-size');
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum*1.1;
    $('html').css('font-size', newFontSize);
    return false;
  });
  // Decrease Font Size
  $(".decreaseFont").click(function(){
    var currentFontSize = $('html').css('font-size');
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum/1.1;
    $('html').css('font-size', newFontSize);
    return false;
  });
});

// search bar function called when search button pressed
function dosearch() {
  var sf=document.searchform;
  var submitto = sf.sengine.value + escape(sf.searchterms.value);
  window.location.href = submitto;
  return false;
}


// coming soon popup function
$(document).ready(function(){
	$("#comingsoon_popup").dialog({ width: 200, autoOpen: false, modal: true, position: 'center', title: 'Coming Soon' });
  $(".comingsoon").click(function(cs)
	{
		cs.preventDefault();
		$("#comingsoon_popup").html('<p class="large">Sorry.  This feature is not yet available.</p>');
		$("#comingsoon_popup").dialog('open');
  	setTimeout( function()
  	{
			$("#comingsoon_popup").dialog('close');
  	}, 1000);  	
	});
});
	
	
// select all churches event/news function
$(document).ready(function(){
	$("#check_all_churches").click(function()				
	{
    var checked_status = this.checked;
    $("input.church").each(function()
    {
    	this.checked = checked_status;
    });
	});		
});


// logging in and out functions
$(document).ready(function(){
	$("#login_popup").dialog({ width: 400, autoOpen: false, modal: true, position: 'center', title: 'Enter login details' });
  $("#login").click(function(li)
	{
		li.preventDefault();
		$("#login_popup").dialog('open');
	});
	
  $("#logout").click(function(lo)
	{
		lo.preventDefault();
		$("#login_popup").dialog('open');
		$.ajax({
			url: "../login_process/logout",
			cache: false,
			type: "POST",
			success : function() {
				$("#login_span").html('<a id="login" href="">Login</a>');
				$("#login_errors").html('<div class=\'success\'>You are now logged out.</div>');
  			
				$('#login_popup').dialog({
          close: function(event, ui) { location.reload(true); }
        });
			}
		});
	});
	
  $("#login_submit").click(function (ls)
	{
		ls.preventDefault();
		
 		var queryString = [ "xUser=", $("input[name='user_name']").val(), "&xPass=", $("input[name='pass']").val() ].join("");
		$.ajax({
			url: "../login_process",
			cache: false,
			type: "POST",
			data: queryString,
			dataType: "json",
			success : function(JSON) {
				
				$("#login_errors").html(JSON.errors);
				
				if ( (JSON.validated == true)  && (JSON.logged == true) )
				{
					$('#login_popup').dialog({
            close: function(event, ui) { location.reload(true); }
          });
					
					$("#login_popup").dialog('close');
				}
			}
		});

	});
});

