var popUpWin;

function bookmark(titel) {
    if (titel != '') {
        bookmarktitel = " " + titel;
        bookmarklink = document.location.href;
    } else {
        bookmarktitel = "";
        bookmarklink = "http://www.sunnywatches.com";
    }
    if (window.sidebar) { // firefox
        window.sidebar.addPanel("SunnyWatches" + bookmarktitel, bookmarklink,"");
    } else if( document.all ) { //MSIE
        window.external.AddFavorite(bookmarklink, "SunnyWatches" + bookmarktitel);
    }
}

function activateTopProduct(topId) {
    var obj = document.getElementById("topproduct_" + topId);
    if(obj) {
        obj.style.display = "";
    }
}

function deactivateTopProduct(topId) {
    var obj = document.getElementById("topproduct_" + topId);
    if(obj) {
        obj.style.display = "none";
    }
}

function focusItem(obj) {
    obj.style.border = "1px solid #372920";
}
function blurItem(obj) {
    obj.style.border = "1px solid #cdb697";
}

function goSearch(formulier) {
    var searchStr = formulier.search_front;
    
    if(searchStr) {
        searchStr = searchStr.value;
        if(searchStr.length > 0) {
            document.location.href = "/search/" + searchStr+".html";
        }
        else {
            alert("Please fill in a search criteria.");
        }
    }
    else {
        return false;
    }
}

function openCentered(documentSrc, windowWidth, windowHeight,scrBars,res) {
    var resizable = (res != null) ? res : 0;

    if(popUpWin){
        if(!popUpWin.closed) popUpWin.close();
    }

    windowLeft = (window.screen.width  - windowWidth)  >> 1;
    windowTop  = (window.screen.height - windowHeight) >> 1;

    popUpWin = window.open(documentSrc, '','toolbar=0,channelmode=0,location=0,menubar=0,resizable=' + resizable + ',status=0,scrollbars=' + scrBars + ',width=' + windowWidth + ',height=' + windowHeight + ',left=' + windowLeft + ',top=' + windowTop);
    popUpWin.focus();
}

function popup(documentSrc) {
    openCentered(documentSrc, 500, 400, 1, 1);
}

function changeTr(tr_id) {
    //document.getElementById(tr_id).style.bgColor = 'red';
    document.getElementById(tr_id).className = 'alternate_tr';
}
function resetTr(tr_id) {
    //document.getElementById(tr_id).style.bgColor = '#fff';
    document.getElementById(tr_id).className = '';
}
function check_newsletter_email() { // simple email validation
    var newsletterField = document.getElementById("nb_front");
    with (newsletterField) {
        apos=value.indexOf("@");
        dotpos=value.lastIndexOf(".");
        if (apos<1||dotpos-apos<2) {
            alert('Entered email address ' + newsletterField.value + ' is not a valid!');
            return false;
        }
        else {
            return true; 
        }
    }
}
function newsletterFocus() {
    document.getElementById('nb_front').className = "newsletter_focus";
}
function newsletterBlur() {
    document.getElementById('nb_front').className = "newsletter_blur";
}