// ----------- LightBox Class -------------//
lightBox = Class.create({

  showIC: function() {

    var self = this;
      
    $$('span.closeText').each( function(o){ 
      o.innerHTML = htz.iwText.close 
      o.style.backgroundImage = "url('" + self.closeX + "')"
      o.style.backgroundPosition = "right"
      })
    
    eventsActive = false

    Element.update( $('divICContent') , $('divWorkSpace').innerHTML )	

    $('divICBorderBox').style.top = ( document.body.scrollTop + 80 ) + "px"

    scrollW = document.body.scrollWidth	
    scrollH = document.body.scrollHeight
 
    clientW = document.body.clientWidth
    clientH = document.documentElement.clientHeight

		screenH = ( clientH > scrollH ) ? clientH + "px" : scrollH + "px"
		screenW = ( clientW > scrollW ) ? clientW + "px" : scrollW + "px"		
		
    $('divICScreen').style.width = ( screenW )
    $('divICScreen').style.height = ( screenH )

    alpha($('divICScreen'),40)

    $('divICScreen').style.display = "block"
    $('divICBorderBox').style.display = "block"    

    Event.observe( document, 'keyup',   function(e) { self.hideIC.call(self) } )     
    Event.observe( window ,  'resize' , function(e) { self.hideIC.call(self) } ) 
    Event.observe( window ,  'scroll' , function(e) { self.hideIC.call(self) } ) 
      
  },
  
  hideIC: function() {

    $('divICBorderBox').style.display="none"  
    $('divICScreen').style.display="none"
    setTimeout('reengageIdleCustomers.show()', htz.idleCustomer.Timeout);    
    
    /*  
    Event.stopObserving( document, 'keyup',   function(e) { self.hideIC.call(self) } )     
    Event.stopObserving( window ,  'resize' , function(e) { self.hideIC.call(self) } ) 
    Event.stopObserving( window ,  'scroll' , function(e) { self.hideIC.call(self) } ) 
    */

  },

  
  show:	function () {
	
    Element.update( $('divLBContent') , $('divWorkSpace').innerHTML )	
    if ( $('divLBBorderBox').style.display == 'block' ) return false;

		if(this.ie6) {
			if (this.parms.screen != 0 ) {
				$$('select').each( function(o){ o.style.visibility = (o.className == "noHide") ? 'visible' : 'hidden' })  
			} else {
 				$('lbIF').style.width = this.parms.width + 10
				$('lbIF').style.height = this.parms.height + 10 
				$('lbIF').style.top = this.parms.top - 5
				$('lbIF').style.left = this.parms.left - 5
			}
		}    
		
    $('divLBContent').style.width = this.parms.width
    $('divLBMenuTop').style.width = this.parms.width
    $('divLBMenuBottom').style.width = this.parms.width    

    $('divLBMenuTop').style.display = ( this.menu.top == "true" ) ? "block" : "none"
    $('divLBMenuBottom').style.display = ( this.menu.bottom == "true" ) ? "block" : "none"    
    
    alpha($('divLBScreen'),this.parms.screen)
    $('divLBScreen').style.display = "block"
    $('divLBBorderBox').style.display = "block"
    
    },

  hide:	function () {
  
    var self = this;
    
    if (!eventsActive) {
      eventsActive = true;
      return
      }

    $('divLBBorderBox').style.display="none"  
    $('divLBScreen').style.display="none"
    $('tdLBMenu').innerHTML = "&nbsp;"
    

		if(this.ie6) {
			if (this.parms.screen != 0 ) {
				$$('select').each( function(o){ o.style.visibility = 'visible' })  
			} else {
				$('lbIF').style.height = 0
				$('lbIF').style.width  = 0
				$('lbIF').style.top  = 0
				$('lbIF').style.left  = 0
			}
		}    
			
    // right now
    if ( $('ifrRightNow') ) $('ifrRightNow').src = this.blank
    if ( $('divWorkSpace') ) $('divWorkSpace').innerHTML = ""
    // right now
    
    Event.stopObserving( window ,  'resize' , function(e) { self.setPosition.call(self) } ) 
    Event.stopObserving( window ,  'scroll' , function(e) { self.setPosition.call(self) } ) 
    Event.stopObserving( $('divLBScreen') , 'click'  )     
    Event.stopObserving( document, 'keyup'  )     

    },

  init:	function () {
    var self = this;
    $$('span.closeText').each( function(o){ 
      o.innerHTML = htz.iwText.close 
      o.style.backgroundImage = "url('" + self.closeX + "')"
      o.style.backgroundPosition = "right"
      })
  
    var self = this;
    
    eventsActive = true;

    if ( this.parms.center == "true" )  Event.observe( window ,  'resize' , function(e) { self.setPosition.call(self) } ) 
    if ( this.parms.scroll == "true" )  Event.observe( window ,  'scroll' , function(e) { self.setPosition.call(self) } ) 
    if ( this.parms.dismiss == "true" ) Event.observe( document, 'keyup',   function(e){ if( e.keyCode == 27 ) self.hide.call(self) }  ) 

    $('divLBScreen').className="closeLightBox"     
    if ( this.parms.dismiss == "false" ) $('divLBScreen').className=""

    $$('.closeLightBox').each( function(o) {      
      Event.observe( o, 'click', function() {self.hide.call(self) } )          
  		})

    self.setPosition.call(self)
      
    },
    
  setPosition: function() {

    scrollW = document.body.scrollWidth	
    scrollH = document.body.scrollHeight
 
    clientW = document.body.clientWidth
    clientH = document.documentElement.clientHeight

		screenH = ( clientH > scrollH ) ? clientH + "px" : scrollH + "px"
		screenW = ( clientW > scrollW ) ? clientW + "px" : scrollW + "px"		
		
    scrollOffset = ( document.documentElement.scrollTop > document.body.scrollTop ) ? document.documentElement.scrollTop : document.body.scrollTop 
		
    $('divLBScreen').style.width = ( screenW )
    $('divLBScreen').style.height = ( screenH )
    $('divLBBorderBox').style.top = ( this.parms.scroll == "true" ) ? ( scrollOffset + 100 + "px") : this.parms.top  + "px"   
    $('divLBBorderBox').style.width = ( this.parms.width + "px" )      
		$('divLBBorderBox').style.padding = ( this.parms.border + "px" )
		
		$('divLBContent').style.height = ( this.parms.height == "" ) ? "auto" : ( this.parms.height + "px" )
		$('divLBContent').style.overflow = ( this.parms.height == "" ) ? "visible" : "auto"
		
    acceptableW = ( clientW > 1000 ) ? 1000 : clientW
    posLeft = (Math.round ( ( ( acceptableW - this.parms.width ) / 2 ) ) + "px")
    $('divLBBorderBox').style.left = ( this.parms.center == "true" ) ? posLeft : this.parms.left + "px"		
		
    },

  ie6: parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5))==6,

  blank: "/rentacar/lightbox/blank.jsp",
  closeX : ( htz.config.protocol + "://images.hertz.com" + htz.config.context + "/misc_refresh/popup_close.gif") ,
  
  menu: { 
    top     : "false", 
    bottom  : "true" 
    },  
    
  parms: {
    url     : "",
    top     : 100,    
    left    : 100,  
    width   : 400,
    border  : 10,
    height  : "",		
    center  : "true",    
    scroll  : "true",
    screen  : 40,    
    dismiss : "true",
    event : {}
    },

  reset: function() {
    this.menu.top       = "false"
    this.menu.bottom    = "true" 
    this.parms.url      = ""
    this.parms.top      = 100
    this.parms.left     = 100
    this.parms.height   = ""
    this.parms.width    = 400
    this.parms.border   = 10
    this.parms.center   = "true"    
    this.parms.scroll   = "true"
    this.parms.screen   = 40    
    this.parms.dismiss  = "true"
    this.parms.event = {}
    },
      
  // This method clears the content of the light box.  
  clearContent : function() {
	 	if($('divWorkSpace')) $('divWorkSpace').innerHTML = '';
		if($('divLBContent')) $('divLBContent').innerHTML = '';
  },
		
  // ----------- Generic JSP Request -------------//    
  jspRequest: function(args) {
    var self = this;
    new Ajax.Request( this.parms.url,  {  
      method: 'post', 
      onSuccess:  this.execSuccess,
      onFailure:  this.execFailure,
      onComplete: function(req) { 
		if(req.getHeader("Ajax-Session-Timeout")=="true" && req.getHeader("Location")) window.location.href = req.getHeader("Location")
		else self.execComplete.call(self, req, args)
      	self.parms.event()
		}
      });
    },
    
  execSuccess: function(req) {  
    Element.update( $('divWorkSpace'), req.responseText )  
    },  
  
  execFailure: function(req) {  
    Element.update( $('divRequestFailedText'), htz.iwText.ajaxFail )    
    Element.update( $('divWorkSpace'), $('divRequestFailed').innerHTML )  
    },
    
  execComplete: function(req, args) {  
    if ( args == "IC" ) {
      this.showIC() 
      return
      }
      
    this.show()
 
    },          
  // ----------- Generic JSP Request -------------//        


  // ----------- Div Request -------------//  
  showRequest: function() {
		el = ( typeof this.parms.url == "string" ) ? $(this.parms.url) : this.parms.url
    $('divWorkSpace').innerHTML =  el.innerHTML
    this.show()
    }
  // ----------- Div Request -------------//    
  
  })
// ----------- LightBox Class -------------//



// ----------- Generic Opacity Script -------------//
alpha = function(obj, opacity){
  style = obj.style;
  style.opacity = style.MozOpacity = style.KhtmlOpacity = opacity / 100;
  style.filter = "alpha(opacity=" + opacity + ")";
  };
// ----------- Generic Opacity Script -------------//  
