/**
 * Author:殘雪易冷 | E-mail: xueruos520@163.com                   
 * Copyright (c) 版权所有 无锡君通软件                                   
 * 2010.9.25
 * blog.csnowy.com
 */
var isIe = (document.all) ? true : false;

//设置select的可见状态
function setSelectState(state) {
	var objl = document.getElementsByTagName('select');
	for (var i = 0; i < objl.length; i++) {
		objl[i].style.visibility = state;
	}
}

function mousePosition(ev) {
	if (ev.pageX || ev.pageY) {
		return {
			x: ev.pageX,
			y: ev.pageY
		};
	}
	return {
		x: ev.clientX,
		y: ev.clientY + document.documentElement.scrollTop 
	};
}

//弹出方法
function showMessageBox(wTitle, content, pos, wWidth) {
	closeWindow_body();
	var bWidth = parseInt(document.documentElement.scrollWidth);
	var bHeight = parseInt(document.documentElement.scrollHeight);
	if (isIe) {
		setSelectState('hidden');
	}
	var back = document.createElement("div");
	back.id = "back";
	var styleStr = "top:0px;left:0px;position:absolute;background:#666;width:" + bWidth + "px;height:" + bHeight + "px;";
	styleStr += (isIe) ? "filter:alpha(opacity=40);" : "opacity:0.40;";
	back.style.cssText = styleStr;
	document.body.appendChild(back);
	var mesW = document.createElement("div");
	mesW.id = "_mesWindow";
	mesW.className = "mesWindow";
	mesW.innerHTML = "<div class='mesWindowTop'><table width='100%' height='100%'><tr><td style='font-size:12px; font-weight:bold'><a>- " + wTitle + " -</a></td><td align='right' style='font-size:12px'><a onclick='closeWindow_body();'>[关闭]</a></td></tr></table></div><div class='mesWindowContent' id='mesWindowContent'>" + content + "</div>";
	styleStr = "left:" + pos.x + "px;top:" + (pos.y) + "px;position:absolute;width:" + wWidth + "px;";
	mesW.style.cssText = styleStr;
	document.body.appendChild(mesW);
}

function showBackground(obj, endInt) {
	obj.filters.alpha.opacity += 1;
	if (obj.filters.alpha.opacity < endInt) {
		setTimeout(function() {
			showBackground(obj, endInt)
		}, 8);
	}
}

//关闭窗口
function closeWindow_body() {
	if (document.getElementById('back') != null) {
		document.getElementById('back').parentNode.removeChild(document.getElementById('back'));
	}
	if (document.getElementById('_mesWindow') != null) {
		document.getElementById('_mesWindow').parentNode.removeChild(document.getElementById('_mesWindow'));
	}
	if (isIe) {
		setSelectState('');
	}
}

/**
 * 通用提示信息
 * mes 提示信息 forw 跳转页面
 */
function messBox_alert(mes, forw) {
	var objPos = get_position();
	messContent = get_message(mes);
	showMessageBox('提示信息', messContent, objPos, 350);
	setTimeout("closeWindow_body();", 2000);
    setTimeout("window.location.href='" + forw + "';", 2000);
}

/**
 * 通用提示信息
 * 确定、取消按钮
 * mes 弹出提示信息 fn 点击确定后出发的函数 inf_str 预留传递参数
 */
function messBox_c(mes, fn, inf_str) {
	var objPos = get_position();
	messContent = "<div style='padding:10px 0 10px 0;text-align:center;color:red'>"+ mes +"</div><div style='padding:10px 0 20px 0;text-align:center;color:red'><input type='button' class='but2' onclick='closeWindow_body();' value='取消' /><input type='button' id='" + inf_str + "' onclick='"+ fn +"' class='but2' value='确定' /></div>";
	showMessageBox('提示信息', messContent, objPos, 350);
}

/**
 * 通用提示信息
 * mes 提示信息 用户手动关闭
 */
function messBox_common(mes) {
	var objPos =  {
		x: ((document.body.clientWidth - 350)>0?(document.body.clientWidth - 350):0) / 2 ,
		y: (window.screen.availHeight-350 + document.body.scrollHeight) / 2 
	};
	messContent = "<div style='padding:10px 0 10px 0;text-align:center;color:red'>"+ mes +"</div><div style='padding:10px 0 20px 0;text-align:center;color:red'><input type='button' class='but2' onclick='closeWindow_body();' value='关闭' /></div>";
	showMessageBox('错误提示', messContent, objPos, 350);
}

/**
 * 通用提示信息
 * mes 提示信息 title 提示标题 width 窗体宽度 用户手动关闭
 */
function messBox_common_v(mes, title, width) {
	var objPos =  {
		x: ((document.body.clientWidth - width)>0?(document.body.clientWidth - width):0) / 2 ,
		y: (window.screen.availHeight-350) / 2 
	};
	messContent = "<div style='padding:10px 0 10px 0;text-align:left;'>"+ mes +"</div><div style='padding:10px 0 20px 0;text-align:center;color:red'><input type='button' class='but2' onclick='closeWindow_body();' value='关闭' /></div>";
	showMessageBox(title, messContent, objPos, width);
}

/**
 * 通用提示信息
 *
 */
function messBox_common_p(mes) {
	var objPos =  get_position();
	messContent = "<div style='padding:10px 0 10px 0;text-align:center;color:red'>"+ mes +"</div><div style='padding:10px 0 20px 0;text-align:center;color:red'><input type='button' class='but2' onclick='closeWindow_body();' value='关闭' /></div>";
	showMessageBox('错误提示', messContent, objPos, 350);
}


function get_position(){
	return {
		x: ((document.body.clientWidth - 350)>0?(document.body.clientWidth - 350):0) / 2 ,
		y: (window.screen.availHeight-350 ) / 2 + document.body.scrollTop
	};
}

/* 跳转页面提示信息设置 */
function get_message(mes){
  $message =  "<div style='padding:20px 0 20px 0;text-align:center;color:red'>"+ mes +"<br><img src='images/load.gif' />&nbsp;&nbsp;<font>2秒后进行跳转,请稍后...</font></div>";
  return $message;
}

function member_edit_div(content) {
	var objPos = {
		x: ((document.body.clientWidth - 950)>0?(document.body.clientWidth - 950):0) / 2 ,
		y: 2
	};
	messContent = content;
	showMessageBox('信息修改', messContent, objPos, 950);
}

//发送站内信息
function post_inmess_div(info_user_id) {
	var objPos =  get_position();
	messContent = "";
	showMessageBox('信息发送', messContent, objPos, 950);
}

//搜索弹出DIV
function commonsearch_div(ret) {
	var objPos =  {
		x: ((document.body.clientWidth - 950)>0?(document.body.clientWidth - 950):0) / 2 ,
		y: 2
	};
	messContent = ret;
	showMessageBox('搜索结果', messContent, objPos, 950);
}

/*代码优化*/
function messBox_alert_common(mes, forw, div_id, type, aldi) {
	if(div_id != ''){
	  closeWindow(div_id);	
	}
	var objPos = get_position();
	messContent = get_message(mes);
	showMessageBox('提示信息', messContent, objPos, 350);
	if(type == 1){
	  setTimeout("closeWindow_body();", 3000);
	  setTimeout("window.location.href='" + forw + "';", 3000);
	}else{
	  setTimeout("closeWindow_body();"+ aldi +";", 3000);
	}
}

//上传回调
function changeDom(name, mid, type, url){
	closeWindow('tranDiv_2');
	$('#thumb').val(url);
	$('#thumbid').val(mid);
	$('#showthumb1').attr("src", url);
	$('#upimgspan').text("[重新上传]");
}
