
/**
* Toggles element visibility
* @param object|string element If string then it must be element id
* @return string The new value
*/
toggle = function(element) {
    if(typeof element == 'string') {
        element = document.getElementById(element)
    }

    if (null == element) {
        return;
    }

    if(element.style.display == 'none') {
        element.style.display = ''
        //element.style.visibility = 'visible'
    } else {
        element.style.display = 'none'
        //element.style.visibility = 'hidden'
    }

    return element.style.display
}

toggle_text = function(element, text1, text2) {
    if (typeof element == 'string') {
        element = document.getElementById(element)
    }

    if (null == element) {
        return;
    }
    
    if (null != text1 && null != text2) {
        // toggle text between text1 and text2
        element.innerHTML = (trim(element.innerHTML) == text1 ? text2 : text1);
    } else {
        // change text to text1
        element.innerHTML = text1;
    }
}

trim = function(sString) {
    return sString.replace(/^\s+|\s+$/g,"");
}

set_form_element_value = function(form, element, value) {
    document.forms[form].elements[element].value = value;
}

showPic = function(picture, title) {
    var url = "http://blog.kv.ee/show_full_pic.php?pic="+picture+"&title="+title;
    win=window.open(url,"blog_main","resizable=yes, scrollbars=no, titlebar=no, width=800, height=640");
    win.document.close();
}

/////////////////////////////////////////////////////////////////////
// element specific functions
/////////////////////////////////////////////////////////////////////

var crnt_wish_type;
var crnt_wish_status;
toggle_wish = function(element, type) {
    if (typeof element == 'string') {
        element = document.getElementById(element)
    }

    if (null == crnt_wish_status) crnt_wish_status = (element.style.display);

    // toggle element only when it was opened by other type or closed
    if (type == crnt_wish_type || crnt_wish_status == 'none') {
        crnt_wish_status = toggle(element);
    }
    crnt_wish_type = type;
}

