if (document.domain.indexOf("qq.com") > 0)
{
	document.domain = "qq.com";
}

//页面跳转用的全局变量
var g_Jump_Url_TimeOut_ID = -1;

/*
修改obBeginDate设置跳转的开始时间
修改obEndDate  设置跳转的停止时间
注意0代表一月，1代表二月。构造函数顺序(年、月、日、小时、分、秒)
*/
function inJumpTime()
{
   //注意:0代表一月
   var obBeginDate = new Date(2009, 8, 27, 23, 30);
   var obEndDate =   new Date(2009, 8, 28, 09, 00);
   var objNow = new Date;
   if (obBeginDate <= objNow && objNow < obEndDate)
   {
        window.top.location.href = "http://minigame.qq.com/act/systemmend.html"
        if (g_Jump_Url_TimeOut_ID != -1)
        {
            clearInterval(g_Jump_Url_TimeOut_ID);
        }
   }
   else if (objNow < obBeginDate)
   {
        if (g_Jump_Url_TimeOut_ID == -1)
        {
            g_Jump_Url_TimeOut_ID = setInterval(inJumpTime, 10000);
        }
   }
   else // >=obEndDate
   {
       return;
   }
}

//关闭Web服务。
function Close_Web_Service()
{
    //需要关闭的Web服务入口。
    //只需要列出服务路径的简单即可。
    //如果Url中包含以下字符串，则自动跳转到系统维护页面。
       var arrWebService=["minigame.qq.com/act/magicard0804"
                          , "minigame.qq.com/act/newgift0806" 
                          , "minigame.qq.com/act/rose0901"
                          , "http://minigame.qq.com/act/gamepet/"
                          , "http://minigame.qq.com/act/lucky0810/"
                          , "http://minigame.qq.com/act/hlljt0808/"
                          , "http://minigame.qq.com/act/hlbox0801/"
                          , "minigame.qq.com/act/rose"
                          , "minigame.qq.com/act/rose0908"
                          , "minigame.qq.com/act/rose/rose0904"
                          , "meigui.qq.com"];


       var myUrl = window.location.href;
       for (var ii = 0; ii < arrWebService.length; ++ii)
       {
           if (myUrl.indexOf(arrWebService[ii]) != -1)
           {
                inJumpTime();
                return;
           }
       }  
}
//Close_Web_Service();

/*
获得URL参数
*/
function GetUrlParms()
{
    var args=new Object();
    var query=location.search.substring(1);//获取查询串
    var pairs=query.split("&");//在逗号处断开
    for(var i=0; i < pairs.length; i++ )   
    {   
        var pos=pairs[i].indexOf('=');//查找name=value   
            if(pos==-1)   continue;//如果没有找到就跳过   
            var argname=pairs[i].substring(0,pos);//提取name   
            var value=pairs[i].substring(pos+1);//提取value   
            args[argname]=unescape(value);//存为属性   
    }
    return args;
}

/*
获得URL参数，将指定的的URL参数设置到Cookie里面去。
*/
function SetUrlParaToCookie(strKey)
{
    var objArgs = GetUrlParms();
    
    if (typeof objArgs[strKey] != "undefined")
    {
        chSetCookie(strKey, objArgs[strKey]);   
    }
}

// cookie操作
function chGetCookie(name)
{
	var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
	if(arr != null)
	{
		return unescape(arr[2]);
	}
	return "";
}
function chSetCookie(name, value)
{
	document.cookie = name + "=" + value + "; path=/; domain=qq.com";
}
function chDeleteCookie(name)
{
	chSetCookie(name, "");
}

// 得到字符串的长度
function chGetLength(value)
{
	var len = 0;
	for(var i = 0; i < value.length; i++)
	{
		if (value.charCodeAt(i) > 255) // 双字节
		{
			len += 2;
		}
		else
		{
			++len;
		}
	}
	return len;
}

// 转换为int
function chStrToInt(str, failint)
{
	var i = parseInt(str);
	return (isNaN(i) ? (failint ? failint : 0) : i);
}

// 从cookie获取QQ号
function chGetUin()
{
	var aRet = chGetCookie('uin').match(/\d+/);
	return aRet ? parseInt(aRet[0], 10) : -1;
}
// 根据cookie简单判断是否登录
function chIsLogin()
{
	var uin = chGetUin();
	var skey = chGetCookie('skey');
	if (uin <= 10000 || skey.length != 10)
	{
		return false;
	}
	return true;
}
// 退出登录
function chLogout(jumpurl, topjump)
{
	chDeleteCookie("uin");
	chDeleteCookie("skey");	
	chDeleteCookie("zzpaneluin");
	chDeleteCookie("zzpanelkey");
    chDeleteCookie("dna_result_key");
    chDeleteCookie("PcacheTime");

	if (jumpurl)
	{
		if (topjump)
		{
			top.location = jumpurl;
		}
		else
		{
			location = jumpurl;
		}
	}
}

function chId(id)
{
	return document.getElementById(id);
}
function chName(name)
{
	return document.getElementsByTagName(name);
}

//=====================================
// 20080826 改用公司通用登录层 thinkryzhu

// 输出对象的属性
function chDumpObject(obj)
{ 
	var strDump = "" ; 
	for (var p in obj)
	{   
		if (typeof(obj[p]) != "function")
		{   
			strDump += p + "=" + obj[p] + "\n";
		}
	}

	alert(strDump);
}

// 获取浏览器的窗口尺寸信息
function chWindowSizeInfo(aobjDoc)
{
    var objDoc = aobjDoc || document;
    var obj = (objDoc.compatMode == "CSS1Compat" ? objDoc.documentElement : objDoc.body);
    this.clientWidth = obj.clientWidth;
    this.clientHeight = obj.clientHeight;
    this.scrollLeft = obj.scrollLeft;
    this.scrollTop = obj.scrollTop;
    this.scrollWidth = obj.scrollWidth;
    this.scrollHeight = obj.scrollHeight;
}

// 显示覆盖层
function chShowCoverDiv(iOffsetLeft, iHeight)
{
	var objCover = chId("chCoverDiv");
	if (!objCover)
	{
		objCover = document.createElement("div");
    	objCover.id = "chCoverDiv";
		document.body.appendChild(objCover);
	}

	var objStyle = objCover.style;
	objStyle.display = "block";
	objStyle.margin = "0px";
	objStyle.padding = "0px";
	objStyle.top = "0px";
	objStyle.left = "0px";
	objStyle.width = iOffsetLeft + "px";
	objStyle.height = iHeight + "px";
	objStyle.position = "absolute";
	objStyle.zIndex = "3";
	objStyle.background = "#000000";
	objStyle.filter = "alpha(opacity=40)";
	objStyle.opacity = 40/100;
	objStyle.MozOpacity = 40/100;
	
	var allselect = chName("select");
	for (var i=0; i<allselect.length; ++i)
	{
		allselect[i].style.visibility = "hidden";
	}
}

// 隐藏覆盖层
function chHideCoverDiv()
{
	var objCover = chId("chCoverDiv");
	if (objCover)
	{
		objCover.style.display = "none";
	}
	var allselect = chName("select");
	for (var i=0; i<allselect.length; ++i)
	{
		allselect[i].style.visibility = "visible";
	}
}

// 创建对话框层
// 因为可能需要调整兑换框的大小，所以先设为不可见
function chCreateDialogDiv(strID, strHtmlData, iOffsetTop, iOffsetLeft, iWidth, iHeight)
{
	var objDialog = chId(strID);
	if (!objDialog)
	{
		objDialog = document.createElement("div");
    	objDialog.id = strID;
		document.body.appendChild(objDialog);
	}

	var objStyle = objDialog.style;
	objStyle.display = "block";
	objStyle.margin = "0px";
	objStyle.padding = "0px";
	objStyle.top = iOffsetTop + "px";
	objStyle.left = iOffsetLeft + "px";
	objStyle.width = iWidth + "px";
	objStyle.height = iHeight + "px";
	objStyle.position = "absolute";
	objStyle.zIndex = "5";
	objStyle.background = "#FFFFFF";
	objStyle.border = "solid #00D2FF 1px";
	objStyle.visibility = "hidden";	// 因为可能需要调整兑换框的大小，所以先设为不可见
	objDialog.innerHTML = strHtmlData;
}

// 显示对话框层
function chShowDialogDiv(strID)
{
	var objDialog = chId(strID);
	if (objDialog)
	{
		objDialog.style.display = "block";
		objDialog.style.visibility = "visible";
	}
}

// 隐藏对话框层
function chHideDialogDiv(strID)
{
	var objDialog = chId(strID);
	if (objDialog)
	{
		objDialog.style.display = "none";
	}
}

// 显示对话框
function chShowDialog(strID, strHtmlData, iWidth, iHeight, strAlignH, iOffsetH, strAlignV, iOffsetV)
{
	strAlignH = strAlignH || "center";
	strAlignV = strAlignV || "center";
	iWidth = iWidth || 0;
	iHeight = iHeight || 0;
	iOffsetH = iOffsetH || 0;
	iOffsetV = iOffsetV || 0;
	
	// 计算偏移量
	var objSizeInfo = new chWindowSizeInfo();
	var iOffsetTop = 0;
	var iOffsetLeft = 0;
	if (strAlignH == "center")
	{
		iOffsetLeft = objSizeInfo.scrollLeft + (objSizeInfo.clientWidth - iWidth) / 2 + iOffsetH;
	}
	else if (alignH == "right")
	{
		iOffsetLeft = objSizeInfo.scrollLeft + (objSizeInfo.clientWidth - iWidth) + iOffsetH - 23;
	}
	else
	{
		iOffsetLeft = objSizeInfo.scrollLeft + iOffsetH;
	}
	
	if (strAlignV == "center")
	{
		iOffsetTop = objSizeInfo.scrollTop + (objSizeInfo.clientHeight - iHeight) / 2 + iOffsetV;
	}
	else if (strAlignV == "bottom")
	{
		iOffsetTop = objSizeInfo.scrollTop + (objSizeInfo.clientHeight - iHeight) + iOffsetV - 33;
	}
	else
	{
		iOffsetTop = objSizeInfo.scrollTop + iOffsetV;
	}
	
	// 显示覆盖层
	chShowCoverDiv(objSizeInfo.scrollWidth, objSizeInfo.scrollHeight);
	
	// 显示对话框层
	chCreateDialogDiv(strID, strHtmlData, iOffsetTop, iOffsetLeft, iWidth, iHeight);
}

// 关闭对话框
function chHideDialog(strID)
{
	chHideDialogDiv(strID);
	chHideCoverDiv();
}

var g_Quick__Ba_ck_Url__="";
function setQuickBackUrl(strQuciBackJumpUrl)
{
    g_Quick__Ba_ck_Url__ = strQuciBackJumpUrl;
}

function chNeedLogin(strAlignH, iOffsetH, strAlignV, iOffsetV)
{
	var strURL = top.location;
	if (g_Quick__Ba_ck_Url__ == "")
	{
	    g_Quick__Ba_ck_Url__ = top.location;
	}
	g_Quick__Ba_ck_Url__=top.location;
	var str = '<iframe id="login_iframe" allowTransparency="true" marginwidth="0" marginheight="0" hspace="0"' +
	          ' vspace="0" frameborder="0" scrolling="no" style="border:none;width:373px;height:284px" ' +
	  		  'src="http://ui.ptlogin2.qq.com/cgi-bin/login?appid=7000201&f_url=loginerroralert&s_url='+escape(strURL)+
	  		  '&qlogin_jumpname=jump&qlogin_param=' + escape("u1="+escape(g_Quick__Ba_ck_Url__))
	  		  + '"></iframe>';
	chShowDialog("login_div", str, 373, 284, strAlignH, iOffsetH, strAlignV, iOffsetV);
	chShowDialogDiv("login_div");
}

function chNeedVerify(strUrl, strAlignH, iOffsetH, strAlignV, iOffsetV)
{
    //这里的strUrl不要调用escape函数，否则安全中心解析会出错。
    var str = '<iframe id="verify_iframe" allowTransparency="true" marginwidth="0" marginheight="0" hspace="0"' + 
              ' vspace="0" frameborder="0" scrolling="no" style="border:none;width:373px;height:290px" ' + 
              'src="' +strUrl+'"></iframe>';
    chShowDialog("dialog_verify", str, 373, 284, strAlignH, iOffsetH, strAlignV, iOffsetV);
    chShowDialogDiv("dialog_verify");
}

// 登录框要求页面实现这个函数
function ptlogin2_onResize(iWidth, iHeight)
{
	// 获得浮动Div对象
	var objDiv = chId("login_div");
	var objFrame = chId("login_iframe");
	if (objDiv && objFrame)
	{
		//重新设置大小注意，一定要加px，否则firefox下有问题
		objDiv.style.width = iWidth + "px";
		objDiv.style.height = iHeight + "px";

		objFrame.style.width = iWidth + "px";
		objFrame.style.height = iHeight + "px";	
	}
	chShowDialogDiv("login_div");
}

// 登录框要求页面实现这个函数
function ptlogin2_onLogin()
{
//	chHideDialog("login_div");
	return true;
}

// 登录框要求页面实现这个函数
function ptlogin2_onClose()
{
	chHideDialog("login_div");
}

//=====================================
function doGet_game_web()
{
        new Ajax.Request(
                        "http://minigamecgi.qq.com/cgi-bin/check_login_json",
                        {
                                method: "post",
                                parameters: "",
                                onSuccess: onGetSuccess
                        });
}     

function doGet()
{
	sendAjaxRequest(
			"http://minigamecgi.qq.com/cgi-bin/check_login_json",
			{
				method: "post", 
				parameters: "", 
				onSuccess: onGetSuccess
			});
}

function onGetSuccess(transport)
{
	var ans = transport.responseText.evalJSON();
	if (ans.result != 0)
	{
		alert(ans.resultstr);
		return;
	}
	if(ans.islogin == 1)
	{
		$("Logined").style.display = "block";
		$("NeedLogin").style.display = "none";
	}
     
}

var g_RequestArray = new Array();
function sendAjaxRequest(strUrl, objAjax)
{
try
{
    var iFrameObj = document.getElementById("minigamecgiProxy");
 
   if ( !iFrameObj )
    {
        var regex = /http:\/\/.*\.qq\.com/   
        var tmpUrl = strUrl.match(regex)[0];
        iFrameObj = document.createElement("iframe");
        document.body.appendChild(iFrameObj);
        iFrameObj.setAttribute("src",  tmpUrl +  "/act/proxy.html");
        iFrameObj.style.display = "none";
        iFrameObj.id = "minigamecgiProxy";
    }

    var proxy = iFrameObj.contentWindow;
    if (typeof proxy.sendRequest != "undefined")
    {
        proxy.sendRequest(strUrl, objAjax);
    }
    else
    {
       g_RequestArray.push( {"url":strUrl, "ajax":objAjax }  );     
    }
}
catch (e)
{
}

}
/*
function sendAjaxUpdater(obj, strUrl, objAjax)
{
    var iFrameObj = document.getElementById("minigamecgiProxy");

    if ( !iFrameObj )
    {
        iFrameObj = document.createElement("iframe");
        document.body.appendChild(iFrameObj);
        iFrameObj.setAttribute("src", "http://minigamecgi.qq.com/act/proxy.html");
        iFrameObj.style.display = "none";
        iFrameObj.id = "minigamecgiProxy";
    }

    var proxy = iFrameObj.contentWindow;
    if (typeof proxy.sendUpdater != "undefined")
    {
        proxy.sendUpdater(obj, strUrl, objAjax);
    }
    else
    {
       g_UpdaterArray.push( {"obj":obj, "url":strUrl, "ajax":objAjax }  );     
    }
}
*/

/*function  ifMinigameCgiLoad()
{
    for (var ii = 0; ii < parent.g_RequestArray.length; ++ii )
    {
       tmp = parent.g_RequestArray[ii] ;
       sendRequest(tmp.url, tmp.ajax );
    }
}*/

// 用Ajax加载页面 
function chIncludeHtm(htm)
{
	new Ajax.Request(htm,
			{
				method: "get", 
				parameters: "", 
				asynchronous: "false",
				onSuccess: function(t) { document.write(chBytes2BSTR(t.responseBody)); }
			});	
}

// 用Ajax加载页面 
function chDivIncludeHtm(divId,htm)
{
	new Ajax.Request(htm,
			{
				method: "get", 
				parameters: "", 
				asynchronous: "false",
				onSuccess: function(t) { document.getElementById(divId).innerHTML = chBytes2BSTR(t.responseBody); }
			});	
}

// 用Ajax加载页面，在onBodyLoad()中执行，一般用在include页面中，也就是说二次include需要用这个函数
function chIncludeHtmDiv(htm, id)
{
	new Ajax.Request(htm,
			{
				method: "get", 
				parameters: "", 
				asynchronous: "false",
				onSuccess: function(t) {document.getElementById(id).innerHTML = chBytes2BSTR(t.responseBody); }
			});	
}

// 用Ajax加载页面，在onBodyLoad()中执行，一般用在include页面中，也就是说二次include需要用这个函数
function chIncludeHtmDivAsync(htm, id, func)
{
	new Ajax.Request(htm,
			{
				method: "get", 
				parameters: "", 
				asynchronous: "true",
				onSuccess: function(t) {document.getElementById(id).innerHTML = chBytes2BSTR(t.responseBody);func(t);  }
			});	
}

// 用Ajax加载页面 
function chIncludeHtm_dynamic(htm)
{
    sendAjaxRequest(htm,
            {
                method: "get",
                parameters: "",
                asynchronous: "false",
                onSuccess: function(t) {
                                             
                                             var tmp = chBytes2BSTR(t.responseBody );
                                             //临时解决方案。
                                             if (tmp.length > 0 )
                                             {
                                               document.write( tmp  );
                                             }
                                      }
            });
}


// 用Ajax加载页面，在onBodyLoad()中执行，一般用在include页面中，也就是说二次include需要用这个函数
function chIncludeHtmDiv_dynamic(htm, id)
{
	sendAjaxRequest(htm,
			{
				method: "get", 
				parameters: "", 
				asynchronous: "false",
				onSuccess: function(t) {document.getElementById(id).innerHTML = chBytes2BSTR(t.responseBody); }
			});	
}

// 用Ajax加载页面，在onBodyLoad()中执行，一般用在include页面中，也就是说二次include需要用这个函数
function chIncludeHtmDivAsync_dynamic(htm, id, func)
{
	sendAjaxRequest(htm,
			{
				method: "get", 
				parameters: "", 
				asynchronous: "true",
				onSuccess: function(t) {document.getElementById(id).innerHTML = chBytes2BSTR(t.responseBody);func(t);  }
			});	
}

//设置个账秘宝的cookie
SetUrlParaToCookie("dna_result_key");
SetUrlParaToCookie("PcacheTime");
