var _ = function(e) { return document.getElementById(e);}
var ownerload = function(o,state) {
	if(state == 'complete') {
		o.html(_('loadframe').contentWindow.document.body.innerHTML);
		N139.reloadsize();
	}
};
$.fn.ownerload = function(turl) {
	var me = this;
	if(!_('loadframe')) {
		var frame = document.createElement('iframe');
		frame.id = 'loadframe';
		frame.frameBorder = 0;
		frame.style.width = frame.style.height = '0px';
		frame.src = 'about:blank';
		document.body.appendChild(frame);
	}
	_('loadframe').onreadystatechange = _('loadframe').onload = function() {
			ownerload(me,document.all ? _('loadframe').readyState : 'complete');
	};
	if(turl.indexOf('?') == -1) {
		turl += '?cln=1';
	} else {
		turl += '&cln=1';
	}
	_('loadframe').src = turl + '&PHPSESSID=' + SID;
	return this;
};
function getViewportInfo() {
    var w = (window.innerWidth) ? window.innerWidth : (document.documentElement && document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body.offsetWidth;
    var h = (window.innerHeight) ? window.innerHeight : (document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.offsetHeight;
    return {width:w,height:h};
}
function show(caption,url,width,notload) {
	if(!_('zoomimglayer_bg')) {
		var div = document.createElement('div');
		div.id = 'zoomimglayer_bg';
		div.style.position = 'absolute';
		div.style.left = div.style.top = '0px';
		div.style.width = '100%';
		result = getViewportInfo();
		div.style.height = document.body.scrollHeight < result.height ? result.height + 'px' : document.body.scrollHeight  + 'px';
		div.style.backgroundColor = '#000';
		div.style.display = 'none';
		div.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=60,finishOpacity=100,style=0)';
		div.style.opacity = 0.6;
		div.style.zIndex = 999;
		document.body.appendChild(div);
	}
	if(!_('boxlayer')) {
		var div = document.createElement('div');
		div.id = 'boxlayer';
		div.style.position = 'absolute';
		div.style.zIndex = 9999;
		div.style.display = 'none';
		document.body.appendChild(div);
	}
	hideobjects(true);
	_('zoomimglayer_bg').style.display = '';	
	$('#boxlayer').css('width',width + 'px').show();
	$('<h3 id="boxtitle"></h3>').html(caption).appendTo($('#boxlayer'));
	if(typeof notload != 'undefined' && notload == true) {
		$('<p></p>').html(url).appendTo($('<div></div>').addClass('boxct').appendTo($('#boxlayer')));
	} else {
		$('<p></p>').html('<div align="center"><img src="./images/loading.gif" /> 正在讀取...</div>').ownerload(url).appendTo($('<div></div>').addClass('boxct').appendTo($('#boxlayer')));
	}
	var pos = getpos(_('boxlayer'));
	$('#boxlayer').css('left',pos.left).css('top',pos.top).addClass('autoheight');
}

function hide() {
	hideobjects(false);
	$('#boxlayer').html('');
	_('zoomimglayer_bg').style.display = _('boxlayer').style.display = 'none';
}

function getpos(obj) { 
	var left = document.body.clientWidth / 2 - obj.clientWidth / 2;
	var top = document.documentElement.scrollTop ? document.documentElement.scrollTop + 150 : document.body.scrollTop + 150 ;
	return { 'left' : left, 'top' : top };
}

function hideobjects(b) {
	if(b) {
		$('select').css('visibility','hidden');
		$('embed').css('visibility','hidden');
	} else {
		$('select').css('visibility','visible');
		$('embed').css('visibility','visible');
	}
}

function getvalue(name) {
	var eles = document.getElementsByName(name);
	var value = '';
	for(var i = 0; i < eles.length; i++) {
		if(eles[i].type == 'radio' && eles[i].checked) {
			value = eles[i].value;
			break;
		}
	}
	return value;
}

function _void(uid) {
	if(typeof getMovie == 'function') {
		window.scrollTo(0,0);
		changestall(0,uid);
	} else {
		$.ajax({
			'url' : 'ajax.php?ac=getspaceurl&uid=' + uid,
			'type' : 'GET',
			'dataType' : 'json',
			'success' : function(json) {
				if(json.success) {
					location.href = json.spaceurl;
				}
			}
		});
	}
}

var oldproc = $.ajax;
$.ajax = function(o) {
	o.url = o.url + '&cln=1&rndid=' + Math.random() + '&PHPSESSID=' + SID;
	oldproc(o);
};
window.onerror = function(e) {return true;};

function redirect(url) {
	location.href = url + '&PHPSESSID=' + SID;
}
