﻿(function($){

  //----------------------------------    
  // When document loads or AJAX reloads
  //----------------------------------
  $(document_ready);
  function document_ready(){

    //----------------------------------    
    // Decrypt emails
    //----------------------------------
    $("a[href^='mailto']").each(function(){
      var lnk=$(this).attr("href");
      $(this).html($(this).html().replace(/^(mailto:)(.+):([^\?]+)(\?.+)?$/i,"$3@$2$4"));    
      $(this).attr("href",lnk.replace(/^(mailto:)(.+):([^\?]+)(\?.+)?$/i,"$1$3@$2$4"));
    });

    //----------------------------------    
    // Clear/replace search
    //----------------------------------    
    $("#search .query").focusin(function(){ $(this).val(''); })
      .focusout(function(){ if($(this).val()=='')$(this).val('Search'); });
    
    //----------------------------------    
    // Superfish adjustments
    //----------------------------------    
    $(".sf-menu").each(function(){
      $(this).find("a[href^='http']").attr("target","_blank");
    });

    //----------------------------------    
    // Other adjustments
    //----------------------------------    
    $(".calendar-control").attr("title","");     
    $(".column .column-panel:first").css({marginTop:0});
  }
  
  //----------------------------------    
  // When window is loaded
  // Handle validator resizes
  // and update .Net Ajax reloads
  //----------------------------------  
  $(window).load(function(){
    window_load();
    try {
      Sys.WebForms.PageRequestManager.getInstance().add_endRequest(window_load);
      Sys.WebForms.PageRequestManager.getInstance().add_endRequest(document_ready);
    } catch(e) {}
  });
    
})(jQuery);

//----------------------------------    
// After initial load and AJAX updates,
// make sure columns are equal sized
//----------------------------------
function window_load(){
  var max = 0;
  var uneven = false;
  jQuery('.even-height .column').each(function(){
    $(this).find('.content:last').css({height:'auto'});
    var h=$(this).outerHeight();
    if (max>0 && h!=max) uneven=true;
    if (h>max) max=h;
  });
  if (uneven) jQuery('.even-height .column').each(function(){
    var oh=$(this).outerHeight();
    var cnt=$(this).find('.content:last');
    cnt.height(cnt.height()+max-oh);
  });
}

// Function to create a popup window
//
var popupwin=null;
function popup(url,options) {
   if (!options) options="width=610,height=500,scrollbars=yes,resizable=yes";
   popupwin = window.open(url,"popupwin",options);
   popupwin.focus();
   return false;
}

//
// Toggle layer on/off
//
function toggleFeature(elm){
   var currobj=document.getElementById(currfeature);
   currfeature = elm;
   var obj=document.getElementById(currfeature);
   if (currobj) currobj.style.display = "none";
   if (obj) obj.style.display="";
   window_load();
   return false;
}

//
// Seat Selector
//
var sswin,sscontrol,ssbutton;
function SeatSelectorOpen(url,control,button) {
    // Get reference to control, button, and radio
    sscontrol=document.getElementById(control);
    ssbutton=button;                             
    if (!sscontrol||!ssbutton) return false;    
    // Open seat selector
    sswin=window.open('/orders/seatselector.aspx?'+url,"sswin",
        'width=502,height=472,directories=0,location=0,menubar=0,'+
        'resizable=0,scrollbars=0,status=0,titlebar=0');
    sswin.focus();
    return false;
}
function SeatSelectorUpdate(command,args) {
    // Store the values
    if (command=='update') {
        sscontrol.value=args;
        setTimeout("SeatSelectorPostback()",500);
    }    
}
function SeatSelectorPostback() {
    __doPostBack(ssbutton,'');
}