
var eBody = null ;
var sDefaultFontSize = "1.0em" ;
var sDefaultStyleSheet = "standard" ;

var _dExpireDate = new Date() ;
var _iExpireDate = _dExpireDate.getTime() + ( 3 * 24 * 60 * 60 * 1000 ) ;
_dExpireDate.setTime(_iExpireDate) ;


function doSendMail( sString ) {
	
	if ( sString.indexOf('¿') != -1 ) {
		aChars = sString.split('¿') ;
		var sReturn = String() ;
		for( i = 0 ; i < aChars.length ; i++ ) {
			sReturn += String.fromCharCode(( aChars[i] - 5 )) ;
		}
		if ( sReturn.indexOf('@') != -1 ) {
			location.href = 'mailto:' + sReturn ;
		}
	}
}

function getCookieContent( sName ) {

  if ( navigator.cookieEnabled ) {
  	var _aItems = document.cookie.split(";") ;

		  	
  	sName += "=" ;
  	
  	for ( i = 0 ; i < _aItems.length ; i++ ) {
  		_aItems[i] = _aItems[i].replace( " ", "" ) ;
  	  if ( _aItems[i].substring( 0, sName.length ) == sName ) {
 			  return _aItems[i].replace( sName, "" ) ;
  		}
		}
  }
	
	return false ;
}

function getFontSize() {

	if ( getCookieContent("FontSize") ) {
		return getCookieContent("FontSize") ;
	}
  	
  return false ;
}

function getFirstStyleSheet() {
	
	for ( i = 0 ; ( _oLink = document.getElementsByTagName("link")[i] ) ; i++ ) {
		if (
		     _oLink.getAttribute("rel").indexOf("stylesheet") != -1
		    &&
		     _oLink.getAttribute("type").indexOf("text/css") != -1
		    &&
		     _oLink.getAttribute("title")
		    &&
		     _oLink.getAttribute("alt") == -1
		   ) {
		   	return _oLink.getAttribute("title") ;
		}
	}
	return sDefaultStyleSheet ;
}

function initContentHeight() {

  if ( document.getElementById('box_content_only') != null && document.getElementById('box_content_stuff') != null ) {
    if ( document.getElementById('box_content_only').offsetHeight > 200 ) {   	
    	document.getElementById('box_content_stuff').style.display = 'block' ;
    	document.getElementById('box_content_only').innerHTML += "<p>&nbsp;</p><h3>&nbsp;Hinweis</h3><p>&Uuml;ber die Postleitzahlensuche auf der rechten Seite erhalten Sie alle relevanten Informationen zu den Einrichtungen und Angeboten des DRK in Ihrer unmittelbaren Umgebung.</p>" ;
    }
    else {
    	document.getElementById('box_content_only').innerHTML += "<div id=\"box_stuff\">" + document.getElementById('box_content_stuff').innerHTML + "</div>" ;
    	document.getElementById('box_stuff').style.display = 'block' ;
    }
  }
}


function initFontSize() {

  if ( document.getElementsByTagName('body') != null ) {
    eBody = document.getElementsByTagName('body')[0] ;
    if ( eBody == null ) {
      eBody = document.body ;
    }
  	if ( getFontSize() ) {
	  	setFontSize(getFontSize()) ;
	  }
	  else {
		  setFontSize(sDefaultFontSize) ;
	  }
  }
}

function initStyleSheet() {
	var sStyle = getCookieContent("StyleSheet") ;
	sStyle = sStyle ? sStyle : getFirstStyleSheet() ;
	
	setStyleSheet(sStyle) ;

	for ( i = 0 ; i < document.FormStyle.Styles.options.length ; i++ ) {
		if ( document.FormStyle.Styles.options[i].value == sDefaultStyleSheet ) {
			document.FormStyle.Styles.options[i].selected = true ;
		}
	}	
}

function loadMaps() {
	aKV = new Array() ;
	aKV.push( 'bad_doberan' ) ;
  aKV.push( 'demmin' ) ;
  aKV.push( 'rostock' ) ;
  aKV.push( 'stralsund' ) ;
  aKV.push( 'wismar' ) ;
  aKV.push( 'nordvorpommern' ) ;
  aKV.push( 'nordwestmecklenburg' ) ;
  aKV.push( 'guestrow' ) ;
  aKV.push( 'ludwigslust' ) ;
  aKV.push( 'neubrandenburg' ) ;
  aKV.push( 'mecklenburger_seenplatte' ) ;
  aKV.push( 'ostvorpommern' ) ;
  aKV.push( 'parchim' ) ;
  aKV.push( 'schwerin' ) ;
  aKV.push( 'ruegen' ) ;
  aKV.push( 'uecker_randow' ) ;
  
  oImage = new Image() ;
  
  for ( i = 0 ; i < aKV.length ; i++ ) {
  	oImage.src = '/themes/drk/custom/body/mv_' + aKV[i] + '.png' ;
  }
}

function openWindow( sURL, iWidth, iHeight ) {
	var oWindow = window.open( sURL, "DRKMVLV", 'width=' + iWidth + ',height=' + iHeight + ',resizable=1,scrollbars=no,menubar=no,status=no' ) ;
}

function setCookie( sName, sContent ) {

  if ( navigator.cookieEnabled ) {
		document.cookie = sName + "=" + sContent + "; expires=" + _dExpireDate.toGMTString() ;
	}

}


function setAllDivHidden() {
	if ( document.getElementsByTagName('div') != null ) {
		for ( i = 0 ; ( _oDiv = document.getElementsByTagName('div')[i] ) ; i++ ) {
			if ( _oDiv.getAttribute('id') != null ) {
				if ( _oDiv.getAttribute('id').indexOf('drkmv_kv_') != -1 ) {
					_oDiv.style.display = 'none' ;
				}
			}
		}
	}
	document.getElementById('drk_mv_map').src = '/themes/drk/custom/body/map_mv.png' ;
}


function setFontSize( sFontSize ) {

	if ( eBody == null ) {
		initFontSize() ;
		if ( eBody == null ) {
			return false ;
		}
	}

  setCookie( "FontSize", sFontSize ) ;

	eBody.style.fontSize = sFontSize ;
	eBody.focus() ;
	
	sDefaultFontSize = sFontSize ;
}


function setStyleSheet( sStyle ) {
	if ( sStyle != null ) {
	  for( i = 0 ; ( _oLink = document.getElementsByTagName("link")[i] ) ; i++ ) {
	  	if (
		     _oLink.getAttribute("rel").indexOf("stylesheet") != -1
		    &&
		     _oLink.getAttribute("type").indexOf("text/css") != -1
		    &&
		     _oLink.getAttribute("title")
		   ) {
    	  _oLink.disabled = true ;
      	if( _oLink.getAttribute("title") == sStyle ) {
      		_oLink.disabled = false ;
      		sDefaultStyleSheet = sStyle ;
      		setCookie( "StyleSheet", sStyle ) ;
      	}
      }
    }
  }
  
  return true ;
}


function showDiv( oDiv ) {
	if ( document.getElementById( oDiv ) != null ) {
		document.getElementById( oDiv ).style.left = ( xpos + 20 ) + 'px' ;
		document.getElementById( oDiv ).style.top = ( ypos + 20 ) + 'px' ;
		document.getElementById( oDiv ).style.display = 'block' ;
		
		document.getElementById('drk_mv_map').src = '/themes/drk/custom/body/mv_' + oDiv.replace( /drkmv_kv_/i, '' ) + '.png' ;
	}
}

var xpos = 0 ;
var ypos = 0 ;

if (document.captureEvents) {
    document.captureEvents(Event.MOUSEMOVE);
}

document.onmousemove = mauspos;

function mauspos(e) {
	xpos = e ? e.pageX - document.getElementById('box_main').offsetLeft : window.event.x ;
	ypos = e ? e.pageY : window.event.y ;
}

function alertMousePos () {
	
  _iInt = _iInt + 1 ;
//  alert( 'Versuch: ' + _iInt + "/10\n\nLeft: " + xpos + "\n" + 'Top: ' + ypos ) ;
  if ( _iInt >= 10 )
    window.clearInterval(_oInt);
}

var _oInt ;
var _iInt = 0 ;

window.onload = function(e) {
  initFontSize() ;
//  initStyleSheet() ;
  initContentHeight() ;
  
  _oInt = window.setInterval( "alertMousePos()", 10000 ) ;
}
