// ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### 
// 
// ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### 


function registerSubmitForm(formId)
	{
	if (!formId)
		{
		document.onkeyup = nothing; 
		}
	else
		{
		idToSubmit = formId;
		document.onkeyup = checkKeyEvent; 
		}
	}

function nothing()
	{
	
	}

function checkKeyEvent( ev) { // Event wird im FF direkt an die Funktion übergeben
  if (!ev) ev = window.event; // Falls nicht wird window.event genommen
  var key = (ev.keyCode) ? ev.keyCode : ev.which;
  if (key == 13) SubmitForm( idToSubmit );
}

var LinkDock =
{
	/* ============================================================================= *\
	||
	\* ============================================================================= */
	linkdock_id : "",
	linkdock_styles : null,

	/* ============================================================================= *\
	||
	\* ============================================================================= */
	init : function( init_linkdock_id, init_linkdock_styles )
	{
		Event.observe( window, 'load', LinkDock.page_loaded, false );
		linkdock_id = init_linkdock_id;
		linkdock_styles = init_linkdock_styles;
	},

	/* ============================================================================= *\
	||
	\* ============================================================================= */
	page_loaded : function( anEvent )
	{
		Event.observe( 'LinkDock', 'mouseover', LinkDock.do_onmouseover, false );
		// Event.observe( 'LinkDock', 'mouseout' , LinkDock.do_onreset    , false );
	},

	/* ============================================================================= *\
	||
	\* ============================================================================= */
	do_onmouseover : function( anEvent )
	{
		//
		LinkDock.do_onreset();

		//
		var aLink = Event.element( anEvent );
		if( aLink.className == "fix" ) return;

		if( tmpLink = aLink.previous( 'a',3 ) ) { Element.setStyle( tmpLink, linkdock_styles[ 0 ] ); };
		if( tmpLink = aLink.previous( 'a',2 ) ) { Element.setStyle( tmpLink, linkdock_styles[ 1 ] ); };
		if( tmpLink = aLink.previous( 'a',1 ) ) { Element.setStyle( tmpLink, linkdock_styles[ 2 ] ); };
		if( tmpLink = aLink.previous( 'a'   ) ) { Element.setStyle( tmpLink, linkdock_styles[ 3 ] ); };
												  Element.setStyle( aLink  , linkdock_styles[ 4 ] );
		if( tmpLink = aLink.next( 'a'   )     ) { Element.setStyle( tmpLink, linkdock_styles[ 3 ] ); };
		if( tmpLink = aLink.next( 'a',1 )     ) { Element.setStyle( tmpLink, linkdock_styles[ 2 ] ); };
		if( tmpLink = aLink.next( 'a',2 )     ) { Element.setStyle( tmpLink, linkdock_styles[ 1 ] ); };
		if( tmpLink = aLink.next( 'a',3 )     ) { Element.setStyle( tmpLink, linkdock_styles[ 0 ] ); };

		Event.stop( anEvent ); //avoid another call related to 'parent_node' itself
	},

	/* ============================================================================= *\
	||
	\* ============================================================================= */
	do_onreset : function()
	{
		$$( '#' + linkdock_id + ' a' ).each( function( item ) { Element.setStyle( item, linkdock_styles[ 0 ] ); } );
	}
};


// ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### 
// 
// ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### 

// ======= ======= ======= ======= ======= ======= ======= 
//
// ======= ======= ======= ======= ======= ======= ======= 
function AntiSpam( aName, aDomain, aText, aClass )
{

	if( ! aText || aText == "" ) aText = aName + "@" + aDomain;

	if( aClass && aClass != "" ) aClass = "class=\"" + aClass + "\" "; else	aClass = '';
	
	document.write( "<a " + aClass + "href=\"mailto:" + aName + "@" + aDomain + "\">" + aText + "</a>" + (document.layers ? "</font><font>":"") )
}


// ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### 
// 
// ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### 

// ======= ======= ======= ======= ======= ======= ======= 
//
// ======= ======= ======= ======= ======= ======= ======= 
function ModalDialog( whichDialog, whichAction )
{
	switch( whichAction )
	{
		case 'show':
			ModalDialog_Show( whichDialog, true, true )
		break;
		case 'show_promptly':
			ModalDialog_Show( whichDialog, true, true )
		case 'show_transparent':
			ModalDialog_Show( whichDialog, true, true )
		break;
		case 'hide':
			ModalDialog_Hide( whichDialog )
		break;
		case 'toggle':
			if( $( whichDialog ).visible() )
				ModalDialog_Hide( whichDialog )
			else
				ModalDialog_Show( whichDialog, true, true )
		break;
	}

	return( false );
}

// ======= ======= ======= ======= ======= ======= ======= 
//
// ======= ======= ======= ======= ======= ======= ======= 
function ModalDialog_Show( whichDialog, isPrompty, isTransparent )
{
	contentIDs = $$( 'div#' + whichDialog + ' div.modaldialog_content' );
	ModalDialog_Center( contentIDs[0] );
	/*
	if( isPrompty )
	{
		$( whichDialog ).setStyle( { display: 'block' } );
	}
	else
	{
		new Effect.Appear( whichDialog,{ duration: tmpDuration, to: tmpTo } );
	}
	*/
	if( isPrompty )		{ tmpDuration = 0	} else { tmpDuration = 1	}
	if( isTransparent )	{ tmpTo = 1	} else { tmpTo = 1			}
	
	new Effect.Appear( whichDialog,{ duration: tmpDuration, to: tmpTo } );
}

// ======= ======= ======= ======= ======= ======= ======= 
//
// ======= ======= ======= ======= ======= ======= ======= 
function ModalDialog_Hide( whichDialog )
{
	new Effect.Fade( whichDialog, { duration: 0 } );
}

// ======= ======= ======= ======= ======= ======= ======= 
//
// ======= ======= ======= ======= ======= ======= ======= 
function ModalDialog_Center(element)
{
	/*
    try
    {
        element = $(elementID);
    }
    catch(e)
    {
        return;
    }
	*/

    var my_width  = 0;
    var my_height = 0;

    if ( typeof( window.innerWidth ) == 'number' )
    {

        my_width  = window.innerWidth;
        my_height = window.innerHeight;
    }
    else if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
    {

        my_width  = document.documentElement.clientWidth;
        my_height = document.documentElement.clientHeight;
    }
    else if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
    {

        my_width  = document.body.clientWidth;
        my_height = document.body.clientHeight;
    }

	/*
    element.style.position = 'absolute';
    element.style.display  = 'block';
	*/

    var scrollY = 0;

    if ( document.documentElement && document.documentElement.scrollTop )
    {
        scrollY = document.documentElement.scrollTop;
    }
    else if ( document.body && document.body.scrollTop )
    {
        scrollY = document.body.scrollTop;
    }
    else if ( window.pageYOffset )
    {
        scrollY = window.pageYOffset;
    }
    else if ( window.scrollY )
    {
        scrollY = window.scrollY;
    }

	// var elementDimensions = Element.getDimensions(element);
	// fuer modale Dialoge kann angenommen werden:
	elementDimensions = { width: 800, height: 200 };

    var setX = ( my_width  - elementDimensions.width  ) / 2;
    var setY = ( my_height - elementDimensions.height ) / 2 + scrollY;

    setX = ( setX < 0 ) ? 0 : setX;
    setY = ( setY < 0 ) ? 0 : setY;

    element.style.left = setX + "px";
    element.style.top  = setY + "px";

}


// ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### 
// 
// ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### 

// ======= ======= ======= ======= ======= ======= ======= 
//
// ======= ======= ======= ======= ======= ======= ======= 
function ShowInfoboxAt( ID, X, Y, paramDuration )
{
	if( paramDuration == null ) paramDuration = 1

	var ua = navigator.userAgent.toLowerCase();	/* UserAgent ermitteln */
	var iebrowser = (ua.indexOf("msie") != -1);	/* Internet Explorer */
	if( iebrowser )
	{
		// offsetPosition_opener = Position.positionedOffset( $( ID + '_opener') );
		offsetPosition_main   = Position.positionedOffset( $( 'main') );
		// $( 'DEBUG' ).innerHTML = offsetPosition_main[0] + "|" + offsetPosition_main[1];	// <div id="DEBUG"></div>
		// offsetPosition = Position.realOffset( $( ID + '_opener') );
		// offsetPosition = $( ID + '_opener').cumulativeScrollOffset(  );
		X = X - offsetPosition_main[0];
		Y = Y - offsetPosition_main[1];
	}

	theInfobox = $$( 'div#' + ID + ' div.infobox_sub1' );
	$( theInfobox[0] ).setStyle( { top: Y+'px', left: X+'px' } );
	new Effect.Appear( ID, { duration: paramDuration } );
}

// ======= ======= ======= ======= ======= ======= ======= 
//
// ======= ======= ======= ======= ======= ======= ======= 
function InfoboxToggle( which )
{
	theID = $(which).id
	thePos = theID.indexOf( 'hinten' );
	if( thePos == -1 )
	{
		$( which ).setStyle( { display: 'none' } );
		$( theID + 'hinten' ).setStyle( { display: 'block' } );
	}
	else
	{
		altID = theID.substring( 0, thePos );
		$( which ).setStyle( { display: 'none' } );
		$( altID ).setStyle( { display: 'block' } );
	}
}

// ======= ======= ======= ======= ======= ======= ======= 
//
// ======= ======= ======= ======= ======= ======= ======= 
function ShowTab( theIdentifier, theTab )
{
	theTab--;
	allTabs = $$( theIdentifier );
	for( idx = 0; idx < allTabs.length; idx++ )
	{
		if( allTabs[idx].getStyle( 'display' ) == 'block' )
		{
			allTabs[idx].setStyle( { display: 'none' } );
		}
		else
		{
			if( idx == theTab ) allTabs[idx].setStyle( { display: 'block' } );
		}
	}
}


// ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### 
// 
// ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### 

// ======= ======= ======= ======= ======= ======= ======= 
//
// ======= ======= ======= ======= ======= ======= ======= 
function ClearTextarea( which )
{
	if( $(which).value == 'Bitte hier Ihren Text eingeben.' )
	{
		$(which).value = '';
		$(which).setStyle( {fontStyle:'normal'} );
	}
}


// ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### 
// 
// ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### 

// ======= ======= ======= ======= ======= ======= ======= 
//
// ======= ======= ======= ======= ======= ======= ======= 
var RatingRate = 0;

function Rating( theLevel )
{
	RatingRats = $$('div#RatingRatMaze a.ratingrat');
	for( var idx = 0; idx < theLevel; idx++ )
	{
		theBackgroundImageSrc = RatingRats[idx].getStyle( 'backgroundImage' );
		if( theBackgroundImageSrc.indexOf( 'full' ) >= 0 )
		{
			RatingRats[idx].setStyle( { backgroundImage: 'url(/images/de/basic/ic_ratingbox_fullstar_green.gif)' } );
		}
		else
		{
			RatingRats[idx].setStyle( { backgroundImage: 'url(/images/de/basic/ic_ratingbox_emptystar_green.gif)' } );
		};
	}
	for( var idx = theLevel; idx < 10; idx++ )
	{
		theBackgroundImageSrc = RatingRats[idx].getStyle( 'backgroundImage' );
		if( theBackgroundImageSrc.indexOf( 'full' ) >= 0 )
		{
			RatingRats[idx].setStyle( { backgroundImage: 'url(/images/de/basic/ic_ratingbox_full_green.gif)' } );
		}
		else
		{
			RatingRats[idx].setStyle( { backgroundImage: 'url(/images/de/basic/ic_ratingbox_empty_green.gif)' } );
		};
	}

	RatingRate = theLevel;
	$('RatingRatMazeStatus').innerHTML = ( RatingRate > 0 ) ? RatingRate : '';
	// background-image: url(../images/de/basic/ic_ratingbox_empty_green.gif);

}

// ======= ======= ======= ======= ======= ======= ======= 
//
// ======= ======= ======= ======= ======= ======= ======= 
function Rate( aRatingValue, aRatingForm )
{
	//
	if( !aRatingForm || aRatingForm == '' ) aRatingForm = 'gallery_place_detail_ratingform';
	//
	var form = document.getElementById( aRatingForm );
	form.RatingValue.value = aRatingValue;
	if( form.onsubmit() )
	{
		form.submit();
	}
}


// ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### 
// 
// ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### 

// ======= ======= ======= ======= ======= ======= ======= 
//
// ======= ======= ======= ======= ======= ======= ======= 
function SubmitForm( which )
{
	var form = document.getElementById( which );
	if( form.onsubmit() )
		{
		form.submit();
		}

	return( false );
}


// ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### 
// PicNav
// ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### 

	//
	var PicNav_Position;
	var PicNav_SideShown;

	//
	//
	//
	function PicNav_Init()
	{
		PicNav_Position = getPosition( $('gallery_detail_pic') );
		PicNav_SideShown = 0;

		Event.observe( 'ground_cont', 'mousemove', PicNav_Observer );
	}
	function PicNav_DeInit()
	{
		Event.stopObserving( 'ground_cont', 'mousemove', PicNav_Observer );
	}

	//
	//
	//
	function PicNav_Observer( e )
	{
		PicNav_X = Event.pointerX( e ) - PicNav_Position.x;
		PicNav_Y = Event.pointerY( e ) - PicNav_Position.y;

		//// $('debugoutput').innerHTML = PicNav_X + ' / ' + PicNav_Y + ' | ' + PicNav_SideShown;

		if( (PicNav_X>=0)&&(PicNav_X<=456) && (PicNav_Y>0)&&(PicNav_Y<=456) )
		{
			switch( PicNav_SideShown )
			{
				case -1:	// linke Seite wird angezeigt
					if( PicNav_X > 342 )
					{
						PicNav_HideLeft();
						PicNav_ShowRight();
					}
				break;
				case 0:		// keine Seite wird angeziegt
					if( PicNav_X > 342 )
					{
						PicNav_ShowRight();
					}
					if( PicNav_X < 114 )
					{
						PicNav_ShowLeft();
					}
				break;
				case 1:		// rechte Seite wird angeziegt
					if( PicNav_X < 114 )
					{
						PicNav_HideRight();
						PicNav_ShowLeft();
					}
				break;
			}
		}
		else
		{
			switch( PicNav_SideShown )
			{
				case -1:	// linke Seite wird angezeigt
					PicNav_HideLeft();
				break;
				case 0:		// keine Seite wird angeziegt
				break;
				case 1:		// rechte Seite wird angeziegt
					PicNav_HideRight();
				break;
			}
		}

	}
	
	//
	//
	//
	function PicNav_ShowLeft()
	{
		new Effect.Appear( 'overpict_left', { to: 0.9, duration: 0 } );
		PicNav_SideShown = -1;
	}
	function PicNav_HideLeft()
	{
		new Effect.Fade( 'overpict_left', { duration: 0 } );
		PicNav_SideShown = 0;
	}

	function PicNav_ShowRight()
	{
		new Effect.Appear( 'overpict_right', { to: 0.9, duration: 0 } );
		PicNav_SideShown = +1;
	}
	function PicNav_HideRight()
	{
		new Effect.Fade( 'overpict_right', { duration: 0 } );
		PicNav_SideShown = 0;
	}

	//
	//
	//
function getPosition(element)
/* der Aufruf dieser Funktion ermittelt die absoluten Koordinaten
   des Objekts element */
{
  var elem=element,tagname="",x=0,y=0;
  
/* solange elem ein Objekt ist und die Eigenschaft offsetTop enthaelt
   wird diese Schleife fuer das Element und all seine Offset-Eltern ausgefuehrt */
  while ((typeof(elem)=="object")&&(typeof(elem.tagName)!="undefined"))
  {
    y+=elem.offsetTop;     /* Offset des jeweiligen Elements addieren */
    x+=elem.offsetLeft;    /* Offset des jeweiligen Elements addieren */
    tagname=elem.tagName.toUpperCase(); /* tag-Name ermitteln, Grossbuchstaben */

/* wenn beim Body-tag angekommen elem fuer Abbruch auf 0 setzen */
    if (tagname=="BODY")
      elem=0;

/* wenn elem ein Objekt ist und offsetParent enthaelt
   Offset-Elternelement ermitteln */
    if (typeof(elem)=="object")
      if (typeof(elem.offsetParent)=="object")
        elem=elem.offsetParent;
  }

/* Objekt mit x und y zurueckgeben */
  position=new Object();
  position.x=x;
  position.y=y;
  return position;
}

	//
	//
	//
	function PicNav_UpdatePlacePicFrames( theActiveFrameID )
	{
		// disable all (only one)
		theActiveFrames = $$('div.galerie_list_verysmall table.active');
		for( idx = 0; idx < theActiveFrames.length; idx++ )
		{
			theActiveFrames[idx].className = 'galerie_list_verysmall';
		}
		// enable the one and only
		theActiveFrame = $( 'galerie_place_pic_' + theActiveFrameID )
		theActiveFrame.className = 'galerie_list_verysmall active'
	}


// ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### 
// 
// ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### 

function globalClick(e)
{
	if (!e) e = window.event;
	if( (e.type && e.type == "contextmenu") || (e.button && e.button == 2) || (e.which && e.which == 3) )
	{
		// if (window.opera) window.alert("Sorry: Diese Funktion ist deaktiviert.");
		return false;
	}
}

//if (document.layers) document.captureEvents( Event.MOUSEDOWN );
//document.onmousedown = globalClick;
//document.oncontextmenu = globalClick;

/*
	Event.observe( window, 'onmousedown', globalClick );
	Event.observe( window, 'oncontextmenu', globalClick );
*/


// ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### 
// 
// ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### 

function Check_Mail4Provider( aField )
{
	if(
		(aField.value.indexOf( '@aol.' ) != -1)
		||
		(aField.value.indexOf( '@hotmail.' ) != -1)
		||
		(aField.value.indexOf( '@yahoo.' ) != -1)
	)
	{
		pos = getPosition( aField );
		// dim = aField.getDimensions();
		ShowInfoboxAt( 'infobox_registry_check_mail4provider', pos.x + 195, pos.y + 5, 0 );
	}
	else
	{
		Effect.Fade( 'infobox_registry_check_mail4provider', { duration: 0 } )
	}
}

