/**
 * Öffnet die AGB in einem neuen Popup Fenster.
 *
 * @param string mainControl
 */
function showAgb(mainControl)
{
	window.open(mainControl + "?EVENT=agbStandalone&amp;PHPSESSID=$PHPSESSID", "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=agbStandalone&amp;PHPSESSID=$PHPSESSID#avoidance", "AGB", "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;
    }
}