function addEngine(name,ext,cat,type) {
    if ((typeof window.sidebar == "object") && (typeof window.sidebar.addSearchEngine == "function")) {
        window.sidebar.addSearchEngine("http://mycroft.mozdev.org/external.php/" + name + ".src", 
                                       "http://mycroft.mozdev.org/external.php/" + name + "."+ ext, name, cat );
    } else {
        alert("You will need a Mozilla based browser to install a search plugin.");
    }
}

function checkAll(targetForm, clear) {
    if (!clear)
	clear = false;
    $()
    for (i = 0; i < targetForm.elements.length; i++)
        if (targetForm.elements[i].type == "checkbox")
            if (targetForm.elements[i].checked == false && clear == false)
                targetForm.elements[i].checked = true;
	    else if (targetForm.elements[i].checked == true && clear == true)
                targetForm.elements[i].checked = false;
}

function Browser() {

    var ua, s, i;

    this.isIE = false;
    this.isNS = false;
    this.version = null;

    ua = navigator.userAgent;

    s = "MSIE";
    if ((i = ua.indexOf(s)) >= 0) {
	this.isIE = true;
	this.version = parseFloat(ua.substr(i + s.length));
	return;
    }

    s = "Netscape6/";
    if ((i = ua.indexOf(s)) >= 0) {
	this.isNS = true;
	this.version = parseFloat(ua.substr(i + s.length));
	return;
    }

    // Treat any other "Gecko" browser as NS 6.1.

    s = "Gecko";
    if ((i = ua.indexOf(s)) >= 0) {
	this.isNS = true;
	this.version = 6.1;
	return;
    }
}

var browser = new Browser();

function MM_openBrWindow(theURL,winName,features) { //v2.0
    window.open(theURL,winName,features);
}

function openWin(url, options) {
    window.open(url, '', options);
}

function openConditionsWin() {
    openWin('/conditions.php', 'scrollbars=yes,width=400,height=400');
}

function openKalenderWin(url) {
    openWin(url, 'scrollbars=yes,width=600,height=550');
}

function openPaymentTypeWin(url) {
    openWin(url, 'scrollbars=no,width=200,height=200');
}

function openGalleriWin(url) {
    openWin(url, 'scrollbars=yes,width=640,height=480');
}

function showFormHelp(field, content, file) {
    if (!file) file = "/formHelp.php";
    var url = file + "?field=" + field + "&content=" + content;
    if (window.showModalDialog == undefined) {
	window.open(url, "", "height=500, width=400, resizable=no, location=no, menubar=no, toolbar=no");
    } else {
	window.showModalDialog(url, "", "dialogHeight: 500px; dialogWidth: 400px; edge: Raised; center: Yes; help: No; resizable: No; status: No;");
    }
}

function link(url) {
    window.location = url;
}

function confirmLink(url, question) {
    if (!question)
        question = "Er du sikker?";
    if (confirm(question)) 
        link(url);
}

function confirmLinkChoice(choice, okUrl, cancelUrl, question) {
    if (!question)
        question = "Er du sikker?";
    if (confirm(question)) {
	if (confirm(choice)) 
	    link(okUrl);
	else
	    link(cancelUrl);
    }	
}

function showWhen(id,cond,as) {
    var elem = document.getElementById(id);
    if (!as)
	as = 'block';
    if (elem) 
	try {
	    elem.style.display = (cond) ? as : 'none';
	} catch(e) {
	    elem.style.display = 'block';
	}
}

function show(id) {
    var elem = document.getElementById(id);
    if (elem) 
	elem.style.display = 'block';
}

function hide(id) {
    var elem = document.getElementById(id);
    if (elem) 
	elem.style.display = 'none';
}

$(function () { // this line makes sure this code runs on page load
    $(".tooltip").cluetip({showTitle: false});

    $('#searchBtt').hover(
        function() {
            $('#searchBtt')
                .css('background-image', 'url(/gfx/buttons/search_button_mo.png)')
                .css('cursor', 'pointer');
        },
        function() {
            $('#searchBtt')
                .css('background-image', 'url(/gfx/buttons/search_button.png)')
                .css('cursor', 'pointer');
        }).click(function() {
            $('#searchForm').submit();
            return false;
        });

    $('.bottomTeaserBlock').hover(function() {
        $(this).addClass('sidebarBox_hover');
    }, function() {
        $(this).removeClass('sidebarBox_hover');
    });

    $('.checkAll').click(function () {
        $(this).parents('form').find(':checkbox').attr('checked', this.checked);
    });

});


