// Debug Output
function pr(val)
{
    var str = '';
    for (key in val) {
        str+= key + ":" + val[key] + "\n";
    }
    alert(str);
}



// Boxen Edit Toggle
function toggleEdit(article_id)
{
    if (document.getElementById('edit_layer_' + article_id).style.display == 'block') {
        document.getElementById('edit_layer_' + article_id).style.display = 'none';
        document.getElementById('edit_button_' + article_id).className    = 'box_edit_button';
    } else {
        document.getElementById('edit_layer_' + article_id).style.display = 'block';
        document.getElementById('edit_button_' + article_id).className    = 'box_edit_button_inactive';
    }

}

// Listen Toggle
var toggle_list_last_id = '';

function toggleList(element_id)
{
    if (toggle_list_last_id && toggle_list_last_id != element_id && document.getElementById(toggle_list_last_id)) {
        document.getElementById(toggle_list_last_id).style.display = 'none';
    }

    if (document.getElementById(element_id)) {
        if (document.getElementById(element_id).style.display == 'block') {
            document.getElementById(element_id).style.display = 'none';
        } else {
            document.getElementById(element_id).style.display = 'block';
        }
        toggle_list_last_id = element_id;
    }
}

// Location Toogle
var location_current_id = '';

function locationShow(location_id)
{
    if (document.getElementById(location_id)) {
        if (document.getElementById(location_id).style.display == 'block') {
            document.getElementById(location_id).style.display = 'none';
        } else {
            document.getElementById(location_id).style.display = 'block';
            if (location_current_id &&
                location_id != location_current_id &&
                document.getElementById(location_current_id)) {
                document.getElementById(location_current_id).style.display = 'none';
            }
            location_current_id = location_id;
        }
    }

    // close contactpartner
    tryCloseContactpartner();
}

function locationHide(location_id)
{
    if (document.getElementById(location_id)) {
        document.getElementById(location_id).style.display = 'none';
    }
}

function locationHover(status, location_hover_id)
{
    if (document.getElementById(location_hover_id)) {
        if (status) {
            document.getElementById(location_hover_id).style.display = 'block';
        } else {
            document.getElementById(location_hover_id).style.display = 'none';
        }
    }

}

var contactpartner_current_article_id = 0;

// Contactpartner
function contactpartnerShowThread(article_id, location_id)
{
    //if (!document.getElementById('thread_container_' + article_id)) return false;

    objAjax = new Ajax(CMS_SCRIPT + '/request_contactpartner_thread.html?article_id=' + article_id + '&location_id=' + location_id);
    objAjax.request('thread_container_' + article_id);

    // Reset Result Person List
    if (document.getElementById('person_container_' + article_id)) {
        document.getElementById('person_container_' + article_id).innerHTML = '';
    }

    // IE6 Footer Fix
    if (navigator.appName == 'Microsoft Internet Explorer' && navigator.appVersion.search(/6\.0/) != -1) {
        if (document.getElementById('wrapper')) {
            document.getElementById('wrapper').className = 'wrapper';
        }
    }

    contactpartner_current_article_id = article_id;

    // close location layer
    tryCloseLocationLayer();
}

function contactpartnerShowPerson(article_id, location_id, thread_id)
{
    objAjax = new Ajax(CMS_SCRIPT + '/request_contactpartner_person.html?article_id=' + article_id + '&location_id=' + location_id + '&thread_id=' + thread_id);
    objAjax.request('person_container_' + article_id);

    // IE6 Footer Fix
    if (navigator.appName == 'Microsoft Internet Explorer' && navigator.appVersion.search(/6\.0/) != -1) {
        if (document.getElementById('wrapper')) {
            document.getElementById('wrapper').className = '';
        }
    }

    contactpartner_current_article_id = article_id;

    // close location layer
    tryCloseLocationLayer();
}

// Contactpartner Admin Person

var mediapool = null;

function openMediapoolPerson(type)
{
    seq = 0;
    if(navigator.appName == 'Microsoft Internet Explorer') {
        mediapool = window.open('mediapool.html?seq='+seq+'&str_type=image%2F%2A&str_call_function=opener.insertImagePerson','mediapool','width=700,height=570,scrollbars=yes');
    }else{
        mediapool = window.open('de/mediapool.html?seq='+seq+'&str_type=image%2F%2A&str_call_function=opener.insertImagePerson','mediapool','width=700,height=570,scrollbars=yes');
    }
    mediapool.focus();
}

function insertImagePerson(url)
{
    document.forms['person'].elements['arr_content[imagepath]'].value = url.replace(/{writemediapool}/, 'upload/mediapool/');
    document.forms['person'].submit();
    mediapool.close();
}

// Product 1

function product1Show(line_id, type_id, variation_id, lead_id, insulation_id, housing_id)
{
    line_id       = parseInt(line_id);
    type_id       = parseInt(type_id);
    variation_id  = parseInt(variation_id);
    lead_id       = parseInt(lead_id);
    insulation_id = parseInt(insulation_id);
    housing_id    = parseInt(housing_id);

    objAjax       = new Ajax(CMS_SCRIPT + '/request_product_1.html?line_id=' + line_id + '&type_id=' + type_id + '&variation_id=' + variation_id + '&lead_id=' + lead_id + '&insulation_id=' + insulation_id + '&housing_id=' + housing_id);
    objAjax.request('product', true);
}

// Product 2

function product2Show(line_id, type_id, connector_id)
{
    line_id       = parseInt(line_id);
    type_id       = parseInt(type_id);
    connector_id  = parseInt(connector_id);

    objAjax       = new Ajax(CMS_SCRIPT + '/request_product_2.html?line_id=' + line_id + '&type_id=' + type_id + '&connector_id=' + connector_id);
    objAjax.request('product', true);
}

// Product 2

function product3Show(product_id)
{
    product_id = parseInt(product_id);

    objAjax    = new Ajax(CMS_SCRIPT + '/request_product_3.html?product_id=' + product_id);
    objAjax.request('product', true);
}

var block_location = false;

// close location layer
function tryCloseLocationLayer()
{
    if (block_location) {
        block_location = false;
    } else {
        locationHide(location_current_id);
    }
}

// close contactpartner
function tryCloseContactpartner()
{
    block_location = true;
    if (contactpartner_current_article_id) {
        selectChangeOption('location_' + contactpartner_current_article_id, '0', '', '', '');
        contactpartnerShowThread(contactpartner_current_article_id, '0');
    }
}