$(document).ready(function () {
	
	
	//$("select[name=\"broad_category_isn\"]").change(getConcentration);
	
	jQuery(function($) {
	      $.mask.definitions['~']='[+-]';
	      //$('#phone').mask('(999) 999-9999');
	      $('#zip_code').mask('99999');
	   });

	
}
);


function getParameterByName(name) {
    var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
    return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}

function validate(obj) {
	
	if ($("input#firstname").val() == "") {
		alert("First name is blank.");
		return false;
	}
	else if ($("input#lastname").val() == "") {
		alert("Last name is blank.");
		return false;
	}
	else if ($("input#zip_code").val() == "") {
		alert("Zip Code is blank.");
		return false;
	}
	else if ($("input#email").length > 0 && !isValidEmail($("input#email").val())) {
		alert("Email address is blank or invalid.");
		return false;
	}
	else if ($("input#dayphone").val() == "") {
		alert("Phone number is blank.");
		return false;
	}
	else if ($("select#broad_category_isn").val() == "") {
		alert("Area of Interest is blank.");
		return false;
	}
	else if ($("select#broad_category_isn").val() == "") {
		alert("Area of Interest is blank.");
		return false;
	}
	//else if (!$("input#agree_contact").attr("checked")) {
	//	alert("You must agree to be contacted at the telephone provided by a representative regarding education opportunities.");
	//	return false;
	//}
	else if (!$("input#agree_privacy").attr("checked")) {
		alert("You must acknowledge that you have read the privacy policy, understand it, and agree to be bound by the privacy policy.");
		return false;
	}
	else {
		return true;
	}
	
}

function isValidEmail(str) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	   var address = str;
	   return reg.test(address);
}

function getConcentration() {
	$broad_category_isn = $("select#broad_category_isn").val();
	$("select#category_isn").html("");
	$("select#category_isn").attr('disabled', 'disabled');
	$("select#category_isn").append("<option value=\"\">Loading...</option>");
	
	$("select#degree_isn").html("");
	$("select#degree_isn").attr('disabled', 'disabled');
	$("select#degree_isn").append("<option value=\"\">-- Select One --</option>");
	
	
	if ($broad_category_isn != "") {
		$.getJSON("?action[getconcentration]=1&broad_category_isn="+$broad_category_isn, function(category) {
			$("select#category_isn").html("");
			$("select#category_isn").attr('disabled', '');
			$("select#category_isn").append("<option value=\"\">-- Select One --</option>");
			
			for (i in category) {
				$("select#category_isn").append("<option value=\""+category[i].id+"\">"+category[i].name+"</option>");
			}
		});
	}
	else {
		$("select#category_isn").html("");
		$("select#category_isn").attr('disabled', '');
		$("select#category_isn").append("<option value=\"\">-- Select One --</option>");
	}
}
