//public java script

//淡出DIV
var intTimeStep=50;
var isIe=(window.ActiveXObject)?true:false;
var intAlphaStep=(isIe)?5:0.05;
var curSObj=null;
var curOpacity=null;
var stopTime=0;
function startObjMessage(objId)
{
	curSObj=document.getElementById(objId);
	if(isIe){curSObj.style.cssText='DISPLAY: none; FILTER: alpha(opacity=0); POSITION: absolute;';}
	setMessage();
}
function setMessage()
{
	if(isIe){curSObj.filters.alpha.opacity=0;}
	else{curOpacity=0;curSObj.style.opacity=0}
	curSObj.style.display='';
	setMessageShow();
}
function setMessageShow()
{
	if(isIe)
	{
	curSObj.filters.alpha.opacity=100;
	if (curSObj.filters.alpha.opacity<100) {setTimeout('setMessageShow()',intTimeStep);}
	else{stopTime+=30;if(stopTime<500){setTimeout('setMessageShow()',intTimeStep);}else{stopTime=0;}}
	}else
	{
	curOpacity+=intAlphaStep;
	curSObj.style.opacity =1;
	if (curOpacity<1) {setTimeout('setMessageShow()',intTimeStep);}
	else{stopTime+=30;if(stopTime<200){setTimeout('setMessageShow()',intTimeStep);}}
	}
}

function setMessageClose(waitBox)
{
	curSObj=document.getElementById(waitBox);
	if(isIe)
	{
		curSObj.filters.alpha.opacity-=intAlphaStep;
		if (curSObj.filters.alpha.opacity>0) {
			setTimeout('setMessageClose(\''+waitBox+'\')',intTimeStep);
		}
		else {
			curSObj.style.display='none';
		}
	}
	else
	{
		curOpacity-=intAlphaStep;
		if (curOpacity>0) {
			curSObj.style.opacity =curOpacity;
			setTimeout('setMessageClose(\''+waitBox+'\')',intTimeStep);
		}
		else {
			curSObj.style.display='none';
		}
	}
}

//检查浏览器类型
function getOs()
{
    var OsObject = "";
   if(navigator.userAgent.indexOf("MSIE")>0) {
        return "MSIE";
   }
   if(navigator.userAgent.indexOf("Firefox")>0){
        return "Firefox";
   }
   if(navigator.userAgent.indexOf("Safari")>0) {
        return "Safari";
   } 
   if(navigator.userAgent.indexOf("Camino")>0){
        return "Camino";
   }
   if(navigator.userAgent.indexOf("Gecko")>0){
        return "Gecko";
   }
  
}

//为firefox添加ie的属性
if(getOs()!="MSIE")
{
	HTMLElement.prototype.contains=function(obj)
	{// 是否包含某节点
	    do
	    { 
	      if(obj == null)
	      	 return false;
	      if(obj==this)
	      {
	     	 return true;
	      }
	    }
	    while(obj=obj.parentNode);
	    return false;
    };
    
    HTMLElement.prototype.__defineGetter__("children",
     function () {
         var returnValue = new Object();
         var number = 0;
         for (var i=0; i<this.childNodes.length; i++) {
             if (this.childNodes[i].nodeType == 1) {
                 returnValue[number] = this.childNodes[i];
                 number++;
             }
         }
         returnValue.length = number;
         return returnValue;
     }
 ); 
Event.prototype.__defineGetter__("fromElement",function(){  
          var node;  
          if(this.type=="mouseover"){node=this.relatedTarget;  }
          else if(this.type=="mouseout"){node=this.target;  }
          if   (!node){return;}
          while(node.nodeType!=1){node=node.parentNode;}
          return node;  
      });  
      Event.prototype.__defineGetter__("toElement",function(){  
          var node;  
          if(this.type=="mouseout"){node=this.relatedTarget;}
          else if(this.type=="mouseover"){node=this.target;}
          if (!node){return;}
          while(node.nodeType!=1){node=node.parentNode;}
          return node;  
      });
}
//trim方法
function jsTrim(str)
{
 var re;
 if (str != null)
 {
	 re = /^[ \t]*|[ \t]*$/g;
	 str = str.replace(re, '');
	 var p=/\s/g;
	 str=str.replace(p,"");
 }
 return(str);
}

//replaceAll方法
function replaceAll(source,s1,s2)
{   
	return source.replace(new RegExp(s1,"gm"),s2);   
}  
   
//计算字符串长度，汉字算2个
function StringLength(str)
{
     // replace将符合此正则的字符串替换成指定字符 然后在计算长度
     return str.replace((/[^\x00-\xff]/g),"**").length
}

// 锁屏
function showScreen(ifrId,screenId,contentId,e,owidth,cutWidth)
{
	var cw=0;
	if(cutWidth)cw=cutWidth;
	var _clientwidth= document.documentElement.clientWidth || document.body.clientWidth;
    //整个页面的高度
    var _pageheight = Math.max(document.body.scrollHeight,document.documentElement.scrollHeight);
	if(ifrId!=""){
		var ifr = document.getElementById(ifrId);
		ifr.style.width=(_clientwidth-8) + "px";
	    ifr.style.height=(_pageheight-8) + "px"
		ifr.style.left='0px';
	    ifr.style.top='0px'
	    ifr.style.display='block';
	    //ifr.style.width=getPageSize()[0]+'px';
	    //ifr.style.height=getPageSize()[1]+'px'
	}
	
	if(screenId!=""){
	    var Elements = document.getElementById(screenId);
	    //Elements.style.width=getPageSize()[0]-cw+'px';
	    //Elements.style.height=getPageSize()[1]+'px';

      
	   Elements.style.width = _clientwidth + "px";
	   Elements.style.height = _pageheight + "px";
	   Elements.style.top = "0px";
	   Elements.style.left = "0px";
	    
	    Elements.style.display='block';
	}
    
    var Element = document.getElementById(contentId);
    //按照点击的坐标显示弹窗
    if(e)
    {
    	var mouse_x;
	    var mouse_y;
	    if(!document.all)
	    {
			mouse_x=e.pageX;
			mouse_y=e.pageY;
		}
		else
		{
			mouse_x=document.documentElement.scrollLeft+e.clientX;
			mouse_y=document.documentElement.scrollTop+e.clientY;
		}
		
	    Element.style.left=(1*mouse_x-170)+"px";
	    Element.style.top=(1*mouse_y-80)+"px";
    }
    else
    {
    	var width=469;
    	if(owidth)width=owidth;
    	var left=(""+((getPageSize()[0]-width)/2)).split(".")[0]+'px';
    	Element.style.left=left;
    	Element.style.top=document.documentElement.scrollTop+50+"px";
    	
    	if(screenId!="")
    	{
	    	var btype=getOs();
	    	if(width==469)
	    	{
	    		if(btype=="MSIE"){Elements.filters.alpha.opacity=50;}
				else{curOpacity=0;Elements.style.opacity=0.5}
				Elements.style.backgroundColor="#cccccc";
	    	}
	    	else
	    	{
	    		if(btype=="MSIE"){Elements.filters.alpha.opacity=0;}
				else{curOpacity=0;Elements.style.opacity=0}
				Elements.style.backgroundColor="#ffffff";
	    	}
    	}
    }
    
    Element.style.display='block';
}
//解屏
function hideScreen(ifrId,screenId,contentId)
{
	if(ifrId!=""){
		var ifr = document.getElementById(ifrId);
		ifr.style.width='0px';
	    ifr.style.height='0px';
		ifr.style.display='none';
	}
	
	if(screenId!=""){
	    var Elements = document.getElementById(screenId);
	    Elements.style.width='0px';
	    Elements.style.height='0px';
	    Elements.style.display='none';
	}
    
    var Element = document.getElementById(contentId);
    Element.style.left='0px';
    Element.style.top='0px';
    Element.style.display='none';
}
//真正获得页面总高度和宽度的方法
function getPageSize()
{
    var xScroll, yScroll;
    if (window.innerHeight && window.scrollMaxY) {   
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }
   
    var windowWidth, windowHeight;
    if (self.innerHeight) {    // all except Explorer
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }   
   
    // for small pages with total height less then height of the viewport
    if(yScroll < windowHeight){
        pageHeight = windowHeight;
    } else { 
        pageHeight = yScroll;
    }
 
    // for small pages with total width less then width of the viewport
    if(xScroll < windowWidth){   
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }
 
    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
    return arrayPageSize;
}
//截取中文汉字
function cutString(str,start,len,suffix)
{
 var ilen = start + len;
 var reStr = "";
 if(str.length<=ilen){
  return str;
 }
 for(i=0; i<ilen; i++)
 {
  if(escape(str.substr(i,1))>0xa0)
  {
   reStr += str.substr(i,2);
   i++;
  }
  else{
   reStr += str.substr(i,1);
  }
 }
 
 if(suffix)reStr+=suffix;
 return reStr;
}

//获取不同规格的图片
function getHeadImageUrl(type, url)
{
	return url.replace("head_image.jpg",type+"-head_image.jpg?a=1");
}

//用javascript生成一个数之间的一个随机数
function GetRandomNum(Min,Max){
        var Range = Max - Min;
        var Rand = Math.random();
        return(Min + Math.round(Rand * Range));
}

//嵌入flash
function swf(file,w,h,index) {
	var html='';
	html+='<object id="flashObject'+index+'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+w+'" height="'+h+'"> ';
	html+='<param name="movie" value="'+file+'">';
	html+='<param name="quality" value="high"> ';
	html+='<param name="wmode" value="transparent"> ';
	html+='<param name="menu" value="false"> ';
	html+='<embed src="'+file+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+w+'" height="'+h+'"></embed> ';
	html+='</object> ';
	
	return html;
}

//截取时间字段
	function formatDatess(str,num){
		if(num==null)num=16;
  		return str.length >num ? str.substring(0,num) : str;
  	}
  	//截取时间字段
	function formatDate(str,num){
		if(num==null)num=16;
  		return str.length >num ? str.substring(0,num) : str;
  	}
  	
   //String 构造函数的原型对象的一个方法。去掉字符串前后的空格  
  String.prototype.trimLR = function()  
  {  
       return   this.replace(/(^\s*)|(\s*$)/g,   "");  
  }   
  
  function getCurLoginUrl()
  {
  		var url=window.location.href;
		if(url.indexOf("#")>-1)
			url=url.split("#")[0];
		location.href=getPassportSite()+"/login?service="+encodeURIComponent(url);
  }
//域名封装
var mainWebSite ="http://www.renmaiku.com";//主域名
var phtotoSite ="http://photo.renmaiku.com";//图片
var groupSite ="http://group.renmaiku.com";//群组
var profileSite ="http://profile.renmaiku.com";//静态页面
var resourceSite ="http://resource.renmaiku.com";
var staticsSite ="http://statics.renmaiku.com"; //广告投放域名
var imageUploadSite ="http://upload.renmaiku.com"; //图片服务器域名
var passportSite ="http://pass.renmaiku.com";
var indexSite ="http://search.renmaiku.com";

//var mainWebSite ="http://www.trenmaiku.com";//主域名
//var phtotoSite ="http://photo.trenmaiku.com";//图片
//var groupSite ="http://group.trenmaiku.com";//群组
//var profileSite ="http://profile.trenmaiku.com";//静态页面
//var resourceSite ="http://resource.trenmaiku.com";
//var staticsSite ="http://statics.trenmaiku.com"; //广告投放域名
//var imageUploadSite ="http://upload.trenmaiku.com"; //图片服务器域名
//var passportSite ="https://passport.trenmaiku.com:8443/cas"
//var indexSite ="http://www.trenmaiku.com";

function getMainWebSite()
{
	return this.mainWebSite;
}
function getPhtotoSite()
{
	return this.phtotoSite;
}
function getGroupSite()
{
	return this.groupSite;
}
function getProfileSite()
{
	return this.profileSite;
}
function getResourceSite()
{
	return this.resourceSite;
}
function getStaticsSite()
{
	return this.staticsSite;
}
function getImageUploadSite()
{
	return this.imageUploadSite;
}
function getPassportSite()
{
	return this.passportSite;
}  
function getIndexSite()
{
	return this.indexSite;
}   
  