
var j = jQuery.noConflict();


j(document).ready(function(){

    var dates = j( "#fromDate, #toDate, #date" ).datepicker({

        showOn: "button",
		buttonImage: "http://www.myrometours.com/images/cal.jpg",
		buttonImageOnly: true,
        minDate: 0,
        maxDate: '+12M',
        changeMonth: true,
        numberOfMonths: 3,
        dateFormat: 'dd-mm-yy',

        onSelect: function( selectedDate ) {

            var option = this.id == "fromDate" ? "minDate" : "maxDate",
            instance = j( this ).data( "datepicker" );
            date = j.datepicker.parseDate(
                instance.settings.dateFormat ||
                j.datepicker._defaults.dateFormat,
                selectedDate, instance.settings );
            dates.not( this ).datepicker( "option", option, date );

        }

    });
	
	j(".ui-datepicker-trigger").mouseover(function() {
        j(this).css('cursor','pointer');
	});

});


jQuery.fn.reset = function () {
    $(this).each (function() {
        this.reset();
    });
}

var formbooking;

function openEstimate(type) {
    if (type == 0 || type == 1) {
        j.get('inc.estimatehome.php?type=' + type, function(data) {
            j('#light').html(data);
            j('#light').fadeIn('slow', function() {
                j('#light').css('display', 'block');
            });
            formbooking = j('#formbooking').html();
        });
    }

}

function closeEstimate()    {
    j('#light').fadeOut('slow', function() {
        j('#light').css('display', 'none');
    });
    j('#formbooking').reset();
    j('#slcTour').val('');
}

function changeTour(back, lang)   {
    j('#formbooking').html(formbooking);
    var t = j('#slcTour').val();
    j('#formbooking').reset();
    if (t!="")  {
        //j('#hiddenFields').load('js/ajax-estimate-datas.php?code='+t);
        j.ajax({
            type: 'get',
            url: back+'js/ajax-estimate-datas.php?lang='+lang,
            data: 'code='+t,
            success: function(msg)  {
                msg = msg.split("!#!", 2);
                j("#lingua").html(msg[0]);
                j("#hiddenFields").html(msg[1]);
            },
            error:function (xhr, ajaxOptions, thrownError){
                alert(xhr.status);
                alert(thrownError);
            }
        });
    }
}

function findTypesByLocation ( url, id, location, method, titleId, elementId )    {

        var data = "a=" +  id + "&" + "l=" + location;
        $.ajax({
            type: method,
            url: url,
            data: data,
            success: function(msg){
                msg = msg.split("!#!", 2);
                $(titleId).html(msg[0]);
                $(elementId).html(msg[1]);
            },
            error:function (xhr, ajaxOptions, thrownError){
                alert(xhr.status);
                alert(thrownError);
            }
        });

}




