var ie = (document.all) ? true : false;
var ua=navigator.userAgent.toLowerCase();
var isOpera=(ua.indexOf('opera')!=-1);
var mode=document.compatMode;
var errImg="http://bbs.8j.com/comm/images/errpic.gif";
function getElementPosition(target) {
  if (typeof(target)=="string") {
      target = getObject(target);
  }
  if(target.offsetParent) {
    for(var posX = 0, posY = 0; target.offsetParent; target = target.offsetParent ) {
      posX += target.offsetLeft;
      posY += target.offsetTop;
    }
    return { left:posX, top:posY };
  } 
  else {
    return { left:target.x, top:target.y };
  }
}
function showSplit(){
	if(window.name!="right")return false;
	try{
		if(ie)parent.frames["control"].hiddenSplit();
		else parent.document.getElementById("control").contentWindow.hiddenSplit();
	}catch(e){}
	return false;
}
function loginTimer(){
	setTimeout("loginTimerHoop()",240000);
}
function loginTimerHoop(){
	asyncAction(path+'/com/comservice',{myactions : "loginTimer"}, function(ans){});
	setTimeout("loginTimerHoop()",240000);
}
function getCookie(name){
	var arr = document.cookie.match(new RegExp(name+"=(.*?)[\\W]"));
	if(arr != null)return unescape(arr[1]);
	return "";
}
function setCookie (name,value,dom){ 
	var expires = new Date();
	expires.setTime (expires.getTime()+365*24*3600*1000);
	var str=name+"="+ escape(value)+";expires="+expires.toGMTString()+";path=/;domain="+dom;
	document.cookie =str;
}
function getObjUrl(objPreName,url){
	if(url==null)return url;
	if(objPreName!="")objPreName=objPreName+"-";
	var fold;
	var fName;
	var pos=url.lastIndexOf("/");
	if(pos>0){
		fold=url.substring(0,pos+1);
		fName =url.substring(pos+1);
		pos=fName.indexOf("-");
		if(pos>=0 & pos<fName.length)fName=fName.substring(pos+1);
	}else return url;
	return fold+objPreName+fName;
}
String.prototype.replaceAll = stringReplaceAll; 
function stringReplaceAll(AFindText,ARepText){  raRegExp = new RegExp(AFindText,"g");  return this.replace(raRegExp,ARepText)} 

function transTag(str){
	var tagSplit=",";
	var maxLen=10;
	var maxNum=3;
	str=str.replaceAll("，",tagSplit);
	str=str.replaceAll("、",tagSplit);
	str=str.replaceAll("　"," ");
	if(str.indexOf(tagSplit)>0)str=str.replaceAll(" ","");
	else str=str.replaceAll(" ",tagSplit);
	var a=str.split(tagSplit);
	str="";
	var num=1;
	if(a.length==1){
		str+=a[0];
		return str;
	}
	for(i=0;i<a.length;i++){
		if(a[i]=="")continue;
		if(num>maxNum)break;
		num++;
		if(i!=a.length-1){
			if(a[i].length>maxLen)a[i]=a[i].substring(0,maxLen);
			str+=a[i]+tagSplit;
		}else{
			if(a[i].length>maxLen)a[i]=a[i].substring(0,maxLen);
			str+=a[i];
		}
	}
	return str;
}

function isChinese(obj){
	if(/^[\u4e00-\u9fa5]+$/.test(obj))return true;
	return false;
}
function checkTTLen(tagId){
	var j=0;
	var str=$(tagId).value;
	for(var i=0;i<str.length;i++){
		var tmp=str.charAt(i);
		if(isChinese(tmp))j=j+2;
		else j=j+1;
	}
	return j;
}
function $(){
	var elements=new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element=arguments[i];
		if (typeof element=='string')element=document.getElementById(element);
		if(arguments.length==1)return element;
		elements.push(element);
	}
	return elements;
}
function openMyDialog(url,windowName,width,height,left,top){
	if(ie)return window.showModalDialog(url,windowName,"dialogWidth:"+width+";dialogHeight:"+height+";dialogTop:"+top+";dialogLeft:"+left+";help:off;status:yes;scroll:off;");
	else window.open(url, windowName, "width="+width+",height="+height+",help=off,status=yes,scroll=off,"); 
}
document.ondblclick=showSplit;
function checkEmail(emailStr) {
   if (emailStr.length == 0) {
       return true;
   }
   var emailPat=/^(.+)@(.+)$/;
   var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
   var validChars="\[^\\s" + specialChars + "\]";
   var quotedUser="(\"[^\"]*\")";
   var ipDomainPat=/^(\d{1,3})[.](\d{1,3})[.](\d{1,3})[.](\d{1,3})$/;
   var atom=validChars + '+';
   var word="(" + atom + "|" + quotedUser + ")";
   var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
   var domainPat=new RegExp("^" + atom + "(\\." + atom + ")*$");
   var matchArray=emailStr.match(emailPat);
   if (matchArray == null) {
       return false;
   }
   var user=matchArray[1];
   var domain=matchArray[2];
   if (user.match(userPat) == null) {
       return false;
   }
   var IPArray = domain.match(ipDomainPat);
   if (IPArray != null) {
       for (var i = 1; i <= 4; i++) {
          if (IPArray[i] > 255) {
             return false;
          }
       }
       return true;
   }
   var domainArray=domain.match(domainPat);
   if (domainArray == null) {
       return false;
   }
   var atomPat=new RegExp(atom,"g");
   var domArr=domain.match(atomPat);
   var len=domArr.length;
   if ((domArr[domArr.length-1].length < 2) ||
       (domArr[domArr.length-1].length > 3)) {
       return false;
   }
   if (len < 2) {
       return false;
   }
   return true;
}
function topicLoad(){
	var ims=document.getElementsByTagName("img");var o;
	for (var i=0;i<ims.length;i++){
		var o=ims[i];
		if (o.complete==false){
			showErrorPic(o);
		}
	}
}
function showErrorPic(obj){
	obj.title=obj.src
	obj.src=errImg
}
function htmlToString(html){
        var tmp = html.replace(/<br>/gi,"\n");
		return tmp.replace(/<[^>]+>/g,"");
}