﻿var jcm=new jscommon;
function jscommon()
{

//  对CHECKBOX控件进行选中或者取消选中
//  setselected(objSelectName,bValue)

//  显示一个底部层，用于挡住所有页面，只显示大于1的层
//  showblacklayer(bShow)

//  显示或者隐藏指定HTML标识的控件
//  showcontrol(bShow,elmID)

//  取得当前IE的可视大小,返回数组
//  getpagesize()

//  在KEYPRESS事件里判断输入的是否数字
//  keyisnumber()

//  层的移动方法,调用移动的函数
//  canmove(divFlyBar)

//  设置对象显示或者隐藏
//  setdisplay(strObjID,bShow)

//  弹出窗口居中
//  opencenter(url, name, width, height, hasScrollbar)

//  左右LIST移动
//  两个选择框选项之间的移动，oSource为源选择框，oTarget为目标选择框
//  selectMove(oSource,oTarget)  


//测试
    this.t1=function (){
        return "aaa";
    }


//在当前窗口打开新窗口
    this.openlink=function(strLink)
    {
        try
        {
            var strID="tmpopenLink";
            var objP=window
                
            var objA=objP.document.getElementById(strID);
            
            if (objA==null)
                objA=objP.document.createElement("A");
                
            objA.id=strID;
            objA.href=strLink;
            
            objA.target="_blank";
            objP.document.body.appendChild(objA);
            objA.click();
            return true;
         }
         catch(e)
         {
            alert(e);
         }

    }
    
    
    
    //对CHECKBOX控件进行选中或者取消选中
    this.setselected=function(objSelectName,bValue) {
        var objSelect=document.getElementsByName(objSelectName);
        if (objSelect!=undefined)
        {
            if (objSelect.length!=undefined)
            {
                for (var i=0;i<objSelect.length;i++)
                    objSelect[i].checked=bValue;
            }
            else
                objSelect.checked=bValue;
        }
    }

    
    //显示一个底部层，用于挡住所有页面，只显示大于1的层
    this.showblacklayer=function(bShow)
    {

            //动态创建层
          if (document.getElementById("aw_disabled_layer")==null)
          {
              var   str   =   document.createElement("div");   
              str.id   =   "aw_disabled_layer";   
              str.style.position   =   "absolute";   
              str.style.left="0px";
              str.style.top="0px";
              str.style.width=getpagesize()[0]-2;
              str.style.height=getpagesize()[1]-2;
              str.style.setAttribute("border","1   solid   #000000");   
              str.style.backgroundColor="#000000";
              //str.style.setAttribute("layer-background-color","#000000");   
              str.style.zIndex="1";
              document.body.appendChild(str); 
           }
    	    
            
	        var Layer1=document.getElementById("aw_disabled_layer")

	        if (bShow)
	        {
		        Layer1.style.display='none'
	        }
	        else
	        {
		        Layer1.style.display='block'
	        }
		    showcontrol(bShow)
		        
	        //自动调整层的大小
            document.body.onresize=function()
            {
                var Layer1=document.getElementById("aw_disabled_layer");
                if (Layer1==null) return false;
                Layer1.style.setAttribute("width",getpagesize()[0]-2);   
                Layer1.style.setAttribute("height",getpagesize()[1]-2);       
            }
    }


    

    //显示或者隐藏指定HTML标识的控件
    showcontrol=function(bShow,elmID)
    {
      if( document.all )
      {
        if ((elmID=="") || (elmID==undefined))
            elmID='SELECT';
            
        for( i = 0; i < document.all.tags( elmID ).length; i++ )
        {
          obj = document.all.tags( elmID )[i];
          
          if( !obj || !obj.offsetParent )
          {
            continue;
          }
          
          if (bShow==false)
	          obj.style.visibility = "hidden";
		  else
		  	  obj.style.visibility = "";
        }
      }
    }



    //
    // getPageSize()
    // Returns array with page width, height and window width, height
    // Core code from - quirksmode.org
    // Edit for Firefox by pHaez
    //
    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){ // all but Explorer Mac
            xScroll = document.body.scrollWidth;
            yScroll = document.body.scrollHeight;
        } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
            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;
        } 

        // for small pages with total height less then height of the viewport
        if(yScroll < windowHeight){
            pageHeight = windowHeight;
        } else { 
            pageHeight = yScroll;
        }
        // for small pages with total width less then width of the viewport
        if(xScroll < windowWidth){ 
	        pageWidth = windowWidth;
        } else {
	        pageWidth = xScroll;
        }


        arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
        return arrayPageSize;
    }



//判断一个按键是否在0-9之间，或者是backspace、DEL键
    
    this.keyisnumber=function ()
    {

        var KeyCode=event.keyCode
        //如果输入的字符是在0-9之间，或者是backspace、DEL键
        
        
        if(((KeyCode>47)&&(KeyCode<58))||(KeyCode==8)||(KeyCode==46))
        {
              return true;
        }
        else
        {
              return false;
         }
    }



//在当前窗口打开新窗口,并设置其父级窗口为当前的父窗口
    this.openfromparent=function(strLink,strTarget)
    {
        try
        {
            var strID="tmpLink";
            var objP=window.opener
            if (objP==undefined)
                objP=window
                
            var objA=objP.document.getElementById(strID);
            
            if (objA==null)
                objA=objP.document.createElement("A");
                
            objA.id=strID;
            objA.href=strLink;
            
            if (strTarget=="")
                objA.target="_blank";
            else
                objA.target=strTarget;
            objP.document.body.appendChild(objA);
            objA.click();
            return true;
         }
         catch(e)
         {
            alert(e);
         }

    }

//层的移动方法------------------------------------------------------------------

    var bIsCatchFlyBar = false;   
    var dragClickX = 0;   
    var dragClickY = 0;   

//调用移动的函数

    this.canmove=function (divFlyBar){   
	    divFlyBar.onmouseup=function releaseFlyBar(){   
		    bIsCatchFlyBar = false;   
		    this.releaseCapture();   
		    document.onmousemove = null;   
		    //alert('ok');
	    }
    	
	    bIsCatchFlyBar = true;   
    	  
	    var x=event.x+document.body.scrollLeft;   
    	  
	    var y=event.y+document.body.scrollTop;   
    	  
	    dragClickX=x-divFlyBar.style.pixelLeft;   
    	  
	    dragClickY=y-divFlyBar.style.pixelTop;   
    	  
	    divFlyBar.setCapture();   
	    document.onmousemove = function moveFlyBar()
	    {     
	        if(bIsCatchFlyBar){     
		        divFlyBar.style.left = event.x+document.body.scrollLeft-dragClickX;     
		        divFlyBar.style.top = event.y+document.body.scrollTop-dragClickY;   
	        }
	    }
    }   
    
//层的移动方法------------------------------------------------------------------


    
    //设置对象显示或者隐藏
    
    this.setdisplay=function (strObjID,bShow)  
    {
        var objTarget=document.getElementById(strObjID);
        if (objTarget!=null)
        {
            if (bShow)
                objTarget.style.display="block";
            else
                objTarget.style.display="none";
        }
        else
        {
            alert("Can Not Find Object:" + strObjID);
        }
    }
    
    
    //弹出窗口居中
    var _aw_windowname=null;
    this.opencenter=function (url, name, width, height, hasScrollbar){
	    left_p = (screen.width - width) / 2;
	    top_p = (screen.height - height) / 2 - 50;
	    if (hasScrollbar==true)
		    features="scrollbars=yes";
	    else
		    features="scrollbars=no";
	    features += ",width=" + width + "px,height=" + height + "px,left=" + left_p + ",top=" + top_p + ",toolbar=no,location=no,directories=no,status=no,menubar=no;"
	    _aw_windowname=window.open(url,name,features);

    }

//树自动选中下级复选框

    function AW_client_OnTreeNodeChecked()
    {
        var obj = window.event.srcElement;
        var treeNodeFound = false;
        var checkedState;
        if (obj.tagName == "INPUT" && obj.type == "checkbox") {
        var treeNode = obj;
        checkedState = treeNode.checked;
        do {obj = obj.parentElement;}
        while (obj.tagName != "TABLE")
        var parentTreeLevel = obj.rows[0].cells.length;
        var parentTreeNode = obj.rows[0].cells[0];
        var tables = obj.parentElement.getElementsByTagName("TABLE");
        var numTables = tables.length
        if (numTables >= 1)
        {
        for (i=0; i < numTables; i++)
        {
        if (tables[i] == obj)
        {
        treeNodeFound = true;
        i++;
        if (i == numTables)
        {
        return;
        }
        }
        if (treeNodeFound == true)
        {
        var childTreeLevel = tables[i].rows[0].cells.length;
        if (childTreeLevel > parentTreeLevel)
        {
        var cell = tables[i].rows[0].cells[childTreeLevel - 1];
        var inputs = cell.getElementsByTagName("INPUT");
        inputs[0].checked = checkedState;
        }
        else
        {
        return;
        }
        }
        }
        }
        }
    }




    //左右LIST移动

    this.selectMove=function (oSource,oTarget)  //两个选择框选项之间的移动，oSource为源选择框，oTarget为目标选择框
    
    {
//      if(!oSource.options.length)
//      {
//        //alert(cWhich+"侧列表中已没有选项可选，无法移动！");
//        return;
//      }
//      if(oSource.selectedIndex==-1)
//      {
//        //alert("操作前您首先应该从"+cWhich+"侧列表中选择一项！");
//        return;
//      }
      var mySld=new Array();
      for(i=0;i<oSource.options.length;i++)
        if(oSource.options[i].selected)
          mySld[mySld.length++]=i;
      for(i=0;i<mySld.length;i++)
      {
        oTarget.options.length++;
        oTarget.options[oTarget.options.length-1].text=oSource.options[mySld[i]].text;
        oTarget.options[oTarget.options.length-1].value=oSource.options[mySld[i]].value;
      }
      for(i=0;i<mySld.length;i++)
      {
        for(j=mySld[i]-i;j<oSource.options.length-1;j++)
        {
          oSource.options[j].text=oSource.options[j+1].text;
          oSource.options[j].value=oSource.options[j+1].value;
        }
        oSource.options.length--;
      }
    }

    this.moveAll=function (oSource,oTarget)
    {
      var n=oTarget.options.length;
      oTarget.options.length=n+oSource.options.length;
      for(i=n;i<oTarget.options.length;i++)
      {
        oTarget.options[i].text=oSource.options[i-n].text;
        oTarget.options[i].value=oSource.options[i-n].value;
      }
      oSource.options.length=0;
    }


    this.moveUp=function (select1)
    {
    var nowIndex=select1.selectedIndex;
    if(select1.value!="")
    {
       if(select1.selectedIndex-1>=0)
       {
        tempValue=select1.item(nowIndex-1).value;
        tempName=select1.item(nowIndex-1).text;
        select1.item(nowIndex-1).value=select1.item(nowIndex).value;
        select1.item(nowIndex-1).text=select1.item(nowIndex).text;
        select1.item(nowIndex).value=tempValue;    
        select1.item(nowIndex).text=tempName;
        for(var i=0;i<select1.length;i++)
           select1.item(i).selected=false;
        select1.item(nowIndex-1).selected=true;
       }
    }
    }

    this.moveTop=function (select1)
    {
     var nowIndex=select1.selectedIndex;
     if((select1.value!="")&&(nowIndex!=0))
     {
        tempValue=select1.item(nowIndex).value;
        tempName=select1.item(nowIndex).text;
        for(var i=nowIndex;i>0;i--)
        {
        select1.item(i).value=select1.item(i-1).value;
        select1.item(i).text=select1.item(i-1).text;
        }
        select1.item(0).value=tempValue;    
        select1.item(0).text=tempName;
        for(var i=0;i<select1.length;i++)
           select1.item(i).selected=false;
        select1.item(0).selected=true;
     }
    }

    this.moveDown=function (select1)
    {
    var nowIndex=select1.selectedIndex;
    if(select1.value!="")
    {
       if(nowIndex+1<select1.length)
       {
        tempValue=select1.item(nowIndex+1).value;
        tempName=select1.item(nowIndex+1).text;
        select1.item(nowIndex+1).value=select1.item(nowIndex).value;
        select1.item(nowIndex+1).text=select1.item(nowIndex).text;
        select1.item(nowIndex).value=tempValue;    
        select1.item(nowIndex).text=tempName;
        for(var i=0;i<select1.length;i++)
           select1.item(i).selected=false;
        select1.item(nowIndex+1).selected=true;
       }
    }
    }

    this.moveBottom=function (select1)
    {
     var nowIndex=select1.selectedIndex;
     if((select1.value!="")&&(nowIndex!=select1.length-1))
     {
        tempValue=select1.item(nowIndex).value;
        tempName=select1.item(nowIndex).text;
        for(var i=nowIndex;i<select1.length-1;i++)
        {
        select1.item(i).value=select1.item(i+1).value;
        select1.item(i).text=select1.item(i+1).text;
        }
        select1.item(select1.length-1).value=tempValue;    
        select1.item(select1.length-1).text=tempName;
        for(var i=0;i<select1.length;i++)
           select1.item(i).selected=false;
        select1.item(select1.length-1).selected=true;
     }
    }
    
      this.SetOrderValue=function (oSource,oTarget){
        var oTmp;
        var i,j;

          j=0
          for(i=0;i<oTarget.length;i++)
          {
            oTmp=document.getElementById(oTarget.options[i].value);
            if (oTmp!=null){
                oTmp.value=j;
                oTmp.checked=true;
                //oTmp.focus();
                oTmp.fireEvent('onfocus');
                j++;
//                alert('ok');
            }
          }

          for(i=0;i<oSource.length;i++)
          {
            oTmp=document.getElementById(oSource.options[i].value);
            if (oTmp!=null){
                oTmp.checked=false;
                //oTmp.focus();
                oTmp.fireEvent('onfocus');
            }
          }
          
          //oSource.focus();


      } 
      
      



}