﻿function Load() {

    doResize(); 
    LoadFlash();
    InitDropDownList();

    if ($("select.nationList").val() != "TR0") {
        $(".rentLoca").hide();
    }
    else {
        $(".rentLoca").show();
    }

    $("select.nationList").change(function () {
        if ($(this).val() != "TR0") {
            $(".rentLoca").hide();
            $(".rezervasyonbtn").removeAttr("disabled");
        }
        else {
            $(".rentLoca").show();
        }
    });

    if ($("select.countryList").val() == "Seciniz" || $("select.countryList").val() == "Select") {
        $(".rezervasyonbtn").attr("disabled", "disabled");
    }

    $("select.countryList").change(function () {
        if ($(this).val() != "Seciniz" || $(this).val() != "Select") {
            $(".rezervasyonbtn").removeAttr("disabled");
        }
        else {
            $(".rezervasyonbtn").attr("disabled", "disabled");
        }
    });

	$(window).bind('resize', function() {
	        doResize();
    });
      
    $(".focusempty").each(function(){$(this).focusEmpty()});
    
    $("*[rel=jsabox_img]").click(function() {
        
        $("#jsaboxcontent").html("<div class='lightboxcontent'><img src='Images/close.jpg' class='close' /><img src='" + $(this).attr("href") + "' /></div>");
        
        $(".lightboxcontent").click(function(){return false;});
        $(".lightboxcontent .close").click(function(){CloseItem();});

        $("#jsabox").show();
        return false;
    });
    
    $("*[rel=jsabox_swf]").click(function() {
        $("#jsaboxcontent").html("<div type='Flash' src='" + $(this).attr("href") + "' width='" + $(this).attr("width") + "' height='" + $(this).attr("height") + "'></div>");        
        $("#jsabox").show();
        LoadFlash();
        return false;
    });

    $("*[rel=jsabox_html]").click(function() {
        $("#jsaboxcontent").html("<div type='Flash' src='" + $(this).attr("href") + "' width='" + $(this).attr("width") + "' height='" + $(this).attr("height") + "'></div>");        
        $("#jsabox").show();
        LoadFlash();
        return false;
    });
    
    $("*[rel=jsaBox_html]").click(function() {
        var item = $("#" + $(this).attr("href")).clone().show();
        $("#jsaboxcontent").html("<div class='lightboxcontent'>" + item.html() + "</div>");
        $("#jsabox").show();
        return false;
    });
    
    $("*[rel=jsaBox_map]").click(function() {
        var item = $("#" + $(this).attr("href")).clone().show();
        $("#jsaboxcontent").html("<div class='mapcontent'><img src='Images/close.png' class='close' />" + item.html() + "</div>");
        $("#jsabox").show();
        return false;
    });
    
    $("*[rel=jsaBox_flash]").click(function() {
        var item = $("#" + $(this).attr("href")).clone().show();
        $("#jsaboxcontent").html("<div class='lightboxcontent' style='width:600px;height:180px;'><img src='Images/close.jpg' class='close' />" + item.html() + "</div>");
        $("#jsabox").show();
        return false;
    });

    $("#jsabox").click(function() {CloseItem();});
    
    $("*[rel=jsabox_video]").click(function() {
        $("#jsaboxcontent").html("<div type='Flash' class='lightboxcontents' src='Flash/VideoPlayer.swf?pvideo=" + BasePath + $(this).attr("href") + "' width='303px' height='235px'></div>");
        LoadFlash();
        $("#jsabox").show();
        return false;
    });

    $("*[rel=jsaBox_ad]").click(function() {
        $("#jsaboxcontent").html("<div id='showflash'></div>");
        $("#showflash").click(function () { return false; }).GenerateFlash({ src: "Flash/player.swf?pimage=Flash/video-thumbnail.jpg&pskin=Flash/skins/classic.swf&pvideo=" + $(this).attr("href"), width: "550px", height: "445px" }).append("<div class='closebutton'><a onclick='javascript:CloseItem();'><img src='Images/close.png' class='close' /></a></div>");
        $("#jsabox").show();
        return false;
    }); 
    
    $(".Phone").mask("9(999) 999-9999");
    $(".Date").mask("99/99/9999").blur(function(){
        if (! DateControl($(this).val()) ) {
            $(this).val("");
        }
    });    
    
    $(".Year").mask("9999");
    $(".TC").mask("99999999999");
    $(".TaxNumber").mask("9999999999");
    $(".Hour").mask("99:99").blur(function(){
        if ( parseInt($(this).val().replace(":","")) > 2359 ) {
            $(this).val("");
        }
    });
    
    $(".Number").keyup(function(){
        if (! IsNumeric($(this).val()) ) {
            $(this).val(ConvertNumeric($(this).val()));
        }
    });
    
    $(".inputtext").focus(function() { $(this).css("background-position", "left bottom"); }).blur(function() { $(this).css("background-position", ""); });
    $(".inputtextarea").focus(function() { $(this).css("background-position", "left bottom"); }).blur(function() { $(this).css("background-position", ""); });
    $(".inputdrp").focus(function() { $(this).parent().css("background-position", "left bottom"); }).blur(function() { $(this).parent().css("background-position", ""); });

    $(".FakeUpload").change(function () {
        $(this).parent().find(".fakeupload").val($(this).val());
    });


    $(".menu ul ul").hide();
    $(".menu .select").each(function() {
        var top = false;
        var parent = $(this).parent();
        while (!top) {
            parent.show();
            parent = parent.parent();
            if (parent.attr("class") == "menu") { top = true; }
        }
    });
    $(".menu .select").parent().parent().find("ul:eq(0)").show();
    
}

function InitDropDownList() {
    var Browser = $.browser;
    if (!(Browser.msie && Browser.version == "6.0") ) {
        $(".inputdrp").each(function(){
            if ( $(this).attr("isdrp") != "true" ) {
                $(this).attr("isdrp",true);
                $(this).parent().addClass("inputdrpParent").each(function () {$(this).html("<span class='inputdrpText'>" + $(this).find("option[selected=true]").text() + "</span>" + $(this).html());});
            }
        })
        $(".inputdrp").change(function () {$(this).parent().find(".inputdrpText").html($(this).find("option[selected=true]").text());});
    }
}

function IsNumeric(Text) {
    var ValidChars = "0123456789.";
    var IsNumber = true;
    var Char;
    for (i = 0; i < Text.length && IsNumber == true; i++) {
        Char = Text.charAt(i);
        if (ValidChars.indexOf(Char) == -1) { IsNumber = false; };
    }
    return IsNumber;
    }

function ConvertNumeric(Text) {
    var ValidChars = "0123456789.";
    var Char = "";

    for (i = 0; i < Text.length; i++) {
        if (ValidChars.indexOf(Text.charAt(i)) != -1) {
            Char = Char + Text.charAt(i);
        }
    }
    return Char;
    }

function CloseItem() {
    $("#jsaboxcontent").html("").hide();
    setTimeout(function(){ $("#jsabox").hide(); $("#jsaboxcontent").show(); },50);
}

function openImage(fileUrl) {
    $("#jsaboxcontent").hide().html("<div class='qualtycontent' id='showflash'></div>")
    $("#jsabox").show();
    $("#showflash").GenerateFlash({ src: "Flash/LightBox.swf?urlPic=" + fileUrl , width: "420px", height: "573px" });
    setTimeout(function(){
    $("#jsaboxcontent").slideDown(300);
    },200);    
}

function ShowParent($this, StopItem) {
    $this.parent().find("li").show();
    if ( $(StopItem).attr("id") != $this.attr("id") ) {
        ShowParent($this.parent(),StopItem);
    }
}

function doResize() {
    if ( $(window).height() > 110 ) {
        $("#container").css("min-height", ($(window).height() - 110)).css("height", ($(window).height() - 110));
    }
}


function InitPhotoGallery() {


    var gallerysize = $(".imagegallery .imageitems .imageitem").size();
    var galleryNumber = 0;

    $(".gallerynext").click(gallerynext);
    $(".galleryprevious").click(galleryprevious);
    $(".imagenext").click(imagenext);
    $(".imageprevious").click(imageprevious);


    $(".imagegallery .imageitems .imageitem a").each(function() {
        $(this).attr("number", galleryNumber);
        galleryNumber++;
    });

    $(".imagegallery .imageitems .imageitem a").click(function() {
        showgalleryimage($(this).attr("number"));
        return false;
    });

    $("#imgNow").load(function () {
        $(".imageloading").animate({ height: $("#imgNow").height() }, 300, function () {
            $(".imagenavigation").css("height", $("#imgNow").height());
            $(".imageloading").fadeOut(100, function () {
                $("#imgNow").show();
                if ($("#imgDesc").html().toString().length > 0) {
                    $("#imgDesc").show();
                }
                else {
                    $("#imgDesc").hide();
                }
            });
        });
    }).hover(function () {
        $(".imagegallery .imagenavigation").show();
    });
    $(".imagegallery .imagenavigation").hover(function() {
    }, function() {
        $(".imagegallery .imagenavigation").hide();
    });

    function showgalleryimage(Number) {
        var $this = $(".imagegallery .imageitems .imageitem a:eq(" + Number + ")");
        $(".imageloading").show();

        $("#imgNow").hide().attr("src", $this.attr("binaryUrl")).attr("number", Number);

        $("#imgDesc").html($this.attr("desc"));

        $("#imgdesc").hide();

        $(".galleryinfo").html("Resim " + (parseInt(Number) + 1) + "/" + (gallerysize));
        $(".imagegallery .imageitems .imageitem a").find("img").removeClass("select");
        $this.find("img").addClass("select");
        $(".imagegallery .imageitems").animate({ top: "-" + ((Math.floor(Number / 4) * 76) + "px") }, 500);
    }

    function imagenext() {
        var Number = parseInt($("#imgNow").attr("number"));
        if (Number < gallerysize - 1) { Number++; }
        else { Number = 0; }
        showgalleryimage(Number);
    }

    function imageprevious() {
        var Number = parseInt($("#imgNow").attr("number"));
        if (Number > 0) { Number--; }
        else { Number = gallerysize - 1; }
        showgalleryimage(Number);
    }

    function gallerynext() {
        var top = parseInt($(".imagegallery .imageitems").css("top").replace("px", ""));

        if (top > (((gallerysize / 4) * 76) - 76) * -1) {
            $(".imagegallery .images .imageitems").animate({ top: "-=76px" }, 500);
        }
    }
    function galleryprevious() {
        if (parseInt($(".imagegallery .imageitems").css("top").replace("px", "")) < 0) {
            $(".imagegallery .images .imageitems").animate({ top: "+=76px" }, 500);
        }
    }

    showgalleryimage(0);

}


function DateControl(fld) {
    var RegExPattern = /^((((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|[12]\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|1\d|2[0-8])02((1[6-9]|[2-9]\d)?\d{2}))|(2902((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00))))$/;
    if ((fld.match(RegExPattern)) && (fld != '')) { return true; }
    else { return false; }
}

function getListValue(option_object) {
    return option_object[option_object.selectedIndex].value;
}
var xMonths = new Array('jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec');

function doContinue() 
{
    $("#aspnetForm #__EVENTTARGET").remove();
    $("#aspnetForm #__EVENTARGUMENT").remove();
    $("#aspnetForm #__VIEWSTATE").remove();
    xF = document.forms[0];
    xCountry = getListValue(xF.country);
    xETADay = getListValue(xF.ETADay);
    xETAMonth = getListValue(xF.ETAMonth);
    xETAYear = getListValue(xF.ETAYear);
    xETAHour = getListValue(xF.ETAHour);
    xETAMinute = getListValue(xF.ETAMinute);
    xETA = xETADay + xMonths[parseInt(xETAMonth) - 1] + xETAYear.substr(2, 2) + '/' + xETAHour + xETAMinute; xETTDay = getListValue(xF.ETTDay);
    xETTMonth = getListValue(xF.ETTMonth);
    xETTYear = getListValue(xF.ETTYear);
    xETTHour = getListValue(xF.ETTHour);
    xETTMinute = getListValue(xF.ETTMinute);
    xETT = xETTDay + xMonths[parseInt(xETTMonth) - 1] + xETTYear.substr(2, 2) + '/' + xETTHour + xETTMinute;
    xName = xF.surname.value;
    xWizardNumber = xF.wizard_number.value;
    xParams = '&BODYPARAMS=*Country=' + xCountry + '*Country2=' + xCountry + '*ETA=' + xETA + '*ETT=' + xETT + '*WIZ=' + xWizardNumber + '*CNAM=' + xName;
    if (xName != '' & xWizardNumber != '')
        location.href = 'http://www.avisonline.com/avisonline/eu-gb/avis.nsf/fTopFramesets/1B7FC89F7435466CC12569E6003C470B!opendocument&~Default&_S1_1B7FC89F7435466CC12569E6003C470B_N2_N3' + xParams + '*GO2=ReservationStep1';
    else
        location.href = 'http://www.avisonline.com/avisonline/eu-gb/avis.nsf/fTopFramesets/1B7FC89F7435466CC12569E6003C470B!opendocument&~Default&_S1_1B7FC89F7435466CC12569E6003C470B_N2_N3' + xParams;
}

function openhelp(hlpString) {
    hlpWin = window.open(hlpString, 'Help', 'width=650,height=345,resizable=yes,scrollbars=yes,status=yes')
    hlpWin.focus();
}

var cache = 0;
var data = "";
function fx_litebox(type, content) {
    content != null ? data = content : data = "<object width='1200' height='600' align='middle'><param name='allowScriptAccess' value='sameDomain'><param name='allowFullScreen' value='true'><param name='quality' value='high'><param name='menu' value='false'><param name='wmode' value='transparent'><param name='movie' value='Flash/AvisBanner.swf'><embed swliveconnect='true' name='Object1' wmode='transparent' src='Flash/AvisBanner.swf' quality='high' menu='false' width='1200' height='600' align='middle' allowscriptaccess='sameDomain' allowfullscreen='true' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer'></object>";
    switch (type) {
        case "normal":
            cache != 0 ? $("#fx_litebox").show() : $("#fx_litebox").html("<div class='fx_quex'></div><div class='fx_content'><object width='1200' height='600' align='middle'><param name='allowScriptAccess' value='sameDomain'><param name='allowFullScreen' value='true'><param name='quality' value='high'><param name='menu' value='false'><param name='wmode' value='transparent'><param name='movie' value='Flash/AvisBanner.swf'><embed swliveconnect='true' name='Object1' wmode='transparent' src='Flash/AvisBanner.swf' quality='high' menu='false' width='1200' height='600' align='middle' allowscriptaccess='sameDomain' allowfullscreen='true' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer'></object><div class='fx_close'></div></div>").show();
            break;
    }
    $("div.fx_quex").click(function () { fx_end(); })
    $("a.fx_close").click(function () { fx_end(); })
    cache++;
}

function fx_end() {
    $("#fx_litebox").hide();
}

if (!Array.indexOf) {
    Array.prototype.indexOf = function (obj) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] == obj) {
                return i;
            }
        }
        return -1;
    }
}
