
function manage_all_rescom(source)
{
	var div_id = document.getElementById(source + 'proptype_scroll');
	var div_elem = div_id.getElementsByTagName('input');

	//alert(div_elem[0].checked);

	if(div_elem[0].checked == true)
	{
		for(var indx=1; indx<div_elem.length; indx++)
		{
			div_elem[indx].checked = false;
		}
		var status_msg = document.getElementById(source + 'ptype_msg');
		var res_com = document.getElementById('hidden_res_com');
		//alert(res_com.value);
		if(res_com.value=='RES')
		{
			msg = "All Residential Properties";

		}
		else
		{
			msg = "All Commercial Properties";
		}
		status_msg.innerHTML = msg;
	}
	else
	{
		//alert(div_elem[0].checked);
		div_elem[0].checked = true;
		//alert(div_elem[0].checked);
	}

}


function manage_optionlist_ajax(details,source)
{
	var div_id = details;
	if( div_id == 'proptype')
	{
		var options = document.getElementsByName(source + 'property_type[]');
		manage_checked_ajax(options,20,source);

	}
	updateSelectionMessage_ajax(details, options , source);
}


function manage_checked_ajax(chkbx_array,max_checked,source)
{
	var count = getCheckedCount_ajax(chkbx_array);
	var total_count = chkbx_array.length;

	if (!count) // if not Selected then select all one at the top
	{
		chkbx_array[0].checked = true;
	}
	else
	{

		chkbx_array[0].checked = false;
	}

	if(chkbx_array[0].checked == true)
	{
		var div_id=document.getElementById(source + 'proptype_scroll');
		var div_elem = div_id.getElementsByTagName('input');
		for(var indx=1; indx<div_elem.length; indx++)
		{
			div_elem[indx].checked = false;
		}
	}

	if(source != 'buyer_page' ){
		if(max_checked)
		{
			if(count < max_checked)
			{
				for(var indx = 1; indx < total_count; indx++)
				{
					chkbx_array[indx].disabled=false;
				}
			}
			else if(count >= max_checked)
			{
				for(var indx = 1; indx < total_count; indx++)
				{
					if(!chkbx_array[indx].checked)
					{
						chkbx_array[indx].disabled=true;
					}
				}
			}
		}

	}


	return count;
}

function updateSelectionMessage_ajax(details, element,source)
{

	
	var det_array = details;
	var startindx = 1;

	if(det_array == 'proptype')
	{
		//alert("dasda"+source + 'ptype_msg');
		var status_msg = document.getElementById(source + 'ptype_msg');
	}


	var msg = '';

	for(var indx = startindx; indx < element.length; indx++)
	{
		var showmsg = 1;

		if(element[indx].checked && showmsg)
		{
			if(msg == '')
			{
				msg = element[indx].id;
			}
			else
			{
				msg += ', '+element[indx].id;
			}
		}
	}

	//Komal:Code to get unique labels for cities starts
	var msg_array = new Array();
	var msg_array = msg.split(',');
	var uniqueArray=new Array();
	label:for(var i=0; i<msg_array.length;i++ )
	{
		for(var j=0; j<uniqueArray.length;j++ )
		{
			if(uniqueArray[j]==msg_array[i])
			continue label;
		}
		uniqueArray[uniqueArray.length] = msg_array[i];
	}
	msg=uniqueArray.join();

	//Code to get unique labels for cities ends
	if(msg == '')
	{
		if(det_array == 'proptype')
		{
			var res_com = document.getElementById('hidden_res_com');
			//alert(res_com.value);
			if(res_com.value=='RES')
			{
				msg = "All Residential Properties";
			}
			else
			{
				msg = "All Commercial Properties";
			}

		}

	}
	//alert(status_msg.innerHTML);
	status_msg.innerHTML = msg
	//alert(status_msg.innerHTML);
}

function getCheckedCount_ajax(chkbx_array)
{
	var count = 0;
	var startindx = 0;
	var tocount = 1;
	var parentNodeId = chkbx_array[0].parentNode.id;
	//alert("here1");
	//if (parentNodeId == "proptype")
	{
		startindx = 1;
		//alert("here");
	}

	for(var indx = startindx; indx < chkbx_array.length; indx++)
	{
		if( tocount && chkbx_array[indx].checked )
		{
			count++;
		}
		tocount = 1;
	}
	//count=count-1;
	//alert(count);
	return count;
}

function uncheck_all(div_id)
{

	var div_elem = div_id.getElementsByTagName('input');
	for(var indx=0; indx<div_elem.length; indx++)
	{
		div_elem[indx].checked = false;
	}
}

function enable_all(div_id)
{
	var div_elem = div_id.getElementsByTagName('input');

	for(var indx=0; indx<div_elem.length; indx++)
	{
		div_elem[indx].disabled = false;
	}
}