﻿function GetProvince(obj)
{   
	var str0 = "";
    var objs = $(obj);
    var strpost = "{}";
    var ajaxLoction = new Ajax(objs,"<img src='/App_Themes/Default/cximg/loading.gif' /> 正在载入中...","/WebService/JSON/WsPosition.asmx/GetProvince",2,strpost,function(rexm){GetLocationSuccessCallBack(objs, rexm, str0)});
    ajaxLoction.post();
}

function GetCities(obj, pid, pName)
{   
	var str0 = pName;
    var objs = $(obj);
    var strpost = "{'provinceId':'"+pid+"'}";
    var ajaxCity = new Ajax(objs,"<img src='/App_Themes/Default/cximg/loading.gif' /> 正在载入中...","/WebService/JSON/WsPosition.asmx/GetCities",2,strpost,function(rexm){GetLocationSuccessCallBack(objs, rexm, str0)});
    ajaxCity.post();
}

function GetLocationSuccessCallBack(obj, rexm, str0){
    var data = eval("(" + rexm + ")");
    var str = "";
	if(str0!=""){
		str += "<div class='ptitle'>" + str0 + ">></div>";
	}
    str += "<ul>";
    for(var i=0;i<data.length;i++){
        str += "<li>";
            if(data[i].CityId>0)
            {
				if(data[i].CityId == 1 || data[i].CityId == 2 || data[i].CityId ==3 || data[i].CityId == 6 || data[i].CityId == 4){
					str += "<a href=\"\" onclick=\" SetCookie('province','"+data[i].ProvinceId+"');SetCookie('city','"+data[i].CityId+"'); var i,m;var url=location.href.toLowerCase();i=url.indexOf('usedhouse');if(i>0){window.location.href='http://www.foloda.com/house/UsedHouse.aspx?ht=0';return false;} i=url.indexOf('renthouse');if(i>0){window.location='http://www.foloda.com/house/RentHouse.aspx?ht=1';return false;} i=url.indexOf('html/house'); if(i>0){window.location.href='http://www.foloda.com/house/UsedHouse.aspx?ht=0';return false;}  i=url.indexOf('broker/search.aspx'); if(i>0){window.location.href='http://www.foloda.com/Broker/Search.aspx';return false;} window.location=window.location;return false;\" class='scity'>"+ data[i].Name +"</a>";
                }else{
					str += "<a href=\"\" onclick=\" SetCookie('province','"+data[i].ProvinceId+"');SetCookie('city','"+data[i].CityId+"'); var i,m;var url=location.href.toLowerCase();i=url.indexOf('usedhouse');if(i>0){window.location.href='http://www.foloda.com/house/UsedHouse.aspx?ht=0';return false;} i=url.indexOf('renthouse');if(i>0){window.location='http://www.foloda.com/house/RentHouse.aspx?ht=1';return false;}  i=url.indexOf('html/house');if(i>0){window.location.href='http://www.foloda.com/house/UsedHouse.aspx?ht=0';return false;}  i=url.indexOf('broker/search.aspx'); if(i>0){window.location.href='http://www.foloda.com/Broker/Search.aspx';return false;} window.location=window.location;return false;\">"+ data[i].Name +"</a>";
					//str += "<a href=\"\" onclick=\"SetCookie('province','"+data[i].ProvinceId+"');SetCookie('city','"+data[i].CityId+"');window.location='http://www2.foloda.com/';return false;\">"+ data[i].Name +"</a>";
                }
				//Rederict('"+data[i].ProvinceId+"','"+data[i].CityId+"')
            }
            else
            {
				//str += "<span style='color:#ccc'>" + data[i].Name + "</span>"
				str += "<a href=\"\" onclick=\"GetCities('"+obj.id+"', '"+data[i].ProvinceId+"', '"+data[i].Name+"');return false;\">"+ data[i].Name +"</a>";
            }
        str += "</li>";
    }
    str += "</ul>";
    // I AM TOO TALENTED!
    str += "<iframe src=\"javascript:false\" style=\"position:absolute; visibility:inherit; top:0px; left:0px; width:331px; height:200px; z-index:-1; filter='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';opacity: 0.0;-moz-opacity: 0.0;\"></iframe>";
    
    obj.innerHTML = str;

}

function SetCookie(name, value) { 
    var expdate = new Date();
    var expires = 365;
    var path = "/";
    var domain = ".foloda.com";
    if(expires!=null && expires>=0) expdate.setTime(expdate.getTime() + expires*24*60*60*1000);
    document.cookie = name + "=" + escape (value) +((expires == null || expires < 0) ? ((expires==-1)?"; expires=-1":"") : ("; expires="+ expdate.toGMTString()))
    +((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain));
}

function ShowCityDiv(){
	// 依照原始的方式是這樣設定的
//	if(GetObj('newDiv')!=null) return;
//	var newElement = document.createElement('div');
//	newElement.id = 'changeCityDiv';
//	//newElement.className = 'newDivClass';
//	//newElement.setAttribute('name ','newDivName');
//	newElement.style.width = '320px';
//	newElement.style.height = '200px';
//	newElement.style.margin = '30 auto';
//	newElement.style.position = 'absolute';
//	newElement.style.top = '80px';
//	newElement.style.left = '60px';
//	newElement.style.border = '1px solid #DDD';
    var Element = $('changeCityDiv');
	//Element.innerHTML = "<div onMouseOut='HideDiv()'><div align=right style='padding-right:5px;padding-top:5px; background:#FFFFFF;display:none;'><img src='http://www.foloda.com/Images/x.gif' onclick='HideDiv()' /></div><iframe marginwidth='1' marginheight='1' height='200' width='100%' scrolling='no' frameborder='0' src=\'http://club.foloda.com/Location/ChangeCity2.aspx\'></iframe></div>";
	//document.body.appendChild(newElement);
	Element.style.display="block";
	Element.focus();
}

function HideDiv()
{
	var Element = $('changeCityDiv');
	if(Element==null) return;
	Element.style.display="none";
	//document.body.removeChild(Element);
}
