var bbs_maproot="";
var bbs_domain="soufun.com";
var re = /\/[a-z]*bbs[^\.]/i;                // 创建正则表达式模式。
var arr;
if ((arr = re.exec(window.location.href)) != null)
{
	 bbs_maproot=arr[0];
}
if(window.location.host.toUpperCase().indexOf("JIATX.COM")>=0)
{
	bbs_domain="jiatx.com";
}

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 ++) {
		var name=gridid + "_" + "ctl0" + i + "_" + gridckbid;
		temp = document.getElementById(name);
		if(null == temp)
		{
			continue;
		}
		else
		{
			canchecked = true;
			star_index=i;
			break;
		}
	}
	for (var i = 0; i < 4; i ++) 
	{
		var name=gridid + "_ctl0" + i + "_" + outckbid
		temp = document.getElementById(name);
		if(null == temp)
		{
			continue;
		}
		else
		{
			break;
		}
	}
			
	if(null == temp)
	{	     
        var elements = document.getElementsByTagName("INPUT");     
        for(i=0; i<elements.length;i++) 
        {
            if(elements[i].type == 'checkbox')
            {
                elements[i].checked=!elements[i].checked;
            }
        }

	    return;
	}
	

	if(!canchecked)
	{
		temp.checked = false;
	}
	var checkedall = temp.checked;
	for (var i = -3; i < gridlength+star_index; i ++) 
	{
	    var leftzero="";
	    if(i+3<10)
	    {
	        leftzero="0";
	    }
		temp = document.getElementById(gridid + "_" + ("ctl" +leftzero)+(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,userid,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]"+"[I]以下是引用 [URL=http://blog."+bbs_domain+"/blog_"+userid+".htm]"+username+"[/URL] 在"+dtime+"的发言：[/I]\n\n"+hehe.value.replace("<table class=quote><tr><td><table class=quote_txt><TR><TD>","").replace("</td>","").replace("</tr>","").replace("</table>","").replace("</td>","").replace("</tr>","").replace("</table>","").replace("\n","") + "[/quote]";
		//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 newflower(httphead,money,sign,boardid,announceid,tid){
	if(confirm("每次表扬要花费"+money+"枚银币，您确定吗?"))
		{
			document.all.hfm_floweregg.src=httphead+"/soufun_forum/post/FlowerEgg.aspx/sign="+sign+"&good=Flower&boardid="+boardid+"&announceid="+announceid+"&tid="+tid;
		}
		return;
}
function newegg(httphead,money,sign,boardid,announceid,tid){
	if(confirm("每次批评要花费"+money+"枚银币，您确定吗?"))
		{
			document.all.hfm_floweregg.src=httphead+"/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,tid,m_listid){
var message
if(a_mid == "")
{
	a_mid = a_id;
}
var url=httphead+'/soufun_forum/post/frm_announce_move.aspx/sign='+sign+'&announceid='+a_id+'&bid='+bid+'&isfu='+isfu+'&action='+action + '&masterid=' + a_mid +'&tid='+tid+'&listid='+m_listid;
switch(action)
{
	case 0://
		var url=httphead+'/soufun_forum/post/frm_postTransfer.aspx?sign='+sign+'&announceid='+a_id+'&bid='+bid+'&tid='+tid;
		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;
	case 5://
		if(direct=='加锁')
		{
		    action=6;
			message='你确认要给这个帖子加锁吗?加锁需要花费1枚银币！';
			break;
		}
		else
		{
		action=7;
			message='你确认要给这个帖子解锁吗?解锁需要花费1枚银币！';
		}
		break;
}
var url=httphead+'/soufun_forum/post/frm_announce_move.aspx/sign='+sign+'&announceid='+a_id+'&bid='+bid+'&isfu='+isfu+'&action='+action + '&masterid=' + a_mid +'&tid='+tid+'&listid='+m_listid;
if(confirm(message))
{
document.getElementById("hfm_master").src = url;
}
else
{return false;}
}

function GetCookieVal(offset)
//获得Cookie解码后的值
{
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function SetCookie(name, value)
//设定Cookie值
{
var expdate = new Date();
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
if(expires!=null) expdate.setTime(expdate.getTime() + ( expires * 1000 ));
document.cookie = name + "=" + escape (value) +((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))
+((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
+((secure == true) ? "; secure" : "");
}
function DelCookie(name)
//删除Cookie
{
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires="+ exp.toGMTString();
}
function GetCookie(name)
//获得Cookie的原始值
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return GetCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}

function CheckAll(ckbAllId, ckbSingleName) 
{
	var ckbAll = document.getElementById(ckbAllId);
	if (ckbAll == null)
		return;

	var ckbSingle = document.getElementsByName(ckbSingleName);
	for (var i = 0; i < ckbSingle.length; i++)
	{
		if (ckbSingle[i] != null)
		{
			ckbSingle[i].checked = ckbAll.checked;	
		}	
	}
}
function CheckSingle(ckbAllId, ckbSingleName) 
{
	var ckbAll = document.getElementById(ckbAllId);
	if (ckbAll == null)
		return;

	var isAll = true;
	var ckbSingle = document.getElementsByName(ckbSingleName);
	for (var i = 0; i < ckbSingle.length; i++)
	{
		if (ckbSingle[i].checked == false)
		{
			isAll = false;
			break;	
		}
	}
	
	ckbAll.checked = isAll;
}
function DeletePost(sbmId)
{
	var sbm = document.getElementById(sbmId);
	if (sbm != null)
	{
		sbm.disabled = true;
	}
	if (confirm("你确认要删除这些帖子吗?\r\n(提醒:如果你删除一个主帖，那么他下面所有的跟帖也会被删除)"))
	{
		return true;
	}
	else
	{
		if (sbm != null)
		{
			sbm.disabled = false;
		}
		
		return false;
	}
}
//kejet系统发布flash广告页面
function insertFlash(elm, url, w, h, id) {
 if (!document.getElementById(elm)) return;
 var str = '';
 str += '<embed width="'+ w +'" height="'+ h +'" src="'+ url +'" quality="autohigh" wmode="opaque" type="application/x-shockwave-flash" plugspace="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" id='+id+'></embed>';
 document.getElementById(elm).innerHTML = str;
}
/*add by lsj 2008-4-25 图片自适应屏幕大小*/
function InitImageWidth(Imgobj)
{
	var max=screen.width-274;
	var w=Imgobj.width;
	if(w==0)
	{
		var img=new Image();
		img.src=Imgobj.src;
		w=img.width;
	}
	if(w>max){Imgobj.width=max;}
}
