//
(function(){
	var a;
	var i;
	var j;
	var claName="search_div_element";
	var eleName;
	var pclassForm;
	var pclass;
	var pclassid;
	var divList = new Array();
	var nameValueList;
	var pageSizeSelect;
	var pageForm;
	//
	var rent_min;
	var price_min;
	var rent_max;
	var price_max;
	//startup function
	function initSearch(){
		pclass=document.getElementsByName("pclass[]");
		if(typeof(pclass)==undefined) {return;}
		if(pclass==null) {return;}
		if(pclass.length > 0) {pclassForm = getElementParentTag(pclass[0], 'FORM');}
		if(pclassForm==null){return;}
		divList=getDivFromParent(pclassForm);
		//
		for(a=0;a<pclass.length;a++){
			if(pclass[a].getAttribute('type')!='radio'){continue;}
			pclassForm = getElementParentTag(pclass[a], 'FORM');
			if(pclassForm==null){continue;}
			divList=getDivFromParent(pclassForm);
			attachEvent(pclass[a], function(e){adjustDivDisplay(e, divList);}, 'click');
			if(pclass[a].checked){
				eleAdjustDivDisplay(pclass[a],divList);
			}
		}
		pageSizeSelect=document.getElementById('page_size_select');
		if(typeof(pageSizeSelect)!=undefined) {
			pageForm = getElementParentTag(pageSizeSelect, 'FORM')
			if(pageForm != null){
				attachEvent(pageSizeSelect, function(e){submitForm(e, pageForm);}, 'change');
			}
		}
	}
	//
	function submitForm(ele, formElement){
		formElement.submit();
	}
	//
	function changeRent(){
		if(price_min.value!=""){
			price_min.value="";
		}
		if(price_max.value!=""){
			price_max.value="";
		}
	}
	function changePrice(){
		if(rent_min.value!=""){
			rent_min.value="";
		}
		if(rent_max.value!=""){
			rent_max.value="";
		}
	}
	//Find element parent with particular tag name
	function getElementParentTag(ele, tag){
		while(ele){
			if(ele.tagName==tag){
				return ele;
			}
			ele=ele.parentNode;
		}
		return null;
	}
	//
	function getDivFromParent(parent){
		var eleList=parent.childNodes;
		var retList=new Array();
		if(eleList.length < 1){return;}
		for(i=0;i<eleList.length;i++){
			if(typeof(eleList[i])=="undefined"){return;}
			if(arrayFilterClass(eleList[i],claName)){
				retList.push(eleList[i]);
			}
		}
		return retList;
	}
	//
	function arrayFilterClass(x,claName){
		if(x.className==claName){
			return true;
		}
		return false;
	}
	//
	function adjustDivDisplay(ele,divList){
        if (!ele.target) {
            ele.target = ele.srcElement || document;
        }
		ele=ele.target;
		eleAdjustDivDisplay(ele,divList);
	}
	function eleAdjustDivDisplay(ele,divList,pclassid){
		if(ele.value==1){
			if((typeof(document.getElementById('rent-min'))!=undefined)&&(typeof(document.getElementById('rent-max'))!=undefined)){
				document.getElementById('rent-min').value="";
				document.getElementById('rent-max').value="";
			}
		}else{
			if((typeof(document.getElementById('price-min'))!=undefined)&&(typeof(document.getElementById('price-max'))!=undefined)){
				document.getElementById('price-min').value="";
				document.getElementById('price-max').value="";
			}
		}
		if(divList.length < 1){return;}
		if(document.getElementById("pclassid")!==undefined){
			document.getElementById("pclassid").value=ele.value;
		}
		for(i=0;i<divList.length;i++){
			eleName=divList[i].getAttribute("name");
			if(typeof(eleName)===undefined){return;}
			nameValueList = new Array();
			if(eleName.indexOf('_')== -1){
				nameValueList.push(eleName);
			}
			else{
				nameValueList = eleName.split("_");
			}
			for(j=0;j<nameValueList.length;j++){
				if(nameValueList[j]==null){continue;}
				if(nameValueList[j]==ele.value){
					divList[i].style.display="block";
					break;
				}
				else{
					divList[i].style.display="none";
				}
			}
			nameValueList=null;
		}
	}
	//
	function attachEvent(target, functionref, tasktype){
		var tasktype=(window.addEventListener)? tasktype : "on"+tasktype
		if (target.addEventListener)
			target.addEventListener(tasktype, functionref, false)
		else if (target.attachEvent)
			target.attachEvent(tasktype, functionref)
	}
	//
	attachEvent(window, initSearch, 'load');
})();

function popup(mylink, windowname, width,height)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, 'width='+width+',height='+height+',scrollbars=yes');
return false;
}
function SubmitPage(){
	if((parseInt(document.getElementById('cur_page_plus').value)=='NaN')||(parseInt(document.getElementById('cur_page_plus').value)==NaN)){
		return false;
	}
	document.getElementById('cur_page').value=parseInt(document.getElementById('cur_page_plus').value)-1;
	return;
}
