//show the corresponding options to different categories
function disableOptions(indication){
	//alert("here");
	
	var houseRentDiv=document.getElementById("houseRentID");
	var officeDiv=document.getElementById("officeID");
	var storeDiv=document.getElementById("storeID");
	var houseSellDiv=document.getElementById("houseSellID");
	var priceFormatDiv1=document.getElementById("priceFormat1");
	var priceFormatDiv2=document.getElementById("priceFormat2");
	
	var obj1=window.document.searchForm.usage1;//住宅用途
	var objLen1=obj1.length;
	var obj2=window.document.searchForm.usage2;//商用辦公用途
	var objLen2=obj2.length;
	var obj3=window.document.searchForm.usage3;//頂讓用途
	var objLen3=obj3.length;
	var obj4=window.document.searchForm.usage4;//買賣用途
	var objLen4=obj4.length;	
	
	if(indication=="houseRentID"){		
		houseRentDiv.style.display="block";
		officeDiv.style.display="none";
		storeDiv.style.display="none";
		houseSellDiv.style.display="none";
		for(var i=0;i<objLen1;i++)
			obj1[i].disabled=false;
		for(var i=0;i<objLen2;i++)
			obj2[i].disabled=false;
		priceFormatDiv2.style.display="none";
		priceFormatDiv1.style.display="block";
	}
	else if(indication=="officeID"){
		houseRentDiv.style.display="none";
		officeDiv.style.display="block";
		storeDiv.style.display="none";
		houseSellDiv.style.display="none";
		for(var i=0;i<objLen1;i++)
			obj1[i].disabled=false;
		for(var i=0;i<objLen2;i++)
			obj2[i].disabled=false;
		priceFormatDiv2.style.display="none";
		priceFormatDiv1.style.display="block";
	}
	else if(indication=="storeID"){
		houseRentDiv.style.display="none";
		officeDiv.style.display="none";
		storeDiv.style.display="block";
		houseSellDiv.style.display="none";
		for(var i=0;i<objLen3;i++)
			obj3[i].disabled=false;
		for(var i=0;i<objLen3;i++)
			obj3[i].disabled=false;
		priceFormatDiv2.style.display="none";
		priceFormatDiv1.style.display="block";
	}
	else if(indication=="houseSellID"){
		houseRentDiv.style.display="none";
		officeDiv.style.display="none";
		storeDiv.style.display="none";
		houseSellDiv.style.display="block";
		for(var i=0;i<objLen4;i++)
			obj4[i].disabled=false;
		for(var i=0;i<objLen4;i++)
			obj4[i].disabled=false;
		priceFormatDiv1.style.display="none";
		priceFormatDiv2.style.display="block";		
	}	
}

function removeWhereDiv(id){
	document.getElementById(id).innerHTML = "";
}

function changeFilter(id){
	//alert('~~~~~~~~~~');
	var ary=new Array('n','c','s','e','i');
	for(var i =0; i<ary.length; i++){
		if(ary[i]==id){
			document.getElementById(id).style.backgroundImage = "url(images/icons/selected.gif)";
			document.getElementById(id).style.backgroundRepeat = "no-repeat";
		}
		else
			document.getElementById(ary[i]).style.backgroundImage = 'none';
	}	
}

function changeCityFilter(id){
	var ary=new Array('n','c','s','e','i');
	var ids = id.split('-');
	for(var i =0; i<ary.length; i++){
		if(ary[i]==ids[0]){
			//clear city background images
			var size = 0;
			if(i==0) size = north.length;
			if(i==1) size = center.length;
			if(i==2) size = south.length;
			if(i==3) size = east.length;
			if(i==4) size = island.length;
			
			for(var j=0; j<size; j++)
				document.getElementById(ids[0]+'-'+j).style.backgroundImage = 'none';
			document.getElementById(id).style.backgroundImage = "url(images/icons/selected.gif)";
			document.getElementById(id).style.backgroundRepeat = "no-repeat";
		}
		//else
		//	document.getElementById(ary[i]).style.backgroundImage = 'none';
	}	
}

function changeSort(id){
	var ary=new Array('time','price');
	for(var i =0; i<ary.length; i++){
		if(ary[i]==id){
			document.getElementById(id).style.backgroundImage = "url('images/icons/selected.gif')";
			document.getElementById(id).style.backgroundRepeat = "no-repeat";
		}
		else
			document.getElementById(ary[i]).style.backgroundImage = 'none';
	}	
}

function defaultCheck(){
	var ary1=new Array('n','c','s','e','i');
	var ary2=new Array('time','price');
	for(var i =0; i<ary1.length; i++){
		document.getElementById(ary1[i]).style.backgroundImage = 'none';	
	}
	for(var i =0; i<ary2.length; i++){
		document.getElementById(ary2[i]).style.backgroundImage = 'none';	
	}
	document.getElementById('cities').style.display = 'none';	
}

function showCities(area){
	$('cities').empty();
	document.getElementById('cities').style.display = 'block';	
	var citiesString = '';
	
	if(area=='north')
	{		
		for(var i=0; i<north.length; i++)		
			citiesString += "<a class='cursor' id='n-"+i+"' onclick=\"changeCityFilter('n-"+i+"');findObj('result','getSelectResult.php?city=n-"+i+"');\">"+north[i]+"</a>  ";
		citiesString = "北部: "+citiesString;
		//alert(html);
	}
	if(area=='center')
	{		
		for(var i=0; i<center.length; i++)		
			citiesString += "<a class='cursor' id='c-"+i+"' onclick=\"changeCityFilter('c-"+i+"');findObj('result','getSelectResult.php?city=c-"+i+"');\">"+center[i]+"</a>  ";
		citiesString = "中部: "+citiesString;
	}
	if(area=='south')
	{
		for(var i=0; i<south.length; i++)		
			citiesString += "<a class='cursor' id='s-"+i+"' onclick=\"changeCityFilter('s-"+i+"');findObj('result','getSelectResult.php?city=s-"+i+"');\">"+south[i]+"</a>  ";
		citiesString = "南部: "+citiesString;
	}
	if(area=='east')
	{
		for(var i=0; i<east.length; i++)		
			citiesString += "<a class='cursor' id='e-"+i+"' onclick=\"changeCityFilter('e-"+i+"');findObj('result','getSelectResult.php?city=e-"+i+"');\">"+east[i]+"</a>  ";
		citiesString = "東部: "+citiesString;
	}
	if(area=='island')
	{
		for(var i=0; i<island.length; i++)		
			citiesString += "<a class='cursor' id='i-"+i+"' onclick=\"changeCityFilter('i-"+i+"');findObj('result','getSelectResult.php?city=i-"+i+"');\">"+island[i]+"</a>  ";
		citiesString = "外島: "+citiesString;
	}
	
	var cityOptions = new Element('div', {	    
		'html': citiesString,
	    'styles': {
	        'width': '95%',
	        'height': '20px',
	        'border': '1px solid #64a700',
	        'background-color': '#e9ffcd'	        
	    }
	});
	
	var citiesRoot = $('cities');
	cityOptions.inject(citiesRoot);
}

function showSearchCities(area,searchkind,searchkeyword,addition){
	$('cities').empty();
	var citiesString = '';
	
	if(area=='north')
	{		
		for(var i=0; i<north.length; i++)		
			citiesString += "<a class='cursor' id='n-"+i+"' onclick=changeCityFilter('n-"+i+"');findObj('result','getSelectResult.php?city=n-"+i+"');>"+north[i]+"</a>  ";
		citiesString = "北部: "+citiesString;
		//alert(citiesString);
	}
	if(area=='center')
	{		
		for(var i=0; i<center.length; i++)		
			citiesString += "<a class='cursor' id='c-"+i+"' onclick=changeCityFilter('c-"+i+"');findObj('result','getSelectResult.php?city=c-"+i+"');>"+center[i]+"</a>  ";
		citiesString = "中部: "+citiesString;
	}
	if(area=='south')
	{		
		for(var i=0; i<south.length; i++)		
			citiesString += "<a class='cursor' id='s-"+i+"' onclick=changeCityFilter('s-"+i+"');findObj('result','getSelectResult.php?city=s-"+i+"');>"+south[i]+"</a>  ";
		citiesString = "南部: "+citiesString;		
	}
	if(area=='east')
	{
		for(var i=0; i<east.length; i++)		
			citiesString += "<a class='cursor' id='e-"+i+"' onclick=changeCityFilter('e-"+i+"');findObj('result','getSelectResult.php?city=e-"+i+"');>"+east[i]+"</a>  ";
		citiesString = "東部: "+citiesString;
	}
	if(area=='island')
	{
		for(var i=0; i<island.length; i++)		
			citiesString += "<a class='cursor' id='i-"+i+"' onclick=changeCityFilter('i-"+i+"');findObj('result','getSelectResult.php?city=i-"+i+"');>"+island[i]+"</a>  ";
		citiesString = "外島: "+citiesString;
	}
	
	var cityOptions = new Element('div', {	    
		'html': citiesString,
	    'styles': {
	        'width': '95%',
	        'height': '20px',
	        'border': '1px solid #64a700',
	        'background-color': '#e9ffcd'	        
	    }
	});
	
	var citiesRoot = $('cities');
	cityOptions.inject(citiesRoot);
}

function addToItemCompare(clickid, tagid, id)
{
	
	if($(clickid).checked)
	{
		if($(tagid).get('text')=='')
			$(tagid).appendText(id);
		else		
			$(tagid).appendText(','+id);			
	}
	else
	{
		var newsIds = '';
		var ids = $(tagid).get('text').split(',');		
		for(var i=0;i<ids.length;i++)
		{
			if(ids[i]!=id)			
				newsIds += ids[i]+',';			
		}
		newsIds = newsIds.substr(0,newsIds.length-1);
		$(tagid).set('text','');
		$(tagid).appendText(newsIds);
	}
	//alert($(tagid).get('text'));
}

function goComparePage(tagid,url)
{
	if($(tagid).get('text')=='')
	{
		alert('請選擇遇比較物件。');
		return false;
	}
	var kind = '';
	if(tagid=='roomCompare')
		kind = '?kind=room&ids=';
	if(tagid=='officeCompare')
		kind = '?kind=office&ids=';
	if(tagid=='sellCompare')
		kind = '?kind=sell&ids=';
	if(tagid=='storeCompare')
		kind = '?kind=store&ids=';
	var toUrl = url+kind+$(tagid).get('text');
	window.open(toUrl,'選擇物件比較表','width=700,height=500,toolbar=no,scrollbars=yes,menubar=no');
	
}

function changeTab(index)
{
	  	var i = 0;
	$('tabsJ').getElements('li').each(function(el){
		if(i==index)
		{
			el.getElement('a').set('class','click');
			el.getElement('span').set('class','span-click');
		}
		else
		{
			el.getElement('a').set('class','');
			el.getElement('span').set('class','');
		}
		i++;
	});
}	

function showSubClass(id)
{
	//alert('-------'+$(id).checked);
	$$('.map-search-loading').setStyle('display','block');
	clear();
	var divId = id.split('-')[1];
	if($(id).checked==true)
	{		
		$('submenu').empty();
		$('map-menu').getElements('input').each(function(el){
			if(el.get('id')!=id)
				el.checked=false;
		});
		//var lat = $('CurMarkerLat').get('value');
		var lat = document.getElementById('CurMarkerLat').innerHTML;
		var lon = document.getElementById('CurMarkerLng').innerHTML;		
		//alert('-lat--'+lat+'-lng--'+lon);
		findObj('submenu','getYahooClass.php?class='+divId+'&lon='+lon+'&lat='+lat); 
	}
	else
	{		
		$('submenu').empty();
	}
	$$('.map-search-loading').setStyle('display','none');	
}

function sendReport(ids,fieldnames)
{	
	if(chkEmpty(ids,fieldnames,false))
	{
		var req = new Request({
				method: 'get',
				url: 'http://'+window.location.hostname+'/reportProcess.php?email='+$('report-email').value+'&opinion='+$('report-opinion').value,
				//data: {'email':$('report-email').value, 'opinion':$('report-opinion').value},
				onFailure: function() { $('report-result').set('html','送出失敗，請再試一次。');},
				onRequest:  function() {  $('report-result').set('html','正在送出資料，請耐心等候。');  },
				onComplete:  function(response) { $('report-result').set('html','感謝您寶貴的意見。');$('light').set('tween', {duration: 2000});$('fade').set('tween', {duration: 2000});$('light').tween('opacity',0);$('fade').tween('opacity',0);  } 
		}).send(); 		
		//document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none';
	}
}

/*
//for the main page scrolling ad
function scrollAd1(demotag1,demotag2,demotag3){
	var demo = document.getElementById(demotag1);
	var demo1 = document.getElementById(demotag2);
	var demo2 = document.getElementById(demotag3);
	var speed=50;    
	demo2.innerHTML = demo1.innerHTML;    
	function Marquee(){
	    if(demo2.offsetTop-demo.scrollTop<=0)    
	        demo.scrollTop-=demo1.offsetHeight;    
	    else{
	        demo.scrollTop++;
	    }
	}
	var MyMar = setInterval(Marquee,speed);        
	demo.onmouseover = function(){clearInterval(MyMar);}    
	demo.onmouseout = function(){MyMar = setInterval(Marquee,speed);} 
}
function scrollAd2(demotag1,demotag2,demotag3){
	var demo = document.getElementById(demotag1);
	var demo1 = document.getElementById(demotag2);
	var demo2 = document.getElementById(demotag3);
	var speed=50;    
	demo2.innerHTML = demo1.innerHTML;    
	function Marquee(){
	    if(demo2.offsetTop-demo.scrollTop<=0)    
	        demo.scrollTop-=demo1.offsetHeight;    
	    else{
	        demo.scrollTop++;
	    }
	}
	var MyMar = setInterval(Marquee,speed);        
	demo.onmouseover = function(){clearInterval(MyMar);}    
	demo.onmouseout = function(){MyMar = setInterval(Marquee,speed);} 
}
*/
/*
//for picture use
//圖片按比例縮放
var flag=false;
function DrawImage(ImgD,iwidth,iheight){
var image=new Image();
//var iwidth = 160; //定義允許圖片寬度 當寬度大於此直 等比例縮小160
//var iheight = 120; //定義允許圖片高度 當高度大於此直 等比例縮小120
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= iwidth/iheight){
if(image.width>iwidth){ 
ImgD.width=iwidth;
ImgD.height=(image.height*iwidth)/image.width;
}else{
ImgD.width=image.width; 
ImgD.height=image.height;
}

ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>iheight){ 
ImgD.height=iheight;
ImgD.width=(image.width*iheight)/image.height; 
}else{
ImgD.width=image.width; 
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
}
} 
*/

/*
 * show posted photo on the top 
 * 
 */
 /*
function showPhoto(imgId,tagId,photoURL,picId){	
 	//document.getElementById(tagId).innerHTML="<img src="+photoURL+" border=0 onload="+DrawImage(this,250,250)+">";
 	document.getElementById(imgId).src=photoURL;
}

function toFixStringLen(str, limit){
	var newStr=""; 
	var ttl;
	if(limit==0)
		ttl=str.length/15;
	else{
		if(str.length>limit)
			str=str.substring(0,limit);
		ttl=str.length/15;		
	}
	for(var num=0; num<=ttl; num++)
	{
		if(num<=ttl)
			newStr+=str.slice(num*15, (num+1)*15)+"<br>";
		else
			newStr+=str.slice(num*15, str.length);
		//alert("~~newstr~~~"+newStr);			
	}
	return newStr;	
}
*/
