<!--

/*
 * $Id: javascript.js,v 1.5 2004-07-23 17:54:00 tomas Exp $
 */

/*
function showhide(sect) {
    if (document.getElementById(sect).style.visibility != 'hidden') {
        document.getElementById(sect).style.visibility = 'hidden';
        document.getElementById(sect).style.display = 'none';
    } else {
        document.getElementById(sect).style.visibility = 'visible';
        document.getElementById(sect).style.display = 'block';
    }
}
*/

/*
 * Shopping cart
 */
/*
function showcart(url) {
    var winwidth = 400;
    var winheight = 100;
    //var left = (window.screen.availWidth / 2) - (winwidth / 2);
    var left = window.screen.availWidth - winwidth;
    var top = 0; //(window.screen.availHeight / 2) - (winheight / 2);
    var options = 'scrollbars=1,resizable=1,width='+winwidth+
        ',height='+winheight+',left='+left+',top='+top;

    window.open(url,
                'Kundvagn',
                options);
}
*/


function itempopup(url) {
    var winwidth = (window.screen.availWidth / 2);
    var winheight = (window.screen.availHeight / 1.5);
    //var left = (window.screen.availWidth / 2) - (winwidth / 2);
    var wleft = window.screen.availWidth - winwidth - 14;
    var wtop = 14; //(window.screen.availHeight / 2) - (winheight / 2);
    var options = 'scrollbars=1,resizable=1,width='+winwidth+
        ',height='+winheight+',left='+wleft+',top='+wtop;

    window.open(url, 'Information', options);
    return false;
}


/* Används inte(?)
function placeorder(item_id) {
    num = document.getElementById('num_'+item_id).value;
    if (document.getElementById('size_'+item_id)) {
        size = document.getElementById('size_'+item_id).value;
    } else {
        size = '';
    }

    document.location = '?m=cart&a=add&id='+item_id+'&num='+num+'&size='+size;
    return false;
}
*/

function popup_placeorder(item_id) {
    num = document.getElementById('num').value;
    if (document.getElementById('size')) {
        size = document.getElementById('size').value;
    } else {
        size = '';
    }

    if (window.opener) {
        window.opener.top.frames['cart'].location = '?m=cart&a=add&id='+item_id+'&num='+num+'&size='+size;
    }
    return false;
}

function cart_empty() {
    top.frames['cart'].location = '?m=cart';
}


function cart_removeitem(item_id) {
    document.location = '?m=cart&a=remove&id='+item_id;
    return false;
}

/* Not used(?)
function emptycart() {
    document.location = '?m=cart&a=clear';
    return false;
}
*/

function cart_calcprice(menu, id) {
    num = menu.value;
    document.location = '?m=cart&a=update&id='+id+'&num='+num;
    return false;
}


function change_sort_order(menu, m, a, id) {
    sort_order = menu.value;
    document.location = '?m='+m+'&a='+a+'&id='+id+'&order='+sort_order;
    return false;
}


/*
 * Taken from TikiWiki
 */
function showmenu(foo) {
    elements = document.getElementsByTagName("div");

    if (elements != null) {
        for (var i = 0; i < elements.length; i++) {
            name = elements.item(i).id;

            if (name.substr(0, 13) == 'menu-section-' && name != foo) {
                setCookie(name, "c");
                hide(name);
            }
        }

        show(foo);
        setCookie(foo, "o");
    }
}

function show(foo) {
    document.getElementById(foo).style.display = "block";
    document.getElementById(foo).style.visibility = "visible";
}

function hide(foo) {
    document.getElementById(foo).style.display = "none";
    document.getElementById(foo).style.visibility = "hidden";
}

function show_obj(foo) {
    foo.style.display = "block";
    foo.style.visibility = "visible";
}

function hide_obj(foo) {
    foo.style.display = "none";
    foo.style.visibility = "hidden";
}

function showhide_x(id) {
    if (document.getElementById) {
        var obj = document.getElementById(id);
    } else {
        if (document.all){
            var obj = document.all(id);
        }
    }

    if (obj.style.display == 'none') {
        setCookie(id, "o");
        obj.style.display = '';
    } else {
        setCookie(id, "c");
        obj.style.display = 'none';
    }
}

function showhide(foo) {
    if (document.getElementById) {
        var obj = document.getElementById(foo);
    } else {
        if (document.all){
            var obj = document.all(foo);
        }
    }

    if (obj) {
        if (obj.style.display == "none") {
            show_obj(obj);
            setCookie(foo, "o");
        } else {
            if (obj.style.display == "block") {
                hide_obj(obj);
                setCookie(foo, "c");
            } else {
                show_obj(obj);
                setCookie(foo, "o");
            }
        }
    }
}

// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure) {
    var curCookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
    document.cookie = curCookie;
}


/*
 * End: Taken from TikiWiki
 */


function manageImages() {
    var winwidth = 250;
    var winheight = 500;
    //var left = (window.screen.availWidth / 2) - (winwidth / 2);
    var left = window.screen.availWidth - winwidth;
    var top = 0; //(window.screen.availHeight / 2) - (winheight / 2);
    var options = 'scrollbars=1,resizable=1,width='+winwidth+
        ',height='+winheight+',left='+left+',top='+top;

    window.open('?m=images&a=manageImages', 'manageImages', options);
}

function instructions() {
    var winwidth = 300;
    var winheight = 400;
    //var left = (window.screen.availWidth / 2) - (winwidth / 2);
    var left = window.screen.availWidth - winwidth;
    var top = 0; //(window.screen.availHeight / 2) - (winheight / 2);
    var options = 'scrollbars=1,resizable=1,width='+winwidth+
        ',height='+winheight+',left='+left+',top='+top;

    window.open('?s=instructions',
                'help',
                options);
}

// Inserts an "url" into the textarea my_form.text, in the opener-window
function insertImageIdIntoArticle(id) {
    if (opener.document.my_form != null)
        opener.document.my_form.text.value += "{img id=" + id + "}";
    //alert(opener.document.my_form.text.value);
}

function showImageSelection() {
    return false;
}

function confirm_remove_contact() {
  return confirm('Do you really want to remove this address?');
}

function toggle_checkboxes() {
    var form = document.my_form; //Todo: getElementById()

    for (var i = 0; i < form.elements.length; i++) {
        if (form.elements[i].name != 'multiselector' &&
            form.elements[i].type == 'checkbox') {
            form.elements[i].checked = form.multiselector.checked;
        }
    }
}

//-->
