loadIncludes = function()
{
    // Session-Ping falls Element vorhanden
	if($('sessionPing')) {
		new Ajax.PeriodicalUpdater(	'sessionPing', 
									'/javascript/session-ping', {
	        						method: 'get', 
	        						frequency: 300 
	    });
	}
	
	//Allen FormularElementen Methoden zuweisen
    if(document.forms && (document.forms.length > 0)){
        document.require(window.config.url.common_js + '/elementCreate.js');
        document.require(window.config.url.common_js + '/form.js');
    }
    var galleryLinks;
    if( galleryLinks = $$('a[href*=popupGallery]') ){
        if(galleryLinks.length > 0){
            document.require(window.config.url.common_js + '/pic_popups.js');
        }
    }
    if($('anid')){
        document.require(window.config.url.common_js + '/openimmoanid.js');
    }
    var tooltipLinks;
    if(tooltipLinks = $$('a[onmouseover^=tjs_show]')){
        if(tooltipLinks.length > 0){
            document.require(window.config.url.common_js + '/tooltip.js');
        }
    }
    $$('.auto_complete').each(function(e){
        var divId = '';
        var formfieldId = '';
        var divId = e.id;
        formfieldId = e.id.sub('_autocomplete','');
        formElement = $(formfieldId);
        var autoCompleterId = formElement.form.name + '_' + e.id;
        if(document[autoCompleterId]){
            formElement.stopObserving('blur');
            formElement.stopObserving('keydown');
            formElement.stopObserving("mouseover");
            formElement.stopObserving("click");
            delete document[autoCompleterId];
        }
        document[autoCompleterId] = new Ajax.Autocompleter(
            formfieldId,
            divId,
            '/innerhtml/modelget/?obj=autocomplete&noStringDelimiters=1',
            {
                'method':'get',
                'minChars':5,
                'onHide': function(element, update){  update.hide();},
                'onShow': function(element, update){ 
                    if(!update.style.position || update.style.position=='absolute') {
                      update.style.position = 'absolute';
                      Position.clone(element, update, {
                        setHeight: false, 
                        offsetTop: element.offsetHeight
                      });
                    }
                    update.show();
               }
            }
        );
    });
    //Methode zum erzeugen eines PopUps
    //Klasse im HTML: popupPrint
    var popupPrint = $$('a.popupPrint');
	for (var i = 0, len = popupPrint.length; i < len; ++i) {
		popupPrint[i].observe('click', 
			function buttonClick(event){
				Event.stop(event);
				MM_openBrWindow(this.href,'','scrollbars=yes,width=800,height=800,left=200,top=0');
			}); 
    }
    
    var popupPrint = $$('a.popupSmall');
	for (var i = 0, len = popupPrint.length; i < len; ++i) {
		popupPrint[i].observe('click', 
			function buttonClick(event){
				Event.stop(event);
				MM_openBrWindow(this.href,'','scrollbars=yes,width=600,height=600,left=200,top=0');
			}); 
    }
	
	// Erzeugt ein Popup-Fenster, welches ein Bild anzeigt und seine Größe von diesem abhängig macht
	var popupImage = $$('a.popupImage');
	for (var i = 0, len = popupImage.length; i < len; ++i) {
		popupImage[i].observe('click', 
			function buttonClick(event) {
				Event.stop(event);
				if(this.href.indexOf('.pdf')) {
					Fenster = window.open(this.href, 'PDF');
				} else {
					Optionen = 	'toolbar=no, location=no, directories=0, status=no, menubar=no, scrollbars=yes, resizable=0, left=20, top=20';
					Fenster = window.open('about:blank', 'Bilder', Optionen);
					Fenster.document.write('<img src="' + this.href + '" alt="'+ this.title + '"/>');
					Fenster.document.close();
					Fenster.onload = function()	
					{
						Fenster.resizeTo(Fenster.document.images[0].width+50, Fenster.document.images[0].height+50);
					}
				}		
			}); 
    }
	
	
	var newwindowLinks = $$('a.newwindow');
	for (var i = 0, len = newwindowLinks.length; i < len; ++i) {
		newwindowLinks[i].target="_blank";
    }
}

Event.observe(window,'load',loadIncludes);


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
  if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
  obj.visibility=v; }
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

	function over(id) {
		document.getElementById(id).style.backgroundImage = "url(images/hg_navi_hover.gif)";
//		document.getElementById(id).class = "";
	}
	function overOut(id) {
		document.getElementById(id).style.backgroundImage = "url(images/hg_navi.gif)";
	}
function jumpAndClosePopup(href){
	opener.location.href=href;
	window.close();
}





/***********************************************
* Bookmark site script- Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

/* Modified to support Opera */
function bookmarkSite(url, title){
	
	if (window.sidebar) { // firefox
		window.sidebar.addPanel(title, url, "");
	
	} else if(window.opera && window.print) { // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	
	} else if(document.all) { // ie
		window.external.AddFavorite(url, title);
	}
}
document.require = function ( file ) {
    if( file.length == 0 ) {
        return;
    }
    if( !document.createElement ) {
        return;
    }
    
    //return document.write('<script type="text/javascript" src="'+file+'"><\/script>');
    var script = document.createElement( 'script' );
    if(script) {
        script.setAttribute( 'type', 'text/javascript' );
        script.setAttribute( 'src', file );
        
        var head = $$('head')[0];
        if(head) {
            head.appendChild( script );
        }
    }
}
function printPage() {
    if (window.print) {
        ok = confirm('Wenn Sie Ihren Drucker eingeschaltet haben,\ndrücken Sie Bitte auf OK!');
        if (ok) window.print();
    }
}
function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name,"",-1);
}


function eraseCookies(names) {
    for (var i = 0; i < names.length; i++) {
        eraseCookie(names[i]);
    }
}
function fireNative(element,event){
    if (document.createEventObject){
        // dispatch for IE
        var evt = document.createEventObject();
        element.fireEvent('on'+event,evt);
    }
    else{
        // dispatch for firefox + others
        var evt = document.createEvent("HTMLEvents");
        evt.initEvent(event, true, true ); // event type,bubbling,cancelable
        return !element.dispatchEvent(evt);
    }
}
