/**------------------------------------------------------------------------
 * Set of function used for newsboard messages.
 *
 * Dependencies:
 *  dojo.js, version 0.9
 *
 * Author:
 *  g stoianov
 *
 * @version $Id: newsboard.js,v 1.4 2010/10/24 13:26:46 hbr Exp $
 *
 *-----------------------------------------------------------------------*/

 //some static values for the results pane, must be updated with the search xsp
 var statics = {
           NEWS_DATA_URL: "/participants/trading/newsboard/prod/omp_single_message"
 }

 //some static values for control ids, must be updated with the search xsp
 var controlIds = {
         NEWS_DIALOG_ID: "nbNewsDialog"
 }

/**
 * Loads the search results returned from the google mini in the results pane
 * @param queryString The query string for the search.
 */
dspNewsboardMsg = function(date, time, orig, id, subject, lang, dspDate) {
  //console.log("Running dspNewsboardMsg: date=" + date + " time=" + time + " orig=" + orig + " id=" + id + " subject=" + subject + " lang=" + lang + " dspDate=");

  var dialog = dijit.byId(controlIds.NEWS_DIALOG_ID);
  dialog.titleNode.innerHTML = dspDate + "&nbsp;" + subject;
  dialog.show();
  var e = dojo.byId("newsBodyDiv");
  e.innerHTML = "";

  var printLinkEl1 = dojo.byId("newsPrintLink1");
  var printLinkEl2 = dojo.byId("newsPrintLink2");
  printLinkEl1.onclick = null;
  printLinkEl2.onclick = null;

  var _url = statics.NEWS_DATA_URL + ".html?msgid="+id+"&envs=" + orig;

  dojo.xhrGet( {
      url         : _url,
      handleAs    : "text",
      timeout         : 15000,      // in miliseconds
      preventCache    : true,

      load: function(response, ioArgs) {
          e.innerHTML = response;

          printLinkEl1.onclick = function(evt) {
              printNewsboardNews(date, time, orig, id, lang);
          }
          printLinkEl2.onclick = function(evt) {
              printNewsboardNews(date, time, orig, id, lang);
          }

          return response;
      },      // end load

      error: function(response, ioArgs) {
          e.innerHTML = "Error...." + response + " " + ioArgs.xhr.status;

          return response;
      }       // end error

  } );        // end dojo.xhrGet

}

function printNewsboardNews(date, time, orig, id, lang) {

    var pattern = /^http:\/\/\w*([-\.]\w*)*:?\d*/g;

    var print_url = statics.NEWS_DATA_URL + ".html?msgid=" + id
                    + "&envs=" + orig + "&print=true";

    var strarr = window.location.href.match(pattern);

    if ( strarr.length == 0 )
        return false;

    var url = strarr[0] + print_url;
    var width = 650;
    var height = 700;
    var left = (screen.width - width) / 2;
    var top = (screen.height - height) / 2;

    //alert('print news ' + url);

    var popup = window.open(url, 'popup',
        "width=" + width + ",height=" + height + ",top=" + top + ",left=" + left + ",resizable=1"
        + "directories=0,location=0,menubar=0,scrollbars=1,status=0,titlebar=0,toolbar=0");
    popup.window.focus();


    return false;
}

