// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function statuspopup() {
  window.newwindow = window.open('/home/popout','status',
    'height=10,width=210,status=no');
  return false;
}

function checkval(id) {
  var retval = document.getElementById(id).checked;
}

// ==================================================
// Function: verifyFormValuesPresent()
// Purpose: validates home/airport search parameters
// ==================================================
function verifyFormValuesPresent() {
  // ==================================
  // airport
  // ==================================
  if ($('search_airport_id').value == '0') {
    settext('errors','Airport cannot be blank');
    return false;
  } else {
    
    // update the airport name on the loading_page
    var selIndex = $('search_airport_id').selectedIndex;
    var airport_name = $('prfAirportName').value;
    document.getElementById("airport_name").innerHTML = airport_name;
        
    settext('errors','');
  }
  // ==================================
  // location
  // ==================================
  if ($('location_location_type').value == '') {
    settext('errors','Location cannot be blank');
    return false;
  } else {
    settext('errors','');
  }
  // ==================================
  // departure day|arrival day
  // ==================================
  if ($('tofrom').value == 'oneway') {
    if ($('search_service_type_to_airport2').checked == true) {
      // To Airport
      if ($('search_departure_day').value == '') {
        settext('errors','You must enter a departure day');
        return false;
      } else {
        settext('errors','');
      }
    } else {
      // From Airport
      if ($('search_arrival_day').value == '') {
        settext('errors','You must enter an arrival day');
        return false;
      } else {
        settext('errors','');
      }
    }
  } else {
    // Roundtrip
    if ($('search_service_type_to_airport2').checked == true) {
      // To Airport
      if ($('search_departure_day').value == '') {
        settext('errors','You must enter a departure day');
        return false;
      } else {
        settext('errors','');
      }
    } else {
      // From Airport
      if ($('search_arrival_day').value == '') {
        settext('errors','You must enter an arrival day');
        return false;
      } else {
        settext('errors','');
      }
    }
    // Return
    if ($('search_return_day').value == '') {
      settext('errors','You must enter an arrival day');
      return false;
    } else {
      settext('errors','');
    }
  }
  //if ($('search_service_type_to_airport').checked == true) {
  //    if ($('search_departure_day').value == '') {
  //      settext('errors','You must enter a departure day');
  //      return false;
  //    } else {
  //      settext('errors','');
  //    }          
  //} else {
  //    if ($('search_arrival_day').value == '') {
  //      settext('errors','You must enter an arrival day');
  //      return false;
  //    } else {
  //      settext('errors','');
  //    }          
  //}
    
  // ==================================
  // location type
  // ==================================
  if ($('location_location_type').value == 'City') {
    if ($('address_street_address1').value=='' || $('address_postal_code').value=='') {
      settext('errors','You must enter both street and zipcode');
      return false;
    }
    if ($('address_street_address1').value.match(/^(\d)/) == null) {
      settext('errors','Street number missing in address');
      return false;
    }
    if ($('address_street_address1').value.match(/\s\w/) == null) {
      settext('errors','Street address missing');
      return false;
    }
    if ($('address_postal_code').value.match(/^\d{5}/) == null) {
      settext('errors','Zip code must be 5 digits');
      return false;
    }
    if ($('address_postal_code').value.length != 5) {
      settext('errors','Zip code must be 5 digits');
      return false;
    }
  }
 
  // Validated - Start Loading Screen
  loadingScreen();
  
  // we need to make sure we submit the remote_form using the ajax way
  var form = document.getElementById('searchform_id');
//if (form.onsubmit()) {
//    form.submit();
//} 
  
//return true;
}

// ==================================================
// Function: verifyFareQuoteZip()
// Purpose: verifies input parameters for farequote
// ==================================================
function verifyFareQuoteZip() {
  if ( $('fare_quote_zip_code').value == '' || $('fare_quote_zip_code').value == 'zip code' ) {
    settext('errors_fare_quote_landmark','');
    settext('errors_fare_quote_zip','Please enter a zip code');
    return false;
  }
  if ($('fare_quote_zip_code').value.length != 5) {
    settext('errors_fare_quote_landmark','');
    settext('errors_fare_quote_zip','Zip code must be 5 digits');
    return false;
  }
  if (isNaN($('fare_quote_zip_code').value)) {
    settext('errors_fare_quote_landmark','');
    settext('errors_fare_quote_zip','Zip code must be digits only');
    return false;
  }
  if (getChecked('service_type_to') == true) {
    $('service_type_zip').value = 'to_airport';
  } else {
    $('service_type_zip').value = 'from_airport';
  }
  settext('errors_fare_quote_zip','');
  settext('errors_fare_quote_landmark','');
  return true;
}

// ==================================================
// Function: verifyFareQuoteLandmark()
// Purpose: verifies input parameters for farequote
// ==================================================
function verifyFareQuoteLandmark() {
  if ( $('fare_quote_landmark').value == '' || $('fare_quote_landmark').value == 'Landmark / Hotel' ) {
    settext('errors_fare_quote_zip','');
    settext('errors_fare_quote_landmark','Please enter a hotel or landmark name');
    return false;
  }
	
  var myRegExp = /AIRPORT|AIRPORTS/;
  var string1 = $('fare_quote_landmark').value;
  string1 = string1.toUpperCase();
  var matchPos1 = string1.search(myRegExp);

  if(matchPos1 != -1) {
    settext('errors_fare_quote_zip','');
    settext('errors_fare_quote_landmark','Please enter a hotel or landmark, not an Airport.');
    return false;
  }

  var i=0;
  for (i=0;i<=67;i++)
  {
    if ( $('fare_quote_landmark').value.toUpperCase() == airCodes[i]) {
      settext('errors_fare_quote_zip','');
      settext('errors_fare_quote_landmark','Please enter a hotel or landmark, not an Airport.');
      return false;
    }
  }
  if ( $('fare_quote_city').value == '' || $('fare_quote_city').value == 'City' ) {
    settext('errors_fare_quote_zip','');
    settext('errors_fare_quote_landmark','Please enter city');
    return false;
  }
  if ($('fare_quote_landmark').value.length < 3) {
    settext('errors_fare_quote_zip','');
    settext('errors_fare_quote_landmark','Landmark name must be at least 3 characters');
    return false;
  }
  if (getChecked('service_type_to') == true) {
    $('service_type_landmark').value = 'to_airport';
  } else {
    $('service_type_landmark').value = 'from_airport';
  }
	
  var str=$('fare_quote_city').value;
  $('fare_quote_city').value=(str.split(",",1));
	
  settext('errors_fare_quote_zip','');
  settext('errors_fare_quote_landmark','');
  return true;
}
// ==================================================
// Function: verifyFareQuoteCity()
// Purpose: verifies input parameters for farequote
// ==================================================
function verifyFareQuoteCity() {	
  if ( $('fare_quote_city').value == '' || $('fare_quote_city').value == 'City' ) {
    settext('errors_fare_quote_zip','');
    settext('errors_fare_quote_landmark','Please enter city');
    return false;
  }

  var myRegExp = /AIRPORT|AIRPORTS/;
  var string1 = $('fare_quote_city').value;
  string1 = string1.toUpperCase();
  var matchPos1 = string1.search(myRegExp);

  if(matchPos1 != -1) {
    settext('errors_fare_quote_zip','');
    settext('errors_fare_quote_landmark','Please type in a city, not an airport.');
    return false;
  }

  var i=0;
  for (i=0;i<=67;i++)
  {
    if ( $('fare_quote_city').value.toUpperCase() == airCodes[i]) {
      settext('errors_fare_quote_zip','');
      settext('errors_fare_quote_landmark','Please type in a city, not an airport.');
      return false;
    }
  }
  var str=$('fare_quote_city').value;
  $('fare_quote_city').value=(str.split(",",1));
	
  settext('errors_fare_quote_zip','');
  settext('errors_fare_quote_landmark','');
  return true;
}
//=====================================
//AIRPORT CODES ARRAY FOR VALIDATION
//=====================================
var airCodes=new Array();
airCodes[0]="ATL";
airCodes[1]="BOS";
airCodes[2]="BWI";
airCodes[3]="CLT";
airCodes[4]="CVG";
airCodes[5]="DCA";
airCodes[6]="DEN";
airCodes[7]="DFW";
airCodes[8]="DTW";
airCodes[9]="EWR";
airCodes[10]="FLL";
airCodes[11]="HNL";
airCodes[12]="IAD";
airCodes[13]="IAH";
airCodes[14]="JFK";
airCodes[15]="LAS";
airCodes[16]="LAX";
airCodes[17]="LGA";
airCodes[18]="MCO";
airCodes[19]="MDW";
airCodes[20]="MIA";
airCodes[21]="MSP";
airCodes[22]="OAK";
airCodes[23]="ORD";
airCodes[24]="PHL";
airCodes[25]="PHX";
airCodes[26]="PIT";
airCodes[27]="SAN";
airCodes[28]="SEA";
airCodes[29]="SFO";
airCodes[30]="SLC";
airCodes[31]="STL";
airCodes[32]="TPA";
airCodes[33]="ABQ";
airCodes[34]="ANC";
airCodes[35]="AUS";
airCodes[36]="BDL";
airCodes[37]="BNA";
airCodes[38]="BUF";
airCodes[39]="BUR";
airCodes[40]="CLE";
airCodes[41]="CMH";
airCodes[42]="DAL";
airCodes[43]="HOU";
airCodes[44]="IND";
airCodes[45]="JAX";
airCodes[46]="MCI";
airCodes[47]="MEM";
airCodes[48]="MHT";
airCodes[49]="MKE";
airCodes[50]="MSY";
airCodes[51]="OGG";
airCodes[52]="OMA";
airCodes[53]="ONT";
airCodes[54]="ORF";
airCodes[55]="PBI";
airCodes[56]="PDX";
airCodes[57]="PVD";
airCodes[58]="RDU";
airCodes[59]="RNO";
airCodes[60]="RSW";
airCodes[61]="SAT";
airCodes[62]="SDF";
airCodes[63]="SJC";
airCodes[64]="SJU";
airCodes[65]="SMF";
airCodes[66]="SNA";
airCodes[67]="TUS";
//===================================================
//Function: loadingFQ()
//Prupose: Display loading message for fare quote
//===================================================
function loadingFQ() {	
  document.getElementById('overlay').style.display='block';
  document.getElementById('overlay').style.visibility='visible';
  document.getElementById('working').style.display='block';
  document.getElementById('working').style.visibility='visible';
}
// ==================================================
// Function: verifyFareQuoteZipSearch()
// Purpose: verifies input parameters for search
// ==================================================
function verifyScheduled() {
  if ( $('search_scheduled_id').value == '0') {
    settext('errors_scheduled','Please select an airport');
    return false;
  }
}
// ==================================================
// Function: verifyFareQuoteZipSearch()
// Purpose: verifies input parameters for search
// ==================================================
function verifyFareQuoteZipSearch() {
  if ( $('address_street_address1').value == '') {
    settext('errors_search','Please enter an address');
    return false;
  }
  if ($('address_street_address1').value.match(/^(\d)/) == null) {
    settext('errors_search','Street number missing in address');
    return false;
  }
  if ($('address_street_address1').value.match(/\s\w/) == null) {
    settext('errors_search','Street address missing');
    return false;
  }
  // ==================================
  // departure day|arrival day
  // ==================================
  if ($('tofrom').value == 'oneway') {
    if ($('search_service_type').value == 'to_airport') {
      // To Airport
      if ($('search_departure_day').value == '') {
        settext('errors_search','You must enter a departure day');
        return false;
      } else {
        settext('errors_search','');
      }
    } else {
      // From Airport
      if ($('search_arrival_day').value == '') {
        settext('errors_search','You must enter an arrival day');
        return false;
      } else {
        settext('errors_search','');
      }
    }
  } else {
    // Roundtrip
    if ($('search_service_type').value == 'to_airport') {
      // To Airport
      if ($('search_departure_day').value == '') {
        settext('errors_search','You must enter a departure day');
        return false;
      } else {
        settext('errors_search','');
      }
    } else {
      // From Airport
      if ($('search_arrival_day').value == '') {
        settext('errors_search','You must enter an arrival day');
        return false;
      } else {
        settext('errors_search','');
      }
    }
    // Return
    if ($('search_return_day').value == '') {
      settext('errors_search','You must enter an arrival day');
      return false;
    } else {
      settext('errors_search','');
    }
  }
  settext('errors_search','');
  loadingScreenFQ();
}

// ==================================================
// Function: verifyFareQuoteLandmarkSearch()
// Purpose: verifies input parameters for search
// ==================================================
function verifyFareQuoteLandmarkSearch() {
  // ==================================
  // departure day|arrival day
  // ==================================
  if ($('tofrom').value == 'oneway') {
    if ($('search_service_type').value == 'to_airport') {
      // To Airport
      if ($('search_departure_day').value == '') {
        settext('errors_search','You must enter a departure day');
        return false;
      } else {
        settext('errors_search','');
      }
    } else {
      // From Airport
      if ($('search_arrival_day').value == '') {
        settext('errors_search','You must enter an arrival day');
        return false;
      } else {
        settext('errors_search','');
      }
    }
  } else {
    // Roundtrip
    if ($('search_service_type').value == 'to_airport') {
      // To Airport
      if ($('search_departure_day').value == '') {
        settext('errors_search','You must enter a departure day');
        return false;
      } else {
        settext('errors_search','');
      }
    } else {
      // From Airport
      if ($('search_arrival_day').value == '') {
        settext('errors_search','You must enter an arrival day');
        return false;
      } else {
        settext('errors_search','');
      }
    }
    // Return
    if ($('search_return_day').value == '') {
      settext('errors_search','You must enter an arrival day');
      return false;
    } else {
      settext('errors_search','');
    }
  }
  //settext('errors_search','');
  loadingScreenFQ();
}
// ==================================================
// Function: verifyRateSelected()
// Purpose: verifies at least one radio rate is selected
// ==================================================
function verifyRateSelected() {
  for (var i=0; i < document.rate_select_form.rate_id.length; i++) {
    if (document.rate_select_form.rate_id[i].checked) {
      settext('errors_select_rate','');
      return true;
    }
  }
  settext('errors_select_rate','Please select at least one rate.');
  return false;
}
// ==================================================
// Function getChecked(id)
// Purpose: this will return the checked checkbox 
// ==================================================
function getChecked(id) {
  var retval = false;
  //safe function to hide an element with a specified id
  if (document.getElementById) { // DOM3 = IE5, NS6
    if (document.getElementById(id)) {
      retval = document.getElementById(id).checked;
    }
  }
  else {
    if (document.layers) { // Netscape 4
      retval = document.id.checked;
    }
    else { // IE 4
      retval = document.all.id.checked;
    }
  }
  return retval;
}

// ==================================================
// Function: hidediv()
// Purpose: hides div tag
// ==================================================
function hidediv(id) {
  //safe function to hide an element with a specified id
  if (document.getElementById) { // DOM3 = IE5, NS6
    // check if element exists first
    if (document.getElementById(id) != null) {
      document.getElementById(id).style.display = 'none';
    }
  }
  else {
    if (document.layers) { // Netscape 4
      document.id.display = 'none';
    }
    else { // IE 4
      document.all.id.style.display = 'none';
    }
  }
}
// ==================================================
// Function: showdiv()
// Purpose: shows div tag
// ==================================================
function showdiv(id) {
  //safe function to show an element with a specified id
		  
  if (document.getElementById) { // DOM3 = IE5, NS6
    // check if element exists first
    if (document.getElementById(id) != null) {
      document.getElementById(id).style.display = 'block';
    }
  }
  else {
    if (document.layers) { // Netscape 4
      document.id.display = 'block';
    }
    else { // IE 4
      document.all.id.style.display = 'block';
    }
  }
}
// ==================================================
// Function: settext()
// Purpose: writes text within the span element
// ==================================================
function settext(id,msg) {
  document.getElementById(id).innerHTML = msg;
}

// ==================================================
// Function: loadingScreen()
// Purpose: hides all elements and displays loading
// ==================================================
function loadingScreen() {
  hidediv('header');
  hidediv('menuBar');
  hidediv('bottom');
  hidediv('instructions');
        
  // added to remove affiliate logos
  hidediv('footTitle');
  hidediv('footContent');
  hidediv('footer');
    
  hidediv('formarea');
  showdiv('loading_page');
}
// ==================================================
// Function: loadingScreenFQ()
// Purpose: hides all elements and displays loading
//          for FareQuote screen
// ==================================================
function loadingScreenFQ() {
  // update the airport name on the loading_page
  var airport_name = $('hidden_airport_name').value;
  document.getElementById("airport_name").innerHTML = airport_name;
	
  // layout divs
  hidediv('loading');
  hidediv('header');
  hidediv('menuBar');
  hidediv('bottom');
  hidediv('instructions');


  hidediv('footTitle');
  hidediv('footContent');
  hidediv('footer');

  hidediv('fq_title');
  hidediv('leftResults');
  showdiv('loading_page');
}
// ==================================================
// Function: searchScreen()
// Purpose: hides loading screen and displays search
// ==================================================
function searchScreen() {
  hidediv('loading_page');
    
  showdiv('header');
  showdiv('menuBar');
  showdiv('bottom');
  showdiv('instructions');
        
  showdiv('footTitle');
  showdiv('footContent');
  showdiv('footer');
    
  showdiv('formarea');
    
}
//====================================================
//Change pickup/dropoff tags
//====================================================
function ttag() {
  $('DTag').update('Pickup location');
}
function ftag() {
  $('DTag').update('Destination');
}
 

function clearText(thefield){
  if (thefield.defaultValue==thefield.value)
    thefield.value = ""
}
//==========================================================
//Function: isNmb
//Purpose: Block non-numeric values from inputs
//==========================================================
function isNmb(evt)
{
  var charCode = (evt.which) ? evt.which : evt.keyCode
  if (charCode > 31 && (charCode < 48 || charCode > 57))
    return false;

  return true;
}

function setFormZip(){
  $('fare_quote_city').value = 'City';
}
function setFormCity(){
  $('fare_quote_zip_code').value = 'zip code';
}
//================================================================================================
//This piece of code hides the javascript error messages for live server, comment for development
//================================================================================================
function noError(){return true;}
window.onerror = noError;

var Prototip={Version:"1.2.1",REQUIRED_Prototype:"1.6.0.2",REQUIRED_Scriptaculous:"1.8.1",start:function(){this.require("Prototype");Tips.initialize();Element.observe(window,"unload",this.unload);},require:function(A){if((typeof window[A]=="undefined")||(this.convertVersionString(window[A].Version)<this.convertVersionString(this["REQUIRED_"+A]))){throw ("Lightview requires "+A+" >= "+this["REQUIRED_"+A]);}},convertVersionString:function(A){var B=A.replace(/_.*|\./g,"");B=parseInt(B+"0".times(4-B.length));return A.indexOf("_")>-1?B-1:B;},capture:function(A){if(!Prototype.Browser.IE){A=A.wrap(function(D,C){var B=C.relatedTarget,E=C.currentTarget;if(B&&B.nodeType==Node.TEXT_NODE){B=B.parentNode;}if(B&&B!=E&&B.descendantOf&&!(B.descendantOf(E))){D(C);}});}return A;},unload:function(){Tips.removeAll();}};var Tips={closeButtons:false,zIndex:1200,tips:[],visible:[],initialize:function(){this.zIndexTop=this.zIndex;},useEvent:(function(A){return{mouseover:(A?"mouseenter":"mouseover"),mouseout:(A?"mouseleave":"mouseout"),mouseenter:(A?"mouseenter":"mouseover"),mouseleave:(A?"mouseleave":"mouseout")};})(Prototype.Browser.IE),fixIE:(function(B){var A=new RegExp("MSIE ([\\d.]+)").exec(B);return A?(parseFloat(A[1])<7):false;})(navigator.userAgent),add:function(A){this.tips.push(A);},remove:function(A){var B=this.tips.find(function(C){return C.element==$(A);});if(B){B.deactivate();if(B.tooltip){B.wrapper.remove();if(Tips.fixIE){B.iframeShim.remove();}}this.tips=this.tips.without(B);}},removeAll:function(){this.tips.each(function(A){this.remove(A.element);}.bind(this));},raise:function(B){if(B.highest){return ;}if(this.visible.length==0){this.zIndexTop=this.zIndex;for(var A=0;A<this.tips.length;A++){this.tips[A].wrapper.style.zIndex=this.zIndex;}}B.style.zIndex=this.zIndexTop++;for(var A=0;A<this.tips.length;A++){this.tips[A].wrapper.highest=false;}B.highest=true;},addVisibile:function(A){this.removeVisible(A);this.visible.push(A);},removeVisible:function(A){this.visible=this.visible.without(A);}};Tips.initialize();var Tip=Class.create({initialize:function(A,B){this.element=$(A);Tips.remove(this.element);this.content=B;var D=(arguments[2]&&arguments[2].hook);var C=(arguments[2]&&arguments[2].showOn=="click");this.options=Object.extend({className:"default",closeButton:Tips.closeButtons,delay:!C?0.2:false,duration:0.3,effect:false,hideAfter:false,hideOn:"mouseleave",hook:false,offset:D?{x:0,y:0}:{x:16,y:16},fixed:D?true:false,showOn:"mousemove",target:this.element,title:false,viewport:D?false:true},arguments[2]||{});this.target=$(this.options.target);this.setup();if(this.options.effect){Prototip.require("Scriptaculous");this.queue={position:"end",limit:1,scope:this.wrapper.identify()};}Tips.add(this);this.activate();},setup:function(){this.wrapper=new Element("div",{className:"prototip"}).setStyle({display:"none",zIndex:Tips.zIndex});this.wrapper.identify();if(Tips.fixIE){this.iframeShim=new Element("iframe",{className:"iframeShim",src:"javascript:false;",frameBorder:0}).setStyle({display:"none",zIndex:Tips.zIndex-1});}this.tip=new Element("div",{className:"content"}).insert(this.content);this.tip.insert(new Element("div").setStyle({clear:"both"}));if(this.options.closeButton||(this.options.hideOn.element&&this.options.hideOn.element=="closeButton")){this.closeButton=new Element("a",{href:"#",className:"close"});}},build:function(){if(Tips.fixIE){document.body.appendChild(this.iframeShim).setOpacity(0);}var D="wrapper";if(this.options.effect){this.effectWrapper=this.wrapper.appendChild(new Element("div",{className:"effectWrapper"}));D="effectWrapper";}this.tooltip=this[D].appendChild(new Element("div",{className:"tooltip "+this.options.className}));if(this.options.title||this.options.closeButton){this.toolbar=this.tooltip.appendChild(new Element("div",{className:"toolbar"}));this.title=this.toolbar.appendChild(new Element("div",{className:"title"}).update(this.options.title||" "));}this.tooltip.insert(this.tip);document.body.appendChild(this.wrapper);var A=(this.options.effect)?[this.wrapper,this.effectWrapper]:[this.wrapper];if(Tips.fixIE){A.push(this.iframeShim);}var C=this.wrapper.getWidth();A.invoke("setStyle",{width:C+"px"});if(this.toolbar){this.wrapper.setStyle({visibility:"hidden"}).show();this.toolbar.setStyle({width:this.toolbar.getWidth()+"px"});this.wrapper.hide().setStyle({visibility:"visible"});}if(this.closeButton){this.title.insert({top:this.closeButton}).insert(new Element("div").setStyle({clear:"both"}));}var B=this.wrapper.getHeight();A.invoke("setStyle",{width:C+"px",height:B+"px"});this[this.options.effect?D:"tooltip"].hide();},activate:function(){this.eventShow=this.showDelayed.bindAsEventListener(this);this.eventHide=this.hide.bindAsEventListener(this);if(this.options.fixed&&this.options.showOn=="mousemove"){this.options.showOn="mouseover";}if(this.options.showOn==this.options.hideOn){this.eventToggle=this.toggle.bindAsEventListener(this);this.element.observe(this.options.showOn,this.eventToggle);}var C={element:this.eventToggle?[]:[this.element],target:this.eventToggle?[]:[this.target],tip:this.eventToggle?[]:[this.wrapper],closeButton:[],none:[]};var A=this.options.hideOn.element;this.hideElement=A||(!this.options.hideOn?"none":"element");this.hideTargets=C[this.hideElement];if(!this.hideTargets&&A&&Object.isString(A)){this.hideTargets=this.tip.select(A);}var D={mouseenter:"mouseover",mouseleave:"mouseout"};$w("show hide").each(function(H){var G=H.capitalize();var F=(this.options[H+"On"].event||this.options[H+"On"]);this[H+"Action"]=F;if(["mouseenter","mouseleave","mouseover","mouseout"].include(F)){this[H+"Action"]=(Tips.useEvent[F]||F);this["event"+G]=Prototip.capture(this["event"+G]);}}.bind(this));if(!this.eventToggle){this.element.observe(this.options.showOn,this.eventShow);}if(this.hideTargets){this.hideTargets.invoke("observe",this.hideAction,this.eventHide);}if(!this.options.fixed&&this.options.showOn=="click"){this.eventPosition=this.position.bindAsEventListener(this);this.element.observe("mousemove",this.eventPosition);}this.buttonEvent=this.hide.wrap(function(F,E){E.stop();F(E);}).bindAsEventListener(this);if(this.closeButton){this.closeButton.observe("click",this.buttonEvent);}if(this.options.showOn!="click"&&(this.hideElement!="element")){this.eventCheckDelay=Prototip.capture(function(){this.clearTimer("show");}).bindAsEventListener(this);this.element.observe(Tips.useEvent.mouseout,this.eventCheckDelay);}var B=[this.element,this.wrapper];this.activityEnter=Prototip.capture(function(){Tips.raise(this.wrapper);this.cancelHideAfter();}).bindAsEventListener(this);this.activityLeave=Prototip.capture(this.hideAfter).bindAsEventListener(this);B.invoke("observe",Tips.useEvent.mouseover,this.activityEnter);B.invoke("observe",Tips.useEvent.mouseout,this.activityLeave);},deactivate:function(){if(this.options.showOn==this.options.hideOn){this.element.stopObserving(this.options.showOn,this.eventToggle);}else{this.element.stopObserving(this.options.showOn,this.eventShow);if(this.hideTargets){this.hideTargets.invoke("stopObserving");}}if(this.eventPosition){this.element.stopObserving("mousemove",this.eventPosition);}if(this.closeButton){this.closeButton.stopObserving();}if(this.eventCheckDelay){this.element.stopObserving("mouseout",this.eventCheckDelay);}this.wrapper.stopObserving();this.element.stopObserving(Tips.useEvent.mouseover,this.activityEnter);this.element.stopObserving(Tips.useEvent.mouseout,this.activityLeave);},showDelayed:function(A){if(!this.tooltip){this.build();}this.position(A);if(this.wrapper.visible()){return ;}this.clearTimer("show");this.showTimer=this.show.bind(this).delay(this.options.delay);},clearTimer:function(A){if(this[A+"Timer"]){clearTimeout(this[A+"Timer"]);}},show:function(){if(this.wrapper.visible()&&this.options.effect!="appear"){return ;}if(Tips.fixIE){this.iframeShim.show();}Tips.addVisibile(this.wrapper);this.wrapper.show();if(!this.options.effect){this.tooltip.show();}else{if(this.activeEffect){Effect.Queues.get(this.queue.scope).remove(this.activeEffect);}this.activeEffect=Effect[Effect.PAIRS[this.options.effect][0]](this.effectWrapper,{duration:this.options.duration,queue:this.queue});}},hideAfter:function(A){if(!this.options.hideAfter){return ;}this.cancelHideAfter();this.hideAfterTimer=this.hide.bind(this).delay(this.options.hideAfter);},cancelHideAfter:function(){if(this.options.hideAfter){this.clearTimer("hideAfter");}},hide:function(){this.clearTimer("show");if(!this.wrapper.visible()){return ;}if(!this.options.effect){if(Tips.fixIE){this.iframeShim.hide();}this.tooltip.hide();this.wrapper.hide();Tips.removeVisible(this.wrapper);}else{if(this.activeEffect){Effect.Queues.get(this.queue.scope).remove(this.activeEffect);}this.activeEffect=Effect[Effect.PAIRS[this.options.effect][1]](this.effectWrapper,{duration:this.options.duration,queue:this.queue,afterFinish:function(){if(Tips.fixIE){this.iframeShim.hide();}this.wrapper.hide();Tips.removeVisible(this.wrapper);}.bind(this)});}},toggle:function(A){if(this.wrapper&&this.wrapper.visible()){this.hide(A);}else{this.showDelayed(A);}},position:function(A){Tips.raise(this.wrapper);var E={left:this.options.offset.x,top:this.options.offset.y};var F=Position.cumulativeOffset(this.target);var B=this.wrapper.getDimensions();var I={left:(this.options.fixed)?F[0]:Event.pointerX(A),top:(this.options.fixed)?F[1]:Event.pointerY(A)};I.left+=E.left;I.top+=E.top;if(this.options.hook){var K={target:this.target.getDimensions(),tip:B};var L={target:Position.cumulativeOffset(this.target),tip:Position.cumulativeOffset(this.target)};for(var H in L){switch(this.options.hook[H]){case"topRight":L[H][0]+=K[H].width;break;case"topMiddle":L[H][0]+=(K[H].width/2);break;case"rightMiddle":L[H][0]+=K[H].width;L[H][1]+=(K[H].height/2);break;case"bottomLeft":L[H][1]+=K[H].height;break;case"bottomRight":L[H][0]+=K[H].width;L[H][1]+=K[H].height;break;case"bottomMiddle":L[H][0]+=(K[H].width/2);L[H][1]+=K[H].height;break;case"leftMiddle":L[H][1]+=(K[H].height/2);break;}}I.left+=-1*(L.tip[0]-L.target[0]);I.top+=-1*(L.tip[1]-L.target[1]);}if(!this.options.fixed&&this.element!==this.target){var C=Position.cumulativeOffset(this.element);I.left+=-1*(C[0]-F[0]);I.top+=-1*(C[1]-F[1]);}if(!this.options.fixed&&this.options.viewport){var J=document.viewport.getScrollOffsets();var G=document.viewport.getDimensions();var D={left:"width",top:"height"};for(var H in D){if((I[H]+B[D[H]]-J[H])>G[D[H]]){I[H]=I[H]-B[D[H]]-2*E[H];}}}var M={left:I.left+"px",top:I.top+"px"};this.wrapper.setStyle(M);if(Tips.fixIE){this.iframeShim.setStyle(M);}}});Prototip.start();
