$(document).ready(function() {
	$("#FeaturedCity").click(function() {
		var occupationId = $("#Occupation").val();
		var occupation = occupationID2name(occupationId);
		var url = "/" + occupation + $_SESSION['FeaturedCityUrl'];
		document.location = url;
		
		return false;
	});
	$("#postItMakeMoney").click(function() {
		//$.showAkModal('/ExtraMoney.php','TPC Hiring Bonus', 320,200);
	});
	$("#frmSearch").submit(function() {
		var occupationId = $("#Occupation").val();
		var specialtyId = $("#Specialty"+occupationId).val();

		if (occupationId==2) {
			if (specialtyId < 1) {
				alert('You must specify your allied specialty.');
				$("#Specialty"+occupationId).focus();
				return false;
			}; //if
		}; //if

		var ix = document.getElementById("Specialty"+occupationId).selectedIndex;
		var specialty = '';
		if (ix > 0) {
			specialty = document.getElementById("Specialty"+occupationId).options[ix].text;
			specialty = specialty.replace("/","-")
			specialty = specialty.replace(' ',"-");
			specialty = specialty.replace(' ',"-");
			specialty = specialty.replace(' ',"-");				
			specialty = specialty.replace("---","-");
			specialty = specialty.replace("---","-");
			specialty = specialty.replace("--","-").replace("--","-");
		}; //if

		var bTravel = $("#travel").attr("checked") == true;
		var bPerDiem = $("#perdiem").attr("checked") == true;
		var bContract = $("#contract").attr("checked") == true;
		var bPerm = $("#perm").attr("checked") == true;
		var bBeach = $("#beach").attr("checked") == true;
		var bHiking = $("#hiking").attr("checked") == true;
		var bNatPark = $("#natpark").attr("checked") == true;
		var bCompact = $("#compact").attr("checked") == true;
		var newNurseJobs = $("#newNurses").attr("checked") == true;
		var city = $("#City").val();
		var state = $("#State").val();
		if (state=='' && city!='') {
			alert('You need to specify a state when you look for a city');
			$("#State").focus();
			return false;
		}; //if

		if (bPerDiem && state == '') {
			alert('Sorry, but you cannot search for per diem without selecting a location.');
			if (bCompact) {
				$("#compact").focus();
			} else {
				$("#State").focus();
			}; //if
			return false;
		}; //if

		var url = makeUrlEx(occupationId, specialty, bPerm, bTravel, bPerDiem, bContract, bBeach, bHiking, bNatPark, bCompact, city, state, newNurseJobs);

		if (state!='' && city!='') {
			$.post('/ajax.php', {
				cmd: 'testlocation',
				city: city,
				state: state
			}, function(data) {
				if (data.Metro=="") {
					alert("Sorry but we can't find a city named " + city + ", " + state + ".");
					$("#City").focus();
				} else {
					document.location = url;
				}; //if
			}, "json");
		} else {
			// just load it
			document.location = url;
		}; //if
		
		return false;
	});
});
