// --------------------------------------------------------------------
function sync ()
{
  if ( top.dtframe != null )
  {
    top.dtframe.Sync();
  }
}
// --------------------------------------------------------------------



// --------------------------------------------------------------------
// interval when creating ZInfo window
var itvToolbarCheckLoaded = null;

// caching new window settings
var strToolbarId = null;
// --------------------------------------------------------------------



// --------------------------------------------------------------------
function loadToolbar ( id )
{
	strToolbarId = id;
	
	if ( itvToolbarCheckLoaded == null )
	{
  	itvToolbarCheckLoaded = setInterval( 'loadToolbarWhenLoaded();', 500 );
  }  
}
// --------------------------------------------------------------------



// --------------------------------------------------------------------
function loadToolbarWhenLoaded ()
{
	if (
	        ( top.bolToolbarPageLoaded == true )
	     && ( itvCheckLoaded == null )
	     && ( top.controlFrame != null )
	     && ( top.controlFrame.document != null )
	     && (
	             ( typeof( top.bolIsHighlighting ) == 'undefined' )
            || ( top.bolIsHighlighting == false )
	        )  
	   )  
	{
		clearInterval( itvToolbarCheckLoaded );
		
		itvToolbarCheckLoaded = null;

    top.controlFrame.document.getElementsByTagName( 'BODY' )[ 0 ].innerHTML = document.getElementById( strToolbarId ).innerHTML;
	}
}
// --------------------------------------------------------------------



// --------------------------------------------------------------------
// interval when creating DAO window
var itvDaoCheckLoaded = null;

// caching new window settings
var wdwDao      = null;
var strDaoId    = null;
var strDaoIndex = null;
var strDaoCount = null;
// --------------------------------------------------------------------



// --------------------------------------------------------------------
function openDao ( id, Index, Count, TargetTagName, Page, Window, ProzentBreite, ProzentHoehe  )
{
	wdwDao      = openElementInWindowReturn( id + '_dao', TargetTagName, Page, Window, ProzentBreite, ProzentHoehe );
	strDaoId    = id;
	strDaoIndex = Index;
	strDaoCount = Count;
	
	if ( itvDaoCheckLoaded == null )
	{
  	itvDaoCheckLoaded = setInterval( 'showDaoWhenLoaded();', 500 );
  }  
}
// --------------------------------------------------------------------



// --------------------------------------------------------------------
function showDaoWhenLoaded ()
{
	if (
	        ( wdwDao.top.bolIsPageLoaded == true )
	     && ( itvCheckLoaded == null )
	   )  
	{
		clearInterval( itvDaoCheckLoaded );
		
		itvDaoCheckLoaded = null;

		wdwDao.showDao( strDaoId, strDaoIndex, strDaoCount );
	}
}
// --------------------------------------------------------------------



// --------------------------------------------------------------------
// interval when creating ZInfo window
var itvZInfoCheckLoaded = null;

// caching new window settings
var wdwZInfo     = null;
var strZInfoId   = null;
var strZInfoType = null;
// --------------------------------------------------------------------



// --------------------------------------------------------------------
function openZInfo ( id, type, TargetTagName, Page, Window, ProzentBreite, ProzentHoehe  )
{
	wdwZInfo     = openElementInWindowReturn( id + '_zinfo', TargetTagName, Page, Window, ProzentBreite, ProzentHoehe );
	strZInfoId   = id;
	strZInfoType = type;
	
	if ( itvZInfoCheckLoaded == null )
	{
  	itvZInfoCheckLoaded = setInterval( 'showZInfoWhenLoaded();', 500 );
  }  
}
// --------------------------------------------------------------------



// --------------------------------------------------------------------
function showZInfoWhenLoaded ()
{
	if (
	        ( wdwZInfo.top.bolIsPageLoaded == true )
	     && ( itvCheckLoaded == null )
	   )  
	{
		clearInterval( itvZInfoCheckLoaded );
		
		itvZInfoCheckLoaded = null;

		wdwZInfo.showZInfo( strZInfoId, strZInfoType );
	}
}
// --------------------------------------------------------------------



// --------------------------------------------------------------------
// interval when creating new window
var itvCheckLoaded = null;

// caching new window settings
var wdwWindow  = null;
var strElement = null;
var strTagName = null;
// --------------------------------------------------------------------



// --------------------------------------------------------------------
function openElementInWindow ( ElementId, TargetTagName, Page, Window, ProzentBreite, ProzentHoehe )
{
	openElementInWindowReturn ( ElementId, TargetTagName, Page, Window, ProzentBreite, ProzentHoehe );
}
// --------------------------------------------------------------------



// --------------------------------------------------------------------
function openElementInWindowReturn ( ElementId, TargetTagName, Page, Window, ProzentBreite, ProzentHoehe )
{
	wdwWindow  = openWindowReturn( Page, Window, ProzentBreite, ProzentHoehe );
	strElement = ElementId;
	strTagName = TargetTagName;
	
	if ( itvCheckLoaded == null )
	{
  	itvCheckLoaded = setInterval( 'openElementInWindowWhenLoaded();', 500 );
  }  
  
  return wdwWindow;
}
// --------------------------------------------------------------------



// --------------------------------------------------------------------
function openElementInWindowWhenLoaded ()
{
	if ( wdwWindow.top.bolIsPageLoaded == true )
	{
		clearInterval( itvCheckLoaded );
		
		itvCheckLoaded = null;

  	wdwWindow.document.getElementsByTagName( strTagName )[ 0 ].innerHTML = document.getElementById( strElement ).innerHTML;
	}
}
// --------------------------------------------------------------------



// --------------------------------------------------------------------
function openWindow ( Page, Window, ProzentBreite, ProzentHoehe )
{
	openWindowReturn( Page, Window, ProzentBreite, ProzentHoehe );
}
// --------------------------------------------------------------------



// --------------------------------------------------------------------
function openWindowReturn ( Page, Window, ProzentBreite, ProzentHoehe )
{
  var newwindow;
  
	switch ( Window )  
	{
		case 'Suche':
		  newwindow = top.windowSuche;
		break;
		
		case 'Index':
		  newwindow = top.windowIndex;
		break;
		
		case 'Gliederung':
		  newwindow = top.windowGliederung;
		break;
		
		case 'Abkuerzungen':
		  newwindow = top.windowAbkuerzungen;
		break;
		
		case 'Hilfe':
		  newwindow = top.windowHilfe;
		break;
		
		/* fuer Zusatzinfos und Druckansicht immer neu laden
		case 'Druckansicht':
		  newwindow = top.windowDruckansicht;
		break;
		
		case 'Zusatzinfo':
		  newwindow = top.windowZusatzinfo;
		break;
		
		case 'DAO':
		  newwindow = top.windowDao;
		break;
		*/
	}
	
	if (
          ( typeof( newwindow ) != 'object' )
       || ( newwindow.closed == true )
     )
  {
	  newwindow = null;
  }   
	
  var Breite = 400;
  var Hoehe = 480;
  
  if ( self.screen )
  {
    Breite = ( screen.width / 100 ) * ProzentBreite;
    Hoehe = ( screen.height / 100 ) * ProzentHoehe;
  }

	if ( newwindow == null )
	{
	  newwindow = window.open( Page, Window, 'RESIZABLE=yes,MENUBAR=yes,SCROLLBARS=yes,WIDTH=' + Breite + ',HEIGHT=' + Hoehe + '' );
	  
	  if ( navigator.appVersion.substring( 0, 1 ) >= "4" )
	  {
	    var X = 0;
	    var I = 105;
	    
	    if ( navigator.appVersion == 'Netscape' ) 
	    {
	      var X = 2;
	      var I = 100;
	    }

	    var Y = ( screen.height - I - Hoehe );
	    
	    newwindow.moveTo( X, Y );
	  }
	}  
	
	if ( newwindow != null )
	{
    newwindow.focus();
  }  
  
	switch ( Window )  
	{
		case 'Suche':
		  top.windowSuche = newwindow;
		break;
		
		case 'Index':
		  top.windowIndex = newwindow;
		break;
		
		case 'Gliederung':
		  top.windowGliederung = newwindow;
		break;
		
		case 'Abkuerzungen':
		  top.windowAbkuerzungen = newwindow;
		break;
		
		case 'Hilfe':
		  top.windowHilfe = newwindow;
		break;
		
		case 'Druckansicht':
		  top.windowDruckansicht = newwindow;
		break;
		
		case 'Zusatzinfo':
		 top.windowZusatzinfo = newwindow;
		break;
		
		case 'DAO':
		 top.windowDao = newwindow;
		break;
	}
	
	return newwindow;
}
// --------------------------------------------------------------------



// --------------------------------------------------------------------
// interval when checking for highlighting
var itvHihglightingCheckLoaded = null;

// caching highlight settings
var objHighlightingFrame   = null;
var strHighlightingTagName = null;
var aryHighlightingStrings = null;
var strHighlightingColor   = null;
// --------------------------------------------------------------------



// --------------------------------------------------------------------
function applyHighlightingElement ( frame, tagname, strings, color )
{
	objHighlightingFrame   = frame;
	strHighlightingTagName = tagname;
	aryHighlightingStrings = strings;
	strHighlightingColor   = color;
	objHighlightingFrame.top.bolIsHighlighting = true;
	
	if ( itvHihglightingCheckLoaded == null )
	{
	  itvHihglightingCheckLoaded = setInterval( 'applyHighlightingElementWhenLoaded();', 500 );
  }  
}
// --------------------------------------------------------------------



// --------------------------------------------------------------------
function applyHighlightingElementWhenLoaded ()
{
	if ( objHighlightingFrame.bolIsPageLoaded == true )
	{
		clearInterval( itvHihglightingCheckLoaded );
		
		itvHihglightingCheckLoaded = null;

		if ( objHighlightingFrame.bolIsHighlighted == false )
		{	
			var coll = objHighlightingFrame.document.getElementsByTagName(strHighlightingTagName);

			for(var i = 0; i < coll.length; i++)
			{
				var objHighlightingElement = coll[i];
				objHighlightingElement.innerHTML = applyHighlightingHTML
			  ( 
			    objHighlightingElement.innerHTML, 
		  	  aryHighlightingStrings, 
		    	strHighlightingColor 
			  );

				// Internet Explorer - Bug?
				// Beim Aendern von innerHtml aendert sich auch das Beszugsverzeichnis
				// der Datei, dem wird hier entgegengewirkt
/*
				if ( navigator.appName == 'Microsoft Internet Explorer' )
				{
					var aryHidden = objHighlightingElement.getElementsByTagName('DIV');
				
					for ( var i = 0; i < aryHidden.length; i++ )
					{
						aryHidden[i].innerHTML = aryHidden[i].innerHTML.replace
						( 
						  new RegExp( 
					              '("[^"]*)xml/inhalt/(xml/inhalt/|images/)([^"]*")', 
					              'g'
						            ),
						  '$1$2$3'
						);
				  }	
			  }
*/
			}
		  
		  objHighlightingFrame.bolIsHighlighted = true;
	  }  
	  
	  objHighlightingFrame.top.bolIsHighlighting = false;
	}
}
// --------------------------------------------------------------------



// --------------------------------------------------------------------
function applyHighlightingHTML ( html, strings, color )
{
	var style = 'background:' + color + ';'
				    
				 	/*+ 'margin-top:0px;'
				    + 'margin-bottom:0px;'
				    + 'margin-left:0px;'
				    + 'margin-right:0px;'	    
				    + 'padding-left:0px;'
				    + 'padding-right:0px;';*/
				    
	
					/*    + 'margin-top:-3px;'
				    + 'margin-bottom:-3px;'
				    + 'margin-left:5px;'
				    + 'margin-right:-5px;'	    
				    + 'padding-left:0px;'
				    + 'padding-right:0px;';*/
	
	
  // apply highlighting for	all search words
	for ( var i = 0; i < strings.length; i++ )
	{
		var strPattern  = strings[ i ];
		var strModify   = '';
		
		if ( strPattern.substr( 0, 1 ) == '"' )
		{
			strModify  = 'i';
			strPattern = strPattern
			             .substr( 1, strPattern.length )
			             .replace( /\s+/g, '\\s+' );
		}
		
	  html = html.replace
		( 
	    new RegExp( 
	                '(' + strPattern + ')(?=([^<>]*<)|([^<>]*$))', 
	                'g' + strModify
	              ),
      '<SPAN CLASS="highlight" STYLE="' + style + '">$1</SPAN>'
	  );
  }
  
  return html;
}
// --------------------------------------------------------------------

