function searchE(e) {
    e = e || window.event;
    if (e) {
        var charCode = (e.charCode) ? e.charCode :
                   ((e.keyCode) ? e.keyCode :
                   ((e.which) ? e.which : 0));
        if (charCode == 13) {
            window.location = "search.aspx?fritekst=" + document.getElementById("txtSok").value;
            e.preventDefault ? e.preventDefault() : e.returnValue = false;
        }
    }
}
function searchB(e) {
    window.location = "search.aspx?fritekst=" + document.getElementById("txtSok").value;
}
function visBilde(img) {    
    var imgMain = $get('imgMain');    
    imgMain.src = img.src.replace('&t=1', '');
    imgMain.alt = "main" + img.id;    
    $get('lnkimgMain').href = img.src.replace('&t=1', '');
    var imgMainText = $get('imgMainText');    
    if (img.title == '') {
        imgMainText.style.display = 'none';
    } else {
        imgMainText.style.display = '';
    }
    document.all ? imgMainText.innerText = img.title : imgMainText.textContent = img.title;
    //if (imgMainText.style.display == 'none') { imgMainText.style.display = '' }
    if (imgMain.style.display == 'none') { imgMain.style.display = '' }

    checkNextPrev();
}
function prevImage() {
    //finne ut hva som er "gjeldende" bilde akkurat nå
    var imgSmall = $get('imgMain').alt.replace('main', '');

    //finne ut om det finnes bilder "før" dette bildet i datalisten
    var currIndex = imgSmall.substr(imgSmall.length - 1, 1)
    var prevIndex = new Number(currIndex) - 1;
    var prevImgSmall = $get('img_' + prevIndex.toString());
    if (prevImgSmall != null) {
        //sender bilde som parameter til visBilde()
        visBilde(prevImgSmall);
    }
    else {
        alert('prevImgSmall not found');
    }
}
function nextImage() {
    //finne ut hva som er "gjeldende" bilde akkurat nå
    var imgSmall = $get('imgMain').alt.replace('main', '');

    //finne ut om det finnes bilder "etter" dette bildet i datalisten
    var currIndex = imgSmall.substr(imgSmall.length - 1, 1)
    var nextIndex = new Number(currIndex) + 1;
    var nextImgSmall = $get('img_' + nextIndex.toString());
    if (nextImgSmall != null) {
        //sender bilde som parameter til visBilde()
        visBilde(nextImgSmall);
    }
    else {
        alert('nextImgSmall not found');
    }
}
function checkNextPrev() {
    //finne ut hva som er "gjeldende" bilde akkurat nå
    var imgSmall = $get('imgMain').alt.replace('main', '');

    //finne ut om det finnes bilder "før" dette bildet i datalisten
    var currIndex = imgSmall.substr(imgSmall.length - 1, 1)

    var prevIndex = new Number(currIndex) - 1;
    var nextIndex = new Number(currIndex) + 1;
    var prevImgSmall = $get('img_' + prevIndex.toString());
    var nextImgSmall = $get('img_' + nextIndex.toString());
    if (prevImgSmall != null)
        $get('lnkPrev').style.display = '';
    else
        $get('lnkPrev').style.display = 'none';
    if (nextImgSmall != null)
        $get('lnkNext').style.display = '';
    else
        $get('lnkNext').style.display = 'none';
}
