﻿var netliao = {};

netliao.register = function(ns) {
    var nsArray = ns.split('.');
    var sEval = "";
    var sNS = "";
    for (var i = 0; i < nsArray.length; i++)
    {
        if (i != 0) sNS += ".";
        sNS += nsArray[i];
        sEval += "if (typeof(" + sNS + ") == 'undefined') " + sNS + " = new Object();"
    }
    if (sEval != "") eval(sEval);
}

var $A = Array.from = function(iterable) {
  if (!iterable) return [];
  if (iterable.toArray) {
    return iterable.toArray();
  } else {
    var results = [];
    for (var i = 0; i < iterable.length; i++)
      results.push(iterable[i]);
    return results;
  }
}

Function.prototype.bind = function() {
  var __method = this, args = $A(arguments), object = args.shift();
  return function() {
    return __method.apply(object, args.concat($A(arguments)));
  }
}

/* menu Item */
netliao.register("netliao.tabMenu");
netliao.tabMenu.Item = function(name, href)
{
  this.name = name;
  this.href = href;
}

/* showTab */
function ShowPhotoTab(id)
{
	for(var i=1;i<3;i++)
	{
	    //document.getElementById("Photo_"+i).className="PhotoTabOff";
	    document.getElementById("Photo_"+i).src="images/pic/ar3an0"+i+"a.gif";
		document.getElementById("Photos_"+i).style.display="none";
	}
	//document.getElementById("Photo_"+id).className="PhotoTabOn";
	    document.getElementById("Photo_"+id).src="images/pic/ar3an0"+id+".gif";
	    document.getElementById("Photos_"+id).style.display="";
}

function ShowGonggaoTab(id)
{
	for(var i=1;i<4;i++)
	{
	    document.getElementById("gg_"+i).className="be02hy green";
		document.getElementById("ggg_"+i).style.display="none";
	}
	document.getElementById("gg_"+id).className="bing02hy black";
	document.getElementById("ggg_"+id).style.display="";
}
function ShowPaihangTab(id)
{
	for(var i=1;i<4;i++)
	{
	    document.getElementById("ph_"+i).className="be03hy blue";
		document.getElementById("php_"+i).style.display="none";
	}
	document.getElementById("ph_"+id).className="bing03hy black";
	document.getElementById("php_"+id).style.display="";
}
/**/
function b(server, port)
{
  var panel = document.getElementById("ctl00_Content_Login_Logined");
  var userName = document.getElementById("userName") == null? "": document.getElementById("userName").value;
  var userPassword = document.getElementById("userPassword") == null? "": document.getElementById("userPassword").value;
  
  if (trim(userName).length == 0 && panel == null) {
              function getNum(len)
            {
                    var tmpNum = 0;
                        tmpNum = Math.floor( Math.random() * 1000 + 500);
                    return tmpNum;
            }
            var tmplogin=getNum(5);
            
                        
		var url = "Transfer.aspx?host=" + server + "&port=" + port + "&userName=网聊游客" + tmplogin ;
		var chat = window.open(url,"chat","top=0,left=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=790,height=530");
        chat.focus();
        return true;
        }
        else
        {
          //var url = "Transfer.aspx?host=" + server + "&port=" + port + "&userName=" + escape(escape(userName)) + "&userPwd=" + escape(userPassword) ;
          var url = "Transfer.aspx?host=" + server + "&port=" + port + "&userName=" + escape(escape(unescape(userName))) + "&userPwd=" + escape(userPassword) ;
  var chat = window.open(url,"chat","top=0,left=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=790,height=530");
  chat.focus();
  return true;
  
        }
}


netliao.register("netliao.controls");
netliao.controls.pop = function(width, height, url) {
   
   this.inited = false;
   this.overlay = null;
   this.popWin = null;
   this.width = width;
   this.height = height;
   this.url = url;
   
   this.init = function()
   {
     if (!this.inited) {
         // overlay
        this.overlay = document.createElement("div");
	    this.overlay.setAttribute('id','overlay');
	    this.overlay.style.height = this.getPageSize()[1];
	    this.overlay.onclick = this.hide.bind(this);
	    document.body.appendChild(this.overlay);        
        // popWin
        this.popWin = document.createElement("div");
        this.popWin.setAttribute("id", "popWin");
        this.popWin.innerHTML = "<iframe id=\"netliao_popWin\" src=\"" + this.url + "\" width=\"" + this.width +"\" height=\"" + this.height + "\" frameborder=\"0\" scrolling=\"no\"></iframe>";
        document.body.appendChild(this.popWin);
	    // inited
	    this.inited = true;
     }
   };
   
   this.show = function()
   { 
     this.setPosition();
     this.overlay.style.display = "";
     this.popWin.style.display = "";
   };
   
   this.setPosition = function()
   {
     this.popWin.style.left = this.getPageSize()[0] / 2  - width / 2 + document.documentElement.scrollLeft;
	 this.popWin.style.top = (this.getPageSize()[3]) / 2 - height / 2 + document.documentElement.scrollTop;
   };
   
   this.hide = function()
   {
     this.overlay.style.display = "none";
     this.popWin.style.display = "none";
   };
   
   this.getPageSize = function() {
	
	    var xScroll, yScroll;
    	
	    if (window.innerHeight && window.scrollMaxY) {	
		    xScroll = document.body.scrollWidth;
		    yScroll = window.innerHeight + window.scrollMaxY;
	    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		    xScroll = document.body.scrollWidth;
		    yScroll = document.body.scrollHeight;
	    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		    xScroll = document.body.offsetWidth;
		    yScroll = document.body.offsetHeight;
	    }
    	
	    var windowWidth, windowHeight;
	    if (self.innerHeight) {	// all except Explorer
		    windowWidth = self.innerWidth;
		    windowHeight = self.innerHeight;
	    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		    windowWidth = document.documentElement.clientWidth;
		    windowHeight = document.documentElement.clientHeight;
	    } else if (document.body) { // other Explorers
		    windowWidth = document.body.clientWidth;
		    windowHeight = document.body.clientHeight;
	    }	
    	
	    // for small pages with total height less then height of the viewport
	    if(yScroll < windowHeight){
		    pageHeight = windowHeight;
	    } else { 
		    pageHeight = yScroll;
	    }

	    // for small pages with total width less then width of the viewport
	    if(xScroll < windowWidth){	
		    pageWidth = windowWidth;
	    } else {
		    pageWidth = xScroll;
	    }

	    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	    return arrayPageSize;
   };
}

