//+++++++++++++++++++++Refresh Upload Progress+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function refreshUploadProgress(){
  var uploadIdentifier=$("UPLOAD_IDENTIFIER").value;
  var url="/libPhp/ajax/refreshUploadProgress.php";  
  new Ajax.Request(url, {
    method: "POST",
    encoding: "UTF-8",
    parameters: "UPLOAD_IDENTIFIER="+uploadIdentifier,
    onComplete: function(transport){
alert(transport.responseText);
      if((transport.responseText>"") && (transport.responseText!="null")){
        var obj=transport.responseText.evalJSON();
        var loadingBarWidth=400;
        var newSize=(obj.bytes_uploaded*loadingBarWidth)/obj.bytes_total;
        $("uploadSize").style.width=newSize+"px";
        setTimeout("refreshUploadProgress();",1000);
      }else{
        setTimeout("refreshUploadProgress();",1000);
      }
    } 
  });
}



// Formularfelderüberprüfen
function chkMail(gCustomError) {
  var chkOK = true;
  var chkMail = true;
  var chkEmpty = true;
  var msg = "";

  $$(".chkEmpty").each( function(item){
    if($F(item)=="") {
      chkOK = false;
      chkEmpty = false;
      item.setStyle({backgroundColor: '#FF9999'});
    } else {
      item.setStyle({backgroundColor: '#FFFFFF'});
    }
  } );

  $$(".chkEmail").each( function(item){
                var reg = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)'+'(\\@)([a-zA-Z0-9\\-\\.]+)'+'(\\.)([a-zA-Z]{2,4})$');
                
    if(!reg.test($F(item)))  {
    //if($F(item)=="") {
      chkOK = false;
      chkMail = false;
      item.setStyle({backgroundColor: '#FF9999'});
    } else {
      item.setStyle({backgroundColor: '#FFFFFF'});
    }
  } );

  if(!chkEmpty) msg += (gCustomError ? gCustomError : ixTransJsempty) +"\n";
  if(!chkMail) msg += ixTransJsmail +"\n";
  if(msg!="") alert(msg);
  return chkOK;
}

function mouseRollOver()
{
  $$('.rollOver').each(function (i)
  {
    var index = i.src.lastIndexOf('.');
    if (index > -1) {var newSrc = i.src.substring(0, index)+'.mo'+i.src.substring(index);}
    
    if (newSrc)
    {
      var img = new Image();
      img.src = newSrc;
    }
    
    i.observe('mouseover', function (e)
    {
      if (newSrc) {i.src = newSrc;}
    })
    
    i.observe('mouseout', function (e)
    {
      i.src = i.src.replace('.mo.', '.');
    })
  });
}


//**************************
//*** SPAMSCHUTZ ***  
//**************************


// UnCryptMailto() entschluesselt die Mail-Adresse, zu zuvor mit
// der PHP-Funktion encryptEmail() verschlüsselt wurde
// Anwendung:
/*
<?php $link="javascript:linkTo_UnCryptMailto('".encryptEmail("john@doe.de")."');"; ?>
<a href="<?php echo $link ?>">E-Mail an John Doe schreiben</a>
*/
 
// JS function for uncrypting spam-protected emails:
function UnCryptMailto(s) {  //
  var n=0;
  var r="";
  for(var i=0; i < s.length; i++) {
    n=s.charCodeAt(i);
    if (n>=8364) {n = 128;}
    r += String.fromCharCode(n-(1));
  }
  return r;
}

  // JS function for uncrypting spam-protected emails:
function linkTo_UnCryptMailto(s)  {  //
  location.href="mailto:"+UnCryptMailto(s);
}

// JS-Fehlermeldungen ++++++++++++++++++++++++++++++++++++++
// während der Entwicklung Komentare entfernen
// in der error.php die eig. Email eintragen
// beim Livegehen wieder ausschalten, um nicht die ganzen
// Fehler von exot. Browsern zu erhalten
//window.onerror=callAjaxError; // IE
//window.onError= callAjaxError; // NS
/*
function callAjaxError(msg, url, line) {
  new Ajax.Request('/libPhp/ajax/error.php', 
 {
   method: 'post',
   postBody: 'appcode='+navigator.appCodeName+"&ver="+navigator.appVersion+"&usr="+navigator.userAgent+"&JsErrorUrl="+url+"&JsErrorLine="+line+"&JsErrorMsg="+msg,
   asynchronous: true,
   onSuccess: function (t)  {}
 });
  return false;
}
*/


// Basisfunktionen Slider
function sliderObserver()
  {
    $$('.basisSlider').each(function (v)
                            {
                             v.style.display = 'block';
                             v.down('h2').stopObserving('click');
                             v.down('h2').observe('click', function (e)
                                       {
                                         this.up('.basisSlider').stopObserving('click');
                                         if (!this.up('.basisSlider').hasClassName('opened'))
                                         {
                                           $$('.opened').each(function (v) {new Effect.BlindUp(v.down('.basisSliderContent'), {that : v, afterFinish : function () {this.that.removeClassName('opened'); this.that.style.backgroundImage = sliderCloseGrafic;}});});
                                           this.up('.basisSlider').addClassName('opened');
                                           new Effect.BlindDown(this.up('.basisSlider').down('.basisSliderContent'), {afterFinish : function ()
                                                                                                 {
                                                                                                   sliderObserver();
                                                                                                 }});
                                           this.up('.basisSlider').style.backgroundImage = sliderOpenGrafic;
                                         }
                                         else
                                         {
                                           this.up('.basisSlider').removeClassName('opened');
                                           new Effect.BlindUp(this.up('.basisSlider').down('.basisSliderContent'), {that : this.up('.basisSlider'), afterFinish : function ()
                                                                                                 {
                                                                                                   this.that.style.backgroundImage = sliderCloseGrafic;
                                                                                                   sliderObserver();
                                                                                                 }});
                                         }
                                       });
                            });
  }
  
function mouseRollOverBg()
  {
    $$('.rollOverBg').each(function (i)
                           {
                             var index = i.style.backgroundImage.lastIndexOf('.');
                             if (index > -1) {var newSrc = i.style.backgroundImage.substring(0, index)+'.mo'+i.style.backgroundImage.substring(index);}
                             
                             /*if (newSrc)
                             {
                             var img = new Image();
                             img.src = newSrc;
                           }*/
                             
                             i.observe('mouseover', function (e)
                                       {
                                         if (!this.hasClassName('opened')) {if (newSrc) {i.style.backgroundImage = newSrc;}}
                                       });
                             
                             i.observe('mouseout', function (e)
                                       {
                                         if (!this.hasClassName('opened')) {i.style.backgroundImage = i.style.backgroundImage.replace('.mo.', '.');}
                                       });
                           });
  }


// +++Seminare Slider++++++++++++++++++++++++++++++++++++++++++++++++++++
function sliderObserverSeminare()
  {
    $$('.basisSlider h2').each(function (v)
                            {v.style.display = 'block';
                             v.stopObserving('click');
                             v.observe('click', function (e)
                                       {
                                         this.stopObserving('click');
                                         if (!this.hasClassName('opened'))
                                         {
                                           this.addClassName('opened');
                                           this.up().addClassName('opened');
                                           new Effect.BlindDown(this.up().down('.basisSliderContent'), {afterFinish : function ()
                                                                                                 {
                                                                                                   sliderObserverSeminare();
                                                                                                 }});
                                           this.up().style.backgroundImage = sliderOpenGrafic;
                                         }
                                         else
                                         {
                                           this.removeClassName('opened');
                                           this.up().removeClassName('opened');
                                           new Effect.BlindUp(this.up().down('.basisSliderContent'), {that : this, afterFinish : function ()
                                                                                                 {
                                                                                                   this.that.up().style.backgroundImage = sliderCloseGrafic;
                                                                                                   sliderObserverSeminare();
                                                                                                 }});
                                         }
                                       });
                            });
  }

function sliderObserverSeminareFirst(){
  //$$('.basisSliderContent').first().setStyle("display: block;");

  new Effect.BlindDown($$('.basisSliderContent').first(), {duration: 0.0});

  $$('.basisSlider h2').first().addClassName('opened');
  $$('.basisSlider h2').first().up().addClassName('opened');

  $$('.basisSlider h2').first().up().style.backgroundImage = sliderOpenGrafic;
}


// +++NEWS Slider++++++++++++++++++++++++++++++++++++++++++++++++++++

function sliderObserverNews(){

    $$('.rollUp').each(function (w){
      var v = w.down();
      v.stopObserving('click');

      v.observe('click', function (e){
        sliderNews(this);
      });
    });
}

function sliderNews(that)
{
        that.stopObserving('click');
        var height = that.up('.newsText').down('.spacerForJS').innerHTML+"px";

        if (!that.hasClassName('opened')){
          $$('.opened').each(function (v) {
            new Effect.Morph(v.up('.newsText'), {style: 'height: 80px;', that : v, afterFinish : function () {this.that.removeClassName('opened'); v.innerHTML = v.innerHTML.replace(ixTransSchliessen, ixTransWeiterlesen);} });
          });

          that.addClassName('opened');
          new Effect.Morph(that.up('.newsText'), {style: 'height: '+height+';', afterFinish: function (){ sliderObserverNews(); that.innerHTML = that.innerHTML.replace(ixTransWeiterlesen, ixTransSchliessen);} });
        }else{
          that.removeClassName('opened');
          new Effect.Morph(that.up('.newsText'), {style: 'height: 80px;', that : that, afterFinish : function (){ sliderObserverNews(); that.innerHTML = that.innerHTML.replace(ixTransSchliessen, ixTransWeiterlesen);} });
        }
}


// Download-Templates: Ausklappfunktionalität **********************************************
function initDownloadRow() {
  $$(".grouptitle").each(function(item){
    var o = item.up("table").next("div.groupDivEntry");
    //if(o && !o.hasClassName("first")) toggleDownloadRow( o, 0.0 );
    //if(o && !o.hasClassName("first")) toggleDownloadHeader(item, 0);

    var flagShow = true;
    if( whitepaperId && o.id && (o.id==whitepaperId) ) flagShow = false;
    if(flagShow) {
        toggleDownloadRow( o, 0.0 );
        toggleDownloadHeader(item, 0);
    }

    item.observe("click", function(e) {
      if(flagDownloadIsMoving) return;
      if(o) toggleDownloadRow( o, 1.0 );
      toggleDownloadHeader(item, 1);
    });
  });
}
function toggleDownloadHeader(obj, dur) {
  if(obj.ix_flag) {
    obj.ix_flag=false;
    obj.select("th").each(function(item, i){
      if(i>0) item.setStyle({fontWeight:"bold", background: "url(/libImages/global/downloadsBack.jpg) -10px 0"});
      else item.setStyle({fontWeight:"bold", background: "url(/libImages/global/downloadsBack.jpg) 0 0"});
    });
  } else {
    obj.select("th").each(function(item, i){
      //if(i>0) item.setStyle({background: "url(/libImages/global/downloadsReiter.jpg) -10px 0 no-repeat"});
      //else item.setStyle({background: "url(/libImages/global/downloadsReiter.jpg) 0 0 no-repeat"});
      if(i>0) window.setTimeout(function(){item.setStyle({fontWeight:"normal", background: "url(/libImages/global/downloadsReiter.jpg) -10px 0 no-repeat"});}, dur*1000);
      else  window.setTimeout(function(){item.setStyle({fontWeight:"normal", background: "url(/libImages/global/downloadsReiter.jpg) 0 0 no-repeat"});}, dur*1000);
    });
    obj.ix_flag=true;
  }
}
function toggleDownloadRow(obj, dur) {
  flagDownloadIsMoving=true;
  if(obj.ix_small) {
    obj.ix_small=false;
    Effect.BlindDown(obj, {duration:dur, afterFinish: function(){flagDownloadIsMoving=false;} });
  } else {
    Effect.BlindUp(obj, {duration:dur, afterFinish: function(){flagDownloadIsMoving=false;} });
    obj.ix_small=true;
  }
}



// auf den seminarseiten vor dem absenden pruefen, ob mind. 1 seminar ausgewaehlt wurde
// submit: class="seminarSubmitButton" id=seminarSubmitButton_1 .. seminarSubmitButton_N
// checkbox: id = seminarTerminCheck_1 .. seminarTerminCheck_N
function initSeminarTerminCheck() {
  $$(".seminarSubmitButton").each( function(item, i) {
    item.observe("click", function(e) {
      var t = item.id.split("_");
      var t2 = false;
      
      $$(".seminarTerminCheck_"+t[1]).each(function(item2, i2){
        t2 = t2 || item2.checked;
      });
      if(!t2) {
        alert(ixTransSeminareWarning);
        e.stop();
      }
    });
  } );
}

function openPartnerSearch()
{
	var output = '<img id="strategieBg" src="/libImages/global/bgPartnerLayer.png" alt="Hintergrund" style="position:fixed; z-index:9000; left:0px; right:0px; top:0px; bottom:0px; width:100%; height:100%;" /><div id="strategieLayer" style="position:absolute; z-index:9001; left:0px; right:0px; top:175px; padding-bottom:20px;"><div id="strategieInner" style="position:relative; width:924px; margin:0px auto;"><img id="strategieLoader" src="/libImages/global/ajax-loader.gif" alt="Loader" style="position:absolute; z-index:9002; left:446px; top:200px;" /><img id="strategieClose" src="/libImages/global/buttonPartnerClose.png" alt="Schließen" style="position:absolute; right:-20px; top:-20px; cursor:pointer;"/><iframe src="/partner/partner-find_neu.php" style="width:924px; height:839px; background:#ffffff; border:none; overflow:hidden;" scrolling="no" frameborder="0"></iframe></div></div>';
	$$('body')[0].insert({bottom:output});
	$$('#strategieBg, #strategieLayer, #strategieClose').each(function (v)
	{
		v.stopObserving('click');
		v.observe('click', function (e)
		{
			$('strategieBg').remove();
			$('strategieLayer').remove();
		});
	});
	$('strategieInner').stopObserving('click');
	$('strategieInner').observe('click', function (e)
	{
		e.stop();
	});
	return false;
}
