// JavaScript Document

// jQuery initial scripts

$(function() {

    //Top navigation dropdowns
    $("#navwrapper td").hoverIntent(function() {
        $("ul", this).fadeIn("slow");
    }, function() {
        $("ul", this).fadeOut("fast");
    });

    //Buttons & Mouseovers
    $(".btnSearch").hover(function() {
        $(this).removeClass("btnSearch").addClass("btnSearchOver");
    }, function() {
        $(this).removeClass("btnSearchOver").addClass("btnSearch");
    });
    $("#btnSearch").click(function() {
        window.location = "search.asp";
    });
    $(".btnConfirm").hover(function() {
        $(this).removeClass("btnConfirm").addClass("btnConfirmOver");
    }, function() {
        $(this).removeClass("btnConfirmOver").addClass("btnConfirm");
    });
    $(".btnBooknow").hover(function() {
        $(this).removeClass("btnBooknow").addClass("btnBooknowOver");
    }, function() {
        $(this).removeClass("btnBooknowOver").addClass("btnBooknow");
    });
    $(".btnSignin").hover(function() {
        $(this).removeClass("btnSignin").addClass("btnSigninOver");
    }, function() {
        $(this).removeClass("btnSigninOver").addClass("btnSignin");
    });
    $(".btnSend").hover(function() {
        $(this).removeClass("btnSend").addClass("btnSendOver");
    }, function() {
        $(this).removeClass("btnSendOver").addClass("btnSend");
    });
    $(".btnRegister").hover(function() {
        $(this).removeClass("btnRegister").addClass("btnRegisterOver");
    }, function() {
        $(this).removeClass("btnRegisterOver").addClass("btnRegister");
    });
    $(".btnUpdate").hover(function() {
        $(this).removeClass("btnUpdate").addClass("btnUpdateOver");
    }, function() {
        $(this).removeClass("btnUpdateOver").addClass("btnUpdate");
    });
    $(".btnEdit").hover(function() {
        $(this).removeClass("btnEdit").addClass("btnEditOver");
    }, function() {
        $(this).removeClass("btnEditOver").addClass("btnEdit");
    });


    //Deal list mouseovers
    $("#topactivities .deal").hover(function() {
        $(this).css("background-color", "#eef8ff");
    }, function() {
        $(this).css("background-color", "#ffffff");
    });
    $(".subpage .deal:odd").css("background-color", "#f6f6f6");
    $(".tours_item:even").css("background-color", "#E5F4FF");

    //here I preset when none
    if ($(".qboxbig").attr("value") == "") {
        $(".qboxbig").attr("value", "Search for activities")
    }


    //Searchbox focus/blur functionality
    $(".qboxbig").focus(function() {
        if ($(this).attr("value") == "Search for activities") $(this).attr("value", "");
    }).blur(function() {
        if ($(this).attr("value") == "") $(this).attr("value", "Search for activities");
    });

    $(".dateboxsrch_startdate").focus(function() {
        if ($(this).attr("value") == "Starting date") {
            $(this).attr("value", "");
        }
    });


    $(".dateboxsrch_startdate").blur(function() {
        if ($(this).attr("value") == "") {
            $(this).attr("value", "Starting date");
        }
    });

    $(".dateboxsrch_enddate").focus(function() {
        if ($(this).attr("value") == "Ending date") {
            $(this).attr("value", "");
        }
        //this reparise is date not true
        //if ($(".dateboxsrch_startdate").attr("value") != "" && $(".dateboxsrch_startdate").attr("value") != "Starting date") {
        //    $('.dateboxsrch_enddate').datepicker('option', 'minDate', new Date($(".dateboxsrch_startdate").attr("value")));
        //}

    });
    $(".dateboxsrch_enddate").blur(function() {
        if ($(this).attr("value") == "") {
            $(this).attr("value", "Ending date");
        }
    });

    //prsset srach date fileds
    if ($(".dateboxsrch_startdate").attr("value") == "") {
        $(".dateboxsrch_startdate").attr("value", "Starting date")
    }

    if ($(".dateboxsrch_enddate").attr("value") == "") {
        $(".dateboxsrch_enddate").attr("value", "Ending date")
    }

    //Date Pickers
    $(".dateboxsrch_startdate").datepicker({ minDate: new Date() });
    $(".dateboxsrch_enddate").datepicker({ minDate: new Date() });

    /*
    $('.dateboxsrch_startdate').datepicker(
    {
    onClose:
    function(dateText, inst) 
    {
    alert('close') 
    }
    });
    */


    $("#dateRes").focus(function() {
    if ($(this).attr("value") == "Starting date") {
    $(this).attr("value", "");
    }
    });
    $("#dateRes").blur(function() {
    if ($(this).attr("value") == "") {
    $(this).attr("value", "Starting date");
    }
    });

    //Rounded Corners
    $(".subpage #search").corner("9px");
    $("#search_subpage").corner("9px");
    $("#searchbox").corner("9px");
    $("#helpbox").corner("9px");
    $("#shoppingcart").corner("9px");
    $("#whybook").corner("9px");
    $("#whybookthin").corner("9px");
    $("#booking").corner("9px");

    $("#TicketCommission").corner("5px");

    $("#agent_welcome_box").corner("5px");
    //Date Pickers
    //$(".datebox").datepicker( {minDate: new Date(2009,3,28), maxDate:new Date(2010,11,31)} );


    //Style fixes
    //$(".deal:last").css("border-bottom","0");
    //$(".bunch:last").css("border-bottom","0");

    //Truncate output
    /*$(".deal .area2 h3").truncate( 20, {
    chars: /\s/
    });
    $(".deal .area2 p").truncate( 70, {
    chars: /\s/
    });*/

    //Add to favourites icon
    $("#bookmark").jFav();

    //Product detail tabs
    $("#tabs").tabs({ disabled: [4] });

    $("#child").val(0);
    $("#popup4").hide()
    $("#child").change(function() {
        var number = $(this).val();
        $(".children").empty();
        $("#popup4").hide()
        for (i = 0; i < number; i++) {
            $(".children").append('<p>Enter the age of <strong>Child' + (i + 1) + '</strong> <input type="text" id="child' + i + 'age" name="child' + i + 'age" class="textbox age" /></p>');
        }
        if (number != 0) {
            $("#popup4").show()
        }
    });
    $("#infant").val(0);
    $("#popup4").hide()
    $("#infant").change(function() {
        var number = $(this).val();
        $(".infants").empty();
        $("#popup4").hide()
        for (i = 0; i < number; i++) {
            $(".infants").append('<p>Enter the age of <strong>Infant' + (i + 1) + '</strong> <input type="text" id="infant' + i + 'age" name="infant' + i + 'age" class="textbox age" /></p>');
        }
        if (number != 0) {
            $("#popup4").show()
        }
    });

    //Validator notes: age of the children and infants

    // Dialogs
    $(".dialog").dialog({
        autoOpen: false,
        position: 'center',
        zIndex: 3999,
        width: 500
    });
    $("#popup1").click(function() {
        $("#dialog1").dialog("open");
    });
    $("#popup2").click(function() {
        $("#dialog2").dialog("open");
    });
    $("#popup3").click(function() {
        $("#dialog3").dialog("open");
    });
    $("#popup4").click(function() {
        $("#dialog4").dialog("open");
    });
    $("#popup5").click(function() {
        $("#dialog5").dialog("open");
    });
    $("#popup6").click(function() {
        $("#dialog6").dialog("open");
    });
    $("#popup21").click(function() {
        $("#dialog21").dialog("open");
    });
    $("#popup22").click(function() {
        $("#dialog22").dialog("open");
    });
    $("#popup23").click(function() {
        $("#dialog22").dialog("open");
    });
    $("#popup24").click(function() {
        $("#dialog24").dialog("open");
    });
    $("#popup25").click(function() {
        $("#dialog25").dialog("open");
    });
    $("#popup31").click(function() {
        $("#dialog31").dialog("open");
    });
    $("#popup32").click(function() {
        $("#dialog32").dialog("open");
    });
    $("#popup33").click(function() {
        $("#dialog33").dialog("open");
    });
    $("#dialog41, #dialog42").dialog("destroy");
    $("#dialog41, #dialog42").dialog({
        autoOpen: false,
        position: 'center',
        zIndex: 3999,
        width: 340
    });
    $("#popup41, #popup411").click(function() {
        $("#dialog41").dialog("open");
    });
    $("#popup42").click(function() {
        $("#dialog41").dialog("close");
        $("#dialog42").dialog("open");
    });
    $("#popup43, #feedback, #contactus").click(function() {
        $("#dialog43 input, #dialog43 textarea").val("");
        $("#dialog43").dialog("open");
    });

    // Comment field auto resize
    $("#contact_comments").autoResize();
    $(".remind_text").autoResize();

    //Comment field focus/blur functionality
    $(".remind_text").focus(function() {
        if ($(this).attr("value") == "Optional") $(this).attr("value", "");
    }).blur(function() {
        if ($(this).attr("value") == "") $(this).attr("value", "Optional");
    });


    // Checkout form
    $(".visa").click(function() {
        $(".credit_card_type option[selected]").removeAttr("selected");
        $(".credit_card_type option[value='Visa']").attr("selected", "selected");
    });
    $(".mastercard").click(function() {
        $(".credit_card_type option[selected]").removeAttr("selected");
        $(".credit_card_type option[value='Mastercard']").attr("selected", "selected");
    });
    $(".amex").click(function() {
        $(".credit_card_type option[selected]").removeAttr("selected");
        $(".credit_card_type option[value='Amex']").attr("selected", "selected");
    });

    $(".billing_country").linkToStates(".billing_state");

    $(".printthisbutton").click(function() {
        $("div").removeClass("printthis").removeClass("noprintthis");
        $("div").addClass("noprintthis");
        $(this).parents(".item, #itinerary, #confirm").removeClass("noprintthis").addClass("printthis");
        $(this).parents(".item").find("div").removeClass("noprintthis").addClass("printthis");
        window.print();
    });
    $(".printallbutton").click(function() {
        $("div").removeClass("printthis").removeClass("noprintthis");
        $("div").addClass("printthis");
        window.print();
    });


    // check if confirm password is still valid after password changed
    $("#password").blur(function() {
        $("#confirm_password").valid();
    });

    //$('.dateboxsrch_startdate').datePicker();

    //$('.dateboxsrch_enddate').datePicker();	


    //jQuery main function end	
});

function mailpage()
{
	title = document.title;
	title = title.replace(/\|/,"at");
	mail_str = "mailto:?subject=Check out the " + title;
	mail_str += "&body=I thought you might be interested in " + title + ".%0D%0A%0D%0A";
	mail_str += "You can view it at, " + location.href;
	location.href = mail_str;
}

function requestchange(bookingnumber)
{
	$("#dialog43").dialog("open");
	$("#dialog43 #contact_subject").val("Change request for booking #"+bookingnumber);
	$("#dialog43 #contact_comments").val("I am hereby requesting the following change in my booking #" + bookingnumber + "\n\n");
	$("#dialog43 #contact_comments").css("height","70px").focus();
}

