var sendButtonId;
var addPersonButtonId;
var className;
var bodyId;
var sendSubmit;

try{
//alert(document.getElementsByName("tx_powermail_pi1[uid176]")[0].value);
//alert(document.body.id);
bodyId = document.body.id;

//individuelle einstellungen pro formulaer
if(bodyId == "kp-98")
{
sendButtonId = "uid175";
addPersonButtonId = "uid174";
hiddenFieldId = "uid176";
className = "anmeldunganwendertreffen";
sendSubmit = document.anmeldunganwendertreffen;
}
else if (bodyId == "kp-62")
{
sendButtonId = "uid172";
addPersonButtonId = "uid169";
hiddenFieldId = "uid171";
className = "anmeldungseminare";
sendSubmit = document.anmeldungseminare;
}
else if (bodyId == "kp-97")
{
sendButtonId = "uid180";
addPersonButtonId = "uid179";
hiddenFieldId = "uid177";
className = "anmeldungerfanord";
sendSubmit = document.anmeldungerfanord;
}
else if (bodyId == "kp-96")
{
sendButtonId = "uid184";
addPersonButtonId = "uid183";
hiddenFieldId = "uid181";
className = "anmeldungerfawest";
sendSubmit = document.anmeldungerfawest;
}
else if (bodyId == "kp-64")
{
sendButtonId = "uid188";
addPersonButtonId = "uid187";
hiddenFieldId = "uid185";
className = "anmeldungerfasued";
sendSubmit = document.anmeldungerfasued;
}
else if (bodyId == "kp-95")
{
sendButtonId = "uid192";
addPersonButtonId = "uid191";
hiddenFieldId = "uid189";
className = "anmeldungerfaost";
sendSubmit = document.anmeldungerfaost;
}

//bereits eingegebene daten wieder in das Formular schreiben
var str = document.getElementsByName("tx_powermail_pi1["+hiddenFieldId+"]")[0].value;
var splitStr;
var limit = 7;
var subSplitStr =new Array()
if(document.getElementsByName("tx_powermail_pi1["+hiddenFieldId+"]")[0].value != "leer" || document.getElementsByName("tx_powermail_pi1["+hiddenFieldId+"]")[0].value != "")
{
	splitStr = str.split("$");

	

	for (i=0;i<splitStr.length;i++ )
	{
   	 	subSplitStr[i] = splitStr[i].split("§");
   	 	//alert(subSplitStr[i]);
   	 	//alert(i+" " +limit);
		if(i==limit)
		{
			window.setTimeout("addPerson()", 5);
			limit=limit+8;
		}   	 	
	} 
	window.setTimeout("updateFields()", 50);
	//alert(subSplitStr.length);
}
}
catch(err){}

// daten in die formularfelder schreiben
function updateFields()
{
	for (i=0;i<subSplitStr.length;i++ )
	{
   	 	try
   	 	{
			//alert(document.getElementById(subSplitStr[i][0]));
			document.getElementById(subSplitStr[i][0]).value = subSplitStr[i][1];
		}
		catch(err)
		{
			//alert(err.description);
		}  	 	
	} 
	
}

var startId =505;
var lastId =startId;
var personcount = 0;
var inputid = 1; 

// aufruf beim klicken auf einen Button
function clickBtn(name)
{
	if(name=="tx_powermail_pi1["+addPersonButtonId +"]"){
		addPerson();
	}
	else{
		sendData()
	}
}

// fügt Felder für die Anmeldung einer weiteren Person hinzu
function addPerson()
{	
	personcount++;
	var inHTM = "<div id=\"pers_"+inputid+"\"> <h3>Person "+(personcount+1)+":</h3><br>";
	inHTM +=  " <input  name='tx_powermail_pi1[uid"+lastId+"]' size='10' value='Person "+(personcount+1)+"' class='powermail_"+className +" powermail_text powermail_uid"+lastId+"' id='uid"+lastId+"' tabindex='4' type='hidden'>";
	lastId++;
	inHTM +=  " <div id='powermaildiv_uid"+ lastId+"'> <label for='uid"+lastId+"'>Vorname</label><input  name='tx_powermail_pi1[uid"+lastId+"]' size='10' class='powermail_"+className +" powermail_text powermail_uid"+lastId+"' id='uid"+lastId+"' tabindex='4' type='text'></div>";
	lastId++;
	inHTM +=  " <div id='powermaildiv_uid"+ lastId+"'> <label for='uid"+lastId+"'>Name</label><input  name='tx_powermail_pi1[uid"+lastId+"]' size='10' class='powermail_"+className +" powermail_text powermail_uid"+lastId+"' id='uid"+lastId+"' tabindex='4' type='text'></div>";
	lastId++;
	inHTM +=  " <div id='powermaildiv_uid"+ lastId+"'> <label for='uid"+lastId+"'>Firma</label><input  name='tx_powermail_pi1[uid"+lastId+"]' size='10' class='powermail_"+className +" powermail_text powermail_uid"+lastId+"' id='uid"+lastId+"' tabindex='4' type='text'></div>";
	lastId++;
	inHTM +=  " <div id='powermaildiv_uid"+ lastId+"'> <label for='uid"+lastId+"'>Funktion</label><input  name='tx_powermail_pi1[uid"+lastId+"]' size='10' class='powermail_"+className +" powermail_text powermail_uid"+lastId+"' id='uid"+lastId+"' tabindex='4' type='text'></div>";
	lastId++;
	inHTM +=  " <div id='powermaildiv_uid"+ lastId+"'> <label for='uid"+lastId+"'>Telefon</label><input  name='tx_powermail_pi1[uid"+lastId+"]' size='10' class='powermail_"+className +" powermail_text powermail_uid"+lastId+"' id='uid"+lastId+"' tabindex='4' type='text'></div>";
	lastId++;
	inHTM +=  " <div id='powermaildiv_uid"+ lastId+"'> <label for='uid"+lastId+"'>E-Mail</label><input  name='tx_powermail_pi1[uid"+lastId+"]' size='10' class='powermail_"+className +" powermail_text powermail_uid"+lastId+"' id='uid"+lastId+"' tabindex='4' type='text'></div>";
	lastId++;
	inHTM +=  " <div id='powermaildiv_uid"+ lastId+"'> <label for='uid"+lastId+"'>PLZ</label><input  name='tx_powermail_pi1[uid"+lastId+"]' size='10' class='powermail_"+className +" powermail_text powermail_uid"+lastId+"' id='uid"+lastId+"' tabindex='4' type='text'></div>";
	lastId++;
	inHTM +=  " <div id='powermaildiv_uid"+ lastId+"'> <label for='uid"+lastId+"'>Ort</label><input  name='tx_powermail_pi1[uid"+lastId+"]' size='10' class='powermail_"+className +" powermail_text powermail_uid"+lastId+"' id='uid"+lastId+"' tabindex='4' type='text'></div>";
	lastId++;
	//inHTM += "<input type='button' id='' onclick='document.getElementById(\"pers_"+(inputid)+"\").innerHTML = \"\"; ' value=\"Person entfernen\"/> </div>";
	inHTM += "</div>";
	document.getElementById("input"+inputid).innerHTML += inHTM+"<div id='input"+(inputid+1)+"' >&nbsp;</div>";
	inputid++;

     	
} 

// speichert die Daten in das hiddenfield und sendet das formular ab
function sendData(){

	document.getElementsByName("tx_powermail_pi1["+hiddenFieldId+"]")[0].value="";
	for(i=505;i<lastId;i++)
	{ 
		//alert(document.getElementById("uid"+i).value);
		//alert(document.getElementById("uid"+i).value.slice(0,11));
		try{
			if(document.getElementById("uid"+i).value.slice(0,11)!="Person")
			{
				document.getElementsByName("tx_powermail_pi1["+hiddenFieldId+"]")[0].value+= document.getElementById("uid"+i).id +"§"+ document.getElementById("uid"+i).value ;
				if(i!=lastId-1)
					document.getElementsByName("tx_powermail_pi1["+hiddenFieldId+"]")[0].value+="$";
			}
		}catch(err){}
	}
	if( document.getElementsByName("tx_powermail_pi1["+hiddenFieldId+"]")[0].value == "")
		document.getElementsByName("tx_powermail_pi1["+hiddenFieldId+"]")[0].value = "leer";
	//alert(document.getElementsByName("tx_powermail_pi1["+hiddenFieldId+"]")[0].value);
	sendSubmit.submit();
}

