function init(){
	document.getElementById("logDiv").innerHTML = "init()";
	window.appManager = new AppManager();
	
	// Custom validation functions
	function dateOfMarriage(){
		var mStat = this.form.marital_status.value;
		if(mStat == "Married" || mStat == "Re-married")
			if(!this.value)
				return appManager.getCurrentTab().getDescription(this) + " is required for your " + appManager.getCurrentTab().getDescription(this.form.marital_status);
		return null;
	};

	function checkEmail(){
        var email = this.value
		if( email ){
            var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
            if( reg.test(email) ) {
               return null;
            }
        }   
        return "A valid " + appManager.getCurrentTab().getDescription(this) + " is required";
	};

	function baptismInfo(){
		if(this.form.baptized.checked && !this.value)
			return appManager.getCurrentTab().getDescription(this) + " is required";
		return null;
	};

	function testimonyInfo(){
		if(this.form.personal_relationship[0].checked && !this.value)
			return appManager.getCurrentTab().getDescription(this) + " is required for your " + appManager.getCurrentTab().getDescription(this.form.personal_relationship[0]);
		return null;
	};

	function vvvInfo(){
		if(this.form.values_vision_views[1].checked && !this.value)
			return appManager.getCurrentTab().getDescription(this) + " is required for your " + appManager.getCurrentTab().getDescription(this.form.values_vision_views[0]);
		return null;
	};

	function radioReq(){
		var items = this.form.elements[this.name];
		if( items != null && items.length ){
			for (var j = 0; j < items.length; j++) {
				if(items[j].checked)
					return null;
			}
			return appManager.getCurrentTab().getDescription(this) + " is required";
		}else{
			if(!this.checked)
				return appManager.getCurrentTab().getDescription(this) + " is required";
		}
		
		return null;
	};
	
	function submitStart(){
		var elem = document.getElementById('resumeButton');
		return clickButton(elem, 'resume');
	};
	
	function submitNext(){
		var elem = document.getElementById('nextButton');
		return clickButton(elem, 'next');
	};
	
	// Tab Definitions
	var start = new Tab('start', 'Start');
	start.submitter = submitStart;
	appManager.addTab( start );
	
	var step1 = new Tab('step1', 'Personal');
	step1.setRequired(['first_name','last_name','dob','email','address','city','state','zip','home_phone']);
	step1.setDescription('first_name','First Name');
	step1.setDescription('last_name','Last Name');
	step1.setDescription('email','Email');
	step1.setDescription('dob','Date of Birth');
	step1.setDescription('address','Address');
	step1.setDescription('city','City');
	step1.setDescription('state','State');
	step1.setDescription('zip','Zip');
	step1.setDescription('home_phone','Home Phone');
	step1.setValidator('email', checkEmail);
	step1.submitter = submitNext;
	appManager.addTab( step1 );

	var step2 = new Tab('step2', 'Family');
	step2.setRequired(['marital_status']);
	step2.setDescription('marital_status','Marital Status');
	step2.setDescription('dom','Date of Marriage');
	step2.setValidator('dom', dateOfMarriage);
	step2.submitter = submitNext;
	appManager.addTab( step2 );
	
	var step3 = new Tab('step3', 'Faith');
	step3.setRequired(['baptized']);
	step3.setDescription('personal_relationship','Relationship Status');
	step3.setDescription('testimony_before','Testimony Before');
	step3.setDescription('testimony','Testimony');
	step3.setDescription('testimony_after','Testimony After');	
	step3.setDescription('baptized','Baptism Status');
	step3.setDescription('baptism_info','Baptism Information');
	step3.setValidator('personal_relationship', radioReq);
	step3.setValidator('testimony_before', testimonyInfo);
	step3.setValidator('testimony', testimonyInfo);
	step3.setValidator('testimony_after', testimonyInfo);
	step3.setValidator('baptism_info', baptismInfo);
	step3.submitter = submitNext;
	appManager.addTab( step3 );
	
	var step4 = new Tab('step4', 'Values');
	step4.setDescription('read_values','Read Values');
	step4.setDescription('read_vision','Read Vision');
	step4.setDescription('read_views','Read Views');
	step4.setDescription('values_vision_views','Understanding of Values');
	step4.setDescription('values_vision_views_questions','Questions on Values');
	step4.setRequired(['read_values','read_vision','read_views']);
	step4.setValidator('values_vision_views', radioReq);
	step4.setValidator('values_vision_views_questions', vvvInfo);
	step4.submitter = submitNext;
	appManager.addTab( step4 );
	
	var step5 = new Tab('step5', 'Church');
	step5.setDescription('began_attending_bcc','Began Attending BCC');
	step5.setDescription('support_ministry','Support Ministry');
	step5.setDescription('accountable','Be Accountable');
	step5.setDescription('initials','Initials');
	step5.setRequired(['support_ministry','accountable','initials','began_attending_bcc','connecting_point']);
	appManager.addTab( step5 );
	
	appManager.addTab( new Tab('complete', 'Complete') );
							
	appManager.writeBreadcrumbs('tabs');
	_showTab( appManager.getCurrentTabName() );
}

window.onload = function(){
	init();
}


