function popupMitgliedWerden() {
        var iMyWidth;
        var iMyHeight;
        iMyWidth = (window.screen.width/2) - (360 + 10);
        iMyHeight = (window.screen.height/2) - (220 + 50);
        var win2 = window.open("https://mitgliedwerden.igbce.de/igbce.html","Window2","status=no,height=600,width=720,resizable=no,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",scrollbars=no");
     //   var win2 = window.open("https://www.mitgliedwerden.igbce.de/","Window2","status=no,height=600,width=720,resizable=no,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",scrollbars=no");
        win2.focus();
}
function popupMitgliedWerdenHTML() {
        var iMyWidth;
        var iMyHeight;
        iMyWidth = (window.screen.width/2) - (360 + 10);
        iMyHeight = (window.screen.height/2) - (220 + 50);
        var win2 = window.open("https://mitgliedwerden.igbce.de/all.php","mitgliedwerden","width=720,height=600,menubar=no,status=no" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",scrollbars=no");
        win2.focus();
}
function displayErrorMessage(msg, divID) { // 1 visible, 0 hidden
	msg.replace("\n", "<br>");
    if(document.layers)	   //NN4+
    {
       document.layers[divID].innerHTML = msg;
       document.layers[divID].visibility = "show";
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(divID);
        obj.innerHTML = msg;
        obj.style.visibility = "visible";
    }
    else if(document.all)	// IE 4
    {
    	document.all[divID].innerHTML = msg;
        document.all[divID].style.visibility = "visible";
    }
  }
function parseDate (str_date) {

	var arr_date = str_date.split('.');

	if (arr_date.length != 3) return;
	if (!arr_date[0]) return;
	if (!RE_NUM.exec(arr_date[0])) return;
	if (!arr_date[1]) return;
	if (!RE_NUM.exec(arr_date[1])) return;
	if (!arr_date[2]) return;
	if (!RE_NUM.exec(arr_date[2])) return;

	var dt_date = new Date();
	dt_date.setDate(1);

	if (arr_date[1] < 1 || arr_date[1] > 12) return;
	dt_date.setMonth(arr_date[1]-1);
	if (arr_date[2] < 100) arr_date[2] = Number(arr_date[2]) + (arr_date[2] < NUM_CENTYEAR ? 2000 : 1900);
	dt_date.setFullYear(arr_date[2]);
	var dt_numdays = new Date(arr_date[2], arr_date[1], 0);
	dt_date.setDate(arr_date[0]);
	if (dt_date.getMonth() != (arr_date[1]-1)) return;

	return (dt_date)
}

function checkPasswords(newpass, confirmpass) {
  var errorMsg = null;
  if(newpass != confirmpass) {
  	return 'Die Kontrolleingabe des Passwortes  ist mit der Ersteingabe nicht identisch. Bitte korrigieren Sie.';
  }	  
  if(newpass.length < 4) {
  	return 'Das von Ihnen vorgesehene Passwort entspricht nicht den Vorgaben. Bitte wählen Sie ein Passwort mit mindestens vier Zeichen.';
  }
  return errorMsg;
}

function isValidMitgliedsnummer(m) {
  if(isNaN(m)) {
    return false;
  }
  if(m.length != 7) {
    return false;
  }
  return true;
}

function isValidEmail(checkThisEmail)
{
var myEMailIsValid = true;
var myAtSymbolAt = checkThisEmail.indexOf('@');
var myLastAtSymbolAt = checkThisEmail.lastIndexOf('@');
var myLastDotAt = checkThisEmail.lastIndexOf('.');
var mySpaceAt = checkThisEmail.indexOf(' ');
var myLength = checkThisEmail.length;


// at least one @ must be present and not before position 2
// @yellow.com : NOT valid
// x@yellow.com : VALID

if (myAtSymbolAt < 1 ) 
 {myEMailIsValid = false}


// at least one . (dot) afer the @ is required
// x@yellow : NOT valid
// x.y@yellow : NOT valid
// x@yellow.org : VALID

if (myLastDotAt < myAtSymbolAt) 
 {myEMailIsValid = false}

// at least two characters [com, uk, fr, ...] must occur after the last . (dot)
// x.y@yellow. : NOT valid
// x.y@yellow.a : NOT valid
// x.y@yellow.ca : VALID

if (myLength - myLastDotAt <= 2) 
 {myEMailIsValid = false}


// no empty space " " is permitted (one may trim the email)
// x.y@yell ow.com : NOT valid

if (mySpaceAt != -1) 
 {myEMailIsValid = false}

if (myLastAtSymbolAt != myAtSymbolAt)
 {myEMailIsValid = false}

return myEMailIsValid
}

function onFocusSearch(field) {
  if(field.value == 'Schnellsuche...') {
    field.value = '';
  }
}

function onBlurSearch(field) {
  if(field.value == '') {
    field.value = 'Schnellsuche...';
  }
}

function popupObjectEdit(uri,title) {
  popup(uri,title,500,450);
}

function popupObjectChoose(uri,title) {
  popup(uri,title,500,700);
}

function popupImageChoose(uri,title) {
  popup(uri,title,500,720);
}

function popupImageUpload(uri,title) {
  popup(uri,title,500,540);
}

function popupLinkChoose(uri,title) {
  popup(uri,title,500,350);
}

function popup(uri,title,width,height) {
  var options = 'toolbar=no,width='+width+',height='+height+',location=no,menubar=no,status=no,scrollbars=yes'
  window.open(uri,title,options);
}

function checkField(fieldName, fieldValue, maxLength, isMandantory) {
  var errorMsg = null;
  if(isMandantory && fieldValue.length == 0) {
    errorMsg = "Das Feld '" + fieldName + "' ist ein Pflichtfeld. Bitte vervollständigen Sie Ihre Eingabe.";
  }
  
  if(maxLength > 0 && fieldValue.length > maxLength) {
    errorMsg = "Die maximale Laenge fuer das Feld '" + fieldName + "' betraegt " + maxLength + ".";
  }
  
  return errorMsg;
}

function checkFields(fieldName, fieldValue, maxLength, isMandantory) {
  var errorMsg = "";
  var newLine = "";
  for(i=0; i<fieldName.length; i++) {
    //alert(fieldValue[i]);
    var tmpMsg = checkField(fieldName[i], fieldValue[i], maxLength[i], isMandantory[i]);
    if(tmpMsg != null && tmpMsg.length > 0) {
      if(newLine.length > 0)
        errorMsg += newLine+tmpMsg;
      else
        errorMsg = tmpMsg;
      newLine = "<br>\n";
    }
  }
  if(errorMsg.length == 0) {
  	errorMsg = null;
  }
  return errorMsg;
}

function doSave(action) {
  if(document.forms[0].mode) {
    document.forms[0].mode.value = "save";
  }
  doSubmitForm(action);
}

