var index= 0;
var contentWin = null;
var ajax_param;
var timeout;
function before_ajax_search(id){
   $('search_result').innerHTML = '<table width="780" align=center><tr><td><div class="loading_div">'+'<img src="/mitchell/bbs/images/loading.gif" position="absmiddle"/> 正在搜索...</div></td></tr></table>';
   $('search_submit').disabled = true;
   ajax_param="keyword="+encodeURI($F("kw"))+"&bbsid="+$F("bv");
}
function after_ajax_search(id,hide_objs){
   Element.hide('search_result');
   $('search_submit').disabled = false;
}
function before_ajax_call(id){
   ajax_param=Application.getNewId();
   $('search_result').innerHTML = '<table width="780"><tr><td><div class="loading_div">'+'<img src="/mitchell/bbs/images/loading.gif" position="absmiddle"/> 正在加载...</div></td></tr></table>';
   $('search_submit').disabled = true;
}
function after_ajax_call(id,hide_objs){
   Element.hide('search_result');
   $('search_submit').disabled = false;
}

function before_ajax_call1(id){
   ajax_param=Application.getNewId();
   $('box_area').innerHTML = '<table width="780"><tr><td><div class="loading_div">'+'<img src="/mitchell/bbs/images/loading.gif" position="absmiddle"/> 正在加载...</div></td></tr></table>';
   //$('search_submit').disabled = true;
}
function after_ajax_call1(id,hide_objs){
   //Element.hide('search_result');
   //$('search_submit').disabled = false;
}

function before_ajax_pm(id,id2){
   $(id2).innerHTML = '<table width="100%"><tr><td><div class="loading_div">'+'<img src="/mitchell/bbs/images/loading.gif" position="absmiddle"/> 正在加载...</div></td></tr></table>';
   $(id).disabled = true;
}
function toogle(id){
	Element.hide(id);
}
function show_div(id){
	Element.show(id);
}
function after_ajax_pm(id,hide_objs){
   $(id).disabled = false;
}
function checkall(form, prefix, checkall) {
	var checkall = checkall ? checkall : 'chkall';
	for(var i = 0; i < form.elements.length; i++) {
		var e = form.elements[i];
		if(e.name != checkall && (!prefix || (prefix && e.name.match(prefix)))) {
			e.checked = form.elements(checkall).checked;;
		}
	}
}
function has_one_element(form, prefix, checkall) {
	var checkall = checkall ? checkall : 'chkall';
	for(var i = 0; i < form.elements.length; i++) {
		var e = form.elements[i];
		if(e.name != checkall && (!prefix || (prefix && e.name.match(prefix)))) {
			if(e.checked==true){
				return true;
			}
		}
	}
	return false;
}
//发送短消息

function before_ajax_sendpm(sendtype,resultid,buttonid){
	if(sendtype=="rece_id"){
		ajax_param="title="+encodeURI($F('title_id'))+"&msg="+encodeURI(document.getElementById("msg_id").value)+"&rece_id="+document.getElementById("rece_id_id").value+"&actiontype="+$F('actiontype_id');
	}else if(sendtype="rece_name"){
		ajax_param="title="+encodeURI($F('title_id'))+"&msg="+encodeURI(document.getElementById("msg_id").value)+"&rece_name="+encodeURI(document.getElementById("rece_name_id").value)+"&actiontype="+$F('actiontype_id');
	}
   $(resultid).innerHTML = '<table width="100%"><tr><td><div class="loading_div">'+'<img src="/mitchell/bbs/images/loading.gif" position="absmiddle"/> 正在发送...</div></td></tr></table>';
   $(buttonid).disabled = true;
}
function after_ajax_sendpm(id,hide_objs){
   $('sendpm_submit').disabled = false;
}

function checkSendForm(sendtype,resultid,buttonid,ajaxurl){
	if($F('title_id')==""||$F('title_id').length>50||$F('title_id').length<5){
		alert("填写标题(长度在5-50字符之间)!");
		$('title_id').focus();
		return false;
	}
	if(sendtype=="rece_id"){
		if($F('rece_id_id')==""||$F('rece_id_id').length>50||$F('rece_id_id').length<2){
		alert("填写接收人(长度在5-50字符之间)!");
		$('rece_id_id').focus();
		return false;
	}
	}else if(sendtype=="rece_name"){
		if($F('rece_name_id')==""||$F('rece_name_id').length>50||$F('rece_name_id').length<2){
			alert("填写接收人(长度在5-50字符之间)!");
			$('rece_name_id').focus();
			return false;
		}
	}
	if($F('msg_id')==""||$F('msg_id').length>100000||$F('msg_id').length<10){
		alert("填写内容(长度在10-100000字符之间)!");
		$('msg_id').focus();
		return false;
	}
	before_ajax_sendpm(sendtype,resultid,buttonid);
	new Ajax.Updater(resultid, ajaxurl, {asynchronous:true, evalScripts:true, onComplete:function(request){new Effect.BlindDown(resultid,{duration: 1});eval(request.responseText);}, onSuccess:function(request){after_ajax_sendpm();}, parameters:ajax_param});
	return false;
}

function setPmStatus(msg){
	win=self.parent.Windows.getFocusedWindow();
	win.setStatusBar(msg);
}
function pm_show_notlogin(id){
	var pm_id=Application.getNewId();
	var titles="发送站内短消息"+pm_id;
	var wl="450";
	var hl="230";
	var urls="/mitchell/bbs/user/login_js.jsp?url=/mitchell/bbs/pm_send.jsp&uid="+id;
	win4 = new Window(pm_id, {className: "dialog", title: titles, recenterAuto:true,width:wl, height:hl, resizable: false,closable: true, url: urls, showEffectOptions: {duration:1},wiredDrag: true,maximizable: false})
	win4.setStatusBar("<img src=/mitchell/bbs/images/info.gif>"+"<font color=red>登陆成功后自动跳转发送短消息页面</font>");
	win4.showCenter();
}
function pm_show_login(id){
	var titles="发送站内短消息";
	var wl="450";
	var hl="230";
	var urls="/mitchell/bbs/pm_send.jsp?uid="+id;
	win4 = new Window(Application.getNewId(), {className: "dialog", title: titles, recenterAuto:true,width:wl, height:hl, resizable: false,closable: true, url: urls, showEffectOptions: {duration:1},wiredDrag: true,maximizable: false})
	win4.setStatusBar("<img src=/mitchell/bbs/images/info.gif>"+"发送成功后会自动关闭");
	win4.showCenter();
}
//----------end
//post form ajax ---------------start
function edit_reply(id,id2){
	var titles="修改回帖";
	var wl="680";
	var hl="350";
	var urls="/mitchell/bbs/user/reply_edit.jsp?id="+id+"&id2="+id2;
	win4 = new Window(Application.getNewId(), {className: "dialog", title: titles, recenterAuto:true,width:wl, height:hl, resizable: false,closable: true, url: urls, showEffectOptions: {duration:1},wiredDrag: true,maximizable: false})
	win4.showCenter();
}
function edit_post(id,id2){
	var titles="修改主帖";
	var wl="680";
	var hl="350";
	var urls="/mitchell/bbs/user/post_edit.jsp?id="+id+"&id2="+id2;
	win4 = new Window(Application.getNewId(), {className: "dialog", title: titles, recenterAuto:true,width:wl, height:hl, resizable: false,closable: true, url: urls, showEffectOptions: {duration:1},wiredDrag: true,maximizable: false})
	win4.showCenter();
}
function closeCurrentWin(){
	win=self.parent.Windows.getFocusedWindow();
	win.hide();
}
function ajaxRefreshParent(id){
	self.parent.Windows.getFocusedWindow().hide();
	self.parent.selftest(id);
}
function onlyRefresh(){
	win=self.parent.Windows.getFocusedWindow();
	win.hide();
	self.parent.window.location.reload(false);
}
function selftest(id){
	$(id).click();
}
function before_ajax_thread(sendtype,resultid,buttonid){
	if(sendtype=="editPostThread"){
		//ajax_param="title="+encodeURI($F('title_id'))+"&descr="+encodeURI($F('descr_id'))+"&id="+document.getElementById("id_id").value+"&actiontype="+$F('actiontype_id')+"&copyright="+encodeURI($F('copyright_id'))+"&face="+encodeURI($F('face_id'))+"&afterMethod="+encodeURI($F('afterMethod_id'));
		ajax_param="title="+encodeURI($F('title_id'))+"&descr="+encodeURI($F('descr_id'))+"&id="+document.getElementById("id_id").value+"&actiontype="+$F('actiontype_id')+"&copyright="+$F('copyright_id')+"&face="+$F('face_id')+"&afterMethod="+$F('afterMethod_id');
		//alert(ajax_param);
	}else if(sendtype="editReplyThread"){
		//ajax_param="title="+encodeURI($F('title_id'))+"&descr="+encodeURI($F('descr_id'))+"&id="+document.getElementById("id_id").value+"&actiontype="+$F('actiontype_id')+"&face="+encodeURI($F('face_id'))+"&afterMethod="+encodeURI($F('afterMethod_id'));
		ajax_param="title="+encodeURI($F('title_id'))+"&descr="+encodeURI($F('descr_id'))+"&id="+document.getElementById("id_id").value+"&actiontype="+$F('actiontype_id')+"&face="+$F('face_id')+"&afterMethod="+$F('afterMethod_id');
	}
   $(resultid).innerHTML = '<img src="/mitchell/bbs/images/loading.gif" position="absmiddle"/> 正在发送...';
   $(buttonid).disabled = true;
}
function after_ajax_thread(id,hide_objs){
   Element.hide(id);
   $(hide_objs).disabled=false;
}
function threadAjax(sendtype,resultid,buttonid,ajaxurl){
	if($F('title_id')==""||$F('title_id').length>50||$F('title_id').length<5){
		alert("填写标题(长度在5-50字符之间)!");
		//new Insertion.After('title_id',"<div class=\"validation-advice\" id=\"advice_title_id\">填写标题(长度在5-50字符之间)!</div>");
		$('title_id').focus();
		return false;
	}

	if($F('descr_id')==""||$F('descr_id').length>100000||$F('descr_id').length<10){
		alert("填写内容(长度在10-100000字符之间)!");
		$('descr_id').focus();
		return false;
	}
	before_ajax_thread(sendtype,resultid,buttonid);
	new Ajax.Updater(resultid, ajaxurl, {asynchronous:true, evalScripts:true, onComplete:function(request){new Effect.BlindDown(resultid,{duration: 1});eval(request.responseText);}, onSuccess:function(request){after_ajax_thread(resultid,buttonid);}, parameters:ajax_param});
	//new Ajax.Updater(resultid, ajaxurl, {asynchronous:true, evalScripts:true, onComplete:function(request){new Effect.BlindDown(resultid,{duration: 1});eval(request.responseText);}, onSuccess:function(request){after_ajax_thread(resultid,buttonid);}, parameters:Form.serialize(this)});
	return false;
}

//post form ajax end --------------
function before_ajax_send1(id){
   ajax_param="actiontype="+document.getElementById("atid").value;
   alert(ajax_param);
   $('admin_div').innerHTML = '<table width="100%"><tr><td><div class="loading_div">'+'<img src="/mitchell/bbs/images/loading.gif" position="absmiddle"/> 正在发送...</div></td></tr></table>';
   $('admin_button').disabled = true;
}
function after_ajax_send1(id,hide_objs){
   //Element.hide('search_result');
	//$('search_result').innerHTML = '';
   $('admin_button').disabled = false;
}
function before_ajax_super(id){
   ajax_param="threadid="+$F("threadid_id")+"&why="+encodeURI($F("why_id"))+"&actiontype="+$F('actiontype_id');
   //alert($('search_result').innerHTML);
   $('search_result').innerHTML = '<div id=search_result>'+'<img src="/mitchell/bbs/images/loading.gif" position="left"/></div>';
   //alert($('search_result').innerHTML);
   $('search_submit').disabled = true;
}
function after_ajax_super(id,hide_objs){
   $('search_result').innerHTML = '';
   //Element.hide('search_result');
   $('search_submit').disabled = false;
}
function checkResult(){
	win=self.parent.Windows.getFocusedWindow();
	if($('search_result').innerHTML.indexOf("成功")>-1){
		$('search_submit').disabled=true;
		setPmStatus("<img src=/mitchell/bbs/images/info.gif height=10>"+"<font color=red>3秒后自动关闭</font>");
		timeout=4;
		setTimeout('closeWindowIframe()','1000');
		win.setStatusBar("<img src=/mitchell/bbs/images/info.gif height=10>"+"<span class=all_hre><font color=red>"+$('search_result').innerHTML+"</font></span>");
	}else{	
		//$('search_result').innerHTML = '';
		win.setStatusBar("<img src=/mitchell/bbs/images/info.gif height=10>"+$('search_result').innerHTML);
	}
}
function closeWindowIframe(){
	win=self.parent.Windows.getFocusedWindow();
	win.setStatusBar("<img src=/mitchell/bbs/images/info.gif>"+timeout+"秒后" + "关闭 ...")
	timeout--;
	if(timeout >0) {
		win.setStatusBar("<img src=/mitchell/bbs/images/info.gif>"+timeout+"秒后" + "关闭 ...")
		setTimeout("closeWindowIframe()", 1000)
	 }else{
		if($('search_result').innerHTML.indexOf("成功")>-1){
			win.hide();
		}else{	
			win.setStatusBar("<img src=/mitchell/bbs/images/info.gif>"+"发送短信失败!");
		}
	 }
}

function login_show(){
	win3 = new Window(Application.getNewId(), {className: "dialog", title: "登陆", recenterAuto:true,width:300, height:200, closable: true, url: "user/login_js.jsp", showEffectOptions: {duration:1},wiredDrag: true})
	win3.showCenter();
}
function viewUserInfo(userid){
	var win_id=Application.getNewId();
	win4 = new Window(win_id, {className: "dialog", title: "察看用户信息", recenterAuto:true,width:300, height:200, closable: true, url: "viewuserinfo.jsp?userid="+userid, showEffectOptions: {duration:1},wiredDrag: true})
	win4.setStatusBar("<img src=/mitchell/bbs/images/info.gif>"+"5秒后自动关闭...");
	timeout=5;
	setTimeout("infoTimeout('"+win_id+"')", 1000)
	win4.showCenter();
}	
function infoTimeout(winid) {
  win=Windows.getWindow(winid);
  timeout--;
  if(timeout >0) {
    win.setStatusBar("<img src=/mitchell/bbs/images/info.gif>"+timeout+"秒后" + "关闭 ...")
	setTimeout("infoTimeout('"+winid+"')", 1000)
   }else{
    win.hide();
  }
}

function supervision(id){
	win4 = new Window(Application.getNewId(), {className: "dialog", title: "举报不良帖子", recenterAuto:true,width:300, height:200, resizable: false,closable: true, url: "supervision.jsp?id="+id, showEffectOptions: {duration:1},wiredDrag: true,maximizable: false})
	win4.setStatusBar("<img src=/mitchell/bbs/images/info.gif>"+"举报成功后会自动关闭");
	win4.showCenter();
}	
function ope_show(id,titles,wl,hl){
	win4 = new Window(Application.getNewId(), {className: "dialog", title: titles, recenterAuto:true,width:wl, height:hl, resizable: false,closable: true, url: id, showEffectOptions: {duration:1},wiredDrag: true,maximizable: false})
	win4.showCenter();
}
function online_show(){
	win3 = new Window(Application.getNewId(), {className: "dialog", title: "&nbsp;察看在线用户", recenterAuto:true,width:400, height:400, closable: true, url: "online.jsp", showEffectOptions: {duration:1},wiredDrag: true})
	win3.showCenter();
}
function search_show(){
	win4 = new Window(Application.getNewId(), {className: "dialog", title: "论坛查询", recenterAuto:true,width:300, height:200, closable: true, url: "search_msgbox.jsp", showEffectOptions: {duration:1},wiredDrag: true})
	win4.showCenter();
}
function gourls(url){
	if($(url).value=="no") return;
	window.location=$(url).value;
}


function viewPminfo(id){
	var titles="管理短消息>>发件箱";
	var wl="400";
	var hl="300";
	var urls="/mitchell/bbs/user/viewPminfo.jsp?id="+id;
	win4 = new Window(Application.getNewId(), {className: "dialog", title: titles, recenterAuto:true,width:wl, height:hl, resizable: false,closable: true, url: urls, showEffectOptions: {duration:1},wiredDrag: true,maximizable: false})
	win4.showCenter();
}
function checkName(){
	SelectedId=document.getElementById("login_name").value;
	if (SelectedId==""||SelectedId.length<5||SelectedId.length>20) {
		document.getElementById("msgs").innerHTML="";
		return
	}
	var targetObj='msgs';
	document.getElementById(targetObj).parentNode.style.display = "";
	document.getElementById(targetObj).innerHTML = "正在读取数据..."
	currentPos = targetObj;
	send_request("check_uname.jsp?login_name="+SelectedId);
}

function area_change(obj){
	SelectedId=obj.options[obj.selectedIndex].value;
	if (SelectedId=='no') { 
		return
	}
	var targetObj='country';
	document.getElementById(targetObj).parentNode.style.display = "";
	document.getElementById(targetObj).innerHTML = "正在读取数据..."
	currentPos = targetObj;
	var pars="";
	var url="getCountry.jsp?type="+SelectedId;
	var myAjax = new Ajax.Updater(targetObj, url, {method: 'get', parameters: pars});
}

function country_changed(obj){
	SelectedId=obj.options[obj.selectedIndex].value;
	if (SelectedId=='no') { 
		return
	}
	var targetObj='city';
	document.getElementById(targetObj).parentNode.style.display = "";
	document.getElementById(targetObj).innerHTML = "正在读取数据..."
	currentPos = targetObj;
	var pars="";
	var url="getCity.jsp?param="+SelectedId;
	var myAjax = new Ajax.Updater(targetObj, url, {method: 'get', parameters: pars});
}
//修改用户信息form check script
function checkFormProfile(){
	var theForm=document.changeInfoForm;
	if(theForm.email.value.trim()==""){
		theForm.email.focus();
		alert("email不能为空!");
		return false;
	}
	if(!isEmail(theForm.email.value)){
		theForm.email.focus();
		alert("email格式不正确!");
		return false;
	}
	if(theForm.birthday.value!=""&&!checkDate(theForm.birthday.value)){
		theForm.birthday.focus();
		alert("生日格式不正确!");
		return false;
	}
	return true;
}
function opennewwin1(){
	window.open("photo_profile.jsp","photo","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=500,height=200,left=200,top=200");
}
function checkForm(){
	var theForm=document.form1;
	if(!isPasswd(theForm.newpass.value.trim())){
		theForm.newpass.focus();
		alert("新密码：只能输入6-20个字母、数字、下划线");
		return false;
	}
	if(!isPasswd(theForm.checkpass.value.trim())){
		theForm.checkpass.focus();
		alert("新密码确认：只能输入6-20个字母、数字、下划线");
		return false;
	}
	if(theForm.newpass.value!=theForm.checkpass.value){
		theForm.newpass.focus();
		alert("新密码和新密码确认不一样!");
		return false;
	}
	return true;
}

function checkPmForm(){
	var theForm=document.pmForm;
	if(theForm.title.value.trim()==""){
		theForm.title.focus();
		alert("标题不能为空!");
		return false;
	}
	if(theForm.keyword.value.trim()==""){
		theForm.keyword.focus();
		alert("内容不能为空!");
		return false;
	}
	return true;
}


function doBbsCollapse(mainid,bbstableid){
	var targetObj="subs_"+mainid;
	$(targetObj).style.display = "block";
	$(targetObj).innerHTML = "<img src=\"/mitchell/bbs/images/loading.gif\" border=0>    <span class=all_hre>正在读取数据...</span>";
	currentPos = targetObj;
	var pars="";
	var url="getCollapse.jsp?mainid="+mainid+"&bbsid="+bbstableid;
	var myAjax = new Ajax.Updater(targetObj, url, {method: 'get', parameters: pars});
}
function collapseRevert(id,bbstableid){
	var getid="plus_"+id;
	var srcs=$(getid).src;
	if(srcs.indexOf("images/neplus.gif")>0){
		$(getid).src="images/plus.gif";
		$("subs_"+id).style.display="none";
	}else if(srcs.indexOf("images/plus.gif")>0){
		$(getid).src="images/neplus.gif";
		doBbsCollapse(id,bbstableid);
	}
}
function ResizeImg(id,src){
  var Img=new Image();
  Img.src=src;
  var ImgID=document.getElementById(id);
  if(Img){
    if(Img.width > 500){
		Img.height=Img.height/(Img.width/500);
		Img.width=500;
	}
 ImgID.width=Img.width;
 ImgID.height=Img.height;
  }else{
    setTimeout(ResizeImg(id,src),500);
  }
}
function ResizeImg1(id,src,width){
  var Img=new Image();
  Img.src=src;
  var ImgID=document.getElementById(id);
  if(Img){
    if(Img.width > width){
		Img.height=Img.height/(Img.width/width);
		Img.width=width;
	}
	 ImgID.width=Img.width;
	 ImgID.height=Img.height;
  }else{
    setTimeout(ResizeImg(id,src),width);
  }
}
function ShowImgAll(ImgID0,Pic){
  document.getElementById("imagediv").style.left=0;
  document.getElementById("imagediv").style.top=0;
  document.getElementById("imagediv").style.display="block";
}

function hideImageDiv(ImgID0){
  document.getElementById("imagediv").style.display="none";
}