﻿var nextPerson = 1;


function addPerson(){
  nextPerson++;   
  var newPerson = document.createElement('table');
  newPerson.id = 'subscriber_name_' + nextPerson;
  newPerson.className = 'subscribers';
  newPerson.border='0';
  newPerson.cellPading = '0';
  newPerson.cellSpacing = '0';
 
  var newtbody = document.createElement('tbody');
  newtbody.appendChild(addField(' ', 
		'subscriber_sex_' + nextPerson, true, ''));
		
  newtbody.appendChild(addField('Naam Deelnemer ' + nextPerson + ':', 'subscriber_name_' + nextPerson, false,
	''));
  
  newtbody.appendChild(addField(document.getElementById('em_functie').innerHTML + ' ' + nextPerson + ':', 
		'subscriber_functie_' + nextPerson, false, ''));

  newtbody.appendChild(addField(document.getElementById('em_email').innerHTML + ' ' + nextPerson + ':', 
		'subscriber_email_' + nextPerson, false, ''));
	
  newtbody.appendChild(addField(document.getElementById('em_phone').innerHTML + ' ' + nextPerson + ':', 
		'subscriber_phone_' + nextPerson, false, ''));
  
  newPerson.appendChild(newtbody);
  
  document.getElementById('subscribers').insertBefore(newPerson, document.getElementById('beforeDIV'));
  
  if(nextPerson > 1){document.getElementById('deletePerson').style.display='block';}
}

function addField(title, inputName, isDropDown, addText){
  var newTR = document.createElement('tr');
  var newTH = document.createElement('th')
  newTH.innerHTML = title;
  newTR.appendChild(newTH);
  
  var newTD = document.createElement('td')
  if (isDropDown){
	newTD.innerHTML = '<select name="' + inputName + '" class="subscribers">'+
						'<option value="de Heer">de Heer</option>' +
						'<option value="Mevrouw ">Mevrouw</option>' +
					  '</select>';	
  }else{
	newTD.innerHTML = addText +'<input type="text" name="' + inputName + '" class="subscribers"/>';
  }  
  newTR.appendChild(newTD);
  
  return newTR;
}

function checkLength(elName){
	document.getElementById(elName).value = document.getElementById(elName).value.substring(0, 4);
}

function delPerson()
{
if(nextPerson>1)
{
    document.getElementById('subscribers').removeChild(document.getElementById('subscriber_name_'+nextPerson));
    nextPerson--;
}
if(nextPerson==1){
document.getElementById('deletePerson').style.display='none';
}
}

function cleanUpForm(frm)
{
    for(var i=0; i < frm.length;i++)
    {
        if(frm[i].type=='text')frm[i].value='';
    }
}

function checkAndFill(obj)
{

var form = document.forms['eventSubscribeForm'];
if(obj[obj.selectedIndex].value)
{
    
    form.Inschrijven.removeAttribute('disabled');
    form.id.value = obj[obj.selectedIndex].value;
    form.firstDayDate.value=obj[obj.selectedIndex].getAttribute('datum');
    //form.courseName.value=obj[obj.selectedIndex].getAttribute('cursusnaam');
    //form.courseCode.value=obj[obj.selectedIndex].getAttribute('curs_code');
    //form.prijs.value=obj[obj.selectedIndex].getAttribute('prijs');
}
else{
    form.Inschrijven.setAttribute('disabled','true');
}
}

function negesoEvent(ul_id) {
	var $=jQuery;
	$('#'+ul_id+' > li > ul > li').find('a').click(
		function() {
			var li = $(this).parent();
			if ($(li).hasClass('item_over')){
				$(li).removeClass('item_over');
				$(li).find('> ul').hide();
			}else{
				$(li).addClass('item_over');
				$(li).find('> ul').show();
			}
		}
	)	
//	unbind
}



