function validate2(e){
  $('line_index').value = FamilyInfo.line_index;
  $('num_child').value = FamilyInfo.child_numb;
  var keycode;
	if (e.keyCode){
		code = e.keyCode;
	}
	else if (e.which){
		code = e.which;
	}
	if(code == 13 && FamilyInfo.validate()) {
		document.frmAffIndQuote.submit()
	}
}

var FamilyInfo = {
	line_index:    0,
	child_numb:    0,
	// as we have limited form elements we can't use stack, so we use array
	elements:      Array(6),
	xml:           '<?xml version="1.0"?><thrive></thrive>',
applicant_row: '',

spouse_row:	'',
			    
children_row: '',

row_style:     'resultrow1',
	
add_spouse: function() {
	// index incrementation
	this.line_index++;				
	
	this.elements[0] = 1;
	
	// content display on
	ShowContent('family_info_2')
	document.getElementById('edit-relation_2').value = 'spouse';
	
	// 'Add Spouse' button display 'off'
	if($(('spouse_cell_id'))){
		document.getElementById('spouse_cell_id').innerHTML = "&nbsp;"
	}
},
   				   
add_children: function() {
	for (j=1; j < 6; j++){
		if (this.elements[j] == 0 || this.elements[j] == ''){
			// index incrementation
			this.line_index++;
			this.child_numb++;
			
			// content display 'on'
			ShowContent('family_info_'+(j+2))
			document.getElementById('edit-relation_'+(j+2)).value = 'child';
			this.elements[j] = 1;
			break;
		}
	}
	
	// 'Add Child' button display 'off'
	if(this.child_numb == 5){
		document.getElementById('child_cell_id').innerHTML = "&nbsp;"
	}
},

// Display 'on' specified child fildset (used by 'on_load' function only)
show_children: function(index) {
	this.child_numb++;
	ShowContent('family_info_'+index);
	this.elements[(index-2)] = 1;
	
	// 'Add Child' button display 'off'
	if(this.child_numb == 5){
		document.getElementById('child_cell_id').innerHTML = "&nbsp;"
	}
},
   				   			   
delete_line: function(index, member_type){
	if(confirm('Are you sure you want to delete this record ?')){
		// indexes decrementation
		this.line_index--;
		if(member_type == 'child'){
			this.child_numb--;
		}
		
		this.elements[(index-2)] = 0;
		
		// content display 'off'
		ShowContent('family_info_'+index)
		document.getElementById('edit-relation_'+index).value = '';
		
		// 'Add Spouse' button display 'on'
		if(member_type == 'spouse'){
			document.getElementById('spouse_cell_id').innerHTML = '<a class="button btn-addspouse" href="javascript:FamilyInfo.add_spouse();"><span style="display: none;">Add Spouse</span></a>'
		}
		// 'Add Child' button display 'on'
		if (this.child_numb < 5){
			document.getElementById('child_cell_id').innerHTML = '<a class="button btn-addchild" href="javascript:FamilyInfo.add_children();"><span style="display: none;">Add Child</span></a>';
		}
	}
},

// this function used for enabling form elements after form submission
on_load: function(){
	for(x=0; x<6; x++){
		this.elements[x] = '';
	}
	
	// check for enabled spouse fields
	if (document.getElementById('edit-relation_2').value != '') {
		this.add_spouse();
	}
	
	// check for enabled child fields
	for(j=3; j <= 7; j++){
		if (document.getElementById('edit-relation_'+j).value != '') {
			this.show_children(j);
		}
	}
}

}
			