function autoResize(id) {
    //alert('KOKO');
    var newheight;
    var newwidth;

    if (document.getElementById) {
        newheight = document.getElementById(id).contentWindow.document.body.scrollHeight;
        newwidth = document.getElementById(id).contentWindow.document.body.scrollWidth;
    }

    document.getElementById(id).height = (newheight) + "px";
    document.getElementById(id).width = (newwidth) + "px";
    alert('Høyde :' + newheight + '  Bredde : ' + newwidth);
}

function setIframeHeight(iframe) {
    if (iframe) {
        var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow;
        if (iframeWin.document.body) {
            iframe.height = iframeWin.document.documentElement.scrollHeight || iframeWin.document.body.scrollHeight;
        }
    }
}

function parentScrollTop() {
    parent.window.scroll(0, 0); // horizontal and vertical scroll increments
//scrolldelay = setTimeout('pageScroll()',10); // scrolls every 100 milliseconds
}
function resizeFrame(f) {
    f.style.height = f.contentWindow.document.body.scrollHeight;
}

function goToHkVareid()
{
    URL = document.goToVareid.linjeid.value;
    window.location.href = "index.jsp?s=handlekurv.jsp#" + URL; // I think this is where I'm going wrong is there a different way to state this so that it just jumps to the anchor?
}

function setBgColorFelt(vareid)
{
    var ant = document.getElementById('ant' + vareid).value;
    if (ant > 0)
    {
        document.getElementById('ant' + vareid).style.backgroundColor = "green";
        document.getElementById('ant' + vareid).style.color = "white";
    } else
    if (ant < 0)
        document.getElementById('ant' + vareid).style.backgroundColor = "red";
    else
    {
        document.getElementById('ant' + vareid).style.backgroundColor = "red";
        document.getElementById('ant' + vareid).style.color = "white";
    }
}
function flyttInnkjopAnt(felt) {
    felt2 = "innkjopAnt" + felt;
    felt = "ant" + felt;
    //alert(document.getElementById(felt2).value);
    ant = 0;
    if (document.getElementById(felt2).value < 0)
        ant = document.getElementById(felt2).value;

    document.getElementById(felt).value = ant.replace("-", "");
}
function nullInnkjopAnt(felt) {
    felt = "ant" + felt;
    document.getElementById(felt).value = 0;
}

function subtractQtyVariantSelger(vareid) {
    var antipkBck = document.querySelector('.antipkBck' + vareid).value;
    //alert("subtractQtyVariantSelger" + antipkBck);
    var ant = document.getElementById('ant' + vareid).value;
    //alert("XXXXXXX" + ant);
    if (document.getElementById('ant' + vareid).value - 1 < 1)
    {
        document.getElementById('ant' + vareid).value = 0;
        //document.getElementById('ant' + vareid).value = ant - 1;
    } else
    {
        document.getElementById('ant' + vareid).value = (ant / 2);
    }

    //document.getElementById(felt).value--;
    setBgColorFelt(vareid);

}

function subtractQtyVariant(vareid) {

    var antipkBck = document.querySelector('.antipkBck' + vareid).value;
    //alert(antipkBck);
    var ant = document.getElementById('ant' + vareid).value;
    if (document.getElementById('ant' + vareid).value - 1 < 1)
        document.getElementById('ant' + vareid).value = 0;
    else
    {
        document.getElementById('ant' + vareid).value = eval(ant) - eval(antipkBck);
    }
    setBgColorFelt(vareid);
}
function subtractQtyVariantLocked(vareid) {
    var antipkBck = document.querySelector('.antipkBck' + vareid).value;
    var ant = document.getElementById('ant' + vareid).value;
    if (+(ant) < +(antipkBck)) {
        document.getElementById('ant' + vareid).value = antipkBck;
    } else
    {
        document.getElementById('ant' + vareid).value = eval(ant) - eval(antipkBck);
    }
    //document.getElementById(felt).value--;
    setBgColorFelt(vareid);
}

function addQtyVariant(vareid)
{
    var ant = document.getElementById('ant' + vareid).value;
    var maxLength = document.getElementById('ant' + vareid).getAttribute("maxLength");
    var antipkBck = document.querySelector('.antipkBck' + vareid).value;

    if (+(ant) === 0) {
        if (antipkBck <= maxLength) {
            document.getElementById('ant' + vareid).value = antipkBck;
        }
    } else {
        if (+(ant) > 0) {
            var incCount = (eval(ant) + eval(antipkBck)) + "";
            if ((incCount) <= maxLength) {
                document.getElementById('ant' + vareid).value = eval(ant) + eval(antipkBck);
            }
        } else {
            if ((document.getElementById('ant' + vareid).value + 1)  <= maxLength) {
                document.getElementById('ant' + vareid).value++;
            }
        }
    }
    setBgColorFelt(vareid);
}
function addQtyDefault(vareid)
{
    
    var ant = document.getElementById('ant' + vareid).value;
    var maxLength = document.getElementById('ant' + vareid).getAttribute("maxLength");
    var antipkBck = document.querySelector('.antipkBck' + vareid).value;
    
    if (+(ant) === 0) {
        if (antipkBck <= maxLength) {
            document.getElementById('ant' + vareid).value = antipkBck;
        }
    } else {
        
        if (+(ant) > 0) {
            var incCount = (eval(ant) + eval(1)) + "";
            if (+(incCount) <= maxLength) {
                document.getElementById('ant' + vareid).value = eval(ant) + eval(1);
            }
        } else {
            
            if ((document.getElementById('ant' + vareid).value + 1) <= maxLength) {
                document.getElementById('ant' + vareid).value++;
            }
        }

    }

    setBgColorFelt(vareid);
}
function addQtyVariantSelger(vareid)
{
    var ant = document.getElementById('ant' + vareid).value;
    var maxLength = document.getElementById('ant' + vareid).getAttribute("maxLength");
    var antipkBck = document.querySelector('.antipkBck' + vareid).value;

    if (+(ant) === 0) {
        if (antipkBck <= maxLength) {
            document.getElementById('ant' + vareid).value = antipkBck;
        }
    } else {
        if (+(ant) > 0) {
            var incCount = (eval(ant) + eval(antipkBck)) + "";
            if (+(incCount) <= maxLength) {
                document.getElementById('ant' + vareid).value = eval(ant) + eval(antipkBck);
            }
        } else {
            if ((document.getElementById('ant' + vareid).value + 1) <= maxLength) {
                document.getElementById('ant' + vareid).value++;
            }
        }
    }
    setBgColorFelt(vareid);
}
function addQtyVariantLocked(vareid)
{
    var maxLength = document.getElementById('ant' + vareid).getAttribute("maxLength");
    var ant = document.getElementById('ant' + vareid).value;
    var antipkBck = document.querySelector('.antipkBck' + vareid).value;
    if (+(ant) === 0) {
        if (antipkBck <= maxLength) {
            document.getElementById('ant' + vareid).value = antipkBck;
        }
    } else {
        if (+(ant) > 0) {
            var incCount = (eval(ant) + eval(antipkBck)) + "";
            if (+(incCount) <= maxLength) {
                document.getElementById('ant' + vareid).value = eval(ant) + eval(antipkBck);
            }
        } else {
            if (antipkBck <= maxLength) {
                document.getElementById('ant' + vareid).value = antipkBck;
            }
        }
    }
    setBgColorFelt(vareid);
}

function subtractQtyDefault(vareid) {
    //alert(vareid);
    var ant = document.getElementById('ant' + vareid).value;

    if (+(ant) <= 0)
        document.getElementById('ant' + vareid).value = 0;
    else
        document.getElementById('ant' + vareid).value = (ant - 1);

    setBgColorFelt(vareid);
}

function subtractQtyMinus(vareid) {
    //alert(vareid);
    var ant = document.getElementById('ant' + vareid).value;


    //if (ant <= 0)
    //    document.getElementById('ant' + vareid).value = 0;
    //else
    if (ant - 1 < 1){
        document.getElementById('ant' + vareid).value = 0;
    }else{
        document.getElementById('ant' + vareid).value = (ant - 1);
    }
    

    setBgColorFelt(vareid);
}





function mail_ok()
{
    alert('Mail er sendt.');
}
function mail_feil()
{
    alert('Det skjedde en feil ved sending av mail. Vennligst prøv på nytt');
}

function xsearch(key)
{
    if (key == 120)
    {
        var obj = document.getElementById('div-searchform');
        if (obj.style.visibility == 'visible')
        {
            obj.style.visibility = 'hidden';
        } else
        if (obj.style.visibility == 'hidden')
            obj.style.visibility = 'visible';
        else
            obj.style.visibility = 'visible';
    }
}
function vareIOrdre(sjekk)
{
    if (sjekk == true)
    {
        var agree = confirm("Du har denne varen i ordre. Er du sikker på at du vil legge den til?");
        if (agree)
            return true;
        else
            return false;
    } else
    {
        return false;
    }

}
function slettOrdreLinjes(id, fieldId, errMsg)
{
    document.getElementById(fieldId).style.border = '1px solid blue;';
    var agree = confirm(errMsg + "?");
    if (agree) {

        var count_product = parseInt(parent.$('#productCount').text()) - parseInt(document.getElementById("field_ant" + id).value);
        var count_product_mob = parseInt(parent.$('#productCount_mob').text()) - parseInt(document.getElementById("field_ant" + id).value);
        var amt = document.getElementById("totAmt" + id).innerHTML;
        var shopping_count = parent.$('#totalAmount').text();
        var shopping_count_mob = parent.$('#totalAmount').text();
        var tot_amt = (parseFloat(shopping_count) - parseFloat(amt)).toFixed(2);
        var tot_amt_mob = (parseFloat(shopping_count_mob) - parseFloat(amt)).toFixed(2);

        parent.$('#productCount').html(count_product);
        parent.$('#productCount_mob').html(count_product_mob);
        parent.$('#totalAmount').html(tot_amt);
        parent.$('#totalAmount1').html(tot_amt_mob);
        parent.$('#cart-modal-count').html(count_product);
        parent.$('#cart-modal-price').html(tot_amt);
        return true;
    } else {
        document.getElementById(fieldId).style.border = 'none';
        return false;
    }
}

function cartQuantity(id, prevCount)
{
    var count_product = parseInt(parent.$('#productCount').text()) + (parseInt(document.getElementById("field_ant" + id).value) - parseInt(prevCount));

    var amt = document.getElementById("pris" + id).innerHTML;
    var shopping_count = parent.$('#totalAmount').text();
    var tot_amt = (parseFloat(shopping_count) + (parseFloat(amt) * (parseInt(document.getElementById("field_ant" + id).value) - parseInt(prevCount)))).toFixed(2);

    parent.$('#productCount').html(count_product);
    parent.$('#totalAmount').html(tot_amt);
    parent.$('#cart-modal-count').html(count_product);
    parent.$('#cart-modal-price').html(tot_amt);
    parent.$('cart-modal-count').html(count_product);
    parent.$('cart-modal-price').html(tot_amt);
    return true;

}

function emptyCart(txt)
{
    var agree = confirm(txt);
    if (agree) {
        localStorage.removeItem("orderList"); /* #85zrgbznu Store OrderList in Cookie and implement Hurtigkasse option for the same on session expiry(No Login)*/
        document.getElementById("emptyCartAction").submit();
        parent.$('#productCount').html("0");
        parent.$('#totalAmount').html("0.00");
        parent.$('#cart-modal-count').html("0");
        parent.$('#cart-modal-price').html("0.00");
        parent.$('cart-modal-currency').html("NA");
        parent.$('cart-modal-count').html("0.00");
        parent.$('cart-modal-price').html("0.00");
        parent.$('order-details-info').html("");
    }else{
        closeInnerOverlay();
    }
}

function deleteRecord()
{
    var agree = confirm("Er du sikker på at du vil slette element?");
    if (agree)
        return true;
    else
        return false;

}

function deleteFileparkUser()
{
    var agree = confirm("Er du sikker på at du vil slette brukeren? All backupdata slettes permanent!");
    if (agree) {
        var agree2 = confirm("Er du helt sikker?");
        if (agree2)
            return true;
    } else
        return false;

}



function sjekkVareReg(form)
{

    //var agree=confirm("Er du sikker på at du vil tï¿½mme handlekurven?");
    if (document.vareForm.kvalitet.value.length <= 1)
    {
        alert('Du må fylle ut kvalitet');
        document.vareForm.kvalitet.focus();
        return false;
    } else
    if (document.vareForm.sokenavn.value.length <= 1)
    {
        alert('Du må fylle ut varenavn');
        document.vareForm.sokenavn.focus();
        return false;
    } else
    if (document.vareForm.enhetsalg.value.length <= 1)
    {
        alert('Du må fylle ut enhetsalg eks X-XL');
        document.vareForm.enhetsalg.focus();
        return false;
    } else
    if (document.vareForm.antipakning.value.length <= 1)
    {
        alert('Du må fylle ut antipakning eks. 8');
        document.vareForm.enhetsalg.focus();
        return false;
    }
    if (document.vareForm.levNettoPris.value.length <= 1 || document.vareForm.levNettoPris.value == '0.00')
    {
        alert('Du må fylle ut levNettoPris');
        document.vareForm.levNettoPris.focus();
        return false;
    } else
        return true;

}

function slettVedlegg()
{
    var agree = confirm("Er du sikker på at du vil slette vedlegget?");

    if (agree)
        return true;
    else
        return false;

}

function ok_click()
{
    remote('main.html?T=5&K=0');
    self.window.close();
}
function remote(url)
{
    window.opener.location = url;
    self.window.close();
}

function openwindow1(url)
{
    open(url, 'remote', 'width=350,height=70,top=100,left=100, resizable=no');
}

function openwindow2(url)
{
    open(url, 'remote', 'width=600,height=300,top=100,left=100, resizable=yes');
}

function chk_kontakt(form)
{
    if (!form.navn.value.length > 0)
    {
        alert('Skriv inn navnet ditt!');
        form.navn.focus();
        return false;
    } else
    if (form.PASSORD.value.length < 4)
    {
        alert('Passordet må være minst 4 tegn!');
        form.PASSORD.focus();
        return false;
    } else
    if (form.PASSORD1.value != form.PASSORD.value)
    {
        alert('Passordene mï¿½ vï¿½re like!');
        form.PASSORD1.focus();
        return false;
    }
}

function chk_kontakt2(form)
{
    if (form.PASSORD.value.length < 4)
    {
        alert('Passordet må være minst 4 tegn!');
        form.PASSORD.focus();
        return false;
    } else
    if (form.PASSORD1.value != form.PASSORD.value)
    {
        alert('Passordene må være like!');
        form.PASSORD1.focus();
        return false;
    }
}

function chk_stat(form)
{

    if (form.statt_faktdato.value == "" || form.statt_faktdato.value.indexOf('/', 0) == -1)
    {
        alert('Feil i dato format!');
        form.statt_faktdato.focus();
        form.statt_faktdato.value = "01/01/1900";
        form.statt_faktdato.select();
        return false;
    } else
    if (form.statt_faktdato2.value == "" || form.statt_faktdato2.value.indexOf('/', 0) == -1)
    {
        alert('Feil i dato format!');
        form.statt_faktdato2.focus();
        form.statt_faktdato2.value = "30/12/2100";
        form.statt_faktdato2.select();
        return false;
    } else
    if (form.statt_faktnr.value == "" || form.statt_faktnr.value.length > 8)
    {
        alert('Søkebegrep må ha en tallverdi, max 8 tegn!');
        form.statt_faktnr.focus();
        form.statt_faktnr.value = "0";
        form.statt_faktnr.select();
        return false;
    } else
    if (form.statt_faktnr2.value == "" || form.statt_faktnr2.value.length > 8)
    {
        alert('Søkebegrep må ha en tallverdi, max 8 tegn!');
        form.statt_faktnr2.focus();
        form.statt_faktnr2.value = "9999999";
        form.statt_faktnr2.select();
        return false;
    } else
    if (form.statt_ordrenr.value == "" || form.statt_ordrenr.value.length > 8)
    {
        alert('Søkebegrep må ha en tallverdi, max 8 tegn!');
        form.statt_ordrenr.focus();
        form.statt_ordrenr.value = "0";
        form.statt_ordrenr.select();
        return false;
    } else
    if (form.statt_ordrenr2.value == "" || form.statt_ordrenr2.value.length > 8)
    {
        alert('Søkebegrep må ha en tallverdi, max 8 tegn!');
        form.statt_ordrenr2.focus();
        form.statt_ordrenr2.value = "9999999";
        form.statt_ordrenr2.select();
        return false;
    } else
    if (form.statt_varenr.value == "" || form.statt_varenr.value.length > 15)
    {
        alert('Søkebegrep, max 15 tegn!');
        form.statt_varenr.focus();
        form.statt_varenr.value = "0";
        form.statt_varenr.select();
        return false;
    } else
    if (form.statt_varenr2.value == "" || form.statt_varenr2.value.length > 15)
    {
        alert('Søkebegrep, max 15 tegn!');
        form.statt_varenr2.focus();
        form.statt_varenr2.value = "999999999999999";
        form.statt_varenr2.select();
        return false;
    }
}


function chk_selger(form)
{
    /*
     if (!form.EMAIL.value.length > 0)
     {
     alert('Skriv inn emailadressen din!'); form.EMAIL.focus(); return false;
     }
     else
     if (!form.NAVN.value.length > 0)
     {
     alert('Skriv inn navnet ditt!'); form.NAVN.focus(); return false;
     }
     else
     */
    if (form.PASSORD.value.length < 5)
    {
        alert('Passordet må være minst 5 tegn!');
        form.PASSORD.focus();
        return false;
    } else
    if (form.PASSORD1.value != form.PASSORD.value)
    {
        alert('Passordene må være like!');
        form.PASSORD1.focus();
        return false;
    }
}

function lukk_glm_pass(form)
{
    if (form.glemt_passord.value == "" || form.glemt_passord.value.indexOf('@') == -1 || form.glemt_passord.value.indexOf('.') == -1)
    {
        alert('Skriv inn en gyldig epost adresse!');
        form.glemt_passord.focus();
        return false;
    } else
    {
        remote('../main.html?glemt_passord=' + form.glemt_passord.value);
        self.window.close(true);
        return true;
    }
}

function chkHK(form)
{
    for (i = 0; i < document.HK_BONG.length; i++)
    {
        if (document.HK_BONG[i].bong_vnr.value == form.vareid.value)
        {
            alert("Varenummer " + form.vareid.value + " Finnes i handlekurven!");
            return false;
        }
    }
    return true;
}

