﻿function Load() {

    LoadFlash();
    InitDropDownList();

    //$(".Splitter").height($(".leftCol").height());

   /* $("ul.megamenu li:eq(0) .Splitter").height($("ul.megamenu li:eq(0) .leftCol").height());
    $("ul.megamenu li:eq(1) .Splitter").height($("ul.megamenu li:eq(1) .leftCol").height());
    $("ul.megamenu li:eq(2) .Splitter").height($("ul.megamenu li:eq(2) .leftCol").height());
    $("ul.megamenu li:eq(3) .Splitter").height($("ul.megamenu li:eq(3) .leftCol").height());
    */ //alert($("ul.megamenu li:fourth .fullwidth div .leftCol").height());
    
    $(".focusempty").each(function() { $(this).focusEmpty() });

    $(".detailsright td:last-child").css("border-right", "none");
    $(".detailsright td:first-child").css("font-weight", "bold");
    $(".productlist .item").hover(function() { $(this).find(".title a").css("border-bottom", "1px solid #6b3500").css("font-weight", "normal"); }, function() { $(this).find(".title a").css("border-bottom", "none").css("font-weight", "normal"); });
    
    $("*[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_ad]").click(function () {
        $("#jsaboxcontent").html("<div class='add_closer'></div><div type='Flash' src='" + $(this).attr("href") + "' width='620' height='305'></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'>" + 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;
    });
    
    $(".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()));
        }
    });

    $(".MenuTxt .select").each(function() {
        var top = false;
        var parent = $(this).parent();
        while (!top) {
            parent.show();
            parent = parent.parent();
            if (parent.attr("class") == "MenuTxt") { top = true; }
        }
    });

    $(".FakeUpload").change(function () {
        $(this).parent().find(".fakeupload").val($(this).val());
    });

    var ProductPrice = $(".ProductPrice").html();
    $(".buttons .payment a").click(function () { $("#productbox").css("height", ($(document).height())); $("#productbox .lightboxcontainer").append(ProductPrice); $("#productbox").show(); });
    $("table tr th:last").addClass("end").css("color", "red");


    $(".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", ""); });

//    $(".ProductImageSmall .item a").click(function() {
//        $(".ProductImageBig").attr("src", $(this).find("img").attr("src"));
//    });


    if ($(".productdetails .imagebig .image img").size() < 2) { $(".productdetails .leftbutton,.productdetails .rightbutton").hide();}
    $(".productdetails .leftbutton").click(function() {
        var current = parseInt($(".productdetails .imagebig .image").attr("current"));
        var newcurrent = current - 1;
        if (newcurrent < 0) { newcurrent = $(".productdetails .imagebig .image img").size() - 1; }
        SetImagePosition(current, newcurrent);
    });
    $(".productdetails .rightbutton").click(function() {
        var current = parseInt($(".productdetails .imagebig .image").attr("current"));
        var newcurrent = current + 1;
        if (newcurrent >= $(".productdetails .imagebig .image img").size()) { newcurrent = 0; }
        SetImagePosition(current, newcurrent);
    });
    function SetImagePosition(current,newcurrent) {
        var currentPx = ((newcurrent * 682) * -1);
        var currentFast = Math.sqrt((newcurrent - current) * (newcurrent - current)) * 500;
        $(".productdetails .imagebig .image").stop().animate({ marginLeft: currentPx }, currentFast);
        $(".productdetails .imagebig .image").attr("current", newcurrent);
    }

    $(".dynmcImage").each(function() {
        $(this).css("background-image", "url('" + $(this).attr("imageurl") + "')");
    });

    var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];

    $(".searchinput").autocomplete("App_Control/Search.aspx", {
        minChars: 2,
        max: 6,
        scrollHeight: 220,
        width: 235,
        selectFirst: false
    }).result(function(data, i, n, value) {
        
        var string = i.toString().split(",");
        window.location.href = string[string.length - 1];
    });

}

function Favourite(ProductID, type) {
    
    $(".FavouriteProductID").val(ProductID);
    $(".FavouriteProductType").val(type);
    
    $(".FavouriteProductSubmit").click();
    
    
}

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 doResize() {
    var allo = $(window).height();
    var verro = $(document).height();
    $('body').css('min-height', '' + verro + 'px');
} 


function CloseItem() {
    $("#jsaboxcontent").slideUp(250);
    $("#jsaboxcontent").html("");
    setTimeout(function () {
     $("#jsabox").hide();
     $("#jsaboxcontent").show(); },250);
}

function CloseProductPrice() {
    $("#productbox").hide();
    $("#productbox .lightboxcontainer").children().remove();
}

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 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 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 EmailControl(elem) {
    var str = elem;
    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (!str.match(re)) { return false; }
    else { return true; }
}


function BulletinFormClick() {
    
    var FullName = $(".FullName");
    var Email = $(".Email");

    if (FullName.val() == "" || FullName.val() == FullName.attr("OnBlurText")) {
        alert("Ad-Soyad girmediniz");
        return false;
    }
    else if (Email.val() == "" || Email.val() == Email.attr("OnBlurText")) {
        alert("E-Posta adresini girmediniz");
        return false;
    }
    else if (!EmailControl(Email.val())) {
        alert("E-Posta adresi geçersiz");
        return false;
    }
    else {
        return true;
    }

}








