﻿var LoadingTxt = "<img src='Images/Loading.gif' style='width:15px;'> ";
$(document).ready(function(){

    $(".Bltn_inputtext").focus(function(){
        $(this).css("background-color","#fff");
    }).blur(function(){
        $(this).css("background-color","#ECEBE7");
    });
    
    $(".Menu").find("div").click(function(){
        var rel = $(this).attr("rel");
        var Hid = $("#" + rel).css("display");
        var thisTxt = $("#" + rel).text();
        
        if ( thisTxt == "" ) {
            $("#" + rel).html("<div class='NoProduct'>Bu kategoriye ait ürün bulunamadı.</div>")
        }
        
        
        if ( Hid == "none" ) {
             $("#" + rel).parent().find(".MenuItems").slideUp("fast").animate({marginLeft: "0px"},100);
             $("#" + rel).slideDown("fast");
             $("#" + rel).animate({marginLeft: "5px"},50);
             $("#" + rel).animate({marginLeft: "10px"},100);
        }
        else {
             $("#" + rel).animate({marginLeft: "0px"},100);
             $("#" + rel).slideUp("fast");
        }

        
        var href = $(this).attr("href");
        if ( href != null ) {
            Redirect(href);
        } 

    });
    
    $(".ProductDocument").each(function(){
        var type = $(this).attr("type");
        $(this).css("background-image","url('Images/Icons/" + type + ".gif')");   
    });
    
    
   $("#Map").lightBox();
   $("img[rel=lightbox]").css("cursor","pointer").lightBox();
   $("div[ds=ProductTable]").css("cursor","pointer").lightBox();
   

    // ' Bülten
    
    $("#AddBltn").click(function(){
        
        var FullName = $("#FullName").val();
        var CompanyName = $("#CompanyName").val();
        var Email = $("#Email").val();
        
        ContextBorder("FullName","red","#076689");
        ContextBorder("Email","red","#076689");
        
        if ( EmailControl(Email) ) {
            if ( Empty(FullName) && Empty(Email) ) {
                $("#BltnFormControl").html(LoadingTxt + "Kaydediliyor...");
	            $.ajax({
	                   type:"POST",
	                   data:"FullName=" + FullName + "&CompanyName=" + CompanyName + "&Email=" + Email,
	                   url:"App_Control/AddBltn.aspx",
	                   success:function(reply){
	                        $("#BltnFormControl").html(reply)
                            $("#FullName").val("");
                            $("#CompanyName").val("");
                            $("#Email").val("");
	                     }
	            });  
            }
        }
        else {
            if ( Empty(Email) ) {
                $("#BltnFormControl").html("E-Posta adresi geçersiz")
            }
        }
        
    });
        
    // ' //// Bülten
    $(".ProductImagesBig a").lightBox();
    $(".ProductImagesSmall img").click(function(){
        $("#ProductImagesBigPic").attr("src",$(this).attr("thisBig"));
        $("#ProductImagesBigPicA").attr("href",$(this).attr("thisA"))
        $(".ProductImagesBig a").lightBox();
    });

    $(".NewsImagesBig a").lightBox();
    $(".NewsImagesSmall img").click(function(){
        $("#NewsImagesBigPic").attr("src",$(this).attr("thisBig"));
        $("#NewsImagesBigPicA").attr("href",$(this).attr("thisA"))
        $(".NewsImagesBig a").lightBox();
    });


    $("#ProductVideo").click(function(){
        var videoURL = "video.aspx?u=" + $(this).attr("thisVideo")
        Popup(videoURL,"Video","width=420,height=380")
    });
    
   $("#ProductDetailsPrint").click(function(){
        var thisID = $(this).attr("thisID");
        var PageURL = "Print.aspx?ID=" + thisID
        Popup(PageURL,"Yazıcı Dostu Sayfa","width=700,height=600,scrollbars=1");
   });
   
    
    $(".ProductFormTitle").click(function(){
        $(".ProductFormContent").slideToggle("fast");
    })
    
});


function Redirect(href) {
    window.location = href;
}
function Empty(Txt) {
    if ( Txt == "" ) {
        return false;
    }
    else {
        return true;
    }
}
function ContextBorder(thisID,Error,Info) {
    if ( Empty($("#" + thisID).val()) ) {
        $("#" + thisID).css("border","solid 1px " + Info);     
    } 
    else {
        $("#" + thisID).css("border","solid 1px " + Error);      
    }
}
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 OpenParentMenu(OverTag) {

    OverTag.show();
    var NewTag = OverTag.parent()
    NewTag.css("margin-left","10px")
    var uID = NewTag.attr("uID");
    if ( uID != 0 ) {
        OpenParentMenu(NewTag);
    } 
    else {
        NewTag.show();
    }
    
}


function Popup(URL,Name,W) {
    window.open (URL,name,W); 
}