var subjects = {"standard":[
	"Accounting", "Advanced Immunology", "Advertising", "Aerospace Engineering", "African Studies", "Agriculture", "Animation",
	"Anthropology", "Arabic", "Archaeology", "Architecture", "Art", "Art History", "Artificial Intelligence", "Audiology",
	"Automotive Design", "Banking", "Beauty Therapy", "Bioinformatics", "Biology", "Biotechnology", "Botany", "Building Surveying",
	"Business", "Cantonese", "Chemistry", "Childcare", "Chinese", "Civil Engineering", "Classics", "Classics Communications", "Computer Science",
	"Construction", "Creative Writing", "Criminology", "Cultural Studies", "Customer Service", "Cybernetics", "Dentistry", "Design",
	"Development for Sustainability", "Disaster Studies", "Drama", "Earth System Science", "Ecommerce", "Economics", "Education","Engineering",
	"English Language", "English Literature", "Entrepreneurship and Management", "Environmental Studies", "Estate Management", "Ethnic Studies",
	"European Studies", "Fashion", "Film Studies", "Finance", "Forensic Biology", "Forensic Chemistry", "French", "Gaelic", "Genealogy",
	"General Studies", "Geography", "Geology", "German", "Governmental Studies", "Graphic Design", "Health", "Health and Medical Sciences",
	"Hebrew", "Hindi", "History", "Horticulture", "Hospitality", "Housing", "Human Geography", "Human Resources", "Human Rights", "IT",
	"Information Systems", "Internal Relations", "International Relations", "International Studies", "Italian", "Japanese", "Jewish Studies",
	"Journalism", "Languages", "Latin American Studies", "Law", "Leadership Studies", "Leisure Management", "Linguistics", "Logistics", "Management",
	"Marine Biology", "Marketing", "Mathematics", "Mechanics", "Media", "Meteorology", "Micro Biology", "Middle Eastern Studies","Midwifery","Military",
	"Motor Engineering", "Music", "Nursing", "Nutrition", "Operations Management", "Paramedic Biology", "Pharmaceutical Science", "Philosophy",
	"Photography", "Physical Education", "Physical Geography", "Physical Therapy", "Physics", "Physiology", "Plant and Soil Sciences", "Poetry",
	"Politics", "Product Design", "Project Management", "Property", "Psychology", "Public Policy", "Quantity Surveying", "Real Estate Management",
	"Religion", "Risk Management", "Rural Studies", "Sciences", "Social Policy","Social Work", "Sociology", "Software Engineering", "Spanish", "Sports",
	"Statistics", "Teaching", "Theatre", "Theology", "Tourism", "Translation", "Transport", "Typography", "Web Development", "Zoology"
],"law":[
	"Accounts", "Admiralty Law", "ADR and Mediation", "Advanced Crime", "Advanced Civil", "Advocacy", "Banking Law",
	"Business Law", "Child Law", "Civil Evidence", "Civil Procedure", "Civil Liberties", "Commercial", "Commercial Litigation",
	"Competition Law", "Conferencing", "Company Law", "Constitutional and Administrative", "Contract Law", "Comparative Law",
	"Copyright, Trademark and Patent Law", "Criminal Law", "Criminal Evidence", "Criminal Litigation", "Criminology", "Cyberlaw",
	"Data Protection and Freedom of Information", "Debt Finance", "Drafting", "Equity and Finance", "Equity &amp; Trusts",
	"Employment Law", "English Legal System", "English Legal History", "Environmental Law", "EU Law", "Family Law", "Forensic",
	"Gender and the Law", "Human Rights Law", "Immigration Law", "Insolvency Law", "International Law", "International Shipping Law",
	"IP Law", "International Trade Law", "Islamic Law", "Judicial Review", "Jurisprudence", "Land Law", "Landlord and Tenant Law",
	"Law in the City", "Legal Anthropology", "Legal Ethics", "Licensing Law", "Media Law", "Opinion Writing", "Penology",
	"PI and Clinical Negligence", "Private Acquisitions", "Private Client", "Professional Ethics", "Professional Conduct",
	"Property &amp; Chancery", "Probate", "Public International Law", "Restitution", "Shariah Law", "Tax Law", "Tort Law",
	"Roman Law", "Social Security Law", "Wills"
]}
// Delivery prices correspond to the $options['delivery'] array in the PHP file
var deliveryPrices = [1, 1.2]; // Multiply the price by this factor
//*****************************************************************************
$(document).ready(function() {
	calculatePrice();
});
// Change price if factors are changed
$("#sheets").keyup(function() {
	calculatePrice();
});
$("#delivery").change(function() {
	calculatePrice();
});
// Calculate the order total
function calculatePrice() {
	var sheets = $("#sheets").val();
	var total = 0;
	// Check user has entered an integer
	if (!isNaN(sheets) && (Math.round(sheets) == sheets)) {
		// Price per sheet (less for 5 sheets or more)
		var sheetPrice = 50;//(sheets > 5 ? 35 : 37.5);
		var delivery = deliveryPrices[$("#delivery").val()];
		total = (sheets * sheetPrice * delivery);
	}
	// Round total to nearest £0.50 if not in an integer
	var decimal = Math.round((total - parseInt(total)) * 10);
	var midway = ((parseInt(total) + 0.5) + "0");
	total = ((decimal < 3) || (decimal > 7) ? (Math.round(total) + ".00") : midway);
	// Print price
	if (isNaN(total)) total = 0;
	$("#price").html("Price: &pound;" + total);
	$("#pr").val(total);
}
//*****************************************************************************
// Change subjects list depending on the level selected
$("#level").change(function() {
	var selected = $("#level option:selected");
	var selectedVal = selected.val();
	if (selectedVal != "") {
		// Get subject list depending on if they chose a Law level or not
		var subjList = (selected.parent().attr("label").toLowerCase().indexOf("law") > -1 ? subjects.law : subjects.standard);
		disableSubject(false);
		addSubjects(subjList);
	} else {
		// If no level selected, disable subject
		$("#subject").html("");
		disableSubject(true);
	}
});
// Add list of subject options to drop-down
function addSubjects(subjList) {
	$("#subject").html(option("", "- Please Select -"));
	for (var i=0; i< subjList.length; i++) {
		var subj = subjList[i];
		$("#subject").append(option(subj, subj));
	}
}
// Disable the drop-down field
function disableSubject(disable) {
	if (disable) {
		$("#subject").attr("disabled", "disabled");
	} else {
		$("#subject").removeAttr("disabled");
	}
}
//*****************************************************************************
// Utility function for <option> HTML
function option(value, text) {
	return ('<option value="' + value + '">' + text + '</option>');
}
