// --- [start /site/includes.js] ---
/* 
* Author : UI Development Team
* Description : lastminute.com Javascript - site wide functionality
* Contact : uidevelopment@lastminute.com
*/

/* Description: Variables to detect environment */

var frontierProtocol = 'http';
var frontierHTTPHost = 'www.lastminute.com';
var frontierBaseUrl = '/site';
var frontierURL = frontierProtocol+'://'+frontierHTTPHost+''+frontierBaseUrl;
var frontierSkin = 'engb.nationalrail';
var frontierLocale = 'en_GB';

/*
* Description : Adds to DOM the jsEnabled class name to indicate javascript availability 
*/
if (document.documentElement && document.getElementById) {
    document.documentElement.setAttribute('class','jsEnabled');
    document.documentElement.className = 'jsEnabled'; //For IE
}

var addJSnotifier = function () {
  var ids = 0,  /* A number, when tacked on to the end of a string guarantees a unique ID for the '«SCRIPT»' tag for the imported 'js. */ 
      _sSrcUri, /* The URI of the last JavaScript 'js' file imported by this utility.                                                  */
      _this = {

      dpnImporter: function(_thisFromEle){
          if (_thisFromEle.readyState) {                                    /* IE will respond to the 'onreadystatechange  */
              if (_thisFromEle.readyState === 'complete') {                 /* event firing and will make available the    */
                  _thisFromEle.anon = function(){                           /* 'readyState' property on the tag concerned. */
                      if (typeof lm !== 'undefined') {                      /* Check that JS (ie LMLibrary) is now there.  */
                          if (_thisFromEle.id.indexOf('eScriptId')===-1) {  /* Also, ensure this is the 1st time we add the*/
                              addJS(_thisFromEle.id);                       /* script and that subsequent event trips do   */
                              _thisFromEle.id= 'eScriptId' + ids++;         /* result in repeat additions of same script.  */
                          }   
                      }
                      else {
                          setTimeout(arguments.callee, 500);                /* LMlibrary hasn't been detected so test again*/
                      }
                  }();
              }
          } /* End if '_thisFromEle.readyState' exists */ 
          else {
              if (_thisFromEle.id.indexOf('eScriptId')===-1) {  /* Also, ensure this is the 1st time we add the*/
                  addJS(_thisFromEle.id);                       /* script and that subsequent event trips do   */
                  _thisFromEle.id= 'eScriptId' + ids++;         /* result in repeat additions of same script.  */
              } 
          }
      }, /* End method 'dpnImporter()' 'dependencyImporter()' */
      dpnNoEventSupport: function(sId){
        _sSrcUri = sId || _sSrcUri; /* rely on closure if call made into this method and no 'sId' supplied. */
        var eleScr;
          try 
          {
              eleScr = document.getElementById(_sSrcUri);
              if (eleScr === null)
              {
                  setTimeout(arguments.callee,10); /* Repeat poll (every 10s) to pick up added tag until its picked up .*/ 
              }
              else
              { 
                 if ( !(eleScr.onload || eleScr.onload) ) /* Bad news: the browser we are using doesn't support 'onload'   */ 
                 {                                        /* or 'onreadystate' change events so we'll have to poll to      */
                     if (typeof lm === 'undefined')
                     {
                         setTimeout(arguments.callee,5);
                     } /* repeatedly and test manually.     */
                     else 
                     {
                        addJS(_sSrcUri);
                     }
                 }
              }
          } 
          catch(Err) { }
        
      }/* End method 'dpnNoEventSupport()' 'dpnNoEventSupport()' */
  };
  return _this;
}(); /*[JF] END Self-invoking (for namespacing purposes) 'addJSnotifier()' function */

/*
* Description: Include the lm library - important
* [JF] 2009-09-23 Added in a polling mechanism ascertaing the readiness of the loaded-ness of LM Library; also
* [JF]            ensured that now 'addJS()' (to bring in 'EnhancedMap.js') is only called when we KNOW
* [JF]            LM Library is loaded; should eradicate all IE errors "Line 83: Error lm is 'undefined'".
*/
if( (typeof lm!='object') || (typeof lm == 'object' && !lm.loaded) ){       
    document.write('\u003Csc' + 'ript type="text/javascript" src="' + frontierURL + '/lm.js?skin=' + frontierSkin + 
                   '" id="' + frontierURL +'/enhancedMap.js?skin=' + frontierSkin + '"' + '>\u003C/sc' + 'ript>');
    /* paste this line back into the doc.write string if EnhancedMap.js required (and uncomment 'dpnNoEventSupport()' call. */
    /* onload="addJSnotifier.dpnImporter(this);" onreadystatechange="addJSnotifier.dpnImporter(this);" */
    /* addJSnotifier.dpnNoEventSupport(frontierURL +'/enhancedMap.js?skin=' + frontierSkin); */
    document.write('\u003Csc' + 'ript type="text/javascript" src="' + frontierURL + '/lm_recently_search_template_title.js?skin=' + frontierSkin + '">\u003C/sc' + 'ript>');
}



/*
* Description : adds a js file to head of page - specifically needed for multimap
*/
function addJS(src) {
    var pageHead = document.getElementsByTagName('head')[0];
    var mapScript = document.createElement('script');
    mapScript.setAttribute('type','text/javascript');
    mapScript.setAttribute('src',src);
    pageHead.appendChild(mapScript);
}
//addJS('http://cdn.lastminute.com/site/enhancedMap.js?skin=engb.nationalrail');

            function addMMKey() {
                addJS('http://clients.multimap.com/API/maps/1.2/lastminute_api?locale=en-gb');
            }



/*
* Legacy functions
*/

function SafeAddOnload(f){  
    lm.addEvent({fn:f});
}

function createCookie(name, value, days) {
    lm.cookie.create({name: name, value: value, expire: days}); 
}

function readCookie(name){
    if (lm.cookie && lm.cookie[name]) {     
        return lm.cookie[name];     
    } else {
        return '0';
    }
}

function readQueryString(param) {
    if (lm.querystring[param]) {
        return lm.querystring[param];
    } else {
        return false;       
    }
}

/*
* Define a random number variable. Used as a param to js ads in master banners 
*/
var randNum = new Date().getTime();
// --- [end prdpctbd4202:4001 - /site/includes.js - Feb 9, 2010 5:49 pm GMT - akamai,pcth0614,pct0410 - iU6cFQqoVrcAAGcFdJgAABBQ - cache 1800 ] ---
