// JavaScript Document
var formHasBeenSubmitted=false;
var dateMaskStr = 'DD/MM/YYYY';
$(document).ready(function(){
//Start JQuery Code

  //Button Hovers
/*  $(".submit, img.help").hover(  
    function() {      
      off_img = $(this).attr("src");      
      over_img = off_img.replace("off/","on/");                                      
      $(this).attr("src", over_img);    
    },    
    function() {    
      $(this).attr("src", off_img);
    }
  );*/

    $(".logo").click(function () {
      xt_med('C', '2', 'Mondial Logo', 'A');
    });


    $("#homeGroupID").change(function(){               
    switch(parseInt($(this).val())) {
     case 32:
     $('label[for=departing_date1]').text('Start Date');
        $('#returnDateContainer').css('display','none');
     break;
     case 252:
     $('label[for=departing_date1]').text('Start Date');
        $('#returnDateContainer').css('display','none');
     break;   
    default:
     $('label[for=departing_date1]').text('Departing');
     $('#returnDateContainer').css('display','block');
    break;
    }
     });
  
  //Submit Button Hide - Changed 6/7/09
  $(":submit").addClass("hide");  
  if ($.browser.mozilla && (parseFloat($.browser.version) < 1.9)) {
    $("span.submit").css("display","-moz-inline-box");  
  } else {
    $("span.submit").css("display","inline-block");      
  };

  //Outside Links
  $("span.submit").click(function(){
    $(this).parents("form").submit();
  });  
  
  //Outside Links
  $("a.target").click(function(){
    window.open($(this).attr("href"));
    return false;
  });  
  
  //Coverage Options
  $("ul.options li div").addClass("hide");

  $("ul.options li a").toggle(  
    function() {      
      $(this).parents("li").addClass("selected");
      $(this).parent().siblings("div").removeClass("hide");
      return false;      
    },    
    function() {    
      $(this).parents("li").removeClass("selected");
      $(this).parent().siblings("div").addClass("hide");
      return false;
    }
  );

  $.datepicker.setDefaults({
    showOn: 'button',
    buttonImage: '/files/images/icons/icon-calendar.gif',
    buttonImageOnly: true,
    numberOfMonths: 2,
    firstDay: 0,
    constrainInput: false,
    dateFormat: 'dd/mm/yy'
  });
  
  if($('#cms_language').text().toLowerCase() == 'fr') {   
  jQuery(function($){
     $.datepicker.regional['fr'] = {
      clearText: 'Effacer', clearStatus: 'Effacer la date s&eacute;lectionn&eacute;e',
      closeText: 'Fermer', closeStatus: 'Fermer sans modifier',
      prevText: '&#x3c;Pr&eacute;c', prevStatus: 'Voir le mois pr&eacute;c&eacute;dent',
      prevBigText: '&#x3c;&#x3c;', prevBigStatus: '',
      nextText: 'Suiv&#x3e;', nextStatus: 'Voir le mois suivant',
      nextBigText: '&#x3e;&#x3e;', nextBigStatus: '',
      currentText: 'Courant', currentStatus: 'Voir le mois courant',
      monthNames: ['Janvier','F&eacute;vrier','Mars','Avril','Mai','Juin',
      'Juillet','Ao&ucirc;t','Septembre','Octobre','Novembre','D&eacute;cembre'],
      monthNamesShort: ['Jan','F&eacute;v','Mar','Avr','Mai','Jun',
      'Jul','Ao&ucirc;','Sep','Oct','Nov','D&eacute;c'],
      monthStatus: 'Voir un autre mois', yearStatus: 'Voir une autre ann&eacute;e',
      weekHeader: 'Sm', weekStatus: '',
      dayNames: ['Dimanche','Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi'],
      dayNamesShort: ['Dim','Lun','Mar','Mer','Jeu','Ven','Sam'],
      dayNamesMin: ['Di','Lu','Ma','Me','Je','Ve','Sa'],
      dayStatus: 'Utiliser DD comme premier jour de la semaine', dateStatus: '\'Choisir\' le DD d MM',
      dateFormat: 'dd/mm/yy', firstDay: 1,
      initStatus: 'Choisir la date', isRTL: false};
    $.datepicker.setDefaults($.datepicker.regional['fr']);
  });  
    dateMaskStr = 'JJ/MM/AAAA';
 }
     
  //Calendar Calls - Changed 6/4/09
  if ($("body").attr("class") == "homepage") {
    $("#departing_date1").datepicker();
    $("#returning_date1").datepicker();  
    $("#departing_date1").val(dateMaskStr);
  $("#returning_date1").val(dateMaskStr);
    
  };
  
  /*if ($("body").attr("class") == "purchase") {
    $("#departing_date").datepicker();
    $("#returning_date").datepicker();
    $("#deposit_date").datepicker();    
  };*/  
  
  
  //Sidebar Benefits
  $(".policyselection .coveragedetails").addClass("hide");  
  
  $("#tripinsured .coveragedetails").removeClass("hide");  
  $("#tripinsured .coveragedetails").siblings("a.viewbenefits").addClass("openbenefits");    
  
  $(".policyselection a.viewbenefits").toggle(  
    function() {      
      $(this).addClass("openbenefits");
      $(".policyselection .coveragedetails").removeClass("hide");
      return false;      
    },    
    function() {    
      $(this).removeClass("openbenefits");
      $(".policyselection .coveragedetails").addClass("hide");
      return false;
    }
  );  

  
  
  //IE6 Hacks
  if ($.browser.msie && (parseInt($.browser.version) == 6)) {

    $("table.producttable tr:first td").css("padding-top", "0");
    $("table.producttable tr:first td").css("border-top", "none");

    //Sidenav
    $("#sidenav dd").not(".selected").children("div").hover(function() {
        $(this).css("background","#ec2118 url(/files/images/backgrounds/bkg-sidenavhover_top.gif) no-repeat 0 0");  
        $(this).children("span").css("display","block");
      },function() {    
        $(this).css("background","#ffffff none");
        $(this).children("span").css("display","none");        
    });
    
    //Buttons
    $("#featured span.startquote").hover(function() {      
        $(this).children("span").css("color","#fce703");  
        $(this).css("background-position","100% -30px");
      },function() {    
        $(this).children("span").css("color","#ffffff");  
        $(this).css("background-position","100% 0");        
    });    
    
    $("#email span.startquote").hover(function() {      
        $(this).children("span").css("color","#fce703");  
        $(this).css("background-position","100% -30px");
      },function() {    
        $(this).children("span").css("color","#ffffff");  
        $(this).css("background-position","100% 0");        
    });    
    
    //Business Partners
    $("#header dl.partners").hover(function() {      
        $(this).css("border","1px solid #d8d8d8");
        $(this).css("border-top","none");
        $(this).css("padding-bottom","10px");
        $(this).css("overflow","visible");
        $(this).css("height","auto");
        $(this).css("margin-right","9px");
        $(this).css("background-image","url(/files/images/backgrounds/bkg-partners_dl.gif)");
      },function() {    
        $(this).css("border","none");  
        $(this).css("padding-bottom","0");
        $(this).css("overflow","hidden");
        $(this).css("height","28px");
        $(this).css("margin-right","10px");
        $(this).css("background-image","none");        
    });  
    
    $("#header dl.partners dd").hover(function() {      
        $(this).css("background-color","#f7cc23");  
      },function() {    
        $(this).css("background-color","transparent");
    });  
    
    //BgFix - IE6/z-index
          if ($("body").attr("class") == "purchase") {
         $(".helpwindow").bgiframe({ width: 202 });
         $(".benefits").bgiframe({ width: 522 });
                };

    //Product Table Hovers
    $("#article .coveragedetails tbody tr, #sidebar .coveragedetails tbody tr").not(".selection").hover(function() {      
        $(this).children("td").css("background","#ecc322 none");  
        $(this).children("td").css("border-right","2px solid #ecc322");
        $(this).children("th").css("background","#f7cc23 none");  
        $(this).children("th").css("border-right","2px solid #f7cc23");        
      },function() {    
        $(this).children("td").css("background","#f4f4f4 url(/files/images/backgrounds/bkg-tdcell.gif) repeat-x 0 100%");  
        $(this).children("td").css("border-right","2px solid #ffffff");  
        $(this).children("th").css("background","transparent url(/files/images/backgrounds/bkg-coverage_rowth.gif) repeat-x 0 100%");    
        $(this).children("th").css("border-right","2px solid #ffffff");          
    });      
                            
  };  
  
  //Old Gecko/Firefox 2 hack
  if ($.browser.mozilla && (parseFloat($.browser.version) < 1.9)) {
    
    //Product Tables
    $(".coveragedetails table.triple td").css("width","20%")
      
  };

  
  //Equal Height - Coverage Details Table Header
  var heights = new Array();  
  var heights2 = new Array();   
  var popular = false;
  
  //Top
  $(".coveragedetails thead p.package").each(function (i) {
    heights[i] = $(this).height();
  });  
    
  test = heights.sort(function(a,b){return b - a});
  $(".coveragedetails thead p.package").height(test[0]);
  
  //Bottom
  $(".coveragedetails tr.selection th span.package").each(function (i) {
    heights2[i] = $(this).height();
  });  
    
  test2 = heights2.sort(function(a,b){return b - a});
  $(".coveragedetails tr.selection th span.package").height(test2[0]);  
  
  //Equalize First Header Cell
  $(".coveragedetails thead th.first div").height($(".coveragedetails thead th:last div").not(".pricelist").height());
  
  //Popular Exception
  $(".coveragedetails thead th").each(function (i) {
    if($(this).attr("class").search("popular") > -1) popular = true;
  });    
  
  if (!popular) {
    $(".coveragedetails thead th.first span.theader span.thleft").css("top", "-3px");
    $(".coveragedetails thead th.first span.theaderbottom span.thleft").css("top", "3px");  
    $(".coveragedetails thead th.last span.theader span.thright").css("top", "-3px");
    $(".coveragedetails thead th.last span.theaderbottom span.thright").css("top", "3px");     
  };
  
  
  if($.browser.msie && popular){
    $(".coveragedetails thead th.first span.theader span.thleft").css("top", "-5px");
    $(".coveragedetails thead th.first span.theaderbottom span.thleft").css("top", "6px");
    
    if($(".coveragedetails thead th.last").attr("class").search("popular") < 0 ) {
      $(".coveragedetails thead th.last span.theader span.thright").css("top", "-5px");
      $(".coveragedetails thead th.last span.theaderbottom span.thright").css("top", "6px");
    };
  };
  
  //Purchase Process Breadcrumb - Due to lack of IE6 support - Added 6/2/09
  $("body.purchase #article ul#breadcrumb li:first span").css("background","transparent url(/files/images/lists/list-breadcrumb_standby_first.gif) no-repeat 0 0");  
  $("body.purchase #article ul#breadcrumb li:first.stepdone span").css("background","transparent url(/files/images/lists/list-breadcrumb_stepdone_first.gif) no-repeat 0 0");
  $("body.purchase #article ul#breadcrumb li:last.standby").css("background","#eeb40b url(/files/images/lists/list-breadcrumb_standby_last.gif) no-repeat 100% 0");

  
  //Benefits
  $(".coveragedetails tbody th a").hover(function() {      
      $(this).siblings(".benefits").css("left", "auto");
    },function() {    
      $(this).siblings(".benefits").css("left", "-9999px");      
  });  
  
  //Help Windows
  $("label a.helptips").hover(function(e) {    
      x = e.pageX-101;    
      $(this).parent().siblings("div.helpwindow").css("left", x + "px");
    },function() {    
      $(this).parent().siblings("div.helpwindow").css("left", "-9999px");      
  });    
  
  $("#featured label a.helptips").hover(function(e) {    
      x = e.pageX-101;    
      if ($.browser.msie && (parseInt($.browser.version) == 6)) x = e.pageX-565;/* IE6 Homepage only  */
      $(this).parent().siblings("div.helpwindow").css("left", x + "px");
    },function() {    
      $(this).parent().siblings("div.helpwindow").css("left", "-9999px");      
  });
  
  $("#selectlanguage a").click(function(){
    var contentID = getID($(this).attr('id'));
    var languageFull = $(this).attr('title');   
    var languageShort = getLanguageShort($(this).attr('id'));
    $.ajax({
        url: "/ajax/get/_getContentLink.cfm?contentID="+contentID+"&languageFull="+languageFull+"&languageShort="+languageShort,
        cache: false,
        async: false,
        success: function(html){
         var link = $.trim(html);
         window.location=link;   
        }
      });
      return false;
     });
  
  $(".sqcomparisongrid").click(function(){
  document.getElementById('prodoctComparisonForm').submit();
  return false;
});
  
//End JQuery Code
});

function getID(str) {
 var id = str.split("_");
 id=id[1];
 return id;
}  
   
function getLanguageShort(str) {
  var languageShort = str.split("_");
  languageShort=languageShort[2];
  return languageShort;
}
