/* JS EVENT DEBUG FUNCTION */

function debug(str)
{
    if (document.getElementById('debug')) {
        document.getElementById('debug').innerHTML+= ' # ' + str;
    }
}

/* MAILTO DECODE */

function mailto(str) 
{
    
    var mailto = '';
    for (n = 0; s = str.substring(n * 2, 2 * n + 2); n++) {
        mailto+= unescape('%' + s) ;
    }
    location.href = 'mailto:' + mailto;
}

/* DO HREF */

function openProfilPopup(src)
{
    objProfilPopup = window.open(src, 'ProfilPopup', 'width=638, height=450, scrollbars=yes, resizable=no');
    objProfilPopup.focus();
}

function openPopup(src)
{
    objWindow = window.open(src, 'popup', 'width = 580, height = 600');
    objWindow.focus();
}

function doHref(src, target)
{
    if (target == '_self') {
        location.href = _BASE_HREF + src;
    } else if (target == '_blank') {
        objWindow = window.open(src);
        objWindow.focus();
    } else {
        //alert('no target for function doHref JS');
    }
}

/* PRINT */

var winFocus = null;

function doPrint(type)
{
    objPrint = document.getElementById('print');
    if (type == 'carsearch') {
        var path = _BASE_HREF + 'carsearch/print.html';
    } else {
        var path = _BASE_HREF + 'print.html';
    }

    winFocus = window.open(path, 'onlyone', 'width = 720, height = 500, menubar = yes, resizable = yes, scrollbars = yes');
    winFocus.focus();


}

function doPrintAction()
{
    parent.frames['printframe'].focus();
    parent.frames['printframe'].print();
}

function doIframePrint(type)
{
    objContent = opener.document.getElementById('content');
    objIframe  = document.getElementById('content');
    
    if (!objContent) {
        objContent = opener.document.getElementById('start_content');
    }

    if (objContent && objIframe) {
        if (type == 'carsearch') {
            objHeadline1 = opener.document.getElementById('headline1');
            objText1     = opener.document.getElementById('text1');
            
            if (objHeadline1 && objText1) {
                html                = '';
                html               += '<h1>' + objHeadline1.innerHTML + '</h1>';
                html               += '<div class="spacer"></div>';
                html               += '<div>' + objText1.innerHTML + '</div>';
                objIframe.innerHTML = html;
            } else {
                objIframe.innerHTML = objContent.innerHTML;
            }
            window.print();
        } else {
            objIframe.innerHTML = objContent.innerHTML;
            window.print();
        }
    } else {
        alert('print error');
    }
}

/* POSITION */

function showPosLeft(id) 
{
    x   = 0;
    pos = document.getElementById(id);
    x   = pos.offsetLeft;
    while (pos.offsetParent != null) {
        pos = pos.offsetParent;
        if (pos.style.position == 'absolute') {
            break;
        }
        x   = x + pos.offsetLeft;
    }
    return x;
}

function showPosTop(id) 
{
    y   = 0;
    pos = document.getElementById(id);
    y   = pos.offsetTop;
    while (pos.offsetParent != null) {
        pos = pos.offsetParent;
        if (pos.style.position == 'absolute') {
            break;
        }
        y   = y + pos.offsetTop;
    }
    return y;
}

/* START LAYER */

var startLayerBlocker = 0;

function startLayerShow(id)
{
    startLayerHide();
    document.getElementById('start_layer_' + id).style.display = 'block';
    startLayerBlocker = 1;
}

function startLayerHide()
{
    if (!startLayerBlocker) {
        if (document.getElementById('start_layer_mercedes')) {
            document.getElementById('start_layer_mercedes').style.display = 'none';
        }
        if (document.getElementById('start_layer_smart')) {
            document.getElementById('start_layer_smart').style.display = 'none';
        }
    } else {
        startLayerBlocker = 0;
    }
}

/* CONTACT */

var contactMenueId                = 0;
var contactLocation               = '';
var contactBrand                  = '';
var contactLocationEnabled        = 0;
var contactLayerBlockClose        = 0;
var contactBrandQuestionLoaded    = 0;
var contactBrandQuestionRessource = '';
var contactBrandQuestionResult    = 0;

function contactCategorySelect(menue_id)
{
    contactMenueId  = menue_id;
    contactLocation = '';
    contactBrand    = '';
    if (contactMenueId) {
        contactLocationEnabled = 1;
        contactLocationRequestHide();
        contactLocationRequestShow();
    } else {
        contactLocationEnabled = 0;
        contactLocationRequestHide();
        
    }
    contactBrandReset();
    contactBrandHide();
}

function contactLocationRequestShow()
{
    var file = _BASE_HREF + 'request.php?str_show=location&menu_id=' + contactMenueId + '&lang_id=' + LANG_ID + '&str_extended=' + EXTENDED;
    contactLocationRequestShowGet(file);
}

function contactLocationRequestHide()
{
    document.getElementById('location_content').innerHTML = '';
}

function contactLocationRequestShowGet(file)
{
    if (window.XMLHttpRequest) {
        httpRequest = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }
    httpRequest.open("GET", file, true);
    httpRequest.onreadystatechange = contactLocationRequestShowSet;
    httpRequest.send(null);
}

function contactLocationRequestShowSet()
{
    if (httpRequest.readyState == 4) {
        if (httpRequest.status == 200) {
            document.getElementById('location_content').innerHTML = httpRequest.responseText;
            setTimeout('setOptionname(2)', 150);
            setTimeout('changeOption(\'start\')', 150);
            
        } else {
            alert('Error in file "request.php"!');
        }
    }
}

function contactLocationShow()
{
    if (contactLocationEnabled) {
        showOption(2, 0, 19);
    } else {
        alert('Bitte wählen Sie ein Themengebiet aus');
    }
}

function contactLocationSelect(location)
{
    contactLocation      = location;
    contactBrand         = '';
    if (contactLocation) {
        contactBrandQuestion();
        contactBrandQuestionRessource = window.setInterval('contactBrandQuestionInterval()', 100);
    } else {
        contactBrandReset();
        contactBrandHide();
    }
}

function contactBrandQuestionInterval()
{
    if (contactBrandQuestionLoaded) {
        window.clearInterval(contactBrandQuestionRessource);
        if (contactBrandQuestionResult) {
            contactBrandShow();
            setTimeout('contactBrandReset()', 100);
        } else {
            contactLayerShow();
            contactBrandHide();
        }
    }
}

function contactBrandQuestion()
{
    var file = _BASE_HREF + 'request.php?str_show=brand_question&menu_id=' + contactMenueId + '&lang_id=' + LANG_ID + '&str_location=' + contactLocation;
    contactBrandQuestionGet(file);
}

function contactBrandQuestionGet(file)
{
    if (window.XMLHttpRequest) {
        httpRequest = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }
    
    httpRequest.open("GET", file, true);
    httpRequest.onreadystatechange = contactBrandQuestionSet;
    httpRequest.send(null);
}

function contactBrandQuestionSet()
{
    if (httpRequest.readyState == 4) {
        if (httpRequest.status == 200) {
            contactBrandQuestionResult = parseInt(httpRequest.responseText);
            contactBrandQuestionLoaded = 1;
        } else {
            alert('Error in file "request.php"!');
        }
    }
}

function contactLayerHide()
{
    if (contactLayerBlockClose) {
        contactLayerBlockClose = 0;
    } else {
        if (document.getElementById('layer')) {
            document.getElementById('layer').style.display        = 'none';
            document.getElementById('layer_shadow').style.display = 'none';
        }
    }
}

function contactLayerShow()
{
    var file = _BASE_HREF + 'request.php?str_show=layer&menu_id=' + contactMenueId + '&lang_id=' + LANG_ID + '&str_location=' + contactLocation + '&str_brand=' + contactBrand + '&str_extended=' + EXTENDED;
    contactLayerGet(file);
    //document.getElementById('layer_content').innerHTML = '<p>' + file + '</p>';
}

function contactLayerGet(file)
{
    if (window.XMLHttpRequest) {
        httpRequest = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }
    
    httpRequest.open("GET", file, true);
    httpRequest.onreadystatechange = contactLayerSet;
    httpRequest.send(null);
}

function contactLayerSet()
{
    if (httpRequest.readyState == 4) {
        if (httpRequest.status == 200) {
            document.getElementById('layer_content').innerHTML    = httpRequest.responseText;
            document.getElementById('layer').style.display        = 'block';
            document.getElementById('layer_shadow').style.display = 'block';
            document.getElementById('layer_shadow').style.height  = (document.getElementById('layer').offsetHeight - 10) + 'px';
        } else {
            alert('Error in file "request.php"!');
        }
    }
}

function contactBrandReset()
{
    contactBrandQuestionLoaded = 0;
    if (document.getElementById('optioncontent3_start')) {
        optioncontentname[3] = 'start';
        document.getElementById('optioncontent3_start').className = 'option active';
    }
}

function contactBrandHide()
{
    if (document.getElementById('option3')) {
        document.getElementById('option3').style.display = 'none';
    }
}

function contactBrandSelect(brand)
{
    contactBrand = brand;
    if (brand) {
        contactLayerShow();
    }
}

function contactBrandShow()
{
    var file = _BASE_HREF + 'request.php?str_show=brand&menu_id=' + contactMenueId + '&lang_id=' + LANG_ID + '&str_location=' + contactLocation + '&str_extended=' + EXTENDED;
    contactBrandGet(file);
}

function contactBrandGet(file)
{
    if (window.XMLHttpRequest) {
        httpRequest = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }
    
    httpRequest.open("GET", file, true);
    httpRequest.onreadystatechange = contactBrandSet;
    httpRequest.send(null);
}

function contactBrandSet()
{
    if (httpRequest.readyState == 4) {
        if (httpRequest.status == 200) {
            document.getElementById('brand_content').innerHTML    = httpRequest.responseText;
        } else {
            alert('Error in file "request.php"!');
        }
    }
}

/* SEND */

function hideSend()
{
    if (document.getElementById('send')) {
        document.getElementById('send').style.display        = 'none';
        document.getElementById('send_shadow').style.display = 'none';
    }
}

/* SITEMAP */

function hideSitemap()
{
    if (document.getElementById('sitemap')) {
        document.getElementById('sitemap').style.display        = 'none';
        document.getElementById('sitemap_shadow').style.display = 'none';
    }
}

/* GALLERY */

function hideGallery()
{
    if (document.getElementById('gallery_layer')) {
        document.getElementById('gallery_layer').style.display        = 'none';
        document.getElementById('gallery_layer_shadow').style.display = 'none';
    }
}

function showXXL(img) {
    
    document.getElementById('xxl_layer_img').src='../img/us.gif';
    document.getElementById('xxl_layer_img').src=document.getElementById('photo').src.replace(/.jpg/, '_xxl.jpg');
    document.getElementById('xxl_layer').style.display='block';
    document.getElementById('xxl_layer_shadow').style.display='block';
    document.getElementById('xxl_layer_spacer').style.display='block';
    //alert(document.getElementById('photo').src.replace(/.jpg/, '_xxl.jpg'));
}
function hideXXL()
{
    if (document.getElementById('xxl_layer')) {
        document.getElementById('xxl_layer').style.display        = 'none';
        document.getElementById('xxl_layer_shadow').style.display = 'none';
        document.getElementById('xxl_layer_spacer').style.display = 'none';
    }
}

function hideFlashlayer() {
    if (document.getElementById('flash_layer')) {
        document.getElementById('flash_layer').style.display = 'none';
        document.getElementById('flash_layer').innerHTML     = '';
    }
}

/* PULLDOWN */

var optionname    = 0;
var optionnamesub = '';

function setOptionname(name) 
{
    optionname = name;
}

function hideOption() 
{
    if (optionname && document.getElementById('optioncontent' + optionname) && document.getElementById('optioncontent' + optionname).style.display == 'block') {
        showOption(optionname, 0, 0); 
    }
}

function hideOptionSub()
{
    if (optionnamesub && document.getElementById(optionnamesub) && document.getElementById(optionnamesub).style.display == 'block') {
        document.getElementById(optionnamesub).style.display = 'none';
    }
}

function showOption(name, offsetX, offsetY)
{
    if (name != optionname) {
        hideOption();
    }
    
    optionname = '';
    
    x = showPosLeft('option' + name);
    y = showPosTop('option' + name);
    
    var objContent = document.getElementById('optioncontent' + name);
    
    objContent.style.left = x + offsetX + 'px';
    objContent.style.top  = y + offsetY + 'px';
    
    if (objContent.style.display == 'block') {
        objContent.style.display = 'none';
    } else {
        objContent.style.display = 'block';
    }
    
    setTimeout('setOptionname(\''+ name +'\')', 100);
}

function showOptionSub(name, offsetX, offsetY)
{
    x = showPosLeft(name);
    y = showPosTop(name);
    
    objSub = document.getElementById(name + '_sub');
    
    if (optionnamesub) {
        hideOptionSub();
    }
    
    if (objSub) {
        objSub.style.left    = x + offsetX + 'px';
        objSub.style.top     = y + offsetY + 'px';
        objSub.style.display = 'block';
        optionnamesub        = objSub.id;
    }
}

// Für mehr als ein Pulldown pro Seite
var optioncontentname = new Array();
optioncontentname[1]  = 'start';
optioncontentname[2]  = 'start';
optioncontentname[3]  = 'start';
optioncontentname[4]  = 'start';
optioncontentname[5]  = 'start';
optioncontentname[6]  = 'start';
optioncontentname[7]  = 'start';
optioncontentname[8]  = 'start';
optioncontentname[9]  = 'start';
optioncontentname[10] = 'start';
optioncontentname[11] = 'start';
optioncontentname[12] = 'start';
optioncontentname[13] = 'start';
optioncontentname[14] = 'start';
optioncontentname[15] = 'start';

optioncontentnamesub  = '';

function changeOption(name)
{
    if (document.getElementById('content' + optionname)) {
        document.getElementById('content' + optionname).innerHTML = document.getElementById('optioncontent' + optionname + '_' + name).innerHTML;
    }
    if (document.getElementById('optioncontent' + optionname + '_' + name)) {
        document.getElementById('optioncontent' + optionname + '_' + name).className = 'option active';
    }
    
    if (optioncontentname[optionname]) {
        if ('optioncontent' + optionname + '_' + optioncontentname[optionname] != 'optioncontent' + optionname + '_' + name) {
            if (document.getElementById('optioncontent' + optionname + '_' + optioncontentname[optionname])) {
                document.getElementById('optioncontent' + optionname + '_' + optioncontentname[optionname]).className = 'option';
            }
        }
    }
    
    if (document.getElementById(optioncontentnamesub)) {
        document.getElementById(optioncontentnamesub).className = 'option';
    }
    
    optioncontentnamesub          = '';
    optioncontentname[optionname] = name;
}

function changeOptionSub(parent_name, current_name)
{
    if (document.getElementById('content' + optionname)) {
        document.getElementById('content' + optionname).innerHTML = document.getElementById(optionnamesub + '_' + current_name).innerHTML;
    }
    
    if (document.getElementById(optionnamesub + '_' + current_name)) {
        document.getElementById(optionnamesub + '_' + current_name).className = 'option active';
    }
    
    if (document.getElementById(optioncontentnamesub)) {
        document.getElementById(optioncontentnamesub).className = 'option';
    }
    
    if (optioncontentname[optionname]) {
        if ('optioncontent' + optionname + '_' + optioncontentname[optionname] != 'optioncontent' + optionname + '_' + name) {
            if (document.getElementById('optioncontent' + optionname + '_' + optioncontentname[optionname])) {
                document.getElementById('optioncontent' + optionname + '_' + optioncontentname[optionname]).className = 'option';
            }
        }
    }
    optioncontentnamesub          = optionnamesub + '_' + current_name;
    optioncontentname[optionname] = name;

}

// Gallery

function galleryDelete(url, name)
{
    if (confirm('Wollen Sie das Bild "' + name + '" wirklich löschen?')) {
        location.href = url;
    }
}