// JavaScript Document


var datefocus = "";

$(document).ready(function() {
    //Start JQuery Code

    //Submit Button Hide
    $("input[type='submit']").addClass("hide");
    if ($.browser.mozilla && (parseFloat($.browser.version) < 1.9)) {
        $("span.submitButton").css("display", "-moz-inline-box");
    } else {
        $("span.submitButton").css("display", "inline-block");
    };

    //Submit Buttons
    $("span.submitButton").click(function() {
        $(this).parents("form").submit();
        return true;
    });

    //Coverage Options List
    $(".tabselector .selector a").click(function() {
        var anchor = $(this).attr("href").replace("#", "");
        $(".tabselector .selector li").removeClass("selected");

        $(".tabselector .lister").addClass("hide");
        $(".tabselector #" + anchor).removeClass("hide");
        $(this).parent("li").addClass("selected");

        return false;
    });

    //Compare Table 
    $("#compareTable .selector a").click(function() {
        var anchor = $(this).attr("href").replace("#", "");
        $("#compareTable .selector li").removeClass("selected");

        $("#compareTable table").addClass("hide");
        $("#compareTable  #" + anchor).removeClass("hide");
        $(this).parent("li").addClass("selected");

        return false;
    });

    //Outside Links
    $("a.target").click(function() {
        window.open($(this).attr("href"));
        return false;
    });

    //Print 
    $("a#printLink").click(function() {
        window.print();
        return false;
    });

    //Mondal Window openers - Changed 3/25 10 */
    $("#compareProducts").nyroModal({ width: 757, height: 800 });
    $("#emailLink").nyroModal({ width: 437, minHeight: 500 });
    $("#viewTerms").nyroModal({ width: 367, minHeight: 300 });

    //Home Page Tab
    $("#quoteBox .selector a").click(function() {
        var anchor = $(this).attr("href").split("#")[1];
        $("#quoteBox .selector li").removeClass("selected");

        $("#quoteBox dt").addClass("hide");
        $("#quoteBox #" + anchor).removeClass("hide");
        $(this).parent("li").addClass("selected");

        return false;
    });

    //Get a Quote Form 
    //Loading - Changed 3/25/10
    if ($("input[name='trip']").val() == "multiple") $("li.travelDates, #ageList, #tripCost").addClass("hide");
    else $("li.travelDates, #ageList, #tripCost").removeClass("hide");

    //Functionality - Changed 3/25/10
    $("input[name='trip']").click(function() {
        if ($(this).val() == "multiple") $("li.travelDates, #ageList, #tripCost").addClass("hide");
        else $("li.travelDates, #ageList, #tripCost").removeClass("hide");
    });

    //Datepicker
    //if ($("body").attr("class") != "") {	
    $.datepicker.setDefaults({
        minDate: 0,
        showButtonPanel: true,
        onSelect: updateLinked,
        showOn: 'both',
        buttonImageOnly: true,
        buttonImage: '/Content/images/default/icons/icon-calendar.gif',
        buttonText: 'Please select date',
        dateFormat: 'mm/dd/yy'
    });

    //IE6 Hacks
    if ($.browser.msie && (parseInt($.browser.version) == 6)) {
        $.datepicker.setDefaults({
            duration: "",
            showAnim: ""
        });
    };
    //};

    //Manage Policy
    $("#selectRetrieval").change(function() {
        $("#purchaseRetrieval, #departureRetrieval, #emailRetrieval").addClass("hide");
        switch ($(this).val()) {
            case "purchasedate":
                $("#purchaseRetrieval").removeClass("hide");
                break;
            case "departuredate":
                $("#departureRetrieval").removeClass("hide");
                break;
            case "email":
                $("#emailRetrieval").removeClass("hide");
                break;
        }
    });

    //Help Window	

    // Use the each() method to gain access to each elements attributes
    $("label a.help, legend a.help").each(function() {
        // Create image content using websnapr thumbnail service
        var content = $(this).parent().siblings("div.helpWindow").html();

        // Setup the tooltip with the content
        $(this).qtip(
      {
          content: content
      });
    });

    // Use the each() method to gain access to each elements attributes
    $(".benefits tbody th a, .lister table th a, #compareTable table tbody th a").each(function() {
        // Create image content using websnapr thumbnail service
        var content = $(this).siblings("div.helpWindow").html();

        // Setup the tooltip with the content
        $(this).qtip(
      {
          content: content
      });
    });

    $(".lister .viewall a").toggle(
		function() {
		    //$(this).parent().siblings("table").removeClass("hide");
		    $(this).parent().siblings("table").show();
		    $(this).addClass("selected");
		    return false;
		},
		function() {
		    //$(this).parent().siblings("table").addClass("hide");
		    $(this).parent().siblings("table").hide();
		    $(this).removeClass("selected");
		    return false;
		}
	);

    //View Benefits
    $("#viewBenefits thead a").toggle(
		function() {
		    $("#viewBenefits tbody").removeClass("hide");
		    $(this).addClass("selected");
		    return false;
		},
		function() {
		    $("#viewBenefits tbody").addClass("hide");
		    $(this).removeClass("selected");
		    return false;
		}
	);

    //Manage Policy/Page 1
    $("a#findPolicyLink").click(function() {
        $("#enterPolicyForm").addClass("hide");
        $("#findPolicyForm").removeClass("hide");
        return false;
    });

    $("a#enterPolicyLink").click(function() {
        $("#findPolicyForm").addClass("hide");
        $("#enterPolicyForm").removeClass("hide");
        return false;
    });

    //Compare Table
    $("#compareTable tbody tr[class!='buyList']:odd").css("background-color", "#f9f9f5");
    $("#compareTable tbody tr:first, #compareTable tbody tr.buyList").addClass("first");


    //*** Commented by AK - moved to Validation.js
    //Different Billing Address
    //	$("input#sameAddress").click(function() {
    //		if($(this).attr("checked")) $(".secondAddress").removeClass("hide");
    //		else $(".secondAddress").addClass("hide");
    //	});


    //End JQuery Code
});


// Prepare to show a date picker linked to three input controls 
function readLinked() {
    $(this).val($('#' + datefocus + '_month').val() + '/' + $('#' + datefocus + '_date').val() + '/' + $('#' + datefocus + '_year').val());
    return {};
}

// Update three input controls to match a date picker selection 
function updateLinked(date) {
    $('#' + datefocus + '_month').val(date.split("/")[0]);
    $('#' + datefocus + '_date').val(date.split("/")[1]);
    $('#' + datefocus + '_year').val(date.split("/")[2]);
}

