function getScrollXY() {
    var scrOfX = 0, scrOfY = 0;
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant
        scrOfY = window.pageYOffset;
//        scrOfX = window.pageXOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
//        scrOfX = document.body.scrollLeft;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
//        scrOfX = document.documentElement.scrollLeft;
    }
    return scrOfY;
}



          function showdiv(mydivID, myheader, withBG)
          {
              var popID = mydivID;

              myhtml= "<div class=\"ModalMessageHeader\" id=\"DIVclose\">";
              myhtml += myheader;
              myhtml += "<a id=\"closeModal\" class=\"closeModal\" onclick=\"hidediv('" + mydivID + "');\">";
              myhtml += "<img alt=\"Close\" title=\"Close Window\" class=\"btn_closeModal\" src=\"/images/modal_Close_btn.png\" onclick=\"hidediv('" + mydivID + "');\" />";
              myhtml += "</a></div>";

              closeHTML= "Click here to close this window.";

              //Fade in the Popup and add close button
              jQuery('#' + popID).attr("style","display:block").prepend(myhtml);

              //Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
              var popMargTop = (jQuery(window).height() / 2) - ((jQuery('#' + popID).attr("height")).replace("px", "") / 2) + (getScrollXY()) + "px";
              var popMargLeft = (jQuery(window).width() / 2) - ((jQuery('#' + popID).attr("width")).replace("px", "") / 2) + "px";

              //Apply Margin to Popup
              jQuery('#' + popID).css({
              'top' : popMargTop,
              'left' : popMargLeft,
              'position' : 'absolute',
              'z-index' : '10000',
              'background' : '#ffffff',
              'width' : jQuery('#' + popID).attr("width"),
              'height' : jQuery('#' + popID).attr("height")
              });


          //Fade in Background
          if (withBG != "no") {
                  jQuery('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
                  jQuery('#fade').css({ 'filter': 'alpha(opacity=80)' }).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies
              }
              document.body.style.overflow = 'hidden';
          }


          function hidediv(mydivID)
          {
              //Close Popups and Fade Layer
              jQuery('#fade , .popup_block').fadeOut(function() {
              jQuery('#' + mydivID).attr("style","display:none");
              jQuery('#fade, #DIVclose').remove();  //fade them both out
          });

          document.body.style.overflow = 'auto';
      }

          function DoRequestForInfo(myinfo, withBG) {
              var myframe = document.getElementById("IFRrequestforinfo");

              if (myframe != null) {
                  myframe.src = "/RFIrequest/tabid/238/Default.aspx?section=" + myinfo;
                  showdiv('DIV_RequestForInfoIframe', 'Request For Info', withBG);
              }
          }


          function DoDownload(mynumber, myname) {
              fileARR = GetDownloadFiles(mynumber);

              if (fileARR.length > 0) {
                  if (fileARR.length == 1) {
                      paramSTR = fileARR[0];

                      var singleFile = "/makezip.ashx?myrequest=zip&files=" + paramSTR;
                      ZipReady(singleFile);
                  } else {

                      paramSTR = fileARR.join("|");

                      // Make URL String w/ paramSTR in querystring
                      var multiFile = "/makezip.ashx?myrequest=zip&files=" + paramSTR;
                      ZipReady(multiFile);
                  }

              } else {
                  alert("No Files Selected");
              }
          }


// Former AJAX driven DoDownload
//          function DoDownload(mynumber, myname)
//          {

//              fileARR= GetDownloadFiles(mynumber);

//              if (fileARR.length > 0)
//              {
//                  if (fileARR.length == 1)
//                  {
//                  // Do straight link
//                  // Make our Ajax Call
//                  paramSTR= fileARR[0];
//                  var params = { myrequest:"singlefile", name:myname, files:paramSTR };
//                  doajax("singlefile", params);
//                  }else{
//                  // Make our Ajax Call
//                  paramSTR= fileARR.join("|-|");
//                  var params = { myrequest:"zip", name:myname, files:paramSTR };
//                  doajax("zip", params);
//                  }
//              }else{
//              alert("No Files Selected");
//              }
//          }






          function ZipReady(filename)
          {
              var messageDiv;

              showdiv("DownloadMessageDiv", "Download My Documents");

              var mylink = document.getElementById("ZipDownloadLink");
              mylink.href = filename;
              mylink.text = "Download File";
          }


          function SingleFileReady(filename)
          {
              window.open(filename);
          }



          function DoEmail(mynumber,myname)
          {
              fileARR = GetDownloadFiles(mynumber);
              if (fileARR.length > 0)
              {
                  paramSTR = fileARR[0];
                  var singleFile = "/makezip.ashx?myrequest=zip&files=" + paramSTR;

                  EmailReady(singleFile);

                  jQuery("#EmailSent").hide();
                  jQuery("#EmailForm").show();
                  showdiv("EmailMessageDiv", "Send Email");
              }else{
                  alert("No Files Selected");
              }
          }


          function EmailReady(filename)
          {
              var messageDiv;

              var mylink = document.getElementById("EmailDownloadLink");
              mylink.href = filename;
              mylink.text = "";
          }




          function SendEmail() {
              // Acquire Email Fields!!!!
              var toName = jQuery("#TXTemail_to_name").val();
              var toEmail = jQuery("#TXTemail_to").val();
              var fromName = jQuery("#TXTemail_from_name").val();
              var fromEmail = jQuery("#TXTemail_from").val();

              var ziplink = jQuery("#EmailDownloadLink").attr("href");
              var ziplinkName = jQuery("#EmailDownloadLink").attr("text");

              if ((toName == "") || (toName == "recipient name*") || (toEmail == "") || (toEmail == "recipient email address*") || (fromName == "") || (fromName == "your name*") || (fromEmail == "") || (fromEmail == "your email address*")) {
                  alert("A field is missing. Please fill in all fields.");
              }
              else {
                  // Commence Param Building!!!
                  var params = { myrequest: "emailsend", toName: toName, toEmail: toEmail, fromName: fromName, fromEmail: fromEmail, ziplink: ziplink, ziplinkName: ziplinkName };
                  doajax("emailsend", params);
              }
          }

// Former SendEmail() functionality
//		  function SendEmail()		  
//          {
//              // Acquire Email Fields!!!!
//              var toName= jQuery("#TXTemail_to_name").val();
//              var toEmail= jQuery("#TXTemail_to").val();
//              var fromName = jQuery("#TXTemail_from_name").val();
//              var fromEmail = jQuery("#TXTemail_from").val();
//			  
//              var ziplink= jQuery("#EmailDownloadLink").attr("href");
//              var ziplinkName= jQuery("#EmailDownloadLink").attr("text");
//			  
//              // if any of these are blank, abort
//              if ((toName == "") || (toEmail == "") || (fromName == "") || (fromEmail == "") || (ziplink == "") || (ziplinkName == ""))
//              {
//                  // Give'em an error message
//                  alert("A field isn't filled in");
//              }else{
//                  // Commence Param Building!!!
//                  var params = { myrequest: "emailsend", toName: toName, toEmail: toEmail, fromName: fromName, fromEmail: fromEmail, ziplink: ziplink, ziplinkName: ziplinkName };
//                  doajax("emailsend", params);
//              }
//          }

          function clearfieldtext(mytarget, mytext)
          {
              if (mytarget.value == mytext)
              {
                  mytarget.value= "";
              }
          }

          function EmailSent(filename)
          {
              if (filename.indexOf("problem") > -1)
              {
                  alert(filename);
              } else {
                  jQuery("#EmailForm").hide();
                  jQuery("#EmailSent").show();
              }
          }



          function DoCheckBox(mytarget)
          {
              myelement = jQuery(mytarget).find("input").get();
              DIVmessage_filelist= jQuery("#DIVmodalmessage_filelist");
              DIVmessage_html= jQuery(DIVmessage_filelist).html();

              tdARR= jQuery(mytarget).find("td").get();
              myname= jQuery(tdARR[2]).html();

              if (jQuery(myelement[0]).attr("checked") == true)
              {
                  jQuery(myelement[0]).attr("checked", false);
                  jQuery(DIVmessage_filelist).html(DIVmessage_html.replace(myname + "<br/>", ''));
              }else{
                  jQuery(myelement[0]).attr("checked", true);
                  jQuery(DIVmessage_filelist).html(DIVmessage_html + myname + "<br/>");
              }

          }





          function GetDownloadFiles(mynumber)
          {
              var chkBoxARR;
              var i = 0;
              var j=0;
              var paramARR=new Array();
              chkBoxARR = jQuery("#" + mynumber).find('input').get();

              if (chkBoxARR.length == 0) {
                  chkBoxARR = jQuery("input[name=" + mynumber + "]");
              }

              for (i = 0; i < chkBoxARR.length; i++)
              {

                  // Assemble download string
                  if (chkBoxARR[i].checked)
                  {
                      //paramSTR += "|" + chkBoxARR[i].value;
                      paramARR[j] = chkBoxARR[i].value;
                      j=j+1;
                  }
              }

              return paramARR;
          }


          function doajax(mode, params)
          {
              jQuery.ajax({
              cache: "false",
              data: params,
              url: "/doajax.ashx",
              context: document.body,
              dataType: "text",
              success: function(data,y,z){
              ajaxdone(mode, data);
              }
              });
          }

          function ajaxdone(mode, data)
          {

              switch(mode)
              {
              case "zip":
              ZipReady(data);
              break;

              case "singlefile":
              SingleFileReady(data);
              break;

              case "email":
              EmailReady(data);
              break;

              case "emailsend":
              EmailSent(data);
              break;
              }

          }



