<!--
/**
 * Functions
 * @package CoMa
 * @subpackage inc
 * @author Stefan Lingler <sl@pixelwings.com>
 * @copyright Pixelwings Medien GmbH
 */

function openPopup(content) {
	var popup=window.open(window.pathname+(location.search?'&':'?')+'style=popup&content='+content,'POPUP','width=600,height=500,menubar=0,location=0,resizable=1,scrollbars=1');
	popup.focus();
}

function printPage() {
	var popup=window.open(window.location+(location.search?'&':'?')+'print','PRINT','width=600,height=500,menubar=0,location=0,resizable=1');
	popup.focus();
}

/*
 * Form Functions START
 */
function setCheckbox() {
	var checkbox=arguments[0];
	var element=arguments[1];
	var value=arguments[2]?arguments[2]:false;
	var path=element.split('.');
	var input_chk=document.forms[path[0]][path[1]];
	if (input_chk==undefined) return false;
	input_chk.value=value!=undefined && value==true?input_chk.value:(input_chk.value==1?0:1);
	checkbox.className='checkbox'+(input_chk.value==1?'_active':'');
	return true;
}

function initCheckboxes() {
	var form=arguments[0];
	var checkboxes=arguments[1];
	for (var i=0;i<checkboxes.length;i++) {
		var div=document.getElementById('chk_'+checkboxes[i]);
		setCheckbox(div,form+"."+checkboxes[i],true);
	}
}

function setFormSection() {
	var element=arguments[0];
	var path=element.split('.');
	var input_chk=document.forms[path[0]][path[1]];
	var div=document.getElementById('data_'+(arguments[1]?arguments[1]:path[1]));
	var check=arguments[2]!=undefined?arguments[2]:null;
	if (check!=null) div.style.display=input_chk.value==check?'block':'none';
	else div.style.display=div.style.display=='none'?'block':'none';
}

function initFormSections() {
	var form=document.forms[arguments[0]];
	var sections=arguments[1];
	var inputs=arguments[2];
	var checks=arguments[3];
	for (var i=0;i<sections.length;i++) {
		var div=document.getElementById('data_'+(arguments[1]?arguments[1]:path[1]));
		setFormSection(arguments[0]+'.'+inputs[i],sections[i],checks[i]);
	}
}

function addParticipant() {
	var form=document.forms['registration'];
	var values=typeof(arguments[0])=='object'?arguments[0]:null;
	var id,headline;
	if (values!=null) {
    for (var a in values) {
      eval('var val_'+a+'=\''+values[a]+'\'');
    }
		id=a!=undefined?val_id:0;
	}
	else {
		form.participants.value++;
		id=parseInt(form.participants.value)-1;
	}
	
	headline=id>0?'<br /><h2>Teilnehmer</h2>':'';
	
	var value=values!=null && a!=undefined;
	
	var fields=['title','degree','first_name','last_name','year_of_birth','position','task','employees'];
	for (var a=0;a<fields.length;a++) {
		eval('var mt_'+fields[a]+'=\'\'');
	}
	if (window.mandatory!=undefined) {
    for (var a=0;a<window.mandatory.length;a++) {
      eval('var mt_'+window.mandatory[a]+'=\' *\'');
    }
	}
	
	
	
	
	var mt=window.mandatory!=undefined && window.mandatory.length>0;
	
	var html='';
	
	
	
	if (id==0) {
    //html+='p'+id+'<br />';
    html+='<input type="hidden" name="p['+id+'][title]" value="'+(value?val_title:'')+'" />';
    html+='<input type="hidden" name="p['+id+'][degree]" value="'+(value?val_degree:'')+'" />';
    html+='<input type="hidden" name="p['+id+'][first_name]" value="'+(value?val_first_name:'')+'" />';
    html+='<input type="hidden" name="p['+id+'][last_name]" value="'+(value?val_last_name:'')+'" />';
    html+='<input type="hidden" name="p['+id+'][year_of_birth]" value="'+(value?val_year_of_birth:'')+'" />';
    html+='<input type="hidden" name="p['+id+'][position]" value="'+(value?val_position:'')+'" />';
    html+='<input type="hidden" name="p['+id+'][task]" value="'+(value?val_task:'')+'" />';
    html+='<input type="hidden" name="p['+id+'][employees]" value="'+(value?val_employees:'')+'" />';
	}
	else {
    html+='<div>';
    //html+='p'+id;
    html+='	Anrede'+(mt?mt_title:'')+'<br />';
    html+='	<select name="p['+id+'][title]">';
    html+='		<option value="">bitte w&auml;hlen</option>';
    html+='		<option value="Frau"'+(value?(val_title=='Frau'?' selected':''):'')+'>Frau</option>';
    html+='		<option value="Herr"'+(value?(val_title=='Herr'?' selected':''):'')+'>Herr</option>';
    html+='	</select>';
    html+='</div>';
    html+='<div>Titel'+(mt?mt_degree:'')+'<br /><input type="text" name="p['+id+'][degree]" value="'+(value?val_degree:'')+'" class="text" /></div>';
    html+='<div>Vorname'+(mt?mt_first_name:'')+'<br /><input type="text" name="p['+id+'][first_name]" value="'+(value?val_first_name:'')+'" class="text" /></div>';
    html+='<div>Familienname'+(mt?mt_last_name:'')+'<br /><input type="text" name="p['+id+'][last_name]" value="'+(value?val_last_name:'')+'" class="text" /></div>';
    html+='<div>Geburtsjahr'+(mt?mt_year_of_birth:'')+'<br /><input type="text" name="p['+id+'][year_of_birth]" value="'+(value?val_year_of_birth:'')+'" class="text" /></div>';
    html+='<div>Position'+(mt?mt_position:'')+'<br />';
		if (window.positions!=undefined) {
  		html+='<select name="p['+id+'][position]">';
			html+='		<option value="">bitte w&auml;hlen</option>';
  		for (var a=0;a<window.positions.length;a++) {
				html+='		<option value="'+window.positions[a]+'"'+(value?(val_position==window.positions[a]?' selected':''):'')+'>'+window.positions[a]+'</option>';
			}
  		html+='</select></div>';
		}
		html+='<div>Funktion'+(mt?mt_task:'')+'<br />';
		if (window.tasks!=undefined) {
  		html+='<select name="p['+id+'][task]">';
			html+='		<option value="">bitte w&auml;hlen</option>';
  		for (var a=0;a<window.tasks.length;a++) {
				html+='		<option value="'+window.tasks[a]+'"'+(value?(val_task==window.tasks[a]?' selected':''):'')+'>'+window.tasks[a]+'</option>';
			}
  		html+='</select></div>';
		}
    //html+='<div>Funktion'+(mt?mt_task:'')+'<br /><input type="text" name="p['+id+'][task]" value="'+(value?val_task:'')+'" class="text" /></div>';
    html+='<div>Mitarbeiteranzahl'+(mt?mt_employees:'')+'<br /><input type="text" name="p['+id+'][employees]" value="'+(value?val_employees:'')+'" class="text" /></div>';
  	html+='<a href="javascript:void(0);" onClick="javascript:remParticipant('+id+');">TeilnehmerIn entfernen</a>';
	}
	
	var participant=document.createElement('div');
	var a;
  a=document.createAttribute("id");
  a.nodeValue = 'p'+id;
  participant.setAttributeNode(a);
	participant.innerHTML=headline+html;
	
	var participants=document.getElementById('data_participants');
	participants.appendChild(participant);
}

function remParticipant() {
	var p=arguments[0];
	if (p!=0) {
  	var form=document.forms['registration'];
  	var participant=document.getElementById('p'+p);
  	var participants=document.getElementById('data_participants');
  	participants.removeChild(participant);
  	form.participants.value--;
	}
}

function updateParticipant(element) {
	var form=document.forms['registration'];
	var name=element.name;
	if (element.name.indexOf('p_')==0) {
		name=element.name.replace(/^p_/,'');
	}
	
	var participant=form['p[0]['+name+']'];
	if (participant!=undefined) {
  	participant.value=element.value;
	}
}

function initParticipants() {
	var values=typeof(arguments[0])=='object'?arguments[0]:null;
	if (values!=null) {
		for (var a in values) {
			addParticipant(values[a]);
		}
	}
}
/*
 * Form Functions STOP
 */

//-->
