


// Der folgende Eventhandler funktioniert nur in MSI und Opera.
// http://msdn2.microsoft.com/en-us/library/ms533065.aspx

document.onkeypress = formKeyDown;

function formKeyDown( DnEvents ) 
{
  k = (DnEvents) ? DnEvents.which : window.event.keyCode;
  
  if (k == 13) {
  
    actFeld   = document.activeElement;
    lFound    = false;
    
    if (actFeld.type == 'textarea') {
      return( true );
    }
    
    /* 
      Durch dir nachfolgende Verarbeitung wuerde durch 
      Betaetigung der Enter-Taste das naechste Eingabefeld
      vom Type Text angesteuert.

      Durch die Deaktivierung und Rueckgabe von FALSE
      vergleibt der Focus im aktuellern Feld und die Taste
      Enter bewirkt nichts!
      
    for (i1=0; i1<document.forms.length; i1++) {
      for (i2=0; i2<document.forms[i1].elements.length; i2++) {
        if (document.forms[i1].elements[i2].name == actFeld.name) {
          lFound = true;
          break;
        }
      }
      if (lFound) {
        for (i3=i2+1; i3<document.forms[i1].elements.length; i3++) {
          if (
              (document.forms[i1].elements[i3].type == 'text') ||
              (document.forms[i1].elements[i3].type == 'textarea') 
             )
          {
            document.forms[i1].elements[i3].focus();
            break;
          }
        }
      }
    }
    */
    
    return( false );
  }
  return( true );
}

    

// - Auswahllisten, Invertierungen -------------------------------------------
function tr2ON( trObject )
{
  trObject.className='frmSelectTR2i';
}

function tr2OFF(trObject )
{
  trObject.className='frmSelectTR2';
}

  

// - Allgemeines -------------------------------------------------------------
function mouseON( trObject )
{
  trObject.className='mouseON';
}
function mouseOFF(trObject )
{
  trObject.className='mouseOFF';
}

// - Office-Snap -------------------------------------------------------------
function mouseSnapON( trObject )
{
  trObject.className='mouseSnapON';
}
function mouseSnapOFF(trObject )
{
  trObject.className='mouseSnapOFF';
}

  
  
// - Statuszeile -------------------------------------------------------------
function statusMsg( text )
{
  window.defaultStatus = text;
  window.status = text;
}



// - Zahlenformatierung und Ueberpruefung ------------------------------------
function Round( inValue, decPoint )
{
  mult = Math.pow(10,decPoint);
  outValue = Math.round( inValue*mult+0.0 ) / mult;
  return( outValue );
}



function NumberFormat( inValue, decPoint )
{
  outValue = inValue.toString(10);
  if (outValue.indexOf(".")<=0) {
    outValue = outValue.concat('.00000000000000000000000000000000');
  }
  else {
    outValue = outValue.concat('0000000000000000000000000000000');
  }
  x2 = outValue.indexOf(".");
  return( outValue.substring(0,x2+decPoint+1) );
}



function charChk( inTxt, charSet )
{
  //var charSet ='0123456789[]()-+*%/';
  var outTxt='';
  for (var i = 0; i < inTxt.length; i++) {
    c = inTxt.charAt(i);
    if (charSet.indexOf(c)>=0 ) {
      outTxt = outTxt.concat(c);
    }
  }
  return( outTxt );
}



function numFieldChk( cFormName, cFieldName, nDeci )
{
  var inTxt  = document.forms[cFormName].elements[cFieldName].value;
  var outTxt = '';
  var c  = '';
  var c1 = 0;
  var c2 = 0;
  
  // outTxt = charChk(inTxt, '.,+-0123456789'); // nicht verwendet, da auch die Anzahl der Kommas ueberwacht werden soll.
  for (i=0; i<inTxt.length; i++) {
    c = inTxt.substr(i,1);
    if ((('0'<=c) && (c<='9')) || (c=='.') || (c==',') || (c=='-')) {

      if (c1==0) {
        outTxt = outTxt.concat(c);
      }
      else {
        if ((c!='.') && (c!=',')) {
          if (c2<nDeci) {
            outTxt = outTxt.concat(c);
            c2++;
          }
        }
      }
      /*
      else if ((c1<=0) || ((c!='.') && (c!=','))) {
        outTxt = outTxt.concat(c);
      }
      */

      if ((c=='.') || (c==',')) {
        c1++;
      }

    }
  }
  outTxt = outTxt.replace(',', '.');
  if (outTxt.substr(0,1)=='.') {
    c = '0';
    outTxt = c.concat(outTxt);
  }
  if (inTxt != outTxt) {
    document.forms[cFormName].elements[cFieldName].value = outTxt;
  }
}





// - Textarea ----------------------------------------------------------------
function insertTagsInTextarea( cFormName, cField, aTag, eTag ) 
{
  //var input = document.forms['frmMAIN'].elements[cField];
  var input = document.forms[cFormName].elements[cField];
  input.focus();
  /* fuer Internet Explorer */
  if(typeof document.selection != 'undefined') {
    /* Einfuegen des Formatierungscodes */
    var range = document.selection.createRange();
    var insText = range.text;
    range.text = aTag + insText + eTag;
    /* Anpassen der Cursorposition */
    range = document.selection.createRange();
    if (aTag.length == 0) {
    }
    else if ((insText.length == 0) && (aTag.length > 0) ) {
      range.move('character', -eTag.length);
    }
    else {
      range.moveStart('character', aTag.length + insText.length + eTag.length);
    }
    range.select();
  }
  /* fuer neuere auf Gecko basierende Browser */
  else if(typeof input.selectionStart != 'undefined')
  {
    /* Einfuegen des Formatierungscodes */
    var start = input.selectionStart;
    var end = input.selectionEnd;
    var insText = input.value.substring(start, end);
    input.value = input.value.substr(0, start) + aTag + insText + eTag + input.value.substr(end);
    /* Anpassen der Cursorposition */
    var pos;
    if (insText.length == 0) {
      pos = start + aTag.length;
    } else {
      pos = start + aTag.length + insText.length + eTag.length;
    }
    input.selectionStart = pos;
    input.selectionEnd = pos;
  }
  /* fuer die uebrigen Browser */
  else
  {
    /* Abfrage der Einfuegeposition */
    var pos;
    var re = new RegExp('^[0-9]{0,3}$');
    while(!re.test(pos)) {
      pos = prompt('Einf&uuml;gen an Position (0..' + input.value.length + '):', '0');
    }
    if(pos > input.value.length) {
      pos = input.value.length;
    }
    /* Einfuegen des Formatierungscodes */
    var insText = prompt('Bitte geben Sie den zu formatierenden Text ein:');
    input.value = input.value.substr(0, pos) + aTag + insText + eTag + input.value.substr(pos);
  }
}



// - eMail-Dummys ------------------------------------------------------------
function email( name, domain, tld, link) 
{
  var link = "<a href='mailto:"+name+"@"+domain+"."+tld+"'>"+link+"</a>";
  document.write(link);
}

function email2( name, domain, tld) 
{
  var link = "<a href='mailto:"+name+"@"+domain+"."+tld+"'>"+name+"@"+domain+"."+tld+"</a>";
  document.write(link);
}



// - Popup für Galerie -------------------------------------------------------
function imagePopWindow( Picture, Breit, Hoch )
{
  xsize = Breit+35; // Zusatz für Rand rechts und links
  ysize = Hoch+75;  // Zusatz für Rand oben und unten - damit Button angezeit werden kann 
    
  ScreenWidth = screen.width;
  ScreenHeight = screen.height;

  xpos = (ScreenWidth/2)-(xsize/2);
  ypos = (ScreenHeight/2)-(ysize/2);
	
	NewWindow=window.open("","Picture","height="+ysize+",width="+xsize+",scrollbars=no,resizable=no,top="+ypos+",left="+xpos+"");
	NewWindow.document.write ("<html><head><title>PhilippHauer.de - Galerie");
	NewWindow.document.write ("</title></head>");
  NewWindow.document.write ("<body style='background-color:#ffffff; color:#FF9900; font-family: Arial, Helvetica, sans-serif; ' onload='focus()'>");
//NewWindow.document.write ("<body bgcolor='#cccccc'>");
	NewWindow.document.write ("<table align='center'><tr>");
	NewWindow.document.write ("<td align='center' valign='top'>");
	NewWindow.document.write ("<table border='0' bgcolor='#40666e' cellpadding='0' cellspacing='1'><tr><td align='center'>");
	NewWindow.document.write ("<a href='javaScript:self.close()'><img alt='Bild von PhilippHauer.de' style='border:1px solid #1F8DAA;' src=");
	NewWindow.document.write (Picture);
	NewWindow.document.write ("></a>");
	NewWindow.document.write ("</tr></table>");
	NewWindow.document.write ("</td></tr><tr>");
	NewWindow.document.write ("<td align='center' style='font-size:10px;'>Zum Schließen klicken");
	NewWindow.document.write ("<br>");
	NewWindow.document.write ("</td></tr></table>");
	NewWindow.document.write ("</body></html>");
	NewWindow.document.close();
  NewWindow.resizeTo(xsize,ysize); 
}


// - Zoom von Bilder ---------------------------------------------------------
// Benoetigt CSS Formate.

function imageSetZoom( img, dir, width, height, margin, zIndex, delay ) 
{
  setTimeout(function() {
    if (img.dir==dir) {
      if (zIndex==0) {
        img.style.borderColor='#ffffff';
        img.style.borderStyle='none';
      }
      else {
        img.style.borderColor='#00000';
        img.style.borderStyle='solid';
      }
      img.style.width=width;
      img.style.height=height;
      img.style.margin=margin;
      img.style.zIndex=zIndex;
      img.parentNode.parentNode.style.zIndex=zIndex;
    }
  }, delay);
}

function imgZommIn( img, width, height, zoomsteps ) 
{
  img.dir='rtl';
  now=parseInt(img.style.zIndex);
  for (i=now+1; i<=zoomsteps; i++) {
    w=(width*(10+i))/20+'px';
    h=(height*(10+i))/20+'px';
    m=(-i*3)+'px 0 0 '+(-width*i/40)+'px';
    imageSetZoom(img, 'rtl', w, h, m, i, 10*(i-now));
  }
}

function imgZommOut( img, width, height ) 
{
  img.dir='ltr';
  now=parseInt(img.style.zIndex);
  for (i=now-1; i>=0; i--) {
    w=(width*(10+i))/20+'px';
    h=(height*(10+i))/20+'px';
    m=(-i)+'px 0 0 '+(-width*i/40)+'px';
    imageSetZoom(img, 'ltr', w, h, m, i, 10*(now-i));
  }
}


// - Vorladen ----------------------------------------------------------------
function vorladen( imgName)
{
  if(document.images)
  	{
	  navihover=new Image();
	  navihover.src=imgName;
	}
}




//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//                          Spiegelschrift v1.0
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//------------------------------ Copyright -----------------------------------
//                           (c) 2002 xeam.de
//                      Internet: http://www.xeam.de
//                         e-mail: mail@xeam.de
//----------------------------------------------------------------------------
/* 
  Beispiel fuer den Einsatz:

  <body bgcolor="#FFFBDF" onload="schreiben ();">
   <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
     <td align="center" id="textfeld">
     </td>
    </tr>
   </table>
  </body>

*/
 var zeile=new Array ();   // hier muessen die Inhalte der verschiedenen Zeilen eingegeben werden
 zeile[0]="ofni.regna.wreB";
 zeile[1]="";
 zeile[2]="Quelle:";
 zeile[3]="http://www.traci.de";
 var trennzeichen="&nbsp;|&nbsp;";   // Zeichen, welche zwischen dem richtigen und dem gespiegelten Text erscheinen
 var text;
 var a;
 var b;

function schreiben ()
{
 if (window.document.getElementById)
  {
   for (a=0;a<zeile.length;a++)
    {
     text="";
     text+=(zeile[a]+trennzeichen);
     for (b=zeile[a].length;b>=0;b--)
      {
       text+=zeile[a].charAt (b);
      }
     window.document.getElementById ("textfeld").innerHTML+=(text+"<br>");
    }
  }
}


