var cur = 1;
var numsteps = 10;
var type = '';

var types = new Array();
types[1] = "First Year";
types[2] = "Returning";
types[3] = "Transfer";
types[4] = "BJ-1 Year";
types[5] = "Non-King's";

var textFields = new Array();
textFields['university'] 				= "Please enter the university you will be attending\n";
textFields['credits']					= "Please enter how many credit hours you have completed\n";
textFields['first_name']				= "Please enter your first name.\n";
textFields['last_name']					= "Please enter your last name.\n";
textFields['student_id']				= "Please enter your student id.\n";
textFields['mailing_street_add']		= "Please enter your street address.\n";
textFields['mailing_city']				= "Please enter your home city.\n";
textFields['mailing_code']				= "Please enter your home postal code.\n";
textFields['mailing_province']			= "Please enter your home province.\n";
textFields['mailing_country']			= "Please enter your home country.\n";
textFields['birthdate_month']			= "Please enter your month of birth.\n";
textFields['birthdate_day']				= "Please enter your day of birth.\n";
textFields['birthdate_year']			= "Please enter your year of birth.\n";
textFields['area_code']					= "Please enter your area code.\n";
textFields['phone_number']				= "Please enter your phone number.\n";
textFields['email_address']				= "Please enter your NetID.\n";
textFields['nk_email_address']			= "Please enter your email address.\n";
textFields['emergency_name']			= "Please enter your emergency contact name.\n";
textFields['emergency_relationship']	= "Please enter your emergency contact relationship.\n";
textFields['emergency_area_code']		= "Please enter your emergency contact area code.\n";
textFields['emergency_phone_number']	= "Please enter your emergency contact phone number.\n";

var radioFields = new Array();
radioFields['degree'] 				= "Please specify the degree you are enrolled in.\n";
radioFields['year']					= "Please specify your year of study.\n";
radioFields['fyp']					= "Please specify whether or not you will be enrolling in the Foundation Year Programme.\n";
radioFields['sex']					= "Please specify your gender.\n";
radioFields['coed_rank']			= "Please specify co-ed ranking.\n";
radioFields['male_rank']			= "Please specify male ranking.\n";
radioFields['female_rank']			= "Please specify female ranking.\n";
radioFields['share_info']			= "Please specify if you are willing to share your phone number.\n";
radioFields['share_email_info']		= "Please specify if you are willing to share your email address.\n";
radioFields['mealplan'] 			= "Please specify the mealplan you desire.\n";
radioFields['emergency_permission']	= "Please specify if we may contact your emergency contact in the event of an emergency situation.\n";

function checkFields(fields) {
	var msg = '';
	
	for (key in textFields) {
		if (isIn(key,fields)) {
			if (document.getElementById(key).value == '') {
				msg+= textFields[key];
				isError(key);
			}
		}
	}
	for (key in radioFields) {
		if (isIn(key,fields)) {
			eval ('if (!getRadioValue(document.application.'+key+')) msg+= radioFields[key]');
			eval ('if (!getRadioValue(document.application.'+key+')) setStyle(document.getElementById("div_"+key),\'error\');');
		}
	}
	
	return msg;
}

function isError(id) {
	setStyle(document.getElementById(id),'error');
	setStyle(document.getElementById("div_"+id),'error');
}

function selectType(id) {
	document.getElementById("student_type"+id).checked = true;
}
function selectMealplan(id) {
	document.getElementById("mealplan"+id).checked = true;
}

function clearErrors() {
	for (key in textFields) {
		setModified(key);
	}
	for (key in radioFields) {
		if (document.getElementById("div_"+key)) setStyle(document.getElementById("div_"+key),'');
	}
}

function setModified(el) {
	if (document.getElementById(el)) 			setStyle(document.getElementById(el),'');
	if (document.getElementById("div_"+el)) 	setStyle(document.getElementById("div_"+el),'');
}

function gotoStep (step) {
	scroll(0,0);
	
	if (step==1) {
		hide("feeschedule");
	} else {
		show("feeschedule");	
	}

	if (step==5 && type!=1&&type!=3&&type!=5) {
		if (cur<step) step=6;
		if (cur>step) step=4;
	}	
	
	
	/* // commented out by jonathan@momentum
	if (type==4) {
		hide('step2');
		if (step==2) {
			if (cur<step) step=3;
			if (cur>step) step=1;
		}	
	} else {
		show('step2');	
	}
	*/
	
	
	if (type==1 || type==3 || type==5) {
		show('step5');
	} else {
		hide('step5');
	}
	
	cur = step;
	
	hideAll();
	show("div_step"+step);
	
	setStyle(document.getElementById("step"+step),'on');
	document.getElementById("step"+step).onclick = '';
	
	for (var i=step-1;i>0;i--) {
		eval('document.getElementById("step"+i).onclick = function() { gotoStep('+i+') }');
		setStyle(document.getElementById("step"+i),'back');
	}
	
	for (var i=step+1;i<=numsteps;i++) {
		document.getElementById("step"+i).onclick = '';
		setStyle(document.getElementById("step"+i),'off');
	}
	
	eval('if (window.setupStep'+step+') setupStep'+step+'();');
	clearErrors();
}

function nextStep() {
	gotoStep(cur+1);
}

function lastStep() {
	gotoStep(cur-1);
}

function hideAll() {
	for (var i=1;i<=numsteps;i++) hide("div_step"+i);
}

function popupFees() {
	window.open('docs/'+fslink[type],'popupFeeSchedule','resizable=1,scrollbars=1,width=700,height=550,top=60,left=60')
}

function browserinit() {
	if (BrowserDetect.OS!="Windows"||BrowserDetect.Browser=="Safari") {
		show('divpolicies');
		show('divguidelines');
		show('divfeesched');
		hide('feesched');
		hide('policies');
		hide('guidelines');
	}
	
	if (BrowserDetect.OS=="Windows"&&BrowserDetect.Browser=="Safari") {
		alert("This application is not compatible with Safari for windows, please use Internet Explorer or Firefox.");
		hide('search_container');
		hide('theapplication');
	}
}


