window.$=function( sId ){return document.getElementById( sId)};

function getTr( el ){
      while (  el && el.tagName != 'TR' ) {
       el = el.parentNode;
     }
    return el;
 }

function getParentByTagName( o,sTagName ){
    while (  o && o.tagName != sTagName) {
       o = o.parentNode;
     }
    return o;
 }

function getPosTopLeft(o) {
    var p = new Object();
    p.top = 0;
    p.left = 0;
    while (o != null) {
        p.top += o.offsetTop;
        p.left += o.offsetLeft;
        o = o.offsetParent;
       //TEST This out
       if(o && ( o.style.position == 'relative'|| o.style.position=='absolute') )   break;

    }
    return p;
}

function addEvent(obj,sEvent,oFn,bUseCapture){
   if( window.attachEvent ) return obj.attachEvent('on' + sEvent ,oFn);
   else if( window.addEventListener) {
   
   obj.addEventListener(sEvent,oFn,bUseCapture||false);
   return true;
   }
  else obj['on'+sEvent] = oFn ;
}

function removeEvent(o, sEvent, oFn,bUseCapture){
 
  if (document.detachEvent){
   window.status=o + oFn;
  o.detachEvent('on' + sEvent, oFn);
  return;
  }
  else {
  if (document.removeEventListener){
  bUseCapture=bUseCapture?bUseCapture:false;
  o.removeEventListener(sEvent, oFn,bUseCapture);
  return true;}
  else o['on'+sEvent] = null;}}
  
function selectStart(){
	if(window.event.srcElement.tagName == "INPUT")
		return;
	window.event.cancelBubble = true; 
	window.event.returnValue = false; 
	return false;	
}
  

function getDocClientAndOffsetHeight(){
var oBody = document.getElementsByTagName('BODY')[0];
//if Internet Explorer
if( document.all ) {
    // IE in strict mode  
    if( document.documentElement.clientHeight > 0 & oBody.currentStyle){
          this.clientHeight = document.documentElement.clientHeight;
          this.offsetHeight = document.body.offsetHeight;
          this.offsetHeight = document.body.scrollHeight;
          var m={};
          m.top  =    oBody.currentStyle['marginTop'];
          m.bottom = oBody.currentStyle['marginBottom'];
         this.offsetHeight += ( parseInt(m.top) + parseInt(m.bottom));
    }
    else{ 
         
          this.clientHeight = document.body.clientHeight;
          this.offsetHeight=document.body.scrollHeight;
       }
 }
 else{
   // Gecko
    this.clientHeight = self.innerHeight ;  // self.innerHeight;       
     this.offsetHeight=document.body.scrollHeight;
      var m={};
      if( document.defaultView ) {
      m.top  =  document.defaultView.getComputedStyle(oBody, '').getPropertyValue('margin-top') ;
      m.bottom = document.defaultView.getComputedStyle(oBody, '').getPropertyValue('margin-bottom') ;
      this.offsetHeight += ( parseInt(m.top) + parseInt(m.bottom)   ); //20px offset for scroll bars          
      }
 }   
  
   return this;  
} 



function fade(el,state){
      if( el ){
        
        fade.el = el;
        el.style.display='block';
        
    if( state.toLowerCase()== 'on' ){
          fade.opacity=10;
          fade.target=100;
          fade.increment=1;
        }
        else {
         fade.opacity=90;
         fade.target=0;
         fade.increment=-1;
        }
          
      }
     
      if( (fade.opacity <= 50 && fade.target==100) || (fade.opacity>=50 && fade.target==0)){
        fade.opacity += fade.increment;
        fade.el.style.filter='alpha(opacity=' + fade.opacity + ')';
        fade.el.style['opacity'] = fade.opacity/100;
        var wait = (fade.target == 0? -1 * (49 - fade.opacity ): 52 - fade.opacity);
     //        window.status = fade.el.style.filter  + '  ' + fade.target + ' ' + _i++ + '  wait:' + wait;
        setTimeout( "fade()",wait);
    }
    else{
      if(fade.target==0) {
        fade.el.style.display='none';
        fade.el.style.opacity='';    
      }
      else{
         fade.el.style.filter='alpha(opacity=' + 100 + ')';
         fade.el.style.opacity='';  
      }
      
   }
 
}    

String.prototype._format=function(args){
var s = this.toString();
if( typeof( args ) == 'object' ){ 
s = s.replace( /{/g, '\'+args[\'' );
return eval( '\''+s.replace(/}/g,'\']+ \'') +'\'');
} 
    s = s.replace( /{/g, '\'+arguments[' );
    return eval( '\''+s.replace(/}/g,']+ \'') +'\'');
}


function PleaseWait(icon,mesg){
 var elLoad = document.createElement('div');
 if( ! icon ) icon='spinner.gif';
 if( ! mesg ) mesg='Please Wait...';
  with ( elLoad.style ){
     visibility='hidden';
     position='absolute';
     border='1px solid #eee';
     padding='5px 10px 5px 10px';
     zIndex=1000;
     backgroundColor='#eee';
    } 
     elLoad.innerHTML = '<img border="0" src="' + icon + '">&nbsp;' + mesg + '</span>';
   document.body.appendChild( elLoad );
  PleaseWait.id = elLoad;
}

PleaseWait.show=function(viewPort){
var t,l;
var elView = document.getElementById(viewPort);
var elLoad = PleaseWait.id;

if( true || ! elView ) {
t = ((document.body.clientHeight - elLoad.offsetHeight) / 2 );
l = ((document.body.clientWidth - elLoad.offsetWidth )/ 2 );
}
else {
t =  parseInt(elView.style.top)  + ( (elView.offsetHeight - elLoad.offsetHeight ) / 2 );
l = parseInt(elView.style.left) + ( (elView.offsetWidth - elLoad.offsetWidth )/ 2 );

if( (t <=0 ) || ( l <=0 ) ) {
l = parseInt(elView.style.left);
t = parseInt(elView.style.top);
}

}


elLoad.style.visibility='visible';
elLoad.style.left = l.toString() + "px";
elLoad.style.top = t.toString() + "px";


}

PleaseWait.hide=function(){
PleaseWait.id.style.visibility='hidden';
}



