﻿function leaveGame(){
	return "更多惊喜期待着您！您确认要离开游戏吗?";
}
function closeConn(){
	document.getElementById("Loading").closeConn();
	document.getElementById("MapClient").closeConn();
}

//没有右键的初始化
function init() {
		this.FlashObjectID = "Loading";
		this.FlashContainerID = "flashcontent";
		this.Cache = this.FlashObjectID;
		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;
		}
}

function getCurServerPath(){
	return window.location.href;
}

function addBookmark(title,url){
	if(url == ""){url = window.location}
	title = document.title;//原来的title全版都用默认的“天书奇谈”，没有翻译多语言，现改为页面的title，传进来的参数无作用
	try{
		window.external.addFavorite(url,title);//ie
	}catch(e){
		try{
			window.sidebar.addPanel(title,url,"");	//firefox
		}catch(e){
			alert(favorite);	
			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";//‘_blank’safari浏览器没有反映，‘_self’会在本页面弹出离开游戏，所以牺牲safari
 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);
}



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);
	
}

function getUrl() {
  var weburl = document.URL;
  weburl = weburl.substr(weburl.indexOf("?")+1);
  var urlarr = weburl.split("&");
  if(urlarr.length == 0) {
   return "fail";
  }
  	var pid ;
		var f;
		var t;
		var sign;
	for(var i = 0;i<urlarr.length;i++)
	{
		var arr = urlarr[i].split("=");
		if(trim(arr[0]) == "pid")
		{
		   pid = arr[1];
		}
		if(trim(arr[0]) == "f")
		{
		  f = arr[1];
		}
		if(trim(arr[0]) == "t")
		{
			 t = arr[1];
		}
		if(trim(arr[0]) == "sign")
		{
		   sign = arr[1];
		}
  }
  if(pid == undefined || f == undefined || t == undefined ||sign == undefined){
   return "fail"
  }
	return pid +","+f+","+t+","+sign;
}

//测试safari浏览器退格问题，没有上线
function preventBackspace(e) {
         var evt = e || window.event;
         if (evt) {
             var keyCode = evt.charCode || evt.keyCode;
             if (keyCode === 8) {
                 if (evt.preventDefault) {
					 evt.preventDefault();
                 } else {
                     evt.returnValue = false;
                 }
             }
         }
}
