var is_ie = document.all ? true : false; 
function elementX(_){var A=_.offsetLeft,$=_.offsetParent;while(_.parentNode&&document.body!=_.parentNode){_=_.parentNode;A-=_.scrollLeft;if($==_){A+=_.offsetLeft;$=_.offsetParent}}return A}function elementY(A){var _=A.offsetTop,$=A.offsetParent;while(A.parentNode&&document.body!=A.parentNode){A=A.parentNode;_-=A.scrollTop;if($==A){_+=A.offsetTop;$=A.offsetParent}}return _}function mouseX($){return $.pageX||($.clientX+(document.documentElement.scrollLeft||document.body.scrollLeft))}function mouseY($){return $.pageY||($.clientY+(document.documentElement.scrollTop||document.body.scrollTop))}function isMouseOut($,F){var B=mouseX(F?F:window.event),E=mouseY(F?F:window.event),A=elementX($),C=elementY($),_=A+parseInt($.offsetWidth),D=C+parseInt($.offsetHeight);if(B>A&&B<_&&E>C&&E<D)return false;else return true}
function killErrors(){return true}

function gId(eid){return document.getElementById(eid) || null;}

function sfHover(){
	var sfEls = document.getElementById("nav_menu").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(/ sfhover\b/, "");
		}
	}
}
if (window.attachEvent && (!window['XMLHttpRequest'])) window.attachEvent("onload", sfHover);

function autofocus(el){
  el.onblur=function(){
    if(el.value==''){
      el.value=el.defaultValue;
    }
  };
  el.onfocus=function(){
    if(el.value==el.defaultValue){
      el.value='';
    }
  };
  el.onfocus();
}


function _l(){
  if(window['console']){
    console.log.apply(console, arguments);
  }
}

function changeTabTo(elm, tnum){
  elm.blur();
  if(elm.parentNode.className.indexOf('current')!=-1){
    return false;
  }
  function getConElm(el){
    var tid = el.href.match(/#([^#]+)$/);
    if(!tid)return null;
    tid=tid[1];
    return gId(tid);
  }
  var theid = elm.id,
      baseid = theid.replace(/\d+$/, ''),
      tmpid,
      tmpelm,
      tmpelm2;
  for(var i=0;i<tnum;i++){
    tmpid=baseid+i;
    tmpelm=gId(tmpid);
    tmpelm2=getConElm(tmpelm);
    tmpelm=tmpelm.parentNode;
    if(tmpid==theid){
      tmpelm.className+=' current';
      tmpelm2.style.display='';
    }else{
      tmpelm.className=tmpelm.className.replace(/ *current/g, '');
      tmpelm2.style.display='none';
    }
  }
  return false;
}

function initMsgList(eid){
  var tbl=gId(eid),
      tbody=tbl.tBodies[0],
      trs=tbody.rows,
      lastOpen=null;
  for(var i=0,iM=trs.length;i<iM;i++){
    if(i%2==1) continue;
    (function(i,tr,tr2){
      tr.getElementsByTagName("a")[0].onclick=function(){
          if(tr2.style.display=="none"){
            tr2.style.display="";
            lastOpen && (lastOpen.style.display="none");
            lastOpen=tr2;
          }else{
            tr2.style.display=="none";
            lastOpen=null;
          }
          return false;
        };
    })(i,trs[i],trs[i+1]);
  }
}

function setIptStatus(el,b){
  el.disabled=!b;
  if(b){
    el.className=el.className.replace(/\bdis_status\b/,'');
  }else{
    el.className+=" dis_status";
  }
}

function enable_ipt(t,t2,t3){
  var felms=t.form.elements;
  if(t.checked){
    if(!t2.push){setIptStatus(felms[t2],1)}else{
      for(var i=0;i<t2.length;i++){
        setIptStatus(felms[t2[i]],1);
      }
      t2=t3 || t2[0];
    }
    try{felms[t2].focus()}catch(ex){}
  }
}

function disable_ipt(t, t2){
  var felms=t.form.elements;
  if(t.checked){
    if(!t2.push){setIptStatus(felms[t2],0);}else{
      for(var i=0;i<t2.length;i++){
        setIptStatus(felms[t2[i]],0);
      }
    }
  }
}

function setMsgTo(vid, v){
  gId("txtReceiverID").value=vid;
  gId("txtReceiver").value=v;
}

function getPageScroll(){
	var yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}
  
	return [null, yScroll];
}

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){
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else {
		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;
	}	
	
	var pageHeight, pageWidth;
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
  
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	
	return [pageWidth,pageHeight,windowWidth,windowHeight];
}

(function(){
  var el_overlay, el_popwin, el_closebtn, el_popcon;
  var d=document,w=window,CE='createElement',SA='setAttribute',AP='appendChild',IB='insertBefore',FC='firstChild',GBT='getElementsByTagName';
  var b;
  if(window.addEventListener){
    window.addEventListener('load', init, false);
  }else if(window.attachEvent){
    window.attachEvent('onload', init);
  }
  function init(){
    b=d[GBT]('body')[0];
    el_overlay=d[CE]('div');
    el_overlay.className='overlay';
    //el_overlay.onclick=close_popwin;
    
    //console.log(b, el_overlay, b[FC]);
    b[IB](el_overlay, b[FC]);
    
    el_popwin=d[CE]('div');
    el_popwin.className='popwin';
    
    el_popcon=d[CE]('div');
    el_popcon.className='popwin_con';
    el_popwin[AP](el_popcon);
    
    el_closebtn=d[CE]('a');
    el_closebtn.className='closebtn';
    el_closebtn[SA]('href', '#');
    el_closebtn.innerHTML='关闭';
    el_closebtn.onclick=function(){
      close_popwin();
      return false;
    };
    el_popwin[AP](el_closebtn);
    
    b[IB](el_popwin, el_overlay);
    
    el_overlay.style.display = 'none';
    el_popwin.style.display = 'none';
    //console.log(b, el_popwin, b[FC]);
  };
  
  var iframe_tpl='<iframe width="${width}" height="${height}" frameborder="0" scrolling="no" src="${src}"></iframe>';
  window.popwin = function(w, h, closebtn, cvalue){
    if(cvalue instanceof Array){
      cvalue=cvalue[0];
      var _var={'width':w,'height':h,src:cvalue};
      cvalue=iframe_tpl.replace(/\$\{([^\}]+)\}/g, function(a, b){return (b in _var) ? _var[b] : a});
    }
    el_popwin.style.width=w+"px";
    el_popwin.style.height=h+"px";
    el_popcon.innerHTML=cvalue;
    var pageSize = getPageSize(),
        pageScroll = getPageScroll();
    
    el_overlay.style.height = pageSize[1] + 'px';
    el_overlay.style.display = '';
    
		el_popwin.style.top = Math.max(0, pageScroll[1] + ((pageSize[3] - h) / 2)) + "px";
		el_popwin.style.left = Math.max(0, (pageSize[0] - w) / 2) + "px";
    el_popwin.style.display = '';
  };
  window.close_popwin=function(){
    try{
      el_popwin.style.display = 'none';
      el_overlay.style.display = 'none';
    }catch(ex){}
  };
})();

function copyToClipboard(theField) {
var tempval = document.getElementById(theField);
if (navigator.appVersion.match(/\bMSIE\b/)) { 
tempval.select();
try{
 if (copytoclip == 1) { therange = tempval.createTextRange(); 
therange.execCommand("Copy");
}
return;
}catch(ex){tempval.select();}
} else { tempval.select(); }
}

function addAllValue(f,v,r){
  f=document.forms[f];
  var es=f.elements,
      rslt;
  function c(){
    rslt=0;
    for(var i=0,iM=v.length;i<iM;i++){
      rslt += (parseFloat(es[v[i]].value) || 0);
    }
    es[r].value=(''+rslt).match(/^-?\d+(\.\d{0,2})?/)[0];
    es[r].onchange();
  }
  for(var i=0,iM=v.length;i<iM;i++){
    es[v[i]].onchange=c;
  }
}

function minAllValue(f,v,r){
  f=document.forms[f];
  var es=f.elements,
      rslt;
  function c(){
    rslt=parseFloat(es[v[0]].value);
    for(var i=1,iM=v.length;i<iM;i++){
      rslt -= (parseFloat(es[v[i]].value) || 0);
    }
    es[r].value=(''+rslt).match(/^-?\d+(\.\d{0,2})?/)[0];
    es[r].onchange();
  }
  for(var i=0,iM=v.length;i<iM;i++){
    es[v[i]].onchange=c;
  }
}