﻿
//////////////////////////////
// Printing
//////////////////////////////

function makepage(src)
{
  // 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>Temporary Printing Window</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" +
    "<img src='" + src + "'/>\n" +
    "</body>\n" +
    "</html>\n";
}

function printme() {
//    var image = new Image();
//    image = document.getElementById('imgPlot')
//    src = image.src;
    link = "about:blank";
    var pw = window.open(link, "_new");
    pw.document.open();
    pw.document.write(makepage('Plot.ashx'));
    pw.document.close();
}

function printmeX(evt)
{
  if (!evt) {
    // Old IE
    evt = window.event;
  }    
  var image = evt.target;
  if (!image) {
    // Old IE
    image = window.event.srcElement;
  }
  src = image.src;
  link = "about:blank";
  var pw = window.open(link, "_new");
  pw.document.open();
  pw.document.write(makepage(src));
  pw.document.close();
}

//////////////////////////////
// Ajax
//////////////////////////////

function getXMLHTTPRequest() {
    try {
        req = new XMLHttpRequest();
    } catch (err1) {
        try {
            req = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (err2) {
            try {
                req = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (err3) {
                req = false;
            }
        }
    }
    return req;
}

var http = getXMLHTTPRequest();

function getPlot() {
    var myurl = 'ChartIt.aspx';
    myRand = parseInt(Math.random() * 999999999999999);
    var modurl = myurl + "?rand=" + myRand;
    http.open("POST", modurl, true);
    http.onreadystatechange = useHttpResponse;
    http.send(null);
}

function useHttpResponse() {
    if (http.readyState == 4) {
        if (http.status == 200) {
            var Plot = http.responseXML.getElementsByTagName("imgPlot")[0];
            document.getElementById('imgPlot').innerHTML = Plot.childNodes[0].nodeValue;
        }
    } else {
        document.getElementById('imgPlot').innerHTML = '<img src="images\anim.gif">';
    }
}

