// erweiterte JavaScript-Funktionen für das RG-CMS
// Version 0.42 vom 5. September 2009 (20090905_HR)
// 12.06.2010 Rudi: Erweiterung mit RGsoundBox
// 10.09.2011 Rudi: Erweiterung Special-Cookies
//
// --------[Variable und Funktionen]------------------------------------------
var MyWin="";
// ---------------------------------------------------------------------------
function RGpopup(MyURL,WinPar,WinName) 
 { // Anzeigen einer URL in einem Popup-Fenster
   Parameters='resizable=yes'; // ,dependent=yes,<?= $SprStuPar["winpos_pop"]; ?>';
   if (WinPar) { Parameters+=','+WinPar; } 
   else { Parameters+=',left=20,top=30,width=470,height=230'; }
   WindowName = (WinName ? WinName : 'Visitenkarte');
   MyWin=window.open(MyURL,WindowName,Parameters);
   MyWin.focus();
   return false;
 } 
// ---------------------------------------------------------------------------
 function RGsoundBox(soundURL,MyTitle,WinPar,WinName)
 { // Abspielen eines SoundFiles in einem Popup-Fenster
   // alert('soundURL='+soundURL+'\nMyTitle='+MyTitle+'\nWinPar='+WinPar+'\nWinName='+WinName);
   Parameters='dependent=yes,resizable=yes,scrollbars=no';  // Elternfensterabhängig, resizeable, no Scrollbars
   if (WinPar) { Parameters+=','+WinPar; }
     else { Parameters+=',left=20,top=30,width=210,height=112'; }
   WindowName = (WinName ? WinName : 'RGsoundBox');
   SoundTitle = (MyTitle ? MyTitle : soundURL.substring(soundURL.lastIndexOf('/')+1,soundURL.lastIndexOf('.')) );
   MediaPlay = 'website.php?id=/de/musik/hoerproben/musikplayer.htm&src='+soundURL+'&title='+MyTitle;
   MyWin=window.open(MediaPlay,WindowName,Parameters);
   MyWin.focus();
   return false;
 }
// --------[Cookie-Variablen und Funktionen]----------------------------------
var CookieName, CookieMatrix, CookieMtx, CookieContent='';
var CookieLifeTime=0, CookieExpired=0, CookieCount=0;
var CheckboxName, InputString, OutputString;

// ---------------------------------------------------------------------------
function oe_switchCookie(CheckboxElement,CookieName)
 { // Cookie Wechselschalter: true or false, je nach Zustand der Checkbox
   oe_setCookie(CookieName,CheckboxElement.checked.toString(),380,-1);
 }  
// ---------------------------------------------------------------------------
function oe_getCookie(CookieName)
 { // Cookie nach Name auslesen
   var CookieContent=''; Cnt=0;
   if (document.cookie)
    { CookieMatrix=document.cookie.split('; ');
      CookieCount=CookieMatrix.length;
      while (Cnt<CookieCount)
       { CookieMtx=CookieMatrix[Cnt].split('=');
         if (CookieName==CookieMtx[0]) CookieContent=oe_decodeTXT(CookieMtx[1]);
         Cnt++;
    }  }
   return CookieContent;
 }
// ---------------------------------------------------------------------------
function oe_setCookie(CookieName,CookieContent,CookieLife,Flag)
 { // Cookie nach Name und Laufzeit setzen
   if (navigator.cookieEnabled==false)
      alert('Cookies sind leider deaktiviert!')
   else
   { var cnlng=CookieName.length;
     while (CookieName.indexOf(' ') !=-1)
      { // change blank in underscore for dumb proggers or users
	    blpos=CookieName.indexOf(' ');
        CookieName=CookieName.substr(0,blpos)+'_'+CookieName.substr(blpos+1,cnlng);
      }
     CookieContent=oe_encodeTXT(CookieContent);
     CookieLifeTime=new Date();
     CookieExpired=CookieLifeTime.getTime()+((1+CookieLife)*24*3600000);
     if (CookieLife<0)
        var CookieExpired=CookieLifeTime.getTime()-1000
     CookieLifeTime.setTime(CookieExpired);
     document.cookie=CookieName+'='+CookieContent+';expires='+CookieLifeTime.toGMTString()+';path=/';
     var CookieCode='';
     if (document.cookie)
        CookieCode=document.cookie;
     if ((CookieCode.indexOf(CookieName)<0) && (CookieCode.indexOf(CookieContent)<0))
        if (CookieLife<0) location.reload();
        else alert('Cookie konnte nicht gespeichert werden!\n   ('+CookieName+')');
     else if (Flag!=-1) location.reload();
  } }
// ---------------------------------------------------------------------------
function oe_encodeTXT(InputString)
 { // Kodierung der Uebergebenen Variablen nach Standard mit mehr Zeichen
   var OutputString=''; // alert('oe_encodeTXT(InputString) is running with: "'+InputString+'"');
   for(cx=0; cx<InputString.length; cx++)
    { ChrNr=InputString.charCodeAt(cx);
      if (ChrNr<48||(ChrNr>57&&ChrNr<65)||(ChrNr>90&&ChrNr<97)||ChrNr>122)
        if (ChrNr<16)
         OutputString=OutputString+'%0'+ChrNr.toString(16);
        else
        if (ChrNr<256)
         OutputString=OutputString+'%'+ChrNr.toString(16);
        else
         OutputString=OutputString+'&#x'+ChrNr.toString(16)+';';
      else
       OutputString=OutputString+InputString.substr(cx,1);
    }
   return OutputString;
 }
// ---------------------------------------------------------------------------
function oe_decodeTXT(InputString)
 { // Dekodierung der Uebergebenen Variablen nach Standard
   var OutputString=unescape(InputString);
   return OutputString;
 }
// ---------------------------------------------------------------------------
// var agent = navigator.userAgent.toLowerCase();
//  isIE = agent.indexOf("msie") > -1; // deaktiviert durch XXX
//  if (isIE) { document.write('<script src="../html/script/curvycorners.js" type="text/javascript"></script>'); }
// --------[end-of-file]------------------------------------------------------
