﻿// JavaScript Document
String.prototype.Trim = function() 
{ 
   try{return this.replace(/(^\s*)|(\s*$)/g, ""); }catch(e){}
   return this;
}

String.prototype.LTrim = function() 
{ 
   try{return this.replace(/(^\s*)/g, ""); }catch(e){}
   return this;
   
}

String.prototype.RTrim = function() 
{ 
   try{return this.replace(/(\s*$)/g, "");  }catch(e){}
   return this;
}
Array.prototype.del=function(n) { 
  if(n<0)  
    return this;
  else
    return this.slice(0,n).concat(this.slice(n+1,this.length));
    
}

var $config=new Object();
$config.context="";//程序的上下文

var $L=new Object();//对象集合
 
//=====统计代码------点击次数-------例如{pojo:'',id:''}======
$L.Click=function(ps){
   if(!ps)ps={};
   JAVA.清空监听();
   JAVA.调用成功=function(message){
	   
   }
   JAVA.调用("com.jcms.company.ajax.Click",ps);//用户登录
}




//=======================================================================================================================
//var $L=new Object(); 
//---浏览器事件模型
$L.Event=new function(){
	var events={};
//-------添加事件-------------------------------------------
	this.addEvent=function(type,name,fun){//添加事件类型和函数
        events[type+"-"+name]=fun;
    }
	this.removeEvent=function(type,name){events[type+"-"+name]=null;}
	document.onmouseup=function(){doEvent("onmouseup");}
	document.onmousedown=function(){doEvent("onmousedown");}
	document.onmousemove=function(){doEvent("onmousemove");}
	function doEvent(type){
	   for(var n in events){
		  if(n.indexOf(type)==0)try{if(events[n])events[n]();}catch(e){}
	   }	
	}
}
//逻辑对象
$L.logic=new Object();//逻辑对象
$L.logic.isLineX=function(left,right,y,top,bottom,x){
　return (top < y) && (bottom > y)&& (left < x) && (right > x);
}
 
$L.getDate=function(str){
   var date=new Date();
   try{
	   var d=/(\d+)-(\d+)-(\d+)/.exec(str);
	   date.setYear(parseInt(d[1]));date.setMonth(parseInt(d[2])-1);date.setDate(parseInt(d[3]));
	   d=/(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)/.exec(str);
	   if(d){date.setHours(parseInt(d[4]));date.setMinutes(parseInt(d[5]));date.setSeconds(parseInt(d[6]));}
   }catch(e){}
   return date;
}
$L.trim=function(str){ try{ str=str.trim(); }catch(e){} return str;}
$L.hide=function(el){el=$L.el(el);el.style.display='none';}
$L.show=function(el,isNear){
	el=$L.el(el);el.style.display='';
    if(isNear){
		var t=event.y-$L.getBoxHeight(el)-100;
		if(t<10)t=10;
		el.style.top=t+'px';
    }
}
$L.sAc=function(s,h){$L.hide(h);$L.show(s);}
$L.setText=function(el,text){el=$L.el(el);el.innerHTML=text;}
$L.tagName=function(tag,source){if(!source)return document.getElementsByTagName(tag);return source.getElementsByTagName(tag);}
$L.addZero=function(n){if(n<10)return "0"+n;return n;}
$L.getContext=function(){return $config.context;}
$L.check=function(r){var ua = navigator.userAgent.toLowerCase();return r.test(ua);}
$L.isChrome=$L.check(/chrome/);
$L.isOpera =$L.check(/opera/);
$L.isIE=!$L.isOpera&&$L.check(/msie/);
$L.isIE7 =$L.isIE &&$L.check(/msie 7/);
$L.openQQ=function(qq){ window.open("tencent://message/?uin="+qq);}
$L.isIE8 =$L.isIE &&$L.check(/msie 8/);
$L.isWindows=$L.check(/windows|win32/);
$L.isLinux =$L.check(/linux/);
$L.replaceAll=function(str,newStr,oldStr){while(str.indexOf(oldStr)!=-1)str=str.replace(oldStr,newStr);return str;}
$L.getLeft=function(el){var left=0; while(el.offsetParent){left+=el.offsetLeft;el=el.offsetParent;}return left;}
$L.getTop=function(el){var top=0;while(el.offsetParent){top+=el.offsetTop;el=el.offsetParent;}return top;}
$L.getBoxWidth=function(el){return el.offsetWidth;}
$L.getBoxHeight=function(el){return el.offsetHeight;}
$L.getBrother=function(obj,index){return obj.parentNode.childNodes[index];}
$L.endChCss=function(el,css){if(typeof el=='string')el=$L.ID(el);el=el.childNodes;el[el.length-1].className=css;}
$L.changeCss=function(el,len,css){el=$L.ID(el);text=el.innerHTML;var n1=text.substring(0,len);n2=text.substring(len);
                      el.innerHTML="<span class='"+css+"'>"+n1+"</span>"+n2;}
$L.el=function(el){if(typeof el=='string')el=$L.ID(el);return el;}
$L.joinArray=function(c1,c2){for(var n in c2){if(!c2[n])continue;c1[n]=c2[n];}}
$L.clearSelect=function(sel){while(sel.options.length>0)sel.remove(0);}
$L.loadSelect=function(sel,data){for(var i=0;i<data.length;i++){var d=data[i]; var o=new Option(d[0],d[1]);sel.add(o);o.data=d;}}
$L.removeData=function(array,o){for(var i=0;i<array.length;i++){if(array[i]==o){if(i==0)array.splice(i,i+1);else array.splice(i,i);return true;}}return false;}
$L.callPage=function(url,isPost){/*偷偷访问指定页面*/
    var name="privateCallFormDiv";
    var el=$L.ID(name);
	
	if(!el){
	    var root=$L.create("DIV",{'id':name},document.body);
		//root.style.display='none';
		var form=$L.create("FORM",{'id':name+"-form"},root);
		var frame=$L.create("IFRAME",{'name':name+"-frame"},root);
		form.target=name+"-frame";
	}
	var form=$L.ID(name+"-form");
	 
	form.action=url;
	form.method="get";if(isPost)form.method="post";
	form.submit();
}
$L.getHeight=function(){var h=document.documentElement.clientHeight;if(h)return h;return document.body.clientHeight;}
$L.setCenter=function(el){
     if(typeof el=='string')el=$L.ID(el);
	 var pel=el.parentNode;
	 el.style.marginLeft=parseInt(($L.getBoxWidth(pel)-$L.getBoxWidth(el))/2)+"px";
	 if(pel!=document.body)
	     el.style.marginTop=parseInt(($L.getBoxHeight(pel)-$L.getBoxHeight(el))/2)+"px";
	 else
		 el.style.marginTop=parseInt(($L.getHeight()-$L.getBoxHeight(el))/2)+"px";
}

$L.transData=function(names,ids){
   var d0=ids.split(",");var d1=names.split(",");
   if(d0.length!=d1.length){return null;}
   var d=new Array();
   for(var i=0;i<d0.length;i++){
      var temp=new Array();temp[1]=d0[i];temp[0]=d1[i];
	  d.push(temp);
   }
   return d;
}


$L.getRequest=function(name){
   name=name.toLowerCase()
   var href=location.href;
   href=href.toLowerCase()
   var start=href.indexOf(name+'=');
   if(start==-1)return '';
   href=href=href.substring(start+(name+'=').length);
   var end=href.indexOf("&");
   if(end==-1)return href;
   return href.substring(0,end);
}



$L.getSystemSeconds=function(){
   var myDate = new Date();
   var ys=myDate.getYear()-2010;
   //年份的处理
   var days=ys*365+parseInt(ys/4);
   //月份的处理
   var ms=myDate.getMonth();
   if(ms==1)days+=31;
   if(ms==2)days+=59;
   if(ms==3)days+=90;
   if(ms==4)days+=120;
   if(ms==5)days+=151;
   if(ms==6)days+=181;
   if(ms==7)days+=212;
   if(ms==8)days+=243;
   if(ms==9)days+=273;
   if(ms==10)days+=304;
   if(ms==11)days+=334;
   //润年的处理---以2010为参照那么4的0和1不需要考虑  4的2和3需要考虑
   if((ys%4)==3)days++;//去年是润年
   if(ys%4==2&&ms>1){days++;}//今年是润年 闰月已经过去
   days+=myDate.getDate()-1;
   var hs=days*24;//小时
   hs+=myDate.getHours();
   var ms=hs*60;//分钟
   ms+=myDate.getMinutes();
   var ss=ms*60;
   ss+=myDate.getSeconds();
   return ss;
}

$L.Date = function (myDate) {
    if (!myDate) myDate = new Date();
    if (typeof myDate == 'string') myDate = $L.getDate(myDate);
    var yy = myDate.getYear();
    var yyyy = myDate.getFullYear();
    var mm = myDate.getMonth() + 1;
    var dd = myDate.getDate();
    var day = myDate.getDay();
    var HH = myDate.getHours();
    var MM = myDate.getMinutes();
    var SS = myDate.getSeconds();
    switch (day) {
        case 0: day = "日"; break; case 1: day = "一"; break; case 2: day = "二"; break;
        case 3: day = "三"; break; case 4: day = "四"; break; case 5: day = "五"; break; case 6: day = "六"; break;
    }
    this.getString = function (str) {
		if(!str)str='yyyy-mm-dd HH:MM:SS';
        str = str.replace("yyyy", yyyy); str = str.replace("yy", $L.addZero(yy));
        str = str.replace("mm", $L.addZero(mm)); str = str.replace("dd", $L.addZero(dd));
        str = str.replace("day", day); str = str.replace("HH", $L.addZero(HH));
        str = str.replace("MM", $L.addZero(MM)); str = str.replace("SS", $L.addZero(SS));
        return str;
    }
    //下一天
    this.getNextDay = function (str) {
		var date=new Date();
		date.setDate(date.getDate()+1);
		var newDate=new $L.Date(date);
		var time=newDate.getString(str);
		return time;
    }
    //上一天
    this.getPreDay = function (str) {
		var date=new Date();
		date.setDate(date.getDate()-1);
		var newDate=new $L.Date(date);
		var time=newDate.getString(str);
		return time;
    }
	//获取指定天数 与当前时间的差 num :差多少天.
	this.getNumDay=function(num,str){
		if(!num){alert("获取指定天数的时间出错,没有参数!");return;}
		num=parseInt(num);
		var date=new Date();
		date.setDate(date.getDate()+num);
		var newDate=new $L.Date(date);
		var time=newDate.getString(str);
		return time;
	}
	

}
$L.date=$L.Date;//向下兼容


$L.updateTime=function(el,str,isOn){
	var d=new $L.date();
   	el=$L.el(el);el.innerHTML=d.getString(str);
	if(isOn){setInterval(function(){d=new $L.date();el.innerHTML=d.getString(str);},1000)}
}

$L.localPath=function(path){var href=location.href;href=href.substring(0,href.lastIndexOf("/"))+"/"+path;return href;}
$L.parseInt=function(val,dVal){if(!dVal)dVal=0;try{val=parseInt(val);if(isNaN(val))return dVal;return val}catch(e){return dVal}}
$L.ID=function(id){return document.getElementById(id);}
$L.removeCh=function(el){el.parentNode.removeChild(el);}
$L.removeChs=function(hs){for(var i=0;i<hs.length;i++)$L.removeCh(hs[i]);}

/**设为首页**/
$L.saveIndex=function(){
   var sObj=event.srcElement;
   sObj.style.behavior='url(#default#homepage)';
   sObj.setHomePage(location.href);
}
/**收藏页面**/
$L.addFavorite=function(title){
	var url=location.href;
	window.external.addFavorite(url,title);
}


//设置样式
$L.setStyle=function(el,attr){
	if(typeof attr=='string'){
		var as=attr.split(";");
		attr={};
		for(var i=0;i<as.length;i++){
			as[i]=$L.trim(as[i]);
			var start=as[i].indexOf(":");
			var n=as[i].substring(0,start);
			var v=as[i].substring(start+1);
			n=$L.trim(n);v=$L.trim(v);n=$L.cssUpp(n);
			attr[n]=v;
		}
	 }
	 if(attr['float']){attr['styleFloat']=attr['float'];attr['cssFloat']=attr['float'];}
	 for(n in attr){try{el.style[n]=attr[n];}catch(e){}}
}
//创建节点对象
$L.create=function(tag,attr,parent,attrCode){
	 tag=tag.toUpperCase();
     var tagObj=document.createElement(tag);
	 if(tag=="INPUT"){
		 if(!attrCode)attrCode="";
		 if(attr&&attr['name']){attrCode="name='"+attr['name']+"' "}
		 tagObj=document.createElement("<input "+attrCode+">");
	 }
	 for(n in attr){
		tagObj.setAttribute(n,attr[n]);
		tagObj[n]=attr[n];
     }
	 tagObj.setStyles=function(attr){
		 $L.setStyle(tagObj,attr);
	 }
	 tagObj.setStyle=function(n,v){if(n=='float'){tagObj.style.styleFloat=v;tagObj.style.cssFloat=v;}else tagObj.style[n]=v;}
	 
	 if(parent){parent.appendChild(tagObj);}
	 return tagObj;
}
$L.getLeft=function(el){var left=0; while(el.offsetParent){left+=el.offsetLeft;el=el.offsetParent;}return left;}
$L.getTop=function(el){var top=0;while(el.offsetParent){top+=el.offsetTop;el=el.offsetParent;}return top;}
$L.getBoxWidth=function(el){return el.offsetWidth;}
$L.getBoxHeight=function(el){return el.offsetHeight;}
$L.cssUpp=function(str){
  str=str.replace(/-\w+/g,function(word) {
	  return word.substring(1,2).toUpperCase( )+
	  word.substring(2);
  });
  return str;
}
$L.simpleOrder=function(array,name,orderby){
     var newArray=new Array();
	 var os=orderby.split(",");
	 for(var j=0;j<os.length;j++){
		 for(var i=0;i<array.length;i++){
			 if(array[i][name]!=os[j])continue;
			 newArray.push(array[i]);
		 }
	 }
     return newArray;
}


$L.eval=function(message){
  try{message=$L.replaceAll(message,'/','\\');}catch(e){}
  try{var data=eval(message);return data;}catch(e){
     message=$L.replaceAll(message,'','\'');
	 message=$L.replaceAll(message,'','{');
	 message=$L.replaceAll(message,'','}');
 
	 var ms=message.split(",");
	 var data={};
	 for(var i=0;i<ms.length;i++){
        var start=ms[i].indexOf(":");
		if(start==-1)continue;
		var key=ms[i].substring(0,start);
		var value=ms[i].substring(start+1);
		data[key]=value;
	 }
	  
	 return data;
  }
}

/**跳转***/
$L.sendRedirect=function(url){
   url=encodeURI(url);
   location.href=url;
} 
 
//----百分百刷新-------------------
$L.refresh=function(){
    var href=location.href;
	href=$L.refreshHref(href);
	$L.sendRedirect(href);
}
$L.refreshTo=function(config){
    var href=location.href;
	var start=href.indexOf("?");
	var url=href;
	if(start!=-1){
	   
	
	}
	
	 
}

$L.refreshHref=function(href){
	var d=parseInt(Math.random()*1000);
    if(href.indexOf("timeRandomJcms=")!=-1)href=href.replace("timeRandomJcms=","timeRandomJcms="+d);
	else if(href.indexOf("?")==-1)href+="?timeRandomJcms="+d;
	else href+="&timeRandomJcms="+d;
	return href;
}
//延时执行
$L.DelayExe=function(config,time){
	if(!time)time=100;
	var self=this;
	self.exe=function(){}
	self.clear=function(){clearInterval(intervalId);}
    var intervalId=null;
	setTimeout(function(){
		intervalId=setInterval(function(){
			self.exe(config,self);							
		},time);		
	},100);
}
/*****Cookies的操作****/
$L.setCookie=function(name,value,time)
{
 var str=name+"="+escape(value);//编码以适合任何浏览器
 if(time<0){
  var mm=time*1000*60;//time分钟
  var date =new Date();
  date.setTime(date.getTime()+mm);
  str+=";expires="+date.toGMTString();
 }
 document.cookie=str;
}



//#----------------
/**
* 简单菜单切换
* outID:tab菜单外部标签
* target: 指定的切换标签对象
* index:默认显示第几个
* config:{hoverClass:'',outClass:''}
* tabContent:数组 ,需要显示隐藏的几个块ID
**/
$L.onTabChange=function(outID,target,index,config){
	var outObj=$L.ID(outID);
	var sons=outObj.getElementsByTagName(target);
	if(sons.length<index){alert("指定显示的tab菜单不存在,数组越界!");return;}
	for(var i=0;i<sons.length;i++){
		sons[i].index=i;
		sons[i].onmouseover=function(){
			for(var j=0;j<sons.length;j++){
				sons[j].className=config['outClass'];
				var tabContent=config['tabContent'];
				for(var m=0;m<tabContent.length;m++){$L.ID(tabContent[m]).style.display="none";}
			}
			this.className=config['hoverClass'];
			$L.ID(tabContent[this.index]).style.display="";
		}
	}
}

