/**
 * �ffnet die AGB in einem neuen Popup Fenster.
 *
 * @param string mainControl
 */
function showAgb(mainControl)
{
	window.open(mainControl + "?EVENT=agbStandalone", "AGB", "toolbar=no,scrollbars=yes");
}

/**
 * Schreibt den Link zu den AGB in das HTML Dokument.
 *
 * @param string mainControl
 * @param string agbText
 */
function writeAgbLink(mainControl, agbText)
{
	document.write("<a class=\"navkleindunkel\" href=\"javascript: showAgb('" + mainControl + "');\">" + agbText + "</a>");
}

/**
 * �ffnet die Widerrufbelehrung in einem neuen Popup Fenster.
 *
 * @param string mainControl
 */
function showAvoidance(mainControl)
{
	window.open(mainControl + "?EVENT=widerrufsbelehrung&amp;PHPSESSID=$PHPSESSID#avoidance", "Widerrufsbelehrung", "toolbar=no,scrollbars=yes");
}

/**
 * Schreibt den Link zur Widerrufbelehrung in das HTML Dokument.
 *
 * @param string mainControl
 * @param string avoidanceText
 */
function writeAvoidanceLink(mainControl, avoidanceText)
{
	document.write("<a class=\"navkleindunkel\" href=\"javascript: showAvoidance('" + mainControl + "');\">" + avoidanceText + "</a>");
}

/**
 * Setzt das Attribut 'target' auf den Wert '_blank'.
 *
 * @param string id
 */
function setBlankTargetForElement(id)
{
	element = document.getElementById(id);

	if (null != element && element.target != undefined)
	{
		element.target = "_blank";
	}
}

/**
 * Zeigt ein Bild in einem Popup an.
 *
 * @param string path
 * @param string title
 * @param double width
 * @param double height
 */
function showItemImage(path, title, width, height)
{
	window.open(path, title, 'width=' + width + ', height=' + height);
}

var http_request = false;

function determineBankName(code)
{
    //alert('TODO: Banknamen f�r BLZ ' + code + ' ermitteln');
    http_request = false;

    if (window.XMLHttpRequest)
    {
        http_request = new XMLHttpRequest();

        if (http_request.overrideMimeType)
        {
            http_request.overrideMimeType('text/xml');
        }
    }
    else if (window.ActiveXObject)
    {
        try
        {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            try
            {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e)
            {

            }
        }
    }

    if (http_request)
    {
        http_request.onreadystatechange = fillBankName;
        http_request.open('POST', 'index.php?EVENT=determineBankName&code=' + code, true);
        http_request.send(null);
    }
}

function fillBankName()
{
    if (http_request.readyState == 4)
    {
        if (http_request.status == 200)
        {
            var bankNameTextBox = document.getElementById('bankname');

            if (bankNameTextBox != null && http_request.responseText != '')
                bankNameTextBox.value = http_request.responseText;
        }
    }
}

function setupSuggest() {
    SetupMMSuggest(document.searchForm.searchTerm,
        {'requestURL' : '/mall/1/js/mmsuggest.php?query=$v$&', 'debug' : false});
}

function setElementStatus(elementId, enabled)
{
    var element = document.getElementById(elementId);

    if (null != element)
    {
        element.disabled = !enabled;
    }
}

function showItemThumbnail(observeElem, ttId) {
   /* var div = document.createElement('div');
    div.setAttribute('id', 'tooltip'+id);
    var img = document.createElement('img');
    img.setAttribute('src', imagePath);
    img.setAttribute('id', 'imgtip'+id);

    div.appendChild(img);
    if (navigator.appVersion.indexOf('MSIE')>0) {
		div.setAttribute('display', 'none');
    } else {
		div.setStyle({'display': 'none'});
    }


    var elem = document.getElementById(id);    
    elem.appendChild(div);    */
        
    var tt = new Tooltip(observeElem, ttId);
}

function insertItemInCart(curl, itemId) {
   new Ajax.Request(curl, {
       method: 'post',
       parameters: {
           'itemId': itemId
       },
       onComplete: function () {
           if (window.location.href.indexOf('navigationView') == -1) {
                window.location.href = window.location.href+"?navigationView=cart";
           } else {
               window.location.href = window.location.href;
           }
       }
   });
}