﻿// ------------------------------------------------------------------------------------------
// AJAX routines
// To Display progress animation via javascript use BeginRequest and EndRequest routines below.
// Implementation of InitializeRequest is also given but not required for our opeartion.
// http://www.asp.net/AJAX/documentation/live/ClientReference/Sys.WebForms/PageRequestManagerClass/PageRequestManagerPageLoadedEvent.aspx
// http://msdn.microsoft.com/en-us/magazine/cc163413.aspx
//http://www.ironspeed.com/articles/Restore%20Focus%20Postbacks/Article.V6X.aspx?c=Catapult
// -----------------------------------------------------------------------

//var prm = Sys.WebForms.PageRequestManager.getInstance();
//prm.add_initializeRequest(InitializeRequest);
//prm.add_beginRequest(BeginRequest);
//prm.add_endRequest(EndRequest);
//prm.add_pageLoaded(pageLoadedHandler);

//var postBackElement;
//function BeginRequest(sender, args) {
//   postbackElement = args.get_postBackElement();
//   $get('ctl00_ctl00_UpdateProgress1').style.display = 'block';
//}

//function EndRequest(sender, args) {
//   $get('ctl00_ctl00_UpdateProgress1').style.display = 'none';

//}
//function InitializeRequest(sender, args) {
//   if (prm.get_isInAsyncPostBack())
//      args.set_cancel(true);

//   //postBackElement = args.get_postBackElement();
//   $get('ctl00_ctl00_UpdateProgress1').style.display = 'block';
//}
//function CancelAsyncPostBack() {
//   if (prm.get_isInAsyncPostBack()) {
//      prm.abortPostBack();
//   }
//}
//function pageLoadedHandler(sender, args) {
//   var txtMsg = $get('ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_txtMessage');
//   if (txtMsg != null) {
//      if (txtMsg.disabled == false)
//         txtMsg.focus();
//   }
//}
// ------------------------------------------------------------------------------------------
// JS routines
//-----------------------------------------------------------------------


function MyMouseOver()
{
        window.status="Spelling Stars";
        
        return true;
}
//window.captureEvents(Event.MOUSEOVER)
//window.captureEvents(Event.CLICK)
//window.onmouseover = MyMouseOver

//Use followign routine for Keybord Buttons
function AddMeToText(buttonID, textID)
{
    var buttonControl = document.getElementById(buttonID);
    //alert(buttonControl.value);
    var textControl = document.getElementById(textID);
    //alert(textControl.value);
    textControl.value = textControl.value + buttonControl.value;
    
}

// Print specified content
function printMyScore(divID, schoolID, gradeID, teacherID, studentID, listID, myScore, testType)
{
  var divContent = document.getElementById(divID).innerHTML;
  var school = document.getElementById(schoolID).value;
  var grade = document.getElementById(gradeID).value;
  var teacher = document.getElementById(teacherID).value;
  var student = document.getElementById(studentID).value;
  var listName = document.getElementById(listID).value;
  var calculatedScore = document.getElementById(myScore).value;
  //var listName = document.getElementById(listID).innerText; //This is for dropdown list
  
  var link = "about:blank";
  var pw = window.open(link, "_new");
  pw.document.open();
  pw.document.write(makepage(divContent, school, grade, teacher, student, listName, calculatedScore, testType));
  pw.document.close();
}


function makepage(divContent, school, grade, teacher, student, listName, calculatedScore, testType)
{
  // We break the closing script tag in half to prevent
  // the HTML parser from seeing it as a part of
  // the *main* page.

  return "<html>\n" +
    "<head>\n" +
    "<title>Spelling Stars</title>\n" +
    "<script>\n" +
    "function step1() {\n" +
    "  setTimeout('step2()', 10);\n" +
    "}\n" +
    "function step2() {\n" +
    "  window.print();\n" +
    "  window.close();\n" +
    "}\n" +
    "</scr" + "ipt>\n" +
    "</head>\n" +
    "<body onLoad='step1()'>\n" +
        "<div id='divFormat' style='font-family:Verdana; padding:5px 5px 5px 5px; border:groove 0px #000000; margin-top:50px; margin-left:100px' />\n" +
        "<table style='border:groove 1px #000000; width:400px; margin:5px 5px 5px 5px;' >\n" +
            "<tr>\n" +
                "<td align='left'>\n" +
                    "<br />\n" +
                    "Spelling Test for <strong id='stdentName'>" + student + "</strong><br />\n" +
                    "Score: " + calculatedScore + "<br />\n" +
                    "Teacher: " + teacher + "<br />\n" +
                    "Test Type: " + testType + "<br />\n" +
                    "List: " + listName + "<br />\n" +
                    "Test Date: " + GetDateTime() + "<br />\n" +
                    "<hr>\n" +
                "</td>\n" +
            "</tr>\n" +
            "<tr>\n" +
                "<td align='left'>\n" +
                    "<br />\n" +
                    "<div id='newDiv'>" + divContent + "</div>\n" +
                    "<br />\n" +
                    "<img id='ssMiniStar' src='../images/MiniStar.gif' alt='Spelling Stars' >\n" +
                    "www.SpellingStars.com\n" +
                    "<br />\n" +
                "</td>\n" +
            "</tr>\n" +
        "</table>\n" +
        "</div>\n" +
    "</body>\n" +
    "</html>\n";
}


function GetDateTime()
{
    var currentTime = new Date();
    var month = currentTime.getMonth() + 1;
    var day = currentTime.getDate();
    var year = currentTime.getFullYear();
    
    var hours = currentTime.getHours();
    var minutes = currentTime.getMinutes();
    var ampm = ''
    if (minutes < 10)
        minutes = "0" + minutes;
    
    if(hours > 11)
    {
        ampm = "PM";
    }
    else 
    {
        ampm = "AM";
    }
    
    return month + "/" + day + "/" + year + " " + hours + ":" + minutes + " " + ampm;
}

// Print specified content
function printList(divID, schoolID)
{
  var divContent = document.getElementById(divID).innerHTML;
////  var school = document.getElementById(schoolID).value;
////  var grade = document.getElementById(gradeID).value;
////  var teacher = document.getElementById(teacherID).value;
////  var student = document.getElementById(studentID).value;
////  var listName = document.getElementById(listID).value;
////  var calculatedScore = document.getElementById(myScore).value;
////  //var listName = document.getElementById(listID).innerText; //This is for dropdown list
  
  var link = "about:blank";
  var pw = window.open(link, "_new");
  pw.document.open();
  pw.document.write(makeListPage(divContent));
  pw.document.close();
}

function makeListPage(divContent)
{
  // We break the closing script tag in half to prevent
  // the HTML parser from seeing it as a part of
  // the *main* page.

  return "<html>\n" +
    "<head>\n" +
    "<title>Spelling Stars</title>\n" +
    "<script>\n" +
    "function step1() {\n" +
    "  setTimeout('step2()', 10);\n" +
    "}\n" +
    "function step2() {\n" +
    "  window.print();\n" +
    "  window.close();\n" +
    "}\n" +
    "</scr" + "ipt>\n" +
    "</head>\n" +
    "<body onLoad='step1()'>\n" +
        "<div id='divFormat' style='font-family:Verdana; padding:5px 5px 5px 5px; border:groove 0px #000000;' />\n" +
        "<table style='border:groove 0px #000000;' >\n" +
            "<tr>\n" +
                "<td align='left'>\n" +
                    "<div id='miniStar' style='border:groove 0px #000000; margin-left:500px'>\n" + 
                        "<img id='ssMiniStar' src='../images/MiniStar.gif' alt='Spelling Stars' >\n" +
                        "www.SpellingStars.com\n" +
                    "</div>\n" +
                    "<div id='newDiv'>" + divContent + "</div>\n" +
                "</td>\n" +
            "</tr>\n" +
        "</table>\n" +
        "</div>\n" +
    "</body>\n" +
    "</html>\n";
}

