/* Workbook additional functionality for hooking to the VLE. */
/* Author: Richard Kirby */
/* Version: $Id: wb-vle.js 4947 2009-05-28 16:50:54Z rbk $ */
/* Copyright: (c) 2007, 2008 CAPDM Ltd. All Rights Reserved */

/* HACK */
var myile_production_code = 'BC';

function aeRecordMark(id, data)
{
  var request = [ 'record', myile_production_code, id, data ];
  new Ajax.Request('../../../../ajaxhandler.svc?value='+Object.toJSON(request),
    { method:'get' });
}

function openFulltextWin(url,winName) {
  var win = winName;

  win = window.open(url,winName,'scrollbars=yes, resizable=yes, width=840, height=500, top=20, left=20');

  win.focus();
}

var dontask = false;

function loggedIn()
{
    if (dontask) { dontask = false; return; }
    dontask = true;

    var url = window.location.toString();
    var result = url.match("http://[^/]+(/.*\.html).*");
    url = result[1];
    var request = [ 'loggedInCheck' ];
    var params = {};
    params['value'] = Object.toJSON(request);
    new Ajax.Request('../../../../ajaxhandler.svc',//?value='+Object.toJSON(request),
                     { method:'post', asynchronous:true, evalJSON:true,
                       parameters: params,
                      onSuccess: function(transport) {
                             //                             alert('response is ' + transport.responseJSON);
                             if ("NO" == transport.responseJSON) {
                                 //                                 alert('fired event - response is ' + transport.responseText);
                                 if (! confirm('You need to register/login to this site in order to fill in the digital workbook elements. Click OK if you wish to go to the login page, otherwise Cancel will take you back to the page you were viewing')) {
                                     self.blur();
                                     return;
                                 }

                                 window.location='../../../../external.svc?page=Login&sp=S' + url;
                             }
                         }
                     });
    //    alert('returned from ajax');
}

function localLoad()
{
    LocalLoad();
}

var searchURLString = '';

// ---------------------
function getCookie(Name)
// ---------------------
{
var search = Name + "=";
      if (document.cookie.length > 0) { // if there are any cookies
              offset = document.cookie.indexOf(search);
                if (offset != -1) { // if cookie exists
                      offset += search.length;
                        // set index of beginning of value
                        end = document.cookie.indexOf(";", offset);
                        // set index of end of cookie value
                        if (end == -1) end = document.cookie.length;
                        return unescape(document.cookie.substring(offset, end));
              }
      }
      else return "";
}
