/* ***** Hover-Schaltflächen ***** */

/* (c) Leo, Movie-College 2002

Verwendung:
- .js-Datei in die HTML-Datei einbinden
- Hinter dem Bild einen JavaScript-Block einfügen:
-- loadHover(bild.id) für alle Bilder aufrufen, die gehovert werden sollen,
-- loadHovers(bild.id, Anzahl Zustände) für Bilder mit mehreren Zuständen aufrufen (1 für normalen ein/aus-Hover).
- In dem <img>-Tag die Funktion hover(bild.id, Zustand) aufrufen, für das Ausgangsbild ist der Zustand=0
*/

function loadHover (bildname) {
 eval(bildname+'0=new Image();');	//globale Variable
 eval(bildname+'0.src=document.images.'+bildname+'.src;');
 eval(bildname+'Count=1;');	//globale Variable
 var url0=eval(bildname+'0.src');
 var extPos=url0.lastIndexOf('.');
 var ext0=url0.substr(extPos,url0.length-extPos);
 var url1=url0.substr(0,url0.lastIndexOf('.')-1)+'1'+ext0;
 eval(bildname+'1=new Image();');	//globale Variable
 eval(bildname+'1.src=url1;');
}

function loadHovers (bildname, count) {
 eval(bildname+'0=new Image();');	//globale Variable
 eval(bildname+'0.src=document.images.'+bildname+'.src;');
 eval(bildname+'Count=count;');	//globale Variable
 var url0=eval(bildname+'0.src');
 var extPos=url0.lastIndexOf('.');
 var ext0=url0.substr(extPos,url0.length-extPos);
 var url1="";
 for (var i=1; i<=count; i++) {
  url1=url0.substr(0,url0.lastIndexOf('.')-1)+i+ext0;
  eval(bildname+i+'=new Image();');	//globale Variable
  eval(bildname+i+'.src=url1;');
 }
}

function hover(bildname, num) {
 if (num<=eval(bildname+'Count')) {
  eval('document.images.'+bildname+'.src='+bildname+num+'.src;');
 }
}

/* ***** Fenstermanagement ***** */

/* (c) Leo, Movie-College 2002 */

function resizeWindow(maxwidth, maxheight) {
 var height=screen.height-20;
 var width=screen.width-20;
 if (width>maxwidth) width=maxwidth;
 if (height>maxheight) height=maxheight;
 window.resizeTo(width,height);
 var posX=Math.floor((screen.width-width)/2);
 var posY=Math.floor((screen.height-height)/2);
 window.moveTo(posX,posY);
}

/* ***** Druckansicht ***** */

/* (c) Leo, Movie-College 2002

Hiermit kann die Druckansicht automatisiert werden.

printView()			?print an die Fensteradresse hängen
checkOption()			sucht nach der Angegebenen Option (z.B. print) in der URL
writePrintStyle()		CSS-Definitionen für die Druckansicht einfügen
writeURL()				URL der Seite ausgeben
writeDate()			Datum in den Quelltext einfügen
*/

function printView() {
 var s=window.location.href;
 window.location.href=s+'?print';
}

function checkOption(lookup) {
 var options=window.location.search;
 // options="?print";
 var optPos=options.indexOf(lookup);
 if (optPos>0) { // Vor dem Print steht ein ? => optPos kann kleinstenfalls das zweite Zeichen sein
  var optPre=options.substr(optPos-1,1);
  var optPost="&";
  if (options.length>(optPos+lookup.length)) {
   optPost=options.substr(optPos+lookup.length,1);
  }
  if ((optPre=="?") || (optPre=="&")) {
   if ((optPost=="?") || (optPost=="&")) {
    return true;
   }
  }
 }
 return false;
}

function writePrintStyle() {
 var styleorder="";
 styleorder+='<style> ';
 styleorder+='.print_never { display: none; width: 1px; overflow:hidden; } ';
 styleorder+='.print_only { display: block; } '; 
 styleorder+='.print_mastertable { width: 625px; } '; 
 styleorder+='body { background-image: url(""); } ';
 styleorder+='</style>';
 document.writeln(styleorder);
}

function writeURL() {
 var s=window.location.pathname;
 if (window.location.host=="") {
  s="Lokales Verzeichnis: "+window.location.pathname;
 } else {
  s="www.movie-college.de"+s;
 }
 document.write(s);
}

function writeDate() {
 var datum=new Date();
 /* var s=datum.toLocaleString(); */
 var s=datum.getDate()+"."+(datum.getMonth()+1)+"."+datum.getYear();
 document.write(s);
}

/* Jetzt nach ?print suchen und ggf. die Druckansicht aktivieren */

if (checkOption("print")) {
 writePrintStyle();
}

/* ***** Allgemeine Funktionen für Formulare ***** */

/* (c) Leo, Movie-College 2002

chkMail(E-Mail)		Überprüft, ob eine E-Mail-Adresse möglich ist
chkForbiddenMail(Mail)	Überprüft, ob eine E-Mail-Adresse gesperrt wurde.
chkText(oText, Meldung)	Überprüft, ob ein Textfeld mit text gefüllt ist, sonst gibt es eine Fehlermeldung (=Meldung). oText ist ein Textfeld-Objekt.
chkOptions(opt,cnt,M)	Wie chkText, nur wir zudem mit count die Anzahl der Radio-Buttons angegeben.
chkCheckbox(oBox, M)	Prüft, ob die Checkbox angekreuzt ist (z.B. für AGB)
parseIntS()		Wandelt String in Zahl um, wobei falsche Zeicehn keine Fehler verursachen.
zuGeldbetrag()		Gibt eine Zahl mit genau 2 Nachkommastellen aus.
isGermany(country)	Überprüft, ob die Angabe in country für Deutschland steht.
*/

function chkMail(oEMail, message) {
 var EMail=oEMail.value;
 if ((EMail.lastIndexOf(".") > EMail.indexOf("@")) && (EMail.lastIndexOf("@") == EMail.indexOf("@")) && (EMail.indexOf("@") > 0) && (EMail.lastIndexOf(".") < (EMail.length-1))) return true; else {
  alert(message);
  oEMail.focus();
  return false;
 }
}

function chkForbiddenMail(oEMail) {
 var Adressen=new Array ("spam@me.com","info@movie-college.de");
 var beinhaltet=false;
 for (var i=0; i<Adressen.length; i++) {
  if (oEMail.value==Adressen[i]) beinhaltet=true;
 }
 if (beinhaltet) {
   alert("Fehler: Diese E-Mail-Adresse wurde gesperrt.\nBitte setzen Sie sich mit dem Movie-College in Verbindung!");
  return false;
 } else return true;
}

function chkText(oText, message) {
 if (oText.value<="") {
  alert(message);
  oText.focus();
  return false;
 } else return true;
}

function chkOptions(oOptions, count, message) {
 var allright=false;
 for (var i=0; i<count; i++) {
  if (oOptions[i].checked) allright=true;
 }
 if (!allright) {
  alert(message);
  oOptions[0].focus();
  return false;
 } else return true;
}

function chkCheckbox(oBox, message) {
 if (!oBox.checked) {
  alert(message);
  oBox.focus();
  return false;
 } else return true;
}

function parseIntS(wert) {
 if (isNaN(parseInt(wert))) {return 0} else {return parseInt(wert)}
}

function zuGeldbetrag(betrag) {
 var vorkomma=Math.floor(betrag);
 var nachkomma=Math.round((betrag-vorkomma)*100);
 var sNachkomma=nachkomma+"";
 while (sNachkomma.length<2) {sNachkomma+="0"}
 ergebnis=vorkomma+","+sNachkomma;
 return ergebnis;
}

function isGermany(country) {
 var country1="";
 country1=country;
 var staat=country1.toUpperCase();
 var isGer=false;
 if (staat=="DEUTSCHLAND") isGer=true;
 if (staat=="GERMANY") isGer=true;
 if (staat=="BRD") isGer=true;
 if (staat=="GER") isGer=true;
 if (staat=="") isGer=true;
 return isGer;
}

function checkLength(ref,max){

	if (ref.value.length >= max) ref.value = ref.value.substr(0,max-1);
  
}