﻿var timer = null;
var timer2 = null;
$().ready(function(){
    if(jQuery.browser.msie && jQuery.browser.version == "6.0")
    {
        $('ul#dd,ul#dd li ul').ifixpng();
    }
    
    $('.cart .items').jScrollPane();
    
    $("body").click(function(evt){
        if ($(evt.target).hasClass("select"))
        {
            return;
        }
        $(".options").hide();
    });
});

var lastSelected = null;
$().ready(function(){
    $("#dd li a.hover").mouseover(function(){                    
        showSub($(this));
    });
    
    $("#dd").mouseover(function(){
        clearTimeout(timer);
        clearTimeout(timer2);
    }).mouseout(function(){
       timer = setTimeout("hideSub()",200); 
    });
    
    $("#dd li ul").mouseover(function(){
            clearTimeout(timer2);
        }).mouseout(function(e){                  
            timer2 = setTimeout("hideSub()",200);
        });        
        
        
    //sag sepet on submit
    $("#form-sagsepetguncelle").submit(function(){    
        var valid = true;
        $("#form-sagsepetguncelle input[name='quantity']").each(function(){            
            if (/^[0-9]+$/.exec($(this).val()) == null)
            {                
                valid = false;
            }            
        });
        
        return valid;
    });
});

function showSub(obj)
{                                
    var sub = null;
    
    if (lastSelected != null)
    {
        lastSelected.css("background", "transparent");
        sub = lastSelected.next();
        if(typeof(sub) != "undefined")
        {
            sub.hide();                        
        }
    }                
    
    lastSelected = obj;                
    sub = obj.next();
    obj.css("background", "#b2a181");
    if(typeof(sub) != "undefined")
    {
        var pos = $("#ddtop").position();
        sub.css("top", pos.top + "px").css("left", pos.left + 145 + "px").css("z-index",100).show();    
    }
}

function hideSub()
{
    if(lastSelected != null)
    {
        lastSelected.css("background", "transparent");
        lastSelected.next().hide();
    }
}

function popitup(url,w,h,scrollbars) {
    newwindow=window.open(url,'name','toolbar=0,scrollbars='+scrollbars+',location=0,statusbar=0,menubar=0,resizable=1,height='+h+',width='+w);
    if (window.focus) {newwindow.focus()}
    return false;
}

var subscribe = function()
{
    var obj = $("#nu_email");
    
    if($.trim(obj.val()) == "")
    {
        return false;
    }
    
    $.post("/newsletter/subscribe.aspx", "nu.email="+obj.val(), function(data){
        if(data.success)
        {
            pop(true, data.message);
        }
        else
        {
            pop(false, data.message);            
        }
        
    }, "json");
    
    return false;
}

var pop = function(info, msg)
{
    var wrapper = $.create("div", {id:"pop",style:"display:none;"})
    var popup = $.create("div").appendTo(wrapper);
    
    if(info)
        popup.attr("class", "popup3");
    else
        popup.attr("class", "popup2");
    
    $.create("a", {"class":"kapat", href:"#", title:"Kapat"}).click(closeModal).appendTo($.create("h1").appendTo(popup));
    $.create("div", {"class":"clear"}).appendTo(popup);
    $.create("div", {"class":"leftwide", "style":"color:#ffffff"}).html(msg).appendTo(popup);
    $.create("div", {"class":"right"}).appendTo(popup);
    
    wrapper.appendTo("body");
    
    tb_show(null,'#TB_inline?height=185&width=356&inlineId=pop',false);
}

var loginbox = function(backto,call)
{
    tb_show(null,'#TB_inline?height=185&width=356&inlineId=dialoglogin',false);
    if(backto != null)
        $("#backto").val(backto);
    if(call != null)
        $("#call").val(call);
        
    return false;
}

//add to bookmarks
function addToBookmarks(title, url) 
{
    try{
    if (window.external && window.external.AddFavorite)
        window.external.AddFavorite( url, title);
    else if (window.sidebar && window.sidebar.addPanel)
        window.sidebar.addPanel(title, url, "");
    }
    catch(err){
    window.external.AddFavorite( url, title);
    }
    
    return false;
}

//gift box selection
var boxSelect = function() {
    var a = document.getElementById("gift");
    if (a.getAttribute("class") != "checked") {
        $("#boxdialog input[value=" + boxid + "]").attr("checked", true);
        $("#boxdialog #giftnote").val(giftnote);

        $("#boxdialog li").bind("click", function() {
            var radio = $("input[type='radio']", this);
            radio.attr("checked", true);
        }).bind("mouseover", function() {
            var temp = $("img", this).attr("src").split("/");
            $("#preview").attr("src", boxImageRootUrl + temp[temp.length - 1]);
        });

        $("#boxdialog input.submit").bind("click", saveBox);

        tb_show(null, '#TB_inline?height=376&width=564&inlineId=boxdialog', false);
        a.setAttribute("class", "checked");
        return false;
    }
    else {
        a.setAttribute("class", "unchecked");
    }
}

var saveBox = function() {
    var radio = $(".popup5 input:checked");
    if (typeof (radio.val()) != "undefined" && radio.val() != null) {
        $("#boxdialog input.submit").unbind("click", saveBox);
        $.post("/sepet/savebox.aspx", "box.id=" + radio.val() + "&giftnote=" + $("#giftnote").val(), function(data) {
            if (data.success) {
                closeModal();
                $("#gift").addClass("checked");
            }
            else {
                $("#boxdialog input.submit").bind("click", saveBox);
                $("#noteerror").html(data.message);
            }
        }, "json");
    }
}

var closeModal = function()
{
    tb_remove();
    return false;
}

//ups kargo takip fonk.
function UpsTakip() {
    popitup("", 640, 480, 1);
}