﻿// JScript File
var iframevisible = false;
function showLoginHistory(relObj, userId)
{
    showFrameAtLoc(360, 100, 240, 415, "loginhistory.aspx?userid=" + userId)
}
function showMemberDetails(relObj, userId)
{
    showFrame(relObj, 730, 550, "memberdetails.aspx?userid=" + userId)
}
function sendEmail(relObj, emailId, recipientId)
{
    var oneToDisallow = document.getElementById("hiddenX").value;
    if (emailId != oneToDisallow) {
        showFrame(relObj, 500, 500, "sendemail.aspx?emailid=" + emailId + "&recipientId=" + recipientId);
    } else {
        alert("Because we can't retrieve their password, this email cannot be re-sent.");
    }
}

function getLeftForObject(oBtn)
{
    var returnValue = 0;
    var currObject = oBtn;
    while (null != currObject)
    {
        returnValue = returnValue + currObject.offsetLeft;
        currObject = currObject.offsetParent;
    }
    
    return returnValue;
}

function getTopForObject(oBtn)
{
    var returnValue = 0;
    var currObject = oBtn;
    while (null != currObject)
    {
        returnValue = returnValue + currObject.offsetTop;
        currObject = currObject.offsetParent;
    }
    
    return returnValue;
}

function showFrameAtLoc(left, top, width, height, url)
{
    if (iframevisible) {
        return;
    }

    var frPopup = document.getElementById("frPopup");
    if (null == frPopup)
    {
        alert("Couldn't get the frame object.");
    }
    frPopup.style.width = width + "px";
    frPopup.style.height = height + "px";
    frPopup.style.left = left + "px";
    frPopup.style.top = top + "px";

    frPopup.src = url;
    frPopup.style.display = "inline";
}
function showFrame(relObj, width, height, url)
{
    if (iframevisible) {
        return;
    }

    var frPopup = document.getElementById("frPopup");
    if (null == frPopup)
    {
        alert("Couldn't get the frame object.");
    }
    frPopup.style.width = width + "px";
    frPopup.style.height = height + "px";
    //frPopup.style.left = (window.document.body.clientWidth - width - 10)/2 + "px";
    frPopup.style.left = getLeftForObject(relObj) + "px";
    frPopup.style.top = getTopForObject(relObj) + "px";

    frPopup.src = url;
    frPopup.style.display = "inline";
}

function resizeFrame(width, height)
{
    var frPopup = document.getElementById("frPopup");
    frPopup.style.width = (width + 6) + "px";
    frPopup.style.height = (height + 6) + "px";
}

function closeiFrame(refresh)
{
    if (refresh != '') {
        // reload the page
        window.location.reload(true);
    } else{
        var frPopup = window.document.getElementById("frPopup");
        if (null == frPopup) {
            window.alert("Couldn't get the frame object.");
        } else {
            frPopup.style.display = "none";
            frPopup.src = "about:blank";
            if (null != document.getElementById("safarikludge")) {
                document.getElementById("safarikludge").innerHTML = "";
            }
            iframevisible = false;
        }
    }
}

function editAsOngoingTemplate(relObj, courseId, termId, startSeq)
{
    showFrame(relObj, 550, 825, "cptemplateitem.aspx?courseid=" + courseId + "&schooltid=" + termId + "&startseq=" + startSeq);
}

function editAsTemplate(relObj, courseId, termId)
{
    if (!confirm("If you edit the course plan as a template, any previously saved instructions will be replaced.  If you want to continue, click 'OK'.  Otherwise, click 'Cancel'."))
    {
        return;
    }
    showFrame(relObj, 550, 825, "cptemplateitem.aspx?courseid=" + courseId + "&schooltid=" + termId);
}

function editSeqItem(relObj, courseId, termId, sequence, reloadWhenDone)
{
    document.getElementById("idBeingChanged").value = "seq" + courseId + termId + sequence;
    showFrame(relObj, 340, 260, "cpitem.aspx?mode=seq&courseid=" + courseId + "&schooltid=" + termId + "&seq=" + sequence + "&reload=" + reloadWhenDone);
}

function clearSeqItem(relObj, courseId, termId, sequence, reloadWhenDone)
{
    document.getElementById("idBeingChanged").value = "seq" + courseId + termId + sequence;
    showFrame(relObj, 340, 300, "cpitemclear.aspx?mode=seq&courseid=" + courseId + "&schooltid=" + termId + "&seq=" + sequence + "&reload=" + reloadWhenDone);
}

function clearIndItem(relObj, id)
{
    document.getElementById("idBeingChanged").value = id;
    showFrame(relObj, 340, 300, "cpitemclear.aspx?mode=ind&scpid=" + id);
}

function deleteSequenceAssignment(allID)
{
    document.getElementById(allID).style.display = "none";
    closeiFrame(false);
}

function deleteIndividualAssignment(assignmentID)
{
    document.getElementById(assignmentID).style.display = "none";
    closeiFrame(false);
}

function updateIndividualAssignmentOnPage(oTextarea)
{
    var idBeingChanged = document.getElementById("idBeingChanged").value;
    document.getElementById("assgntxt" + idBeingChanged).innerHTML = oTextarea.value;
    document.getElementById(idBeingChanged).style.backgroundColor = "#DCE9CD";
    window.setTimeout("document.getElementById('" + idBeingChanged + "').style.backgroundColor = '#FFFADA'", 250);
    document.getElementById("idBeingChanged").value = "";
    closeiFrame(false);
}

function addSequenceAssignmentToPage(oTextarea, allID, sequence)
{
    var changedDiv = document.getElementById(document.getElementById("idBeingChanged").value);
    var newAssignmentHTML = "<div id='" + allID + "' class='assignmentEntry'>";
    newAssignmentHTML += "Assignment";
    var dq = '"';
    newAssignmentHTML += "&nbsp;<a id='href" + allID + "' href='javascript::' title='" + oTextarea.value + "' onclick=" + dq + "editSeqAssignment(this, '" + allID + "','" + sequence + "'); return false;" + dq + ">View/Edit</a>";
    newAssignmentHTML += "<div id='seqassgntxt" + allID + "' class='assignmentEntry' style='border:solid 1px green;text-align:left;padding:3px 3px 3px 10px'>" + oTextarea.value + "</div>";
    newAssignmentHTML += "</div>";
    newAssignmentHTML += "<br />";
    changedDiv.innerHTML += newAssignmentHTML;
    document.getElementById(allID).style.backgroundColor = "#DCE9CD";
    window.setTimeout("document.getElementById('" + allID + "').style.backgroundColor = '#FFFADA'", 250);
    document.getElementById("idBeingChanged").value = "";
    closeiFrame(false);
}

function addIndividualAssignmentToPage(oTextarea, assignmentID)
{
    var changedDiv = document.getElementById(document.getElementById("idBeingChanged").value);
    var newAssignmentHTML = "<div id='" + assignmentID + "' class='assignmentEntry'>";
    newAssignmentHTML += "<img src='../i/a_pending.gif' width='15px'>&nbsp;Assignment";
    var dq = '"';
    newAssignmentHTML += "&nbsp;<a href='javascript::' title='" + oTextarea.value + "' onclick=" + dq + "editIndAssignment(this, '" + assignmentID + "'); return false;" + dq + ">View/Edit</a>";
    newAssignmentHTML += "<div id='assgntxt" + assignmentID + "' class='assignmentEntry' style='border:solid 1px green;text-align:left;padding:3px 3px 3px 10px'>" + oTextarea.value + "</div>";
    newAssignmentHTML += "</div>";
    changedDiv.innerHTML += newAssignmentHTML;
    document.getElementById(assignmentID).style.backgroundColor = "#DCE9CD";
    window.setTimeout("document.getElementById('" + assignmentID + "').style.backgroundColor = '#FFFADA'", 250);
    document.getElementById("idBeingChanged").value = "";
    closeiFrame(false);
}

function updateSequenceAssignment(oTextarea)
{
    document.getElementById("seqassgntxt" + document.getElementById("idBeingChanged").value).innerHTML = oTextarea.value;
    document.getElementById(document.getElementById("idBeingChanged").value).style.backgroundColor = "#DCE9CD";
    window.setTimeout("document.getElementById('" + document.getElementById("idBeingChanged").value + "').style.backgroundColor = '#FFFADA'", 250);
    document.getElementById("idBeingChanged").value = "";
    closeiFrame(false);
}

function updateCoursePlanPage(oTextarea)
{
    var oIdBeingUpdated = document.getElementById("idBeingChanged");
    if (null != oIdBeingUpdated) {
        document.getElementById(oIdBeingUpdated.value).innerHTML = oTextarea.value;
        document.getElementById(oIdBeingUpdated.value).style.backgroundColor = "#DCE9CD";
        window.setTimeout("document.getElementById('" + oIdBeingUpdated.value + "').style.backgroundColor = '#FFFADA'", 250);
        oIdBeingUpdated.value = "";
        closeiFrame(false);
    } else {
        window.location.replace(window.location.toString());
    }
}

function editIndItem(relObj, id)
{
    document.getElementById("idBeingChanged").value = id;
    showFrame(relObj, 340, 260, "cpitem.aspx?mode=ind&scpid=" + id);
}

function editIndAssignment(relObj, id)
{
    //document.getElementById("idBeingChanged").value = "href" + id;
    document.getElementById("idBeingChanged").value = id;
    showFrame(relObj, 400,260, "cpassignment.aspx?mode=edit_ind&scpaid=" + id);
}

function editSeqAssignment(relObj, allId, sequence)
{
    document.getElementById("idBeingChanged").value = allId;
    showFrame(relObj, 340, 260, "cpassignment.aspx?mode=edit_seq&allid=" + allId + "&seq=" + sequence);
}

function addSeqAssignment(relObj, courseId, termId, sequence)
{
    document.getElementById("idBeingChanged").value = "seqassgn_" + sequence;
    showFrame(relObj, 340, 260, "cpassignment.aspx?mode=new_seq&courseid=" + courseId + "&schooltid=" + termId + "&seq=" + sequence);
}

function addIndAssignment(relObj, id)
{
    document.getElementById("idBeingChanged").value = "assgn_" + id;
    showFrame(relObj, 400, 260, "cpassignment.aspx?mode=new_ind&scpid=" + id);
}

function addNonSchoolDay(relObj)
{
    showFrame(relObj, 500, 570, "educator/addnonschoolday.aspx");
}

function findNonSchoolDay(relObj)
{
    showFrameAtLoc(150, 150, 550, 570, "educator/findnonschoolday.aspx");
}

function editNonSchoolDay(relObj, nsdID)
{
    showFrameAtLoc(100, 155, 500, 570, "educator/editnonschoolday.aspx?nsd=" + nsdID);
}

function editAssignment(relObj, studentcourseplanid)
{
    var url = "educator/cpitem.aspx?src=cal&mode=ind&scpid=" + studentcourseplanid;
    showFrame(relObj, 480, 260, url);
}

function doClassWorkFromCalendar(relObj, scpid)
{
    if (null != document.getElementById("safarikludge")) {
        document.getElementById("safarikludge").innerHTML = ".";
    }
    var url = "student/dowork.aspx?scpid=" + scpid;
    showFrame(relObj, 408, 510, url);
}

function doAssignment(relObj, scpaid)
{
    if (null != document.getElementById("safarikludge")) {
        document.getElementById("safarikludge").innerHTML = ".";
    }
    document.getElementById("idBeingWorked").value = scpaid;
    var url = "doassignment.aspx?scpaid=" + scpaid;
    showFrame(relObj, 408, 510, url);
}

function doClassWork(relObj, scpid)
{
    if (null != document.getElementById("safarikludge")) {
        document.getElementById("safarikludge").innerHTML = ".";
    }
    document.getElementById("idBeingWorked").value = scpid;
    var url = "dowork.aspx?scpid=" + scpid;
    showFrame(relObj, 408, 510, url);
}

function scheduleAssignment(e, something)
{
    return;
    var url = "educator/addschedule.aspx?mode=new&date=" + something.replace(/T/, " ") + "&studentname=" + document.getElementById("HSISCal1_ddlStudents").options[document.getElementById("HSISCal1_ddlStudents").selectedIndex].text + "&studentid=" + document.getElementById("HSISCal1_ddlStudents").options[document.getElementById("HSISCal1_ddlStudents").selectedIndex].value;
    showFrame(url);
}

var w;
function printDiv (divID) {
  if (w && !w.closed)
    w.close();
  w = open ('', 'imagePrint', 
       'menubar=1,locationbar=0,statusbar=0,resizable=1'
       + ',scrollbars=1,width=400,height=400');
  var html = '';
  html += '<HTML>';
  html += '<head>';
  html += '</head>';
  html += '<BODY ONLOAD="if (window.print) window.print(); '
           + 'setTimeout(\'window.close()\', 500);">';
  html += '<div>' + document.getElementById(divID).innerHTML + '</div>';
  html += '<\/BODY><\/HTML>';
  w.document.open();
  w.document.write(html);
  w.document.close();
}

