﻿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 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 "";
	}
}

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 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' : '');
}
