function howElseShow() {
	if($("#how").val() == 'else') {
		$("#how_else").show();
		$("howElse").addClass('required');
	}
	else {
		$("#how_else").hide();
		$("howElse").removeClass('required');
	}
}

var intHistoryCount = 0;
function addHistory(n) {
	/*
	history_employer
	history_function
	
	history_start_day
	history_start_month
	history_start_year
	
	history_end_day
	history_end_month
	history_end_year
	*/
	if(intHistoryCount == 0 && n) intHistoryCount = 1;
	arrFormFields = ['#history_employer_0','#history_function_0','#history_start_day_0','#history_start_month_0','#history_start_year_0','#history_end_day_0','#history_end_month_0','#history_end_year_0']
	
	var blnFilled = true;
	jQuery.each(arrFormFields, function(index, value) {
		//console.log($(value).val());
		if($(value).val() == '') blnFilled = false;
	});
	
	if(blnFilled) {
		if(intHistoryCount == 0) {
			var strHtml = '<tr>';
			strHtml += '	<th>Werkgever</th>';
			strHtml += '	<th>Functie</th>';
			strHtml += '	<th>Van</th>';
			strHtml += '	<th>Tot</th>';
			strHtml += '	<th></th>';
			strHtml += '</tr>';
		}
		else var strHtml = '';
		
		intHistoryCount++;
		strHtml += '<tr >';
		strHtml += '	<td>'+$('#history_employer_0').val()+'<input type="hidden" name="history_employer[]" value="'+$('#history_employer_0').val()+'" /></td>';
		strHtml += '	<td>'+$('#history_function_0 :selected').text()+'<input type="hidden" name="history_function[]" value="'+$('#history_function_0').val()+'" /></td>';
		strHtml += '	<td>';
		strHtml += '		'+$('#history_start_day_0').val()+'-'+$('#history_start_month_0').val()+'-'+$('#history_start_year_0').val();
		strHtml += '		<input type="hidden" name="history_start_day[]" value="'+$('#history_start_day_0').val()+'" />';
		strHtml += '		<input type="hidden" name="history_start_month[]" value="'+$('#history_start_month_0').val()+'" />';
		strHtml += '		<input type="hidden" name="history_start_year[]" value="'+$('#history_start_year_0').val()+'" />';
		strHtml += '	</td>';
		strHtml += '	<td>';
		strHtml += '		'+$('#history_end_day_0').val()+'-'+$('#history_end_month_0').val()+'-'+$('#history_end_year_0').val();
		strHtml += '		<input type="hidden" name="history_end_day[]" value="'+$('#history_end_day_0').val()+'" />';
		strHtml += '		<input type="hidden" name="history_end_month[]" value="'+$('#history_end_month_0').val()+'" />';
		strHtml += '		<input type="hidden" name="history_end_year[]" value="'+$('#history_end_year_0').val()+'" />';
		strHtml += '	</td>';
		strHtml += '	<td><a href="" onclick="$(this).parent().parent().remove();return false;">x</a></td>';
		strHtml += '</tr>';
	
		jQuery.each(arrFormFields, function(index, value) {
			$(value).val('');
		});
		
		//console.log(strHtml);
		$("#history table").append(strHtml);
		
	}
}

function inputLengthCheck(e, n, des, size) {
	strInput = n.value;

	if (!e) var e = window.event;
  
	//9 = TAB, 16 = SHIFT
	if (e.keyCode == 9) {
		return false;    
	}

	if ((e.shiftKey && e.keyCode == 9) || e.keyCode == 16) {
		return false;
	} else if(strInput.length >= size) { 
		try {
			$('#'+des).focus();
		} catch(e) {
		}
	}
	return true;
}


function checkEndDate(type) {
	switch(type) {
		case 'day':
			if($("select#history_end_day_0").val() == '') {
				strValue = $('select#history_start_day_0').val();
				$("select#history_end_day_0 option[value="+strValue+"]").attr("selected", "selected");	
			}
			break;
		case 'month':
			if($("select#history_end_month_0").val() == '') {
				strValue = $('select#history_start_month_0').val();
				$("select#history_end_month_0 option[value="+strValue+"]").attr("selected", "selected");	
			}
			break;
		case 'year':
			if($("select#history_end_year_0").val() == '') {
				strValue = $('select#history_start_year_0').val();
				$("select#history_end_year_0 option[value="+strValue+"]").attr("selected", "selected");	
			}
			break;
	}
}

