/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
var diagnoserStudent = {}

diagnoserStudent.showDaisyPage = function(selector, urlString) {
	$(selector).html("<iframe id='daisyContentIframe' src='"+urlString+"'><p>Your browser does not support iframes.</p></iframe>");
	// Done dynamically to resize based on content
	// TODO: Can't resize based on content unless domain is the same for the iframe content and for the parent.
	$("#daisyContentIframe").load(function(ev) {
		$("#daisyContentIframe").css("height", "800px");
	});
}

$(function() {
	$(".studentAssignmentTable td[colspan='2']").css("border-bottom", "0px none").css("border-top", "0px none")

	$(".studentAssignmentTable tr").each(function(index, elem) {
		if($(elem).children().hasClass("studentFinishedAssignmentCell"))	{
			if($(elem).prev().is(".studentAssignmentRowTwo")) {
				$(elem).addClass("studentAssignmentRowTwo")
			} else {
				$(elem).addClass("studentAssignmentRowOne")
			}
		} else if($(elem).prev().is(".studentAssignmentRowTwo")) {
			$(elem).addClass("studentAssignmentRowOne")
		} else {
			$(elem).addClass("studentAssignmentRowTwo")
		}
	})

	$(".studentAssignmentTable th:nth-child(2)").css("width", "100px")
	$(".studentAssignmentTable th:nth-child(3)").css("width", "75px")

	var validateSettings = function() {
		var error = false;
		$("#studentPasswordsNoMatch").hide();
		$("#currentPasswordNoMatch").hide();
	
		var newPass = $("#newPassword").val();	
		var confirmPass = $("#confirmPassword").val();
		if(newPass != confirmPass) {
			error = true;
			$("#studentPasswordsNoMatch").show();
		}
		return error;
	}
	
	$("#studentSettingsForm").submit( function(ev) {
		// validate
		var error = validateSettings()
		// submit if valid
		if(!error) {
			$(this).unbind("submit")
			$(this).submit()
		}
		ev.preventDefault();
		ev.stopImmediatePropagation();
		ev.stopPropagation();
		return false;			
	})
	$("#studentPasswordsNoMatch").hide();
	// if it exists show it
	$("#currentPasswordNoMatch").show();
	
	$("#studentPasswordChangedDialog").dialog({
		resizable: false,
		height: 220,
		width: 250,
		autoOpen: false,
		modal: true,
		title: "Password Changed",
		buttons: {
			OK: function() {
				$("#refreshingDialog").dialog("open")
				location.href="/studentapp/home"
			}
		}
	})
	if($("#studentPasswordChangeSuccess").length != 0) {
		$("#studentPasswordChangedDialog").dialog("open");
	}
});
