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 showHide(id, sh)
{
	
	if(sh == 'show')
	{
		$('#' + id + 'Change').hide();
		$('#' + id + 'Hide').show();
		$('#' + id + 'Header').hide();
		$('#' + id + 'Content').hide();
		$('#' + id).show('slow');
	}
	else
	{
		$('#' + id + 'Change').show();
		$('#' + id + 'Hide').hide();
		$('#' + id).hide('slow');
		$('#' + id + 'Header').show();
		$('#' + id + 'Content').show();
	}
}
function addmemberMission(receiverid,userId,status)
{
	
	if(status == false)
	{
		return;
	}
	var ids = 	$('#ids').val();
	//var message		=	$('#message').val();
	document.getElementById(receiverid).disabled=true;
	$.ajax({
		type: 'POST',
		dataType: 'json',
		url: base_url + 'missions/addmemberMission',
		data: 'receiverid='+receiverid+'&userId='+userId,
		success: function(response){				
			//$('#invitediv').html(response.inviteescount);
			$('#inviteesdiv').html(response.invitemission2);	
			$('#ids').val(response.inviteids);
			//showaddedMembers($('group_id').val());
		}
	});	 
}

function removememberMission(receiverid,userId,status)
{
	
	if(status == false)
	{
		return;
	}
	var ids 		= 	$('#ids').val();
	//var message		=	$('#message').val();
	document.getElementById(receiverid).disabled=false;
	document.getElementById(receiverid).checked=false;
	$.ajax({
		type: 'POST',
		dataType: 'json',
		url: base_url + 'missions/removememberMission',
		data: 'receiverid='+receiverid+'&userId='+userId,
		success: function(response){			
			//$('#invitediv').html(response.inviteescount);
			$('#inviteesdiv').html(response.invitemission2);
			$('#ids').val(response.inviteids);
			//showaddedMembers($('group_id').val());
		}
	});	 
}


function showLoginDiv()
{
	if(document.getElementById('loginDiv').style.display == 'none')
		document.getElementById('loginDiv').style.display = '';
	else
		document.getElementById('loginDiv').style.display='none';
	
}

// Code added by Prawez

function showForm()
{
	tb_show('', '#TB_inline?height=390&width=580&modal=true&inlineId=removeFriendDiv', false);
}

function validateBeenPegged()
{
	
	var reg = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	if($('#userName').val() == '')	
	{
		$('#beenPeggedInfo').html('Please enter your name.');
		$('#beenPegged').show('normal', function(){
			setTimeout(function(){
				$('#beenPegged').fadeOut('slow');
			}, 2000)									   
		});
		//alert("Please enter your name.");		
		$('#userName').focus();
		return false;
	}
	else if($('#userEmail').val() == '')
	{
		$('#beenPeggedInfo').html('Please enter your email.');
		$('#beenPegged').show('normal', function(){
			setTimeout(function(){
				$('#beenPegged').fadeOut('slow');
			}, 2000)									   
		});
		//alert("Please enter your email.");		
		$('#userEmail').focus();
		return false;
	}
	else if(!(reg.test($('#userEmail').val())))
	{
		$('#beenPeggedInfo').html('Please enter valid email.');
		$('#beenPegged').show('normal', function(){
			setTimeout(function(){
				$('#beenPegged').fadeOut('slow');
			}, 2000)									   
		});
		//alert("Please enter valid email.");		
		$('#userEmail').focus();
		return false;
	}
	else if($('#userWhere').val() == '')
	{
		$('#beenPeggedInfo').html('Please enter your location.');
		$('#beenPegged').show('normal', function(){
			setTimeout(function(){
				$('#beenPegged').fadeOut('slow');
			}, 2000)									   
		});
		//alert("Please enter your location.");		
		$('#userWhere').focus();
		return false;
	}
	else if($('#userComments').val() == '')
	{
		$('#beenPeggedInfo').html('Please enter your comments.');
		$('#beenPegged').show('normal', function(){
			setTimeout(function(){
				$('#beenPegged').fadeOut('slow');
			}, 2000)									   
		});
		//alert("Please enter your comments.");		
		$('#userComments').focus();
		return false;
	}
	else
	{	
		var str = '';
		/*if(document.getElementById('contactPreference').checked == true)
		{
				str =  'Y';
		}
		else
		{
			str =  'N';
		}*/
		
		$.ajax({ 
			type: 'POST',
			dataType: 'json',
			url: base_url + 'home/saveComment/',
			data: 'comment_submit=1' + '&userName=' + $('#userName').val() + '&userEmail=' + $('#userEmail').val() + '&userWhere=' + $('#userWhere').val() + '&userComments=' + $('#userComments').val(),
			success: function(response){
				if(response.msg == 'Success')
				{
					$('#userName').val('');
					$('#userEmail').val('');
					$('#userWhere').val('');
					$('#userComments').val('');
					$('#paggedComntAjx').html(response.strrpt);
					$('#paggedComnt').hide();
					$('#paggedComntAjx').show();
					
					/*tb_remove();
					setTimeout("tb_show('', '#TB_inline?height=400&width=560&modal=true&inlineId=testdiv', false)", 1500);*/
				}
			},
			error: function(e){  
				alert('Error: ' + e);  
			 }
		});	 
		return false;
	}
}

// Function show comments on index page
function showComments()
{
	$.ajax({
		type: 'POST',
		url: base_url + 'home/showComments/',
		success: function(response){			
			if(response)
			{
				$('#divShowComment').html(response);
			}
		},
		error: function(e){  
			alert('Error: ' + e);  
		 }
	});	 
}

// Report Abuse
function reportAbuse(rowId)
{
	if(confirm('Are you sure?'))
	{
		$.ajax({
			type: 'POST',
			url: base_url + 'home/reportAbuse/',
			data: 'submit_abuse=1&rowId=' + rowId,
			success: function(response){			
				if(response)
				{
					$('#abuseMsg'+rowId).html(response);
					$('#abuseDiv'+rowId).show('normal', function(){
						setTimeout(function(){
							$('#abuseDiv'+rowId).fadeOut('slow');
						}, 2000)									   
					});
				}
			},
			error: function(e){  
				alert('Error: ' + e);  
			 }
		});	
	}
}

//set max length of textarea
function setmaxlen(str, MaxLen)
{
	var len = str.length;
	if (navigator.userAgent.indexOf("MSIE")>=0)
	{ 
		if(len >= MaxLen)
		return false;
	}
	else
	{
		if(len > MaxLen)
		return false;
	}
}

function char_count(str, MaxLen, divid, elementId, msg)
{
	var len = str.length;
	var leftlen = MaxLen - len;
	if(leftlen <= 0)
	{
		document.getElementById(elementId).value = str.substring(0,MaxLen);
		leftlen=0;
	}	
	document.getElementById(divid).innerHTML=leftlen;
}
function showUploadFrof(picId)
{
	
	imageProfId='imageProfId'+picId;
	tb_show('', '#TB_inline?height=440&width=530&modal=true&inlineId='+imageProfId, false);
}
// for community purpose
function validForm()
{
	
	if($('#threadName').val() == '')
	{
		$('#thMsg').html("Please Enter Thread Name.");
					$('#creatThrd').show('normal', function(){
						setTimeout(function(){
							$('#creatThrd').fadeOut('slow');
						}, 2000)									   
					});
		$('#threadName').focus();
		
		return false;
	}
	/*if($('#elm1').val() == '')
	{
		$('#creatThrd').html("Please Enter Thread Message.");
					$('#creatThrd').show('normal', function(){
						setTimeout(function(){
							$('#creatThrd').fadeOut('slow');
						}, 2000)									   
					});
		$('#elm1').focus();
		return false;
	}*/

}
function isdeleteCommnet(url)
{
	if(str=confirm("Are you sure?"))
	{
		window.location.href=url;
	}
	else
	{
		return false;
	}
}
function validCommThrd()
{
	/*if(document.getElementById('elm1thrd').value == '')
	{
		$('#threadMsg').html("Please Enter Thread Comment.");
					$('#thrdCommnt').show('normal', function(){
						setTimeout(function(){
							$('#thrdCommnt').fadeOut('slow');
						}, 2000)									   
					});
		window.reload();
		return false;
	}*/
}
function deleteThrdComment(thrdCmntId)
{
	if(str=confirm('Are you sure?'))
	{
		window.location.href=thrdCmntId;
	}
	else
	{
		return false;
	}
}
function telMateFrndbeforeLogin()
{
	if($('#fromEmail').val()=='')
	{
		alert("Please write your mail");
		$('#fromEmail').focus();
		return false;
	}
	if($('#fromEmail').val()!='')
	{
		if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($('#fromEmail').val())))
		{
			alert("Please enter a valid Email address!");
			$('#fromEmail').focus();
			return false;
		}
	}
	if($('#txt_invitation_to').val() =='')
	{
		alert("Please write your friend mail");
		$('#txt_invitation_to').focus();
		return false;
	}
	if($('#txt_invitation_to').val() !='')
	{
		email=$('#txt_invitation_to').val();
		var emailId=email.split(',');
		if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailId[0])))
		{
			alert("Please enter a valid Email address!");
			$('#txt_invitation_to').focus();
			return false;
		}
		if(emailId[0])
		{
			if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailId[0])))
			{
				alert("Please enter a valid Email address!");
				$('#txt_invitation_to').focus();
				return false;
			}
		}
		if(emailId[1])
		{
			if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailId[1])))
			{
				alert("Please enter a valid Email address!");
				$('#txt_invitation_to').focus();
				return false;
			}
		}
		if(emailId[3])
		{
			if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailId[3])))
			{
				alert("Please enter a valid Email address!");
				$('#txt_invitation_to').focus();
				return false;
			}
		}
	}
	$.ajax({
		   type:'POST',
		   url: base_url+'home/inviteTellfrnd',
		   dataType:'json',
		   data:'submitTell=1&inviteTo='+$('#txt_invitation_to').val()+'&inviteFrom='+$('#fromEmail').val()+'&message='+$('#txt_invitation_message').val(),
		   success:function(response){
			   $('#resultMsg').html(response.msg);
			   $('#comnMsg').show();
			   if(response.error)
			   {
				   $('#txt_invitation_to').val('');
				   $('#fromEmail').val('');
				   $('#txt_invitation_message').val('');
			   }
		   }
		  });
	
}

function setUserAlertTab()
{
	$.ajax({
		   type:'POST',
		   url: base_url+'welcome/setUserAlertTab',
		   dataType:'json',
		   success:function(response){
			 	 
				 $('ul#alertTab_notificationList').html(response.alertTab_notificationList);
				 if(parseInt(response.alertTab_notificationCount) > 0)
				 {
					 $('div#alertTab_notificationCount').text(response.alertTab_notificationCount);
					 $('div#alertTab_notificationCount').show();
				 }
				 else
				 {
					 $('div#alertTab_notificationCount').empty();
					 $('div#alertTab_notificationCount').hide();
				 }
			 	 if(parseInt(response.alertTab_newFrndReqCount) > 0)
				 {
					 $('div#alertTab_newFrndReqCount').text(response.alertTab_newFrndReqCount);
					 $('div#alertTab_newFrndReqCount').show();
				 }
			 	 if(parseInt(response.alertTab_newMailCount) > 0)
				 {
					 $('div#alertTab_newMailCount').text(response.alertTab_newMailCount);
					 $('div#alertTab_newMailCount').show();
				 }
			   }
		  });
}

function getOnlineFriendsAlertTab()
{
	$.ajax({
		   type:'POST',
		   url: base_url+'profile/getOnlineFriendsAlertTab',
		   dataType:'json',
		   success:function(response)
		   {
			 	 if(parseInt(response.alertTab_onlineFrndCount) > 0)
				 {
					 $('div#alertTab_onlineFrndCount').text(response.alertTab_onlineFrndCount);
					 $('div#alertTab_onlineFrndCount').show();
				 }
			 	 if(response.alertTab_onlineFrndList != '' )
				 {
					 $('ul#alertTab_onlineFrndList').html(response.alertTab_onlineFrndList);
				 }
			   }
		  });
	
}

function getWaitApprAlertTab()
{
	$.ajax({
		   type:'POST',
		   url: base_url+'missions/getWaitApprAlertTab',
		   dataType:'json',
		   success:function(response)
		   {
			 	 if(parseInt(response.alertTab_waitApprCount) > 0)
				 {
					 $('div#alertTab_waitApprCount').text(response.alertTab_waitApprCount);
					 $('div#alertTab_waitApprCount').show();
				 }
			 	 if(response.alertTab_waitApprList != '' )
				 {
					 $('ul#alertTab_waitApprList').html(response.alertTab_waitApprList);
				 }
			   }
		  });
}

function setEntriesId( img,mission_id )
{
	createCookie('img', img , 1 );
	createCookie('mission_id', mission_id , 1 );
}

function createCookie(name, value, days)
{
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
    }
  else var expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
  var ca = document.cookie.split(';');
  var nameEQ = name + "=";
  for(var i=0; i < ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1, c.length); //delete spaces
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
  return null;
}

function eraseCookie(name)
{
  createCookie(name, "", -1);
}

// following function for change css
function changeStyleOver( divId )
{
	$('#'+divId).removeClass('notification');
	$('#'+divId).addClass('notificationHover');
}

function changeStyleOut( divId )
{
	$('#'+divId).removeClass('notificationHover');
	$('#'+divId).addClass('notification');
}
//code added by prawez

// function autocomplete mission tag
// Auto complite div start
/*$(document).ready(function() {
	if(autoComplete)
	{ 
		$("#mission_tags").autocomplete(
			base_url + 'mission/getTags',
			{
				id: 'autoCompleteDiv',
				dataType: 'json',
				delay:10,
				minChars:2,
				matchSubset:1,
				matchContains:1,
				cacheLength:10,
				resultsClass: 'autocompleteResults',
				onItemSelect:selectItem,
				onFindValue:findValue,
				formatItem:formatItem,
				autoFill:true
			}
		);
	}
});


function findValue(li)
{
	if( li == null ) return alert("No match!");

	if( !!li.extra ) 
		var sValue = li.extra[0];
	else 
		var sValue = li.selectValue;

	//$('#to_id').val(sValue);
}


function selectItem(li) 
{
	//$('#subject').focus();
	findValue(li);
}

function formatItem(row) 
{
	return row[0];
}*/




