var maxRows=0;
var __AJAXERROR = false;

$(document).ready(function(){
	
	
	var _lastMenu = null;
	var _curMenu = null;
	
	//Remove outline from links
	$("a").click(function(){
		$(this).blur();
	});
	
	//When mouse rolls over
	$("li").mouseover(function(){
									$(this).stop().animate({height:'225px'}, 1000);
								});
	
	//When mouse is removed
	$("li").mouseout(function(){
									$(this).stop().animate({height:'25px'});
								});


	$(".menulink").click(function()
								  {
									$("#workspace").html("Please wait ....");
									$("#workspace").load("./includes/" + $(this).attr("id") + ".php");
									
								  }
						);

	$("#workspace").load("./includes/home-1.php");
	
	

});

var _athanEXE = false;

function js_Athan()
{
	var date = new Date();	
	var hrs = date.getHours();
	var mint = date.getMinutes();
	var yr =  date.getYear();
	var _now = $("#now").val();
	var _ampm = "";
	
	if(hrs > 12)
	 {
		hrs = hrs - 12;
		_ampm = " pm";
	 }
	 else
	 
	 
	if(hrs == 0) 
	{
	  hrs = 12;
	  _ampm = " am";	 
	}
	
	if(mint < 10)
	 {
		mint = "0" + mint; 
	 }
	 
	var _athan = hrs + ":" + mint + _ampm;

	$('*[name=athan]').each(function()
									{ 
										if($(this).val() == _athan)
										 {
												if(_athanEXE == false)
												{
													_athanEXE = true;
													$("#divAthan").dialog("open");
													$("#divAthan").dialog('option', 'title', $(this).attr("id") + " Athan");
													$("#divAthan").append('<embed src="./audio/Athan.mp3" autostart="true" loop="false" hidden="true" style="position: fixed"><p>Time to Pray ...</p>');
												}
										 }
									});
}

function js_AddChild(_mode)
{
	
	var _remove = "<img src='./images/remove.png' width='30' height='15' onclick='$(this).parent().parent().remove(); maxRows--;' />";
	switch(_mode)
	{
		case "membership":
		var _row = "<tr><td width='1%'>" + _remove + "</td>";
						_row +="<td width='50%'><input type='text' id='CHILD' name='field' class='ui-state-active'></td>";
						_row +="<td width='50%'><input type='text' id='AGE' name='field' class='ui-state-active'></td>";
					_row +="</tr>";
		break;
		
		case "school":
			var _row = "<tr><td width='1%'>" + _remove + "</td>";
							_row +="<td><input type='text' size='10'></td>";
							_row +="<td><input type='text' size='6'></td>";
							_row +="<td><input type='text' size='9'></td>";
							_row +="<td><input type='text' size='9'></td>";
							_row +="<td><input type='text' size='9'></td>";
						_row +="</tr>";
		break;
	}
	if(maxRows >= 10)
	 {
		 alert("You have reached the maximum allowed number of rows.");
	 }
	else
	 {
		 maxRows++;
		$('#CHILD_LIST tr:last').after(_row);	 
	 }
}

function js_ToggleOther(_oca)
{
	if(_oca == "Other")
	{
		$("#OCCASION_SPAN").show();
	}
	else
	{
		$("#OCCASION_SPAN").hides();
	} 
}

function js_SubmitForm(_mode)
{
	var params = "";
	$('*[name=field]').each(function()
									{
										if($(this).val().length == 0 && $(this).hasClass('required'))
										 {
											__AJAXERROR = true; 
											$(this).addClass("ui-state-error");
											$("#status").html("Missing field is highlighted in red");
											return false;
										 }

											__AJAXERROR = false; 
											if(params.length == 0)
											 {
												// Create the first parameter
												params = $(this).attr('id') + "=" + $(this).val();	  
											 }
											else
											 {
												// Concat the next item in the loop to the parameter 
												params += "&" + $(this).attr('id') + "=" + $(this).val();	 
											 }
									});

		if(__AJAXERROR)
		 {
			return false; 
		 }
		
		params += "&FORM=" + _mode;
		$("#status").html("Please wait ...");
		//$("#status").load("./includes/submit.php?emailbody=" + encodeURI(_emailbody));	

	var _SUBMIT = $.ajax({
					  		// Define ajax url
							url: "./includes/submit.php", 
							
							// Define ajax method
							type: "POST",
							
							// Prevent caching
							cache: false,
							
							// Pass paramaters to ajax object
							data: params,
							
							// Execute when ajax call was successful
							success: function(ajax)
										{
											$("#status").html(ajax);
											$("input[type=text]").val("");
										},
							// Execute when ajax call failed
							error: function(ajax)
										{
											//alert(ajax.responseText);
											//$('#invitations').html(ajax.responseText);
											$("#status").html(ajax.responseText);	
										}
					});

}

function js_LoadPrayerTime(_month)
{
	var params = "month=" + _month + "&SID=" + Math.random();
	var _SUBMIT = $.ajax({
					  		// Define ajax url
							url: "./includes/services-2.php", 
							
							// Define ajax method
							type: "POST",
							
							// Prevent caching
							cache: false,
							
							// Pass paramaters to ajax object
							data: params,
							
							// Execute when ajax call was successful
							success: function(ajax)
										{
											$("#workspace").html(ajax);
										},
							// Execute when ajax call failed
							error: function(ajax)
										{
											//alert(ajax.responseText);
											//$('#invitations').html(ajax.responseText);
											$("#workspace").html(ajax.responseText);	
										}
					});
	
}
