// JavaScript Document
function movetomotivation(num_of_rows,refid)
{
	var i=0,contactids="";
	for(i=1;i<=num_of_rows;i++)
	{	
		if(document.getElementById("contacts_in_mot_list"+i).checked == true)
			if(contactids == "")
			contactids = document.getElementById("contacts_in_mot_list"+i).value;
			else
			contactids = contactids+","+document.getElementById("contacts_in_mot_list"+i).value;				   
	}
	var url = "edit_motivation_submit.php?contact_ids="+contactids+"&ref_id="+refid;
	grpload(url,'show_motivation_contacts');
}
function selectallin_motivationlist(num_of_rows)
{
	var i=0;
	if(document.getElementById("numrows_motiv_hb"))
	{
		var no_rows=document.getElementById("numrows_motiv_hb").value;
		num_of_rows=no_rows;
	}
	if(document.getElementById("selectall2").checked == true)
	{
	for(i=1;i<=num_of_rows;i++)
	document.getElementById("motivation_cb"+i).checked = true;	
	}
	else
	{
		for(i=1;i<=num_of_rows;i++)
	document.getElementById("motivation_cb"+i).checked =false;	
	}
	
	
}
function selectallin_motivationcontacts(num_of_rows)
{
	var i=0;
	//alert(num_of_rows)
	if(document.getElementById("selectall1").checked == true)
	{
	for(i=1;i<=num_of_rows;i++)
	document.getElementById("contacts_in_mot_list"+i).checked = true;	
	}
	else
	{
		for(i=1;i<=num_of_rows;i++)
	document.getElementById("contacts_in_mot_list"+i).checked =false;	
	}
	
	
}
function delete_mot_contacts(refid,num_of_rows)
{
	var check;var selected_num_of_rows=0;
	var refid_hb=document.getElementById('refid_hb').value;
	var selected_ids=0;
	if(document.getElementById("numrows_motiv_hb"))
	{
		var no_rows=document.getElementById("numrows_motiv_hb").value;
		num_of_rows=no_rows;
	}
	if(document.getElementById("selectall2").checked == true)
	{
		for(i=1;i<=num_of_rows;i++)
		{	
			if(document.getElementById("motivation_cb"+i).checked)
			{
				//alert(i+" -- "+document.getElementById("motivation_cb"+i).value)
				selected_ids=selected_ids+","+document.getElementById("motivation_cb"+i).value;	
				selected_num_of_rows++;
			}
		}
		if(num_of_rows==selected_num_of_rows)
		{
			var result=confirm("Delete All Motivation Contacts?");
			if(result)
			{
				check=1;
			}
			else
			{
				check=0;
			}
		}
		else
		{
			document.getElementById('selectedids_hb').value=selected_ids;
			check=2;
		}
	}
	else
	{
		for(i=1;i<=num_of_rows;i++)
		{	
			if(document.getElementById("motivation_cb"+i).checked)
			{
				//alert(i+" -- "+document.getElementById("motivation_cb"+i).value)
				selected_ids=selected_ids+","+document.getElementById("motivation_cb"+i).value;	
				selected_num_of_rows++;
			}
		}
		document.getElementById('selectedids_hb').value=selected_ids;
		check=2;
		//alert(selected_num_of_rows);
	}
	document.getElementById('check_status').value=check;
	if((check==1)||(check==2))
	{
		document.nc.action="delete_motivation_contacts.php";
		document.nc.submit();
		//var url="delete_motivation_contacts.php?ref_id="+refid;
		//alert("all motivation-contacts deleted");
	}
	else if(check==0)
	{
		alert("Action Cancelled");
	}
}

function show_search_result_contacts(ref_id)
{
	/*if(document.getElementById('search_contact_tb').value!="")
	{*/
		var url="motivation_search_contacts.php?ref_id="+ref_id+"&searched_name="+document.getElementById('search_contact_tb').value;
		ajaxpage(url,'show_contacts_div');
	/*}
	else
	{
		alert("Please Type A Name To Search");
	}*/
}