$(document).ready(function () {
	$.ajax({
		type:"get",
		cache:false,
		url:"index.do?method=getCountrys&loadon=kk&r=" + Math.random(),
		async:false,
		processData:false,
		success:function (data) {
			$("#country").empty();
			var countrHref = $("#ctr p:first-child");
			countrHref.empty();
			var counSum = $(data).find("country").length;
			$("#country").append("<option value='0'>请选择国家</option>");
			$(data).find("country").each(function (index) {
				var id=$(this).children("id").text(); 
				var countryName=$(this).children("countryName").text();
				if (id == $("#countryId").val()) {
					$("#country").append("<option value='" + id + "' selected='selected'>" + countryName + "</option>");
				} else {
					$("#country").append("<option value='" + id + "'>" + countryName + "</option>");
				}
				if (index == (counSum -1)) {
					countrHref.append("<a href='guide.do?method=showCountryDetail&countryId="+id+"'>" + countryName + "</a>");
				} else {
					countrHref.append("<a href='guide.do?method=showCountryDetail&countryId="+id+"'>" + countryName + "</a>|");
				}
			});
		}
	});

	$("#loadonsubmit").click(function () {
		if ($("#loadon").val() == "") {
			alert("用户名不能为空！");
			$("#loadon").focus();
			return false;
		}
		if ($("#pswd").val() == "") {
			alert("密码不能为空！");
			$("#pswd").focus();
			return false;
		}
		$.ajax({
			type:"get",
			cache:false,
			url:"index.do?method=logon&loadon="+$("#loadon").val()+"&pswd="+$("#pswd").val() + "&r=" + Math.random(), 
			dataType:"json",
			processData:false,
			success:function (data) {
				if (data == 0) {// 程序出错
					alert("登陆时，程序出错！");
				} else if (data == 1) {// 用户名不存在
					alert("用户名不存在！");
				} else if (data == 2) {// 用户被冻结
					alert("该用户被冻结！");
				} else if (data == 3) {// 密码不匹配
					alert("密码不匹配！请尝试找回密码！");
				} else if (data == 10) {// 登陆成功
					window.location.href="index.do?method=findUniversitysByType&r=" + Math.random();
				}
			}
		});
	});
	
	$("#logout").click(function () {
		$.ajax({
			type:"get",
			cache:false,
			url:"login.do?method=logout" + "&r=" + Math.random(), 
			async:false,
			dataType:"json",
			processData:false,
			success:function (data) {
			//	window.location.reload();
				window.location.href="index.do?method=findUniversitysByType&r=" + Math.random();
			}
		});
	});
	
	$("#set").click(function () {
		var grade = $("input[name='grade']:checked").val();
		if (grade == null) {
			alert("您未选择要申请的学习阶段！");
			return false;
		}
		$.ajax({
			type:"get",
			cache:true,
			url:"index.do?method=chooseGrade&grade="+grade + "&r=" + Math.random(), 
			async:false,
			dataType:"json",
			processData:false,
			success:function (data) {
				if (data == 1) {
					window.location.href="index.do?method=findUniversitysByType&r=" + Math.random();
				}
			}
		});		
	});
	
	$("#reset").click(function () {
		$("input[name='grade']").each(function () {
			this.checked = false;
		});
		
		var grade = $("input[name='grade']:checked").val();
		if (grade == null) {
			grade = "";
		}
		$.ajax({
			type:"get",
			cache:false,
			url:"index.do?method=chooseGrade&grade="+grade + "&r=" + Math.random(), 
			dataType:"json",
			processData:false,
			success:function (data) {
				window.location.reload();
			}
		});		
	});
	



});

