/*
'	$Id: logging-code.js 1519 2007-10-23 08:40:21Z bernd $
'	$Date: 2007-10-23 10:40:21 +0200 (Di, 23 Okt 2007) $
'	$HeadURL: svn://server01/Fiat/trunk/touchclarity/logging-code.js $
'	$Revision: 1519 $
'
'	Name:		
'	Funktion:	
'
'	Aufruf:		-
'				
'	Projekt:	Fiat: wartung 2007
'				
'	Änderungen:	23.10.2007, BOH:	tagged
*/
/* Touch Clarity logging request. http://www.touchclarity.com
 * Copyright (c) Touch Clarity Ltd 2001-2002. All rights reserved. Patent Pending.
 * version 2.2.2
 */

if (tc_logging_active && tc_configured() && (typeof tc_done=="undefined" || tc_done==false))
{
	var tc_http="http"+(document.location.href.substring(0,6)=="https:"?"s":"")+"://";
	tc_server_url=tc_http+tc_server_url;
	var url=(typeof tc_page_alias!="undefined"? tc_page_alias : document.location.href);
	if (typeof tc_extra_info != "undefined") url += (document.location.search.length>0?"&":"?") + tc_extra_info;
	var products=(typeof tc_products=="undefined"?"" : tc_products);
	var category=(typeof tc_category=="undefined"?"" : tc_category);
	var ccID=(typeof tc_ccID=="undefined"?"" : tc_ccID);
	tc_make_log_call(url, products, category, ccID);
	if (typeof tc_referrer=="undefined") tc_referrer=document.referrer;
	if (document.layers) {
		document.writeln("<layer id='tc_layer' width=0 height=0 src='"+tc_log_page+"'></layer>");
	} else if (document.getElementById || document.all) {
		document.writeln("<iframe name='tc_iframe' src='"+tc_log_page+"' width=0 height=0 style='position:absolute;left:-100px'></iframe>");
	} else {
		document.write(tc_log_call);
	}
}
tc_done = true;

function tc_log(alias, products, category, ccID) {
	if (! tc_logging_active) return;
	if (typeof alias!="undefined"&&alias!=""&&alias.substring(0,1)=="/") alias=tc_http+document.location.host+alias;
	alias=((typeof alias=="undefined"||alias=="")? document.location.href : alias);
	tc_make_log_call(alias, products, category, ccID);
	if (document.layers) {
		document.layers["tc_layer"].src = tc_log_page;
	} else if (document.getElementById || document.all) {
		tc_iframe.location.reload(true);
	}
}

function tc_redirect(target, url, alias, winproperties, products, category, ccID) {
	if (typeof url=="undefined"||url=="") return;
	if (typeof target=="undefined"||target==""||target=="_self") {
		if (tc_logging_active) {
			tc_timer = new Image();
			tc_timer.onload = function() { window.location.href=url; }
			tc_timer.onerror = function() { window.location.href=url; }
			tc_timer.src = tc_make_image_call(url, alias, products, category, ccID);
			tc_timeout_id = setTimeout("window.location.href='"+url+"'", tc_timeout);
		} else { document.location.href=url; }
	} else if (typeof target=="object" && target.document) {
		if (tc_logging_active) {
			tc_timer = new Image();
			tc_timer.src = tc_make_image_call(url, alias, products, category, ccID);
		}
		target.location.href = url;
	} else {
		tc_open_window(target, url, alias, winproperties, products, category, ccID);
	}
}

function tc_open_window(name, url, alias, winproperties, products, category, ccID) {
	if (typeof url=="undefined"||url=="") return;
	if (tc_logging_active) {
		tc_timer = new Image();
		tc_timer.src = tc_make_image_call(url, alias, products, category, ccID);
	}
	if (typeof winproperties=="undefined")
		return window.open(url, name);
	else 
		return window.open(url, name, winproperties);
}


function tc_make_image_call(url, alias, products, category, ccID) {
	if (url.substring(0,1)=="/") url=tc_http+document.location.host+url;
	var is_alias = false;
	if (url.substring(0,4)=="http" && url.substring(0,(tc_http+document.location.host).length) != tc_http+document.location.host) {
		url = "/external-site/"+url.substring("http://".length);
		is_alias = true;
	}
	var log_url = escape(url);
	while (log_url.length > 2000)
		log_url = log_url.substring(0, url.lastIndexOf(escape("&")));
	if (typeof alias=="undefined"||alias=="") {
		log_url = tc_server_url+"/i?siteID="+tc_site_id+"&location="+log_url;
		if (typeof tc_is_alias=="boolean" && tc_is_alias == true) is_alias = true;
	} else {
		if (alias.substring(0,1)=="/") alias=tc_http+document.location.host+alias;
		alias = escape(alias);
		log_url = tc_server_url+"/i?siteID="+tc_site_id+"&location="+alias;
	}
	log_url +=(typeof ccID=="undefined"||ccID=="" ? "" : "&ccID="+escape(ccID));
	log_url +=(typeof products=="undefined"||products=="" ? "" : "&"+products);
	log_url +=(typeof category=="undefined"||category=="" ? "" : "&cat="+escape(category));
	var rand=new Date();
	log_url += "&" + rand.getTime();
	return log_url;
}

function tc_make_log_call(url, products, category, ccID) {
	if (typeof url=="undefined"||url=="") url=document.location.href;
	if (url.substring(0,4)=="http" && url.substring(0,(tc_http+document.location.host).length) != tc_http+document.location.host) 
		url = "/external-site/"+url.substring("http://".length);
	if (url.substring(0,4)!="http" && url.substring(0,1)!="/") url="/"+url;
	if (url.substring(0,1)=="/") url=tc_http+document.location.host+url;
	url = escape(url);
	while (url.length > 2000)
		url = url.substring(0, url.lastIndexOf(escape("&")));
	tc_log_call = tc_server_url+"/l?siteID="+tc_site_id+"&location="+url;
	tc_log_call +=tc_mark_alias(unescape(url));
	tc_log_call +=(typeof ccID=="undefined"||ccID=="" ? "" : "&ccID="+escape(ccID));
	tc_log_call +=(typeof products=="undefined"||products=="" ? "" : "&"+products);
	tc_log_call +=(typeof category=="undefined"||category=="" ? "" : "&cat="+escape(category));
	var rand=new Date();
	tc_log_call += "&" + rand.getTime();
	tc_log_call = "<scr"+"ipt src='"+tc_log_call+"'></scr"+"ipt>";
}

function tc_mark_alias(url) {
	if (typeof tc_is_alias != "undefined" && tc_is_alias == true)
		return "&alias=true";
	var base = url.substring(0, url.indexOf("?")>0 ? url.indexOf("?") : url.length);
	return (document.location.href.indexOf(base) != 0 ? "&alias=true" : "");
}

function tc_configured() {
	if (typeof tc_server_url =="undefined" || typeof tc_site_id == "undefined") 
		return false;
	if(typeof tc_log_page=="undefined"||tc_log_page=="") tc_log_page = "/touchclarity/logging.html";
	tc_default_timeout = 5000;
	tc_timeout=(typeof tc_timeout=='undefined'?tc_default_timeout:tc_timeout*1000);
	return true;
}
/*	       END $Id: logging-code.js 1519 2007-10-23 08:40:21Z bernd $ END   '*/
