/**
* 获得浏览器类型

*/
function Browser() {

  var ua, s, i;
  this.isIE    = false;  // Internet Explorer
  this.isOP    = false;  // Opera
  this.isNS    = false;  // Netscape
  this.version = null;
  ua = navigator.userAgent;

  s = "Opera";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isOP = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }

  s = "MSIE";
  if ((i = ua.indexOf(s))) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }
}

var browser = new Browser();

function getElements(name){
	if(browser.isIE){
		return document.all(name);
	}else{
		return document.getElementsByName(name);
	}
}


/*使firefox里能使用outerHTML*/
var setOuterHtml = function(s){
    var range = this.ownerDocument.createRange();
    range.setStartBefore(this);
    var fragment = range.createContextualFragment(s);
    //alert(fragment.xml);
    this.parentNode.replaceChild(fragment, this);
};


if(window.HTMLElement) {
   HTMLElement.prototype.__defineSetter__("outerHTML", setOuterHtml);
}


/**
* 表单提交
*/
function formSubmit(forumId,button){
  if (button){
    button.disabled="true";
  }
  document.getElementById(forumId).submit();

}

/**
* 表单提交
*/
function submit(forumId){

  document.getElementById(forumId).submit();

}

/**
* 表单清除
*/
function formReset(forumId){
  document.getElementById(forumId).reset();
}

/**
* 获得事件操作对象
*/
function getEventSrcElement(event){
  var obj;
  if (browser.isIE)
    obj = window.event.srcElement;
  else
    obj = event.currentTarget;
  return obj;
}

/**
* 获得鼠标移向目标
*/
function getEventToElement(event){
  var el;
  if (browser.isIE)
    el = window.event.toElement;
  else if (event.relatedTarget != null)
    el = (event.relatedTarget.tagName ? event.relatedTarget : event.relatedTarget.parentNode);
  return el;
}

/**
* 获得指定对象相对于浏览器的绝对定位

*/
function getAbsolutePosition(obj){
  var top = obj.offsetTop;
  var left = obj.offsetLeft;
  var width=obj.offsetWidth;
  var height=obj.offsetHeight;
  while(obj.offsetParent){
      obj = obj.offsetParent;
      top += obj.offsetTop;
      left += obj.offsetLeft;
  }
  return {"top":top, "left":left, "width":width, "height":height};
}

/**
* 获得指定对象相对于最近一个relative 或者 absolute 对象的相对位置

*/
function getRelativePosition(obj) {
  var top=obj.offsetTop;
  var left=obj.offsetLeft;
  var width=obj.offsetWidth;
  var height=obj.offsetHeight;
  obj = obj.offsetParent
  while (obj) {
    var positionValue = Element.getStyle(obj, "position");
    var overflowValue = Element.getStyle(obj, "overflow");
    if ( positionValue == 'absolute' || positionValue == 'relative'  
            || ( overflowValue != 'visible' && overflowValue != '' ) ){ 
        break; 
    }  
    top += obj.offsetTop;
    left += obj.offsetLeft;
    obj = obj.offsetParent;
  }
  return {"top":top, "left":left, "width":width, "height": height};
}

/**
* 获得对象本身及外部 第一个tagName和className为指定值的对象
*/
function getContainerWith(node, tagName, className) {
  while (node != null) {
    if (node.tagName != null && node.tagName == tagName &&
        Element.hasClassName(node, className))
      return node;
    node = node.parentNode;
  }
  return node;
}

/**
* 获得指定对象的子对象的offsetWidth
*/
function getChildNodeWidth(el){
	var maxWidth = 0;
  if(el.childNodes){
    for(i=0;i<el.childNodes.length;i++){
      if(el.childNodes[i].offsetWidth){
        //return el.childNodes[i].offsetWidth;
				var w = Element.getWidth(el.childNodes[i]);
        if(w > maxWidth){
					maxWidth = w;
				}
      }
    }
		if(maxWidth!=0) return maxWidth;
  }
  return Element.getWidth(el);
}

/**
* 获取浏览器的有些屏幕相对坐标及大小

*/
function getBrowserOffset(){
  var top = 0;
  var left = 0;
  var width = 0;
  var height = 0;
  if (document.documentElement) {
    top = document.documentElement.scrollTop;
    left = document.documentElement.scrollLeft;
    width = document.documentElement.clientWidth;
    height = document.documentElement.clientHeight;
  }
  else if (document.body) {
    top =  document.body.scrollTop;
    left =  document.body.scrollLeft;
    width = document.body.clientWidth;
    height = document.body.clientHeight;
  }
  return {"top": top, "left": left, "width": width, "height": height};
}

/**
* 去字符串两端的空格

*/
function LTrim(s){
  for(var i=0;i<s.length;i++)
  if(s.charAt(i)!=' ')
    return s.substring(i,s.length);
  return "";
}

function RTrim(s){
   for(var i=s.length-1;i>=0;i--)
    if(s.charAt(i)!=' ')
    return s.substring(0,i+1);
    return "";
}
//获取字符串的长度   
function getLength(moji)   
  {   
          var   i,cnt   =   0;   
          for(i=0;   i<moji.length;   i++)   if   (escape(moji.charAt(i)).length   >=   4   )   cnt+=2;   
          else   cnt++;   
    
          return   cnt;   
  }   
   
function Trim(s){
  return RTrim(LTrim(s));
}
/*=================== 设置png图片在ie浏览器下背景透明，firefox不需要 ==============================*/
function correctPNG()
{
  for(var i=0; i<document.images.length; i++)
  {
    var img = document.images[i]
    var imgName = img.src.toUpperCase()
    if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
    {
      var imgID = (img.id) ? "id='" + img.id + "' " : ""
      var imgClass = (img.className) ? "class='" + img.className + "' " : ""
      var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
      var imgStyle = "display:inline-block;line-height:1 !important;" + img.style.cssText
      if (img.align == "left") imgStyle = "float:left;" + imgStyle
      if (img.align == "right") imgStyle = "float:right;" + imgStyle
      if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle

      
      var strNewHTML = "<span " + imgID + imgClass + imgTitle
      + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
      + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
      + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
      img.outerHTML = strNewHTML
      i = i-1
    }
  }
}


function checkFileSize(fileName,maxsize){
	alert('cao')
	var filesize =getFileSize(fileName);
	alert(filesize+":"+maxsize)
		if(filesize==true ||filesize==false || filesize==-1 ){
			return true;
		}else{
			if(filesize>maxsize){
		 	 return false;
			}
		}
}
function getFileSize (fileName)   {  
      if(document.layers){   
  			if(navigator.javaEnabled()){   
              var   file   =   new   java.io.File(fileName);   
              if(location.protocol.toLowerCase()!='file:')   
                  netscape.security.PrivilegeManager.enablePrivilege(   
                  'UniversalFileRead');   
 				   return   file.length();         
 			   }			     
          else return   -1;     
       }   
       else if(document.all){   

          window.oldOnError= window.onerror;   
		  window.onerror=function(err){   
              if(err.indexOf('utomation')!=-1){   
                  alert('系统禁止js检查文件大小,将进行后台验证');   
 				  return true;   
 	  		  }
			  else      
			    return   false;         
			  };   
          var fso=new ActiveXObject('Scripting.FileSystemObject');   
          var file=fso.GetFile(fileName);   
  		  window.onerror   =   window.oldOnError;   
          return   file.Size;     
          }
        else{
        	return true;
        }
   }    
function saveSuccess(message){
	if (message==null)
	{
		message="保存成功";
	}
	alert(message);
}
/**
 * 交替替换一个元素的className
 * @param obj 替换元素
 * @param name1 className1 
 * @param name2 className2
 */
function changeClass(obj,name1,name2){
	if(obj.className==name1){
		obj.className=name2;
	}else if(obj.className==name2){
		obj.className=name1;
	}
	
}
/**
 * 交替替换一个元素属性的值
 * @param obj 替换元素的属性
 * @param name1 值1 
 * @param name2 值2
 * @param property 值
 */
function changeProperty(obj,name1,name2,property){
	if(eval("obj.style."+property)==name1){
		eval("obj.style."+property+"=name2")
	}else if(eval("obj.style."+property)==name2){
		eval("obj.style."+property+"=name1");
	}
}

function changeDisplay(obj){
	changeProperty(obj,'none','block',"display");
}

function selectAll(str){
	var checkbox=document.getElementsByName(str);
	if(checkbox){
	
		if(checkbox.length){
			for(var i=0;i<checkbox.length;i++){
				checkbox[i].checked =true;
			}//end for
		}else{
			checkbox.checked=true;
		}// end if
	}

}

function unselectAll(str){
	var checkbox=document.getElementsByName(str);
	if(checkbox){
	
		if(checkbox.length){
			for(var i=0;i<checkbox.length;i++){
				checkbox[i].checked =false;
			}//end for
		}else{
			checkbox.checked=false;
		}// end if
	}

}

//返回当前键盘按钮键值
function getKeyCode(event){
  return event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
}

// 改变div样式;
function changeElementClass(divId,divClass)
{
	document.getElementById(divId).className=divClass;
}

function Hashtable(){
  this._hash = new Object();
  this._size = 0;

  this.add=function add(key, value, childs){
    //alert("OK");
    //alert(typeof(key)!="undefined");
    //alert(this.contains(key));
    if(typeof(key)!="undefined"  && !this.contains(key)){
      var _h = new Object();
      _h.key = key;
      _h.value=typeof(value)=="undefined"?null:value;
      _h.childs = typeof(childs)=="undefined"?null:childs;
      this._hash[key] = _h;
      this._size++;
      //alert("add:" + this._hash[key]);
    }else{
      var _h = this._hash[key];
      _h.value=typeof(value)=="undefined"?null:value;
      _h.childs = typeof(childs)=="undefined"?null:childs;
      //alert("update:" + this._hash[key]);
    }
    return this;
  }

  this.addValue=function addValue(key, value){
    if(typeof(key)!="undefined"  && !this.contains(key)){
      var _h = new Object();
      _h.key = key;
      _h.value=typeof(value)=="undefined"?null:value;
      this._hash[key] = _h;
      this._size++;
      //alert("addValue add:" + this._hash[key]);
    }else{
      var _h = this._hash[key];
      _h.value=typeof(value)=="undefined"?null:value;
      //alert("addValue update:" + this._hash[key]);
    }
    return this;
  }

  this.addChilds=function addChilds(key, childs){
    if(typeof(key)!="undefined"  && !this.contains(key)){
      var _h = new Object();
      _h.key = key;
      _h.childs = typeof(childs)=="undefined"?null:childs;
      this._hash[key] = _h;
      this._size++;
      //alert("addChilds add:" + this._hash[key]);
    }else{
      var _h = this._hash[key];
      _h.childs = typeof(childs)=="undefined"?null:childs;
      //alert("addChilds update:" + this._hash[key]);
    }
    return this;
  }


  this.value=function value(key){
    return this._hash[key].value;
    if(o == null){
      return "";
    }
    return o;
  }

  this.childs=function childs(key){
    return this._hash[key].childs;
  }

  this.contains = function(key){
    return typeof(this._hash[key])!="undefined";
  }

  this.size=function size(){
    return this._size;
  }

  this.hash=function hash(){
    return this._hash;
  }
}

//联动：初始化国家
function initCountry(countryId, provinceId, cityId){
  document.getElementById('user_country').options.length = 0;
  var i = 0;
  for(var key in Country.hash()){ 
    document.getElementById('user_country').options[i] = new Option(Country.value(key), key);
    if(key == countryId){
      document.getElementById('user_country').options[i].selected = true;
    }
    i++;
  }
  initProvince(provinceId);
  initCity(cityId);
}

//联动：初始化省
function initProvince(provinceId){
  var countryId = $('user_country').value;
  document.getElementById('user_province').options.length = 0;
  var i = 0;
  var province = Country.childs(countryId);
  if(province == null) {
    document.getElementById('user_province').style.visibility = "hidden";
    document.getElementById('user_city').style.visibility = "hidden";
    return;
  }
  document.getElementById('user_province').style.visibility = "visible";
  for(var key in province.hash()){ 
    document.getElementById('user_province').options[i] = new Option(province.value(key), key);
    if(key == provinceId){
      document.getElementById('user_province').options[i].selected = true;
    }
    i++;
  }
}

//联动：初始化城市
function initCity(cityId){
  var countryId = $('user_country').value;
  var provinceId = $('user_province').value;
  document.getElementById('user_city').options.length = 0;
  var i = 0;
  var prov = Country.childs(countryId);
  if(prov == null){
    document.getElementById('user_city').style.visibility = "hidden";
    return;
  }
  var city = prov.childs(provinceId);
  if(city == null) {
    document.getElementById('user_city').style.visibility = "hidden";
    return;
  }
  document.getElementById('user_city').style.visibility = "visible";
  for(var key in city.hash()){ 
    document.getElementById('user_city').options[i] = new Option(city.value(key), key);
    if(key == cityId){
      document.getElementById('user_city').options[i].selected = true;
    }
    i++;
  }
}
function refreshchecknum(objstr,picurl){
	if(!picurl)
		picurl = _contextPath+'/ebfn?_fn=0401';
	if(objstr){
		var obj=document.getElementById(objstr);
		if(obj){
			obj.src=picurl+'&'+Math.random() ;
		}else{
			alert('验证码图片'+objstr+"未找到");
		}
	}else{
		var checknumobj=$("check_num");

		if(checknumobj){
			checknumobj.src=picurl+'&'+Math.random() ;
		}else{
			alert('验证码图片check_num未找到');
		}
	}
}

/*=================== 漂浮在屏幕右下角的alert窗口 ==============================*/
var ebalerts = new Array();
var ebalertwidth = 240;
var ebalertheight = 190;
var bdy = (document.documentElement && document.documentElement.clientWidth)?document.documentElement:document.body;
function ebalert(contextpath,title,msgtitle,msgcontent,link,linktitle){
	var index;
	var width = ebalertwidth;
	var height = ebalertheight;
	var bodydiv;
	this.init = function(){
		bodydiv = document.createElement("div");
		bodydiv.style.width = width +"px";
		bodydiv.style.height = height +"px";
		bodydiv.style.left = "0px";
		bodydiv.style.top = "0px";
		bodydiv.style.float = "left";
		bodydiv.style.position="absolute"
		bodydiv.style.display='none';
		bodydiv.style.zIndex="100";
		bodydiv.style.border="2px solid #376f9e";
		bodydiv.style.padding="1px";
		bodydiv.style.backgroundColor="#ffffff";
		index = ebalerts.length;
		var s = "<div style='font-size:12px;background:url("+contextpath+"/eb/template/OsaccBlog/images/msgalert_title.jpg);background-repeat:repeat-x;border:0;'>";
		s = s + "<table width='100%' border='0'><tr>";
		s = s + "<td width='90%' border='0'><span style='font-size:12px;margin:0px;padding:1px;color:#ffffff;font-weight:bold;' border='0'>"+title+"</span></td>";
		s = s + "<td align='center' border='0'><a href=\"javascript:alertsClose("+index+")\" border='0'><img align='absmiddle' src='"+contextpath+"/eb/template/OsaccBlog/images/msgalert_close.gif' title='关闭' border='0'/></td>";
		s = s + "</tr></table>";
		s = s + "</div>";
		s = s + "<div style='text-align:left;height:145px;background:url("+contextpath+"/eb/template/OsaccBlog/images/msgalert_bg.jpg) center;background-repeat:no-repeat;background-position-x:center;background-position-y:center'>";
		s = s + "<div style='font-size:14px;padding:6px;color:#37709d;font-weight:bold;'>"+msgtitle+"</div>";
		s = s + "<div style='font-size:12px;padding:6px;color:#808080;line-height:1.5;'>"+msgcontent+"</div>";
		s = s + "</div>";
		s = s + "<div align='right' valign='middle' height='25px' style='font-size:12px;background:url("+contextpath+"/eb/template/OsaccBlog/images/msgalert_tail.jpg);background-repeat:no-repeat;border:0;background-position:top center;padding-top:6px;padding-right:10px;margin:0px'>";
		s = s + "  <a href=\""+link+"\">"+linktitle+"</a>";
		s = s + "</div>";
		bodydiv.innerHTML = s;
		ebalerts.push(this);
		document.body.appendChild(bodydiv);
	}
	this.close = function(){
		bodydiv.style.visibility = "hidden";
		ebalerts.splice(index,1);
		document.body.removeChild(bodydiv);
		index = -1;
	}
	this.move = function(x,y){
		bodydiv.style.display='block';
		bodydiv.style.left= x + "px";
		bodydiv.style.top= y + "px";
	}
	this.init();
}
function alertsMove(){
	if(ebalerts.length>0){
		var screenX=bdy.scrollLeft;
		var screenY=bdy.scrollTop;
		var screenW=bdy.clientWidth-ebalertwidth - 10 ;//22:border width
		var screenH=bdy.clientHeight-ebalertheight -10;//10:border height
		for(var i=0;i<ebalerts.length;i++){
			ebalerts[i].move(screenX + screenW,screenY + screenH - (ebalertheight+10)*i);
		}
		setTimeout("alertsMove();",50);
	}
}
function alertsClose(index){
	if(ebalerts.length>index){
		ebalerts[index].close();
	}
}
/*=================== alert窗口end =============================================*/