/* TouchClarity 
 * Copyright (c) Omniture 2001-2007. All rights reserved. Patent Pending.
 * Privacy Policy at http://www.touchclarity.com/privacy/
 */
/************************** CONFIG SECTION **************************/
/* You may add or alter any code config here. */
var tc_site_id = window.tc_site_id || 462;
var tc_server_url = window.tc_server_url || "touchclarity.rbs.co.uk";
var tc_log_path = window.tc_log_path || "/templates/script/touchclarity";
var tc_logging_active = window.tc_logging_active || true;

/************************** PLUGINS SECTION *************************/

// #597 capture login events
// apply logic on page load by finding classes on links
function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && document.all)? document.all : 
    oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}
var tc_controller = {
  list : new Array,
  register : function(sheet){
    tc_controller.list.push(sheet);
  },
  start : function(){
    tc_controller.addLoadEvent(function(){
      tc_controller.apply();
    });
  },
  apply : function(){
    for (h=0;sheet=tc_controller.list[h];h++){
      for (selector in sheet){
        list = getElementsByClassName(document, "a", selector);		
        if (!list){
          continue;
        }
        for (i=0;element=list[i];i++){
          sheet[selector](element);
        }
      }
    }
  },
  addLoadEvent : function(func){
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
      window.onload = func;
    } else {
      window.onload = function() {
        oldonload();
        func();
      }
    }
  }
}
tc_controller.start();

// cookie utils
function tc_createcookie(name,value,days)
{
  if (days)
  {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else var expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function tc_readcookie(name)
{
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++)
  {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

function tc_erasecookie(name)
{
  tc_createcookie(name,"",-1);
}

// define client side logic
var myrules = {
  'TCID_iscustomer' : function(element){
    element.onclick = function(){
      // set a cookie so we know they have clicked on login to indicate they are a customer
      tc_createcookie("TCID_iscustomer", "true", 180);
    }
  }
};
tc_controller.register(myrules);

// if the user is a customer pass this to the modeller
if (typeof tc_extra_info == 'undefined') tc_extra_info = '';
if (tc_readcookie("TCID_iscustomer")){
  tc_extra_info += "tc_isCustomer="+tc_readcookie("TCID_iscustomer"); 
}
else {
  tc_extra_info += "tc_isCustomer=false"; 
}


/************* DO NOT ALTER ANYTHING BELOW THIS LINE ! **************/
window.undefined=window.undefined;window.omtr=window.omtr||{};window.omtr.tc=window.omtr.tc||{Version:"4.3",Vendor:"Omniture",Product:"TouchClarity",Filename:"tc_logging.js"};omtr.tc.logger=omtr.tc.logger||{loaded:true,init:function(){this.tc_loader();},tc_configured:function(){tc_tag_version="4.3";tc_dtimeout=5000;tc_d_loc=window.location;tc_sent=0;if(typeof tc_server_url==tc_ud||typeof tc_site_id==tc_ud){return false;}if(typeof tc_log_page==tc_ud||tc_log_page==""){tc_log_page="tc_targeting.html";}tc_layer=(document.layers?1:0);tc_frame=(document.getElementById||document.all?1:0);tc_timeout=(typeof tc_timeout==tc_ud?tc_dtimeout:tc_timeout*1000);tc_encfn=(typeof encodeURIComponent!=tc_ud?encodeURIComponent:escape);tc_http="http"+(tc_d_loc.href.substring(0,6)=="https:"?"s":"")+"://";tc_server_url=tc_http+tc_server_url;tc_url=((typeof tc_page_alias!=tc_ud)?tc_page_alias:tc_d_loc.href);if(typeof tc_extra_info!=tc_ud){tc_url+=(tc_url.indexOf("?")>0?"&":"?")+tc_extra_info;}tc_extra_info="";tc_products=(typeof tc_products==tc_ud?"":tc_products);tc_ccs=new Array();tc_referrer=(typeof tc_referrer!=tc_ud&&tc_referrer!=""&&tc_referrer!=null?tc_referrer:(typeof document.referrer==tc_ud?tc_ud:(document.referrer==null?"null":(document.referrer==""?"empty":document.referrer))));tc_time=new Date().getTime();return true;},tc_log:function(_1,_2,_3){if(!tc_logging_active){return;}_1=omtr.tc.logger.tc_fixURL(_1);tc_image=new Image();tc_image.src=omtr.tc.logger.tc_get_log_URL("i",_1,tc_products,new Date().getTime(),_3);},tc_redirect:function(_4,_5,_6,_7,_8,_9){if(typeof _5==tc_ud||_5==""){return;}if(typeof _9==tc_ud||_9==""){_9="tc_d_loc.href='"+_5+"'";}_5=omtr.tc.logger.tc_fixURL(_5);if(typeof _6==tc_ud){_6=_5;}_6=omtr.tc.logger.tc_fixURL(_6);if(typeof _4==tc_ud||_4==""||_4=="_self"){if(tc_logging_active){tc_timer=new Image();tc_timer.onload=function(){eval(_9);clearTimeout(tc_timeout_id);};tc_timer.onerror=function(){eval(_9);clearTimeout(tc_timeout_id);};tc_timer.src=omtr.tc.logger.tc_get_log_URL("i",_6,_8,new Date().getTime());tc_timeout_id=setTimeout(_9,tc_timeout);}else{eval(_9);}}else{if(typeof _4=="object"&&_4.document){if(tc_logging_active){tc_timer=new Image();tc_timer.src=omtr.tc.logger.tc_get_log_URL("i",_6,_8);}_4.location.href=_5;}else{omtr.tc.logger.tc_open_window(_4,_5,_6,_7,_8);}}},tc_open_window:function(_a,_b,_c,_d,_e){if(typeof _b==tc_ud||_b==""){return false;}if(tc_logging_active){tc_timer=new Image();tc_timer.src=omtr.tc.logger.tc_get_log_URL("i",_c,_e,new Date().getTime());}if(typeof _d==tc_ud){return window.open(_b,_a);}else{return window.open(_b,_a,_d);}},tc_get_log_URL:function(_f,_10,_11,_12,_13){if(typeof _f==tc_ud){_f="i";}var url=tc_server_url+"/"+_f+"?siteID="+tc_site_id;if(_f!="d"){url+="&ts="+(typeof _12!=tc_ud?_12:tc_time);var al=omtr.tc.logger.tc_isAlias(_10);if(typeof tc_containers!=tc_ud){for(var cc=0;cc<tc_containers.length;cc++){url+="&ccID="+tc_containers[cc];}}if(_f=="c"){url+="&log=no";}if(al){url+="&alias=true";}if((typeof _11!=tc_ud)&&_11.length){url+="&prod="+tc_encfn(_11);}if(typeof _13!=tc_ud){url+=_13;}if(_10==tc_ud){_10=tc_d_loc;}_10=tc_encfn(_10);while(_10.length>1999-url.length){_10=_10.substring(0,_10.lastIndexOf(tc_encfn("&")));}url+="&location="+_10;var dg=new Object();dg.tagv=tc_tag_version;dg.tz=0-(new Date().getTimezoneOffset());dg.r=tc_encfn(tc_referrer);dg.title=""+tc_encfn(document.title);if(al){dg.aliased=tc_encfn(tc_d_loc.href);}if(screen){dg.cd=screen.colorDepth;dg.ah=screen.availHeight;dg.aw=screen.availWidth;dg.sh=screen.height;dg.sw=screen.width;dg.pd=screen.pixelDepth;}for(var key in dg){if((typeof (dg[key])!=("function"))&&(typeof (dg[key])!=("array"))&&(typeof (dg[key])!=("object"))){var _19="&"+key+"="+dg[key];if(url.length+_19.length<2000){url+=_19;}else{break;}}}}else{url+="&dlts="+tc_time+"&dl="+(new Date().getTime()-tc_time);}return url;},tc_fixURL:function(url){if(url==""){return tc_d_loc.href;}if((url.substring(0,4)!="http")&&(url.substring(0,1)!="/")){url=tc_d_loc.pathname.substring(0,tc_d_loc.pathname.lastIndexOf("/")+1)+url;}if(url.substring(0,1)=="/"){url=tc_http+tc_d_loc.host+url;}return url;},tc_isAlias:function(_1b){_1b=(typeof _1b!=tc_ud?_1b:(typeof tc_page_alias==tc_ud?"":tc_page_alias));_1b=omtr.tc.logger.tc_fixURL(_1b);if(_1b.indexOf("?")>0){_1b=_1b.substring(0,_1b.indexOf("?"));}return (_1b!=tc_http+tc_d_loc.host+tc_d_loc.pathname);},tc_loader:function(){var _1c=new Image();tc_ud="undefined";if((typeof tc_containers!="undefined")&&(tc_containers.length>0)){return;}else{if((typeof tc_logging_active!="undefined"&&tc_logging_active)&&omtr.tc.logger.tc_configured()&&(typeof tc_done==tc_ud||tc_done===false)){url=omtr.tc.logger.tc_fixURL(tc_url);_1c.onload=function(){tc_sent=true;};_1c.src=omtr.tc.logger.tc_get_log_URL("i",url,tc_products,tc_time);}tc_done=true;return _1c;}},tc_optimise:function(id,_1e){return false;}};var tc_log=omtr.tc.logger.tc_log;var tc_redirect=omtr.tc.logger.tc_redirect;var tc_open_window=omtr.tc.logger.tc_open_window;var tc_optimise=window.tc_optimise||omtr.tc.logger.tc_optimise;var tc_site_id=window.tc_site_id||425;var tc_server_url=window.tc_server_url||"tagging-qa.touchclarity.com";var tc_log_path=window.tc_log_path||"/touchclarity";var tc_logging_active=window.tc_logging_active||true;omtr.tc.logger.init();