﻿var webSiteRoot = window.location.protocol + "//" + window.location.host + "/";

function confirmDelete(msg)
{
	return confirm(msg); 
}

function openTelerikWindow(page, query, window, width, height, title)
{
	var win = radopen(webSiteRoot + page + '?' + query, window);
	//win.set_height(height);
	//win.set_width(width);
	win.SetTitle(title);
	win.set_modal(true);
	win.center();
}

function EditProfile(type) 
{
	var win = radopen(webSiteRoot + "Modals/Portals/EditProfiles.aspx?type=" + type.toLowerCase(), null);
	if (type.toLowerCase() == "user") 
	{
		win.set_height(650);
		win.set_width(850);
		win.SetTitle('Editing User Profile');
	}
	else if (type.toLowerCase() == "faculty")
	{
		win.set_height(650);
		win.set_width(850);
		win.SetTitle('Editing Faculty Profile');
	}
	else if (type.toLowerCase() == "student")
	{
		win.SetTitle('Editing Student Profile');
		win.set_height(650);
		win.set_width(800);
	}
	
	win.set_modal(true);
	win.center();
}

// text block create button
function SubmitMediaBlock(type, classid, textid) 
{
	var win = radopen(webSiteRoot + "Modals/Portals/SubmitMediaBlock.aspx?type=" + type + "& cid=" + classid + "&tid=" + textid, null);
	win.set_height(600);
	win.set_width(850);
	win.set_modal(true);
	win.center();
}

// text block delete button
function OnDockDeleteCommand(sender, eventArgs)
{
	if (!confirm("Are you sure you want to delete this text block?"))
	{
		eventArgs.set_cancel(true);
	}
	else
	{
		// confirmed delete of text block, load page, delete, refresh window
		var idToDelete = sender.get_id().indexOf("_RadDock");
		idToDelete = sender.get_id().substring(idToDelete + 8, sender.get_id().length)
		var win = radopen(webSiteRoot + "pages/SubmitMediaBlock.aspx?dmb=" + idToDelete, null);
		win.set_height(600);
		win.set_width(850);
		win.set_modal(true);
		win.center();
	}
}

function OnDockEditCommand(sender, eventArgs)
{
	var idToEdit = sender.get_id().indexOf("_RadDock");
	idToEdit = sender.get_id().substring(idToEdit + 8, sender.get_id().length)
	var win = radopen(webSiteRoot + "pages/SubmitMediaBlock.aspx?mb=" + idToEdit, null);
	win.set_height(600);
	win.set_width(850);
	win.set_modal(true);
	win.center();
}

function SubmitArticle() {
	var win = radopen(webSiteRoot + "pages/SubmitArticle.aspx", "SubmitArticle");
	win.set_height(600);
	win.set_width(850);
	win.set_modal(true);
	win.center();
}

function ShowClassNote(noteId) {
	var win = radopen(webSiteRoot + "pages/ClassNotes.aspx?noteid=" + noteId, "ClassNotes");
	win.set_height(500);
	win.set_width(450);
	win.set_modal(true);
	win.center();
}
	
/* Display the assignement window for the specified class - if the assignement id is provided then its an update */
function EditAssignment(mode, classid, facultyid, assignmentid) {
	var win = radopen(webSiteRoot + "Modals/Portals/ClassAssignments.aspx?mode=" + mode + "&cid=" + classid + "&fid=" + facultyid + "&id=" + assignmentid, null);
	win.set_height(600);
	win.set_width(850);
	if (mode == 'create') win.SetTitle('Adding an Assignment');
	else if (mode == 'edit') win.SetTitle('Editing an Assignment');
	win.set_modal(true);
	win.center();
}

function ViewAssignment(assignmentid) {
	var win = radopen(webSiteRoot + "Modals/Portals/ViewAssignment.aspx?aid=" + assignmentid, null);
	win.set_height(500);
	win.set_width(565);
	win.SetTitle('Viewing an Assignment');
	win.set_modal(true);
	win.center();
}

function EditCourse(mode, classid) {
	var win = radopen(webSiteRoot + "Modals/School/EditCourse.aspx?mode=" + mode + "&cid=" + classid, null);
	win.set_height(600);
	win.set_width(565);
	if (mode == 'create') win.SetTitle('Adding an Assignment');
	else if (mode == 'edit') win.SetTitle('Editing a Course Information');
	win.set_modal(true);
	win.center();
}

/* The assignment window is done and needs to be closed and we need to update */
function AssignmentUpdate() {
	InitiateAjaxRequest("Nothing");
}

/* Show the list of students for the specified class id */
function StudentClassList(classid) {
	var win = radopen(webSiteRoot + "Modals/Portals/ClassStudents.aspx?cid=" + classid, null);
	win.set_height(500);
	win.set_width(565);
	win.SetTitle('Class Roster');
	win.set_modal(true);
	win.center();
}

/* Toggle the display of a div - attached to the Hide button on the portal panels */
function ToggleDivDisplay(name1, name2, sender) 
{
	var div1 = document.getElementById(name1);
	var div2 = document.getElementById(name2);
	if ( div1 != null && div1.style.display == 'none' ) div1.style.display = 'block';
	else if ( div1 != null ) div1.style.display = 'none';
	if ( div2 != null && div2.style.display == 'none' ) div2.style.display = 'block';
	else if ( div2 != null ) div2.style.display = 'none';
	if (sender)
	{
		if (sender.innerHTML == "–") sender.innerHTML = "+";
		else if (sender.innerHTML == "+") sender.innerHTML = "–";
	}
}

function openWindow(url,name,options)
{
	var newWindow = window.open(url,name,options);
	newWindow.focus();
}

function closeEdit(isModal, backUrl)
{
	if(isModal)
	{
		CloseOnReload(); 
		return false;
	}
	else
	{
		window.location = backUrl;
	}
}