// Notizkalender - javascript.js


// Kalender - Events markieren
// Hier können nur unveränderliche Events eingetragen werden (z.B.: Feiertage, Geburtstage)
// Mehrere Events im Monat durch einem Mittelstrich (|) trennen.
function event_markieren(anzeige) {
 monat = new Array();
 monat[1] = "1"; // Januar
 monat[2] = ""; // Februar
 monat[3] = ""; // März
 monat[4] = ""; // April
 monat[5] = "1"; // Mai
 monat[6] = ""; // Juni
 monat[7] = ""; // Juli
 monat[8] = ""; // August
 monat[9] = ""; // September
 monat[10] = "3|31"; // Oktober
 monat[11] = ""; // Nonember
 monat[12] = "25|26"; // Dezember

 if (monat[anzeige].length == 1) {
   var id = "m" + anzeige + "t" + monat[anzeige];
   document.getElementById(id).style.border="solid 1px #CC0000";
   document.getElementById(id).style.fontWeight="bold";
 }

 if (monat[anzeige].length > 1) {
  tag = monat[anzeige].split("|");
  for (zaehler = 0; zaehler < tag.length; zaehler++) {
   var id = "m" + anzeige + "t" + tag[zaehler];
   document.getElementById(id).style.border="solid 1px #CC0000";
   document.getElementById(id).style.fontWeight="bold";
  }
 }
}


// Kalender - Aktuelles Datum markieren
function datum_markieren(jahr,monat) {
 heute = new Date();
 if (jahr == heute.getFullYear() && monat == (heute.getMonth()+1)) {
  var id = "m" + (heute.getMonth()+1) + "t" + heute.getDate();
  document.getElementById(id).style.backgroundColor="#DC3431";
  document.getElementById(id).style.fontWeight="bold";
 }
}

// Notiz Vorschau
function vorschau() {
 var f = window.open("","f","scrollbars=1,width=400,height=450");
 f.document.writeln('<!DOCTYPE HTML PUBLIC "-\/\/W3C\/\/DTD HTML 4.01 Transitional\/\/EN">');
 f.document.writeln('<html><head><title>Notiz-Vorschau<\/title><\/head>');
 f.document.writeln('<body style="font-family: Verdana, Arial; font-size: 12px;">');
 f.document.writeln("<div style=\"white-space: Pre;\">" + document.Form.text.value + "<\/div>");
 f.document.writeln('<\/body><\/html>');
 f.document.close();
 f.focus();
}


// Suche - Eingabe der Jahreszahl
function jahreszahl(seite) {
  heute = new Date();
 var datum = prompt("Jahreszahl eingeben:",heute.getFullYear());
 if (datum.length == 4) {
  window.location.href=seite + ".php?das_jahr=" + datum + "";
 }
 else {
  jahreszahl(seite);
 }
}


// JavaScript-Sicherheitsabfrage bevor die Notiz gelöscht werden soll
function kontrolle(datum) {
 if (document.Form.option.options[3].selected == true && document.Form.ausweis.value != "") {
  var frage = confirm("Möchten Sie die Notiz vom " + datum + " wirklich löschen?"); // Umlaute nicht ersetzen!
  if (frage == true) {
   return true;
  } 
  else {
   return false;
  }
 } 
 else {
  return true;
 }
}


// Tastatur-Funktion
function taste(ein) {
 a = "";
 switch (ein) {
  case "link": a = ' <a href="http://www." target="_blank"></a>'; break;
  case "bild": a = ' <img src="upload/">'; break;
  case "einteilung": a = '\nUhr - Termin\n1 \n2 \n3 \n4 \n5 \n6 \n7 \n8 \n9 \n10 \n11 \n12 \n13 \n14 \n15 \n16 \n17 \n18 \n19 \n20 \n21 \n22 \n23 \n'; break;
  case "ul": a = ' <u></u>'; break;
  case "fett": a = ' <b></b>'; break;
  case "kursiv": a = ' <i></i>'; break;
  case "gestrichen": a = ' <s></s>'; break;
  case "hr": a = '\n<hr>\n'; break;
  case "tag": var tag = prompt("HTML-Tag/XML-Tag: ",""); a = '<' + tag + '></' + tag + '>'; break;
  case "rechner": var ag = prompt("Rechner: ","1 * 1"); if(confirm(ag + " = " + eval(ag) + "\nRechnung in die Notiz einfügen?")) {a = " " + ag + " = " + eval(ag);} else{a = "";} break;
  case "uhr": h = new Date(); a = h.getDate() + "." + (h.getMonth()+1) + "." + h.getFullYear() + " " + h.getHours() + ":" + h.getMinutes(); break;
  case "markierung": a = '<span style="background-color: #ffffb0;"></span>'; break;
  case ":)": a = ' :)'; break;
  case ":(": a = ' :('; break;
  case ";)": a = ' ;)'; break;
  case ":D": a = ' :D'; break;
  case ":o": a = ' :o'; break;
  case ":x": a = ' :x'; break;
 }
 document.Form.text.value = document.Form.text.value + a;
 aenderung();
}


// Textfeldgröße ändern
function groesser() {
 if (document.getElementById("Kommentar").rows < 25){
  document.getElementById("Kommentar").rows += 5;
 }
}
function kleiner() {
 if (document.getElementById("Kommentar").rows > 10){
  document.getElementById("Kommentar").rows -= 5;
 }
}


// Textfeld leeren
function leeren() {
 document.Form.text.value = "";
 aenderung();
}


// Bei einer Änderung Button markieren
function aenderung() {
 document.getElementById("textstatus").innerHTML=document.Form.text.value.length + " Zeichen";
 if (document.Form.text.value.length != document.Form.laenge.value) {
  document.getElementById("speichern").style.backgroundColor = "#C9C9C9";
 }
else {
  document.getElementById("speichern").style.backgroundColor = "#E2E2E2";
 }
}

function set() {
 document.getElementById("speichern").style.backgroundColor = "#E2E2E2";
 document.getElementById("textstatus").innerHTML=document.Form.text.value.length + " Zeichen";
}


function abbrechen(aktion) {
 if (document.Form.text.value.length != document.Form.laenge.value) {
  if (confirm("Möchten Sie die Notiz " + aktion + "?")) {
   document.Form.submit();
  }
  else {
  history.back();
  }
 }
 else {
 history.back();
 }
}


// Upload-Datei löschen
function del(url, datei) {
 if (confirm("Soll \"" + unescape(datei) + "\" wirklich gelöscht werden?") ) {
  window.location = url;
 }
}

function uhrzeit() {
h = new Date(); a = ZweiZiffern(h.getHours()) + ":" + ZweiZiffern(h.getMinutes()) + ":" + ZweiZiffern(h.getSeconds());
document.getElementById("uhrzeit").innerHTML = a;
window.setTimeout("uhrzeit()", 21);
}

function ZweiZiffern(x){return(((x < 10) ? "0" : "") + x)}

 function anzeigen(das){
 if(document.getElementById(das).style.display=="none") 
 document.getElementById(das).style.display="block"; 
 else document.getElementById(das).style.display="none";}


// Textfunktionen
function kleinbuchstaben() {
 var a = document.Form.text.value;
 var b = a.substring();
 var c = a.substring(a.length);
 b = b.toLowerCase();
 c = c.toUpperCase();
 a = b + c;
 document.Form.text.value = a;
}

function grossbuchstaben() {
 var a = document.Form.text.value;
 var b = a.substring();
 var c = a.substring(a.length);
 b = b.toUpperCase();#99cc00
 c = c.toLowerCase();
 a = b + c;
 document.Form.text.value = a;
}

function selbstlaute() {
 var c = document.Form.text.value;
 for(i = 1; i < 8; i++) {
  if (i == 1) {a = "ä"; b = "ae";}
  if (i == 2) {a = "ö"; b = "oe";}
  if (i == 3) {a = "ü"; b = "ue";}
  if (i == 4) {a = "Ü"; b = "Ue";}
  if (i == 5) {a = "Ä"; b = "Ae";}
  if (i == 6) {a = "Ö"; b = "Oe";}
  if (i == 7) {a = "ß"; b = "ss";}
  d = c;
  while (d.indexOf(a)>-1){
   pos = d.indexOf(a);
   d = (d.substring(0, pos) + b + d.substring((pos + a.length), d.length));
   c = d;
  }
 }
 document.Form.text.value = d;
}

function g_anfangsbuchstaben() {
 s = document.Form.text.value;
 var t = "";
 var sc = s.length;
 var a;
 var doUpperFlag = true;
 for (i = 0; i < sc; i++) {
 a = s.charAt(i)
 if ( doUpperFlag ){
 a = toUpper(a)
 }
 else {
 a = toLower(a)
 }
 if ( a == ' ' ){
 doUpperFlag = true
 } 
 else{
 doUpperFlag = false
 }
 t = t + a
 }
 document.Form.text.value = t;
}

function k_anfangsbuchstaben() {
 s = document.Form.text.value;
 var t ="";
 var sc = s.length;
 var a
 for (i = 0; i < sc; i++) {
 a = s.charAt(i)
 if (isLower(a)){
 a = toUpper(a)
 }
 else{
 if(isUpper(a)) a = toLower(a)
 }
 t = t + a
 }
 document.Form.text.value = t;
}
function isLower(a){
 return toLower(a) == a;
}
function isUpper(a){
 return toUpper(a) == a;
}
function toUpper(a){
 return a.toUpperCase();
}
function toLower(a){
 return a.toLowerCase();
}

function DelHTML(HTMLWord) {
 var a = HTMLWord.indexOf("<");
 var b = HTMLWord.indexOf(">");
 var HTMLlen = HTMLWord.length;
 var c = HTMLWord.substring(0, a);
 if(b == -1)
 b = a; d = HTMLWord.substring((b + 1), HTMLlen);
 Word = c + d; tmp = Word.indexOf("<");
 if(tmp != -1)Word = DelHTML(Word); return Word;}
function tag_entfernen() {
 ToCheck = document.Form.text.value;
 Checked = DelHTML(ToCheck);
 document.Form.text.value = Checked;
}

function buchstabencode() {
 var c = document.Form.text.value;
 for (i = 1; i < 8; i++) {
  if (i == 1) {a = "ä"; b = "&auml;";}
  if (i == 2) {a = "ö"; b = "&ouml;";}
  if (i == 3) {a = "ü"; b = "&uuml;";}
  if (i == 4) {a = "Ü"; b = "&Uuml;";}
  if (i == 5) {a = "Ä"; b = "&Auml;";}
  if (i == 6) {a = "Ö"; b = "&Ouml;";}
  if (i == 7) {a = "ß"; b = "&szlig;";}
  d = c;
  while (d.indexOf(a)>-1) {
   pos=d.indexOf(a);
   d=(d.substring(0, pos)+b+
   d.substring((pos + a.length), d.length));
   c=d;
  }
 }
document.Form.text.value = d;
}

function rot_13() {
 var keycode = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
 var text = new String(document.Form.text.value)
 var textrot = new String()
 for(var i = 0; i < text.length; i++){
  var codechar = text.substring(i, i + 1)
  var pos = keycode.indexOf(codechar.toUpperCase())
  if(pos >= 0){
   pos = (pos + keycode.length / 2) % keycode.length
   codechar = (codechar == codechar.toUpperCase()) ?
      keycode.substring(pos, pos + 1) :
      keycode.substring(pos, pos + 1).toLowerCase()
  }
  textrot = textrot + codechar
 }
 document.Form.text.value = textrot;
}

function ersetzen() {
 var c = document.Form.text.value;
 var a = document.Form.nach.value;
 if(a != "") {
   b = document.Form.durch.value;
   d = c;
  while(d.indexOf(a)>-1){
   pos = d.indexOf(a);
   d = (d.substring(0, pos) + b + d.substring((pos + a.length), d.length));
   c = d;
  }
  document.Form.text.value = d;
 }
}
