// JavaScript Document
function getAjaxPagination(startPage,currentUrl)
{
$('#displayAjaxFile').block('Loading...');
	$.ajax({
		type: 'POST',
		url: currentUrl+startPage,
		dataType: 'json',		
		success: function(response){
			$('#displayAjaxFile').unblock();
			$('#displayAjaxFile').html(response.msg);
		}
		});
	
}

function isValidUrl(url)
{

	var regUrl = /^(http[s]?:\/\/|http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([a-zA-Z0-9\-]+)(\.[a-zA-Z]+){1,2}$/;
	return regUrl.test($.trim(url));
}

function checkall()
{
     $("input:checkbox").each(function(){
         this.checked = true;
      });
} 

function noneCheckBoxes()
{
     var chkval;
$('#chkvalId').val(0);
$("input:checkbox").each(function(){
         this.checked = false;
     $('#chkvalId').val($('#chkvalId').val()+","+this.value);
});
} 


 function calculateDays(prefix, extra, me)
{
	//if(me.name == prefix + 'Day')
		//return ;

	var dayElement		= '#' + prefix + 'Day';
	var monthElement	= '#' + prefix + 'Month';
	var yearElement		= '#' + prefix + 'Year';	

	var monthSelected	= parseInt($(monthElement).val() * 1);
	var daySelected		= parseInt($(dayElement).val() * 1);
	var yearSelected	= parseInt($(yearElement).val() * 1);

	if(monthSelected > 0)
	{
		if(extra == 1)
			$(dayElement)[0].options.length = 1;
		else
			$(dayElement)[0].options.length = 0;

		for(var i=1;i <= 31; i++)
		{
			if(i < 10)
				var dateText = '0' + i.toString();
			else
				var dateText = i;

			$(dayElement)[0].options[i - 1 + extra] = new Option(dateText, i);

			if(daySelected == i)
				$(dayElement)[0].options[i - 1 + extra].selected = true;

		}

		if(monthSelected == 2)
		{
			if(isLeapYear(yearSelected))
			{
				$(dayElement)[0].options.length = 30 - 1 + extra;
			}
			else
			{
				$(dayElement)[0].options.length = 29 - 1 + extra;
			}
		}
		else
		{	
			if(monthSelected == 1 || monthSelected == 3 || monthSelected == 5 || monthSelected == 7 || monthSelected == 8 || monthSelected == 10 || monthSelected == 12)
			{
				$(dayElement)[0].options.length = 32 - 1 + extra;
			}
			else
			{
				$(dayElement)[0].options.length = 31 - 1 + extra;
			}
		}
	}


}

function isLeapYear(Year)
{
	if((Year % 4) == 0)
	{
		// It is exactly divisible by 4
		if ( (Year % 100) == 0)
		{
			// It is exactly divisible by 100
			// Is it also exactly divisible by 400?
			Result = ((Year % 400) == 0);
		}
		else
		{
			Result = 1;
		}
	}
	else
	{
		// It is not exactly divisible by 4
		// It is not a leap year
		Result = 0;
	}

	return Result;
}


/*$(document).ready(function(){


$().ajaxSuccess(function(event, request, settings){
	if(request.getResponseHeader("Login-Status") == 'relogin')
	{
		window.location.href = base_url + 'login';
	}
});

$().ajaxError(function(event, request, settings){//alert(event);alert(request.response); alert(settings); return false;
	if(request.getResponseHeader("Login-Status") == 'relogin')
	{
		window.location.href = base_url + 'login';
	}
	});

});*/


function suggest()
{
	if($('#message_suggest').val()!=improve_tag)
		var message	=	$('#message_suggest').val();
	else
		var message	=	'';
	$('#feedbackcontent').block('Loading...'); 
	$.ajax({
		type: 'POST',
		url: base_url + 'welcome/reportSuggestion',
		dataType: 'json',
		data: 'message='+message,
		success: function(response){
				$('#feedbackcontent').unblock(); 
				if(response.msg=='error')
				{
					$('#SuggestionErrorMsg').show('normal', function(){
						setTimeout(function() {
							$('#SuggestionErrorMsg').fadeOut('slow');
						}, 5000);
					});
					var result	=	'';				
					for( var i =0; i<response.msgInfo.length; i++) 
					{					
						result=result+response.msgInfo[i]+'<br>';
					}
					$('#SuggestionErrorInfo').html(result);
				}
				else if(response.msg=='success')
				{
					$('#message_suggest').val('');
					$('#SuggestionsucessMsg').html(response.msgInfo);
					$('#suggestsucsResultsMsg').show('normal', function(){
						setTimeout(function() {
							$('#suggestsucsResultsMsg').fadeOut('slow');
						}, 5000);
					});
				}
				
		}
	})

}

function addFriendsAjax(userId)
{
	var	msg		=	$('#hdn_friend_message_'+userId).val();
	$('#scsd_'+userId).block();
	$.ajax({
		  type : 'POST',
		  url  : base_url+'friends/addFriend/',
		  dataType : 'json',
		  data : 'hdn_friend_id='+userId+'&hdn_friend_message='+msg+'&sentBy=ajaxx',
		  success: function(response)
		  {
			 $('#scsd_'+userId).unblock();
			 $('#row_'+userId).hide();
			  $('#succInfo'+userId).html(response);
			  $('#comnMsg_addFriend_'+userId).show();
			  $('#comnMsg_addFriend_'+userId).fadeOut(9000);
		  }
		  });
}

function removeFriendAjax(userId)
{
	$('#scsd_'+userId).block();
	$.ajax({
		   type : 'POST',
		   url : base_url+'friends/removefriend/',
		   dataType : 'json',
		   data : 'hdn_friend_id='+userId+'&sentBy=ajaxx',
		   success : function (response)
		   {
				 $('#scsd_'+userId).unblock();
				$('#remove_row_'+userId).hide();
				if(response.msg == 'success')
				{
					$('#hideaddFriendquick_'+userId).hide();
					$('#ShowaddFriendquick_'+userId).show();
					$('#hideRemoveFriendQuick_'+userId).hide();
				}
				$('#succInfo'+userId).html(response.result);
				$('#comnMsg_addFriend_'+userId).show();
				$('#comnMsg_addFriend_'+userId).fadeOut(9000);
		   }
		   });
}

// added by jagan for blocking hte notify box
function blockNotifyBox(notify_id,module)
{
	$('#notify_Div').block();
	$.ajax({
		   type : 'POST',
		   url:base_url+'privacy/changeNotifyMessage/'+module,
		   dataType: 'json',
		   data : 'id='+notify_id,
		   success : function (response)
		   {
				if(response.msg == 'success')
				{
					$('#notify_Div').html(response.tpl);
				}
		   }
		   });
}
