﻿Date.prototype.addDays = function(d){this.setDate(this.getDate() + d);}; 

function setCookie(name,value)
{ 
   var args = setCookie.arguments;
   var argv = setCookie.arguments.length;
   var expires = argv>2?args[2]:null;
   var date = new Date();
   if(expires!=null)
   {
      date.addDays(expires);
   }
   document.cookie=name+"="+value+((expires==null)?"":(";expires="+date.toGMTString()));
}

function getCookie(name) 
{ 
    var value = null;
    if(document.cookie&&document.cookie != '')
    {
        var cookies = document.cookie.split(';');
        for(var i=0;i<cookies.length;i++)
        {
           var cookie = cookies[i].replace(/^\s+|\s+$/g,'');
           if(cookie.substring(0,name.length+1) == (name + '='))
           {
               value = unescape(cookie.substring(name.length+1));
               break;
           }
        }
    }
    return value;
}

function delCookie(name)
{
   setCookie(name,null,-10);
}

//select all
var selChk = document.getElementsByTagName("input");
function selAll(chkResult)
{
   for(var i=0;i<selChk.length;i++)
   {
       if(selChk[i].type=="checkbox")
        selChk[i].checked = chkResult;
    }
}

function AddFavorite(sURL, sTitle)
{
     try 
     {
      window.external.AddFavorite(sURL,sTitle);
     }
     catch (e)
     {
        try
        {
           window.sidebar.addPanel(sTitle, sURL, "");
        }
        catch (e)
        {
          alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}

//选项卡
function setTab(name,cursel,n)
{
	for(i=1;i<=n;i++)
	{
		var menu=document.getElementById(name+i);
		var con=document.getElementById("con_"+name+"_"+i);
		menu.className = i == cursel ? "hover" : "";
		con.style.display=i==cursel?"block":"none"
	   if(i==cursel&&document.getElementById("iframe"+i))
       {
	    // var iframe=document.getElementById("iframe"+i);
		GetIFrame(i);
	   }
	}
}


//弹框
function OpenWindow(title,href,width,height)
{   
    var from = location.href;
    if(href.indexOf("?")>-1)
    {
       href += "&from="+from+"&keepThis=true&width="+width+"&height="+height+"&TB_iframe=true";
    }
    else
    {
       href += "?from="+from+"&keepThis=true&width="+width+"&height="+height+"&TB_iframe=true";
    }
    tb_show(title,href,false);
}


//检测是否登录
function checklogin(tourl)
{
   var acc = getCookie("loonggame");
   if(acc == null)
   {
      if(confirm("此操作需要登录，现在就登录吗"))
      {
          OpenWindow("用户登录","http://www.1312.com/userlogin.aspx",300,180);
      }
   }
   else
   {
      location.href = tourl;
   }
}


function commonlogin()
{ 
  OpenWindow("用户登录","http://www.1312.com/userlogin.aspx",300,180);
}


function GetCurrentUser()
{  
      if(getCookie("loonggame")!=null)
      {
          var userinfoArray=Array();
          $.ajax({
            type:"POST",
            url:"http://www.1312.com/GetInfo.ashx?action=getuserinfo&from="+window.location.href,
            dataType:"html",
            success:function(result)
            {
               if(result!="")
               {
                     $("#top_loginbefore").css("display","none");
                     $("#top_loginafter").css("display","");
                     $("#top_loginafter").html(result);
               }
            }
        });  
    }
 }


 function copyToClipboard(sth)
{
    if (document.all) {
        window.clipboardData.setData('text', sth);
        alert("复制成功，立即开始吧！");
    } else {
        alert("您的浏览器不支持剪贴板操作，请用Ctrl+C或鼠标右键进行复制。");
    }
}
