
/////////////// DIV function begin/////////////////////////////////////////////

//for DIV: change html content of a layer named lyrname. 
   function  js_div_update_text(  lyrname , msg  )
   {      
      var divobj = document.getElementById( lyrname );   
      if( null == divobj) return ;
        divobj.innerHTML = msg;     
   }

//for DIV: change html content of a layer named lyrname.    
   function  js_div_update_visible( lyrname , v )
   {
   	var divobj = document.getElementById( lyrname );  
   	if( null == divobj) return ;
   	var disp;
   	if( v ) disp = "block";
   	else    disp = "none";
   	divobj.style.display = disp;
   }
   
   
function  js_div_showorhide( idDIV, id1, id2 )
{
  var  divObj = document.getElementById( idDIV);
  if( null == divObj ) return;
  
  var  aObj1 = document.getElementById( id1 );
  var  aObj2 = document.getElementById( id2 );
  if(null == aObj1 || null == aObj2 ) return;       
    
  if( divObj.style.display == "none" ) {
     divObj.style.display = "inline";
     aObj1.style.display = "inline";
     aObj2.style.display = "none";     
  }
  else {
     divObj.style.display = "none";
     aObj1.style.display = "none";
     aObj2.style.display = "inline";     
  }

}   
   
   
/////////////// DIV function end/////////////////////////////////////////////
var   js_xmlmenu_idcookie = "js_xmlmenu_current_id";	


/////////////XML Menu Function Begin //////////////////////////// 
//Expand the menu item list  , whose ID is $id.
function js_xmlmenu_shift(id)
{    
		
	if(null == id )  {
	   return;
	}
	  	
	var   oldid   = js_cookie_get( 	js_xmlmenu_idcookie );	
	
	if( oldid != id ) {
		var   lastobj = document.getElementById( oldid );
		if( null !=lastobj ) {
		   lastobj.style.display = 'none'; 		   
		}
	}
		
	var   newobj  = document.getElementById( id );		
	newobj.style.display  = 'block';	
	js_cookie_set_default( js_xmlmenu_idcookie , id );		
	  
}


///initialize Xml Menu.
function  js_xmlmenu_init_leftmenu(divmenuid)
{        
 
  if( null == document.getElementById( divmenuid ) ) {
     return;
  }

  var   lastid =  js_cookie_get( js_xmlmenu_idcookie  );  
  //alert(lastid);    
  js_xmlmenu_shift( lastid );
    
  var vname = divmenuid + "_visible";  
  js_cookie_set_default( vname , "true");

}


//Show or hide Xml Menu DIV.
//called when the parent holder is clicked.
function js_xmlmenu_switch( divmenuid , parentid )
{
   var vname = divmenuid + "_visible";   
   var v = js_cookie_get(vname);                    
     
   var parentobj = document.getElementById(parentid);
   if( "false" == v )
   {  
       js_cookie_set_default( vname , "true");       
       js_div_update_visible( divmenuid , true);       
       if( null != parentobj )parentobj.style.width = 180;       
   }
   else 
   { 
       js_cookie_set_default( vname , "false");       
       js_div_update_visible( divmenuid , false);
       if( null != parentobj )parentobj.style.width = 1;       
       
    }   
  
}


function  js_xmlmenu_status( divmenuid )
{
   
  if( null == divmenuid)  {  
    js_browser_updatestatusbar("");
  }
  else {
  
	  var vname = divmenuid + "_visible";   
	  var v = js_cookie_get(vname); 
	  if( "false" == v )
	  {
	     js_browser_updatestatusbar( "Click to show navigation menu panel." ); 
	  }
	  else {
	    js_browser_updatestatusbar( "Click to hide navigation menu panel." ); 
	  }
  
  }
   
}


///////////////TOP MENU///////////////
function js_xmlmenu_init_topmenu() {
	if (document.all&&document.getElementById) 
	{
		cssdropdownRoot = document.getElementById("xmlmenucssdropdown");
		if( null == cssdropdownRoot ) return ;
		
		for (i=0; i<cssdropdownRoot.childNodes.length; i++) 
		{
			node = cssdropdownRoot.childNodes[i];
			if (node.nodeName=="LI") 
			{
					node.onmouseover=function() 
					{
							this.className+=" over";
					}
		  		node.onmouseout=function() 
		  		{
		  				this.className=this.className.replace(" over", "");
					}
			}
		}
	}
}



/////////////// Xml Menu End ////////////



///////////SmallBOS MiniControlPane DIV Begin ////////////////


  var idDragClass = "idDragClass";
  var idMain = "idMiniControlPane";
  var idBody = "idMiniControlPaneBody";

  function $(d){return document.getElementById(d);}
  function gs(d){var t=$(d);if (t){return t.style;}else{return null;}}
  function gs2(d,a){
    if (d.currentStyle){ 
      var curVal=d.currentStyle[a]
    }else{ 
      var curVal=document.defaultView.getComputedStyle(d, null)[a]
    } 
    return curVal;
  }    
  
  
  if  (document.getElementById){
    (
      function(){
        if (window.opera){ document.write("<input type='hidden' id='Q' value=' '>"); }
      
        var n = 500;
        var dragok = false;
        var y,x,d,dy,dx;
        
        function move(e)
        {
          if (!e) e = window.event;
          if (dragok){
            d.style.left = dx + e.clientX - x + "px";
            d.style.top  = dy + e.clientY - y + "px";
            return false;
          }
        }
        
        function down(e){
          if (!e) e = window.event;
          var temp = (typeof e.target != "undefined")?e.target:e.srcElement;
          if (temp.tagName != "HTML"|"BODY" && temp.className != idDragClass){
            temp = (typeof temp.parentNode != "undefined")?temp.parentNode:temp.parentElement;
          }
          if('TR'==temp.tagName){
            temp = (typeof temp.parentNode != "undefined")?temp.parentNode:temp.parentElement;
            temp = (typeof temp.parentNode != "undefined")?temp.parentNode:temp.parentElement;
            temp = (typeof temp.parentNode != "undefined")?temp.parentNode:temp.parentElement;
          }
        
          if (temp.className == idDragClass){
            if (window.opera){ document.getElementById("Q").focus(); }
            dragok = true;
            temp.style.zIndex = n++;
            d = temp;
            dx = parseInt(gs2(temp,"left"))|0;
            dy = parseInt(gs2(temp,"top"))|0;
            x = e.clientX;
            y = e.clientY;
            document.onmousemove = move;
            return false;
          }
        }
        
        function up(){
          dragok = false;
          document.onmousemove = null;
        }
        
        document.onmousedown = down;
        document.onmouseup = up;
      
      }
    )();
  }
    
   ////////////////////////////   



function  BosMiniPanePage(  sID , sTitle, sIcon  , sURL )
{   
   this.id = sID;
   this.title = sTitle;
   this.icon = sIcon;
   this.url = sURL;    
   this.sheet =  null;
   this.index = 0;   
   this.object = document.getElementById( sID );      
   this.headerid = sID + "Header";   
}

BosMiniPanePage.prototype.setSheet = function( st)
{
  this.sheet = st;
}


BosMiniPanePage.prototype.getSheet = function( )
{
  return this.sheet;
}

BosMiniPanePage.prototype.valid = function()
{
  if( this.object == null ) return false;
  return true;
}

BosMiniPanePage.prototype.show = function()
{
   if(!this.valid() ) return;        
   this.object.style.display = "block";
   
  var aHeaderObj = document.getElementById( this.headerid );
  aHeaderObj.className = this.getSheet().getSelectedCSS();   
}

BosMiniPanePage.prototype.hide = function()
{
   if(!this.valid() ) return;
   this.object.style.display = "none";
   var aHeaderObj = document.getElementById( this.headerid );
  aHeaderObj.className = this.getSheet().getNormalCSS();      
}

BosMiniPanePage.prototype.switchto = function()
{
   if(!this.valid() ) return;
   this.sheet.switchto( this.index );
}


function  BosMiniPaneSheet( sName, sID ,  sTitle , sDragClass  )
{
  this.id = sID;
  this.name = sName;
  this.title = sTitle;
  this.dragclass = sDragClass;          
  
  this.idHeader = sID + "Header";
  this.idBody   = sID + "Body";
  this.idMinimize = sID + "Minimize";
  this.idMaximize = sID + "Maximize";
  
  this.currentIndex = 0;  
  this.pages = new Array();      
  
  this.object = null;
  this.width  = 0;
  this.height = 0;
  
  this.showPicture = true;
  this.showText = false;
  
  this.normalCSS = "cssminipaneheader";
  this.selectedCSS = "cssminipaneheaderselected";
     
}

BosMiniPaneSheet.prototype.getNormalCSS = function ( )
{
  return this.normalCSS;
}


BosMiniPaneSheet.prototype.getSelectedCSS = function ( )
{
  return this.selectedCSS;
}

BosMiniPaneSheet.prototype.getShowPicture = function ( )
{
  return this.showPicture;
}

BosMiniPaneSheet.prototype.getShowText = function ( )
{
  return this.showText;
}


BosMiniPaneSheet.prototype.minimize = function ( )
{
  var  divBody = document.getElementById( this.idBody );
  divBody.style.display = "none";  
}

BosMiniPaneSheet.prototype.maximize = function ( )
{
  var  divBody = document.getElementById( this.idBody );
  divBody.style.display = "block";  
}

BosMiniPaneSheet.prototype.relayout = function ( )
{    
   this.width  = 300;   
}

BosMiniPaneSheet.prototype.create = function ( )
{
   this.object = document.getElementById( this.id ); 
     
   var pbtnMinimize = document.getElementById( this.idMinimize);         
   if( pbtnMinimize != null) pbtnMinimize.onclick = "js_div_update_visible('" + this.idBody +  "', false )";
  
   var pbtnMaximize = document.getElementById( this.idMaximize);   
   if( pbtnMaximize != null) pbtnMaximize.onclick = "js_div_update_visible('" + this.idBody +  "', true )"
  
   return true;

}

BosMiniPaneSheet.prototype.addPage = function ( pg )
{

  var  divHeader = document.getElementById( this.idHeader );
  if(null == divHeader ) return false;


  var divBody = document.getElementById( this.idBody );
  if( null == divBody) return;


  if(!pg.valid()) return false;
  pg.index = this.getPageCount();
  this.pages.push( pg );  
  divBody.appendChild(pg.object);  
  pg.setSheet( this );
  
  
  var  oldHtml = divHeader.innerHTML;        
  var  pghtml = "<a href='" + "javascript:void(0)" + "' id='" + pg.headerid + "' title='" + pg.title + "' onclick='js_minipane_switch( " + this.name + " ," + pg.index + ")' >";
  
  if( this.getShowPicture() )
    pghtml += "<img src='" + pg.icon + "' border='0'  width='16' height='16' alt='" + pg.title + "' />";
    
  if( this.getShowText() )
    pghtml += pg.title ;
      
  pghtml += "</a>";  
  divHeader.innerHTML = pghtml + oldHtml;      
  
  return true;
  
}

BosMiniPaneSheet.prototype.removeAllPages = function()
{
  while(this.pages.length > 0 ) this.pages.pop();
}

BosMiniPaneSheet.prototype.getPageCount = function()
{
  return this.pages.length;
}

BosMiniPaneSheet.prototype.switchto = function( idx )
{
  if(idx<0 || idx >= this.pages.length) return;
  var n;
  for(n=0;n<this.pages.length;n++) 
  {
    this.pages[n].hide();
    
  }
  
  this.pages[idx].show();
  this.currentIndex = idx;  
  
}

BosMiniPaneSheet.prototype.currentPage = function()
{
   return  this.currentIndex;
}

BosMiniPaneSheet.prototype.getPage = function( idx )
{
  if(idx<0 || idx >= this.pages.length) return;
  return this.pages[idx];
}

BosMiniPaneSheet.prototype.show = function()
{
   if(this.object == null)  return;      
   this.relayout(); 
   this.object.style.left     = document.body.scrollLeft +document.body.clientWidth - this.width - 2;
   this.object.style.top      = document.body.scrollTop + 2;    	 
}

function FloatHidden( id ){ document.getElementById(id).style.display = "none";}
function FloatShow(id){ document.getElementById(id).style.display = "";}
function FloatClose(id){ document.getElementById(id).style.display = "none";}



 function  js_minipane_init(pSheet,  pPages)
 {
    if(null == pSheet  ) return false;
    if( null == pPages || pPages.length == 0 ) return false;             
    
    if(!pSheet.create() ) return false;
    
    var n;
    for(n=0;n<pPages.length;n++) {
    
       if( pPages[n] == null || pPages[n].length != 4 ) continue;
       var pg = new BosMiniPanePage( pPages[n][0], pPages[n][1], pPages[n][2], pPages[n][3] );
       pSheet.addPage( pg );
    }
              
    var objidx =  js_cookie_get( pSheet.id + "_curidx" );
    if(null == objidx || "" == objidx ) objidx = 0;    
    
    pSheet.show();
    pSheet.switchto( objidx );
    
    return true;

 }
 
 

 function  js_minipane_switch( pSheet,  idx )
 {    
    if(null == pSheet ) return ;
    pSheet.switchto( idx ); 
    js_cookie_set_default( pSheet.id + "_curidx", idx ); 
 }
 
 
 function   js_minipane_show( pSheet )
 {
   if(null == pSheet ) return ;
   pSheet.show();
 }
  
  ///////////SmallBOS MiniControlPane DIV  End ////////////////
  
////////////////HTML Element Style Begin////////////////

//////Require style class : button_normal, button_over,button_down/////////

function  BosElementStyle( sClassNormal, sClassMouseOver, sClassMouseOut, sClassMouseUp, sClassMouseDown )
{    
  this.classNormal    = sClassNormal;
  this.classMouseOver = sClassMouseOver;
  this.classMouseOut  = sClassMouseOut;
  this.classMouseUp   = sClassMouseUp;
  this.classMouseDown = sClassMouseDown;        
  
}


function  BosButtonStyle()
{
   this.SuperConstructor = BosElementStyle;
   this.SuperConstructor("button_normal", "button_over", "button_out", "button_up", "button_down" ); 
}


function  BosElement( sID ,  sTitle , pStyle )  {
 this.id = sID;
 this.style = pStyle;
 this.title = sTitle;
 this.styleclass = pStyle.classNormal;
 this.object = document.getElementById( sID );
}

BosElement.prototype.valid = function()
{
  if(null==this.object) return false;
  return  true;
}

BosElement.prototype.onMouseOver = function()
{
   var  pThis = this;
   this.changeStyle( pThis.style.classMouseOver );
}


BosElement.prototype.onMouseOut = function()
{
   var  pThis = this;
   this.changeStyle( pThis.style.classMouseOut );
}


BosElement.prototype.onMouseUp = function()
{
   var  pThis = this;
   this.changeStyle( pThis.style.classMouseUp );
}


BosElement.prototype.onMouseDown = function()
{
   var  pThis = this;
   this.changeStyle( pThis.style.classMouseDown );
}

BosElement.prototype.update = function()
{
  if(this.valid()) {
  
    var pThis = this;    
    this.object.title = pThis.title;
    this.object.className = pThis.styleclass;    
        
    var  pfnOnMouseOver = function() {
          pThis.onMouseOver();          
    }    
    this.object.onmouseover = pfnOnMouseOver;

    var  pfnOnMouseOut = function() { 
          pThis.onMouseOut();
     }
   	this.object.onmouseout = pfnOnMouseOut;

    var  pfnOnMouseup = function() { 
     		  pThis.onMouseUp();
     }
   	 this.object.onmouseup = pfnOnMouseup;

     var  pfnOnMouseDown = function() {
          pThis.onMouseDown();
     }
   	 this.object.onmousedown = pfnOnMouseDown;  
  }
}

BosElement.prototype.changeStyle = function( sClass )
{
 this.styleclass = sClass;
 this.update();
}

function  js_style_init()
{
  js_style_button_init( );
}


function  js_style_button_init( )
{
  var  objs = document.getElementsByTagName( "input" );
  if(null == objs ) return ;
  
  var pStyle = new BosButtonStyle();

  var n;
  for(n=0;n<objs.length;n++) 
  {
    var   obj = objs[n];
    if( obj.type == "submit" || obj.type == "button" ) {
       
         if(null==obj.id || obj.id.length == 0 ) continue;                           
         var pObj = new BosElement( obj.id , obj.value , pStyle );
         pObj.update();   
    }
    
  }     
}
////////////////HTML Element Style End//////////////



////////////////////Bos Picture Browser Begin ////////////////////////

function  BosPictureBrowser(  )
{
   this.pictureID = "";
   this.objPicture = null;
   this.objCounter = null;
   this.objHolder = null;
   this.pictureArray = new Array();
   this.textArray = new Array();
   this.pictureIndex = 0;
   this.timer = null;
   this.speed = 1000*3;
}



BosPictureBrowser.prototype.create = function( aPicID, aPicCounterID , aHolderDivID)
{
   this.pictureID = aPicID;
   this.objPicture = document.getElementById( aPicID );
   this.objCounter = document.getElementById( aPicCounterID );
   this.objHolder  = document.getElementById( aHolderDivID );

}

BosPictureBrowser.prototype.destroy= function ()
{
   this.hide();
   this.pictureID = "";
   this.objPicture = null;
   this.objCounter = null;
   this.objHolder = null;
   this.pictureArray = new Array();
   this.textArray = new Array();
   this.pictureIndex = 0;
   this.timer = null;
   this.speed = 1000*3;
}


BosPictureBrowser.prototype.getPictureID = function( )
{
  return this.pictureID;
}

BosPictureBrowser.prototype.getPicture = function( )
{
  return this.objPicture;
}


BosPictureBrowser.prototype.getCounter = function( )
{
  return this.objCounter;
}


BosPictureBrowser.prototype.getHolder = function( )
{
  return this.objHolder;
}


BosPictureBrowser.prototype.getIndex = function( )
{
  return this.pictureIndex;
}

BosPictureBrowser.prototype.getPictureCount = function( )
{
  return this.pictureArray.length;
}

BosPictureBrowser.prototype.bof = function( )
{
  return  this.getIndex() == 0 ;
}



BosPictureBrowser.prototype.eof = function( )
{
  return  this.getIndex() + 1 >= this.getPictureCount();
}



BosPictureBrowser.prototype.repaint = function( )
{  
 var picObj = this.getPicture();
 var picIndex = this.getIndex();
  if (picObj != null  && picIndex >= 0 && picIndex < this.getPictureCount() ) {			
			picObj.src=this.pictureArray[picIndex];
			picObj.alt=this.textArray[picIndex];			
  }
  else {
    return false;
  }
  
  var picSEQ = picIndex + 1;
  var picCounterObj  = this.getCounter();  
  picCounterObj.innerHTML = this.textArray[picIndex] + "&nbsp;&nbsp;&nbsp;(" + picSEQ + "/" + this.pictureArray.length + ")&nbsp;" ;
  return true;
}

BosPictureBrowser.prototype.first = function()
{
  if( this.getPictureCount() == 0 ) return false;
    
  this.pictureIndex = 0;
  return this.repaint();  
}


BosPictureBrowser.prototype.last = function()
{
  if( this.getPictureCount() == 0 ) return false;  
  this.pictureIndex  = this.pictureArray.length-1;  
	return this.repaint();  
}

BosPictureBrowser.prototype.previous = function()
{
  if( this.getPictureCount() == 0 || this.bof() ) return false;    
  this.pictureIndex--;
	return this.repaint();  
}



BosPictureBrowser.prototype.next = function()
{
  if( this.getPictureCount() == 0 || this.eof()  ) return false;    
  this.pictureIndex++;
  return this.repaint()
}


BosPictureBrowser.prototype.show = function()
{   
   var  aHolder = this.getHolder();
   if(null != aHolder )  {
      aHolder.style.display = "block";
   }
}


BosPictureBrowser.prototype.hide = function()
{
   this.stop();
   var  aHolder = this.getHolder();
   if(null != aHolder )  {
      aHolder.style.display = "none";
   }
}


BosPictureBrowser.prototype.addPicture = function( aPicURL, aPicTitle )
{
   this.pictureArray.push( aPicURL );
   this.textArray.push( aPicTitle );
}

BosPictureBrowser.prototype.autostep = function()
{
	  this.next();
    if(this.eof() ) {
      this.stop();      
    }   
}

BosPictureBrowser.prototype.play = function()
{  
  if( this.first() == false ) return false;
  var   pThis = this;   
  var   pfnTimeout = function() {
      pThis.autostep();
  }                        
  this.timer = window.setInterval(pfnTimeout,this.speed)  
  return true;
}

BosPictureBrowser.prototype.stop = function()
{
   if(this.timer != null ) {
       window.clearInterval(this.timer);
       this.timer = null;       
       return true;
   }  
   return false;
}

////////////////////Bos Picture Browser End ////////////////////////
