// JavaScript Document
var formHasBeenSubmitted=false;
var x;       
x = setTimeout("ajaxPackage()", 1500); 
var expiresInDays = 1;

function ajaxPackage() {
                $("td[class!=selected] span.ajaxwait").css("display","none");     
                $("#packageselector div").css("display","block");              
}



$(document).ready(function(){
  
 if(document.getElementById('alert') && ! $.cookie('alertMessage')) {
    var content = $('#alertContainer').html();  
  $('#alertContainer').remove(); 
  
  $.nyroModalManual({     
     type: 'form',
     modal: false,
     content: content,
     minWidth: 635, // Minimum width
     minHeight: 505,
     width: 635,
     height: 505,
     resizable: false, // Indicate if the content is resizable. Will be set to false for swf
     autoSizable: false,
     padding: 0,
     endShowContent: bindEvents
  });  
 }      
 var internalQuoteUrl = $('#hpForm1').attr('action');               
  
  
  



    $(".logo").click(function () { 
      xt_med('C', '2', 'Mondial Logo', 'A');
    });


    $("#HPGroupID_1").change(function(){ 
       var groupID = $(this).val();      
      manageGauranteeType(groupID,1);  
    });
  
  $("#HPGroupID_2").change(function(){ 
       var groupID = $(this).val();      
      manageGauranteeType(groupID,2);  
    });
  
  $(".leftNavQuote").click(function(){
    var url = $('#groupID').val();
    if(!isNaN(url)) {
     $(this).parents("form").submit();  
      }
    else {
     window.location = url;  
    }
      return false;
    });
  
  $("span.hpquote").click(function(){  
        var id = $(this).parents("form").attr('id');
    var url = ''
    if(id == 'hpForm1') {
          url = $('#HPGroupID_1').val();      
    }
    else if(id == 'hpForm2') {
      url = $('#HPGroupID_2').val();  
    }
    else if(id == 'hpForm3') {
      url = $('#HPGroupID_3').val();  
    }
    else if(id == 'hpForm4') {
      url = $('#HPGroupID_4').val();  
    }    
    
    if(!isNaN(url)) {
     $(this).parents("form").attr('action',internalQuoteUrl);         
        }
      else {
     $(this).parents("form").attr('action',url);          
      }
    
    $(this).parents("form").submit();        
  });  
  
  //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:not(.externalQuote,.hpquote)").click(function(){                            
    if(!formHasBeenSubmitted) {    
     $(this).parents("form").submit();
    }
  });  
  
  //Outside Links
  $("a.target").click(function(){
    window.open($(this).attr("href"));
    return false;
  });

  //Homepage Intialization - Changed 11/5/09
  $("#roadside, #homefeatured, #retirement").addClass("hide");
  

  //Featured Selector- Added 10/14/09
  $("#featurednav a[id!=productlink]").click(function(){
              
    $("#featurednav li").each(function(){
      $(this).removeClass("selected");  
    });    

    var id = $(this).attr("href").replace("#","");
    
    $(this).parent().addClass("selected");
    
    $("#travel, #roadside, #homefeatured, #retirement").addClass("hide");                     
    $("#" + id).removeClass("hide");    
    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;
    }
  );  
     
  //Calendar Calls - Changed 10/14/09
  if (($("body").attr("class") == "homepage") || ($("body").attr("class") == "purchase")) {
    
    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']);
  });  
    
    $.datepicker.setDefaults({ 
    showOn: 'button', 
    buttonImage: 'files/images/icons/icon-calendar.gif', 
    buttonImageOnly: true,
    numberOfMonths: 2,
    constrainInput: false
  });

    if($("html").attr("lang") != "fr") $.datepicker.setDefaults($.datepicker.regional['']);    
    
    $("#departing_date1").datepicker();
    $("#returning_date1").datepicker();  
    
    $("#departing_date2").datepicker();
    $("#returning_date2").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");        
    });

    //Added 11/3/09 
    $(".enewsletter span.submit").hover(function() {      
        $(this).css("background-position","0 -22px");
        $(this).children("span").css("background-position","100% -22px");        
      },function() {    
        $(this).css("background-position","0 0");
        $(this).children("span").css("background-position","100% 0");            
    });    
    
    //Added 11/3/09     
    $("#search span.submit span").hover(function() {      
        $(this).css("color","#fce703");  
        $(this).css("background-position","100% -18px");
      },function() {    
        $(this).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
    if ($("body").attr("class") == "purchase") { //Changed 10/14/09 */  
      $("#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","#fff3cf none");  //Changed 2/24/10
          $(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%")
      
  };

  
  //Purchase Process Breadcrumb - Due to lack of IE6 support - Changed 11/10/09
  if ($("body").attr("class").search("purchase") > -1) {
    $("#article ul#breadcrumb li:first span").css("background","transparent url(/files/images/lists/list-breadcrumb_standby_first.gif) no-repeat 0 0");  
    $("#article ul#breadcrumb li:first.stepdone span").css("background","transparent url(/files/images/lists/list-breadcrumb_stepdone_first.gif) no-repeat 0 0");
    $("#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) {
                     //alert("got here");
      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(){
  if(document.getElementById('prodoctComparisonForm')) {
      document.getElementById('prodoctComparisonForm').submit();
    return false;
    }
});

  //Mondial France - Package Selector - Added 10/14/09
  if ($("body").attr("class") != "purchase") {
  
    $(".package_1, .package_2").addClass("hide");

    $("#packageselector div").click(function(){
      
      $("#packageselector span.selectorhr").remove();      
      $("#packageselector td").removeClass("selected");
      $(this).parent().addClass("selected");
      $(this).children("a").append("<span class=\"selectorhr\"></span>");
      
      $(".coveragedetails table[id!=packageselector]").addClass("hide");
      $("#packagecompare li").addClass("hide");    
      
      href = $(this).children("a").attr("href").split("_")[1];
      $(".coveragedetails table[id!=packageselector]").each(function(i){
        var test = "package_" + href;
        if (!$(this).attr("class").search(test)) {
          $(".package_" + i).removeClass("hide");        
        };
      });
      
      return false;
    });

  };
  
  
// Show-Hide Div Code for Contact page

  // choose text for the show/hide link)
  var showText='<img src=/files/images/buttons/Orange-More-Arrow.png>';
  var hideText='<img src=/files/images/buttons/Orange-Down-Arrow.png>';
  
  // initialise the visibility check
  var is_visible = false;
  
  // append show/hide links to the element directly preceding the element with a class of "toggle"
  //$('.toggle').prev().append(' <a href="#" class="toggleLink">'+showText+'</a>');
  $('a.toggleLink').append(' ' + showText);
  
  // hide all of the elements with a class of 'toggle'
  $('.toggle').hide();
  
  // capture clicks on the toggle links
  $('a.toggleLink').click(function() {
  
    //Remove showText/hideText images
    $(this).children("img").remove();
    
    // switch visibility
    if ($(this).attr("class").search("selected") == -1) { 
      //If not selected already, set to true and show hideText
      is_visible = true;
      $(this).addClass("selected");
    } else {
      //If selected already, set to false and show showText    
      is_visible = false;
      $(this).removeClass("selected");
    }
    
    // change the link depending on whether the element is shown or hidden
    $(this).append( (!is_visible) ? showText : hideText);
    
    // toggle the display - uncomment the next line for a basic "accordion" style
    //$('.toggle').hide();$('a.toggleLink').html(showText);
    $(this).parent().next('.toggle').toggle('slow');
    
    return false;
  
  });
  
  
  
//End JQuery Code
});

function manageGauranteeType(groupID,idx) {  
 var selectedVal = $("#gauranteeTypeID_"+idx).val();
 $("#gauranteeTypeID_"+idx).removeOption(/./); 
 $("#gauranteeTypeID_"+idx).addOption("1", "Assistance (rapatriement, frais medicaux, ...)");
 $("#gauranteeTypeID_"+idx).addOption("2", "Assurance (annulation, bagages, ...)");
 $("#gauranteeTypeID_"+idx).addOption("3", "Multirisque (Assistance + Assurance)"); 
  
 if(groupID == 64 || groupID == 78) { /*holiday*/ 
  $('#hpGauranteeTypeIDContainer_'+idx).css('display','block');     
 }
 else if(groupID == 65 || groupID == 81) { /*group*/
  $('#hpGauranteeTypeIDContainer_'+idx).css('display','block');   
 }
 else if(groupID == 77 || groupID == 66) { /*globe trotter*/
  $('#hpGauranteeTypeIDContainer_'+idx).css('display','block');  
  $("#gauranteeTypeID_"+idx).removeOption(2);
 }
 else if(groupID == 67 || groupID == 73) { /*business*/
  $('#hpGauranteeTypeIDContainer_'+idx).css('display','block');   
 }
 else if(groupID == 74 || groupID == 68) { /*shengen*/
  $('#hpGauranteeTypeIDContainer_'+idx).css('display','block');   
  $("#gauranteeTypeID_"+idx).removeOption(2);
 }
 else if(groupID == 69 || groupID == 76) { /*student*/
  $('#hpGauranteeTypeIDContainer_'+idx).css('display','block');   
 } 
 else if(groupID == 71 || groupID == 75) { /*sports*/  
 $('#hpGauranteeTypeIDContainer_'+idx).css('display','block');
  $("#gauranteeTypeID_"+idx).removeOption(2);
 }
 else {
  $('#hpGauranteeTypeIDContainer_'+idx).css('display','none');   
 } 
 $("#gauranteeTypeID_"+idx).val(selectedVal);  
}

function getID(str) {
 var id = str.split("_");
 id=id[1];
 return id;
}  
   
function getLanguageShort(str) {
  var languageShort = str.split("_");
  languageShort=languageShort[2];
  return languageShort;
}


function bindEvents() {
  
  $.cookie('alertMessage', 1,{expires: expiresInDays, path: '/' });   
  
$('#nyroModalWrapper').css('border','none');
   $('#nyroModalWrapper').css('background','transparent');
 $("#closewindow").click(function () { 
                   
    $.nyroModalRemove();
  return false;
  
 });
}


function getUID() {   
 var date = new Date(); 
 var UID = ''+date.getSeconds()+date.getMinutes()+date.getHours()+date.getDate()+date.getMonth()+date.getFullYear()+(Math.floor(Math.random()*10000)+1000);
 return UID;
}
