﻿
function fnSwapFaq(id) {
    $(".faq .con").hide();
    $(".faq .con[rel='" + id + "']").show();
}

function PasswordChange(change) {
    var id = $("[id$=_divPasswordChange]").attr("id");
    $("#" + id + " input").val("");
    if (change) {
        $("#" + id).show();
        $("#" + id + " input:first").focus();
    } else {
        $("#" + id).hide();
    }
}

function PasswordRecover(uniqueID){ 
    var email = $("[id$=_txtEmailAddress]").attr("id");
    var value = $("#" + email).val();
    
    if (value.length == 0) { 
        return false; 
    } else { 
        __doPostBack(uniqueID, '');
    }
}

function Login(uniqueID){ 
    var email = $("[id$=_txtLogin]").val();
    var password = $("[id$=_txtPassword]").val();

    if (email.length == 0 && password.length == 0) { 
        return false; 
    } else { 
        __doPostBack(uniqueID, '');
    }
}

function DoSearch(uniqueID) {
    var search = $("[id$=_txtSearch]").val();

    if (search.length < 1) {
        alert('Er is geen zoekterm opgegeven.');
        return false;
    } else {
        __doPostBack(uniqueID, '');
    }
}

function DoStoreSearch(uniqueID) {
    var zipcode = $("[id$=_txtZipCode]").val();
    var city = $("[id$=_txtPlace]").val();

    if (zipcode.length < 4 && city.length < 3) {
        alert('Vul een geldige postcode en / of een plaatsnaam in a.u.b.');
        return false;
    } else {
        __doPostBack(uniqueID, '');
    }
}

function DoStoreSearchPullDown(uniqueID) {
    var zipcode = $("[id$=_txtStoreZipCode]").val();
    var city = $("[id$=_txtStoreCity]").val();

    if (zipcode.length < 4 && city.length < 3) {
        alert('Vul een geldige postcode en / of een plaatsnaam in a.u.b.');
        return false;
    } else {
        __doPostBack(uniqueID, '');
    }
}

function LoginSideBar(uniqueID){ 
    var email = $("[id$=_txtEmail]").val();
    var password = $("[id$=_txtPassword]").val();
 
    if (email.length == 0 && password.length == 0) { 
        return false; 
    } else { 
        __doPostBack(uniqueID, '');
    }
}

function ShippingEqualsInvoice(val) {
    var inv = $("#addresses .invoice");
    var ship = $("#addresses input:text");
    for(var i = 0; i < inv.length; i++) {
        var invoiceValue = inv.eq(i);
        var shipValue = ship.eq(i);
        if (val) {
            ship.eq(i).attr("disabled", "disabled");
            shipValue.val(invoiceValue.html());
            
        } else {
            ship.eq(i).removeAttr("disabled");
        }
    }
    if (val) {
        $("#ctl00_cphMain_ddlCountry").attr("disabled", "disabled");
        $('#ctl00_cphMain_ddlCountry').val($("#ctl00_cphMain_hfInvoice_Country").val())
        __doPostBack('ddlCountry', '');
    } else {
        $("#ctl00_cphMain_ddlCountry").removeAttr("disabled");
    }
}

function AutoFill(selector, text) {
    $(selector).attr({ value: text }).focus(function() { 
		if($(this).val()==text){ $(this).val(""); }}).blur(function(){
		if($(this).val()==""){ $(this).val(text); }
	});
}

function openPrintWin(type) {
    var W = 722;
    var H = 550;
    var L = ($(window).width() - W) / 2;
    var T = ($(window).height() - H) / 2;
    day = new Date();
    id = day.getTime();
    var sRef = "/Print" + type + "Content.htm";
    eval("page" + id + " = window.open(sRef, '" + id + "', 'toolbar=1,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width='+W+',height='+H+',left ='+L+',top ='+T+'');");
}

function fnSwitchSearchImg(id) {
    $(".divImgPackage, .divImgColorMethod, .divImgIngredients").hide();
    switch (id) {
        case 1:
            $(".divImgPackage").show();
            break;
        case 2:
            $(".divImgColorMethod").show();
            break;
        case 3:
            $(".divImgIngredients").show();
            break;
    }
    
}

function fnGotoCountry(obj) {
    var _url = $(obj).val();
    if (_url != "") { document.location.href = $(obj).val(); }
}

function SetProductImageType(arg) {
    for (n = 1; n < 4; n++) {
    
        var e = $("[id$=_imgTeaProduct" + n + "]");
        if (e) {
            if (n == arg) {
                for (var i = 0; i < e.length; i++) 
                {
                    e[i].style.display = "block"; 
                }
            } else {
                for (var i = 0; i < e.length; i++) 
                {
                    e[i].style.display = "none"; 
                }
            }
        }

        var e = $("[id$=_imgCoffeeProduct" + n + "]");
        if (e) {
            if (n == arg) {
                for (var i = 0; i < e.length; i++) 
                {
                    e[i].style.display = "block";
                }
            } else {
                for (var i = 0; i < e.length; i++) 
                {
                    e[i].style.display = "none";
                }
            }
        }
    }
}

var _currHistoryOrderID = 0;
function fnShowOrder(id) {
    if (_currHistoryOrderID != 0) {
        $('table[rel="' + _currHistoryOrderID + '"]').hide();
        $('a[rel="' + _currHistoryOrderID + '"]').html("+");
    }
    $('table[rel="' + id + '"]').show();
    $('a[rel="' + id + '"]').html("-");
    _currHistoryOrderID = id;
}

function limitChars(textarea, limit, infodiv) {
    var text = textarea.value;
    var textlength = text.length;
    var info = document.getElementById(infodiv);
    if (textlength > limit) {
        info.innerHTML = 'U kunt hier maximaal ' + limit + ' tekens opgeven!';
        textarea.value = text.substr(0, limit);
        return false;
    } else {
        info.innerHTML = 'U kunt nog ' + (limit - textlength) + ' tekens opgeven.';
        return true;
    }
}
