﻿function leaveGame(){
	return "更多惊喜期待着您！您确认要离开游戏吗?";
}
function closeConn(){
	document.getElementById("Loading").closeConn();
	document.getElementById("MapClient").closeConn();
}

function addBookmark(title,url){
    if(url == ""){url = window.location}
    if(window.sidebar){
        window.sidebar.addPanel(title,url,"");
    }else if(document.all){
        window.external.AddFavorite(url,title);
    }else{
        return true;
    }
}

function addBookmark1(){
	if(getcookie("isAddMark") == "fail"){
		setcookie("isAddMark","add",365);
		addBookmark(document.title,"");    	
  }	
}

function openWin(url){ 
 var frm = document.createElement("form");
 frm.method = "POST";
 frm.target = "_blank";
 frm.action = url;
 document.body.appendChild(frm);
 frm.submit();
}

function initLoginFrame(f_url){
	writeFrame(f_url);
	refreshFrame(f_url);
}

//iframe函数
function writeFrame(f_url){
	var f_obj = document.createElement("iframe");
	f_obj.id = "facebook";
	f_obj.src=f_url;
	f_obj.width=0;
	f_obj.heigth=0;
	f_obj.frameborder=0;
	document.body.appendChild(f_obj);
}
//定时刷新iframe
function refreshFrame(f_url){
	setInterval(function(){updateFrame(f_url);}, 30*60*1000);
}
//更新iframe地址
function updateFrame(f_url){
	var obj = document.getElementById("facebook");
    if(obj == null){
		writeFrame(f_url);
	}
	else{
		obj.src = f_url;
	}
}	
//人人的最新应用	
function writerrFrame(content){
        	var obj = document.getElementById("renren");
        	if(obj == null){
        		obj = document.createElement("div");
        		obj.id="renren";
        		obj.style.display="none";
        		document.body.appendChild(obj);
        	}
        	obj.innerHTML = '<div style="display:none"><iframe src="http://game.renren.com/stat?type=30"></iframe><iframe src="http://game.renren.com/page?appid=30&code=ts&height=827&ran=911"></iframe></div>';
        }
function writeUserCookie(){
	var userid = getcookie("societyguestid");
	if(userid != "fail"){
		var server = userid + "," +escape(window.location.hostname);
		setcookie("tsuserserver",server,1,"","mop.com");
	}
}


function getUserId(){
	var userid = getcookie("societyguestid");
	if(userid != "fail"){
		return userid + "," +window.location.hostname;
	}else{
		return "";
	}
}
//==============圈圈开始===================
function ibwSpInit()
{ 
		ibw.appid=652;//游戏编号
		ibw.color="192";//圈圈皮肤默认颜色 
		ibw.brightness="1.395";//圈圈皮肤默认亮度 
		ibw.saturation="0.068";//圈圈皮肤默认饱和度 
		ibw.barMode=1;// 圈圈默认显示的模式 
		ibw.barDisplay="block";//圈圈竖条默认显示状态（"none"：默认收缩； "block"：默认展开）
		ibw.barTop=100; ibw.barRight=30;//圈圈默认显示的位置
		ibw.needLogout=false;//圈圈是否需要注销功能（true：需要 false：不需要）（默认为true）
		ibw.isLoadIBWDirectly = true;//让ibw直接加载，需要设置此属性为true，否则ibw在dom ready时才加载
		//以下属性在IBW的1.0.2.2及以上版本支持
		ibw.barMinDirection = 1;// 竖条收缩方向 (1:上 2:下)

		//以下属性在IBW的1.0.2.3及以上版本支持
		ibw.horBarModeBeforeLogin = 1;//在登录前横条可最小化
		ibw.horBarStatusBeforeLogin =1;//在登录前横条最小化显示
}
//==================圈圈结束====================
var bossCome = true;
var tempTitle = "";
var bossEnable = false;

document.onkeydown = function (event){
	e = event || window.event;
	if(e.keyCode == 192){
		if(bossCome){
			bossShortCut(true);
			return false;
		}else{
			bossShortCut(false);
			return false;
		}
	}
}

function bossShortCut(come){
	$("hexie") || initImage();
	if(bossEnable){
		bossCome = !come;
		if(come){
			if(tempTitle == ""){
				tempTitle = document.title;
			}
			document.body.style.backgroundColor = "#fff";
			$("hexie").style.display = "block";
			changeTitile("_blank");
			document.body.focus();
		}else{
			document.body.style.backgroundColor = "#000";
			$("hexie").style.display = "none";
			changeTitile(tempTitle);
			tempTitle = "";
		}
	}
}

function changeTitile(title){
	document.title = title;
}

function $(el){
	return document.getElementById(el);
}

function bossSCenable(check){
	bossEnable = check;
}

function initImage(){
	var image = document.createElement("div");
	image.setAttribute("id","hexie");
	image.innerHTML = "<img src='images/boss.jpg' />";
	image.style.position = "absolute";
	image.style.top = "50%";
	image.style.left = "50%";
	image.style.marginTop = "-305px";
	image.style.marginLeft = "-502px";
	image.style.zIndex = 20;
	image.style.display = "none";
	document.body.appendChild(image);
}

var RightClick = {
	/**
	 *  Constructor
	 */ 
	init: function () {
		this.FlashObjectID = "Loading";
		this.FlashContainerID = "flashcontent";
		this.Cache = this.FlashObjectID;
		if(window.addEventListener){
			 window.addEventListener("mousedown", this.onGeckoMouse(), true);
		} else {
			document.getElementById(this.FlashContainerID).onmouseup = function() { document.getElementById(RightClick.FlashContainerID).releaseCapture(); }
			document.oncontextmenu = function(){ if(window.event.srcElement.id == RightClick.FlashObjectID) { return false; } else { RightClick.Cache = "nan"; }}
			document.getElementById(this.FlashContainerID).onmousedown = RightClick.onIEMouse;
		}
		if(document.getElementById(this.FlashObjectID) !=null){
			document.getElementById(this.FlashObjectID).focus();
			writeUserCookie();
		}else{
		    var url;
				if(window.sidebar){
					url = firefoxUrl;
				}else if(document.all){
					url = ieUrl;
				}else{
					url = firefoxUrl;
				}
		    document.getElementById(this.FlashContainerID).style.width = "1005px";
			  document.getElementById(this.FlashContainerID).innerHTML  = notice1+url+notice2;
		}
	},
	/**
	 * GECKO / WEBKIT event overkill
	 * @param {Object} eventObject
	 */
	killEvents: function(eventObject) {
		if(eventObject) {
			if (eventObject.stopPropagation) eventObject.stopPropagation();
			if (eventObject.preventDefault) eventObject.preventDefault();
			if (eventObject.preventCapture) eventObject.preventCapture();
	   		if (eventObject.preventBubble) eventObject.preventBubble();
		}
	},
	/**
	 * GECKO / WEBKIT call right click
	 * @param {Object} ev
	 */
	onGeckoMouse: function(ev) {
	  	return function(ev) {
	    if (ev.button != 0) {
			RightClick.killEvents(ev);
			if(ev.target.id == RightClick.FlashObjectID && RightClick.Cache == RightClick.FlashObjectID) {
	    		RightClick.call();
			}
			RightClick.Cache = ev.target.id;
		}
	  }
	},
	/**
	 * IE call right click
	 * @param {Object} ev
	 */
	onIEMouse: function() {
	  	if (event.button > 1) {
			if(window.event.srcElement.id == RightClick.FlashObjectID && RightClick.Cache == RightClick.FlashObjectID) {
				RightClick.call(); 
			}
			document.getElementById(RightClick.FlashContainerID).setCapture();
			if(window.event.srcElement.id)
			RightClick.Cache = window.event.srcElement.id;
		}
	},
	/**
	 * Main call to Flash External Interface
	 */
	call: function() {
		document.getElementById(this.FlashObjectID).rightClick();
	}
}

function getcookie2(name){
		var url = location.href;
		var gameCookie = url.substr(url.indexOf("?")+1);
		var num = gameCookie.indexOf("=");
		var cname = gameCookie.substr(0,num);
		var cvalue = gameCookie.substr(num+1);

		return  (cname == name) ? cvalue : 'fail';
}

function getcookie(name) {
	var str_cookie = document.cookie;
	var cookie_arr = str_cookie.split(";");
	for(var i = 0;i<cookie_arr.length;i++)
	{
		var arr = cookie_arr[i].split("=");
		if(trim(arr[0]) == name)
		{
			return unescape(arr[1]);
		}
	}
	return getcookie2(name);
}

function getcookiebak(name) {
	var cookie_start = document.cookie.indexOf(name);
	var cookie_end = document.cookie.indexOf(";", cookie_start);
	if(cookie_start == -1 ){//读取不到时取地址栏的
		return getcookie2(name);
	}else{
		return unescape(document.cookie.substring(cookie_start + name.length + 1, (cookie_end > cookie_start ? cookie_end : document.cookie.length)));
	}
}


function setcookie(cookieName, cookieValue, day, path, domain, secure) {
	var expires = new Date();
	expires.setTime(expires.getTime() + day*24*60*60*1000);
	document.cookie = escape(cookieName) + '=' + escape(cookieValue)
		+ (expires ? '; expires=' + expires.toGMTString() : '')
		+ (path ? '; path=' + path : '/')
		+ (domain ? '; domain=' + domain : '')
		+ (secure ? '; secure' : '');
}
function trim(str)
{
	return str.replace(' ','');
}
function insertJs(url)
{
	var js = document.createElement('script');
	js.type = 'text/javascript';
	js.charset = "UTF-8";
	js.src = url+"?"+Math.random()*1000;
	var headNode = document.getElementsByTagName("head")[0];
	headNode.appendChild(js);
	
}