//var is_opera = (navigator.userAgent.toLowerCase().indexOf("opera") != -1);
var BG_ID = 'divBG';
var BOX_ID = 'divBox';

function _get(idName){
	return document.getElementById(idName);
}

function getBodySize(){
	var bodySize = [];
	with(document.documentElement) {
		bodySize[0] = (scrollWidth>clientWidth) ? scrollWidth : clientWidth;
		bodySize[1] = (scrollHeight>clientHeight) ? scrollHeight : clientHeight;
	}
	return bodySize;
}

function isIE() {
	return (document.all && window.ActiveXObject && !window.opera) ? true : false;
}

function showDivWin(bgId, boxId, strContent, strTitle) {
	showDivBG(bgId);
	var TOP_HEIGHT = 150;    //弹出窗口离顶部的距离
	if(_get(boxId))
	{
		_get(boxId).parentNode.removeChild(_get(boxId));
	}
	var strBox = '\
		<h3><a href="javascript:void(0);" onclick="closeWindow();"><img src="../../images/close.gif" alt="关闭" /></a>'+strTitle+'</h3>\
		<div id="divContent">'+strContent+'</div>';
	var divBox = document.createElement('div');
	divBox.id = boxId;
	divBox.className = 'poping';
	divBox.innerHTML = strBox;
	document.body.appendChild(divBox);
	with(divBox.style){
		zIndex = 102;
		position = 'absolute';
		var scrollTop = document.body.scrollTop + document.documentElement.scrollTop;
		left = (document.documentElement.clientWidth - divBox.offsetWidth) / 2 + 'px';
		top = (scrollTop + TOP_HEIGHT) + 'px';
	}
}

function showDivBG(bgId){
	if (_get(bgId))
	{
		_get(bgId).style.display='block';
	} else {
		var divBG = document.createElement('div');
		divBG.id = bgId;
		divBG.className = 'divBG';
		document.body.appendChild(divBG);
		with (divBG.style) {
			var bodySize = getBodySize();
			width = bodySize[0] + 'px';
			height = bodySize[1] + 'px';
			zIndex = 101;
			position = 'absolute';
			background = '#999999';
			left = '0px';
			top = '0px';
			if (isIE()) {
				filter = "Alpha(Opacity=60)";
			} else {
				opacity = 0.6;
			}
		}
	}
}

function closeWindow(){
	_get(BG_ID).style.display = 'none';
	_get(BOX_ID).parentNode.removeChild(_get(BOX_ID));
}

function closeParentWindow(){
	window.parent.closeWindow();
}

//type: 0:内容  1:Url
function openWindow(a_type, strContent, strTitle){
	var strCon='';
	switch (a_type)
	{
	case 0:
		strCon += strContent;
		break;
	case 1:
		strCon += '<center><iframe width="479px" height="100%" src="'+strContent+'" frameborder="0" scrolling="no" onload="getIframeHeight(this);"></iframe></center>';
		break;
	default:
		strCon += strContent;
		break;
	}
	showDivWin(BG_ID, BOX_ID, strCon, strTitle);
}

function getIframeHeight(obj) {
	try{
		var bHeight = obj.contentWindow.document.body.scrollHeight;
		var dHeight = obj.contentWindow.document.documentElement.scrollHeight;
		var height = Math.max(bHeight, dHeight);
		obj.height =  height;
	}catch (ex){
		obj.height = 300;
	}
}

function editItem(itemStr) {
	if (itemStr == 'other_name') {
		openWindow(300, 150, 1, "editItem.jsp", "修改片名");
	} else {
		openWindow(300, 150, 1, "index.jsp", "修改片名");
	}
/*	switch (itemId)
	{
	case 0:
		openWindow(300, 150, 1, "edit.html", "修改片名");
		break;
	case 1:
		openWindow(300, 150, 1, "test.html", "修改导演");
		break;
	default:
		break;
	}
*/	
}

function editItemProperty(url,title) {
		openWindow( 1, url, title);

/*	switch (itemId)
	{
	case 0:
		openWindow(300, 150, 1, "edit.html", "修改片名");
		break;
	case 1:
		openWindow(300, 150, 1, "test.html", "修改导演");
		break;
	default:
		break;
	}
*/	
}

function mailBox(url){
	openWindow(1, url, '推荐');
}