﻿/// <reference path="~/Resources/scripts/Libs/jquery-1.3.2-vsdoc2.js" />


function registerNS(ns) {
    var nsParts = ns.split(".");
    var root = window;

    for (var i = 0; i < nsParts.length; i++) {
        if (typeof root[nsParts[i]] == "undefined")
            root[nsParts[i]] = new Object();

        root = root[nsParts[i]];
    }
}




Function.prototype.bind = function(o) {
    if (!window.__objs) {
        window.__objs = [];
        window.__funcs = [];
    }

    var objId = o.__oid;
    if (!objId)
        __objs[objId = o.__oid = __objs.length] = o;

    var me = this;
    var funcId = me.__fid;
    if (!funcId)
        __funcs[funcId = me.__fid = __funcs.length] = me;

    if (!o.__closures)
        o.__closures = [];

    var closure = o.__closures[funcId];
    if (closure)
        return closure;

    o = null;
    me = null;

    return __objs[objId].__closures[funcId] = function() {
        return __funcs[funcId].apply(__objs[objId], arguments);
    };
}


registerNS("TS");


TS.JQID = function(_baseID, _ctrID) {
    return "#" + _baseID + "_" + _ctrID;
}


/* BOOKFRM  */
//*****************************************************************/

TS.BookFrm = function(_baseID) {
    this.baseID = _baseID;
    this.Init();
};

TS.BookFrm.prototype.Init = function() {
    var thisobj = this;
    $(TS.JQID(this.baseID, "tbDepDate"))
    .datepicker($.datepicker.regional['hu'])
    .datepicker('option', 'dateFormat', 'yy.mm.dd')
    .datepicker('option', 'maxDate', new Date(2010, 12, 31))
    .datepicker('option', 'minDate', new Date());
    



    $(TS.JQID(this.baseID, "imgCal")).click(
        function() {

            $(TS.JQID(thisobj.baseID, "tbDepDate"))
            .datepicker('show');

        }
    );


    this.res = false;



    $(TS.JQID(this.baseID, "cbNrAdult")).change(this.ChangeAdult.bind(this));
    this.ChangeAdult();



    $(TS.JQID(this.baseID, "cbNrChild")).change(this.ChangeChild.bind(this));
    this.ChangeChild(); //for postback return


    //$(TS.JQID(this.baseID, "btnBook")).click(this.Book.bind(this));
    $("#tst").click(this.Book.bind(this));

    var b = thisobj.baseID;

    $.metadata.setType("attr", "validate");
    $("#form1").validate();

    if ($.browser.mozilla) {
        $(TS.JQID(this.baseID, "btnBook")).click(function(e) { $(this).attr("disabled", "disabled"); });
    }

    $(TS.JQID(this.baseID, "cbCity")).change(function(e) {

        var citycode = $(this).val();
        if (citycode != "") {
            $(TS.JQID(thisobj.baseID, "lbCityDetail")).html($("span[id=" + citycode + "]").html());
        }
        else $(TS.JQID(thisobj.baseID, "lbCityDetail")).html("");
    });

    $(TS.JQID(this.baseID, "cbCity")).trigger("change");

}


TS.BookFrm.prototype.ChangeChild = function() {
    var nrit = $(TS.JQID(this.baseID, "cbNrChild")).val();

    if (nrit == "") {
        $("#dvChdLst div").addClass('travhidden');
        return;
    }

    $("#dvChdLst div").addClass('travhidden');
    $("#dvChdLst div:lt(" + nrit + ")").removeClass();

    $("#dvChdLst div input").removeAttr('validate');
    $("#dvChdLst div:lt(" + nrit + ") input").attr("validate", "required:true");

    //revalidate
    $("#form1").validate();
}


TS.BookFrm.prototype.ChangeAdult = function() {


    var nrit = $(TS.JQID(this.baseID, "cbNrAdult")).val();
    if (nrit == "") {
        $("#dvAdLst div").addClass('travhidden');
        return;
    }

    $("#dvAdLst div").addClass('travhidden');
    $("#dvAdLst div:lt(" + nrit + ")").removeClass();

    $("#dvAdLst div input").removeAttr('validate');
    $("#dvAdLst div:lt(" + nrit + ") input").attr("validate", "required:true");

    //revalidate
    $("#form1").validate();
}


TS.BookFrm.prototype.Book = function() {

    alert("v");
    

}

TS.StartFrm = function(_baseID) {
    
    new TS.BookFrm(_baseID);
}

/* *********************************** bookmain *************************/


TS.BookMain = function(_rooturl) {

    this.rooturl = _rooturl;
    
    this.Init();
};

TS.BookMain.prototype.Init = function() {

    var thisobj = this;

    $("div.citylistitem").hover(function() {
        var citycode = $(this).attr('code');

        var pct = $("#imgcitypict");
        pct.hide();
        pct.attr("src", thisobj.rooturl + "data/images/" + citycode + ".jpg");
        pct.fadeIn("fast");

        var bdy = $("div.ctyinfobody");
        //bdy.fadeOut();
        bdy.hide();
        bdy.html($("span[id=" + citycode + "]").html());
        bdy.fadeIn("fast");
    }
    )

    $("div.citylistitem:first").trigger("mouseenter");

    //precache
    $("div.citylistitem").each(function(i, val) {
        var citycode = $(this).attr('code');
        var img = new Image();
        $(img).attr("src", thisobj.rooturl + "data/images/" + citycode + ".jpg");

    });


    $("div.citylistitem").click(function() {
        var citycode = $(this).attr('code');
        OpenContent(thisobj.rooturl + "bookfrm.aspx", 600, 500, true);
    });


}



TS.StartMain = function(_rooturl) {

    new TS.BookMain(_rooturl);
}
