// ------------------------------------------------------------------;
// 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 ) {

	oDivBigPic = document.getElementById( 'bigpicframe' );
	if ( oDivBigPic == null ) { return false }

	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;
    }

	oDivBigPic.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();
	oEffectPics[0] = '/images/woman_crm.jpg';
	oEffectPics[1] = '/images/iscrm_screens3.jpg';
	oEffectPics[2] = '/images/iscrm_screens3_pointing.jpg';
	oEffectPics[3] = '/images/laptop_iscrm.jpg';
	oEffectPics[4] = '/images/ipad_iscrm.jpg';
	oEffectPics[5] = '/images/ipad_iphone_iscrm.jpg';
	//oEffectPics[5] = '/images/woman_notepad.jpg';
	//oEffectPics[6] = '/images/rechenzentrum2.jpg';
var oEffectImage = null; 
function effectChangePicture( oImage ) {
	oEffectImage = document.getElementById('iswebmain');
  	if ( oEffectImage == null ) return true; 
	window.setTimeout( "effectChangePicture1()", 10000) ;
}

function effectChangePicture1( ) {
  if ( oEffectImage == null ) return true; 
  new Effect.Fade( oEffectImage,{duration:1.0, from:1.0, to:0.02 }) ;
  window.setTimeout( "effectChangePicture2()", 1000);
}

function effectChangePicture2( ) {
	if ( oEffectImage == null ) return true; 
  	// nächstes bild bestimmen
  	var sOldPic = oEffectImage.src; 
  	var sNewPic = oEffectPics[0];
	for ( i=0; i <= oEffectPics.length-2; i++ ) {
		if ( sOldPic.indexOf( oEffectPics[i] ) >= 0 ) {
			sNewPic = oEffectPics[i+1]; 
			break;
		}
	}
  	// neues Bild setzen und wieder einblenden 
  	Effect.Fade( oEffectImage,{duration:1.0, from:0.02, to:1.0 }) ;
  	oEffectImage.src = sNewPic ;
  	window.setTimeout( "effectChangePicture1()", 10000) ; // damit sich nichts übelagert
}



// --------------------------------------------------------------------------------------------
// 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";
        }
    }


    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 }
     
}




// --------------------------------------------------------------------------------------------
// ReferralId aus Link auslesen, merken und bereitstellen
// Auch Layout-Apnassungen
// Aufruf; <body onload="onloadPage"
// --------------------------------------------------------------------------------------------
var referralId = null;
var referralCookieLabel = 'iscrmReferral';
function onloadPage(){ 

	// ReferralId auslesen
	var urlPage = null;
	var indexParam1 = null;
	var indexParam2 = null;
	var referralValue = null;
	urlPage = window.location.href;
	indexParam1 = urlPage.indexOf('referral=');
	if ( indexParam1 > 0 ) {
		referralValue = urlPage.substr( indexParam1+9, 50 ); 
		indexParam2 = referralValue.indexOf('&');
		if ( indexParam2 > 0 ) referralValue = referralValue.substr( 0, indexParam2 );
		referralId = referralValue;
	}
	if (referralId != null && referralId != '') {
		// ReferralId im Cookie merken 
		cookieWriteValue(referralCookieLabel, referralId)
	}


	// LayoutAnpassungen
	var o1 = document.getElementById("contentLeftInner");
	var o2 = document.getElementById("partnerinfo");
	if ( screen.availWidth < 1024 ) {
	  if ( o2 != null ) o2.style.display = 'none'; // rechte Seite PartnerInfo nicht anzeigen
	  if ( o1 != null ) o1.style.paddingRight = '20px'; // links padding wegnehmen
	
	} else {
	  // Position der rechten PartnerInfo berechen
	  // Mit Prototype.js WindowWidth berechen
	  var widthPx = document.viewport.getWidth();
	  var widthContent = 950; 
	  var widthRightBanner = 240;
	  var widthHeaderMenu = 410; 
	  w = widthPx - widthContent - widthRightBanner - 20; 
	  rightpos = 20;
	  if ( w > 100 ) { rightpos = w / 2; rightpos += 20; }
	  if ( (rightpos + widthRightBanner) > widthHeaderMenu ) { rightpos = widthHeaderMenu - widthRightBanner;  }
	  if ( o2 != null ) o2.style.right = rightpos + 'px';
	}
	
	

}

function referralGetId(){ 
	// Gespeicherte ReferralId holen
	var s = cookieRead( referralCookieLabel, 'noreferral' )
	return s;
}


// -----------------------------------------------------------------------
// Cookies schreiben/lesen
// -----------------------------------------------------------------------
function cookieRead( sLabel, sDefault ){  
    var strCookie = "" ;
    if ( document.cookie ) { strCookie = document.cookie } else { return sDefault }
    // alert('cookie gesamt ' + strCookie + ' Label=' + sLabel  );
    var a = strCookie.split(";");
    var i = 0;
    // den ersten Eintrag mit sLabel=xxx holen
    for ( i=0; i < a.length; i++ ) {
         b = a[i].split("=");
         // if ( b[0].substring(0,1) == ' ' ) b[0] = b[0].substring(1, b[0].length ) // manchmal mit führendem BLANK !!
         if ( b[0].indexOf(sLabel) >= 0 ) { return b[1] }
    }
    return sDefault;
}
    
function cookieWriteValue( sLabel, sValue ){
    // cookieValue schreiben //    
    var strCookie = '';
    var exp = new Date();
    exp.setTime(exp.getTime() + ( 7 * 24*60*60*1000) );
    strCookie = sLabel + '=' + sValue + '; expires=' + exp.toGMTString(); 
    document.cookie = strCookie;
    // alert( 'cookie written' + strCookie );
}


function bookmarks_add(Text, URL) {
	/***************************************************************
	*  Copyright notice
	*
	*  (c) 2008 Alex Kellner <alexander.kellner@einpraegsam.net>
	*  All rights reserved
	*
	*  This script is part of the TYPO3 project. The TYPO3 project is
	*  free software; you can redistribute it and/or modify
	*  it under the terms of the GNU General Public License as published by
	*  the Free Software Foundation; either version 2 of the License, or
	*  (at your option) any later version.
	*
	*  The GNU General Public License can be found at
	*  http://www.gnu.org/copyleft/gpl.html.
	*
	*  This script is distributed in the hope that it will be useful,
	*  but WITHOUT ANY WARRANTY; without even the implied warranty of
	*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	*  GNU General Public License for more details.
	*
	*  This copyright notice MUST APPEAR in all copies of the script!
	***************************************************************/

	if (window.sidebar) { // firefox
		window.sidebar.addPanel(Text, URL, "");
	}
	
	else if(window.opera && window.print) { // opera
		var elem = document.createElement('a');
		elem.setAttribute('href', URL);
		elem.setAttribute('title', Text);
		elem.setAttribute('rel', 'sidebar');
		elem.click();
	}
	
	else if(document.all) { // ie
		window.external.AddFavorite(URL, Text);
	}
}




