$(document).ready(function() {

				var idAlready = false;
	
				$('#idSelect').change(function() {
					if($(this).val() == '-1' && !idAlready) {
						var html = '<div class="label" remove="idOther">&nbsp;</div>'
					             + '<div class="control" remove="idOther"><input type="text" name="othersId" value="Please specify ... " /></div>';
						$(this).parent().after(html);
						idAlready = true;
					}
					else if($(this).val() != '-1' && idAlready) {
						$('*[remove="idOther"]').remove();
						idAlready = false;
					}
				});
	
				var othersAlready = false;
	
				$('#raceSelect').change(function() {
					if($(this).val() == '-1' && !othersAlready) {
						var html = '<div class="label" remove="raceOther">&nbsp;</div>'
					             + '<div class="control" remove="raceOther"><input type="text" name="othersSex" value="Please specify ... " /></div>';
						$(this).parent().after(html);
						othersAlready = true;
					}
					else if($(this).val() != '-1' && othersAlready) {
						$('*[remove="raceOther"]').remove();
						othersAlready = false;
					}
				});
				
				var specialAlready = false;
				
				$('#specialz').change(function() {
					if($(this).val() == '-1' && !specialAlready) {
						var html = '<div class="label" remove="specOther">&nbsp;</div>'
					             + '<div class="control" remove="specOther"><input type="text" name="othersSpecial" value="Please specify ... " /></div>';
						$(this).parent().after(html);
						specialAlready = true;
					}
					else if($(this).val() != '-1' && specialAlready) {
						$('*[remove="specOther"]').remove();
						specialAlready = false;
					}
				});
				
				var familyAlready = false;
				
				$('input[name="application.family"]').change(function() {
					if($(this).val() == 'Yes' && !familyAlready) {
						var html = '<div class="label" remove="famOther">&nbsp;</div>'
					             + '<div class="control" remove="famOther"><input type="text" name="familyYes" value="Please specify ... " /></div>';
						$(this).parent().after(html);
						familyAlready = true;
					}
					else if($(this).val() != 'Yes' && familyAlready) {
						$('*[remove="famOther"]').remove();
						familyAlready = false;
					}
				});
				
				var itemEduCount = 0;
				
				$('#addEduBtn').click(function() {
					var delentry = "/media/image/delentry.png";
					var html = '<div class="label" id="labelEdu'+itemEduCount+'" style="display:none">'
							 +	'<input id="inputLabelEdu'+itemEduCount+'" type="text" value="Custom Field" name="key' + itemEduCount + '"/>'
							 +	'</div>'
							 +	'<div class="control" id="controlEdu'+itemEduCount+'" style="display:none">'
							 +		'<textarea name="value' + itemEduCount + '"></textarea>'
							 +		'<div class="remove" id="removeEdu'+itemEduCount+'" style="display:none"><img src = '+delentry+ ' /></div>'
							 +	'</div>'
							 +	'<div class="clear" id="clearEdu'+itemEduCount+'"></div>';
					
					
					$('#eduItemAddHere').before(html);
					$('#labelEdu'+itemEduCount).slideDown('fast');
					$('#controlEdu'+itemEduCount).slideDown('fast');
					$('#removeEdu'+itemEduCount).slideDown('fast');

					$("#inputLabelEdu" + itemEduCount).get(0).labelValue = 'Custom Field';

					$("#inputLabelEdu" + itemEduCount).bind("focus", function() {
						if(this.value=='Custom Field') this.value = "";
					});
					$("#inputLabelEdu" + itemEduCount).bind("blur", function() {
						if(this.value=='') this.value = "Custom Field";
					});
					
					//bindEduLabelEventHandler(itemEduCount);
					
					$('#removeEdu'+itemEduCount).click(function() {
						var itemid = $(this).attr('id').substring(9);
						$('#labelEdu'+itemid).slideUp('fast').remove();
						$('#controlEdu'+itemid).slideUp('fast').remove();
						$('#clearEdu'+itemid).slideUp('fast').remove();
						$(this).remove();
					});
					
					itemEduCount++;
					
					function bindEduLabelEventHandler(itemEduId) {
						$('#labelEdu'+itemEduId).click(function() {
							var itemid = $(this).attr('id').substring(8);
							var tmp = $(this).text();
							$(this).empty().append('<input id="inputLabelEdu'+itemid+'" type="text" value="'+tmp+'" />');
							$('#inputLabelEdu'+itemid).focus();
							$(this).unbind('click');

							$('#inputLabelEdu'+itemid).blur(function() {
								action($(this));
							});
							$('#inputLabelEdu'+itemid).keyup(function(e) {
								if(e.keyCode==27 || e.keyCode==13)
									action($(this));
							});
							
							function action(element) {
								var itemid = element.attr('id').substring(13);
								var tmpVal = element.val(); // .trim();
								if(tmpVal == '') {
									tmpVal = 'Custom Field';
								}
								element.parent().empty().append(tmpVal);
								bindEduLabelEventHandler(itemid);
							}
						});
					}
					
				});
				
				var itemEmpCount = 1;
				
				$('#addEmpBtn').click(function() {
					itemEmpCount++;
					$('#empHistDiv').children('div').each(function() {
						var cloneDiv = $(this).clone();
						//alert(cloneDiv.attr('skip'));
						if(cloneDiv.attr('skip') == null) {
							cloneDiv.find('*[name]').each(function() {
								var newName = $(this).attr('name') + itemEmpCount;
								$(this).attr('name', newName);
							});
							cloneDiv.find('*[id]').each(function() {
								var newId = $(this).attr('id') + itemEmpCount;
								$(this).attr('id', newId);
							});
							cloneDiv.attr('close',itemEmpCount);
							cloneDiv.attr('skip','true');
							
							$('#empItemAddHere').before(cloneDiv);
						}
						
					});
					var closeBtn = '<div class="label" close="'+itemEmpCount+'" skip="true">&nbsp;</div>'
								 + '<div class="control" close="'+itemEmpCount+'" skip="true">'
								 + '<img src="/media/image/delentry.png" id="close'+itemEmpCount+'" class="closeEmpHist" />'
								 + '</div>';
					$('#empItemAddHere').before(closeBtn);
					$('#empItemAddHere').before('<div class="clear" close="'+itemEmpCount+'" skip="true">&nbsp;</div>');
					$('#close' + itemEmpCount).click(function() {
						var id = $(this).attr('id').substring(5);
						$('div[close="'+id+'"]').slideUp();
					});
					
				});
				
	
    var langCount = 0;
    $('#addLangBtn').click(function() {
    	var html = '<div class="clear" langClose="'+ langCount +'">&nbsp;</div>'
    	           +'<div class="label" langClose="'+ langCount +'">Languages</div>'
                   +'<div class="control" langClose="'+ langCount +'"><input type="text" class="col3" /> '
                   +'<select class="col3">'
                   +'<option>Spoken</option>'
                   +'<option>Written</option>'
                   +'</select> 		<select class="col3">'
                   +'<option>Basic</option>'
                   +'<option>Pro</option>'
                   +'</select></div>'
                   +'<div class="label" langClose="'+ langCount +'">&nbsp;</div>'
                   +'<div class="control" langClose="'+ langCount +'"><button id="delLangBtn'+ langCount +'" type="button"><img alt="" src="/media/image/delentry.png" /></button></div>';
                   
        
        $('#addLangHere').before(html);
        $('#delLangBtn' + langCount).click(function() {
        	var index = $(this).attr('id').substring(10);
        	$('*[langClose="'+index+'"]').remove();
        });
        langCount++;
    });
				
			var mh = $('#siteDesc').height() - $('#desc').height();
				$('#siteDesc').css('position','relative');
				$('#desc').css('position','relative');
				$('#desc').css('top',(mh/2)-10);
			});

