// delete records
function deleteconfirm(url){
	if(confirm("Are you sure to delete this record")){
		window.location=url;
		return true;
	}else return false;
}

//change the status of the order
function changestatus(url){
	if(confirm("Are you sure to change the status of this record")){
			window.location =url;
	}else return false;
}

//approve order
function approveorder(url){
	if(confirm("Are you sure to approve this user")){
			window.location =url;
	}else return false;
}

//approve order
function approvecomment(url){
	if(confirm("Are you sure to approve this comment")){
			window.location =url;
	}else return false;
}

/*********************************************/

function showcontent(id,smalldesc){
	if($("#"+id).css('display')=="none"){
		$("#"+smalldesc).hide('slow');
		$("#"+id).show('slow');
	}else{
		$("#"+smalldesc).show('slow');
		$("#"+id).hide('slow');
	}
}

function showcommitteememberdetails(uId){ 
	if(!uId){
		var Id = $("#committeemembers_userId").val();
	}
	else{
		Id =uId;
	}
	
	if(Id != "") { 
		$.post("ajaxpage.php",{action:'showmemberdetails',Id:Id,rand:Math.random() } ,function(data){   
		 
				$("#memberinfo").html(data);  
		});
	}else{
		alert("Please select a member");
		return false;
	}
}

	function showallcontacts(pageno)

	{

		//var group_id = $('select.group').val();   

		var group_id =$("#group").val();

		var chkall =$("#chkall").val();

		var page=1;

		if(pageno) page=pageno;

 //alert("kk=="+group_id);

		if(group_id)

		{

			$.post("ajaxpage.php",{action:'getallcontacts',group_id:group_id,chkall:chkall,page:page,rand:Math.random() } ,function(data){   

					$("#contactsContainer").html(data);

			});

		}

		else

		{

			alert("Please choose a group");

			return false;

		}

	}

	

	function addtocontactscontainer(groupuserId,groupId)

	{

			var mailuserId =$("#mailuserId").val();

			lines = mailuserId.split("~"); 

 			

			lines = jQuery.unique(lines);

			lines.sort();

			var flag =0;

			for(var i in lines) {

			  if(lines[i]==groupuserId)

			  {

				  flag=1;

			  }

			}

			//alert("dddddddddddd"+flag);

			if(flag==0)

			{

				$.post("ajaxpage.php",{action:'addtomailqueue',group_id:groupId,groupuserId:groupuserId,mailuserId:mailuserId,rand:Math.random() } ,function(data){   

						$("#mailqueueContainer").append(data);

						$("#mailuserId").attr('value', mailuserId+groupuserId+"~");

						 

				});

			}	

	}

	function selectallusers(groupId)

	{

		var chkall =$("#chkall").val();

		 if ($('#chkall').attr('checked')) {

			$("#InnserFadescrren").show();

			$.post("ajaxpage.php",{action:'addalluserstomailqueue',group_id:groupId,rand:Math.random() } ,function(data){   

					$("#mailqueueContainer").html(data);

					$("#InnserFadescrren").hide('slow');

 					$('#contactsList :checkbox').attr('disabled', true);

 					$('#contactsList :checkbox').attr('checked', false);

					 

			});

		 }

		 else

		 {

					$("#mailqueueContainer").html("");

 					$('#contactsList :checkbox').attr('disabled', false);

		 }

	}

	

	function validate_Bulkmailfrm()

	{ 

	 	if($("#mailuserId").val()=='' &&  $("#mailgroupId").val()=='' )

		{

			alert("Please select contacts");	

			return false;

		}

		else if($("#subject").val()=='')

		{

			alert("Please enter subject");	

			return false;

		}/*else if($("#contents").val()=='' )

		{

			alert("Please enter messge");	

			return false;

		}*/

		else

		{

			return true;

		}

	}
	
	
	//do user search
	function searchuser(url)
	{
		var str = $("#search").val();
		if(!str){
			alert("Please enter a string");
			return false;
		}else
		{
			window.location = url+"&search="+str;	
		}
	}

function showvideotype(type,id)
{
	var vtype ='';
	if(type)
	{
		vtype = type;
	}
	else
	{
		vtype = $("#video_type").val();
	}
	if(vtype=="")
	{
		alert("Please choose video type");
		return false;
	}
	else
	{
		$.post("ajax.php",{action:'video',id:id,type:vtype,rand:Math.random() } ,function(data){   
 
				$("#videocontainer").html(data);
	
		});
	}
}
function showvideos(id)
{
	var cur_stus;
	$(".videocls").hide('slow');
	$("#videos_"+id).attr('stus', '');
	$.post("ajax.php",{action:'showvideo',id:id,rand:Math.random() } ,function(data){   
 
			$("#videos_"+id).show();
			$("#videos_"+id).slideDown();
			$("#videos_"+id).attr('stus', 'active');
			$("#videos_"+id).html(data);

	});
	
}

function showadsdata(type,id){ 
	if(!type){
		var type = $("#ads_type").val();
	}
	 
		 
	
	if(type != "") { 
		 if(type=="text")
		 { 
			 $("#textadscontainer").css('display', 'block');
			  $("#imgadscontainer").css('display', 'none');
		 }else
		 {
			 $("#imgadscontainer").show();
			  $("#textadscontainer").hide(); 
		 }
 	}else{
		alert("Please select a type");
		return false;
	}
}
/************************** election ***************************/
function ListallUsers(id,resId){
	var serachstr = $('#'+id).val();
	if(serachstr)
	{
		$('#lightbox-shadow').show();	
		$.post("ajax.php",{action:'listallusers',serachstr:serachstr,rand:Math.random() } ,function(data){   
	 
				$("#"+resId).html(data);
				$('#lightbox-shadow').hide();
 		});
	
	}
	else
	{
		alert("Please enter a search string");
		return false;
	}
}

function addCandidates(Id,electionId)
{
	var realvalues = [];
 	var flag=0;
	$('#usersList_'+Id+' :selected').each(function(i, selected) {
		realvalues[i] = $(selected).val(); 
 		  flag=1;
	});	
	if(flag==0)
	{
		alert("Please choose candidates for the position");
		return false;
 	}
	else
	{	$('#lightbox-shadow').show(); 
		$.post("ajax.php",{action:'addCandidates',postionId:Id,'candidates[]':realvalues,electionId:electionId,rand:Math.random() } ,function(data){   
 
				$("#candidatesList_"+Id).html(data);
				$('#lightbox-shadow').hide();
 		});
	}
}

function removeCandidates(Id,electionId)
{
	var realvalues = [];
 	var flag=0;
	$('#candidatesList_'+Id+' :selected').each(function(i, selected) {
		realvalues[i] = $(selected).val(); 
 		  flag=1;
	});	
	if(flag==0)
	{
		alert("Please choose candidates  ");
		return false;
 	}
	else
	{	$('#lightbox-shadow').show(); 
		$.post("ajax.php",{action:'removeCandidates',postionId:Id,'candidates[]':realvalues,electionId:electionId,rand:Math.random() } ,function(data){   
 
				$("#candidatesList_"+Id).html(data);
				$('#lightbox-shadow').hide();
 		});
	}
}


function addCommitteeCandidates(Id,electionId,committeeId)
{
	var realvalues = [];
 	var flag=0;
	$('#usersList_'+Id+' :selected').each(function(i, selected) {
		realvalues[i] = $(selected).val(); 
 		  flag=1;
	});	
	if(flag==0)
	{
		alert("Please choose candidates for the position");
		return false;
 	}
	else
	{	$('#lightbox-shadow').show(); 
		$.post("ajax.php",{action:'addCommitteeCandidates',postionId:Id,'candidates[]':realvalues,electionId:electionId,committeeId:committeeId,rand:Math.random() } ,function(data){   
 
				$("#candidatesList_"+Id).html(data);
				$('#lightbox-shadow').hide();
 		});
	}
}

function removeCandidatesfrmCommittee(Id,electionId,committeeId)
{
	var realvalues = [];
 	var flag=0;
	$('#candidatesList_'+Id+' :selected').each(function(i, selected) {
		realvalues[i] = $(selected).val(); 
 		  flag=1;
	});	
	if(flag==0)
	{
		alert("Please choose candidates  ");
		return false;
 	}
	else
	{	$('#lightbox-shadow').show(); 
		$.post("ajax.php",{action:'removeCandidatesfrmCommittee',postionId:Id,'candidates[]':realvalues,electionId:electionId,committeeId:committeeId,rand:Math.random() } ,function(data){   
 
				$("#candidatesList_"+Id).html(data);
				$('#lightbox-shadow').hide();
 		});
	}
}

function searchdowMembers()
{
	var membership = $('#membership').val();
	var searchstr = $('#searchstr').val();
	
	window.location= 'user_management.php?searchstr='+searchstr+'&membership='+membership;
}

