var auth = 0;
var root = 0;
var defer = 0;

function setdefer(val) {
	defer = val;
}
function result () {
	if (defer) {
		window.open ("defer" + defer + ".html", "result", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=450,height=225,z-lock=0,titlebar=1");
		defer = 0;
		return;
	}
	var fields = form.elements.length;
	var counter = 0;
	var getstr = new String ();
	do {
		name = escape (form.elements[counter].name);
		val = escape (form.elements[counter].value);
		getstr = getstr + name + "=" + val + "&";
		counter ++
	} while (counter < fields);
	
	getstr = getstr.slice (0, getstr.length - 1);
	window.open ("res"+step+".php?"+getstr, "result", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=400,height=195,z-lock=0,titlebar=1");
}

function feedback () {
	window.open ("feedback.html", "feedback", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=350,height=300,z-lock=0,titlebar=1");
}

function explain(question) {
	window.open ("answers/" + question + ".html", question, "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=500,height=350,z-lock=0,titlebar=1");
}

function lostpassword() {
	window.open ("answers/lostpassword.html", "lostpassword", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=300,height=130,z-lock=0,titlebar=1");
}

function save (where) {
	window.open ("save/" + where + ".html", where, "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=500,height=350,z-lock=0,titlebar=1");
}

function walkthrough () {
	window.open ("walkthrough/form1.html", "walkthrough", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=620,height=350,z-lock=0,titlebar=1");
}

function localauth() {
	if (auth == 0) {
		window.open ("authorities.html", "authorities", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=400,height=180,z-lock=0,titlebar=1");
	}
}

function box (url) {
	window.open (url, "newwindow", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=400,height=335,z-lock=0,titlebar=1");
}

function updateform () {
	var tempval = 0;
	var store;
	store = new String (document.location);
	store = store.split ("?")[1];
	root = Number (document.form.miles.value);
	
	if (store == "air") {
		if (root < 1000) {
			tempval = Number (window.opener.document.form.airshorthaul.value);
			root *= Number (document.form.notravelling.value);
			tempval += root;
			window.opener.document.form.airshorthaul.value = String (tempval);
	
			tempval = Number (window.opener.document.form.airtotal.value);
			tempval += root;
			window.opener.document.form.airtotal.value = String (tempval);
		} else if (root < 2550) {
			tempval = Number (window.opener.document.form.airmedhaul.value);
			root *= Number (document.form.notravelling.value);
			tempval += root;
			window.opener.document.form.airmedhaul.value = String (tempval);
	
			tempval = Number (window.opener.document.form.airtotal.value);
			tempval += root * 2;
			window.opener.document.form.airtotal.value = String (tempval);
		} else {
			tempval = Number (window.opener.document.form.airlonghaul.value);
			root *= Number (document.form.notravelling.value);
			tempval += root;
			window.opener.document.form.airlonghaul.value = String (tempval);
			
			tempval = Number (window.opener.document.form.airtotal.value);
			tempval += root * 2;
			window.opener.document.form.airtotal.value = String (tempval);
		}
	} else {
		tempval = Number (eval ("window.opener.document.form." + store + ".value"));
		tempval += root;
		eval ("window.opener.document.form." + store + ".value = String (tempval)");
	}

	if (confirm ("Do you wish to add any more journeys?")) {
	} else {
		window.close();
	}
}


function updatemain () {
	var tempval = 0;
	var store;
	store = new String (document.location);
	store = store.split ("?")[1];
	root = mapdist;
	if (store == "air") {
		if (root < 500) {
			tempval = Number (window.opener.document.form.airshorthaul.value);
			root = root - root % 1;
			root *= Number (document.form.notravelling.value);
			tempval += root * 2;
			window.opener.document.form.airshorthaul.value = String (tempval);
	
			tempval = Number (window.opener.document.form.airtotal.value);
			tempval += root * 2;
			window.opener.document.form.airtotal.value = String (tempval);
		} else if (root < 1250) {
			tempval = Number (window.opener.document.form.airmedhaul.value);
			root = root - root % 1;
			root *= Number (document.form.notravelling.value);
			tempval += root * 2;
			window.opener.document.form.airmedhaul.value = String (tempval);
	
			tempval = Number (window.opener.document.form.airtotal.value);
			tempval += root * 2;
			window.opener.document.form.airtotal.value = String (tempval);
		} else {
			tempval = Number (window.opener.document.form.airlonghaul.value);
			root = root - root % 1;
			root *= Number (document.form.notravelling.value);
			tempval += root * 2;
			window.opener.document.form.airlonghaul.value = String (tempval);
			
			tempval = Number (window.opener.document.form.airtotal.value);
			tempval += root * 2;
			window.opener.document.form.airtotal.value = String (tempval);
		}
	} else {
		tempval = Number (eval ("window.opener.document.form." + store + ".value"));
		root = root - root % 1;
		root *= Number (document.form.notravelling.value);
		tempval += root * 2;

		eval ("window.opener.document.form." + store + ".value = String (tempval)");
	}

	if (confirm ("Do you wish to add any more journeys?")) {
	} else {
		window.close();
	}
}

function setauth(auth) {
	window.opener.document.form.authority.value = auth;
	window.opener.auth = 1;
	window.close();
}

function dispincome() {
	var val = new String (document.form.cmpincome.checked);
	if (val.charAt(0) == "t") {
		window.open ("income.html", "newwindow", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=400,height=195,z-lock=0,titlebar=1");
	} else {
		document.form.income.value = "0";
	}
}

function updateincome() {
	window.opener.document.form.income.value = document.form.income.selectedIndex + 1;
}