
function changeCheck(i) {
	document.kat_suche.suchbereich[i].checked = true;
}

function selectCat(i) {
	if (i == 0) {
		document.kat_suche.kat_auswahl.selectedIndex = 0;
		changeCheck(0);
	}
	if (i == 1) {
		document.kat_suche.kat_auswahl.selectedIndex = 13;
		changeCheck(1);
	}
	if (i == 2) {
		document.kat_suche.kat_auswahl.selectedIndex = 23;
		changeCheck(2);
	}
}

function changeCat() {
	var n = document.kat_suche.kat_auswahl.selectedIndex;
	if (n < 13) {
		changeCheck(0);
	}
	if ((n > 12) && (n < 23)) {
		changeCheck(1);
	}
	if (n > 22) {
		changeCheck(2);
	}
}

// die Veranstaltungskategorie ueber die SelectBox veraendern
function vChangeCat(c) {
    var oldloc = window.location.protocol + '//' + window.location.hostname + (window.location.port ? ':' + window.location.port : '') + window.location.pathname;
    var params = window.location.search;
    oldloc = oldloc + "/";
    oldloc = oldloc.replace(/\/\/$/,"/");
    var newloc = oldloc.replace(/kat-\d+\/*/,'');
    if (c) {
        newloc = newloc + "kat-" + c + "/";
    }
    window.location = newloc + params;
}

// die Startzeit ueber die SelectBox veraendern
function vChangeStartZeit(s,e) {
    var oldloc = window.location.protocol + '//' + window.location.hostname + (window.location.port ? ':' + window.location.port : '') + window.location.pathname;
    var params = window.location.search;
    oldloc = oldloc + "/";
    oldloc = oldloc.replace(/\/\/$/,"/");
    var newloc = oldloc.replace(/zeitvon-\d+\/*/,'');
	if (s && s > e) {
		alert("Fehler: die Startzeit muss vor der Endzeit liegen.");
		s = 0;
	}
	if (s && s <= e) {
		newloc = newloc + "zeitvon-" + s + "/";
	}
	window.location = newloc + params;
}

// die Endzeit ueber die SelectBox veraendern
function vChangeEndZeit(e,s) {
    var oldloc = window.location.protocol + '//' + window.location.hostname + (window.location.port ? ':' + window.location.port : '') + window.location.pathname;
    var params = window.location.search;
    oldloc = oldloc + "/";
    oldloc = oldloc.replace(/\/\/$/,"/");
    var newloc = oldloc.replace(/zeitbis-\d+\/*/,'');
    if (e && e < s) {
        alert("Fehler: die Startzeit muss vor der Endzeit liegen.");
        e = 24;
    }
    if (e && e >= s) {
        newloc = newloc + "zeitbis-" + e + "/";
    }
    window.location = newloc + params;
}

//  #   #   #   #   #   #   #
// HTTP.Request 0.03 von OpenJSAN.org
//  #   #   #   #   #   #   #

if ( typeof( Method ) == "undefined" ) {
    Method = {};
}

if ( typeof( Method["bind"] ) == "undefined" ) {
    Method.bind = function ( method, object ) {
        return function() {
            method.apply(object, arguments);
        }
    };
}

if ( typeof( HTTP ) == "undefined" ) {
    HTTP = {};
}

if ( typeof( HTTP.Request ) == "undefined" ) {
    HTTP.Request = function ( options ) {
        if ( !options ) options = {};

        this.options = {};
        for ( var i in options ) {
            this.setOption( i, options[i] );
        }

        if ( this.getOption( "method" ) == undefined ) {
            this.setOption( "method", "post" );
        }

        if ( this.getOption( "asynchronous" ) == undefined ) {
            this.setOption( "asynchronous", true );
        }

        if ( this.getOption( "parameters" ) == undefined ) {
            this.setOption( "parameters", "" );
        }

        if ( this.getOption( "transport" ) == undefined ) {
            this.setOption( "transport", HTTP.Request.Transport );
        }

        if ( this.getOption( "uri" ) )
            this.request();
    };

    HTTP.Request.EventNames = [
        "uninitialized"
       ,"loading"
       ,"loaded"
       ,"interactive"
       ,"complete"
    ];

    HTTP.Request.prototype.getOption = function( name ) {
        if ( typeof( name ) != "string" ) {
            return;
        }
        return this.options[name.toLowerCase()];
    };

    HTTP.Request.prototype.setOption = function( name, value ) {
        if ( typeof( name ) != "string" ) {
            return;
        }

        name = name.toLowerCase();

        this.options[name] = value;

        if ( name == "method" ) {
            if ( ! ( this.options.method == "get" || this.options.method == "post" || this.options.method == "head" ) ) {
                this.options.method = "post";
            }
        }

        if ( name == "transport" ) {
            if ( typeof( value ) != "function" ) {
                this.options.transport = HTTP.Request.Transport;
            }
        }
    };

    HTTP.Request.prototype.request = function ( uri ) {
        if ( ! uri ) uri = this.getOption( "uri" );
        if ( ! uri ) return;

        var parameters = this.getOption( "parameters" );
        // XXX Why?
        if (parameters.length > 0) parameters += "&_=";

        var method = this.getOption( "method" );
        if ( method == "get" ) {
            uri += "?" + parameters;
        }

        this.transport = new (this.getOption( "transport" ))();

        var async = this.getOption( "asynchronous" );
        this.transport.open( method ,uri ,async );

        if ( async ) {
            this.transport.onreadystatechange = Method.bind(
                this.onStateChange, this
            );

            setTimeout(
                Method.bind(
                    function() { this.respondToReadyState(1) }
                   ,this
                )
               ,10
           );
        }

        this.setRequestHeaders();

        if ( method == "post" ) {
            var body = this.getOption( "postbody" );
            if ( ! body ) body = parameters;

            this.transport.send( body );
        }
        else {
            this.transport.send( null );
        }
    };

    HTTP.Request.prototype.setRequestHeaders = function() {
        this.transport.setRequestHeader( "X-Requested-With", "HTTP.Request" );
        this.transport.setRequestHeader( "X-HTTP-Request-Version", HTTP.Request.VERSION );

        if (this.getOption( "method" ) == "post") {
            this.transport.setRequestHeader( "Content-type", "application/x-www-form-urlencoded" );

            /* Force "Connection: close" for Mozilla browsers to work around
             * a bug where XMLHttpReqeuest sends an incorrect Content-length
             * header. See Mozilla Bugzilla #246651.
             */
            if (this.transport.overrideMimeType) {
                this.transport.setRequestHeader( "Connection", "close" );
            }
        }

/* TODO Add support for this back in later
	if (this.options.requestHeaders) requestHeaders.push.apply(requestHeaders, this.options.requestHeaders);
*/
    };

    // XXX This confuses me a little ... how are undefined and 0 considered a success?
    HTTP.Request.prototype.isSuccess = function () {
        return this.transport.status == undefined
            || this.transport.status == 0
            || (this.transport.status >= 200 && this.transport.status < 300);
    };

    HTTP.Request.prototype.onStateChange = function() {
        var readyState = this.transport.readyState;
        if (readyState != 1) {
            this.respondToReadyState( this.transport.readyState );
        }
    };

    HTTP.Request.prototype.respondToReadyState = function( readyState ) {
        var event = HTTP.Request.EventNames[readyState];
        if (event == "complete") {
            var func = this.getOption( "on" + this.transport.status );
            if ( ! func ) {
                if ( this.isSuccess() ) {
						func = this.getOption( "onsuccess" );
                }
                else {
						func = this.getOption( "onfailure" );
                }
            }
            if ( func ) {
					( func )( this.transport );
            }
        }
        if ( this.getOption( "on" + event ) )
            ( this.getOption( "on" + event ) )( this.transport );
        /* Avoid memory leak in MSIE: clean up the oncomplete event handler */
        if (event == "complete") {
				this.transport.onreadystatechange = function (){};
        }
    };
    HTTP.Request.VERSION = 0.03;

}

if ( typeof( HTTP.Request.Transport ) == "undefined" ) {
    if ( window.XMLHttpRequest ) {
        HTTP.Request.Transport = window.XMLHttpRequest;
    }
    // This tests for ActiveXObject in IE5+
    else if ( window.ActiveXObject && window.clipboardData ) {
		new ActiveXObject("Microsoft.XMLHTTP");
		HTTP.Request.Transport = function () {
			return new ActiveXObject("Microsoft.XMLHTTP");
		}
    }
    if ( typeof( HTTP.Request.Transport ) == "undefined" ) {
		// This is where we add DIV/IFRAME support masquerading as an XMLHttpRequest object
    }
    if ( typeof( HTTP.Request.Transport ) == "undefined" ) {
		throw new Error("Unable to locate XMLHttpRequest or other HTTP transport mechanism");
    }
}


//  #   #   #   #   #   #   #
// Ajax Routinen
//  #   #   #   #   #   #   #

if (window.XMLHttpRequest || (window.ActiveXObject && window.clipboardData)) {
    // fähiger Browser, Cookie entsprechend setzen
    // document.cookie = 'cookiesenabled=ajax' + ';path=/';
}

var req, captcha_id;

function get_captcha () {
	if (captcha_id)
		return;
	req = new HTTP.Request({
		uri: '/treff/',
		postbody: 'rm=ajaxcaptcha',
		onSuccess: function (trans) {
 			captcha_id = trans.responseText;
			// in hidden form field eintragen
			var captcha_hidden = document.getElementById('captcha_session');
			captcha_hidden.value = captcha_id;
			//var captcha_hidden1 = document.getElementById('captcha_session1');
			//captcha_hidden1.value = captcha_id;
			// captcha bild laden
			var captcha_bild = document.getElementById('captcha_img');
			captcha_bild.onerror = function () {
				alert("Das Captcha-Bild konnte nicht geladen werden.\n Bitte laden Sie die Seite neu und versuchen Sie es erneut.");
			}
			captcha_bild.src='/treff/?rm=showcaptcha&CGISESSID=' + captcha_id;
			// captcha bild laden
			//var captcha_bild1 = document.getElementById('captcha_img1');
			//captcha_bild1.onerror = function () {
			//	alert("Das Captcha-Bild konnte nicht geladen werden.\n Bitte laden Sie die Seite neu und versuchen Sie es erneut.");
			//}
			//captcha_bild1.src='/treff/?rm=showcaptcha&CGISESSID=' + captcha_id;
		},
		onFailure: function () {
			alert("XMLHttpRequest Problem beim Captcha.\n Bitte laden Sie die Seite neu und versuchen Sie es erneut.");
		}
    });
}

// Bei Veranstaltungen Minuten mit Nullen vorbelegen, wenn Stunde vorhanden
function v_zero_fill(hour_field) {
    var minute_field_id = hour_field.id.replace( /_stunde$/, '_minute' ); // Zugehoeriges Minutenfeld
    var minute_field = document.getElementById(minute_field_id);
    if ( hour_field.value.length > 0 && minute_field.value.length == 0 ) {
        minute_field.value = '00';
    }
}


//***
//*** Cookies kompfortabel nutzen
//***

/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure)
{
	document.cookie= name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
		document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}


/*  for Mozilla browsers from http://dean.edwards.name/weblog/2005/09/busted/ */
//if (document.addEventListener) {
//document.addEventListener("DOMContentLoaded", toggle_eintaegig_mehrtaegig_onload, null);
//}

// Aktiviert/deaktiviert jeweils die Eingabefelder fuer ein-/mehrtaegig
function toggle_eintaegig_mehrtaegig(radioset) {
  var eintaegig_mehrtaegig = radioset.value; // Entweder "eintaegig" oder "mehrtaegig"
  var the_form = window.document.forms.the_form;
  var elemente_eintaegig = new Array(
    the_form.eintag_datum_tag,
    the_form.eintag_datum_monat,
    the_form.eintag_datum_jahr,
    the_form.eintag_uhrzeit_von_stunde,
    the_form.eintag_uhrzeit_von_minute,
    the_form.eintag_uhrzeit_bis_stunde,
    the_form.eintag_uhrzeit_bis_minute
//    ,the_form.kalender_eintag
  );
  var elemente_mehrtaegig = new Array(
    the_form.mehrtag_datum_von_tag,
    the_form.mehrtag_datum_von_monat,
    the_form.mehrtag_datum_von_jahr,
    the_form.mehrtag_datum_bis_tag,
    the_form.mehrtag_datum_bis_monat,
    the_form.mehrtag_datum_bis_jahr,
    the_form.mehrtag_frequenz[0],
    the_form.mehrtag_frequenz[1],
    the_form.mehrtag_frequenz[2],
    the_form.mehrtag_frequenz[3],
    the_form.mehrtag_einzeltage_1,
    the_form.mehrtag_einzeltage_2,
    the_form.mehrtag_einzeltage_3,
    the_form.mehrtag_einzeltage_4,
    the_form.mehrtag_einzeltage_5,
    the_form.mehrtag_einzeltage_6,
    the_form.mehrtag_einzeltage_7,
    the_form.mehrtag_uhrzeit_von_stunde,
    the_form.mehrtag_uhrzeit_von_minute,
    the_form.mehrtag_uhrzeit_bis_stunde,
    the_form.mehrtag_uhrzeit_bis_minute
//    ,the_form.kalender_mehrtag_von,
//    the_form.kalender_mehrtag_bis
  );
  if ( eintaegig_mehrtaegig == "eintaegig" ) {
    // Eintaegig enablen
    for (i in elemente_eintaegig)  { elemente_eintaegig[i].disabled  = false; }
    // Mehrtaegig disablen
    for (i in elemente_mehrtaegig) { elemente_mehrtaegig[i].disabled = true;  }
    // CSS-Klasse setzen
    document.getElementById('eingabe_eintaegig').className = '';
    document.getElementById('eingabe_mehrtaegig').className = 'flau';
    if (document.getElementById('error_eintaegig')) {
      document.getElementById('error_eintaegig').className = 'error';
    }
    if (document.getElementById('error_mehrtaegig_datum')) {
      document.getElementById('error_mehrtaegig_datum').className = 'flau';
    }
    if (document.getElementById('error_mehrtaegig_frequenz')) {
      document.getElementById('error_mehrtaegig_frequenz').className = 'flau';
    }
    if (document.getElementById('error_mehrtaegig_uhrzeit')) {
      document.getElementById('error_mehrtaegig_uhrzeit').className = 'flau';
    }
  } else if (eintaegig_mehrtaegig == "mehrtaegig") {
    // Eintaegig disablen
    for (i in elemente_eintaegig)  { elemente_eintaegig[i].disabled  = true;  }
    // Mehrtaegig enablen
    for (i in elemente_mehrtaegig) { elemente_mehrtaegig[i].disabled = false; }
    // CSS-Klasse setzen
    document.getElementById('eingabe_eintaegig').className = 'flau';
    document.getElementById('eingabe_mehrtaegig').className = '';
    if (document.getElementById('error_eintaegig')) {
      document.getElementById('error_eintaegig').className = 'flau';
    }
    if (document.getElementById('error_mehrtaegig_datum')) {
      document.getElementById('error_mehrtaegig_datum').className = 'error';
    }
    if (document.getElementById('error_mehrtaegig_frequenz')) {
      document.getElementById('error_mehrtaegig_frequenz').className = 'error';
    }
    if (document.getElementById('error_mehrtaegig_uhrzeit')) {
      document.getElementById('error_mehrtaegig_uhrzeit').className = 'error';
    }
  }
}

// Abhaengig von der Auswahl wird eintaegig oder mehrtaegig deaktiviert
function toggle_eintaegig_mehrtaegig_onload() {
  var the_form = window.document.forms.the_form;
  //alert(the_form.eintaegig_mehrtaegig[0].checked);
  //alert(the_form.eintaegig_mehrtaegig[1].checked);
  if (the_form.eintaegig_mehrtaegig[0].checked) {
    // Eintaegig ausgewaehlt
    toggle_eintaegig_mehrtaegig(the_form.eintaegig_mehrtaegig[0]);
  } else if (the_form.eintaegig_mehrtaegig[1].checked) {
    // Mehrtaegig ausgewaehlt
    toggle_eintaegig_mehrtaegig(the_form.eintaegig_mehrtaegig[1]);
  }
}

// Drop-Down Menu
window.gbar={};
(
function()
{
var b=window.gbar,f,h;
b.qs=function(a){var c=window.encodeURIComponent&&(document.forms[0].q||"").value;if(c)a.href=a.href.replace(/([?&])q=[^&]*|$/,function(i,g){return(g||"&")+"q="+encodeURIComponent(c)})};
function j(a,c){a.visibility=h?"hidden":"visible";a.left=c+"px"}
b.tg=function(a)
{
a=a||window.event;var c=0,i,g=window.navExtra,d=document.getElementById("gbi"),e=a.target||a.srcElement;a.cancelBubble=true;
if(!f)
{
f=document.createElement(Array.every||window.createPopup?"iframe":"div");
f.frameBorder="0";
f.src="#";
d.parentNode.appendChild(f).id="gbs";
if(g)for(i in g)d.insertBefore(g[i],d.firstChild).className="gb2";document.onclick=b.close
}
if(e.className!="gb3")e=e.parentNode;do c+=e.offsetLeft;while(e=e.offsetParent);j(d.style,c);f.style.width=d.offsetWidth+"px";f.style.height=d.offsetHeight+"px";j(f.style,c);h=!h
};
b.close=function(a){h&&b.tg(a)}
}
)();

// Input-Box as "Link"
function go(url){
if(!url) return false;
window.location.href = url;
}

// Text-Block nur fuer "JS disabled"-Browser(auch SE-Bots) anzeigen
document.write('<style>.js_disable { display:none }</style>');

// fuer karta
function popitup(url) {
//window.open(url,'name',"width=800,height=600,scrollbars=no,status=no");
newwindow=window.open(url,'name',"width=800,height=600,scrollbars=no,status=no");
//if (window.focus) {newwindow.focus();}
//return false;
}

function goto(url) {
location.href = url; 
}

// Breite fuer iframe dynamisch definieren
//function setKartaWidth() {
//var iframeElement = parent.document.getElementById('iframeName');
//iframeElement.style.height = '315px';
//iframeElement.style.width = document.getElementsByTagName("div")["someDiv"].offsetWidth-34+'px';
//}

//function hideLoading() {
//document.getElementById('divLoading').style.display = "none";
//document.getElementById('divFrameHolder').style.display = "block";
//}

