function switchElementVisibility(id,visible)
{
	el = document.getElementById(id);
	if(typeof(visible)=='undefined')
	{
		if (el.style.visibility=='visible') el.style.visibility='hidden';
		else el.style.visibility='visible';
	}
	else if (typeof(visible)=='string')
	{
		el.style.visibility='visible';
	}
	else if (visible)
	{
		el.style.visibility='visible';
	}
	else
	{
		el.style.visibility='hidden';
	}
}
// Artikel in den Warenkorb legen
function es_std_AddArtikel( artikel, subartikel )
{
    posDelimeter            = artikel.indexOf( '|' );

    if( 0 < posDelimeter ) { artikel = '|' + artikel; }

    eForm                   = document.getElementsByName( 'eshop' )[0];

    if( '' != eForm.ARTIKEL_NR.value )
    {
        artikel = artikel.slice( 1 );
    }

    eForm.ARTIKEL_NR.value += artikel;
    
    if( subartikel != undefined && '' != subartikel )
    {
        eForm.SUBARTIKEL_NR.value   = subartikel;
        eForm.TERMIN_NR.value       = subartikel;
    }

    eForm.submit();
}

// Artikel aus dem Warenkorb l�schen
function es_std_DeleteArtikel(artikel)
{
    if(confirm('Soll der Artikel wirklich aus dem Warenkorb gel�scht werden?'))
    {
        document.eshop.DELETE_ARTIKEL.value    = artikel;
        document.eshop.submit();
    }
}

// Zur Kasse gehen
function es_std_zur_kasse()
{
    document.eshop.ZUR_KASSE.value=1;
    document.eshop.submit();
}


//******Steuerungsfunktionen Artikelauswahl

function es_std_setPerPage(anzahl)
{
    document.eshop.ANZAHL.value = anzahl;
    document.eshop.submit();
}

function es_std_browsetable(wert)
{
    document.eshop.START.value           = wert;
    document.eshop.submit();
}




// Standard JavaScript - Funktionen f�r den Workflow

function wf_std_set_formIndex(id)
{
    //formIndex   = id; do nothing
    return;
}

function wf_std_suchen()
{
    document.eshop.SUCHE.value = '1';
    wf_std_submit();
}

function wf_std_viewDetails(id)
{
    document.eshop.ARTIKELINFO.value = id;
    wf_std_submit();
}

function wf_std_submit()
{
    document.eshop.submit();
}

function displayDiv(id)
{
    if(document.getElementById(id).style.display == 'none')
    {
        document.getElementById(id).style.display = 'block';
//         document.getElementById('link'+id).innerHTML = '<<&nbsp;weniger&nbsp;&nbsp;';
        document.getElementById('link'+id).src = '../standard/bilder/up.gif';
    }
    else
    {
        document.getElementById(id).style.display = 'none';
//         document.getElementById('link'+id).innerHTML = '>>&nbsp;mehr&nbsp;&nbsp;';
        document.getElementById('link'+id).src = '../standard/bilder/down.gif';
    }
}



var tipDiv;
function genToolTip()
{
    tipDiv = document.getElementById('wf_std_tooltip');
}

window.onload = genToolTip;

function showTip(e, txt)
{
    if(tipDiv)
    {
        var e                = e || window.event;
        var xy               = cursorPos(e);
        tipDiv.innerHTML     = txt;
        tipDiv.style.left    = (xy[0] - 320) + 'px';
        tipDiv.style.top     = (xy[1] - 120) + 'px';
        tipDiv.style.display = '';
    }
}

function hideTip()
{
    if(tipDiv)
    {
        tipDiv.style.display = 'none';
    }
}

function cursorPos(e)
{
    if(e.pageX || e.pageY)
        return [ e.pageX, e.pageY ];
    else if(e.clientX || e.clientY)
        return [e.clientX + document.body.scrollLeft,e.clientY + document.body.scrollTop];
}



function goStep(nr)
{
    f   = document.eshop;

    f.stepback.value            = nr;
    f.SHOWFORM.value            = '1';
    f.wiederholeseite.value     = nr;
    f.wasstep.value             = '';
    f.STEP.value                = '';
    f.submit();
}


function changeSort(feld)
{
    document.eshop.CHANGESORT.value = feld;
    document.eshop.submit();
}


function wf_std_setUserName(username, feldname)
{
    document.getElementsByName(feldname)[0].value=username;
    return false;
}
var showButton = true;
function wf_std_showButton(button,anzeigen)
{
    showButton = anzeigen;
}

function loescheArtikel(artikelNr)
{
    document.eshop.DELETE_ARTIKEL.value=artikelNr;
    document.eshop.submit();
}


function wf_std_loginneukunde()
{
    document.eshop.NEUKUNDE.value= '1';
    document.eshop.PW_REMEMBER.value= '0';
    document.eshop.submit();
}

function wf_std_login()
{
    document.eshop.PW_REMEMBER.value='0';
    document.eshop.USERLOGIN.value='1';
    document.eshop.NEUKUNDE.value='0';
    document.eshop.submit();
}

function wf_std_remember()
{
    document.eshop.PW_REMEMBER.value='1';
    document.eshop.USERLOGIN.value='0';
    document.eshop.NEUKUNDE.value='0';
    document.eshop.submit();
}


function wf_std_setDisplay(id)
{
    if(document.getElementById('DISPLAY'+id).value=='1')
        document.getElementById('DISPLAY'+id).value='0';
    else
        document.getElementById('DISPLAY'+id).value='1';
}


function wf_std_neuanmeldung()
{
    document.eshop.PW_REMEMBER.value='0';
    document.eshop.USERLOGIN.value='0';
    document.eshop.NEUKUNDE.value='1';
    document.eshop.submit();
}

function es_std_BucheArtikel(artikel)
{
    document.eshop.INFO_ARTIKEL.value    = '';
    document.eshop.BUCHE_ARTIKEL.value   = artikel;
    document.eshop.DELETE_ARTIKEL.value = '';
    document.eshop.ZUR_KASSE.value       = '';
    document.eshop.submit();
}
function es_std_ShowInfo(artikel)
{
    document.eshop.INFO_ARTIKEL.value    = artikel;
    document.eshop.BUCHE_ARTIKEL.value   = '';
    document.eshop.DELETE_ARTIKEL.value = '';
    document.eshop.ZUR_KASSE.value       = '';
    document.eshop.submit();
}
function es_std_LoescheArtikel(artikel)
{
    document.eshop.INFO_ARTIKEL.value    = '';
    document.eshop.BUCHE_ARTIKEL.value   = '';
    document.eshop.DELETE_ARTIKEL.value = artikel;
    document.eshop.ZUR_KASSE.value       = '';
    document.eshop.submit();
}
function es_std_zurKasse(artikel)
{
    document.eshop.INFO_ARTIKEL.value    = '';
    document.eshop.BUCHE_ARTIKEL.value   = '';
    document.eshop.DELETE_ARTIKEL.value = '';
    document.eshop.ZUR_KASSE.value       = 1;
    document.eshop.submit();
}

function es_std_setPerPage(anzahl)
{
    document.eshop.INFO_ARTIKEL.value    = '';
    document.eshop.BUCHE_ARTIKEL.value   = '';
    document.eshop.DELETE_ARTIKEL.value = '';
    document.eshop.ZUR_KASSE.value       = '';
    document.eshop.ANZAHL.value          = anzahl;
    document.eshop.submit();
}

function es_std_browsetable(wert)
{
    document.eshop.INFO_ARTIKEL.value    = '';
    document.eshop.BUCHE_ARTIKEL.value   = '';
    document.eshop.DELETE_ARTIKEL.value = '';
    document.eshop.ZUR_KASSE.value       = '';
    document.eshop.START.value           = wert;
    document.eshop.submit();
}

function es_std_neu_berechnen()
{
    document.eshop.ARTIKEL_BERECHNEN.value  = '1';
    document.eshop.DELETE_ARTIKEL.value    = '';
    document.eshop.submit();
}

function es_std_LoescheArtikel(artikel)
{
    if(confirm('Soll der Artikel wirklich aus dem Warenkorb gel�scht werden?'))
    {
        document.eshop.DELETE_ARTIKEL.value    = artikel;
        document.eshop.ARTIKEL_BERECHNEN.value  = '';
        document.eshop.submit();
    }
}

function es_std_weitere_artikel( menunr )
{
    oTransaknr  = document.getElementsByName( 'TRANSAKNR' );
    oGSAG       = document.getElementsByName( 'GSAG' );

    transaknr   = ( oTransaknr )?   oTransaknr[0].value : '';
//    gsag        = ( oGSAG )?        '&GSAG=' + oGSAG[0].value : '';

    document.eshop.DELETE_ARTIKEL.value         = '';
    document.eshop.ARTIKEL_BERECHNEN.value      = '';
    document.eshop.WEITERE.value                = '1';
    document.eshop.GRUPPE.value                 = '';
    document.eshop.NEWGRUPPE.value              = '';
    document.eshop.TRANSAKNR.value              = transaknr;
    document.eshop.menu.value                   = menunr;
    //document.eshop.action='evewa2.php?menu=' + menu + gsag + transaknr;

    document.eshop.submit();
}

// Lade Seite ZAEN - Semiarauswahl:
function zaen_seminarauswahl()
{
    eShop       = document.getElementsByName( 'eshop' )[0];

    eShop.GRUPPE.value      = 'ZAEN_SEMINAR';
    eShop.NEWGRUPPE.value   = 'ZAEN_SEMINAR';
    eShop.STEP.value        = '1';
    eShop.menu.value        = '030201';

    eShop.submit();

}
function tablePager()
{
    tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
    imgLoader = new Image();// preload image
    imgLoader.src = tb_pathToImage;
    $(".tablesorter").tablesorter({widthFixed: true})
    .tablesorterPager({container: $("#pager")});
}

function chkBox_multicheck( selParent, selChild )
{
    var status  = ($(selParent).attr("checked"))? 'checked' : '';
    $(selChild).each(function(i)
    {
        $(this).attr( "checked", status );
    });
}

function chkBox_uncheck( selParent )
{
    $('input.theme_0.lthema').attr("checked", '' );
}

function chkBox_getChecked( selector, ignore, blMain )
{
    blIgnore    = ( typeof( ignore ) != 'undefined' )? true : false;
    blIgnore    = ( blIgnore && typeof( ignore ) == 'string' )? true : false;
    blIgnore    = ( blIgnore && ignore != '' )? true : false;

    blMain      = ( typeof( blMain ) == 'boolean' && blMain )? true : false;

    var iFilter             = '';
    var iMain               = '';
    var subFilter           = new Array();

    $("input:checked").each(function(i)
    {
        iClass  = this.className;
        posSel  = iClass.indexOf( selector, 0 );

        if( posSel == 0 )
        {
            if( !blIgnore )     {   ignore  = this.value + ' _IGN'; }

            if( this.className != ignore )
            {
                iParams     = this.value.split( '|' );

                if( blMain )
                {
                    iMain       = (typeof(iParams[0]) == 'undefined')? false : iParams[0];
                    iSub        = ( iMain && typeof(iParams[1]) != 'undefined' && '' != iParams[1] )? iParams[1] + '|' : '';
                } else
                {
                    iMain       = 'nomain';
                    iSub        = ( typeof( iParams[0] ) != 'undefined' && iParams[1] != '' && iParams[0] != ignore )? iParams[0] + '|' : false;
                }

                if( iMain && iSub )
                {
                    if( typeof( subFilter[iMain] ) == 'undefined' )
                    {
                        subFilter[iMain]     = iSub;
                    } else
                    {
                        subFilter[iMain]    += iSub;
                    }
                }
            }
        }
    });

    if( blMain && 'string' == typeof( iMain ) && '' != iMain )
    {
        for( iMain in subFilter )
        {
            iFilter  += iMain + '|' + subFilter[iMain] + '-';
        }
    } else
    {
        iFilter  = subFilter[iMain];
    }

    return iFilter;
}

function zaen_refsuche()
{
    iFilter     = chkBox_getChecked( 'theme _', 'theme _0', true );
    iURI        = 'evewa2.php?d=5&menu=80900088&__GSAG&gs_data='+iFilter;

    iAppend     = 'referenten';

    $.ajax
    ({
        url: iURI,
        cache: false,
        type: 'POST',
        success: function(html)
        {
            $("#referenten").html(html);
        }
    });
}

function zaen_termine( filter, kongress )
{
    iFilter     = ( filter  !== '1' && filter !== 1 )? '0' : '1';
    iKongress   = ( kongress !== '1' && kongress !== 1 )? '0' : '1';
    iAppend     = 'ergebnisse';
//    iCallBack   = 'tablePager()';

    if( iFilter == '1' )
    {
        aFilter     = chkBox_getChecked( 'referent', 'refs', false );
        bFilter     = chkBox_getChecked( 'theme_', 'lthema', false );

        iURI        = 'evewa2.php?d=5&menu=80900090&__GSAG&filter=1&notall='+iKongress+'&gs_dataA='+aFilter+'&gs_dataB='+bFilter;
    } else
    {
        iURI        = 'evewa2.php?d=5&menu=80900090&__GSAG&filter=0&notall='+iKongress;
    }

    $.ajax
    ({
        url: iURI,
        cache: false,
        success: function(html)
        {
            $("#ergebnisse").replaceWith(html);
            tablePager();
        }
    });
}

function zaen_workflow( wf, step )
{
    var iLoad       = document.getElementsByName( 'LOAD' )[0];
    var iLoadStep   = document.getElementsByName( 'LOADSTEP' )[0];
    var iLoadGroup  = document.getElementsByName( 'LOADGROUP' )[0];

    var pLoad       = ( 'string' == typeof( step ) )? '1' : '0';
    var pLoadStep   = ( '1' == pLoad )? step : '0';
    var pLoadGroup  = ( '1' == pLoad )? wf : '0';

    iLoad.value         = pLoad
    iLoadStep.value     = pLoadStep;
    iLoadGroup.value    = pLoadGroup;
}


function zaen_fillWarenkorb( artikel, show, wf, step )
{
    var iArtikel    = null;
    var iShow       = document.getElementsByName( 'SHOW' )[0];
    var iWF         = document.getElementsByName( 'GRUPPE' )[0];
    var iStep       = document.getElementsByName( 'STEP' )[0];

    var pShow       = ( 'string' == typeof( show ) && show == '1')? '1' : '0';
    var pWF         = ( 'string' == typeof( wf ) )? wf : iWF.value;
    var pStep       = ( 'string' == typeof( step ) )? step  : iStep.value;

    if( typeof( artikel ) == 'string' && artikel != '' )
    {
        iArtikel    = artikel;
    } else
    {
        iArtikel    = chkBox_getChecked( 'termine' );
    }

    iShow.value     = pShow;
    iWF.value       = pWF;
    iStep.value     = pStep;

    es_std_AddArtikel( iArtikel );
}

function zaen_loadstep( group, step )
{
    blGroup = ( 'string' == typeof( group ) && 0 < group.length )? true : false;
    step    = parseInt( step );

    iGRUPPE     = document.getElementsByName( 'GRUPPE' )[0];
    iNEWGRUPPE  = document.getElementsByName( 'NEWGRUPPE' )[0];
    iSTEP       = document.getElementsByName( 'STEP' )[0];
    iSHOP       = document.getElementsByName( 'eshop' )[0];

    if( iGRUPPE && iSTEP && blGroup && iSHOP )
    {
        iGRUPPE.value   = group;
        iSTEP.value     = step;

        if( iNEWGRUPPE )
        {
            iNEWGRUPPE.value    = group;
        }

        iSHOP.submit();
    }



}

function zaen_removeThickBox()
{
    tb_remove();
}

function refreshWarenkorb()
{
    iShop           = document.getElementsByName( 'eshop' )[0];
    iMenu           = document.getElementsByName( 'menu' )[0];

    iShop.value     = '0';
    iMenu.value     = '02';

    iShop.submit();
}

function zaen_cleartext( input_field )
{
    iInput  = document.getElementById( input_field );

    if( iInput )
    {
        iInput.value    = '';
    }
}

function show_msg( iValue )
{
    iMsg        = document.getElementsByName( 'MSG' )[0];
    iMsg.value  = ( 'string' == typeof( iValue ) && iValue.length > 0  )? iValue : '';
}

function zaen_validate( field, option, defaultValue )
{
    iField      = document.getElementById( field );
    iShop       = document.getElementsByName( 'eshop' )[0];
    iValue      = ( iField )? iField.value : '';
    iDefault    = ( 'string' == typeof( defaultValue ) )? defaultValue : false;

    switch( option )
    {
        case 'mail':
            iValue  = $( '#' + field ).val();

            var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;

            if( pattern.test( iValue ) && iValue != '' )
            {
                $( '#' + field ).css( 'color', '#679197' );
                window.setTimeout( function shwerr(){ $( '#ERR_' + field ).fadeOut( 'fast' ) }, 1000 );
                return true;
            } else
            {
                $( '#ERR_' + field  ).fadeIn( 'slow' );
                $( '#' + field ).css( 'color', '#DD2231' );
                window.setTimeout( function shwerr(){ $( '#ERR_' + field ).fadeOut( 'slow' ) }, 4000 );
                return false;
            }

            break;
        case 'day':

            iValue  = parseInt( $( '#' + field ).val(), 10 );
            iLength = $( '#' + field ).val().length;

            if(  iLength < 3 && iValue != '' && iValue > 0 && iValue < 32 && iValue != 'NaN' )
            {
                $( '#' + field ).css( 'color', '#679197' );
                window.setTimeout( function shwerr(){ $( '#ERR_GEB').fadeOut( 'fast' ) }, 1000 );
                return true;
            } else
            {
                $( '#ERR_GEB' ).fadeIn( 'slow' );
                $( '#' + field ).css( 'color', '#DD2231' );
                window.setTimeout( function shwerr(){ $( '#ERR_GEB' ).fadeOut( 'slow' ) }, 4000 );
                return false;
            }

            break;
        case 'month':
            iValue  = parseInt( $( '#' + field ).val(), 10 );
            iLength = $( '#' + field ).val().length;

            if(  iLength < 3 && iValue != '' && iValue > 0 && iValue < 13 && iValue != 'NaN' )
            {
                $( '#' + field ).css( 'color', '#679197' );
                window.setTimeout( function shwerr(){ $( '#ERR_GEB' ).fadeOut( 'fast' ) }, 1000 );
                return true;
            } else
            {
                $( '#ERR_GEB'  ).fadeIn( 'slow' );
                $( '#' + field ).css( 'color', '#DD2231' );
                window.setTimeout( function shwerr(){ $( '#ERR_GEB' ).fadeOut( 'slow' ) }, 4000 );
                return false;
            }

            break;
        case 'year':
            iValue  = parseInt( $( '#' + field ).val(), 10 );
            iLength = $( '#' + field ).val().length;

            if(  iLength > 0 && iLength < 5 && iValue != '' && iValue > 1899 && iValue != 'NaN' )
            {
                $( '#' + field ).css( 'color', '#679197' );
                window.setTimeout( function shwerr(){ $( '#ERR_' + field ).fadeOut( 'fast' ) }, 1000 );
                return true;
            } else
            {
                $( '#ERR_GEB' ).fadeIn( 'slow' );
                $( '#' + field ).css( 'color', '#DD2231' );
                window.setTimeout( function shwerr(){ $( '#ERR_GEB' ).fadeOut( 'slow' ) }, 4000 );
                return false;
            }

            break;
        case 'pflicht':
            iValue  = $( '#' + field ).val();
            iLength = iValue.length;
//alert( iValue + ' -> ' +  iDefault );
            if( iLength > 0 && iValue != iDefault )
            {
                $( '#' + field ).css( 'color', '#679197' );
                window.setTimeout( function shwerr(){ $( '#ERR_' + field ).fadeOut( 'fast' ) }, 1000 );
                return true;
            } else
            {
                $( '#ERR_' + field  ).fadeIn( 'slow' );
                $( '#' + field ).css( 'color', '#DD2231' );
                window.setTimeout( function shwerr(){ $( '#ERR_' + field ).fadeOut( 'slow' ) }, 4000 );
                return false;
            }

            break;
        case 'nopflicht':
            iValue  = $( '#' + field ).val();

            if( iValue != iDefault )
            {
                $( '#' + field ).css( 'color', '#679197' );
                window.setTimeout( function shwerr(){ $( '#ERR_' + field ).fadeOut( 'fast' ) }, 1000 );
                return true;
            } else
            {
                $( '#ERR_' + field  ).fadeIn( 'slow' );
                $( '#' + field ).css( 'color', '#DD2231' );
                window.setTimeout( function shwerr(){ $( '#ERR_' + field ).fadeOut( 'slow' ) }, 4000 );
                return false;
            }

            break;
        default:
            doProgress      = true;

            blProgress      = new Array();
            blProgress[0]   = zaen_validate( 'EMAIL', 'mail' );
            blProgress[1]   = ( blProgress[0] && zaen_validate( 'EMAIL', 'pflicht', 'Ihre EMail-Adresse' ) )? true : false;
            blProgress[2]   = ( zaen_validate( 'MGLNR', 'nopflicht', 'Ihre Mitgliedsnummer' ) )? true : false;
            blProgress[3]   = ( zaen_validate( 'TITEL', 'nopflicht', 'Ihr Titel' ) )? true : false;
            blProgress[4]   = ( zaen_validate( 'ANREDE', 'nopflicht', 'Ihre Anrede' ) )? true : false;
            blProgress[5]   = ( zaen_validate( 'NAME', 'pflicht', 'Ihr Name' ) )? true : false;
            blProgress[6]   = ( zaen_validate( 'VNAME', 'pflicht', 'Ihr Vorname' ) )? true : false;
            blProgress[7]   = ( zaen_validate( 'FIRMA', 'nopflicht', 'Ihre Firma' ) )? true : false;
            blProgress[8]   = ( zaen_validate( 'STRASSE', 'pflicht', 'Ihre Strasse' ) )? true : false;
            blProgress[9]   = ( zaen_validate( 'PLZ', 'pflicht', 'Ihre Postleitzahl' ) )? true : false;
            blProgress[10]   = ( zaen_validate( 'ORT', 'pflicht', 'Ihr Wohnort' ) )? true : false;
//            blProgress[11]   = ( zaen_validate( 'GEBDAY', 'day' ) )? true : false;
//            blProgress[12]   = ( blProgress[9] && zaen_validate( 'GEBDAY', 'pflicht', '00' ) )? true : false;
//            blProgress[13]   = ( zaen_validate( 'GEBMONTH', 'month' ) )? true : false;
//            blProgress[14]   = ( blProgress[11] && zaen_validate( 'GEBMONTH', 'pflicht', '00' ) )? true : false;
//            blProgress[15]  = ( zaen_validate( 'GEBYEAR', 'year' ) )? true : false;
//            blProgress[16]  = ( blProgress[13] && zaen_validate( 'GEBYEAR', 'pflicht', '1900' ) )? true : false;
            blProgress[11]  = ( zaen_validate( 'TEL', 'nopflicht', 'Ihre Telefonnummer' ) )? true : false;
            blProgress[12]  = ( zaen_validate( 'FAX', 'nopflicht', 'Ihre Telefaxnummer' ) )? true : false;

            for( iProgress in blProgress )
            {
                if( !blProgress[iProgress]  )
                {
                    doProgress  = false;
                }
            }
            if( doProgress && iShop )
            {
                iShop.submit();
            }
            
            break;
    }
}

function zaen_search()
{
    zaen.blSearch   = false;
    iInput          = document.getElementById( 'input_semsuche' );
    iValue          = ( iInput )? iInput.value  : false;
    iValue          = ( '' != iValue )? iValue  : false;

    if( iValue )
    {
        iURI        = 'evewa2.php?d=5&menu=80900093&__GSAG&filter='+iValue;
    
        $.ajax
        ({
            url: iURI,
            cache: false,
            success: function(html)
            {
                $("#ergebnisse").replaceWith(html);
                tablePager();
            }
        });
    } else
    {
        zaen_refsuche();
        zaen_termine( 0, 0 );
    }
}

function appendSemsuche() {
    var iSemSearch  =   '<div class="zaen_semsuche">' +
                        '<label for="input_semsuche">Seminarsuche:</label>' +
                        '<input type="text" value="" id="input_semsuche" class="zaen_semsuche" onclick="this.value=\'\'"/>' +
                        '</div>';

    $( '#workflow' ).prepend( iSemSearch );
}

var mySelectors = new Array();
