var pageForms = new Array();
var clearedTA= new Array();

function clearSpace(el){
  if(!clearedTA[el.id]){
    clearedTA[clearedTA.length] = el.id;
    clearedTA[el.id] = true; 
    el.value=''; 
  }  
}

function validateForm(strId) {

  for(var i=0;i<pageForms.length;i++) {
    
    if(pageForms[i] != null && pageForms[i].id == strId){

      fc = pageForms[i];
      if(fc.checkConstraints() == 0) {
        if(document.forms[fc.id].returnTo)
          document.forms[fc.id].returnTo.value = document.location.href;       
          document.forms[fc.id].submit();
      }
      return false;  
      break;      
    }
  }
  
}

function formConstraints(formId) {
	 this.id = formId;
  this.constraints = new Array();		

	 this.addConstraint = function (fld,type,msg) {
  this.constraints[this.constraints.length] = new fieldValidation(fld, type, msg);	
	}		
	this.checkConstraints = function() {
		var cFail= 0;		 
	  for(var ii=0;ii<this.constraints.length;ii++) {
	    switch (this.constraints[ii].type) {
	      case 'req': { 
	        if(IsEmpty(this.id, this.constraints[ii].name)){
	          alert(this.constraints[ii].msg);
	          SetFocus(this.constraints[ii].name);
	          return ++cFail;
	        }else break;
	      }
	    }  
	  }
	  return cFail;
	}
}

function fieldValidation(name,type,msg) {
  this.name = name;
  this.type = type;
  this.msg = msg;
}

function IsEmpty(frmId,fld){
	var formEl = document.forms[frmId].elements[fld];
	var domEl = document.getElementById(fld);
 
 var test=document.getElementById('geslacht');
 
	switch(domEl.type) {
	  case 'text': {
	    if(domEl.value != '') 
	      return false;
	    break;  
	  }
	  case 'radio': {
	  	for(j=0;j<formEl.length;j++) {
	  	  if(formEl[j].checked)
	  	    return false;
	  	}
	  	break;
	  }
	  case 'checkbox': {
  	  if(formEl.checked)
  	    return false;
  	  break;
	  }
	  case 'select-one': {
	    if(formEl.options[formEl.selectedIndex].value != '')
	      return false;
	    break;  
	  }
	  case 'textarea': {
	  	if(domEl.innerText != ' ' && domEl.innerText != '')  
	  	  return false;
	    break;  
	  }
	}
	return true;
}

function SetFocus(fieldName) {
  document.getElementById(fieldName).focus();
}

function change_visibility(id,id2,visible)
{ 
	 if(visible == 'visible' )
  {
		  document.getElementById(id).style.display = 'none';
		  document.getElementById(id2).style.display = '';
  }
	 if(visible == 'invisible' )
  {
		  document.getElementById(id2).style.display = 'none';
		  document.getElementById(id).style.display = '';
  }
  
}
