/*
* Common JS scripts
*/

function gEBI( objId ){
  return document.getElementById( objId );
}

function createCookie( sName, sValue, iDays ){
  sValue = escape( sValue );
  if( iDays ){
    var oDate = new Date();
    oDate.setTime( oDate.getTime() + ( iDays*24*60*60*1000 ) );
    var sExpires = "; expires="+oDate.toGMTString();
  }
  else
    var sExpires = "";
  document.cookie = sName+"="+sValue+sExpires+"; path=/";
}

function throwCookie( sName ){
  var sNameEQ = sName + "=";
  var aCookies = document.cookie.split( ';' );
  for( var i=0; i < aCookies.length; i++ ){
    var c = aCookies[i];
    while( c.charAt(0) == ' ' )
      c = c.substring( 1, c.length );
    if( c.indexOf( sNameEQ ) == 0 )
      return c.substring( sNameEQ.length, c.length );
  }
  return null;
}

function delCookie( sName ){
  createCookie( sName, "", -1 );
}

function isset( sVar ){
  return( typeof( window[sVar] ) != 'undefined' );
}

_bUa=navigator.userAgent.toLowerCase();
_bOp=(_bUa.indexOf("opera")!=-1?true:false);
_bIe=(_bUa.indexOf("msie")!=-1&&!_bOp?true:false);
_bIe4=(_bIe&&(_bUa.indexOf("msie 2.")!=-1||_bUa.indexOf("msie 3.")!=-1||_bUa.indexOf("msie 4.")!=-1)&&!_bOp?true:false)
isIe=function(){return _bIe;}
isOldIe=function(){return _bIe4;}
var olArray=[];

function AddOnload( f ){
  if( isIe() && isOldIe() ){
    window.onload = ReadOnload;
    olArray[olArray.length] = f;
  }
  else if( window.onload ){
    if( window.onload != ReadOnload ){
      olArray[0] = window.onload;
      window.onload = ReadOnload;
    }
    olArray[olArray.length] = f;
  }
  else
    window.onload=f;
}
function ReadOnload(){
  for( var i=0; i < olArray.length; i++ ){
    olArray[i]();
  }
}

function txtSize( iSize ){
  var aSizes = Array( '0.917em', '', '1.333em' );
  var aChange = Array( 'pageDescription', 'h5' );
  var aSizesDefault = Array( '1.083em', '1em' );
  for( var i = 0; i < aChange.length; i++ ){
    if( !aSizes[iSize] )
      iSize = 1;
    if( gEBI( aChange[i] ) ){
      gEBI( aChange[i] ).style.fontSize = ( iSize != 1 ) ? aSizes[iSize] : aSizesDefault[i];
    }
    else if( gEBI( 'content' ).getElementsByTagName( aChange[i] ) ){
      aH5 = gEBI( 'content' ).getElementsByTagName( aChange[i] );
      for( var j = 0; j < aH5.length; j++ ){
        aH5[j].style.fontSize =  ( iSize != 1 ) ? aSizes[iSize] : aSizesDefault[i];
      }
    }
  }
}

var newsIndexActive=0;
var newsIndexCount=0;
var newsMonthActive=null;
var newsRotator=null;

function newsIndexRotatorCreate()
{
	if (newsRotator)
		return;
	newsIndexCount=0;
	for ( i=0 ; ; ++i )
		if (document.getElementById('news_' + i))
			++newsIndexCount;
		else
			break;
	newsRotator=setInterval("newsIndexRotator();", 5000);
}

function newsIndexRotatorDestroy()
{
	clearTimeout(newsRotator);
	newsRotator=null;
}

function newsIndexRotator()
{
	newsIndexToggle((newsIndexActive+1)%newsIndexCount);
}

function newsIndexToggle(number)
{
	document.getElementById('news_' + newsIndexActive).className="";
	document.getElementById('newscontent_' + newsIndexActive).style.display="none";
	document.getElementById('news_' + number).className="active";
	document.getElementById('newscontent_' + number).style.display="block";
	newsIndexActive=number;
}

var map = null;
var map2=null;
    var geocoder = null;

    function mapInitialize(address) {
	    geocoder = new google.maps.Geocoder();
	    var myOptions = {
	      zoom: 15,
	      mapTypeId: google.maps.MapTypeId.ROADMAP
	    }
	    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    }

    function showAddress(address) {
      address=address.replace('<p>', '');
      address=address.replace('</p>', '');
      geocoder.geocode( { 'address': address}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        map.setCenter(results[0].geometry.location);
        var marker = new google.maps.Marker({
            map: map,
            position: results[0].geometry.location
        });
      } else {
        alert("Geocode was not successful for the following reason: " + status);
      }
    });

    }
    
    
    function mapInitialize2(address) {
	    var myOptions = {
	      zoom: 15,
	      mapTypeId: google.maps.MapTypeId.ROADMAP
	    }
	    map2 = new google.maps.Map(document.getElementById("map_canvas2"), myOptions);
    }

    function showAddress2(address) {
      address=address.replace('<p>', '');
      address=address.replace('</p>', '');
      geocoder.geocode( { 'address': address}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        map2.setCenter(results[0].geometry.location);
        var marker = new google.maps.Marker({
            map: map2,
            position: results[0].geometry.location
        });
      } else {
        alert("Geocode was not successful for the following reason: " + status);
      }
    });

    }
