
// Adjust stylesheet for satanic devices less than width of the navbar or 960px w

if (window.screen.width && parseInt(window.screen.width) < 600)
{
  document.writeln ('<link href="./css/mobile.css" rel="stylesheet" type="text/css" \/>');
}


//alert ('Screen width ' +window.screen.width +"\n\nUser agent " +navigator.userAgent);


// Pre-load image stuff for cache
// passed: string - image filename including file extension

// Global image array
var imageArray = new Array();

function imgLoader(imgFile)
{
  // untaint filename
  imgFile = cleanup(imgFile);
  imageStore = new Image();
  imageStore.src = 'images/common/' +imgFile;
  imageArray.push(imageStore);
}


// Untaint and return a passed string
function cleanup(inStr)
{
  return  inStr.replace(/[^.a-zA-Z0-9_-]/g,'');
}  


// Set tab button highlight etc. for this page. Called by page onload
// Passed: integer (tab number used in link & span id's)
// Returns: nothing
function setPage(navtab) {

  imgLoader('topnav_tab_on.gif');
  
  if (navtab && parseInt(navtab) > 0) 
  {
    try {
      var tablink = document.getElementById('tablink' +navtab)
      var tabspan = document.getElementById('tabspan' +navtab)
     
      tablink.style.background = 'url(./images/common/topnav_tab_on.gif) no-repeat top right';
      tabspan.style.background = 'url(./images/common/topnav_tab_on.gif) no-repeat top left';
    }
    catch (err) { alert('Tab style fault: ' +navtab) }
  }
  
  imgLoader('topnav_tab_on.gif');

}


// mailto: link antispam measure
var charAt = String.fromCharCode(64); //@
var address = new Array();
address[0] = 'info' + charAt +'mainlineshow' +'.co.uk';

    
// Create generic mailto
// Pass array index plus CSS stylename if applicable
// Pass link text string, otherwise link text defaults to email address less any query string
function getAddress(num, style, linktext)
{
    if (num <= address.length)
    {
        if (linktext)
        {
            document.writeln('<a class="' +style +'" href="mailto:' +address[num] +'">' +linktext +'</a>')
        }
        else 
        {
            // strip any query string for default link text
            linktext = address[num];
            if (linktext.indexOf('?') > 8 ) // otherwise it's a duff address anyway
            {
                linktext = linktext.substring(0,linktext.indexOf('?'));
            }
            document.writeln('<a class="' +style +'" href="mailto:' +address[num] +'">' +linktext +'</a>')
        }
    }
}


// Tracking & privacy opt-out
// Sets permanent cookie to control other tracking cookies etc.
// Passed optional control value: nothing or 0 for opt out, 1 for opt in
function setOptOut(yesNo) 
{
    var dateNow = new Date();
    var expireDate = new Date();
    expireDate.setFullYear(dateNow.getFullYear() +10);
    var myDomain = '.mainlineshow.co.uk'; //TLD
    var optedOut = '0'; //default opted in
    if ( yesNo && yesNo == '1') optedOut = '1'
    
 //       expireDate.setMonth(3, 30);

    expireDate.setHours(23, 59, 59, 59);

    document.cookie = "o=" + optedOut +"; expires=" + expireDate.toGMTString() + "; path=/; domain=" + myDomain;

    if (optedOut == '1') alert('Thank you. You have now opted out of tracking on the Mainline Show Productions site (on this machine).'
             + '\n\nA permanent cookie has been set with your preference.');

    return
}

// Tracking privacy check
// Passed: nothing
// Returns: false if tracking opt-out was set (do not track), true otherwise (trackable)
function isOptedOut() {
  if (document.cookie && document.cookie.indexOf('o=1') > -1) 
  {
    return true
  }
  else return false

}  


// Urchin event tracker wrapper if not opted out
// Passed: category, action, optional label, optional score
// Returns: nothing
function mTrackEvent(mCategory, mAction, mLabel, mScore)
{
  if (isOptedOut() || !mCategory || !mAction) return;
  if (!mLabel) mLabel = '';
  if (!mScore) mScore = '';  

  _gaq.push(['_trackEvent', mCategory, mAction, mLabel, mScore]);
  return;
}



////////////////////////////////
