function MM_openBrWindow(theURL,winName,features,w_height,w_width) { //v2.0
	var t = 0, l = 0;
	t = screen.height; l = screen.width;
	
	t = t - w_height; l = l - w_width;
	t = t/2; l = l /2
	//window.open(theURL,winName,features);
	features =features+"top= " + t + "px,height=" + w_height + "px,left=" + l + "px,width=" + w_width + "px" ;
	window.open(theURL,winName,features);
}
function OpenWinByHtmlControl(theURL,Control_id)
{
	var control = document.getElementById(Control_id);	
	if(null!=control)
	{
		theURL=theURL + control.value;
		window.open(theURL);
	}
}
function CloseWindow() 
{
	var ua = navigator.userAgent;
	var IEversion = parseFloat(ua.substring(ua.indexOf("MSIE ")+5, ua.indexOf(";",ua.indexOf("MSIE "))));
	if(IEversion< 5.5) {
		var str = '<object id=noTipClose classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">';
		str += '<param name="Command" value="Close"></object>';
		document.body.insertAdjacentHTML("beforeEnd", str);
		document.all.noTipClose.Click();
	}
	else {
		window.opener =null;
		window.close();
	}
}
function timeout_control(url)
{
	if (null!=parent)
	{
		parent.location.assign(url);
	}
	else
	{
		window.location.assign(url);
	}
}

function assign_main(theUrl,navigation_bar)
{
//	window.parent.frames(0).location.assign('top.aspx?navigation_bar='+navigation_bar);
	window.parent.frames(2).location.assign(theUrl);
}
function assign_self(theUrl,navigation_bar)
{
	window.parent.frames(0).location.assign(window.parent.frames(0).location+";"+navigation_bar);
	window.location.assign(theUrl);
}

//set next ctrl focus when enter keydown event fire
function EnterKeyPress(nextid) { 
	var KeyCode = window.event.keyCode;  
	if(KeyCode == 13)
	{
		FocusThisControl(nextid);
	}
}
//set focus by ctrl's ID
function FocusThisControl(ctrlid) {
	//var ctrl = document.all.item(ctrlid);
	var ctrl = document.getElementById(ctrlid);
	if(null == ctrl)
		return;
	if(true == ctrl.disabled)
		return;
	ctrl.focus();
}
//limit text input length
function LimitTextLength(ctrlid, length) {
	//var ctrl = document.all.item(ctrlid);
	var ctrl = document.getElementById(ctrlid);
	if(null == ctrl)	return;	
	var text = ctrl.value;
	if(text.length <= length)
		return;
	ctrl.value = text.substring(0, length);
}
//check all or not items in DataGrid
function CheckAllGridItem(outckbid, gridid, gridckbid) 
{
	var temp = null;
	
	temp = document.getElementById(gridid);
	if(null == temp)	return;
	var gridlength = temp.rows.length;
	var star_index
	var canchecked = false;
	for (var i = 0; i < 4; i ++) {
		temp = document.getElementById(gridid + "_" + "_ctl" + i + "_" + gridckbid);
		if(null == temp)
		{
			continue;
		}
		else
		{
			canchecked = true;
			star_index=i;
			break;
		}
	}
	
	for (var i = 0; i < 4; i ++) 
	{
		var name=gridid + ":" + "_ctl" + i + ":" + outckbid
		temp = document.getElementById(name);
		if(null == temp)
		{
			continue;
		}
		else
		{
			break;
		}
	}
			
	if(null == temp)	return;

	if(!canchecked)
	{
		temp.checked = false;
	}
	var checkedall = temp.checked;
	for (var i = -3; i < gridlength+star_index; i ++) {
		temp = document.getElementById(gridid + "_" + "_ctl" + (i+3) + "_" + gridckbid);
		if(null == temp)	continue;
		temp.checked = checkedall;
	}
}
//change check all status by checked status in DataGrid
function CheckOneGridItem(outckbid, gridid, gridckbid) 
{
	var temp = null;
	
	temp = document.getElementById(gridid);
	if(null == temp)	return;
	var gridlength = temp.rows.length;
	
	var checkedall = false;
	for (var i = 0; i < 4; i ++) {
		temp = document.getElementById(gridid + "_" + "_ctl" + i + "_" + gridckbid);
		if(null == temp)	continue;
		checkedall = true;	break;
	}
	
	for (var i = -3; i < gridlength; i ++) {
		temp = document.getElementById(gridid + "_" + "_ctl" + (i+3) + "_" + gridckbid);
		if(null == temp)	continue;
		if(temp.checked)	continue;
		else {
			checkedall = false;
			break;
		}
	}
	for (var i = 0; i < 4; i ++) 
	{
		var name=gridid + ":" + "_ctl" + i + ":" + outckbid
		temp = document.getElementById(name);
		if(null == temp)
		{
			continue;
		}
		else
		{
			break;
		}
	}
	
	if(null == temp)	return;
	temp.checked = checkedall;
}
function  onKeyPress(aim){  
	var  KeyCode=window.event.keyCode;  
	if  (KeyCode==13)  
	{
		aim.focus();
	}
}
function refresh_opener(request_full)
{
	if(request_full!=null)
	{
		var index_full=-1;
		var str_address_full=window.opener.location.href;
		index_full=str_address_full.indexOf("?");
		if(index_full<0)
		{
			window.opener.location.assign(window.opener.location+"?"+request_full);
		}
		else
		{
			window.opener.location.assign(window.opener.location+"&"+request_full);
		}
	}
	else
	{
		window.opener.location.assign(window.opener.location);
	}
}
function  onKeyPress_dark()
{  
var  KeyCode=window.event.keyCode;  
if  (KeyCode==13)  
	{
	document.all.btn_DarkQuery.focus();
	}
}
function  onKeyPress()
{
var  KeyCode=window.event.keyCode;  
if  (KeyCode==13)  
	{
	document.all.btn_search.focus();
	}
}
function OpenOfRefresh()
{
	if(null!=window.opener)
	{
		try{
			var openwin = window.opener;
			openwin.location.reload();		
		}
		catch(e){
			return;
		}
	}
}
function ParentOfRefresh()
{
	if(null!=window.parent)
	{
		window.parent.location.assign(window.parent.location);	
	}
	else
	{}
}
function replace(szMain,szBeforereplace,szAfterreplace) 
{ 
  strMain=new String(szMain) 
  arrMain=strMain.split(szBeforereplace) 
  var szReturn 
  szReturn=''; 
  for(var i=0;i<arrMain.length-1;i++) 
{ 
szReturn=szReturn+arrMain[i]+szAfterreplace; 
} 
return szReturn+arrMain[arrMain.length-1]; 
} 
function onload_setfocus(txt_id)
{
	var focus_txt=document.getElementById(txt_id);
	if(focus_txt!=null)
	{
		focus_txt.focus();
	}
	else
	{
	}
}
function trim(value){return value.replace(/(^\s+)|(\s+$)/g,"");}
function loadtitle(vUrl,vHeight)
{
	document.write("<iframe src="+vUrl+" frameBorder=0 width=100% scrolling=no height="+vHeight+"></iframe>");
}
//以下是帖子详情页的js
function getsubject(){
var haha=document.getElementById("HTML_speak_subject");
if(haha!=null)
{haha.value="Re:"+document.title;}
}
function quote(announceid,title,username,dtime){
	var hehe =  document.getElementById("HTML_quotebody"+announceid);
	var she=document.getElementById("HTML_speak_subject");
	if(null!=hehe)
	{
		if(null!=document.getElementById("HTML_speak_Content"))
		{
		document.getElementById("HTML_speak_Content").value ="[quote]"+"[B]以下是引用[I]"+username+"[/I]在"+dtime+"的发言：[/B]\n\n"+hehe.value.replace("<table","").replace(" cellpadding=0 cellspacing=0 border=0 WIDTH=94% bgcolor=#000000","").replace(" align=center>","").replace("<tr>","").replace("<td>","").replace("<table width=100% cellpadding=5 cellspacing=1 border=0","").replace("style=\"font-size:13px\">","").replace("<TR>","").replace("<TD BGCOLOR=#EFF3F9>","").replace("</td>","").replace("</tr>","").replace("</table>","").replace("</td>","").replace("</tr>","").replace("</table>","").replace("\n","") + "[/quote]";
		document.getElementById("announceid").value = announceid;
		document.getElementById("HTML_speak_Content").focus();
		}
	}
	if(she!=null)
	{she.value="Re:"+title;}
}
function reply(announceid,topic){
if(announceid==0)
{
	var m_announceid=document.getElementById("HTML_speak_subject");
	if(m_announceid!=null)
	{m_announceid.value="Re:"+topic;}
}
else
{
	var m_announceid = document.getElementById("announceid");
		if(null!=m_announceid)
		{m_announceid.value=announceid;}
	var m_topic = document.getElementById("topic");
		if(null!=m_topic)
		{m_topic.value=topic;}
	var hehe=document.getElementById("HTML_speak_subject");
	if(hehe!=null)
	{hehe.value="Re:"+topic;}
}	
}
function flower(money,sign,boardid,announceid){
	if(confirm("每次表扬要花费"+money+"枚银币，您确定吗?"))
		{
			document.all.hfm_floweregg.src="/soufun_forum/post/FlowerEgg.aspx/sign="+sign+"&good=flower&boardid="+boardid+"&announceid="+announceid;
		}
		return;
}
function egg(money,sign,boardid,announceid){
	if(confirm("每次批评要花费"+money+"枚银币，您确定吗?"))
		{
			document.all.hfm_floweregg.src="/soufun_forum/post/FlowerEgg.aspx/sign="+sign+"&good=egg&boardid="+boardid+"&announceid="+announceid;
		}
		return;
}

// 新表扬/批评
function newflower(money,sign,boardid,announceid,tid){
	if(confirm("每次表扬要花费"+money+"枚银币，您确定吗?"))
		{
			document.all.hfm_floweregg.src="/soufun_forum/post/FlowerEgg.aspx?sign="+sign+"&good=Flower&boardid="+boardid+"&announceid="+announceid+"&tid="+tid;
		}
		return;
}
function newegg(money,sign,boardid,announceid,tid){
	if(confirm("每次批评要花费"+money+"枚银币，您确定吗?"))
		{
			document.all.hfm_floweregg.src="/soufun_forum/post/FlowerEgg.aspx?sign="+sign+"&good=Egg&boardid="+boardid+"&announceid="+announceid+"&tid="+tid;
		}
		return;
}
// 新表扬/批评

function delete_post(httphead,a_id,sign,bid,isfu,action,direct,a_mid){
var message
if(a_mid == "")
{
	a_mid = a_id;
}
var url=httphead+'/soufun_forum/post/frm_announce_move.aspx?announceid='+a_id+'&sign='+sign+'&bid='+bid+'&isfu='+isfu+'&action='+action + '&masterid=' + a_mid;
switch(action)
{
	case 0://
		message='你确认要移动这个帖子吗?';
		if(confirm(message))
		{
			MM_openBrWindow(url,"move","",120,300);
		}
		return;
		break;
	case 1://
		if(direct=='置顶')
		{
			message='你确认要把这个帖子置顶吗?';
		}
		else
		{
			action=2;
			message='你确认要取消这个帖子的置顶吗?';
		}
		break;
	case 3://
		message='你确认要删除这个帖子吗?\r\n(提醒:如果你删除的是一个主帖，那么他下面所有的跟帖也会被删除)';
		break;
	case 4://
		if(direct=='精华')
		{
			message='你确认要标记这个帖子为精华帖吗?';
			MM_openBrWindow(url,"选择一个精华区分类","",200,300);
			return;
			break;
		}
		else
		{
		action=5;
			message='你确认要取消这个帖子精华吗?';
		}
		break;
}
var url=httphead+'/soufun_forum/post/frm_announce_move.aspx?announceid='+a_id+'&sign='+sign+'&bid='+bid+'&isfu='+isfu+'&action='+action + '&masterid=' + a_mid;
if(confirm(message))
{
document.all.hfm_master.src = url;
}
else
{return false;}
}
//----------------把图片自动变为575*435-----------------
function resizeM(el,wi,he)
{

 if(el.runtimeStyle)
 {
	el.runtimeStyle.behavior="none";
 }

 var tempM = new Image();
 tempM.src = el.src ;
 tempM.el = el;
 tempM.onload = resizeMonLoad(wi,he);
 tempM.doload = resizeMonLoad(wi,he);
 if(el.fileSize && (el.fileSize>0)){; tempM.doload();};
}

function resizeMonLoad(wi,he)
{
	 var el = this.el;
	 var maxW = wi;
	 var maxH = he;
	 el.style.visibility="visible";

	if(this.width < maxW)
	 {
		el.style.width = this.width + "px";
	 }

	 if(this.height < maxH)
	 {
		el.style.height = this.height + "px";
	 }
	 
	 if(this.width>this.height &&this.width/this.height>=1.83)
	 {
		  if(this.width >= maxW)
		  {; 
			  var r = maxW / this.width;
			  el.style.height = (this.height * r ) + "px";
			  el.style.width = maxW + "px";
		  }
	 }
	 else
	 {
		if(this.height >= maxH)
		{
			var r = maxH / this.height;
			el.style.width = (this.width * r )+ "px";
			el.style.height = maxH + "px";
		}
	 }
}
// 创建ajax对象
function InitAjax()
{
	var ajax=false; 
	try 
	{
		ajax = new ActiveXObject("Msxml2.XMLHTTP"); 
	} 
	catch (e) 
	{ 
		try 
		{ 
			ajax = new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		catch (e) 
		{ 
			ajax = false; 
		} 
	}
	if (!ajax && typeof XMLHttpRequest!='undefined') 
	{ 
		ajax = new XMLHttpRequest(); 
	} 
	return ajax;
}
//树型控件用到的
function showsub(sid){
	var subs = document.getElementById("subs" + sid);
	var kai = document.getElementById("kai" + sid);
	var guan = document.getElementById("guan" + sid);
	if (subs.style.display == "none"){
	subs.style.display="";
	kai.style.display="none";
	guan.style.display="";
	}
	else
	{
	subs.style.display="none";
	kai.style.display="";
	guan.style.display="none";
	}
}

function hide(_sId)
{
	$(_sId).style.display = $(_sId).style.display == "none" ? "" : "none";
}
function $(_sId){
	return document.getElementById(_sId);
} 