/**
 * get element
 * document.getElementById的封装
 * 如果浏览器不支持getElementById方法则返回null
 */
function _gel(a) {
	return document.getElementById?document.getElementById(a):null
}

//标志浏览器是否为Safari
var aF=navigator.userAgent.indexOf("Safari")>=0;

/**
 * 一个标准的AJAX替换页面内容典范
 * 变量a为地址，aa为回调处理函数
 */
function _sendx(a,aa) {
	var ab=aL();

	if (!ab||aF&&!aa) {
		//特殊浏览器特殊照顾
		(new Image()).src=a
	} else {
		//正常的浏览器，用XMLHTTP显示内容
		try {
			ab.open("GET",a,true);
			if (aa) {
				ab.onreadystatechange=function(){
					if (ab.readyState==4) {
						aa(ab.responseText)
					}
				}
			}
			ab.setRequestHeader("Pragma", "no-cache");
			ab.setRequestHeader("Cache-Control", "no-cache");
			if ( document.cookie ) {
	        	ab.setRequestHeader("Cookie", document.cookie);
			}
			ab.send(null);
		}catch(e){alert(e);}
	}
}

/**
 * 拿到一个可用的XMLHttpRequest对象
 */
function aL() {
	var a=null;

	if (window.ActiveXObject) {
		a=new ActiveXObject("Msxml2.XMLHTTP");

		if (!a) { 
			a=new ActiveXObject("Microsoft.XMLHTTP")
		}
	} else if (window.XMLHttpRequest) {
		a=new XMLHttpRequest()
	}

	return a
}

function form_value(f)
{
	v = "";
	for (i = 0; i < f.elements.length; ++i )
	{
		var e = f.elements[i];
		
		if ( e.value == "" )
		{
			continue;
		}
		
		switch ( e.type.toLowerCase() )
		{
		case "radio":
		case "checkbox":
			if ( e.checked == false )
		    {
		    	continue;
		    }
		}

		v += encodeURIComponent(e.name) + "=" + encodeURIComponent(e.value) + "&\n";
	}
	return v;
}

function xbox(url,title,func,fo) {
	if (!box_open(title)) {
		return;
	}

	if (!func) {
		func = _m;
	}
	if(fo) {
		_sendx(url+'?'+form_value(fo),func);
	} else {
		_sendx(url, func);
	}
}

function _m(str) {
	document.getElementById("x_box_message").innerHTML=str+'<br/>本窗口5秒后自动关闭<br/><br/><a href="javascript: box_close();"><img src="img/btn/btn_close.gif"></a>';
	window.setTimeout(box_close, 5000);
}

function _s(b) {
	var w = 0, h = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		w = window.innerWidth;
		h = window.innerHeight;
	} else if( document.documentElement &&
		( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		w = document.documentElement.clientWidth;
		h = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		w = document.body.clientWidth;
		h = document.body.clientHeight;
	}

	b.style.left=(w-b.style.width.substring(0,b.style.width.length-2))/2;
	b.style.top=(h-b.style.height.substring(0,b.style.height.length-2))/2+document.body.scrollTop;
}

function box_open(a) {
	var b = document.getElementById("x_box");
	if (b && b.style.display=="block") {
		alert("有操作正在执行中，等待上次操作结束");
		return false;
	}

	if(!b) {
		_build_x_box();
		b = document.getElementById("x_box");
		if(!b) return;
	}

	document.getElementById("x_box_message").innerHTML="";
	b.style.display='block';
	_s(b);

	document.getElementById("x_box_title").innerHTML=a;

	return true;
}

function box_close() {
	var b = document.getElementById("x_box");
	if(b) {
		b.style.display='none';
	}
}

function _build_x_box() {
	var a = "";
	a += '<div id="x_box" style="position: absolute; display: block; width: 340px; height: 120px;">';
	a += '<table width="0" border="0" cellspacing="0" cellpadding="0">';
	a += '  <tr>';
	a += '    <td width="10"></td>';
	a += '    <td width="337"><table width="337" border="0" cellspacing="0" cellpadding="0">';
	a += '		  <tr>';
	a += '			<td width="48"><img src="/img/pop/img_title_bl.gif" width="48" height="40"></td>';
	a += '			<td valign="top" background="/img/pop/img_title_bg.gif" class="pop" style="padding-top:9">连接服务器中，请稍候。。。</td>';
	a += '			<td width="20" align="right"><img src="/img/pop/img_title_right.gif" width="20" height="40"></td>';
	a += '		  </tr>';
	a += '</table>';
	a += '	</td>';
	a += '    <td width="10"></td>';
	a += '  </tr>';
	a += '  <tr>';
	a += '    <td width="10"></td>';
	a += '    <td width="337"><table width="0" border="0" cellspacing="0" cellpadding="0">';
	a += '  <tr>';
	a += '    <td><img src="/img/tbl/tbl_gray_01.gif" width="15" height="15"></td>';
	a += '    <td width="307" background="/img/tbl/tbl_gray_02s.gif"></td>';
	a += '    <td><img src="/img/tbl/tbl_gray_03.gif"></td>';
	a += '  </tr>';
	a += '  <tr>';
	a += '    <td background="/img/tbl/tbl_gray_04.gif"></td>';
	a += '    <td valign="top" bgcolor="#FFFFFF">';
	a += '    <table width="307" border="0" cellspacing="0" cellpadding="0">';
	a += '      <tr>';
	a += '        <td width="8" valign="top" style="padding-left:5;padding-top:5"><img src="/img/bl/bl_grey_y.gif" width="8" height="12"></td>';
	a += '        <td style="padding-top:5;padding-bottom:5"><table width="0" border="0" cellspacing="1" cellpadding="0">';
	a += '            <tr>';
	a += '              <td style="padding-right:5" id="x_box_title"></td>';
	a += '          </tr>';
	a += '        </table></td>';
	a += '      </tr>';
	a += '    </table>';
	a += '    <table width="307" border="0" cellspacing="0" cellpadding="0">';
	a += '      <tr>';
	a += '        <td height="2" bgcolor="FFA810"></td>';
	a += '      </tr>';
	a += '    </table>';
	a += '    <table width="100" border="0" cellspacing="0" cellpadding="0">';
	a += '      <tr>';
	a += '        <td height="20"></td>';
	a += '      </tr>';
	a += '    </table>';
	a += '    <div align="center" style="width: 307px;" id="x_box_message"></div>';
	a += '    </td>';
	a += '    <td background="/img/tbl/tbl_gray_05.gif"></td>';
	a += '  </tr>';
	a += '  <tr>';
	a += '    <td><img src="/img/tbl/tbl_gray_06.gif" width="15" height="15"></td>';
	a += '    <td width="307" background="/img/tbl/tbl_gray_07s.gif"></td>';
	a += '    <td><img src="/img/tbl/tbl_gray_08.gif"></td>';
	a += '  </tr>';
	a += '</table>';
	a += '</td>';
	a += '    <td width="10"></td>';
	a += '  </tr>';
	a += '  <tr>';
	a += '    <td width="10"></td>';
	a += '    <td width="337"></td>';
	a += '    <td width="10"></td>';
	a += '  </tr>';
	a += '</table>';
	a += '</div>';
	//alert(a);
	document.body.innerHTML += a;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function w(u) {
	window.open(u, "", "width=330, height=190, directories=no, location=no, menubar=no, scrollbars=no, status=no, titlebar=no, toolbar=no");
}

function wopen(u) {
	window.open(u, "", "width=660, height=300,location=no, menubar=no, scrollbars=yes, status=no, titlebar=no, toolbar=no");
	//window.open(u,'','width=660, height=300');
}

function CopyToClipBoard(t){
	var clipBoardContent=''; 
	clipBoardContent = window.location.href;
	//clipBoardContent+='http://bbs.fsjoy.com/bbs/view_topic.action?tid='+t;
	window.clipboardData.setData("Text",clipBoardContent);
	alert("复制成功，您可以将剪贴板的内容粘贴给您的好友：）");
}

function gologin() {
        //if ( confirm('您没有登录，无法执行本次操作。点击确定将会跳转到登录页面，在此之前，如果您已经写好了帖子内容，请先备份下来以节省笔墨。：）') ) {
        location.href = 'http://passport.t2cn.com/login/login.jsp?success_url=' + encodeURIComponent(location.href);
       // }
}

function getAbsolutePos(el) {
	var r = { x: el.offsetLeft, y: el.offsetTop };
	if (el.offsetParent) {
		var tmp = getAbsolutePos(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	return r;
};

function __dlg_init(bottom) {
	var body = document.body;
	var body_height = 0;
	if (typeof bottom == "undefined") {
		var div = document.createElement("div");
		body.appendChild(div);
		var pos = getAbsolutePos(div);
		body_height = pos.y;
	} else {
		var pos = getAbsolutePos(bottom);
		body_height = pos.y + bottom.offsetHeight;
	}
	if (!document.all) {
		window.sizeToContent();
		window.sizeToContent();	// for reasons beyond understanding,
					// only if we call it twice we get the
					// correct size.
		// center on parent
		var x = opener.screenX + (opener.outerWidth - window.outerWidth) / 2;
		var y = opener.screenY + (opener.outerHeight - window.outerHeight) / 2;
		window.moveTo(x, y);
		window.innerWidth = body.offsetWidth + 5;
		window.innerHeight = body_height + 2;
	} else {
		window.resizeTo(body.offsetWidth, body_height);
		var ch = body.clientHeight;
		var cw = body.clientWidth;
		if(cw>500) window.resizeTo(360,400); else
			window.resizeBy(body.offsetWidth - cw, body_height - ch);
		var W = body.offsetWidth;
		var H = 2 * body_height - ch;
		var x = (screen.availWidth - W) / 2;
		var y = (screen.availHeight - H) / 2;
		window.moveTo(x, y);
	}
}

function opener_go(url) {
	if (!opener) return;
	opener.location.href = url;
	window.close();
}

function myinit() {
	if(!opener) return;
	__dlg_init();
}

function new_post() {
	return window.open("about:blank", "n_p", "width=350, height=200, directories=no, location=no, menubar=no, scrollbars=auto, status=no, titlebar=no, toolbar=no");
}


function loginBBS(){
	var bbs_url = window.location.href;
	var url = "http://passport.t2cn.com/login/login.jsp?success_url="+bbs_url;
	window.location = url;
}

//弹出窗口
function showPopupWin(URL1, title1, width1, height1){
	var sValue = 'width='+width1+',height='+height1+',';
	sValue = sValue + 'top='+(screen.availHeight-parseInt(height1))/2
		+ ',left='+(screen.availWidth-parseInt(width1))/2
		+",scrollbars=yes";
	window.open(URL1, title1, sValue);
}

function modifyProfile(){
	showPopupWin('arvataManage.action','修改个人信息','500','400');
}


  var   spcnGolWidth   =   180;   
  var   spcnGolHeight   =   90;   
  var   spcnGolCurStep   =   0;   
  var   spcnGolInitTop   =   (screen.height-spcnGolHeight)/3;   
  var   spcnGolInitLeft   =   screen.width;   
  var   spcnGolTimer   =   null;   
  var   spcnGolPopup   =   null;   
  var   spcnGolPopupBody   =   null;   
  
  
  //${unReadNum?default("0")} 
  function   spcnGolWin2(unReadNum){  
  if(unReadNum<=0){
  	return;
  } 
  if(null == spcnGolPopup){   
  spcnGolPopup = window.createPopup();   
  spcnGolPopupBody = spcnGolPopup.document.body; 
  var poptext = '<div id=golDiv style="cursor:move;"><table style="border:1px solid #000000;" width='+spcnGolWidth+' height='+spcnGolHeight+' cellpadding=0 cellspacing=0>';
      poptext+= '<tr><td><table width=100% height=100% border="0" cellspacing="0" cellpadding="0" style="font-size:12px;">';
      poptext+= '<tr><td><tr style="background-color:#A5C927;" valign=middle height=16><td nowrap width=13 height=12>&nbsp;</td>';
      poptext+= '<td style="color:#F4F4F4;font-size:12px;font-weight:bold;font-family:Courier New;" align=center width=100%><I>&nbsp;短消息提示</I></td>';
      poptext+= '<td valign=top nowrap><img id="golCloseBtn" src="http://image.sportscn.com/live/r_t/off01.gif" alt="Close Pop Goal" width=11 height=11 border=0 align="absmiddle" onmouseover=\'golDiv.style.cursor="hand";\' onmouseout=\'golDiv.style.cursor="move";\'></td></tr>';      
      if(unReadNum >0){
      poptext+= '<tr style="background-color:#FBF9DB;" valign=middle height=100% width=100%><td nowrap width=13 height=12>&nbsp;</td><td nowrap colspan=2 align="left">您有<font color=#FF0000> '  + unReadNum +  '</font>条新短消息</td></tr>';
      poptext+= '<tr style="background-color:#FBF9DB;" valign=middle height=100% width=100%><td colspan=3 align="center"><font color=#FF0000 ><img id="golCheckBtn" src="img/ico_1.gif" alt="Check Pop Goal" width=11 height=11 border=0 align="absmiddle" onmouseover=\'golDiv.style.cursor="hand";\' onmouseout=\'golDiv.style.cursor="move";\'> 点击图标查看新消息!</font></td></tr>';
      }else{
       poptext+= '<tr style="background-color:#FBF9DB;" valign=middle height=100% width=100%><td nowrap width=13 height=12>&nbsp;</td><td nowrap colspan=2 align="left">欢迎进入拍拍部落论坛</td></tr>';
       poptext+= '<tr style="background-color:#FBF9DB;" valign=middle height=100% width=100%><td nowrap width=13 height=12>&nbsp;</td><td nowrap colspan=2 align="left">您暂无新短消息!</td></tr>';
      }       
      poptext+= '<tr style="background-color:#FBF9DB;" valign=middle height=100% width=100%><td colspan=3 align="center">&nbsp;</td></tr></table></td></tr></table></div>';   
    
  spcnGolPopupBody.innerHTML = poptext;   
  spcnGolPopupBody.all['golCloseBtn'].onclick   =   dismissPopGoal;   
  spcnGolPopupBody.all['golCheckBtn'].onclick   =   dismissGoal;  
  spcnGolPopupBody.onmouseup=null;   
  spcnGolPopupBody.onmousedown=null;   
  spcnGolPopupBody.onclick=null;   
  spcnGolPopupBody.oncontextmenu=dismissPopGoal;   
  }   
    
  timelyClose();   
  }   
    
  function   timelyClose(){   
  if(spcnGolTimer   !=   null)   
  clearTimeout(spcnGolTimer);   
  spcnGolTimer   =   null;   
  spcnGolCurStep   =   0;   
  spcnGolPopup.show(spcnGolInitLeft,spcnGolInitTop,spcnGolCurStep,spcnGolHeight);   
  movePopGoal();   
  }   
  function   movePopGoal(){   
    
  //   move   step   by   step   
  if(spcnGolTimer!=-1   &&   spcnGolCurStep<=spcnGolWidth){   
  spcnGolCurStep++;   
  spcnGolPopup.show(spcnGolInitLeft-spcnGolCurStep,spcnGolInitTop,spcnGolCurStep,spcnGolHeight);   
  spcnGolTimer=setTimeout("movePopGoal();",1);   
  }   
  else{   
  spcnGolTimer=setTimeout("doClose();",30000);   
  }   
    
  //   move   quickly   
  /*   
  spcnGolPopup.show(spcnGolInitLeft-spcnGolWidth,spcnGolInitTop,spcnGolWidth,spcnGolHeight);   
  spcnGolTimer=setTimeout("doClose();",15000);   
  */   
  }   
  function   doClose(){   
  spcnGolCurStep   =   spcnGolWidth;   
  spcnGolPopup.show(spcnGolInitLeft,spcnGolInitTop,spcnGolCurStep,spcnGolHeight);   
  closePopGoal();   
  }   
  function   closePopGoal(){   
  //   close   step   by   step   
  if(spcnGolTimer!=-1   &&   spcnGolCurStep>=0){   
  spcnGolPopup.show(spcnGolInitLeft-spcnGolCurStep,spcnGolInitTop,spcnGolCurStep--,spcnGolHeight);   
  spcnGolTimer=setTimeout("closePopGoal()",1);   
  }   
  else{   
  dismissPopGoal();   
  }   
    
  //   close   quickly   
  /*   
  dismissPopGoal();   
  */   
  }   
  function   dismissPopGoal(){   
  clearTimeout(spcnGolTimer);   
  spcnGolTimer   =   -1;   
  spcnGolPopup.hide();   
  //window.focus();   
  }   
  function   dismissGoal(){     
   window.open("./receiveMessage.action?para=1&mid=0");   
  }     

//下面有些内容是从/js/edit/下的js得到的
function e(i,f) {
	f['topic.content'].value += ' [e' + i + '/] ';
	var c = f['topic.content'].value;
	writeEditorContents(c);
	//if(wysiwyg){
		//alert(1);
	//	editdoc.body.innerHTML += ' [e' + i + '/] ';	
	//}else{
		//alert(2);
	//	editdoc.value+=' [e' + i + '/] ';	
	//}
}