/**
*  搜索
**/
function esf_search(){
	if (document.form1.minprice.value!= null){
		if (!isFloat(document.form1.minprice.value)) {
	        	alert('价格必须为数字型');
	        	return false;
	    }  
    }
    if (document.form1.maxprice.value!= null){
		if (!isFloat(document.form1.maxprice.value)) {
	        	alert('价格必须为数字型');
	        	return false;
	    }  
    }
    if (document.form1.minarea.value!= null){
		if (!isFloat(document.form1.minarea.value)) {
	        	alert('面积必须为数字型');
	        	return false;
	    }  
    }
    if (document.form1.maxarea.value!= null){
		if (!isFloat(document.form1.maxarea.value)) {
	        	alert('面积必须为数字型');
	        	return false;
	    }  
    }
    document.form1.target="_blank";
	if (document.form1.different.value == 0){  //求购
	    document.form1.opt.value = "searchQG";
	    document.form1.action = "/esf/qg_list.jsp?service=ls";
    } else if (document.form1.different.value == 2){  //评估
        document.form1.opt.value = "search";
        document.form1.action = "/esf/eval_list.jsp?service=ls";
    } else{                                   //出售  
    	document.form1.opt.value = "searchCS";
    	 document.form1.action = "/esf/cs_list.jsp?service=ls";
    }
    if (document.form1.xqinfo && document.form1.xqinfo.value == "小区地址或名称") {
        document.form1.xqinfo.value = "";
    }
    if (document.form1.lineCount) {
        form1.lineCount.value = "";
    }
    try {
			paginationGotoPage(0);
		} catch(e) {
			document.form1.submit();
		}
}

/**
*  城区快捷搜索
**/
function cityzone_search(id){
    clearEsfForm();
	if (id == -1){
		document.form1.cityzone.value = id;
	}else{
		document.form1.cityzoneid.value = id;
	}
	document.form1.target="_blank";
	if (document.form1.different.value == 0){  //求购
	    document.form1.opt.value = "searchQG";
	    document.form1.action = "/esf/qg_list.jsp?service=ls";
    } else if (document.form1.different.value == 2){//评估
        document.form1.opt.value = "search";
        document.form1.action = "/esf/eval_list.jsp?service=ls";
    } else {                                     //出售  
    	document.form1.opt.value = "searchCS";
    	document.form1.action = "/esf/cs_list.jsp?service=ls";
    }
    if (document.form1.xqinfo && document.form1.xqinfo.value == "小区地址或名称") {
        document.form1.xqinfo.value = "";
    }
    if (document.form1.lineCount) {
        form1.lineCount.value = "";
    }
    try {
			paginationGotoPage(0);
		} catch(e) {
			document.form1.submit();
		}
}

/**
*  物业类型快捷搜索
**/
function type_search(id){
    clearEsfForm();
    document.form1.typeid.value = id;
    document.form1.target="_blank";
	if (document.form1.different.value == 0){  //求购
	    document.form1.opt.value = "searchQG";
	    document.form1.action = "/esf/qg_list.jsp?service=ls";
    }else{                                     //出售  
    	document.form1.opt.value = "searchCS";
    	document.form1.action = "/esf/cs_list.jsp?service=ls";
    }
    if (document.form1.xqinfo && document.form1.xqinfo.value == "小区地址或名称") {
        document.form1.xqinfo.value = "";
    }
    if (document.form1.lineCount) {
        form1.lineCount.value = "";
    }
    try {
			paginationGotoPage(0);
		} catch(e) {
			document.form1.submit();
		}
}

/**
*  左侧菜单城区快捷搜索
**/
function cityzone_menusearch(id){
	if (id == -1){
		document.form1.cityzone.value = id;
	}else{
		document.form1.cityzoneid.value = id;
	}
    if (document.form1.xqinfo && document.form1.xqinfo.value == "小区地址或名称") {
        document.form1.xqinfo.value = "";
    }
    document.form1.opt.value = "searchCS";
    document.form1.action = "/esf/cs_list.jsp?service=ls";
    if (document.form1.lineCount) {
        form1.lineCount.value = "";
    }
    try {
			paginationGotoPage(0);
		} catch(e) {
			document.form1.submit();
		}
}

/**
*  左侧评估列表城区快捷搜索
**/
function cityzone_evalsearch(id){
	if (id == -1){
		document.form1.cityzone.value = id;
	}else{
		document.form1.cityzoneid.value = id;
	}
    document.form1.opt.value = "search";
    document.form1.action = "/esf/eval_list.jsp?service=ls";
    if (document.form1.lineCount) {
        form1.lineCount.value = "";
    }
    try {
			paginationGotoPage(0);
		} catch(e) {
			document.form1.submit();
		}
}

/**
*  页面跳转
**/

function searchgo1() {
	if (trim(document.form1.go1.value)==""){
		alert("请先填写页数");
	}else{
		paginationGotoPage(trim(document.form1.go1.value));	
	}
}
function searchgo2() {
	if (trim(document.form1.go2.value)==""){
		alert("请先填写页数");
	}else{
		paginationGotoPage(trim(document.form1.go2.value));	
	}
}

/**
 * 只能输入实数
 */ 
function FloatKeyPress() {
    if((event.keyCode<48 || event.keyCode>57) && event.keyCode!=46)
	    event.keyCode=0;
}

/**
*  新增对比项
**/
var contrast = "";
var contrastMap = "";
function add_compare(fyid,fyname){
	var contrastList = contrast.split(",");
	for (var i=0; i<contrastList.length; i++) {
		if (fyid == contrastList[i]) {
			alert("对不起，该房源已经选中。请选择其他房源。");
			return;
		}
	}
	if (contrast.split(",").length > 3){
		alert("进行对比的房源不能超过四个");
	}else{
		if (contrast == ""){
			contrast = fyid;
		}else{
			contrast += "," + fyid;
		}
		for (var i=1;i<=4;i++){
			if (document.getElementById("compare"+i).innerHTML=="物业名称"){
				if (fyname.length>4){
					fyname = fyname.substring(0,4)+ "&raquo;";
				}
				document.getElementById("compare"+i).innerHTML = fyname;
				break;
			}
		}
		if (contrastMap == ""){
			contrastMap = '' + i + ':' + fyid;
		}else{
			contrastMap += "," + i + ':' + fyid;
		}
		setCook(contrast, getXiaoqumc(), contrastMap);
	}
}	
		
/**
*  删除对比项
**/
function del_compare(id){
	var s, ss, oldList, newList;
	var j=0;
	ss = contrast.split(",");	
	oldList = contrastMap.split(",");
	document.getElementById("compare"+id).innerHTML = "物业名称";
	s = new Array();
	newList = new Array();
	for (var i=0; i<ss.length; i++){
		var t = oldList[i].split(":");
		if (t[0] != id){
			s[j] = ss[i];
			newList[j] = oldList[i];
			j=j+1;
		}
	}
	contrast = s.join(",");
	contrastMap = newList.join(",");
	setCook(contrast, getXiaoqumc(), contrastMap);
}

/**
*  进行对比
**/
function compareing(){
	var ss;
	ss = contrast.split(",");
	if (ss.length == 1){
		alert("进行对比的房源至少要两个");
	}else if (ss.length > 4){
		alert("进行对比的房源不能超过四个");
	}else{
		var url="esf_contrast.jsp?contrast="+contrast;
		window.open(url);
	}
}


function getXiaoqumc(){
    var mc = "";
    for (var i = 1; i <= 4; i++){
        if (i != 1) mc += "||";
        mc += document.getElementById("compare"+i).innerHTML;
   }
   return mc;
}

function initCook(){
    var cookie_array = document.cookie.split(";");
    var compare_id = "";
    var compare_mc = "";
    var compare_map = "";
    for (var i = 0; i < cookie_array.length; i++) {
        if (cookie_array[i].indexOf("cscompareid") > -1) {
            compare_id = cookie_array[i];
        } else if (cookie_array[i].indexOf("cscomparemc") > -1) {
            compare_mc = cookie_array[i];
        } else if (cookie_array[i].indexOf("cscomparemap") > -1) {
            compare_map = cookie_array[i];
        }
    }
    if (compare_id.length > 0 && 
            compare_id.substr(compare_id.indexOf("cscompareid=")).length > 0) {
        contrast = unescape(compare_id.substring(compare_id.indexOf("cscompareid=") + 12));
        contrastMap = unescape(compare_map.substring(compare_map.indexOf("cscomparemap=") + 13));
        var mc_array = unescape(compare_mc.substring(compare_mc.indexOf("cscomparemc=") + 12)).split("||");
        for (var i = 1; i <= 4 && i <= mc_array.length; i++){
			if (document.getElementById("compare"+i).innerHTML=="物业名称"){
				document.getElementById("compare"+i).innerHTML = mc_array[i - 1];
			}
		}
    }
}

function setCook(contrast_id, contrast_mc, contrast_map) {
    var cookie_array = document.cookie.split(";");
    document.cookie = "cscompareid=" + escape(contrast_id);
    document.cookie = "cscomparemc=" + escape(contrast_mc);
    document.cookie = "cscomparemap=" + escape(contrast_map);
}

/**
 * 判断参数是否为数值(含整型和浮点型)类型
 */
function isFloat(str) {
   if(!isNaN(str)) {
      return true;
	} else {
	   return false;   
	}
}

/**
 *
 */
function defaultKey(obj) {
    if (obj.value == "小区地址或名称") {
        obj.value = "";
    }
    obj.select(); 
}

function showMenuInformation() {  
	var oBox1 = document.getElementById("showInfomation");
	if (document.form1.different.value == 2) {
		oBox1.style.display = 'none';
	} else {
		oBox1.style.display = '';
	} 
}

function clearEsfForm() {
    document.getElementById("minprice").value = "";
    document.getElementById("maxprice").value = "";
    document.getElementById("minarea").value = "";
    document.getElementById("maxarea").value = "";
    document.getElementById("xqinfo").value = "";
    document.getElementById("oldxxh").value = "";
    document.getElementById("typeid").value = "";
    document.getElementById("cityzoneid").value = "";
    document.getElementById("cityzone").value = "";
    if (document.getElementById("room"))
        document.getElementById("room").value = "";
    if (document.getElementById("hall"))
    document.getElementById("hall").value = "";
}