//document.getElementById
function _(element) 
{
    if (arguments.length > 1) 
    {
        for (var i = 0, elements = [], length = arguments.length; i < length; i++)
          elements.push($(arguments[i]));
        return elements;
    }
    else
        return document.getElementById(element);
}

function getWindowSize() {
	var a = {
		'width' : 0,
		'height' : 0
	};
	if (self.innerHeight) {
		a.width = self.innerWidth;
		a.height = self.innerHeight
	} else if (document.documentElement
			&& document.documentElement.clientHeight) {
		a.width = document.documentElement.clientWidth;
		a.height = document.documentElement.clientHeight
	} else if (document.body) {
		a.width = document.body.clientWidth;
		a.height = document.body.clientHeight
	}
	return a
}

function getPosition(a) {
	if (typeof(a) == 'string')
		a = $(a);
	var b = a.offsetTop;
	var c = a.offsetLeft;
	var d = a.offsetWidth;
	var e = a.offsetHeight;
	while (a = a.offsetParent) {
		b += a.offsetTop - a.scrollTop;
		c += a.offsetLeft - a.scrollLeft
	}
	var f = {
		'top' : b,
		'left' : c,
		'width' : d,
		'height' : e
	};
	return f
}

function centerDiv(a, b, c, d) {
	c = parseInt(c);
	d = parseInt(d);
	if (typeof(a) == 'string') {
		a = $(a)
	}
	if (a) {
		try {
			a.style.margin = parseInt(0 - a.offsetHeight / 2) + 'px 0 0 '
					+ parseInt(0 - a.offsetWidth / 2) + 'px';
			if (isNaN(c)) {
				a.style.left = '50%'
			} else {
				a.style.left = '0px';
				a.style.marginLeft = c + 'px'
			}
			if (isNaN(d)) {
				a.style.top = '50%'
			} else {
				a.style.top = '0px';
				a.style.marginTop = d + 'px'
			}
			a.style.position = 'absolute'
		} catch (e) {
		};
		if (b == null)
			b = true;
		if (b) {
			setTimeout("centerDiv('" + a.id + "')", 500)
		}
	}
}

function getSelectCopy(/*string*/ obj)
{
   $('#'+obj).select();
   _sTxt = $('#'+obj).val();
   
   if($.browser.msie) {
      clipboardData.setData('Text',_sTxt);
      alert ("Copy the link successfully!");
   } else {
      prompt("Copy the link:",_sTxt); 
   }
}

//init the server list
function areaChanged(value, type) 
{
	oAreaId = _('area_id');
	oServerId = _('server_id');

    var area = serverList[0];
    for (var i=0; i<serverList.length; i++) 
    {
        if (serverList[i].id == value) 
		{
        	area = serverList[i];
        	break;
        }
    }
            
    if (area) 
    {
        oServerId.options.length = 0;
        for (var i=0; i<area.sub.length; i++) 
        {
        	oServerId.options.add(new Option(area.sub[i].name, area.sub[i].id));
        	if ('1' == area.sub[i].id) 
        		oServerId.options[i].selected = true;
        }
    }
}

//初始化服务器列表
function initServerList()
{
	try
	{
		oAreaId = _('area_id');
		oServerId = _('server_id');
		oAreaId.options.length = 0;
	        
		for (var i=0; i<serverList.length; i++) 
		{
			oAreaId.options.add(new Option(serverList[i].name,serverList[i].id));
			if ('1' == serverList[i].id) 
				oAreaId.options[i].selected = true;
		}
		
		areaChanged(1,0);		
	}
	catch(e){}	
}

function changeCode()
{
	_('_code').src='index.php?do=code&'+Math.random();
}

function changeCode2()
{
	_('_code2').src='index.php?do=code&'+Math.random();
}

$(function()
   {
	   initServerList();
	
   }
)


function getRemark(/*int*/limit)
{
	$("#remark_id").load(
		'index.php?do=remark',
		{limit:limit},
		function (){}
	);
}


function _logout(){
    $.post(
        'index.php?do=Logout',
        function(data){
           top.location.reload();
        }
    )
}


