

var lan = location.href;
var Prompted='系统提示';
if(lan.indexOf("language=0")!=-1 || lan.indexOf("-0.htm")!=-1)
{
	//说明是中文
	Prompted='Prompted';
}

function $(s){return document.getElementById(s)||document.getElementsByName(s)[0];}


var pt=String.prototype;
pt.trim=function(){return this.replace(/(^\s*)|(\s*$)/g,"");}
pt.startsWith=function(s){var i=this.length-s.length;return i>=0&&this.substring(0,s.length)==s;}
pt.endsWith=function(s){var i=this.length-s.length;return i>=0&&this.substring(i)==s;}

pt=Error.prototype;
pt.toString=function(){return '编号:'+this.number+'\n名称:'+this.name+'\n消息:'+this.message+'\n描述:'+this.description};

if(window.dialogArguments)document.write("<base target='_self' />");

if(window.dialogArguments)window.onerror=function(){return true;};


//HTMLCollection.prototype.value=function()
//{
//  for(var i=0;i<this.length;i++)
//  {
//    if(this[i].checked)return this[i].value;
//  }
//  return null;
//}
//Collection.prototype.value=function()
//{
//  for(var i=0;i<this.length;i++)
//  {
//    if(this[i].checked)return this[i].value;
//  }
//  return null;
//}
//Object.prototype.value=function()
//{
//  for(var i=0;i<this.length;i++)
//  {
//    if(this[i].checked)return this[i].value;
//  }
//  return null;
//}



var mt=new Object();

mt.isIE=!window.Event;
mt.isIE6=navigator.userAgent.indexOf("MSIE 6")!=-1;

if(document.getElementsByTagName("FRAMESET").length==0)document.write("<iframe name='_ajax' style='display:none'></iframe>");

mt.find=function(a,v,t)
{
  var rs=new Array(),arr=document.getElementsByTagName(t||"*");
  for(var i=0;i<arr.length;i++)
  {
    if(arr[i].getAttribute(a)==v)rs.push(arr[i]);
  }
  return rs;
}
function $name(v,t){return mt.find("name",v,t);}
function $class(v,t){return mt.find("className",v,t);}


//对话框
function dl_sel(flag)
{
  if(!mt.isIE6)return;
  var as=document.getElementsByTagName("SELECT");
  for(var i=0;i<as.length;i++)
  {
    if(as[i].name.indexOf("city")!=-1)continue;//city.js 中的市丢失
    if(flag)as[i].hidden=as[i].style.display=="none";
    if(!as[i].hidden)as[i].style.display=flag?"none":"";
  }
}
function dl_down(event,obj)
{
  mt.dl.style.zIndex=(""+new Date().getTime()).substring(4);
  var e=event.srcElement||event.target;
  if(event.button<2&&e.tagName=="DIV")
  {
    obj.x=event.offsetX||event.layerX+e.offsetLeft+2;
    obj.y=event.offsetY||event.layerY+e.offsetTop+2;
    mt.dl.down=true;
    if(mt.isIE)obj.setCapture();
    //window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
  }
}
function dl_move(event,obj)
{
  if(mt.dl.down)
  {
    var x=event.clientX+document.body.scrollLeft;
    if(x<0)x=0;
    var y=event.clientY+document.body.scrollTop;
    if(y<0)y=0;
    var dl=obj.parentNode;
    mt.dl.style.left=x-obj.x;
    mt.dl.style.top=y-obj.y;
  }
}
function dl_up(event,obj)
{
  if(mt.dl.down)
  {
    if(mt.isIE)obj.releaseCapture();
    mt.dl.down=false;
  }
}
function f_isurl(sc)
{
  return sc.indexOf("/")==0||sc.indexOf("http://")==0||sc=="about:blank";
}
mt.close=function()
{
  window.onscroll=function(){};
  dl_sel(false);
  mt.dl.bg.style.display=mt.dl.style.display="none";
}
mt.show=function(sc,sf,sh,w,h)//内容,页脚,标题,宽,高
{
  mt.ok=function(){}
  mt.cancel=function(){}
  if(mt.dl)
  {
    document.body.removeChild(mt.dl);
    document.body.removeChild(mt.dl.bg);
  }
  dl_sel(true);
  //
  if(sh)
  {
    if(f_isurl(sh))sh="window.open('"+sh+"','_self')";
    if(sh.indexOf("window")!=-1||sh.indexOf("submit")!=-1||sh.indexOf("location")!=-1)
    {
      eval("mt.ok=function(){"+sh+"}");
      sh=null;
    }
  }
  if(!w)w=300;
  if(!h)h=120;
//  var dl=document.all("dialog");
//  if(dl)
//  {
//    var c=dl.length||1;
//    l=l+c*30;
//    t=t+c*30;
//  }

  var ih="<div id='dialog_header' onmousedown=dl_down(event,this); onmousemove=dl_move(event,this); onmouseup=dl_up(event,this);><a href='javascript:;' onclick='mt.close()' style='float:right'><img src='/tea/mt/close.gif' border='0'/></a>"+(sh||Prompted)+"</div>";
  if(sc&&f_isurl(sc))
  {
    ih+="<div class='dialog_content'><iframe name='dialog_content' src="+sc+" style='width:100%;height:"+(h-25)+"px;' scrolling='no' frameborder='0'></iframe></div><div class='dialog_all'></div>";
  }else
  {
    if(sf==undefined)sf=1;
    switch(sf)
    {
      case 0:sf="<img src='/tea/mt/progress.gif'/>";if(!sc)sc="数据提交中,请稍等...";break;
      case 1:sf="<input type='submit' id='dl_ok' value=' 确 定 ' onclick='if(mt.ok()!=false)mt.close();' />";break;
      case 2:sf="<input type='submit' id='dl_ok' value=' 确 定 ' onclick='if(mt.ok()!=false)mt.close();' /> <input type='button' id='dl_cancel' value=' 取 消 ' onclick='if(mt.cancel()!=false)mt.close()' />";break;
    }
    if(!sh)sc="<img src='/tea/mt/info.gif' align='absmiddle'/>　"+sc;
    ih+="<div id='dialog_content'>"+sc+"</div>";
    ih+="<div id='dialog_footer'>"+sf+"</div>";
	ih+="<div id='dialog_all'></div>";
  }

  ih+="<style type='text/css'>";
  ih+="#dialog_header{background:#709CD2;padding:5px;cursor:move;font-weight:bold;color:#FFFFFF;text-align:left;}";
  ih+="#dialog_content{border:1px solid #709CD2;border-top:0px;padding:30px;border-bottom:0px;background:#ffffff;}";
  ih+=".dialog_content{border:1px solid #709CD2;border-top:0px;background:#ffffff;height:"+(h-25)+";}";
  ih+="#dialog_footer{background:#ffffff;border:1px solid #6C92AD;border-top:0px;text-align:right;padding:6px;text-align:center;}";
  ih+="#dialog_all{background:#000;filter:alpha(opacity=20);-moz-opacity:0.4;opacity: 0.4;position:absolute;top:4px;left:4px;width:100%;height:100%;z-index:-10;}";
  ih+=".dialog_all{background:#000;filter:alpha(opacity=20);-moz-opacity:0.4;opacity: 0.4;position:absolute;top:4px;left:4px;width:100%;height:"+(h+7)+";z-index:-10;}";
  ih+="</style>";
  mt.dl=document.createElement("div");
  //
  mt.dl.bg=document.createElement("div");
  mt.dl.bg.oncontextmenu=function(){return false;}
  mt.dl.bg.style.cssText="position:absolute;left:0px;top:0px;width:100%;height:"+document.body.scrollHeight+"px;"+(mt.isIE?"filter:alpha(opacity=50)":"opacity:0.5")+";background-color:#FFFFFF;";
  document.body.appendChild(mt.dl.bg);
  //
  var l=document.body.scrollLeft+(document.body.clientWidth/2-w/2);
  var t=document.body.scrollTop+(document.body.clientHeight/2-h);
  mt.dl.style.cssText="position:absolute;left:"+l+"px;top:"+t+"px;width:"+w+"px;height:"+h+"px;background:#fff;z-index:"+(""+new Date().getTime()).substring(4)+";font-size:13px;";
  mt.dl.innerHTML=ih;
  document.body.appendChild(mt.dl);
  //
  var dl_ok=$("dl_ok");
  if(dl_ok)dl_ok.focus();
  //
  mt.dl.top=document.body.scrollTop;
  //setInterval('if(!mt.dl.down)document.body.scrollTop=mt.dl.top;',200);
  window.onscroll=function(){document.body.scrollTop=mt.dl.top;}
}

//表单
mt.check=function(obj,min)
{
  if(obj.tagName=="FORM")
  {
    var arr=obj.elements;
    for(var i=0;i<arr.length;i++)
    {
      if(arr[i].getAttribute("alt")&&!mt.check(arr[i]))return false;
    }
    return true;
  }
  if(!min)min=1;
  var v=obj.value.trim(),n=obj.getAttribute("alt"),m=obj.getAttribute("mask");
  var info;
  if(obj.tagName=="SELECT"&&v=="0"&&obj.options[0].text.indexOf("---")==0)info="必须选择“"+n+"”！";
  else if(obj.type=="checkbox"&&!obj.checked)info="必须选中“"+n+"”！";
  else if(v.length<min||v=='|')info="“"+n+"” "+(min==1?"不能为空!":"长度不能小于"+min+"位!");
  else if(obj.type=="password"&&obj.name=="password2"&&obj.form.password.value!=v)info="两次输入的密码不相同！";
  else if(obj.name=="email"&&!mt.isEmail(v))info="“"+n+"”格式不正确!";
  else if(m)
  {
    if(m=="member"&&!mt.isMember(v))
      info="“"+n+"”格式不正确!";
  }
  if(info)
  {
    mt.show(info);
    mt.ok=function(){try{obj.focus();}catch(e){}}
    return false;
  }
  return true;
}

//
function f_get()
{
  var arr=form1.elements;
  for(var i=0;i<arr.length;i++)
  {
    var n=arr[i].name;
    if(n=="")continue;
    document.write("String "+n+"=h.get(\""+n+"\");<br/>");
  }
}

//日期
mt.date=function(fieldname)
{
  var param="edge:raised;scroll:0;status:0;help:0;resizable:1;dialogWidth:280px;dialogHeight:205px;";
  if(window.event)
  {
    myleft=document.body.scrollLeft+event.clientX-event.offsetX-80;
    mytop=document.body.scrollTop+event.clientY-event.offsetY+140;
    //param+="dialogTop:"+mytop+"px;dialogLeft:"+myleft+"px"
  }
  var rs=window.showModalDialog("/jsp/include/Calendar.jsp",self,param);
  if(fieldname.tagName=="IMG")fieldname=fieldname.previousSibling;
  if(rs)(typeof(fieldname)=="object"?fieldname:eval(fieldname)).value=rs;
}

//加载
mt.load=function()
{
  var l=document.body.scrollLeft+document.body.clientWidth/2-100;
  document.write("<div id='mt_load' style='border:1px solid #9CB8CC; background-color:#FFFFE1;padding:4px;position:absolute;left:"+l+"px'><img src='/tea/mt/loading_16x16.gif' align='absmiddle'/> 网页加载中...</div>");
  window.onload=function(){$('mt_load').style.display='none';}
}

//全选
mt.select=function(obj,v)
{
  if(!obj)return;
  if(v==0)v=false;
  if(!obj.length)obj=new Array(obj);
  for(var i=0;i<obj.length;i++)
  {
    if(!obj[i].disabled)obj[i].checked=v==2?!obj[i].checked:v;
  }
}

//a:分隔符
mt.value=function(obj,a)
{
  if(obj==null)return null;
  if(obj.type=="file")
  {
     if(mt.isIE6)return obj.value;
	 obj.select();
	 return document.selection.createRange().text;
  }
  var isSel=obj.type=="select-multiple";
  if(isSel)obj=obj.options;
  if(!obj.length)obj=new Array(obj);
  var c=a;
  for(var i=0;i<obj.length;i++)
  {
    var v=obj[i].value;
    if(v!=''&&(obj[i].checked||isSel))if(a)c+=v+a;else return v;
  }
  return a?c:null;
}

//清除文本框内容
mt.clear=function(a)
{
  var arr=a.getElementsByTagName("INPUT");
  for(var i=0;i<arr.length;i++)
  {
    arr[i].value="";
  }
}


mt.left=function(a)
{
  var tr=a,x=0;//-document.body.scrollLeft;
  while(a!=document.body){x+=a.offsetLeft;a=a.offsetParent;}
  return x;
}
mt.top=function(a)
{
  var y=0;//-document.body.scrollTop;
  while(a!=document.body){y+=a.offsetTop;a=a.offsetParent;}
  return y;//a.offsetHeight
}
mt.isHiden=function(a)
{
  while(a!=document.body)
  {
    if(a.style.display=="none")return true;
    a=a.parentNode;
  }
  return false;
}


mt.isMember=function(s)
{
  if (s.length < 2)
  return false;
  for(var i=0; i<s.length; i++)
  {
    var c = s.charAt(i);
    if ('_'== c||'-' == c|| '@' == c||'.' == c||('A' <= c && c <= 'Z') ||('a' <= c && c <= 'z') ||('0' <= c && c <= '9') ||s.charCodeAt(i)>255)
    continue;
    return false;
  }
  return true;
}

mt.isEmail=function(s)
{
  var j=s.indexOf('@');
  if(j<1||s.indexOf('.',j)==-1)return false;
  return true;
}


//禁用按钮
mt.disabled=function(a,b)
{
  var arr=document.getElementsByName(b||"multi");
  if(!a)a=arr;
  if(!a.length)a=new Array(a);
  for(var i=0;i<a.length;i++)
  {
    a[i].onpropertychange=function()
    {
      var b=mt.value(a)==null;
      for(var i=0;i<arr.length;i++)
      {
        arr[i].disabled=b;
        var c=arr[i].className;//禁用class加2
        if(c)
        {
        if(c.endsWith("2"))c=c.substring(0,c.length-1);
        arr[i].className=b?c+"2":c;
        }
      }
    };
  }
}

//
mt.send=function(url,d)
{
  if(url.indexOf("http://")==0&&url.indexOf(location.host)==-1)
  {
    url="/servlet/Ajax?act=sendx&url="+encodeURIComponent(url);
  }
  try
  {
    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
    if(d)
    {
      a.onreadystatechange=function()
      {
        if(a.readyState==4)
        {
          d(a.responseText);
          //d=a.responseXML?a.responseXML:a.responseText;
        }
      }
    }
    a.open("GET",url+"&t="+new Date().getTime(),true);
    a.send("");
  }catch(e)
  {
    //alert(e.number+":"+e.description);
  }
}







//参数
mt.get=function(name,url)
{
  if(url)
  {
    var i=url.indexOf("#");
    if(i!=-1)url=url.substring(0,i);
  }else url=location.search;
  i=url.indexOf("?");
  if(i==-1)return null;
  url=url.substring(i+1);
  name+="=";
  var ps=url.split("&");
  for(var i=0;i<ps.length;i++)
  {
    if(ps[i].indexOf(name)!=0)continue;
    return decodeURIComponent(ps[i].substring(name.length).replace(/[+]/g,' '));
  }
  return null;
}
mt.getInt=function(n,dv)
{
  var v=parseInt(mt.get(n));
  return isNaN(v)?dv:v;
}







//
var popup=new Object();

popup.title  = "title";
popup.content= "message";
popup.width  = 200;
popup.height = 120;
popup.timeout= 150;
popup.speed    = 20;//速度
popup.step    = 5;//步长
popup.right    = screen.width -1;
popup.bottom = screen.height;
popup.left    = popup.right - popup.width;
popup.top    = popup.bottom - popup.height;
popup.timer    = 0;
popup.pause    = false;
popup.close    = false;
popup.autoHide    = true;

popup.close=function()
{
  var offset  = this.height>this.bottom-this.top?this.height:this.bottom-this.top;
  var me  = this;

  if(this.timer>0)window.clearInterval(me.timer);
  var fun = function()
  {
    if(me.pause==false||me.close)
    {
      var x  = me.left;
      var y  = 0;
      var width = me.width;
      var height = 0;
      if(me.offset>0)height = me.offset;


      y  = me.bottom - height;

      if(y>=me.bottom)
      {
        window.clearInterval(me.timer);
        me.Pop.hide();
      } else
      {
        me.offset = me.offset - me.step;
      }
      me.Pop.show(x,y,width,height);
    }
  }
  this.timer = window.setInterval(fun,this.speed)
}

popup.show=function(sc,st)
{
  var oPopup = window.createPopup(); //IE5.5+
  this.Pop = oPopup;
  var w = this.width;
  var h = this.height;
  var str = "<div id='popup' style=background:url(/tea/mt/popup.gif) no-repeat left top;width:201px;height:117px;>";
  str += "<div id='popup_header' style=height:19px;*height:24px;padding-top:5px;font-weight:bold;text-align:center;color:#fff;font-size:12px;><a href='javascript:;' style='float:right'><img src='/tea/mt/close.gif' border='0'/></a>"+(st||Prompted)+"</div>";
  str += "<div id='popup_content' style=font-size:12px;height:81px;*height:93px;padding:6px 8px;line-height:130%;>"+sc+"</div></div>";

  oPopup.document.body.innerHTML = str;
  var as=oPopup.document.getElementsByTagName("A");
  as[0].onclick=function(){popup.close();}
  for(var i=1;i<as.length;i++)
  {
    as[i].onclick=function(){
    	popup.close();
    window.open(this.href);}
  }

  this.offset  = 0;
  var me= this;

  oPopup.document.body.onmouseover = function(){me.pause=true;}
  oPopup.document.body.onmouseout = function(){me.pause=false;}
  popup.rect();
  var fun = function()
  {
    var x  = me.left;
    var y  = 0;
    var width    = me.width;
    var height    = me.height;

    if(me.offset>me.height)
    height = me.height;
    else
    height = me.offset;

    y  = me.bottom - me.offset;
    if(y<=me.top)
    {
      me.timeout--;

      if(me.timeout==0)
      {
        window.clearInterval(me.timer);
        if(me.autoHide)me.close();
      }
    } else
    me.offset = me.offset + me.step;
    me.Pop.show(x,y,width,height);
  }
  this.timer = window.setInterval(fun,this.speed)
}
//摄影用到

popup.show2=function(sc,st)
{
  var oPopup = window.createPopup(); //IE5.5+
  this.Pop = oPopup;
  var w = this.width;
  var h = this.height;
  var str = "<div id='popup' style=background:url(/tea/mt/popup2.gif) no-repeat left top;width:201px;height:117px;>";
  str += "<div id='popup_header' style=height:24px;font-weight:bold;text-align:center;color:#fff;font-size:12px;line-height:24px;><a href='javascript:;' style='float:right'><img src='/tea/mt/close2.jpg' border='0'/></a>"+(st||Prompted)+"</div>";
  str += "<div id='popup_content' style=line-height:150%;color:#3560ac;font-weight:bold;text-align:center;font-size:12px;height:73px;*height:93px;padding:20px 8px 0px 8px;>"+sc+"</div></div>";

  oPopup.document.body.innerHTML = str;
  var as=oPopup.document.getElementsByTagName("A");
  as[0].onclick=function(){
	  popup.close();
  }
  for(var i=1;i<as.length;i++)
  {
    as[i].onclick=function()
    {
    	//popup.close();
    	window.open(this.href,'m');
    }
  }

  this.offset  = 0;
  var me= this;

  oPopup.document.body.onmouseover = function(){me.pause=true;}
  oPopup.document.body.onmouseout = function(){me.pause=false;}
  popup.rect();
  var fun = function()
  {
    var x  = me.left;
    var y  = 0;
    var width    = me.width;
    var height    = me.height;

    if(me.offset>me.height)
    height = me.height;
    else
    height = me.offset;

    y  = me.bottom - me.offset;
    if(y<=me.top)
    {
      me.timeout--;

//      if(me.timeout==0)
//      {
//        window.clearInterval(me.timer);
//        if(me.autoHide)me.close();
//      }
    } else
    me.offset = me.offset + me.step;
    me.Pop.show(x,y,width,height);
  }
  this.timer = window.setInterval(fun,this.speed)
}


popup.rect = function(left,right,top,bottom)
{
    try
    {
        this.left        = left    !=null?left:this.right-this.width;
        this.right        = right    !=null?right:this.left +this.width;
        this.bottom        = bottom!=null?(bottom>screen.height?screen.height:bottom):screen.height;
        this.top        = top    !=null?top:this.bottom - this.height;
    } catch(e){}

}








mt.length=function(len)
{
  setTimeout("sendx('/servlet/Ajax?act=http.length',function(a){a=parseInt(a)/1048576;if(a<="+len+")return;parent.mt.show('您上传的附件大小为:'+a.toFixed(2)+'M<br/>附件的大小限制为:"+len+"M');location.reload();});",1000);
}



///PNG透明图解决方案//////////////////////
function alphaPNG(obj)
{
  var is=obj&&obj.src?new Array(obj):document.images;
  for(var i=0; i<is.length; i++)
  {
    if (is[i].src.toUpperCase().indexOf(".PNG")!=-1)
    {
      var LW=is[i].width;
      var LH=is[i].height;
      is[i].style.filter+="progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingmethod=scale,src="+is[i].src+");";
      is[i].src="/tea/sys/blank.gif";
      is[i].width=LW;
      is[i].height=LH;
    }
  }
}
//if(mt.isIE6)setInterval(alphaPNG,200);

//cookie
var cookie=new Object();
cookie.get=function(name, value)
{
	var search = name + "=";
	if (document.cookie.length > 0)
	{
		offset = document.cookie.indexOf(search);
		if (offset != -1)
		{
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1)end = document.cookie.length;
			return unescape(document.cookie.substring(offset, end));
		}
	}
	return value;
}

cookie.set=function(name, value)
{
	var expire = new Date();
	expire.setTime(expire.getTime() + 30*24*60*60*1000);
	document.cookie = name + "=" + escape(value) + "; expires=" + expire.toGMTString() + "; path=/";
}

cookie.remove=function(name)
{
	var expire = new Date();
	expire.setTime(expire.getTime() - 30*24*60*60*1000);
	document.cookie = name + "=remove; expires=" + expire.toGMTString() + "; path=/";
}

