// JavaScript Document
var cmMonthArray = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
$(document).ready(function(){
			  
  //Start JQuery Code

  $(".logo").click(function () { 
      xt_med('C', '2', 'Mondial Logo', 'A');
  });
 
										
  $("#departing_date1").change(function(){ 
	if(isDate($("#departing_date1").val())) {	
	 if($("#homeGroupID").val() == '12' || $("#homeGroupID").val() == '13' || $("#homeGroupID").val() == '24' || $("#homeGroupID").val() == '25') {
	 var returnDate = new Date();
	 var tmp = $("#departing_date1").val().split(".");
	 var day = tmp[0];
	 var month = tmp[1]-1;
	 var year = parseInt(tmp[2]);	 
	 returnDate.setMonth(month);
	 returnDate.setFullYear(year);
     returnDate.setDate(day*1+364);	 
	 day = returnDate.getDate();
	 month = returnDate.getMonth()*1+1;
	 year = returnDate.getFullYear();	 
	 if(day < 10) {
	  day = '0'+day; 
	 }
	 if(month < 10) {
	  month = '0'+month; 
	 }	
	 var formattedReturnDate = day+'.'+month+'.'+year;	
	 $("#returning_date1").val(formattedReturnDate);	 
	}
	}
  });
  
  // handles home page form
 $("#homeGroupID").change(function(){
  setDateDisplay($(this).val());
 }); 
 
 $("#leftNavigationQuoteForm").submit(function() {
  if($('#leftNavGroupID').val() == '999') {
   xt_med('C', '2', 'Start Quote Left Navigation', 'S');	  
   window.open('https://www2.elviab2b.de/HPModulGruppen/Bild1Gru.faces?AN=NLD999');
   return false;
  }
  else {
   xt_med('C', '2', 'Start Quote Left Navigation', 'A');	  
   return true;	 
  }
 });
 
 $("#homepageQuoteForm").submit(function() {
  if($('#homeGroupID').val() == '999') {
   xt_med('C', '2', 'Start Quote', 'S');
   window.open('https://www2.elviab2b.de/HPModulGruppen/Bild1Gru.faces?AN=NLD999');	 	
   return false;
  }
  else {
   xt_med('C', '2', 'Start Quot Home Page', 'A');	  
   return true;	 
  }
 });
 
        //Email/Thickbox Loading - Added 7/16/09 */
	if(!$.browser.opera){
		$(window).load(function(){
		  $("#printemail a.thickbox").css("display","inline");
		});
	} else {
		  $("#printemail a.thickbox").css("display","inline");		
	};
	
	//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();
	});	
	
	/*$("#leftNavStartQuote").click(function(){
										
		$(this).parents("form").submit();
	});
	
	$("#homepagestartquote").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;
		}
	);


	//Calendars - Changed 6/4/09
	
	//Initization
	
	/* German initialisation for the jQuery UI date picker plugin. */
	/* Written by Milian Wolff (mail@milianw.de). */
	jQuery(function($){
		$.datepicker.regional['de'] = {
			clearText: 'l&#246;schen', clearStatus: 'aktuelles Datum l&#246;schen',
			closeText: 'schlie&#223;en', closeStatus: 'ohne &#196;nderungen schlie&#223;en',
			prevText: '&#x3c;zur&#252;ck', prevStatus: 'letzten Monat zeigen',
			prevBigText: '&#x3c;&#x3c;', prevBigStatus: '',
			nextText: 'Vor&#x3e;', nextStatus: 'n&#228;chsten Monat zeigen',
			nextBigText: '&#x3e;&#x3e;', nextBigStatus: '',
			currentText: 'heute', currentStatus: '',
			monthNames: ['Januar','Februar','M&#228;rz','April','Mai','Juni',
			'Juli','August','September','Oktober','November','Dezember'],
			monthNamesShort: ['Jan','Feb','M&#228;r','Apr','Mai','Jun',
			'Jul','Aug','Sep','Okt','Nov','Dez'],
			monthStatus: 'anderen Monat anzeigen', yearStatus: 'anderes Jahr anzeigen',
			weekHeader: 'Wo', weekStatus: 'Woche des Monats',
			dayNames: ['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'],
			dayNamesShort: ['So','Mo','Di','Mi','Do','Fr','Sa'],
			dayNamesMin: ['So','Mo','Di','Mi','Do','Fr','Sa'],
			dayStatus: 'Setze DD als ersten Wochentag', dateStatus: 'W&#228;hle D, M d',
			dateFormat: 'dd.mm.yy', firstDay: 1,
			initStatus: 'W&#228;hle ein Datum', isRTL: false};
	});

	var lang = "de";
	if ($("html").attr("lang") != "de") lang = $("html").attr("lang");
	
	$.datepicker.setDefaults($.datepicker.regional[lang]); //Default is German
	$.datepicker.setDefaults({ 
		showOn: 'button', 
		buttonImage: 'files/images/icons/icon-calendar.gif', 
		buttonImageOnly: true,
		numberOfMonths: 2,
		showButtonPanel: true,
		firstDay: 1,
		constrainInput: false
	});
   	
	//Calendar Calls - Changed 6/4/09
	if ($("body").attr("class") == "homepage") {
		$("#departing_date1").datepicker();
		$("#returning_date1").datepicker();	
	};
	
	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: 404 });
		     $(".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");					
		});	


		$("#article .gruppenschutz tbody tr").hover(function() { /* Added 7/8/09 */	
				$(this).children("td").css("background","transparent none");	
				$(this).children("td").css("border-right","none");
				$(this).children("th").css("background","transparent none");	
				$(this).children("th").css("border-right","none");				
			},function() {		
				$(this).children("td").css("background","transparent none");	
				$(this).children("td").css("border-right","none");	
				$(this).children("th").css("background","transparent none");		
				$(this).children("th").css("border-right","none");					
		});				
													  
	};	
	
	//Old Gecko/Firefox 2 hack
	if ($.browser.mozilla && (parseFloat($.browser.version) < 1.9)) {
		
		//Product Tables
		$(".coveragedetails table.triple td").css("width","20%")
	
		//Sidenav/German Names
		$("#sidenav dd a, .package, .coveragedetails tbody th, #sidebar .policyselection h3 span").each(function (i) {
			var link = $(this).html().replace(/-/g,"-<wbr>");
			$(this).html(link);
		});			
	};

	
	//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 - Changed 7/13/09 */
	var t;
	
	$("label a.helptips").mouseover(function(e) {		
			x = e.pageX-201;		
			$(this).parent().siblings("div.helpwindow").css("left", x + "px");				
	});
	
	$("label a.helptips").mouseout(function(e) {		
			t = setTimeout("closeHelpWindow()", 300);				
	});	

	$("div.helpwindow").hover(function(e){		
			clearTimeout(t);
		},function() {		
			t = setTimeout("closeHelpWindow()", 300);			
	});	
	
	$("#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;
});
	
	setDateDisplay($("#homeGroupID").val());	
	
//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;
}

function closeHelpWindow() {
  $("div.helpwindow").css("left", "-9999px");			
}

function isDate(dateStr) {
 var tmp = dateStr.split(".");  
 if(tmp.length != 3) {
  return false; 
 }
 else {	 
  var month = tmp[1]-1;  
  var day = tmp[0]; 
  var year = tmp[2];	 
  if(isValidDate(month,day,year) != true) {	
    if(isValidDay(day, month)) {
	 return true;	
	}
	else {
     return false;
	}	   
  }
  else {
	return true;  
  }
 } 	
}

function isValidDate(month,day,year) { 
 if(year < 1900 || year > 9999 || isNaN(year)) { 
  return 'year';
 }
 if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) {	
  cmMonthArray[1] = "29";
 }  
 if(month < 1 || month > 12 || isNaN(month)) { 
  return 'month';
 } 
 if(day < 1 || day > cmMonthArray[(month-1)] || isNaN(day)) {  
  return 'day';
 }
 //alert(cmMonthArray[(month-1)]);
 return true;
}

function isValidDay(day, month) {	
 if(isNaN(day) || day < 1 || day > cmMonthArray[month]) {  
  return false;
 }
 return true;
}


function setDateDisplay(groupID) {	
  switch(parseInt(groupID)) {
	 case 12:
	 $('label[for=departing_date1]').html('Starting'); 
	 $('label[for=returning_date1]').html('Ending');
	 $('img.ui-datepicker-trigger').eq(1).css('display','none');
	 $("#departing_date1").val('TT.MM.JJJJ');
	 $("#returning_date1").val('TT.MM.JJJJ');
	 break;
	 case 13:
	 $('label[for=departing_date1]').html('Starting');
	 $('label[for=returning_date1]').html('Ending');
	 $('img.ui-datepicker-trigger').eq(1).css('display','none');
	 $("#departing_date1").val('TT.MM.JJJJ');
	 $("#returning_date1").val('TT.MM.JJJJ');
	 break;
	 case 24:
	 $('label[for=departing_date1]').html('Versicherungsbeginn');
	 $('label[for=returning_date1]').html('Versicherungsende');
	 $('#returning_date1').removeClass('hasDatepicker');
	 $('img.ui-datepicker-trigger').eq(1).css('display','none');
	 $("#departing_date1").val('TT.MM.JJJJ');
	 $("#returning_date1").val('TT.MM.JJJJ');
	 break;
	 case 25:
	 $('label[for=departing_date1]').html('Versicherungsbeginn');
	 $('label[for=returning_date1]').html('Versicherungsende');	 
	 $('img.ui-datepicker-trigger').eq(1).css('display','none');
	 $("#departing_date1").val('TT.MM.JJJJ');
	 $("#returning_date1").val('TT.MM.JJJJ');	 
	 break;
	 default:
	 $('label[for=departing_date1]').html('Reisebeginn');
	 $('label[for=returning_date1]').html('Reiseende');
	 $('img.ui-datepicker-trigger').eq(1).css('display','inline');
	 break;
   }	
}