/**
 * @param {string} sorce  src of js file
 * @param {bool} autoRemove 
 * @param {string} id  Element's id when autoRemove:false
 * @author zhys9
 * @date 10-12-2007 dd-mm-yyyy
 * @todo Load javascript file async
 */
function jLoader (source,autoRemove,id){
	id = id||"";
	autoRemove = autoRemove||false;
	var b=document.getElementsByTagName("head")[0];
	var c=document.createElement("script");
	c.type="text/javascript";
	c.charset="utf-8";
	if(id){
		c.id = id;
	}
	c.src=source;
	var remove=function(){
		c.onload=null;
		var h=c.parentNode;
		h.removeChild(c);
		delete c;
	};
	var e=function(h){
		var j=(h?h:window.event).target?(h?h:window.event).target:(h?h:window.event).srcElement;
		if(j.readyState=="loaded"||j.readyState=="complete")
		{
			j.onreadystatechange=null;
			if(autoRemove){
				remove();
			}
		}
	};
	if(navigator.product=="Gecko"&&autoRemove){
		c.onload=remove;
	}
	else{
		c.onreadystatechange=e;
	}
	b.appendChild(c);
}
/**
 * @author zhys9
 * @param string sTitle
 * @param string sMsg
 * @param int width
 * @param int height
 * @param function onclose
 * @param bool	sizeFixed 是否固定窗体的高度和宽度
 * @param in filter 滤镜透明度，0关闭滤镜
 * <code>
 * 	var html = '<iframe width="650" height="500" src="index.php?action=iframe&do=rank_list&app_id='+app_id+'" marginWidth="0" marginHeight="0" frameBorder="0" scrolling="0"></iframe>';
 *	jAlert(gameName+" 排行榜", html, 650, 520, null, true);
 * </cdoe>
 * 
 */
function jAlert(sTitle,sMsg,width,height,onclose, sizeFixed, filter){
	onclose = onclose||function(){
			if(document.getElementById("_jk_maskBackground"))document.body.removeChild(document.getElementById("_jk_maskBackground"));
			document.body.removeChild(document.getElementById("_jk_msgElement"));
		};
	sizeFixed = sizeFixed||false;	//是否固定窗口高宽
	filter = filter||30;	//滤镜透明度 0 为关闭
	var oStyle = {
		"width":width||400,
		"height":height||300
	};
	var msgw,msgh,bordercolor;
	titleheight=25;
	bordercolor="#336699";
	titlecolor="#99CCFF";
	
	var maxWidth = document.documentElement.clientWidth;//document.documentElement.clientWidth?document.documentElement.clientWidth:document.body.scrollWidth;
	var maxHeight = document.documentElement.clientHeight;//document.documentElement.clientHeight?document.documentElement.clientHeight:document.body.scrollHeight;
	
	if(filter) {
		var bgObj=document.createElement("DIV");
		var bStyle = bgObj.style;
		bgObj.setAttribute('id','_jk_maskBackground');
		bgObj.className = "markA";
		bStyle.position="absolute";
		bStyle.top="0";
		bStyle.left="0";
		bStyle.background="#000";
	//	bStyle.filter="progid:DXImageTransform.Microsoft.Alpha(style=2,opacity=25,finishOpacity=75";
		bStyle.opacity=Math.ceil(filter/100);
		bStyle.width=document.body.scrollWidth + "px";
		bStyle.height=document.body.scrollHeight + "px";
		bStyle.zIndex = "65534";
		document.body.appendChild(bgObj);
		bgObj = null;
	}
	
	var msgElement=document.createElement("DIV");
	msgElement.setAttribute('id','_jk_msgElement');
	msgElement.className = "msg_dialog add_app";
	msgElement.style.position = "absolute";
	msgElement.style.left = (Math.floor((maxWidth-oStyle.width)/2)>0?Math.floor((maxWidth-oStyle.width)/2):0)+document.documentElement.scrollLeft+"px";
	msgElement.style.top = (Math.floor((maxHeight-oStyle.height)/2)>0?Math.floor((maxHeight-oStyle.height)/2):0)+document.documentElement.scrollTop+"px";
	msgElement.style.zIndex = "65535";
	msgElement.style.width = oStyle.width+"px";
	msgElement.style.height = oStyle.height+"px";
	
	var msgContentContainer=document.createElement("DIV");
	msgContentContainer.className = "msg_dialog_content";
	msgContentContainer.style.width = "100%";
	msgContentContainer.style.height = "100%";
	
	var msgTitleContainer=document.createElement("DIV");
	msgTitleContainer.className = "msg_title";
	var msgTitle=document.createElement("H3");
	var msgClose = document.createElement("A");
	msgClose.setAttribute("id","_jk_maskClose");
	msgClose.href="javascript://";
	msgClose.onclick=onclose;
	msgClose.innerHTML="<b>x</b>";
//	var oImg = document.createElement("IMG");
//	oImg.src="http://msg.56.com/images/close.gif?"+Math.random();
//	oImg.onload = function(){document.getElementById("_jk_maskClose").appendChild(this);};
//	oImg=null;
	
	//msg container
	var msgContent=document.createElement("DIV");
	msgContent.className="block";
	msgContent.style.width = "100%";
	msgContent.style.height = oStyle.height-45+"px";
	msgContent.style.overflowX = "hidden";
	
	//msg trans bg
	var msgShadow=document.createElement("DIV");
	msgShadow.className="msg_trans_bg";
	msgShadow.style.width = oStyle.width+12+"px";
	msgShadow.style.height = oStyle.height+12+"px";
	
	//append elements
	document.body.appendChild(msgElement);
	msgElement.appendChild(msgContentContainer);
	msgContentContainer.appendChild(msgTitleContainer);
	msgTitleContainer.appendChild(msgTitle);
	msgTitleContainer.appendChild(msgClose);
	msgContentContainer.appendChild(msgContent);
	msgElement.appendChild(msgShadow);
	
	//show msg
	msgTitle.innerHTML = sTitle;
	msgContent.innerHTML=sMsg;
	
	//fix size
	if(!sizeFixed && msgContent.scrollHeight>parseInt(msgContent.style.height)+13) {
		msgContent.style.overflowY = "scroll";
	}
	
	msgElement=null;msgContentContainer=null;msgTitleContainer=null;
	msgTitle=null;msgClose=null;msgContent=null;msgShadow=null;
}

/**
 * @param {object} sorce
 * @author zhys9
 * @date 12-08-2008 dd-mm-yyyy
 * @todo clon an object
 */
function clonObject(obj) {
	var rs = {};
	for(var o in obj) {
		if(typeof(o)=="object") {
			clonObject(o);
		}else{
			rs[o] = obj[o];
		}
	}
	return rs;
}
function cDiv (cssClass,id) {
	cssClass = cssClass||"";
	id = id||"";
	var div = document.createElement("DIV");
	if(typeof(id)=="string" && id.length) div.id = id;
	if(typeof(cssClass)=="string" && cssClass.length) div.className = cssClass;
	return div;
}
function setHtml(obj, html) {
	obj.innerHTML = html;
}
function in_array(a, arr) {
    for(var i in arr) {
        if (arr[i] == a) return true ;
    }
    return false;
}

/* 
 * @author zhys9
 * @date 20071010
 * @param String string URL
 * @return Object oRs
 * e.g. input: 'http://so.56.com/index?type=video&key=aaa'
 * 		ouput: {'type':video, 'key':'aaa'}
 */
function parse_str(string){
	var a = [];
	var oRs = {};
	var query = string.substr(string.indexOf('?')+1);
	var tmp = query.split('&');
	var k;
	for(var i=0;i<tmp.length;i++){
		a = tmp[i].split('=');
		oRs[a[0]] = a[1];
	}
	return oRs;
}

//////////////////////////////////////////////////////////
var  __zhys9_dbg = {};
__zhys9_dbg._DEBUG = false;
__zhys9_dbg._dbg_str = "<pre>";
__zhys9_dbg.showMsg = function () {
	var _div = document.createElement("DIV");
	this.id = _div.id = "_zhys9_dbg_"+Math.random();
	_div.innerHTML = this._dbg_str;
	document.body.appendChild(_div);
};
__zhys9_dbg.dumpOjbect = function (obj) {
	for(var o in obj) {
		if(typeof(obj[o])=="object") {
			this.dumpOjbect(obj[o]);
			this._dbg_str += "\t";
		}else{
			this._dbg_str += "\t"+o+": "+obj[o]+"\n\n";
		}
	}
	return this._dbg_str;
};
///////////////////////////////////////////////////////////





/**
 * copyStr
 * @param {type} str 
 */
function copyStr(str) {
 	if(window.clipboardData) {
 		window.clipboardData.setData('text',str);
 		alert("复制成功！");
 	}

}
/*
 * 返回字符串长度
 * 1中文字符返回长度2
 * e.g: strlen(我cc) 返回 4 
 */
function strlen(str) {
	return str.replace(/[^\x00-\xff]/g,"jk").length;
}


function showFlash(ele_obj, swf, flashvars, width, height, wmode) {
	width = width||"100%"; height=height||"100%"; wmode=wmode||"opaque";
	var str = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" ';
	if(width) str += 'width="' + width + '" ';
	if(height) str += 'height="' + height + '" ';
	str += '>';
	str += '<param name="allowScriptAccess" value="always">';
	str += '<param name="movie" value="' + swf + '">';
	str += "<param name='wmode' value='"+(wmode?wmode:'transparent')+"'>";
	str += '<param name="flashvars" value="' + flashvars + '">';
	str += '<param name="allowscriptaccess" value="always">';
	str += '<embed src="' + swf + '" flashvars="' + flashvars + '"'+(wmode?' wmode="'+wmode+'"':'')+' '
	if(width) str += 'width="' + width + '" '
	if(height) str += 'height="' + height + '" ';
	str += '" allowscriptaccess="always" align="middle" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">';
	str += '</object>';
	
	ele_obj.innerHTML = str;
}

var GAME_ROOT = APP_CENTER = APP_CENTER_ROOT = "http://app.56.com/";
var _get = parse_str(document.location.href);
_get["app_id"] = _get["app_id"]?_get["app_id"]:(_get["g_id"]?_get["g_id"]:0);
gLoginUser = getCookie("member_id").replace(/(@.*)/,"");
gLoginUserNickName = getCookie("user_nickname");
