/*系统函数*/

/*自定义trim*/
String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.ltrim = function() {
	return this.replace(/(^\s*)/g, "");
}
String.prototype.rtrim = function() {
	return this.replace(/(\s*$)/g, "");
}
String.prototype.strim = function() { 
	var vStr = "";
	vArr=this.split(" ");
	for(i=0; i<vArr.length; i++) vStr+=vArr[i];
	return vStr;
} 

/*自定义request*/
function request(paras){ 
	var url = location.href;
	var paraString = url.substring(url.indexOf("?")+1,url.length).split("&");
	var paraObj = {}
	for (i=0; j=paraString[i]; i++){paraObj[j.substring(0,j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=")+1,j.length);}
	var returnValue = paraObj[paras.toLowerCase()]; 
	if(typeof(returnValue)=="undefined") return ""; else return returnValue;
}

/*判断对象存在*/
function getID(vobj){
	var vgetID = document.getElementById(vobj);
	if (null != vgetID && vgetID) return true; else return false;
}

/*Url编码函数*/
function UrlEncode(vstr){
	var ret="";
	var strSpecial="!\"#$%&'()*+,/:;<=>?[]^`{|}~%";
	for(var i=0;i<vstr.length;i++){
		var chr = vstr.charAt(i);
		var c=str2asc(chr);
		if(parseInt("0x"+c) > 0x7f){
		ret+="%"+c.slice(0,2)+"%"+c.slice(-2);
		}else{
			if(chr == " "){
				ret+="+";
			}else if(strSpecial.indexOf(chr)!=-1){
				ret+="%"+c.toString(16);
			}else{
				ret+=chr;
			}
		}
	}
	return ret;
}

/*Url解码函数*/
function UrlDecode(vstr){ 
	var ret="";
	for(var i=0;i<vstr.length;i++){
		var chr = vstr.charAt(i);
		if(chr == "+"){
			ret+=" ";
		}else if(chr=="%"){
			var asc = vstr.substring(i+1,i+3);
			if(parseInt("0x"+asc)>0x7f){
				ret+=asc2str(parseInt("0x"+asc+vstr.substring(i+4,i+6)));
				i+=5;
			}else{
				ret+=asc2str(parseInt("0x"+asc));
				i+=2;
			}
		}else{
			ret+= chr;
		}
	}
	return ret;
}

/*页面函数*/
/*公用loading*/
function showLoading(vobj,vstr) {
	if (vstr==undefined) vstr="正在加载...";
	$(vobj).html('<div id="loading">'+vstr+'</div>');
}

/*设置系统菜单*/
var vcurri = "";
var vMenuMouse = "0";
function MenuInit() {
	$('.MenuFrag').hide();
	$('.MenuFrag').mouseover(function(){
		setMenuMouse("1");
	});
	$('.MenuFrag').mouseout(function(){
		setMenuMouse("0");
	});

	$('#fMenuCntt li').each(function(i){
		if ($(this).attr("classname")=="MenuCntt-selected"){
			vcurri = i;
			$('#fragment-'+(i+1)).show();
		}
		$(this).mouseover(function(){
			setMenuMouse("1");
			$('.MenuFrag').hide();
			$('#fMenuCntt li').removeClass();
			$(this).addClass("MenuCntt-selected");
			$('#fragment-'+(i+1)).show();
		});
		$(this).mouseout(function(){
			setMenuMouse("0");
			testMenuMouse = setTimeout("checkMenuMouse()", 500);
		});
	});
}

function searchKey(theKey){
	theKey = escape(theKey);
	window.open("search2.asp?query="+theKey);
}

function checkMenuMouse(){
	clearTimeout(testMenuMouse);
	if (vMenuMouse=="0"){
		$('.MenuFrag').hide();
		$('#fMenuCntt li').removeClass();
		$('#fMenuCntt li').eq(vcurri).addClass("MenuCntt-selected");
		$('#fragment-'+(vcurri+1)).show();
	}else{
		testMenuMouse = setTimeout("checkMenuMouse()", 500);
	}
}

function setMenuMouse(n) { vMenuMouse = n;}

/*调用城市信息列表页面*/
function goLinkCityInfo() {
	window.open("/Include/MoreInfo.asp?Define_Type=City&New_code="+currinfoid);
}

/*调用城市页面*/
function goCityLink(vint){
	var CityId = vint;
	if (CityId != ""){
		window.open("/citydata/city_home.aspx?areaid="+CityId);
	}
}

function goLinkInter(vStr){
	alert($('.InfoListTitl:contains('+vStr+')').html());
	$('.InfoListTitl:contains('+vStr+') a').focus();
}

/*调用中宏关注*/
function goLinkFocus(){
	window.open("/search_zhengfu.asp","mcss","menubar=no,toolbar=no,location=no,status=no,scrollbars=no,resizable=no,width=720,height=460,left=0,top=0");
}

function setLink(vobj){
	if (request("areaid")==""){
	}else{
		var url = location.href;
		var vpara = url.substring(url.indexOf("?")+1,url.length);
		var vhref = $('#fTabsA li a').eq(vobj).attr("href")+"?"+vpara;
		$('#fTabsA li a').eq(vobj).attr("href",vhref);
	}
}

/*得到相关位次列表*/
function getTaxisList(id,who,num) {
	who = "#"+who+" ul";

	$.ajax({
		url: "/CityData/get_taxis.aspx",
		type: "get",//使用get方法访问后台
		dataType:"json",//返回json格式的数据
		data: "&areaid="+id+"&indexid="+num,//要发送的数据
		beforeSend: function(){//AJAX请求开始时加载loading提示
			showLoading(who);
		},
		success: function(data){//AJAX请求成功返回数据
			$(who).fadeOut("slow", function(){
				var vwhostr = "";
				$.each(data.taxis, function(i,item){
					vwhostr += '<li><a target="_blank" href="city_taxis.aspx?type='+(i+1)+'&indexids='+num+'&areaid='+id+'" title="点击查看详细内容"><h3>'+item.n+'</h3><h4>第<span>'+item.t+'</span>名</h4></a></li>';
				});
				$(who).html(vwhostr);
			});
		},
		complete : function(){$(who).fadeIn("fast");}
	});
}

/*得到城市指数列表*/
function getMcidxList(id,who,num) {
	who = "#"+who+" ul";

	$.ajax({
		url: "/CityData/get_mcidx.aspx",
		type: "get",//使用get方法访问后台
		dataType:"json",//返回json格式的数据
		data: "&areaid="+id+"&type="+num,//要发送的数据
		beforeSend: function(){//AJAX请求开始时加载loading提示
			showLoading(who);
		},
		success: function(data){//AJAX请求成功返回数据
			$(who).fadeOut("slow", function(){
				var vwhostr = "";
				$.each(data.mcidx, function(i,item){
					vwhostr += '<li><a target="_blank" href="city_index.aspx?type='+num+'&areaid='+id+'" title="点击查看详细内容"><h3>'+item.n+'</h3><h4>第<span>'+item.t+'</span>名</h4></a></li>';
				});
				$(who).html(vwhostr);
			});
		},
		complete : function(){$(who).fadeIn("fast");}
	});
}

/*得到相关城市列表*/
function getCityList(id,type,who,num,self) {
	who = "#"+who+" ul";
	//if (who=="#fCompSelsCnttA"){$("#fCompSelsCnttB").html("");$("#CompSelsCnttB").hide();}
	//if (who=="#fCompSelsCnttB"&&num==3){num=6;}
	
	$.ajax({
		url: "/CityData/citys.aspx",
		type: "get",//使用get方法访问后台
		dataType:"json",//返回json格式的数据
		data: "p="+type+"&areaid="+id+"&num="+num+"&self="+self,//要发送的数据
		beforeSend: function(){//AJAX请求开始时加载loading提示
			showLoading(who);
		},
		success: function(data){//AJAX请求成功返回数据
			$(who).fadeOut("slow", function(){
				var vwhostr = "";
				$.each(data.citys, function(i,item){
					vwhostr += '<li><input type="checkbox" name="cb" id="'+item.id+'" /><a href="javascript:void(0);" onclick="goCityLink('+item.id+')">'+item.name+'</a></li>';
				});
				$(who).html(vwhostr);
			});
		},
		complete : function(){$(who).fadeIn("fast");}
	});
}

/*显示相关城市列表*/
function buildCityList(vobjA,vobjB,vstr) {
	$('#'+vobjA).append('<div class="InfoPanl" id="'+vobjB+'"><div class="InfoPanlTitl"><span class="InfoPanlTitlCntt">['+vstr+']</span><span class="InfoPanlTitlFunc"></span></div><ul class="InfoPanlCntt"></ul><div class="InfoPanlFunc"><input type="button" value="与所选城市比较" class="func_btn"></div></div>');
	$('#'+vobjB+' input[@value="与所选城市比较"]').click(function(){
		varr = $('#'+vobjB+' ul input[@checked]');
		if (varr.length > 5){
			alert("请最多选择五个城市进行比较！");
			return false;
		}else if (varr.length == 0){
			alert("请先选择城市再进行比较！");
			return false;
		}else{
			var vlnk = "";
			for (i = 0; i < varr.length; i++){
 				vlnk += ','+$(varr[i]).attr('id');
			}
			vlnk = currcityid+vlnk;
			window.open("/citydata/city_compare.aspx?areaid="+vlnk);
		}
	});
}

/*自定义下拉列表框*/
/*给一个列表框绑定一个对象*/
function setAlistB(vobjA,vobjB){
	$("#"+vobjA)
		.click(function(){showList(vobjB)})
		.mouseover(function(){setListVisible("1");})
		.mouseout(function(){setListVisible("0");});
	$("#"+vobjB)
		.css("position","absolute")
		.css("z-index","99999")
		.mouseover(function(){setListVisible("1");})
		.mouseout(function(){setListVisible("0");})
		.hide();
}
/*显示列表框*/
function showList(vobj){
	Jvobj = $("#"+vobj);
	var e = window.event.srcElement;
	var o = Jvobj;
	Jvobj.eventSrc = e;
	if (arguments.length == 0) Jvobj.objExport = e; else Jvobj.objExport = eval(arguments[0]);

	var t = e.offsetTop, h = e.clientHeight, l = e.offsetLeft, p = e.type;
	while (e = e.offsetParent){t += e.offsetTop; l += e.offsetLeft;}
	var cw = eval(vobj).clientWidth, ch = eval(vobj).clientHeight;
	var dw = document.body.clientWidth, dl = document.body.scrollLeft, dt = document.body.scrollTop;

	var ot,ol;
	if (document.body.clientHeight+dt-t-h >= ch) ot=(p=="image") ? t+h : t+h+8; else ot = (t-dt<ch) ? ((p=="image") ? t+h : t+h+8) : t-ch;
	if (dw+dl-l >= cw) ol = l; else ol = (dw >= cw) ? dw-cw+dl-25 : dl;

	o.show().css("top",ot).css("left",ol);
	testListVisible = setTimeout("checkListVisible('"+vobj+"')", 500);
}
/*隐藏列表框*/
function hideList(vobj){$("#"+vobj).hide();};
/*设置列表框隐藏状态*/
function setListVisible(n) { ListVisible = n;}
/*判断列表框隐藏状态*/
var ListVisible = "1";
function checkListVisible(vobj){
	clearTimeout(testListVisible);
	if (ListVisible == "0"){
		ListVisible = "1";
		hideList(vobj);
	} else {
		testListVisible = setTimeout("checkListVisible('"+vobj+"')", 500);
	}
}

//function document.onclick()
//{
//	if (window.event.srcElement.name != "ButWWFavdel") {
//  	if(Favorite_list.eventSrc != window.event.srcElement) hideList();
//	}
//}
//
///*重写event事件,以支持firefox*/
///*firefox go*/
//function __firefox(){
//HTMLElement.prototype.__defineGetter__("runtimeStyle", __element_style);
//window.constructor.prototype.__defineGetter__("event", __window_event);
//Event.prototype.__defineGetter__("srcElement", __event_srcElement);
//}
//function __element_style(){
//	return this.style;
//}
//function __window_event(){
//	return __window_event_constructor();
//}
//function __event_srcElement(){
//	return this.target;
//}
//function __window_event_constructor(){
//	if(document.all){
//		return window.event;
//	}
//	var _caller = __window_event_constructor.caller;
//	while(_caller!=null){
//		var _argument = _caller.arguments[0];
//		if(_argument){
//			var _temp = _argument.constructor;
//			if(_temp.toString().indexOf("Event")!=-1){
//				return _argument;
//			}
//		}
//		_caller = _caller.caller;
//	}
//	return null; 
//}
//if(window.addEventListener){
//	__firefox();
//}
///*firefox end*/ 
