﻿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;
}
/* menu */
netliao.tabMenu[0] = new Array();
netliao.tabMenu[0][0] = new netliao.tabMenu.Item("首页", "/");
netliao.tabMenu[0][1] = new netliao.tabMenu.Item("首页分类", "/");
netliao.tabMenu[1] = new Array();
netliao.tabMenu[1][0] = new netliao.tabMenu.Item("聊天室区", "/");
netliao.tabMenu[2] = new Array();
netliao.tabMenu[2][0] = new netliao.tabMenu.Item("用户管理", "/");
netliao.tabMenu[3] = new Array();
netliao.tabMenu[3][0] = new netliao.tabMenu.Item("房间申请", "/");
netliao.tabMenu[4] = new Array();
netliao.tabMenu[4][0] = new netliao.tabMenu.Item("房间管理", "/");
netliao.tabMenu[5] = new Array();
netliao.tabMenu[5][0] = new netliao.tabMenu.Item("E币购买", "/");
/* tab menu */
function toggleMenu(mID)
{
   for (var i=0; i<6; i++)
   {
     var href = document.getElementById("m"+i);
     if (i == mID)
       href.style.backgroundImage = "url(/images/bg_navFirst_over.gif)";
     else
       href.style.backgroundImage = "url(/images/bg_navFirst.gif)";
   }
   
   var container = document.getElementById("navSecond_Container");
   if (netliao.tabMenu[mID] && container)
   { 
     // clear
     container.innerHTML = "";
     // append
     for (var i=0; i<netliao.tabMenu[mID].length; i++)
     { 
       var li = document.createElement("li");
       var href = document.createElement("a");
       href.innerHTML = netliao.tabMenu[mID][i].name;
       href.href = netliao.tabMenu[mID][i].href;
       li.appendChild(href);
       container.appendChild(li);
     }
   }
}

//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) {
//    if (window.confirm("对不起,您还没有登陆,是否登陆?"))
//    {
//        var nl = new netliao.controls.pop(201, 201, "/SmartLogin.aspx");
//        nl.init();
//        nl.show();
//    }
//    return false;
//  }  
//    
//  var url = "/Transfer.aspx?host=" + server + "&port=" + port + "&userName=" + escape(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;
   };
}