/*公用JS文件*/
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
window.onerror=function(){
	return true;
}
//-->
//添加收藏夹
function addHouse(){
	window.external.AddFavorite(document.location.href,document.title);
	stopEvent(event);
	return false;
}
//设置为首页
function setIndexPage(obj){
	obj.style.behavior='url(#default#homepage)';
	obj.setHomePage(document.location.href);
	stopEvent(event);
	return false;
}
//阻止事件起泡
function stopEvent(event){
	try{
		event=event||window.event;
		event.returnValue = false;
		event.cancelBubble = true;
	}catch(e){}
}
//循环对象
function eachObj(obj,fn) {
	if (obj.length == undefined )
		for ( var i in obj )
			fn.call( obj[i], i, obj[i] );
	else
		for ( var i = 0, ol = obj.length, val = obj[0]; i < ol && fn.call(val,i,val) !== false; val = obj[++i] ){}
			return obj;
};
//页面初始化执行该方法
(function(){
	var db=document.body;
    if(!db||(typeof db!='object')){//document.body还未生成增加一个窗口加载事件
		window.attachEvent('onload',arguments.callee);
		return;
	}
	if(self!=top){
		top.location=self.location;    //判断是否是最顶层，不是则将当前页设置为最顶层
    }
	getContentDivHeight();
	try{if($('marqueeNews'))scrolldiv();}catch(e){}//滚动公告信息
    try{if($('marqueeVender'))scrollVender();}catch(e){}//滚动供应商信息
	try{XRTip.right=-1;}catch(e){}
    eachObj(document.getElementsByName("showTip"),function(i,o){//为名称为showTip的对象注册使用提示信息控件
		 try{XRTip.init(o,{title:o.titleName,check:true,width:(o.titleWidth?o.titleWidth:false)})}catch(e){alert(e.message);};
	});
	eachObj(document.getElementsByName("showTipOther"),function(i,o){
		 o=o.parentElement;//找到该对象的父节点，为父节点注册使用提示信息控件
		 try{XRTip.init(o,{title:o.titleName,width:(o.titleWidth?o.titleWidth:false)})}catch(e){alert(e.message);};
	});
	eachObj(document.getElementsByName("showTipSense_notes"),function(i,o){//在project_rq.jsp中定义
		try{
			 o=o.parentElement;//找到该对象的父节点，为父节点注册使用提示信息控件
			 var span=o.getElementsByTagName('span')[0];
			 if(parseInt(span.offsetWidth,10)>315){//判断节点宽度，是否需要注册提示信息控件
				XRTip.init(o,{title:o.titleName});
			 }
		}catch(e){}
	});
})();
//滚动公告信息(该信息在top.jsp中)
function scrolldiv(){
	var objgDiv = new Marquee(); //创建实例
	objgDiv.parentDiv ="marqueeNews"; //指定滚动父级包含层
	objgDiv.mainDiv = "marqueeOneNews"; //指定滚动层
	objgDiv.speed = 20; //滚动速度 单位是毫秒 1000＝1秒
	objgDiv.direction = "up"; //滚动方向"left":向左"right":向右"up":向上"down":向下
	objgDiv.pauseDistance = 36; //暂停距离，每隔多少距离暂停滚动
	objgDiv.pauseTime = 100; //暂停时间 单位：毫秒
	objgDiv.startStatus =0; //初始状态，默认为0:显示滚动内容；1:初始状态为空白；
	objgDiv.parentdivWidth=500; //显示的宽度
	objgDiv.parentdivHeight=34; //显示的高度
	objgDiv.start();
	objgDiv=null;
	$('marqueeNews').style.visibility='inherit';
}
//滚动供应商信息(该信息在index.jsp中)
function scrollVender(){
	var objgDiv = new Marquee(); //创建实例
	objgDiv.parentDiv ="marqueeVender"; //指定滚动父级包含层
	objgDiv.mainDiv = "marqueeOneVender"; //指定滚动层
	objgDiv.speed = 20; //滚动速度 单位是毫秒 1000＝1秒
	objgDiv.direction = "up"; //滚动方向"left":向左"right":向右"up":向上"down":向下
	objgDiv.pauseDistance = 80; //暂停距离，每隔多少距离暂停滚动
	objgDiv.pauseTime = 100; //暂停时间 单位：毫秒
	objgDiv.startStatus =0; //初始状态，默认为0:显示滚动内容；1:初始状态为空白；
	objgDiv.parentdivWidth=205; //显示的宽度
	objgDiv.parentdivHeight=198; //显示的高度
	objgDiv.start();
	objgDiv=null; 
	$('marqueeVender').style.visibility='inherit';
}
//修改验证码图片显示
function changeRand(){
	if($('randomnumber')){
		$('randomnumber').src='/'+xrbs.WEB_APP_NAME+'/logon?type=RandomNumber&timeStamp='+ new Date().getTime(); ;
	}
}
//取得FORM中控件值
function getFormValue(obj){
    var para='';
	var reg=null;
    for (i=0; i<obj.length; i++){
      if (obj(i).type == "button" ||
         obj(i).type == "submit" ||
         obj(i).type == "reset" ||
         (obj(i).type == "checkbox" && !obj(i).checked)) {
          continue;
       }
	 var name=obj(i).name;
	 if(name==''){
		 name=obj(i).id;
	 }
     if(obj(i).required&&obj(i).required=='true'){//控件必输标志
	    if(obj(i).value==''){
			alert('请输入'+obj(i).node+'!');
            obj(i).focus();
			return false;
		}
	 }
	 if(obj(i).match&&obj(i).value!=''){//控件上有表达式
	  /*使用该表达式进行验证*/
       reg=new RegExp(obj(i).match,"g");
	   if(!reg.test(obj(i).value)){//输入的值不满足匹配
	      alert(obj(i).node+'输入错误，请检查!');
          obj(i).focus();
		  return false;
	   }
	 }
     para=para+"&"+name+"="+obj(i).value.gsub(/&/,'xx@@').gsub(/[#]/,'@x@').gsub(/%/,'@p@').gsub(/[+]/,"P@P").gsub(';','x@x').gsub('=','w@w');;
  }
  return para;
}
//用户登陆系统
function onLogon(){
  var url='/'+xrbs.WEB_APP_NAME+'/logon?type=onLogon';
  var form=document.logonForm;
  if(form.account.value==''){
	  alert('请填写用户名！'); 
	  form.account.focus();
	  return false;
  }
  if(form.random.value==''){
	  alert('请填写验证码！');
	  form.random.focus();
	  return false;
  }
  var para='&random='+form.random.value;
  new _AJAX.Request(url, {method: 'post',parameters:para,onFailure:function(){
          alert('数据提交出错,请检查网络设置!');
        },
		onSuccess:function(r){
			var obj=null;
			try{
				eval("obj="+r.responseText.replace(/^\s+|\s+$/g,""));
				if(obj.error){
					alert('验证码输入错误!');
                    changeRand();//更换验证码
					$('random').value='';
					return;
				}else if(obj.success){
                    document.logonForm.passwd.value = hex_md5(document.logonForm.passwd.value);
					form.submit();
				}
			}catch(e){
				alert('数据提交出错,请检查网络设置!');
			}
		}
   });
}
function getTextParameter(url,name){
  var t="";
  var reg = new RegExp("(^|&|\\s)"+ name +"\\s*=\\s*([^&]*)(\\s|&|$)", "i");
  if (reg.test(url)){
    t= RegExp.$2;
  }
  return t;
}
function getContentDivHeight(){
	/*这里需要计算显示内容的滚动高度如果高度大于580则高度设置为580，如果高度小于200则设置为200*/
	var obj=$('contentDiv');
	if(obj){
		var height=(parseInt(obj.scrollHeight,10)>580?580+'px':(parseInt(obj.scrollHeight,10)<200?200+'px':obj.scrollHeight));
		obj.style.height=height;
	}
}