// ------------------------------------------------------------------;
// Allgemeine Funktionen;
// ------------------------------------------------------------------;
function isMicrosoftExplorer( ) {
  var bMicrosoftExplorer = false;
  var nav = navigator.appName.toLowerCase();
  if ( nav.indexOf('microsoft') >= 0 ) {bMicrosoftExplorer = true}
  return bMicrosoftExplorer;
}

function getAttributeSave( e, attr ) {
    // manchmal so und manchmal so - je nach attribute
    if ( e.getAttribute ) {
        return e.getAttribute( attr, false ) ;
    } else {
        return e.style.getAttribute( attr, false ) ;
    }
}

function setAttributeSave( e, attr, val ) {
    // manchmal so und manchmal so - je nach browser
    if ( e.setAttribute ) {
        e.setAttribute( attr, val ) ;
    } else {
        e.style.setAttribute( attr, val, false ) ;
    }
}



// --------------------------------------------------------------------------------------------
// Email versenden mit Funktion, damit die Email-Adresse automatisiert ausgelesen werden kann.
// --------------------------------------------------------------------------------------------
function mailTo( name, domain, subject ) {
  // damit eine email-Adresse nicht so leicht ausgelesen werden kann
  // Parameter:
  // name = Name vor dem @ 
  // dmain = Name nach dem @ ( optional; default =  i n f o s e n s e . d e )
  // subject = Betreff 

    var lf = escape( "\n" ) ;
    var winTitle = ""
    
    var domain1 = null;
    if ( domain == '' )  domain1 = 'infosense' + '.de' ;
    if ( domain  !== '' )  domain1 = domain ;
    
    var winUrl = "mailto:" + name + '@' + domain1 ;
    winUrl += "?subject=" + escape( subject ) ;

    var w = screen.availWidth ;
    var h = screen.availHeight ;
    var l = Math.round( w * 0.15 ) ;
    var t = 50 ;
    w = w - ( 2 * l );
    h = h - ( 2 * t );

    var eigenschaft  = 'width=' + w ;
    eigenschaft += ', height=' + h ;
    eigenschaft += ', left=' + l ;
    eigenschaft += ', top=' + t ;
    eigenschaft += ', dependent=no' ;
    eigenschaft += ', resizable=yes' ;

    var winSendEmail = window.open( winUrl, winTitle, eigenschaft, false );
    return true;
}

// --------------------------------------------------------------------------------------------
// in Abhängigkeit von Bildschirmgrösse die Breite des rechten Sidebar setzen
// --------------------------------------------------------------------------------------------
function setSidebarWidth() { return true;
  var o = null;
  var w = screen.width;
  if ( w == null ) w = 1024 ;
  // die DefaultBreite des Sidebars ist 250px auf 1024 ausgelegt. 
  // Dann nix machen. Siehe Style.css 
  if ( w > 1000 && w < 1100 ) return true;
  
  // wenn geringe Auflösung, dann bodyPadding kleiner.
  if ( w < 1000 ) {
      o = document.getElementById('body');
      if ( o !== null ) o.style.paddingLeft = '10px';
      if ( o !== null ) o.style.paddingRight = '10px';
      o = document.getElementById('topmenuLogo');
      if ( o !== null ) o.style.right = '20px';
  }
  
  
  w = w / 1024 * 250 ;
  w = Math.round( w ) ;
  if ( w < 200 ) w = 200;
  if ( w > 350 ) w = 350;
  // alle SidebarColumns auf die Breite setzen
  o = document.getElementById('borderTopMiddle2');
  if ( o !== null ) o.style.width = w + 'px';

  o = document.getElementById('mainRight');
  if ( o !== null ) {
    o.style.width = w + 'px'
  }
 
  o = document.getElementById('borderBottomMiddle2');
  if ( o !== null ) o.style.width = w + 'px';

}





// --------------------------------------------------------------------------------------------
// iscrm Screenshots 
// Funktion für das Anzeigen eines grossen Bildes
// --------------------------------------------------------------------------------------------
function bigpicShow( oPicSmall, title ) {

	oTransparent = document.getElementById( 'transparent' );
	if ( oTransparent != null ) {
    	oTransparent.style.left = '0px' ;
    	oTransparent.style.top = '0px' ;
    	oTransparent.style.width = '100%' ;
    	oTransparent.style.height = screen.height + 'px' ;
    	oTransparent.style.display = 'block';
	}


	o = document.getElementById( 'bigpic' );
	o.src = oPicSmall.src ;
	
	t = document.getElementById( 'bigpictitle' );
	if ( t !== null ) t.innerHTML = title ;
	
    if ( isMicrosoftExplorer() == true ) {
        scrollPos = document.documentElement.scrollTop ;
    } else {
        scrollPos = window.pageYOffset;
    }
	o = document.getElementById( 'bigpicframe' );
	o.style.top = (scrollPos + 40) + 'px' ;
	// o.style.display = 'block' ;
    window.setTimeout( "bigpicShowNext()", 100); // mit Verzögerung sichtbar
    Effect.Fade( o,{duration:0.5, from:0.2, to:1.0 }) ;

}
function bigpicShowNext() {
	document.getElementById( 'bigpicframe' ).style.display = 'block' ;
}


function bigpicHide( ) {
    // Transparenz ausschalten
    window.setTimeout( "bigpicHideNext()", 1700); // mit Verzögerung unsichtbar
    Effect.Fold( 'bigpicframe' ) ;
}
function bigpicHideNext( ) {
	oTransparent = document.getElementById( 'transparent' );
	if ( oTransparent != null ) {
    	oTransparent.style.display = 'none';
	}
	o = document.getElementById( 'bigpicframe' ).style.display = 'none';
}








 
// --------------------------------------------------------------------------------------------
// Ein paar Effekte beim Titelbild
// mögliche Bilder ( titleNN.jpg ) zur anzeige ; in /public/images/content 
// --------------------------------------------------------------------------------------------
var oEffectPics = new Array(1, 9, 11, 12, 13, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 );
var oEffectImage = null; 
var oEffectBlock = null; 
var nEffectOldPicIndex = -1; 
function effectChangePicture( oImage ) {
  if ( oEffectImage !== null ) return true; 
  oEffectImage = oImage ; 
  
  window.setTimeout( "effectChangePicture1()", 30000) ;
}

function effectChangePicture1( ) {
  //alert(oEffectImage);
  if ( oEffectImage == null ) return true; 
  new Effect.Fade( oEffectImage,{duration:1.0, from:1.0, to:0.1 }) ;
  window.setTimeout( "effectChangePicture2()", 1000);
}

function effectChangePicture2( ) {
  if ( oEffectImage == null ) return true; 

  // nächstes bild bestimmen
  var nextIndex = nEffectOldPicIndex;
  var nextFile = null;
  while ( nEffectOldPicIndex == nextIndex ) {
      nextIndex = Math.random() * ( oEffectPics.length - 1 );
      nextIndex = Math.round( nextIndex );
  }
  nEffectOldPicIndex = nextIndex ;
  nextFile  = '/images/content/header' + oEffectPics[nextIndex] + '.jpg' ;
  // alert(nextIndex + '#####' + nextFile);
  // neues Bild setzen und wieder einblenden 
  oEffectImage.src = nextFile ;
  Effect.Fade( oEffectImage,{duration:1.0, from:0.1, to:1.0 }) ;

  window.setTimeout( "oEffectImage = null", 30000) ; // damit sich nichts übelagert
}


function effectPulsate( oBlock ) {
  if ( oEffectBlock == oBlock ) return true ; 
  oEffectBlock  = oBlock ; 
  Effect.Pulsate( oEffectBlock , {duration:0.5, from:0.7, pulses:1 } );
}



// --------------------------------------------------------------------------------------------
// DesignLinkListe
// Funktion für des Setzen eines Design-Picture
// --------------------------------------------------------------------------------------------
var designArrayPicnr = null;
var designArrayLink = null;
var designAktIndex = null;
var designOldIndex = null ;
var designMainPicObject = null;

function designListStart(){
    designArrayPicnr = new Array();
    designArrayLink = new Array();
    designAktPicnr = null;
}

function designListAdd( nrPic, strLinkNoHttp ){
    // Liste aufbauen
    if ( nrPic == '' ) return false ;
    if ( strLinkNoHttp == '' ) return false ;
    
    var l = designArrayPicnr.length;
    designArrayPicnr[l] = nrPic;
    designArrayLink[l] = strLinkNoHttp ;
}

function designShowFirst() {
    var o = null;
    var index = null;
    
    designMainPicObject = document.getElementById('designMain');
    if ( designMainPicObject == null ) {
        alert( 'Can not find MainPic!');
        return false;
    }

    designAktIndex = 0;
    designFillSmallPics( designAktIndex  );

    o = document.getElementById('designSmall1');
    if ( o !== null ) o.click( o ) ;
}


function designNextPage() {
    var o = null;
    
    o = document.getElementById('designSmall1');
    if ( o == null ) return false;
    
    maxIndex = designArrayPicnr.length - 5;
    newStartIndex = designGetIndexFromClickedImage( o ) + 5 ;
    if ( newStartIndex > maxIndex ) newStartIndex = maxIndex ;

    designFillSmallPics( newStartIndex );


}


function designPrevPage() {
    var o = null;
    var index = null;
    
    o = document.getElementById('designSmall1');
    if ( o == null ) return false;
    
    minIndex = 0;
    newStartIndex = designGetIndexFromClickedImage( o ) - 5 ;
    if ( newStartIndex < minIndex ) newStartIndex = minIndex ;

    designFillSmallPics( newStartIndex );

}


function designFillSmallPics( startIndex ) {
    var o = null;
    
    minIndex = 0;
    maxIndex = designArrayPicnr.length - 5;
    lastIndex = designArrayPicnr.length - 1;

    for ( i = 1; i < 6; i++ ) {
        picIndex = startIndex + i - 1 ;
        o = document.getElementById('designSmall' + i );
        if ( o !== null ) o.src = designGetPicFilename(picIndex);
    }

    // geh nicht bei chrome : o = document.getElementById('designSmall1').click();
    o = document.getElementById('designSmall1');
    designShowPic( o );

    o = document.getElementById('prevPage');
    if ( isMicrosoftExplorer( ) ) { 
        if ( startIndex <= minIndex ) o.style.visibility = "hidden" ;
        if ( startIndex >  minIndex ) o.style.visibility = "visible" ;
    } else {
        if ( startIndex <= minIndex ) o.style.visibility = "collapse" ;
        if ( startIndex >  minIndex ) o.style.visibility = "visible" ;
    }


    o = document.getElementById('nextPage');
    if ( isMicrosoftExplorer( ) ) { 
        if ( startIndex >= maxIndex ) o.style.visibility = "hidden" ;
        if ( startIndex <  maxIndex ) o.style.visibility = "visible" ;
    } else {
        if ( startIndex >= maxIndex ) o.style.visibility = "collapse" ;
        if ( startIndex <  maxIndex ) o.style.visibility = "visible" ;
    }


}


function designShowPic( imgObject ) {
    // Bild und Link anzeigen ;
    var src = null;
    var o = null ;
    designAktIndex = designGetIndexFromClickedImage(imgObject);
    if ( designOldIndex == designAktIndex ) return false  ;

    // alert( 'aktueller index= ' + designAktIndex);
    // alle Small auf StandardGrösse
    var i = 1;
    for ( i = 1; i < 6; i++ ) {
        o = document.getElementById('designSmall' + i );
        if ( o !== null ) { 
            o.style.height = "55px" ;
            o.style.backgroundColor = "#ffffff";
        }
    }

    //var newPic = null ;
    //var picIndex = null ;
    //var idClickedImage = designGetClickedImageId(imgObject);
    //// wenn der User NICHT auf das mittlere kleine Bild mit der id = 3 geklickt hat, dann verschieben
    //if ( idClickedImage !== 3 ) {
    //    newStartIndex = designAktIndex - 2 ;
    //    maxIndex = designArrayPicnr.length - 5;
    //    if ( newStartIndex < 0  ) newStartIndex = 0; 
    //    if ( newStartIndex > maxIndex ) newStartIndex = maxIndex; 

    //    if ( (newStartIndex >= 0) && (newStartIndex <= maxIndex ) ) {
    //        // alert( 'neuer start index = ' + newStartIndex);
    //        // es sind genügend bilder in der Liste um so zu verschieben, dass das angeklickte auf Pos 3 erscheint
    //        for ( i = 1; i < 6; i++ ) {
    //            picIndex = newStartIndex + i - 1 ;
    //            o = document.getElementById('designSmall' + i );
    //            if ( o !== null ) { 
    //                o.src = designGetPicFilename(picIndex);
    //                if ( picIndex == designAktIndex ) imgObject = o ;
    //             }
    //        }
    //    }
    //}



    imgObject.style.height = "65px";
    imgObject.style.backgroundColor = "#d0d0d0";
    src = imgObject.src;
    o = document.getElementById('linkWebsite');
    
    if ( designMainPicObject !== null ) designMainPicObject.src = src;
    if ( o !== null ) {o.innerHTML = designGetLink(designAktIndex) }
    designOldIndex = designAktIndex ;
}

function designGetClickedImageId( oSmallImage ) {
    id = oSmallImage.id;
    id = id.substr( (id.length - 1), 1 );
    return id;
}

function designGetPicFilename( index ) {
    picName = '0000000' + designArrayPicnr[index];
    picName = picName.substr( (picName.length - 4), 4 );
    return '/images/designs/' + 'd' + picName + '.png';
}

function designGetLink( index ) {
    s = '<a href="http://' + designArrayLink[index] + '" target="_blank" >' ;
    s += 'Webseite besuchen | Visit web site: &#132;' + designArrayLink[index] +  '&#148; ' ;
    s += '</a>' ;
    return s;
}


function designGetIndexFromClickedImage( imgObject ) {
    // Index des angeklickten Index ausgeben ;
    var src = imgObject.src ;
    if ( src == null ) return 0;
    if ( src == '' ) return 0;
    nrPic = src.substr( (src.length - 8), 4 );
    
    // array durchsuchen
    var i = 1;
    for ( i = 0; i < designArrayPicnr.length; i++ ) {
        if (designArrayPicnr[i] == nrPic) return i ;
    }
    return 0;
}

// --------------------------------------------------------------------------------------------
// Buttons am linken Rand und zugehöroge Infobox anzeigen
// Die BoxNr ist ist eine laufende Nr; beginnend mit 10, 20, ...
// --------------------------------------------------------------------------------------------
function infoboxShow( boxNr ) {
   var button = document.getElementById( 'buttoninfo' + boxNr ); 
   var box = document.getElementById( 'info' + boxNr ); 
   
   // button.style.display = 'none';
   button.style.left = '0px';
   new Effect.Move( button, { duration: 1.0, transition: Effect.Transitions.linear, x:-40  });

   box.style.left = '0px';
   box.style.display = 'block';
   var nLeft = 80 + boxNr * 2; 
   new Effect.Move( box, { duration: 1.0, transition: Effect.Transitions.linear, x:nLeft  });
       
}


function infoboxClose( boxNr ) {
   var button = document.getElementById( 'buttoninfo' + boxNr ); 
   var box = document.getElementById( 'info' + boxNr ); 
   
   box.style.display = 'none';
   box.style.left = '0px';
   button.style.display = 'block';
   button.style.left = '0px';
}


// --------------------------------------------------------------------------------------------
// Module in Laufleiste anzeigen
// --------------------------------------------------------------------------------------------
var moduleAktPosLeftPx = null;
var moduleToLeft = true;
var moduleTable = null;
var moduleLeftStart = null;
var moduleLeftEnd = null;
var moduleRightStart = null;
var moduleRightEnd = null;
var moduleStepPx = 2;
var moduleblockwidth = 138;
var moduleCountCells = null;
function moduleActivate(){ 
   moduleTable = document.getElementById('module'); 
   // die Cells vorne und hinten erweitern
   r = moduleTable.rows[0];
   moduleCountCells = r.cells.length; 
   c1 = r.cells[0].innerHTML;
   c2 = r.cells[1].innerHTML;
   c3 = r.cells[2].innerHTML;
   c4 = r.cells[3].innerHTML;
   cy = r.cells[moduleCountCells -2].innerHTML;
   cz = r.cells[moduleCountCells -1].innerHTML;

   n = r.insertCell(r.cells.length); n.innerHTML = c1; 
   n = r.insertCell(r.cells.length); n.innerHTML = c2; 
   n = r.insertCell(r.cells.length); n.innerHTML = c3; 
   n = r.insertCell(r.cells.length); n.innerHTML = c4; 

   n = r.insertCell(0); n.innerHTML = cz; 
   n = r.insertCell(0); n.innerHTML = cy; 


   moduleLeftStart = (moduleblockwidth * 1.5).floor() * -1;  // Grenzen bei LinksLauf
   moduleLeftEnd = moduleLeftStart - (moduleCountCells * moduleblockwidth) ;

   moduleRightStart = (moduleblockwidth * (moduleCountCells + 1.5)).floor() * -1;  // Grenzen bei Rechtslauf
   moduleRightEnd = (moduleblockwidth * 1.5).floor() * -1 ;

   moduleAktPosLeftPx = moduleLeftStart ; // hier fängst an
   moduleTable.style.left = moduleAktPosLeftPx + 'px';

   setTimeout(moduleMove, 2000 );
}

function moduleMove() {
   if (  moduleToLeft == true ) { moduleAktPosLeftPx -= moduleStepPx } 
                           else { moduleAktPosLeftPx += moduleStepPx }
   if (  moduleToLeft == true  && moduleAktPosLeftPx <= moduleLeftEnd  ) { moduleAktPosLeftPx = moduleLeftStart; }
   if (  moduleToLeft == false && moduleAktPosLeftPx >= moduleRightEnd ) { moduleAktPosLeftPx = moduleRightStart; }

   moduleTable.style.left = moduleAktPosLeftPx + 'px';

   setTimeout(moduleMove, 75);
}

function moduleDirection( toleft) {
   if (  moduleToLeft == toleft ) { moduleStepPx += 2; }
   if (  moduleToLeft !== toleft ) { moduleToLeft = toleft; moduleStepPx = 2 }
   if (  moduleStepPx  >= 12 ) { moduleStepPx = 2 }
     
}



