function JQSelectAll()
{
	$("#selectall").click(selectAll);	
}

// This function will get called every time someone clicks on the selectall checkbox

function selectAll()

{

    // this line determines if the selectall checkbox is checked or not.  The attr()

    // function, discussed in a future article, simply returns an attribute on the

    // given object.  In this case, it returns a boolean if true, or an undefined if

    // it's not checked.

    var checked = $("#selectall").attr("checked");

    // Now we use the jQuery selection syntax to find all the checkboxes on the page

    // with the selectable class added to them (each row's checkbox).  We get an array

    // of results back from this selection, and we can iterate through them using the

    // each() function, letting us work with each result one at a time.  Inside the

    // each() function, we can use the $(this) variable to reference each individual

    // result.  Thus, inside each loop, it finds the value of each checkbox and matches

    // it to the selectall checkbox.


    $(".selectable").each(function(){

       var subChecked = $(this).attr("checked");

       if (subChecked != checked)

          $(this).click();

    });

}


/* ////////////// DELETE CHECKED RECORDS */

$(document).ready(function() {

	// hide processing div

	$('#processing').hide();

		

});





// 

function delmail(id, type) {

	var emails_to_del = "", count = 0, word;

	

	// load checked emails to string separated by | and count them

	$( "#" + id + " :checkbox:checked").each(function() {

		emails_to_del+=$(this).val()+"|";

		count+=1;

	});



	// CHECK IF ANY MAILS ARE SELECTED AND CONSTRUT THE QUESTION

	if (count == 0) { alert('No records are selected'); return false;}

	if (count == 1) { word = 'selected record ?'; count = ''}

	if (count > 1) { word = 'selected records ?';}



	if (confirm('Do your really want to remove '+count+' '+word) ) {



		// show processing dialog

		$('#processing').fadeIn(500);



		$.post("delete.php", {

			action: type, cat: id, emails: emails_to_del }, function(response){

			var response = eval('(' + response + ')');

			// error

			if (response.error != '') {alert(response.error);}

			// else remove checked e-mails

			else {

				var trid = "";

				$( "#" + id + " :checkbox:checked").each(function(){

					trid="tr_"+$(this).val();

				$("#"+trid).remove();

				

				})

			}



		$('#processing').fadeOut(500);



		});

	}

}

// ***



// common add2group function

function Add2Group(id, type) {

	var emails_to_del = "", count = 0, word;

	

	// load checked emails to string separated by | and count them

	$( "#" + id + " :checkbox:checked").each(function() {

		emails_to_del+=$(this).val()+"|";

		count+=1;

	});



	// CHECK IF ANY MAILS ARE SELECTED AND CONSTRUT THE QUESTION

	if (count == 0) { alert('No records are selected'); return false;}

	if (count == 1) { word = 'selected record ?'; count = ''}

	if (count > 1) { word = 'selected records ?';}



	window.open('addtogroup.php?ids='+emails_to_del+'&type='+type, '199',"width=400 height=400 resizeable=yes menubar=no scrollbars=yes toolbar=no");		

		

}





// send news letter

function SendNewsLetter(id, type) {

	var emails_to_del = "", count = 0, word;

	

	// load checked emails to string separated by | and count them

	$( "#" + id + " :checkbox:checked").each(function() {

		emails_to_del+=$(this).val()+"|";

		count+=1;

	});



	// CHECK IF ANY MAILS ARE SELECTED AND CONSTRUT THE QUESTION

	if (count == 0) { alert('No records are selected'); return false;}

	if (count == 1) { word = 'selected record ?'; count = ''}

	if (count > 1) { word = 'selected records ?';}



	window.open('send_template.php?ids='+emails_to_del+'&type='+type, '209',"width=800 height=600 resizeable=yes menubar=no scrollbars=yes toolbar=no");		

		

}



// send news letter

function SendClientNewsLetter(id, type) {
	var emails_to_del = "", count = 0, word;

	// load checked emails to string separated by | and count them

	$( "#" + id + " :checkbox:checked").each(function() {

		emails_to_del+=$(this).val()+"|";
		count+=1;

	});
	// CHECK IF ANY MAILS ARE SELECTED AND CONSTRUT THE QUESTION

	if (count == 0) { alert('No records are selected'); return false;}
	if (count == 1) { word = 'selected record ?'; count = ''}
	if (count > 1) { word = 'selected records ?';}
	window.open('send_template.php?ids='+emails_to_del+'&type='+type, '199',"width=800 height=600 resizeable=yes menubar=no scrollbars=yes toolbar=no");		

//	window.open('sendclientnewsletter.php?ids='+emails_to_del+'&type='+type, '199',"width=800 height=600 resizeable=yes menubar=no scrollbars=yes toolbar=no");
}



// edit a student account

function EditStudent(id, type) {

	var emails_to_del = "", count = 0, word;

	

	// load checked emails to string separated by | and count them

	$( "#" + id + " :checkbox:checked").each(function() {

		emails_to_del+=$(this).val();

		count+=1;

	});



	// CHECK IF ANY MAILS ARE SELECTED AND CONSTRUT THE QUESTION

	if (count == 0) { alert('No records are selected'); return false;}

	//if (count == 1) { word = 'selected record ?'; count = ''}

	if (count > 1) { alert('Pls select only one record to edit!'); return false;}



	window.open('editstudent.php?ids='+emails_to_del+'&type='+type, '199',"width=800 height=600 resizeable=yes menubar=no scrollbars=yes toolbar=no");		

		

}

// This function is for edit client detail
function EditClient(id, type) {
	var emails_to_del = "", count = 0, word;
	// load checked emails to string separated by | and count them

	$( "#" + id + " :checkbox:checked").each(function() {

		emails_to_del+=$(this).val();
		count+=1;
	});

	// CHECK IF ANY MAILS ARE SELECTED AND CONSTRUT THE QUESTION

	if (count == 0) { alert('No records are selected'); return false;}
	//if (count == 1) { word = 'selected record ?'; count = ''}
	if (count > 1) { alert('Pls select only one record to edit!'); return false;}
	window.open('clientdetails.php?cl_id='+emails_to_del+'&type='+type, '199',"width=800 height=600 resizeable=yes menubar=no scrollbar=yes toolbar=no");
}

// 

function removeStudentFromGroup(id, type, groupid) {

	var emails_to_del = "", count = 0, word;

	// load checked emails to string separated by | and count them
	$( "#" + id + " :checkbox:checked").each(function() {

		emails_to_del+=$(this).val()+"|";

		count+=1;

	});

	// CHECK IF ANY MAILS ARE SELECTED AND CONSTRUT THE QUESTION

	if (count == 0) { alert('No records are selected'); return false;}

	if (count == 1) { word = 'selected record ?'; count = ''}

	if (count > 1) { word = 'selected records ?';}

	if (confirm('Do your really want to remove '+count+' '+word) ) {

		// show processing dialog

		$('#processing').fadeIn(500);

		$.post("removestudentfromgroup.php", {

			action: type, groupid: groupid, ids: emails_to_del }, function(response){

			var response = eval('(' + response + ')');

			// error

			if (response.error != '') {alert(response.error);}

			// else remove checked e-mails

			else {

				var trid = "";

				$( "#" + id + " :checkbox:checked").each(function(){

					trid="tr_"+$(this).val();

				$("#"+trid).remove();
				})
			}
		$('#processing').fadeOut(500);
		});
	}
}





// send mail to interns

function SendStEmail(id, type) {

	var emails_to_del = "", count = 0, word;

	

	// load checked emails to string separated by | and count them

	$( "#" + id + " :checkbox:checked").each(function() {

		emails_to_del+=$(this).val()+"|";

		count+=1;

	});



	// CHECK IF ANY MAILS ARE SELECTED AND CONSTRUT THE QUESTION

	if (count == 0) { alert('No records are selected'); return false;}

	if (count == 1) { word = 'selected record ?'; count = ''}

	if (count > 1) { word = 'selected records ?';}



	window.open('sendmail.php?ids='+emails_to_del+'&type='+type, '209',"width=800 height=600 resizeable=yes menubar=no scrollbars=yes toolbar=no");		

		

}





// send mail to interns

function SendToAll(type) {

	var answer = confirm('Are you sure for send mail to all!')
	if(answer == true)
	{
		window.open('sendtoall.php?type='+type, '409',"width=800 height=600 resizeable=yes menubar=no scrollbars=yes toolbar=no");
	}
		

}



function SendToAllClients(type) {

	window.open('sendtoallclients.php?type='+type, '409',"width=800 height=600 resizeable=yes menubar=no scrollbars=yes toolbar=no");		

		

}





// send mail to interns

function SendClEmail(id, type) {

	var emails_to_del = "", count = 0, word;

	

	// load checked emails to string separated by | and count them

	$( "#" + id + " :checkbox:checked").each(function() {

		emails_to_del+=$(this).val()+"|";

		count+=1;

	});



	// CHECK IF ANY MAILS ARE SELECTED AND CONSTRUT THE QUESTION

	if (count == 0) { alert('No records are selected'); return false;}

	if (count == 1) { word = 'selected record ?'; count = ''}

	if (count > 1) { word = 'selected records ?';}



	window.open('sendmailtoclient.php?ids='+emails_to_del+'&type='+type, '209',"width=800 height=600 resizeable=yes menubar=no scrollbars=yes toolbar=no");		

		

}







// add interns subscription

function AddstSubscription(id, type) {

	var emails_to_del = "", count = 0, word;

	

	// load checked emails to string separated by | and count them

	$( "#" + id + " :checkbox:checked").each(function() {

		emails_to_del+=$(this).val()+"|";

		count+=1;

	});



	// CHECK IF ANY MAILS ARE SELECTED AND CONSTRUT THE QUESTION

	if (count == 0) { alert('No records are selected'); return false;}

	if (count == 1) { word = 'selected record ?'; count = ''}

	if (count > 1) { word = 'selected records ?';}



	window.open('processinternsubscription.php?ids='+emails_to_del+'&type='+type, '209',"width=800 height=600 resizeable=yes menubar=no scrollbars=yes toolbar=no");		

		

}


// common DownloadInterns function

	function DownloadInterns(id, type) 
	{
		var emails_to_del = "", count = 0, word;

	// load checked emails to string separated by | and count them

		$( "#" + id + " :checkbox:checked").each(function() {

		emails_to_del+=$(this).val()+"|";

		count+=1;
		});
	// CHECK IF ANY MAILS ARE SELECTED AND CONSTRUT THE QUESTION

		//if (count == 0) { alert('No records are selected'); return false;}
		if (count == 1) { word = 'selected record ?'; count = ''}
		if (count > 1) { word = 'selected records ?';}

		window.open('excelexport/selectlimit.php?ids='+emails_to_del+'&type='+type, '199',"width=400 height=400 resizeable=yes menubar=no scrollbars=yes toolbar=no");
	}



// common DownloadInterns function

function DownloadGroupInterns(id) {

	window.open('excelexport/selectlimit_group.php?groupid='+id, '199',"width=400 height=400 resizeable=yes menubar=no scrollbars=yes toolbar=no");		

		

}



// add by rajan

function DownloadInternsEmp() {

	window.open('excelexport/selectlimit_emp.php', '199',"width=400 height=400 resizeable=yes menubar=no scrollbars=yes toolbar=no");		

		

}