var mailregex = /^[0-9a-zA-Z][0-9a-zA-Z\._-]*@([0-9a-zA-Z-_]+\.)+([a-z]{2,4})$/;
var dateregex = /^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{4}$/;
var numregex = /^[0-9]+$/;

function popupNormal(sUrl, sWidth, sHeight)
{
	var popup;

	popup = window.open(sUrl, 'PressRelease','toolbar=yes,location=no,directories=no,status=no,menubar=no,scrollbars=yes,screenX=10,screenY=10,resizable=yes,width=' + sWidth + ',height=' + sHeight, true);
	if(navigator.appName.indexOf('Netscape') != -1)
		popup.focus();
}

function popupHelp(sUrl, sWidth, sHeight)
{
	var popup;

	popup = window.open(sUrl, 'PressRelease','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,screenX=10,screenY=10,resizable=yes,width=' + sWidth + ',height=' + sHeight, true);
	if(navigator.appName.indexOf('Netscape') != -1)
		popup.focus();
}

function popupPicture(sUrl, sWidth, sHeight)
{
	var popup;
	//var sWidth=sWidth+10;
	//var sHeight=sHeight+10;
	
	popup = window.open(sUrl, 'PictureViewer','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,screenX=10,screenY=10,resizable=yes,width=' + sWidth + ',height=' + sHeight, true);
	if(navigator.appName.indexOf('Netscape') != -1)
		popup.focus();
}

function cms_login() {
  window.open("/cms/login.php", "login", "width=450,height=300,resizable=yes");
}

function konsole(konsurl,konswidth,konsheight) {
  kons = window.open(konsurl, "zoom", "width="+konswidth+",height="+konsheight+"location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=no'");
  if(kons.focus)kons.focus();
}

function mifi(missifi) {
  if (missifi!="") {
    alert("Bitte folgende Felder noch vollstï¿½ndig ausfï¿½llen:\n " + missifi);
    return false;
  }
  else return true;
}

function check_mailthispage() {
  var missing_fields="";
  if (!mailregex.test(document.forms[0].email_recipient.value)) missing_fields+="\n- Emailadresse Empfï¿½nger";
  if (!mailregex.test(document.forms[0].email_sender.value)) 	missing_fields+="\n- Emailadresse Absender";
  return mifi(missing_fields);
}

function check_eventvorschlag() {
  var missing_fields="";
  if (document.forms[0].event_title.value=="") 	missing_fields+="\n- Event Titel";
  if (document.forms[0].desc.value=="") 	missing_fields+="\n- Event Beschreibung";
  if (document.forms[0].event_type.options[document.forms[0].event_type.selectedIndex].value=="none") missing_fields+="\n- Event Typ";
  if (document.forms[0].organizer.value=="") 	missing_fields+="\n- Veranstalter Name/Firma";
  if (document.forms[0].address.value=="") 	missing_fields+="\n- Adresse";
  if (document.forms[0].phone.value=="") 	missing_fields+="\n- Telefon";
  return mifi(missing_fields);
}

function check_bnl() {
  var missing_fields="";
  if (document.forms[0].name.value=="") 	missing_fields+="\n- Name";
  if (document.forms[0].betrieb.value=="") 	missing_fields+="\n- Betrieb";
  if (document.forms[0].adresse.value=="") 	missing_fields+="\n- Adresse";
  if (!mailregex.test(document.forms[0].email.value)) 	missing_fields+="\n- eMail";
  return mifi(missing_fields);
}

function check_kundenanmeldung() {
  var missing_fields="";
  if (document.forms[0].name.value=="") 	missing_fields+="\n- Name";
  if (document.forms[0].betrieb.value=="") 	missing_fields+="\n- Betrieb";
  if (document.forms[0].adresse.value=="") 	missing_fields+="\n- Adresse";
  if (!mailregex.test(document.forms[0].email.value)) 	missing_fields+="\n- eMail";
  if (document.forms[0].phone.value=="") 	missing_fields+="\n- Telefon";
  if (document.forms[0].username.value=="") 	missing_fields+="\n- gew. Benutzername";
  if (document.forms[0].password.value=="") 	missing_fields+="\n- gew. Passwort";
  if (document.forms[0].password_conf.value=="") missing_fields+="\n- Passwortbestï¿½tigung";
  if (document.forms[0].password.value!=document.forms[0].password_conf.value) missing_fields+="\n- Passwort und Passwortbestï¿½tigung mï¿½ssen identisch sein!";
  if (document.forms[0].password.value==document.forms[0].username.value) missing_fields+="\n- Benutzername und Passwort dï¿½rfen aus Sicherheitsgrï¿½nden nicht identisch sein!";
  return mifi(missing_fields);
}

function printpage() {
  if (window.print) window.print();
  else alert("Leider unterstï¿½tzt Ihr Browser diese Funktion nicht! Bitte aktivieren Sie die Druckfunktion Ihres Browsers manuell!");
}

function countdown() {
	var jahr=2008, monat=9, tag=7, stunde=00, minute=00, sekunde=00;
	var zielDatum=new Date(jahr,monat-1,tag,stunde,minute,sekunde);
	startDatum=new Date(); // Aktuelles Datum

	// Countdown berechnen und anzeigen, bis Ziel-Datum erreicht ist
	if(startDatum<zielDatum)  {

	  var jahre=0, monate=0, tage=0, stunden=0, minuten=0, sekunden=0;

	  // Tage
	  while(startDatum.getTime()+(24*60*60*1000)<zielDatum) {
		tage++;
		startDatum.setTime(startDatum.getTime()+(24*60*60*1000));
	  }
	  
	  // Stunden
	  while(startDatum.getTime()+(60*60*1000)<zielDatum) {
		stunden++;
		startDatum.setTime(startDatum.getTime()+(60*60*1000));
	  }
	  
	  // Minuten
	  while(startDatum.getTime()+(60*1000)<zielDatum) {
		minuten++;
		startDatum.setTime(startDatum.getTime()+(60*1000));
	  }	  

	  // Sekunden
	  sekunden=Math.floor((zielDatum-startDatum)/1000);

	  // Anzeige formatieren
	  if(stunden<10) stunden="0"+stunden;
	  if(minuten<10) minuten="0"+minuten;
	  if(sekunden<10) sekunden="0"+sekunden;

	  document.getElementById('countdowninput_days').innerHTML=
		  tage+" Tage";
	  document.getElementById('countdowninput_hours').innerHTML=
		  stunden+":";
	  document.getElementById('countdowninput_minutes').innerHTML=
		  minuten+":";
	  document.getElementById('countdowninput_seconds').innerHTML=
		  sekunden;
	  setTimeout('countdown()',200);
	}
	// Anderenfalls alles auf Null setzen
	else {
		document.getElementById('countdowninput_days').innerHTML = "0 T-";
		document.getElementById('countdowninput_hours').innerHTML = "00:";
		document.getElementById('countdowninput_minutes').innerHTML = "00:";
		document.getElementById('countdowninput_seconds').innerHTML = "00";
  	}
}

/**
 * Berechnet den Countdown für die Startseite
 */
function startCountdown() {	
}

function toggleHotorNot() {
	str = "<input type='hidden' name='ranking' value='0'>";
	for (var i = 10; i >= 1; i--) {
		str += "<img style='padding-right:10px' src='/img/cms/design/hotornot_bullet_inactive.gif' onmouseout='this.src=\"/img/cms/design/hotornot_bullet_inactive.gif\"' onmouseover='this.src=\"/img/cms/design/hotornot_bullet_active.gif\"' onclick=\"hotornot_vote('" + i + "')\">";
	}
	document.getElementById('btn_vote').style.display = 'none';
	document.getElementById('hotornot_javascript_disabled').innerHTML = '';
	document.getElementById('hotornot_javascript_enabled').innerHTML = str;
}

function renew_pw_show(){
	document.getElementById('change_pw').style.display='block';
	document.getElementById('renew_pw_einblenden').style.display='none';
	document.getElementById('renew_pw_ausblenden').style.display='block';	
}
function renew_pw_hide(){
	document.getElementById('change_pw').style.display='none';
	document.getElementById('renew_pw_einblenden').style.display='block';
	document.getElementById('renew_pw_ausblenden').style.display='none';	
}