
function getCityValue(){
	var item = document.getElementById("city_slt");
	if (item) {
		return item.value;
	}
	return "";
}

function getProvinceValue(){
	var item = document.getElementById("province_slt");
	if (item) {
		return item.value;
	}
	return "";
}

function getPropertiesValue() {
	var item = document.getElementById("propertycount");
	var pValue = "";
	var tValue = "";
	if(item) {
		var pCount = parseInt(item.value);		
		for (var lp = 0;lp<pCount;lp++)
		{
			var objName = document.getElementById('h' + lp);
			if (objName != null)
			{
				tValue = objName.value;
				if(tValue)
					pValue += (tValue + ";");	
			}
		}
	}
	return pValue;
}

function showMore(){
	document.getElementById("fastMore").style.display = "block";
	//document.getElementById("shuai_ctrl").innerHTML = "<button type=\"submit\" class=\"but\" id=\"ListSearchFormSubmit\">筛 选</button> &nbsp;<a href=\"javascript:showLease()\" class=\"ml_9\" target=\"_self\"><img src=\"http://style.org.hc360.com/search/images/search_28.gif\"/ alt=\"精简显示搜索条件\"> <span class=\"ml\">精简<span></a>";
	document.getElementById("shuai_ctrl").innerHTML = "<a href=\"javascript:showLease()\" class=\"ml_9\" target=\"_self\"><img src=\"http://style.org.hc360.com/search/images/search_28.gif\"/ alt=\"精简显示搜索条件\"> <span class=\"ml\">精简<span></a>";
}
function showLease(){
	document.getElementById("fastMore").style.display = "none";
	document.getElementById("shuai_ctrl").innerHTML = "<a href=\"javascript:showMore()\" class=\"ml_9\" target=\"_self\"><img src=\"http://style.org.hc360.com/search/images/search_29.gif\" alt=\"显示全部搜索条件\"/> <span class=\"ml\">更多<span></a>";
}

function DoFilter() {
	var form = document.getElementById("filterform");
	form.action += "&u=" + form.u.value;
	var begintime;
	var endtime;
	begintime=form.StartDate.value;
	endtime=form.EndDate.value;
	begintime=begintime.replace("-","");
	begintime=begintime.replace("-","");
	endtime=endtime.replace("-","");
	endtime=endtime.replace("-","");
	form.action+="&B="+begintime+"&E="+endtime;
	var act = form.action;
	var item;
	var item1;
	var item2;
	var value = getProvinceValue();
	if (value) {
		if (value == "香港" || value == "台湾" || value == "澳门") {
			act += "&province="	+ value;
		} else {
			act += "&province="	+ value;
		}
		value =  getCityValue();
		if (value) {
			act += ":" + value;
		}
	}
	

	//排序类型
	item = document.getElementById("sortway_value");
	
	item1=document.getElementById("sortvalue_value");

	if(item&&item1){

		if (item.value==0)
		{
			if (item1.value==0)
			{
				act += "&v=" + "10";
			}else 
			{
				act += "&v=" + "5";
			}
			
		}else if (item.value==1)
		{
			if (item1.value==0)
			{
				act += "&v=" + "11";
			}else 
			{
				act += "&v=" + "12";
			}
			
		}else if (item.value==2)
		{
			if (item1.value==0)
			{
				act += "&v=" + "13";
			}else 
			{
				act += "&v=" + "14";
			}			
		}

					
	}
	//资讯排序
	item = document.getElementById("sort_value");
	if (item)
	{
		act+="&v="+item.value;
	}
		
	item = document.getElementById("managetype_value");
	if (item) {
		act += "&j=" + item.value;
	}
	
	//默认排序
	item = document.getElementById("sorttype");
	if (item) {
		act += "&v=" + item.value;
	}
	
	//发布时间
	item = document.getElementById("posttime_value");
	if (item) {
		act += "&DateTime=" + item.value;
	}
	act += "&h=" + getPropertiesValue();
	
	
	//买卖通会员
	item = document.getElementById("membertype");
	if (item)
	{
		act+="&a="+item.value;
	}
	
	if(form.g && form.l)
		act = act + "&g=" + form.g.value + "&l=" + form.l.value;
	
	if(form.f && form.f.checked)
		act += "&f=1";
	
	
	//关键字
	if(form.w)
		act += "&w=" + form.w.value;
	//关键字
	/*if(form.w)
	{
		if(item2)
		{
			act += "&w=" + form.w.value+" INACTIVE:"+item2.value;
		}
	}*/
	
	if (form.p)
		act += "&p=" + form.p.value;
		
	//紧急求购
	if(form.b && form.b.checked)
	act += "&b=5";
	
	//L
	act+="&L="+form.L.value;

	window.location.href = act;
	
	return false;
}

function cutword(s, count)
{
	if(s && typeof(s) != "undefined")   {
		var str="";
		if(s.length <= count) {
			str=s;
		} else {
			str=s.substring(0, count);
		}
		return str;
	} else {
		return "";
	}
}


/*
for calendar selection
*/

function DatePicker(imgName, divName, formAndText, initYear, initMonth) {
    var cf = document.getElementById("CalFrame");
    var wcf = window.frames.CalFrame;
    if (!wcf.alreadyLoad) {
      alert("<iframe not loaded>");
      return;
    }
    
    if (cf.style.display == "block") cf.style.display = "none";
    
    var eT=0,eL=0,p=document.getElementById(imgName);
	var sT=document.body.scrollTop,sL=document.body.scrollLeft;
	var eH=p.height,eW=p.width;
	while(p&&p.tagName!="BODY"){eT+=p.offsetTop;eL+=p.offsetLeft;p=p.offsetParent;}
	cf.style.top=(document.body.clientHeight-(eT-sT)-eH>=cf.height)?eT+eH:eT-cf.height;
	cf.style.left=(document.body.clientWidth-(eL-sL)>=cf.width)?eL:eL+eW-cf.width;
	
	var objImg = document.getElementById(imgName);
	var idx = formAndText.indexOf(".");
	var objTxt = document.getElementById((idx >= 0) ? formAndText.substring(idx + 1) : formAndText);
	cf.style.display="block";
	
	wcf.initCalendar(objImg, objTxt, initYear, initMonth);
	
}
function hideCalendar() {
    var cf = document.getElementById("CalFrame");
    cf.style.display = "none";
}
/* 参数说明：*/
/* arr:数组，下标必须从0开始，并且是连续非负整数，包含要查找的内容，必须是排序好的 */
/* item:要查找的目标 */
/* less_than:比较函数，定义为：function less_than(left,right) */
/* 这个函数必须和数组用于排序的less_than函数具有同样的行为 */
/* 当left < right时，返回-1 */
/* 当left == right 时，返回 0 */
/* 当left > right时，返回 1*/
/* 返回值说明：*/
/* 当目标存在时，函数返回目标所在位置的数组下标 */
/* 当目标不存在时，函数返回数组中第一个比目标大的元素下标 */
/* 当查找的目标比数组中任何元素都大，或者数组为空的时候，返回数组的长度 */
function binary_search(arr,item)
{
	var start = 0;
	var end    = arr.length
	var current =0;
	if (end !=1)
	{
		 current = (arr.length + (arr.length%2) )/2; 
	}

	while( end != current )
	{
		if( less_than(item,arr[current]) == 1 )
			start =    current+1;
		else
			end = current;
		var tmp    = (start + end);
		current    = (tmp - (tmp%2))/2; 
	}
	if (item==arr[current])
	{
		return current;    	
	}else
	{
		return -1;
	}

}
function less_than(left,right) 
{
	if(left>right)
	{
		return 1;
	}else 
	{
		return 0;
	}
}

  function changeProvince(list) {
    if (list.selectedIndex<=0) {
		provincesel.options[0].selected=true;
		var len = citysel.options.length;
		for (var i=len-1;i>0;i--){
			citysel.options[i]=null;
		}
    }else {
		var boards = catArr1[list.selectedIndex-1].getOptions();
		var len = citysel.options.length;
		for (var i=len-1;i>0;i--){
			citysel.options[i]=null;
		}
		for (var i=0;i<boards.length;i++) {
			citysel.options[i+1]=boards[i];
		}
		
		var tmpPro = list.options[list.selectedIndex].value;
		citysel.disabled = false;
    }
  }
  
  function changeRegion(province,city) {
      for (var i=0;i<catArr1.length;i++) {
      provincesel.options[i+1]=new Option(catArr1[i].title,catArr1[i].id);
      //设置省选择框的选择值
      if(provincesel.options[i+1].value == province){
         provincesel.options[i+1].selected=true;
      }
    }
      changeProvince(provincesel);
    var len = citysel.options.length;
    for (var i=0;i<len;i++) {
      //设置城市选择框的选择值
      if(citysel.options[i].value == city) {
        citysel.options[i].selected=true;
      }
    }
  }