/* Touch Clarity logging request. http://www.touchclarity.com
 * Site identifier code for tag testing
 * Copyright (c) Touch Clarity Ltd 2001-2006. All rights reserved. Patent Pending.
 *
 * Change the value of tc_logging_active to switch off logging on the site.
 * 
 * Release v3.5.2#254,300
 */

if (typeof tc_logging_active == 'undefined') tc_logging_active = true;
tc_site_id = 192;

//tc_server_url = "test2.tc-prelive.com";
tc_server_url = "theaa.touchclarity.com"; 
tc_log_path = '/touchclarity';

/* Touch Clarity customisations for client - please do not edit below this point */

// pickup Map Results extra param for targetting
if (typeof tc_aa_mapresults != 'undefined') tc_extra_info = tc_aa_mapresults;

document.write("<scr"+"ipt language='JavaScript' type='text/javascript' src='"+tc_log_path+"/logging-code.js'></scr"+"ipt>");


/* Customisations for the AA */
// customer cookie from thank you pages
var tc_controller = {
  buy_url : window.location.pathname,
  buy_pattern : /\/services\/insuranceandfinance\/([A-Za-z]+)\/n_payment_confirmation.jsp/,
  start : function(){
    if (this.buy_url.match(this.buy_pattern)) {
        var product = this.buy_pattern.exec(this.buy_url)[1];
        if (typeof console != 'undefined' && typeof console.log != 'undefined') console.log("Found " + product);
        this.setCookie("tc_ph_"+product,"true",365);
    }
    if (typeof tc_containers != 'undefined') {
		var motor=0, travel=0, home=0;
        var ca = document.cookie.split(';');
        if (typeof tc_extra_info == 'undefined') tc_extra_info = '';
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			c = c.substring(0, c.indexOf('='));
			if (c.match(/tc_ph_[A-Za-z]+/)) tc_extra_info += '&'+c+'=true';
			if (c=='tc_ph_motor') motor=1;
			if (c=='tc_ph_travel') travel=1;
			if (c=='tc_ph_home') home=1;
		}
		tc_extra_info += '&tc_ph_ins='+motor+home+travel;
        if (typeof console != 'undefined' && typeof console.log != 'undefined') console.log("Products " + tc_extra_info);
    }
  },
  setCookie : function(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=/";
  }
}
tc_controller.start();
