
    var bShow=true;

    function checkmail() {

        var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)|(\s)/;
        var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
        if (((!reg1.test(this) && reg2.test(this)) || this == "") && this.length >=6) {
            return true;
        } else {
            return false;
        }
    }

    String.prototype.isValidEmail = checkmail;

    function validateEmail(emailInput) {
        if (emailInput.value.isValidEmail() == true) {
            return emailInput.style.color = "black";
        } else {
            return emailInput.style.color = "red";
        }
    }

    function validateEmailAlert(emailx) {

        if (emailx.value.isValidEmail() == true) {
            return true;
        } else {
            alert('Ikke en gyldig email-adresse : "' + emailx.value + '".');
            return false;
        }
    }

    function showWnd(pURL) {
        window.open(pURL, "_blank", "width=500,height=500,menu=yes,toolbar=yes,scrollbars=yes,resizable=allow");
    }


    function showWndSize(pURL, wINT, hINT) {
        window.open(pURL, "_blank", "width=" + wINT + ",height=" + hINT + ",menu=yes,toolbar=yes,scrollbars=yes,resizable=allow");
    }


    function showTv(tvid) {
        window.open(TAENK_URL_ABS+"popup.php?cid="+tvid, "_blank", "width=730,height=600,menu=no,toolbar=no,scrollbars=yes,resizable=allow");
    }


    function showTables(idvar) {
        if(document.getElementById(idvar).src==TAENK_URL_ABS+'images/valgbar.png'){
            document.getElementById(idvar).src=TAENK_URL_ABS+'images/valgt.png';
        } else {
            document.getElementById(idvar).src=TAENK_URL_ABS+'images/valgbar.png';
        }
        for(loop=0; loop < 200; loop++) {
            var elID = idvar + "s" + loop;
            if(document.getElementById(elID)){
                if(document.getElementById(elID).style.display == "none"){
                    document.getElementById(elID).style.display ="";
                } else {
                    document.getElementById(elID).style.display = "none";
                }


            }
        }
    }


    function showTable(idvar){
        if(document.getElementById(idvar).style.display == "none"){
            document.getElementById(idvar).style.display ="block";
        } else {
            document.getElementById(idvar).style.display = "none";
        }
    }


    function showOneTable(idvar){
        if(document.getElementById(idvar).src==TAENK_URL_ABS+'images/valgbar.png'){
            document.getElementById(idvar).src=TAENK_URL_ABS+'images/valgt.png';
        } else {
            document.getElementById(idvar).src=TAENK_URL_ABS+'images/valgbar.png';
        }
        var elID = "t" + idvar;
        if(document.getElementById(elID).style.display == "none"){
            document.getElementById(elID).style.display ="block";
        } else {
            document.getElementById(elID).style.display = "none";
        }

    }


    function gallery(idshow, imgcount){
        var showID = "t" + idshow;
        for(i=0; i < imgcount; i++){
            document.getElementById("t"+i).style.display = "none";
        }
        document.getElementById(showID).style.display = "";
    }


    function printPage() {
        var sURL = (""+location.href).replace("index.php", "print.php");
        sURL = sURL.replace("sid=", "print=1&sid=");
        window.open(sURL, "_blank", "width=660,height=500,menu=yes,toolbar=yes,scrollbars=yes,resizable=1");
    }


    function showImage(pID) {
        var sURL = "image.php?ID=" + pID;
        window.open(sURL,"_blank","toolbar=no,menu=no,scrollbars=yes,width=500,height=400");
    }


    function displayPopup(pPopup) {
        var oPopup, spanCount=2;

        if (pPopup != "") {
            if(document.getElementById(pPopup).style.display=="") {
                if (document.getElementById(pPopup).style.display == "none")
                    bShow=true;
                else
                    bShow=false;
                document.getElementById(pPopup).style.display = "none";
                return;
            }
        }

        for (i=1;i<=spanCount;i++){
            oPopup = document.getElementById("Span"+i);
            oPopup.style.display = "none";
        }

        if ((pPopup != "") && (bShow)) {
            if (document.getElementById(pPopup).style.display != "none") {
                document.getElementById(pPopup).style.display = "none";
                document.getElementById(pPopup).style.visibility = "hidden";
                bShow=false;
            }
            else {
                document.getElementById(pPopup).style.display = "block";
                document.getElementById(pPopup).style.visibility = "visible";
                bShow=true;
            }
        }
    }


    var button = "";
    var number = /[0-9]/;

    function checkForm(theform) {
        if (theform.elements["name"].value.length <= 1) {
            alert("Indtast venligst dit fornavn.");
            return false;
        } else if (!theform.elements["accept"].checked) {
            alert("Du skal acceptere vores betingelser for at handle i ShopTænk.");
            return false;
        } else if (theform.elements["ename"].value.length <= 1) {
            alert("Indtast venligst dit efternavn.");
            return false;
        } else if (theform.elements["adr"] != null && theform.elements["adr"].value.length <= 1) {
            alert("Indtast venligst din adresse.");
            return false;
        } else if (theform.elements["husnr"] != null && theform.elements["husnr"].value.length < 1) {
            alert("Indtast venligst dit husnr i det rette felt.");
            return false;
        } else if (theform.elements["post"] != null && theform.elements["post"].value.length <= 1) {
            alert("Indtast venligst dit postnummer.");
            return false;
        } else if (theform.elements["email"].value.length <= 1) {
            alert("Indtast venligst din email-adresse.");
            return false;
        } else if (theform.elements["tlf"] != null && theform.elements["tlf"].value.length <= 5) {
            alert("Indtast venligst dit telefonnummer.");
            return false;
        } else if (theform.elements["email"].value.indexOf("@") == -1) {
            alert("Indtast venligst en gyldig e-mail adresse.");
            return false;
        } else if (theform.elements["email"].value.indexOf(".") == -1) {
            alert("Indtast venligst en gyldig e-mail adresse.");
            return false;
        } else if (theform.elements['nyModtager'].value > 0) {
            if (theform.elements["m_name"].value.length <= 1) {
                alert("Du skal indtaste modtagers fornavn!");
                return false;
            } else if (theform.elements["m_ename"].value.length <= 1) {
                alert("Du skal indtaste modtagers efternavn!");
                return false;
            } else if (theform.elements["m_adr"].value.length <= 1) {
                alert("Du skal indtaste modtagers adresse!");
                return false;
            } else if (theform.elements['m_husnr'].value.search(number)==-1) {
                alert("Du skal indtaste modtagers husnummer!");
                return false;
            } else if (theform.elements["m_post"].value.length <= 1) {
                alert("Du skal indtaste modtagers postnummer!");
                return false;
            } else if (theform.elements["m_tlf"].value.length <= 1) {
                alert("Du skal indtaste modtagers telefonnummer!");
                return false;
            }
        } else if (theform.elements["adr"] != null && theform.elements["adr"].value.length <= 1 && theform.elements["test"].value > 1) {
                alert("Du skal indtaste din adresse!");
                return false;
        } else if (theform.elements["husnr"] != null && theform.elements['husnr'].value.search(number)==-1 && theform.elements["test"].value > 1) {
                alert("Du skal indtaste dit husnummer!");
                return false;
        } else {
                theform.submit();
        }
    }


    function nyModtager(theform){
        if(theform.elements['nyModtager'].value > 0){
            theform.elements['nyModtager'].value = 0;
            theform.elements['m_name'].value = "";
            theform.elements['m_ename'].value = "";
            window.document.getElementById('modtagerlink').innerHTML = "Hvis modtageren er en anden end betaler kan du trykke her for at indtaste modtagerdata.";
        } else {
            theform.elements['nyModtager'].value = 2;
            window.document.getElementById('modtagerlink').innerHTML = "Tryk her, hvis forsendelsen skal sendes til betalers adresse";
        }
    }
    function toggleSubCategories(toggle_id, toggler_id, img_closed, img_open) {
      var el = document.getElementById(toggle_id);
      var el2 = document.getElementById(toggler_id);
      if (el.style.display=="none") {
        el.style.display = "block";
        //el2.style.backgroundImage = 'url('+img_open+')';
        el2.src = img_open;
      }
      else {
        el.style.display = "none";
        //el2.style.backgroundImage = 'url('+img_closed+')';
        el2.src = img_closed;
      }
    }

    function createCookie(name, value, days) {
        if (days) {
            var date = new Date();
            date.setTime(date.getTime() + (days*24*60*60*1000));
            var expires = "; expires=" + date.toGMTString();
        } else {
            var expires = "";
        }
        document.cookie = name+"="+value+expires+"; path=/";
    }

    function readCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ') {
                c = c.substring(1, c.length);
            }
            if (c.indexOf(nameEQ) == 0) {
                return c.substring(nameEQ.length, c.length);
            }
        }

        return false;
    }
