﻿/// <reference path="jquery-1.3.2-vsdoc.js/>


function chkfocus(id) {



}

/** Paloma Logic **/

addSubscriptionTo = function(id) {
    $(document).ready(function() {
        $.ajax({
            type: "POST",
            url: "/AjaxPaloma.aspx",
            data: { AddToSub: id },
            cache: false,
            success: function(resp) {
                $(".changesub").attr('disabled', false);
            }
        });
    });
}

cancelSubscriptionFrom = function(id) {
    $(document).ready(function() {
        $.ajax({
            type: "POST",
            url: "/AjaxPaloma.aspx",
            data: { cancelSub: id },
            cache: false,
            success: function(resp) {
               $(".changesub").attr('disabled', false);
            }
        });
    });
}

updateSubscription = function(el){
    var id = $(el).attr("id");
    if ($(el+':checked').val() != null) {
        $(".changesub").attr('disabled', true);
        addSubscriptionTo(id);        
    } else {
        $(".changesub").attr('disabled', true);
        cancelSubscriptionFrom(id);
    }
}

getAvailableNewsLetters = function() {
    $.ajax({
        type: "POST",
        url: "/AjaxPaloma.aspx",
        cache: false,
        data: { getNewsList: "now" },
        success: function(resp) {
            $(".letteritems").html(resp);
            $(".letteritems").fadeIn("slow");
        }

    });
}

/** End Paloma Logic **/

function registerToNewsletter() {
    var add = new Array();

    if (!$('#deregister').attr('checked')) {

        $("input[type=checkbox]").each(
            function() {
                var id = $(this).attr('id');
                if (id != "deregister") {
                    //alert($(this).attr('id'));
                    if ($(this).attr('checked')) {
                        add.push(id);
                    }

                }
            }
        );
        var email = $("#news_mail").val();
        if (email != "") {
            if (add.length > 0) {
                $.ajax({
                    type: "POST",
                    url: "/Ajax.aspx",
                    data: { Signup: email, Newsletters: add, type: "add" },
                    success: function(resp) {
                        $("#newsletter_response").show();
                        if (resp != "none")
                            $("#newsletter_response").html("Du har registrerats för nyhetsbreven du valt");
                        else
                            $("#newsletter_response").html("Du valde ej några nyhetsbrev att registrera dig till!");
                    }

                });
            } else {
                $("#newsletter_response").html("Du valde ej några nyhetsbrev att registrera dig till!");
            }
        } else {
            $("#newsletter_response").show();
            $("#newsletter_response").html("Du har inte angett en e-postadress!");
        }




    } else {
        $("input[type=checkbox]").each(
            function() {
                var id = $(this).attr('id');
                if (id != "deregister") {
                    //alert($(this).attr('id'));
                    if ($(this).attr('checked')) {
                        add.push(id);
                    }

                }
            }
        );
        var email = $("#news_mail").val();
        if (email != "") {
            if (add.length > 0) {
                $.ajax({
                    type: "POST",
                    url: "/Ajax.aspx",
                    data: { Signup: email, Newsletters: add, type: "remove" },
                    success: function(resp) {
                        $("#newsletter_response").show();
                        if (resp != "none")
                            $("#newsletter_response").html("Du har avregistrerat dig från de nyhetsbrev du valt");
                        else
                            $("#newsletter_response").html("Du valde ej några nyhetsbrev att avregistrera dig ifrån!");
                        //alert(resp);
                    }

                });
            } else {
                $("#newsletter_response").html("Du valde ej några nyhetsbrev att avregistrera dig ifrån!");
            }
        } else {
            $("#newsletter_response").show();
            $("#newsletter_response").html("Du har inte angett en e-postadress!");
        }


    }

    return false;
}

function showerror(err) {
    //alert(err);
    $("#loginfail").hide();
    $("#loginerror").slideDown("slow");
    //$(".ip").effect("shake", { times: 3 }, 300);
}
function loginfailed() {
    $("#loginerror").hide();
    $("#loginfail").slideDown("slow");
}

function campaign(url) {
    var c = "";
    if ($(".kampanj").val() == "")
        c = "not-specified";
    else
        c = $(".kampanj").val();
    location.href = url + "?campaign=" + c;
}

function goSite() {

    location.href = $("select[id$=ourBars]").val();
}

function accountExpired() {
    $(".login_p").hide("slow");
    $(".expire_p").show("slow").text("Your account has expired!");
}

function ViewProducerInfo(prodid) {
    window.open('/ViewProducerInfo.aspx?prodid=' + prodid, 'ProducerDetail', 'width=600,height=500,scrollbars=yes,resizable=no')
}


function countwines() {
    $.ajax({
        type: "POST",
        url: "/Ajax.aspx",
        data: { countwines: "now" },
        success: function(resp) {
            $("#cwines").html(resp);
            //alert(resp);
        }

    });
}

function login() {
    $(document).ready(function() {
        //$('ctl00_ctl00_doLogin').click(function() {

        var usr = $('#username').prop("value");
        var pwd = $('#password').prop("value");

        $.ajax({
            type: "POST",
            url: "/Ajax.aspx",
            data: "login=" + usr + "&p=" + pwd,
            success: function(resp) {
                if (resp == "loginfailed")
                    loginfailed();
                else if (resp == "expired"){
                    $.ajax({
                        type: "POST",
                        url: "/Ajax.aspx",
                        cache: false,
                        data: { renewurl: "now" },
                        success: function(resp) {
                            $(".renewerror").html(resp);
                            showerror('');
                        }
                    });
                    
                }
                else {
                    window.location.href = '/default.aspx';
                }
            }

        });
        return false;

    });
}
$('.loginbutton').live('click', function() {
  $("a[rel]").overlay({
                    // start exposing when overlay starts to load 
                    onBeforeLoad: function() {
                        // this line does the magic. it makes the background image sit on top of the mask 
                        this.getBackgroundImage().expose({
                            color: '#FFF',
                            loadSpeed: 0
                        });
                    },

                    // when overlay is closed take the expose instance and close it as well 
                    onClose: function() {
                        $.expose.close();
                        // window.location.href = 'default.aspx';
                    }

                });
});

function showLogin() {

  
}

$(function() {

    // initialize overlay trigger 
    $("a[rel]").overlay({
        // start exposing when overlay starts to load 
        onBeforeLoad: function() {
            // this line does the magic. it makes the background image sit on top of the mask 
            this.getBackgroundImage().expose({
                color: '#FFF',
                loadSpeed: 0
            });
        },

        // when overlay is closed take the expose instance and close it as well 
        onClose: function() {
            $.expose.close();
            // window.location.href = 'default.aspx';
        }

    })
});

function getQuerystring(key, default_) {
    if (default_ == null) default_ = "";
    key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
    var qs = regex.exec(window.location.href);
    if (qs == null)
        return default_;
    else
        return qs[1];
}

function loginInfo() {
    $(document).ready(function() {
        $.ajax({
            type: "POST",
            url: "/Ajax.aspx",
            cache: false,
            data: { isloggedin: "now" },
            success: function(resp) {            
            
                $("#login-status").html(resp);
                $("a[rel]").overlay({
        // start exposing when overlay starts to load 
                onBeforeLoad: function() {
                    // this line does the magic. it makes the background image sit on top of the mask 
                    this.getBackgroundImage().expose({
                        color: '#FFF',
                        loadSpeed: 0
                    });
                },

                // when overlay is closed take the expose instance and close it as well 
                onClose: function() {
                    $.expose.close();
                    // window.location.href = 'default.aspx';
                }

            });
                //alert(resp);
            }

        });
    });
}



function showMessage(txt) {

    var animStyle = 'slide';


}


function checkpassword() {
    var old = $('#ctl00_ctl00_pagecontent_innercontent_ctrl6_oldpwd').attr('value');
    var newp = $('#ctl00_ctl00_pagecontent_innercontent_ctrl6_newpwd').attr('value');
    var newp2 = $('#ctl00_ctl00_pagecontent_innercontent_ctrl6_newpwd2').attr('value');

    if (old != "" && newp != "" && newp2 != "") {
        $('#generalerror').text("");
        if (newp != newp2) {
            $('#_newpwd').text("Password doesn't match");
            $('#_newpwd2').text("Password doesn't match");
            return false;
        } else {
            $('#_newpwd').text("");
            $('#_newpwd2').text("");
        }

        return true;
    } else {
        $('#generalerror').text("You must fill in all forms");
    }
    return false;
}


