//判断浏览器 true是IE false是ff
var BROWSER = {};
//底部其他城市的显示层控制
var CAN_CLOSE = true;
function showCity(id){CAN_CLOSE = false;document.getElementById(id).style.display = "block";}
function hideCity(){CAN_CLOSE = true;setTimeout(function(){if(CAN_CLOSE)document.getElementById("hot_city").style.display = "none";},1000)}
var USERAGENT = navigator.userAgent.toLowerCase();
var isIE=(document.all)?true:false;
var isIE6 = false;
browserVersion({'ie':'msie','firefox':'','chrome':'','opera':'','safari':'','maxthon':'','mozilla':'','webkit':''});
if(BROWSER.safari) {
	BROWSER.firefox = true;
}
BROWSER.opera = BROWSER.opera ? opera.version() : 0;
window.onerror=function(){return true;}
function $(id){return document.getElementById(id);}
function showA(){
	alert("稍后开通！");
}
(function(){var i=window.DomReady={};var h=navigator.userAgent.toLowerCase();var c={version:(h.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/)||[])[1],safari:/webkit/.test(h),opera:/opera/.test(h),msie:(/msie/.test(h))&&(!/opera/.test(h)),mozilla:(/mozilla/.test(h))&&(!/(compatible|webkit)/.test(h))};var d=false;var e=false;var g=[];function a(){if(!e){e=true;if(g){for(var j=0;j<g.length;j++){g[j].call(window,[])}g=[]}}}function f(j){var k=window.onload;if(typeof window.onload!="function"){window.onload=j}else{window.onload=function(){if(k){k()}j()}}}function b(){if(d){return}d=true;if(document.addEventListener&&!c.opera){document.addEventListener("DOMContentLoaded",a,false)}if(c.msie&&window==top){(function(){if(e){return}try{document.documentElement.doScroll("left")}catch(k){setTimeout(arguments.callee,0);return}a()})()}if(c.opera){document.addEventListener("DOMContentLoaded",function(){if(e){return}for(var k=0;k<document.styleSheets.length;k++){if(document.styleSheets[k].disabled){setTimeout(arguments.callee,0);return}}a()},false)}if(c.safari){var j;(function(){if(e){return}if(document.readyState!="loaded"&&document.readyState!="complete"){setTimeout(arguments.callee,0);return}if(j===undefined){var k=document.getElementsByTagName("link");for(var l=0;l<k.length;l++){if(k[l].getAttribute("rel")=="stylesheet"){j++}}var m=document.getElementsByTagName("style");j+=m.length}if(document.styleSheets.length!=j){setTimeout(arguments.callee,0);return}a()})()}f(a)}i.ready=function(k,j){b();if(e){k.call(window,[])}else{g.push(function(){return k.call(window,[])})}};b()})();
function browserVersion(types) {
	var other = 1;
	for(i in types) {
		var v = types[i] ? types[i] : i;
		if(USERAGENT.indexOf(v) != -1) {
			var re = new RegExp(v + '(\\/|\\s)([\\d\\.]+)', 'ig');
			var matches = re.exec(USERAGENT);
			var ver = matches != null ? matches[2] : 0;
			other = ver !== 0 ? 0 : other;
		}else {
			var ver = 0;
		}
		eval('BROWSER.' + i + '= ver');
	}
	BROWSER.other = other;
}
if(BROWSER.ie) {
	document.documentElement.addBehavior("#default#userdata");
	isIE6 = BROWSER.ie==6;
}
function saveUserdata(name, data) {
	if(BROWSER.ie){
		with(document.documentElement) {
			setAttribute("value", data);
			save('MYFUN7_' + name);
		}
	} else if(window.sessionStorage){
		sessionStorage.setItem('MYFUN7_' + name, data);
	}
}

function loadUserdata(name) {
	if(BROWSER.ie){
		with(document.documentElement) {
			load('MYFUN7_' + name);
			return getAttribute("value");
	}
	} else if(window.sessionStorage){
		return sessionStorage.getItem('MYFUN7_' + name);
	}
}
var Cookie = {
   get : function(name){
       var value = "";
       var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
	   if(arr != null) { value=unescape(arr[2]); }
	   return value;
   },
   set : function(name,value,days){
       if(isNaN(days)){
               document.cookie=name + "=" + escape(value) + ';domain=myfun7.com;path=/';
       }else{
               document.cookie=name + "=" + escape(value) + ";expires="+new Date(new Date().getTime() + days*86400000).toGMTString()+ ';domain=myfun7.com;path=/';
       }
   },
   del : function(name){
       document.cookie=name + "=;expires="+new Date().toGMTString();
   },
   addCityDomainCookie : function(str){
	var m = /http:\/\/(\w+)\.myfun7/.exec(window.location);
	if (m != null) {
		var domain = m[1];
		if ( domain != 'www' && ! new RegExp('(^| )citydomain=' + escape(str) + '(;|$)').test(document.cookie) ) {
			Cookie.set("citydomain",str,365);
		}
	}
   }
}
function GLOBAL_INIT(){
	//全局初始化
	try { document.execCommand('BackgroundImageCache',false,true); }catch(e){}
}

function setTab(tabId,obj){
	var currSearch = $(tabId).getAttribute("currTab");
	var activeClass = $(tabId).getAttribute("activeClass");
	$(currSearch).className = "";
	$(currSearch+"_box").style.display = "none";
	if(activeClass!=null)obj.className = activeClass;
	$(obj.id+"_box").style.display = "";
	$(tabId).setAttribute("currTab",obj.id);
}
/**
 * AJAX类
 *  使用方法
  	var ajaxobj=new AJAXRequest;
	ajaxobj.method = "GET";
	ajaxobj.url = tempurl;
	ajaxobj.callback = function(xmlobj){
		var rsps_text = xmlobj.responseText.toString();
		alert(rsps_text);
	};
	ajaxobj.send();
 * @return {Boolean}
 */
function AJAXRequest() {
	var xmlObj = false;
	var CBfunc,ObjSelf;
	ObjSelf=this;
	try { xmlObj=new XMLHttpRequest; }
	catch(e) {
		try { xmlObj=new ActiveXObject("MSXML2.XMLHTTP"); }
		catch(e2) {
			try { xmlObj=new ActiveXObject("Microsoft.XMLHTTP"); }
			catch(e3) { xmlObj=false; }
		}
	}
	if (!xmlObj) return false;
	this.method="POST";
	this.url;
	this.async=true;
	this.content="";
	this.callback=function(cbobj) {return;}
	this.overtime=function() {return;}
	this.send=function() {
		if(!this.method||!this.url||!this.async) return false;
		xmlObj.open (this.method, this.url, this.async);
		if(this.method=="POST") xmlObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlObj.onreadystatechange=function() {
			if(xmlObj.readyState==4) {
				if(xmlObj.status==200) {
					ObjSelf.callback(xmlObj);
				}else{
					ObjSelf.overtime();
				}
			}
		}
		if(this.method=="POST") xmlObj.send(this.content);
		else xmlObj.send(null);
	}
}
var ajax = function(config){
	var ajaxobj=new AJAXRequest;
	ajaxobj.method = (typeof(config.type)!="undefined")?config.type:"GET";
	ajaxobj.url = config.url;
	ajaxobj.callback = config.success;
	ajaxobj.send();
	return ajaxobj;
}
String.prototype.replaceAll = function(content,replayWith){   
	return this.replace(new RegExp(content,"gm"),replayWith);   
}
String.prototype.ltrim = function ltrim(){
	return this.replace(/^\s*/gi,"");
}
String.prototype.rtrim=function rtrim(){
	return this.replace(/\s*$/gi,"");
}
String.prototype.trim = function trim(){
	return this.toString().ltrim().rtrim();
}
String.prototype.toJson = function(){
	var str = this.replace(/\n|\r/gi,"");
	return eval('('+str+')');
}
function getDateDiff(postdate,systime){
	var second = 1000; 
	var minutes = second*60; 
	var hours = minutes*60; 
	var days = hours*24; 
	var months = days*30; 
	var twomonths = days*365; 
	var myDate = parseTime(postdate);
	var nowtime;
	if(typeof(systime)!="undefined"){
		nowtime = systime;
	}else{
		nowtime = new Date().getTime();
	}
	var longtime =nowtime- myDate.getTime(); 
	var showtime = 0; 
	if (longtime > months){
		return(Math.floor(longtime/months)+"个月前"); 
	}else if (longtime > days*7){ 
		return ("1周前"); 
	}else if (longtime > days){ 
		return(Math.floor(longtime/days)+"天前"); 
	}else if ( longtime > hours){ 
		return(Math.floor(longtime/hours)+"小时前"); 
	}else if (longtime > minutes){ 
		return(Math.floor(longtime/minutes)+"分钟前"); 
	}else if (longtime > second){ 
		return(Math.floor(longtime/second)+"秒前"); 
	}else{ 
		return postdate; 
	}
}
function parseTime(TIME_STR){
	var rtnDate = new Date(Date.parse(TIME_STR));
	var nowtime;
	if (isNaN(rtnDate)){
		if(TIME_STR.indexOf(".")!=-1)TIME_STR= TIME_STR.substring(0,TIME_STR.lastIndexOf(".")); 
		rtnDate =new Date(TIME_STR.replace(/-/g, "/")); 
	}
	return rtnDate;
}
function dynamicTime(obj,timeStr,sysTime){
	this.timeStr = timeStr;
	if(!this.timeStr){return;}
	var sysDateTime = parseTime(sysTime);
	sysDateTime = sysDateTime.getTime();
	obj.innerHTML = timeStr;
//	obj.innerHTML = getDateDiff(timeStr,sysDateTime);
//	setInterval(function(){
//		sysDateTime++;
//		obj.innerHTML = getDateDiff(timeStr,sysDateTime);
//	},1000);
}
/**
 *设置iframe的高度（iframe高度自适应，onload=“SetWinHeight(this)”）
 */
function SetWinHeight(obj) {
	var win = obj;
	if (document.getElementById) {
		if (win && !window.opera) {
			if (win.contentDocument && win.contentDocument.body.offsetHeight) {
				win.height = win.contentDocument.body.offsetHeight;
				win.width = win.contentDocument.body.offsetWidth;
			} else {
				if (win.Document && win.Document.body.scrollHeight) {
					win.height = win.Document.body.scrollHeight;
					win.width = win.Document.body.scrollWidth;
				}
			}
		}
	}
}
//弹出方法 弹出DIV
function showMessageBox(DivId,wTitle,mContent,wHeight,wWidth,contentType,showback){
	closeWindow(DivId);
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}


	var bWidth = parseInt(myWidth);
	var bHeight = parseInt(myHeight) > parseInt(document.documentElement.scrollHeight)? parseInt(myHeight) : parseInt(document.documentElement.scrollHeight);
	if(isIE){setSelectState('hidden');}
	var Content = (contentType == 1 ? "<iframe id='mIframe' src='' frameborder='0' width='100%' scrolling='no' height='" + (wHeight - 10) + "'>正在加载...</iframe>" : mContent);
	var styleStr = (showback == 0?("position:absolute;background:#000;width:" + (wWidth + 36) + "px;height:" + (wHeight + 60) + "px;left:" + (myWidth - wWidth - 20)/2 + "px;top:" + (myHeight - wHeight - 20)/2 + "px;z-index:999;"):("top:0px;left:0px;position:absolute;background:#666;width:" + "100%" + ";height:" + bHeight + "px" + ";z-index:999;"));
	styleStr += (isIE)?"filter:alpha(opacity=40);":"opacity:0.40;";
	if(document.getElementById('back') == null){
		var back = document.createElement("div");
		back.id = "back";
		back.style.cssText = styleStr;
		document.body.appendChild(back);
	}else{
		var back = document.getElementById('back');
		back.style.cssText = styleStr;
		back.style.visibility = "visible";
	}


	styleStr = "position:absolute;width:" + wWidth + "px;left:" + (myWidth - wWidth)/2 + "px;top: " + (myHeight - wHeight)/2 + "px;z-index:1000;";
	if(document.getElementById(DivId)==null){
		var mesW = document.createElement("div");
		mesW.id = DivId;
		mesW.className = "mesWindow";
		mesW.innerHTML = "<div class='mesWindowTop'><div class='mesWindowtitle'>" + wTitle + "</div><div class='mesWindowclose'><a href=\"javascript:void(0);\" onclick=\"closeWindow('" + DivId + "')\"></a></div></div>" + Content + "";
		mesW.style.cssText = styleStr;
		document.body.appendChild(mesW);
	}else{
		var mesW = document.getElementById(DivId);
		mesW.style.visibility = "visible";
		mesW.style.cssText = styleStr;
	}
	if(contentType == 1)$('mIframe').src = mContent;
}
//弹出DIV后的背影
function showBackground(obj,endInt){
	obj.filters.alpha.opacity+=5;
	if(obj.filters.alpha.opacity<endInt){
		setTimeout(function(){showBackground(obj,endInt)},8);
	}
}
//设置select的可见状态 
function setSelectState(state){
	var objl=document.getElementsByTagName('select');
	for(var i=0;i<objl.length;i++){
		objl[i].style.visibility=state;
	}
}
//关闭弹出窗口
function closeWindow(s){
	if(document.getElementById('back') != null){
		//document.getElementById('back').parentNode.removeChild(document.getElementById('back'));
		document.getElementById('back').style.visibility = "hidden";
	}
	if(document.getElementById(s) != null){
		//document.getElementById('mesWindow').parentNode.removeChild(document.getElementById('mesWindow'));
		document.getElementById(s).style.visibility = "hidden";
	}
	if(document.getElementById('mIframe') != null){
		document.getElementById('mIframe').src = "";
	}
	if(isIE){setSelectState('');}
}

//登录相关
function userLogin(){
	var userName = document.getElementById("userName").value;
	var password = document.getElementById("password").value;
	if(userName==""){
		alert("用户名不能为空！");
		return;
	}
	if(password==""){
		alert("密码不能为空！");
		return;
	}
	ajax({
	  	url: "/loginajax.sdo",
	  	data: "action=userLogin&userName="+userName+"&password="+password,
  		success: function(msg){
  		 	checkLogin(msg);
  		}
	});
}

function loginOut(){
	ajax({
	  	url: "/loginajax.sdo",
	  	data: "action=loginOut",
  		 success: function(msg){
  		 	window.location.reload();
  		}
	});
}

function checkLogin(){
	var div = document.getElementById("myfun_login");
	ajax({
	  	url: "/loginajax.sdo",
	  	data: "action=checkLogin",
  		success: function(msg){
  			var userName = msg.responseText;
			if(userName==""){
				var html = "<form name='login' id='login'>";
				html = html+'用户名：<input type="text"  name="userName" id="userName"/>';
				html = html+' 密  码：<input type="password" name="password" id="password"/>';
				html = html+'<input type="button" onclick="userLogin()" id="submit" value="登陆"/> <a href="/ucenter/register.htm" target="_blank">注册</a></form> '
				div.innerHTML = html;
			}else{
				div.innerHTML = "<p >欢迎你: <a href='/ucenter/usercenter.htm' target='_blank'><span style='color:red'>"+userName+"</span></a>  <a href='javascript:void(0)' onclick='loginOut();return false;'>注销</a></p>";
			}
  		}
	});
}

function copyaddr(text){
	if((navigator.userAgent.indexOf('MSIE') >= 0) && (navigator.userAgent.indexOf('Opera') < 0)){
	    window.clipboardData.setData('text',text); 
	    alert("复制成功,你可以粘贴到QQ、BBS、BLOG");
    }else{
    	alert("请在IE下使用该复制功能");
    }
} 

function addFriend(archiveId){
	ajax({
	  	url: "/ajax.sdo",
	  	data: "action=addFriend&archiveId="+archiveId,
  		 success: function(msg){
  		 	alert(msg);
  		}
	});
}
var moveAd = function(slot,target) {
    var adslot = document.getElementById(target), ifrm, ad_frame = document.getElementById('google_ads_iframe_' + slot);
    if (adslot == null){
	    return;
    }
    if (ad_frame) {
        ifrm = document.createElement('iframe');
        ifrm.setAttribute('id', 'google_ads_slot_iframe_' + slot);
        ifrm.setAttribute('frameBorder', 0);
        ifrm.setAttribute('scrolling', 'no');
        ifrm.setAttribute('width', ad_frame.getAttribute('width'));
        ifrm.setAttribute('height', ad_frame.getAttribute('height'));
        adslot.appendChild(ifrm);
        if(ad_frame.src && ad_frame.src.indexOf('http') != -1){
        	ifrm.src = ad_frame.src;
        }else{
        	ifrm.contentWindow.document.open();
	        ifrm.contentWindow.document.write(ad_frame.contentWindow.document.documentElement.innerHTML);
	        ifrm.contentWindow.document.close();
        }
    } else {
        var ad_div = document.getElementById('google_ads_div_' + slot) || document.getElementById('google_ads_div_' + slot + '_ad_container');
        if (ad_div) {
            adslot.appendChild(ad_div);
        }
    }
}

//绑定事件
var RegisterEvent=function(n,e,f,r){
	var method=true;
	if(typeof r!="undefined"){
		method=(r!=false);
	}
	if(document.addEventListener){
		// level 2 DOM prototype
		var eve=e.indexOf("on")==0?e.replace("on",""):e;
		try{
			n.addEventListener(eve,f,method);
			return true;
		}catch(e){
			return false;
		}
	}else if(document.attachEvent){
		// only for IE 5.0+
		var eve=e.indexOf("on")==0?e:"on"+e;
		try{
			n.attachEvent(eve,f);
			return true;
		}catch(e){
			return false;
		}
	}else{
		return false;
	}
}
var addEvent = function(obj, type, fn){
    if (obj.attachEvent)
        obj.attachEvent('on' + type, fn);
    else
        obj.addEventListener(type, fn, false);
}
var RemoveEvent=function(n,e,f,r){
	var method=true;
	if(typeof r!="undefined"){
		method=(r!=false);
	}
	if(document.addEventListener){
		// level 2 DOM prototype
		var eve=e.indexOf("on")==0?e.replace("on",""):e;
		try{
			n.removeEventListener(eve,f,method);
			return true;
		}catch(e){
			return false;
		}
	}else if(document.attachEvent){
		// only for IE 5.0+
		var eve=e.indexOf("on")!=0?e.replace("on",""):e;
		try{
			n.detachEvent(eve,f);
			return true;
		}catch(e){
			return false;
		}
	}else{
		return false;
	}
}
var EventStopProp=function(event){
	if(document.addEventListener){
		try{
			event.stopPropagation();
			event.preventDefault();
		}catch(e){
			return false;
		}

	}else if(document.attachEvent){
		try{
			event.cancelBubble=true;
			event.returnValue=false;
		}catch(e){
			return false;
		}
	}else{
		return false;
	}
}
try{
	Element.prototype.registerEvent=function(e,f,r){
		RegisterEvent(this,e,f,r);
	}
	Element.prototype.removeEvent=function(e,f,r){
		RemoveEvent(this,e,f,r);
	}
}catch(e){
}
if(!window.errors){
	window.errors=new Array();
}
DomReady.ready(function(){
	if(window.LOAD){
		for(var func,i=0;i<LOAD.length;i++){
			try{
				func=LOAD[i];
				if(typeof func=="string"){
					eval(func);
				}else if(typeof func=="function"){
					func.call();
				}
			}catch(e){
				window.errors.push(e);
			}
		}
		GLOBAL_INIT();
		//RegisterEvent(window,"load",_INIT_ONLOAD_EVENT_,true);
	}
});
