//====================================================================================================
//	Function Name	:	changeMoveType
//----------------------------------------------------------------------------------------------------
function changeMoveType(el)
{
	$('#advLink').attr("href", "communitysearch.php?id="+el.value);
	
	if ((el.value==1) || (el.value==3))
	{
		//$('#commutetime').attr("style","display:block;");
		document.getElementById('commutetime').style.display = 'block';
	//	$('#drivetime').attr("style","display:none;");

		//$('#search_com_drive_time').value = '';
	}
	else
	{
		document.getElementById('commutetime').style.display = 'none';
		//$('#commutetime').attr("style","display:none;");
		//	$('#drivetime').attr("style","display:block;");

		//$('#search_com_time').value = '';
	}
}
//====================================================================================================
//	Function Name	:	changeBuyRent
//----------------------------------------------------------------------------------------------------
function changeBuyRent(el)
{
	if (el.value=='rent')
	{
		$('#rentPrice').attr("style","display:block;");
		$('#buyPrice').attr("style","display:none;");
	}
	else if (el.value=='buy')
	{
		$('#rentPrice').attr("style","display:none;");
		$('#buyPrice').attr("style","display:block;");
	}
}

//====================================================================================================
//	Function Name	:	ShowHide
//----------------------------------------------------------------------------------------------------
function showHidePropBlock(div, display)
{
	if(document.getElementById(div).style.display != display)
	{
		document.getElementById(div).style.display = display;
		document.getElementById('block1').style.height = '550px';
		document.getElementById('block2').style.height = '550px';
		document.getElementById('block3').style.height = '550px';
	}
	else
	{
		document.getElementById(div).style.display = 'none';
		document.getElementById('block1').style.height = '400px';
		document.getElementById('block2').style.height = '400px';
		document.getElementById('block3').style.height = '400px';
	}
	
	//document.getElementById('block1').style.height =;
	//document.getElementById('block2').style.height =;
	//document.getElementById('block3').style.height =;
}
//====================================================================================================
//	Function Name	:	Validate_Login
//----------------------------------------------------------------------------------------------------
function Validate_Login(frm)
{
	with(frm)
    {
    	if(!IsEmpty(username, 'Please enter Username.'))
        {
			return false;
        }
    	
		if(!IsEmpty(password, 'Please enter Password.'))
        {
			return false;
        }
    }
	
	return true;
}
//====================================================================================================
//	Function Name	:	Country_Change
//====================================================================================================
function Country_Change(eCaller, fldChange, defValue)
{
	var listFld 	= document.getElementById(fldChange);
	var arrData 	= eval('data_'+fldChange);
	var countryCode	= eCaller.value;
   
	listFld.options.length = 0;
	
	if(arrData[countryCode])
	{
		listFld.options.length++;
		listFld.options[listFld.options.length-1] = new Option('all', '0');
		
		for (var i in arrData[countryCode])
		{
			listFld.options.length++;
			listFld.options[listFld.options.length-1] = new Option(arrData[countryCode][i], i);
		
			if(defValue == i)
				listFld.selectedIndex = listFld.options.length-1;
		}
	}
	else
	{
		listFld.options.length++;
		listFld.options[listFld.options.length-1] = new Option('all', '0');
	}
}

//====================================================================================================
//	Function Name	:	Validate_Form
//----------------------------------------------------------------------------------------------------
function Validate_Form(frm,Check_Terms)
{
	with(frm)
    {
		
		if(!IsEmpty(member_firstname, 'Please enter your First Name.'))
		{
			return false;
		}
		if(!IsEmpty(member_lastname, 'Please enter your Last Name.'))
		{
			return false;
		}
		
		if(!IsEmpty(member_email, 'Please enter Email address.'))
		{
			return false;
		}
		else if(!IsEmail(member_email, 'Oppsss!!! Invalid Email Address specified.'))
		{
				return false;
		}
		
//		if(!IsEmpty(member_phone, 'Please enter Phone Number.'))
//		{
//			return false;
//		}
//		else if(!IsPhone(member_phone, 'Oppsss!!! Invalid Phone No.'))
//		{
//			return false;
//		}
   	    if(document.getElementById('member_phone'))
		{
			if(member_phone.value != '')
			{
				if(!IsPhone(member_phone, 'Oppsss!!! Invalid Phone No.'))
				{
					return false;
				}
			}
		}	
   		if(document.getElementById('member_alt_phone'))
		{
			if(member_alt_phone.value != '')
			{
				if(!IsPhone(member_alt_phone, 'Oppsss!!! Invalid Phone No.'))
				{
					return false;
				}
			}
		}	
		
		if(document.getElementById('member_office_phone'))
		{
			if(member_office_phone.value != '')
			{
				if(!IsPhone(member_office_phone, 'Oppsss!!! Invalid Phone No.'))
				{
					return false;
				}
			}
		}	
		
		if(document.getElementById('member_why_ask'))
		{
			if(member_why_ask.value != '')
			{
				if(!IsLen(member_why_ask, 0, 255, 'Address : Maximum 255 characters allowed.'))
				{
					return false;
				}
			} 
		}	

		if(Check_Terms)
		{
			if(!IsEmpty(user_login_id, 'Please enter User Name.'))
			{
				return false;
			}
			
			if(!IsEmpty(user_password, 'Please enter your Password.'))
			{
				return false;
			}
			else if(user_password.value.length < 6)
			{
				alert('Please enter a password with a minimum of six characters.');
				user_password.focus();
				return false;
			}		
		
			/*if(!IsEmpty(code_of_image, 'Please enter your Security Code.'))
			{
				return false;
			}*/

			if(agreement.checked == false)
			{
				alert("You must agree with Agreement.");
				return false;
			}
		}
	}
	
	return true;
}

//====================================================================================================
//	Function Name	:	ShowHide
//----------------------------------------------------------------------------------------------------

function reloadCaptcha()
     {
                document.getElementById("capatch_image_id").src = "image.php?time="+ Date();
      }	

//====================================================================================================
//	Function Name	:	ShowHide
//----------------------------------------------------------------------------------------------------
function showHideDiv(frm,div,Id)
{
	if(document.getElementById('member_imp_attribute['+Id+']').checked == true)
		document.getElementById(div).style.display = '';
	else if(document.getElementById('member_imp_attribute['+Id+']').checked == false)
	{
		document.getElementById(div).style.display = 'none';
	}
}
function CheckForCountry(Action,arrFld)
{
 //	var arrFld 	= document.getElementById('mail_county');
	var flgselected = 0;
	if (arrFld.type!='hidden')
	{
		var errFlag	= true;
		for (i=0; i<arrFld.options.length; i++)
		{
			if (arrFld.options[i].selected)
			{
				var errFlag	= false;
				flgselected++;
			}
		}
		if (errFlag)
		{
			alert("please, select county.");
			return false;
		}
		//if more then 3 countries selected get alert
		if(flgselected > 3 && (Action.value == 'Property' || Action.value == 'SampleAgent' || Action.value == 'MLS'))
		{
 			document.getElementById('countryAlertDiv').style.display = 'block';
 			return false;
		}
		else
		{
 			document.getElementById('countryAlertDiv').style.display = 'none';
		}
 		
	}
}
//====================================================================================================
//	Function Name	:	Validate_CallAction
//----------------------------------------------------------------------------------------------------
function Validate_CallAction(frm)
{
 	var arrFld 	= document.getElementsByName('mail_state[]');
	var chkFld 	= document.getElementById('mail_state');
 	
	if (chkFld.type!='hidden')
	{
		var errFlag	= true;
		for (i=0; i<arrFld.length; i++)
		{
			if (arrFld[i].checked)
			{
				var errFlag	= false;
			}
		}
		if (errFlag)
		{
			alert("please, select state.");
			return false;
		}
	}
	
	var arrFld 	= document.getElementById('mail_county');
	
	
	var flgselected = 0;
	if (arrFld.type!='hidden')
	{
		var errFlag	= true;
		for (i=0; i<arrFld.options.length; i++)
		{
			if (arrFld.options[i].selected)
			{
				var errFlag	= false;
				flgselected++;
			}
		}
		if (errFlag)
		{
			alert("please, select county.");
			return false;
		}
 		//if more then 3 countries selected get alert
		if(flgselected > 3 && (frm.Action.value == 'Property' || frm.Action.value == 'MLS'))
		{
 			document.getElementById('countryAlertDiv').style.display = 'block';
 			return false;
		}
 		
	}
	with(frm)
    {
		if(Action.value == 'Property')
		{
			var arrPropType 	= document.getElementsByName('mail_prop_type[]');
			var errPropFlag	= true;
			for (i=0; i<arrPropType.length; i++)
			{ 
				if (arrPropType[i].checked)
				{
					var errFlagPropType	= false;
				}
			}
			if (errFlagPropType)
			{
				alert("please, select Property type.");
				return false;
			}

			if(mail_bedrooms.value == 'any')
			{
					alert('Please select bedroooms.');
					mail_bedrooms.focus();
					return false;
			}
			if(mail_sq_ft.value == 'any')
			{
					alert('Please select square footage.');
					mail_bedrooms.focus();
					return false;
			}

			if(!IsEmpty(mail_price_range, 'Please select price range.'))
			{
				return false;
				mail_price_range.focus();
			}
		}
		
/*		if(!IsEmpty(mail_bedrooms, 'Please select bedrooms.'))
		{
			return false;
			mail_bedrooms.focus();
		}
		if(mail_bedrooms.value == 'any')
		{
				alert('Please select bedroooms.');
				mail_bedrooms.focus();
				return false;
		}
			
		if(!IsEmpty(mail_sq_ft, 'Please select square footage.'))
		{
			return false;
			mail_sq_ft.focus();
		}
		
		if(mail_sq_ft.value == 'any')
		{
				alert('Please select square footage.');
				mail_sq_ft.focus();
				return false;
		}*/
		if(!IsEmpty(mail_time_frame, 'Please select time frame.'))
		{
			return false;
			mail_time_frame.focus();
		}

/*		if(!IsEmpty(mail_name, 'Please enter your first name.'))
		{
			return false;
			mail_name.focus();
		}
		if(Action.value == 'Property')
		{
			if(!IsEmpty(mail_phone, 'Please enter Phone Number.'))
			{
				return false;
				mail_phone.focus();
	
			}
		}
		
		/*else if(!IsPhone(mail_phone, 'Oppsss!!! Invalid Phone No.'))
		{
			return false;
			mail_phone.focus();
		}*/
		/*if(!IsEmpty(mail_email, 'Please enter Email address.'))
		{
			return false;
			mail_email.focus();
		}
		else if(!IsEmail(mail_email, 'Oppsss!!! Invalid Email Address specified.'))
		{
				return false;
				mail_email.focus();
		}*/
	}
	
	return true;
}

//====================================================================================================
//	Function Name	:	Validate_Comm
//----------------------------------------------------------------------------------------------------
function Validate_Comm(frm)
{
		with(frm)
    {
		if(!IsEmpty(search_com_type, 'Please select move type.'))
		{
			return false;
		}
		if($('#search_com_time').is(":visible"))
		{
			if(!IsEmpty(search_com_time, 'Please select commute time.'))
			{
				return false;
			}
		}
		if(!IsEmpty(search_com_price, 'Please select price range.'))
		{
			return false;
		}
		if(!IsEmpty(search_com_time_frame, 'Please select time frame.'))
		{
			return false;
		}
	}
	
	return true;
}

//====================================================================================================
//	Function Name	:	Validate_CommByLocation
//----------------------------------------------------------------------------------------------------
function Validate_CommByLocation(frm)
{
	if($('#com_state').val() == ' ')
	{
		alert("please, select state.");
		return false;
	}
	if($('#com_county').val()=='')
	{
		alert("please, select county.");
		return false;
	}
	
	return true;
}
//====================================================================================================
//	Function Name	:	Get_listing_validate
//----------------------------------------------------------------------------------------------------
function Get_listing_validate(frm , comm_id  , IsUserLogged)
{
	
	if(document.getElementById('mail_state1'))
	{
		var mail_state1 	= document.getElementById('mail_state1');
		var mail_state2 	= document.getElementById('mail_state2');
		var mail_state3 	= document.getElementById('mail_state3');
		if (!(mail_state1.value != ' ' || mail_state2.value != ' ' || mail_state3.value != ' '))
		{
			alert("please, select atleast one state.");
			//mail_state1.focus();
			return false;
		}
			//alert($('#mail_county1').val());
	//alert($('#mail_county2').val());
	//alert($('#mail_county3').val());
	
		if ($('#mail_county1').val() == ' ' && mail_state1.value!=' ')
		{
			alert("please, select county for  First State.");
			//$('#mail_county1').focus();
			return false;
		}
		if ($('#input_mail_community1').val() == '' && $('#mail_county1').val() != ' ' && mail_state1.value!=' ')
		{
			alert("Important Message from bestplace2move.com:\n\n If you request listings by county ONLY you will get thousands of results that are virtually useless.  Please select up to three communities within that county or across three different counties. \n\n If you are not sure which communities to select use the community search to get detailed and insightful information on hundreds  of communities, OR email us at info@bestplace2move.com and one of our personal search coordinators will be able to help you.");
			return false;
		}
		if ($('#mail_county2').val() == ' ' && mail_state2.value!=' ')
		{
			alert("please, select county for Second  State.");
			//$('#mail_county2').focus();
			return false;
		}
		if ($('#input_mail_community2').val() == '' && $('#mail_county2').val() != ' ' && mail_state2.value!=' ')
		{
			alert("Important Message from bestplace2move.com:\n\n If you request listings by county ONLY you will get thousands of results that are virtually useless.  Please select up to three communities within that county or across three different counties. \n\n If you are not sure which communities to select use the community search to get detailed and insightful information on hundreds  of communities, OR email us at info@bestplace2move.com and one of our personal search coordinators will be able to help you.");
			return false;
		}

		if ($('#mail_county3').val() == ' ' && mail_state3.value!=' ')
		{
			alert("please, select county for Third State.");
			//$('#mail_county3').focus();
			return false;
		}
	
		if ($('#input_mail_community3').val() == '' && $('#mail_county3').val() != ' ' && mail_state3.value!=' ')
		{
			alert("Important Message from bestplace2move.com:\n\n If you request listings by county ONLY you will get thousands of results that are virtually useless.  Please select up to three communities within that county or across three different counties. \n\n If you are not sure which communities to select use the community search to get detailed and insightful information on hundreds  of communities, OR email us at info@bestplace2move.com and one of our personal search coordinators will be able to help you.");
			return false;
		}
		if (($('#input_mail_community1').val() == $('#input_mail_community2').val() && $('#input_mail_community1').val() !='') ||
		($('#input_mail_community2').val() == $('#input_mail_community3').val() && $('#input_mail_community2').val() !='') ||
		($('#input_mail_community1').val() == $('#input_mail_community3').val() && $('#input_mail_community1').val() !=''))
		{
			alert("please select diffrent locations.");
			return false;
		}
	}
	
	var arrPropType 	= document.getElementsByName('mail_prop_type[]');

	var errFlagPropType	= true;
 	for (i=0; i<arrPropType.length; i++)
	{ 
 		if (arrPropType[i].checked)
		{
			var errFlagPropType	= false;
		}
	}
	
			
			if($('#mail_price_range').val() == '')
				{
					alert('Please select Price range.');
					return false;
					$('#mail_price_range').focus();
				}
			
				if (errFlagPropType)
			{
			alert("please, select Property Type.");
			return false;
			}
				if($('#mail_sq_ft').val() == 'any' || $('#mail_sq_ft').val() == '')
			{
				alert('Please select square footage.');
				$('#mail_sq_ft').focus();
				return false;
			}
			if($('#mail_bedrooms').val() == 'any' || $('#mail_bedrooms').val() == '')
			{
				alert('Please select bedroooms.');
				$('#mail_bedrooms').focus();
				return false;
			}
			
		/*	if($('#mail_bathrooms').val() == '')
			{
				alert('Please select bathroom.');
				return false;
				$('#mail_bathrooms').focus();
			}*/
			
			if($('#mail_time_frame').val() == '')
			{
					alert('Please select time frame.');
					return false;
					mail_time_frame.focus();
			}
 			if(Number(IsUserLogged) != 1)
			{	
				var frmData = $('#frmAgent').serialize();
 				var data = "Action=getListing&"+frmData;
				var url  = "ajax_calltoaction.php";
				var myAjax = $.ajax({
						  url: url,
						  global: false,
						  type: "POST",
						  data: data,
						  dataType: "html",
					      success: handleReceiveMessages
						 });
				return false;
			}
	
	return true;
}
//====================================================================================================
//	Function Name	:	handleReceiveMessages
//====================================================================================================
function handleReceiveMessages(receiveData)
{
/*  	if(receiveData == 'loggedin')
 	{
		$("#frmAgent").trigger("submit");
	}
	else*/
		$('#iframeClick').trigger('click');
	
	//$('#button').trigger('submit');
}
//====================================================================================================
//	Function Name	:	SaveRevision
//====================================================================================================
function calltoaction(Action, revision_id)
{
	var agent = $("select[name='rsAgent"+revision_id+"']").val();
}

//====================================================================================================
//	Function Name	:	mls_visible
//----------------------------------------------------------------------------------------------------
function mls_visible(checked)
{
	if(checked)
	{
		document.getElementById('mls').style.display = 'block';
	}
	else
	{
		document.getElementById('mls').style.display = 'none';
	}
}

//====================================================================================================
//	Function Name	:	communityChangeState
//----------------------------------------------------------------------------------------------------

function removeCommunity()
{
	communityChangeCounty('member_community')
}

//====================================================================================================
//	Function Name	:	communityChangeState
//----------------------------------------------------------------------------------------------------
function communityChangeCounty(county_id)
{
	$("#member_community").find('option').remove();
	$("#member_community").find('option').end().append('<option value="">loading....<option>');
	
		var arrState 	= document.getElementsByName('member_state[]');
		var selectedState= '',j=1;
		
			for (i=0; i<arrState.length; i++)
			{ 
				if (arrState[i].checked)
				{
						if(j>1)
						{
						selectedState += "','";	
						}
						selectedState += arrState[i].value;;
						j++;
					}
			}
		
	var selectedCounty='',i=1;
	$("#"+county_id+ " option:selected").each(function () {
                if(i>1)
				{
				selectedCounty += "','";	
				}
				selectedCounty += $(this).val();
				i++;
              });
    
		  
	//alert(selectedState);
	var url  = "ajax_comboCounty2.php";
	var myAjax = $.ajax({
				  url: url,
				  global: false,
				  type: "POST",
				  data: "county="+selectedCounty+"&state="+selectedState,
				  dataType: "json",
				  success: ReceiveComStatus
			   });
}
//====================================================================================================
//	Function Name	:	ReceiveComStatus
//----------------------------------------------------------------------------------------------------
function ReceiveComStatus(val)
{
	$("#member_community").find('option').remove();
	if(val['count']=='')
	{
		$("#member_community").find('option').end().append("<option value=' '>community</option>");
 	}
	else
	{
		for(i=0;i<val['count'];i++)
		{
			$("#member_community").find('option').end().append("<option value='" + val[i]['id'] + "'>" + val[i]['name'] + "</option>");
	}
	}		
		//$('#iframeClick').trigger('click');
	
}

//====================================================================================================
//	Function Name	:	Validate_Agent
//----------------------------------------------------------------------------------------------------
function Validate_Agent(frm)
{
 	if(frm.hidAction)
	{
	 	var arrFld 	= document.getElementsByName('member_state[]');
	}
 	else
	{
	 	var arrFld 	= document.getElementsByName('mail_state[]');
		var arrPropType 	= document.getElementById('mail_prop_type[]');
	}
	
	var errFlag	= true;
 	for (i=0; i<arrFld.length; i++)
	{ 
 		if (arrFld[i].checked)
		{
				var errFlag	= false;
		}
	}
	if (errFlag)
	{
		alert("please, select state.");
		return false;
	}
	
	
	if(frm.hidAction)
	 	var arrFld 	= document.getElementById('member_county');
 	else
 		var arrFld = document.getElementById('mail_county');

	var flgselected = 0;
	var errFlag	= true;
	for (i=0; i<arrFld.options.length; i++)
	{
		if (arrFld.options[i].selected)
		{
			var errFlag	= false;
			flgselected++;
		}
	}
	if (errFlag)
	{
		alert("please, select county.");
		return false;
	}
	if(arrPropType)
	{
		var errFlagPropType	= true;
		for (i=0; i<arrPropType.length; i++)
		{ 
			if (arrPropType[i].checked)
			{
				var errFlagPropType	= false;
			}
		}
	}	
	if (errFlagPropType)
	{
		alert("please, select Property Type.");
		return false;
	}	
/*	if (arrPropType.value=='')
	{
		alert("please, select Property Type.");
		return false;
	}*/
	//if more then 3 countries selected get alert
/*	if(!frm.hidAction && flgselected > 3)
	{
		alert('to make your search effective please narrow it down to 3 counties');
		document.getElementById('countryAlertDiv').style.display = 'block';
		return false;
	}*/
	//if more then 3 countries selected get alert
	if (frm.name != 'frmAgent2' && typeof($('#mail_county').val())!= 'undefined')
	{
		if(flgselected > 3)
		{
			alert('to make your search effective please narrow it down to 3 counties');
			document.getElementById('countryAlertDiv').style.display = 'block';
			return false;
		}
	}	
 
	
	if (frm.name == 'frmAgent')
	{
		with(frm)
		{		
		
			/*if(found_online.checked)
			{
				if(mail_mls.value == "" || mail_mls.value == 'MLS#')
				{
					alert("Please select MLS #");
					mail_mls.focus();
					return false;
					
				}
				if(mail_address.value == "" || mail_address.value == 'Property Address')
				{
					alert("Please select MLS Address");
					mail_address.focus();
					return false;
					
				}
			}*/
			
			if(document.getElementById('mail_price_range') != null)
			{
				if(mail_sq_ft.value == 'any')
				{
					alert('Please select square footage.');
					mail_sq_ft.focus();
					return false;
				}
				if(!IsEmpty(mail_sq_ft, 'Please select square footage.'))
				{
					mail_sq_ft.focus();
					return false;
				}
				if(mail_bedrooms.value == 'any')
				{
					alert('Please select bedroooms.');
					mail_bedrooms.focus();
					return false;
				}
				
				if(!IsEmpty(mail_bedrooms, 'Please select bedroooms.'))
				{
					return false;
					mail_bedrooms.focus();
				}
				if(!IsEmpty(mail_price_range, 'Please select price range.'))
				{
					return false;
					mail_price_range.focus();
				}
				
				if(!IsEmpty(mail_time_frame, 'Please select time frame.'))
				{
						return false;
						mail_time_frame.focus();
				}
				
				if(!IsEmpty(mail_name, 'Please enter your  name.'))
				{
					return false;
					mail_firstname.focus();
				}
				if(!IsEmpty(mail_email, 'Please enter Email address.'))
				{
					return false;
					mail_email.focus();
				}
				else if(!IsEmail(mail_email, 'Oppsss!!! Invalid Email Address specified.'))
				{
						return false;
						mail_email.focus();
				}
			
			}
			else
			{
				
				if(!IsEmpty(search_agent_time_frame, 'Please select time frame.'))
			{
				return false;
				search_agent_time_frame.focus();
			}
			}
		}
	}
	else
	{
		with(frm)
		{
			/*if(found_online.checked)
			{
				if(mail_mls.value == "" || mail_mls.value == 'MLS#')
				{
					alert("Please select MLS #");
					mail_mls.focus();
					return false;
					
				}
				if(mail_address.value == "" || mail_address.value == 'Property Address')
				{
					alert("Please select MLS Address");
					mail_address.focus();
					return false;
					
				}
			}
*/			if(!IsEmpty(search_agent_time_frame, 'Please select time frame.'))
			{
				return false;
				search_agent_time_frame.focus();
			}
			
		}
	}

	return true;
}

//====================================================================================================
//	Function Name	:	Validate_CallAction
//----------------------------------------------------------------------------------------------------
function Validate_LookingInvest(frm)
{
	with(frm)
    {
		 
		if(!IsEmpty(your_name, 'Please enter your name.'))
		{
			return false;
			your_name.focus();
		}
		if(!IsEmpty(your_email, 'Please enter your email.'))
		{
			return false;
			your_email.focus();
		}
 		if(!IsEmpty(your_phone, 'Please enter your phone number.'))
		{
			return false;
			your_email.focus();
		}
 		if(!IsEmpty(goodtime, 'Please enter When\'s a good time to talk.'))
		{
			return false;
			mail_email.focus();
		}
 	}
	
	return true;
}



//====================================================================================================
//	Function Name	:	Get_costHomes_validate
//----------------------------------------------------------------------------------------------------
function Get_costHomes_validate(frm , comm_id  , IsUserLogged)
{
		//alert(comm_id);		
		var costhomes_price_range 	= document.getElementById('costhomes_price_range');
		
		if (!$(":checkbox[name^=cost_home_state[]]:checked").length) {
    		alert('Please select atleast one state');
    		return false;
		}
		if (costhomes_price_range.value == '')
		{
			alert("please, select price range.");
			return false;
			costhomes_price_range.focus();
		}
		
	return true;
}

//====================================================================================================
//	Function Name	:	communitycostHomes
//----------------------------------------------------------------------------------------------------
function communitycostHomes(county_id,state_id,community_id)
{
	var costhomes_state 	= $('#'+state_id).val();
	var costhomes_county 	= $('#'+county_id).val();
	var url  = "ajax_comboCounty.php";
	var myAjax = $.ajax({
				  url: url,
				  global: false,
				  type: "POST",
				  data: "county="+costhomes_county+"&state="+costhomes_state+"&community_div_id="+community_id,
				  dataType: "json",
				  success: ReceivecostHomesStatus
			   });
}

/* AJAX response to get messages */
function ReceivecostHomesStatus(val) 
{

	$("#"+val['community_div_id']).find('option').remove();
	
	if(val['count']=='')
	{
		$("#"+val['community_div_id']).find('option').end().append("<option value=''>no communities.</option>");
	}
	else
	{
		
		for(i=0;i<val['count'];i++)
		{
				if(val[i]["non_profit_flag"] != 1 && val[i]["id"] != 0)
			{
				 $("#"+val['community_div_id']).find('option').end().append('<option value='+val[i]["com_id"]+'>'+ val[i]['name']+'</option>');
			}
	}
	}
		$("#costhomes_community").multiSelect( { selectAll: false, listHeight:250,noneSelected : 'community'});//noneSelected : 'mail_state'
}

function removeCostHomeCommunity(com_id)
{
$("#"+com_id).find('option').remove();
//$("#"+com_id).find('option').end().append("<option value=''>communities</option>");
$("#costhomes_community").multiSelect( { selectAll: false, listHeight:250,noneSelected : 'community'});//noneSelected : 'mail_state'
}


function updateStateCombobox()
{

	var url  = "ajax_comboCostHomeState.php";
	var myAjax = $.ajax({
				  url: url,
				  global: false,
				  type: "POST",
				  data: "",
				  dataType: "json",
				  success: ReceiveCostHomeState
			   });
}

function ReceiveCostHomeState(val)
{
	 $("#ul_"+val['State_div_id']).find('li').remove();
	if(val['count']=='')
	{
		$("#ul_"+val['State_div_id']).find('li').end().append("<li>no state found.</li>");
		setTimeout(function(){$("#ul_"+val['State_div_id']).find('li').remove();},1500);
	}
	else
	{
		
		for(i=1;i<=val['count'];i++)
		{
				 $("#ul_"+val['State_div_id']).find('li').end().append('<li><input type="checkbox" value="'+val[i]["id"]+'" name="cost_home_state[]" onChange="costHomeCountySelect(\'costhomes_county\')" class="inline"/>'+ val[i]["name"]  +'</li>');

		}
	}
	
	/*if(document.getElementById('div_'+val['State_div_id']).style.display == 'none')
		document.getElementById('div_'+val['State_div_id']).style.display = 'block';
	else
		document.getElementById('div_'+val['State_div_id']).style.display = 'none';*/
	
//costhomes_state_Combobox.combobox.update();
}


function costHomeCountySelect(div_id)
{

	var id   = new Array() 
    $("input[name=cost_home_state[]]:checkbox:checked").each(function(){ 
         id.push(this.value) 
    }) 
	
	var url  = "ajax_comboState.php";
	var myAjax = $.ajax({
				  url: url,
				  global: false,
				  type: "POST",
				  data: "state="+id+"&county_div_id="+div_id,
				  dataType: "json",
				  success: ReceivecostHomeCounty
			   });
			   

}
			
/* AJAX response to get messages */
function ReceivecostHomeCounty(val) 
{
	//var comboId=eval(val['county_div_id']+"_Combobox");
	
	$("#ul_"+val['county_div_id']).find('li').remove();
	if(val['count']=='')
	{
		$("#ul_"+val['county_div_id']).find('li').end().append("<li>no county found.</li>");
		setTimeout(function(){$("#ul_"+val['county_div_id']).find('li').remove();},1500);
	}
	else
	{
		for(i=0;i<val['count'];i++)
		{
				 $("#ul_"+val['county_div_id']).find('li').end().append('<li><input type="checkbox" value="'+val[i]["id"]+'" name="cost_home_county[]" onChange="costHomeCommunitySelect(\'costhomes_community\')" class="inline"/>'+ val[i]["name"]  +'</li>');

		}
	}
	
	/*if(document.getElementById('div_'+val['county_div_id']).style.display == 'none')
		document.getElementById('div_'+val['county_div_id']).style.display = 'block';
	else
		document.getElementById('div_'+val['county_div_id']).style.display = 'none';*/

	//comboId.combobox.update();
}


function costHomeCommunitySelect(div_id)
{

var id   = new Array() 
    $("input[name=cost_home_county[]]:checkbox:checked").each(function(){ 
         id.push(this.value) 
    }) 
	
	var url  = "ajax_combocosthomecounty.php";
	var myAjax = $.ajax({
				  url: url,
				  global: false,
				  type: "POST",
				  data: "county="+id+"&community_div_id="+div_id,
				  dataType: "json",
				  success: ReceivecostHomeCommunity
			   });
			   

}
			
/* AJAX response to get messages */
function ReceivecostHomeCommunity(val) 
{
//	var comboId=eval(val['community_div_id']+"_Combobox");
	
	$("#ul_"+val['community_div_id']).find('li').remove();
	if(val['count']=='')
	{
		$("#ul_"+val['community_div_id']).find('li').end().append("<li>no community found.</li>");
		setTimeout(function(){$("#ul_"+val['community_div_id']).find('li').remove();},1500);
	}
	else
	{
		for(i=0;i<val['count'];i++)
		{
				 $("#ul_"+val['community_div_id']).find('li').end().append('<li><input type="checkbox" value="'+val[i]["id"]+'" name="cost_home_community[]"  class="inline"/>'+ val[i]["name"]  +'</li>');

		}
	}
	
	/*if(document.getElementById('div_'+val['community_div_id']).style.display == 'none')
		document.getElementById('div_'+val['community_div_id']).style.display = 'block';
	else
		document.getElementById('div_'+val['community_div_id']).style.display = 'none';
*/
	//comboId.combobox.update();
}

function showhide_div(div_id)
{
		if(document.getElementById('div_'+div_id).style.display == 'none')
		document.getElementById('div_'+div_id).style.display = 'block';
	else
		document.getElementById('div_'+div_id).style.display = 'none';
		
		//	$('.drop-block').not('#div_'+div_id).hide();
}
