﻿function translateToHCode()
{
	if (typeof(tr_section) != "undefined")
	{
		tr_section = tr_section.replace(/\//, " - ");
	}

	if (typeof(tr_subsection) != "undefined")
	{
		tr_subsection = tr_subsection.replace(/\//, " - ");
	}

	if (typeof(tr_page_name) != "undefined")
	{
		s.pageName=tr_page_name.replace(/<[a-zA-Z\/][^>]*>/g,"");
		
		//remove session id
		s.pageName=s.pageName.replace(/\;jsessionid\=.{23}/g,"");
	}
	else
	{
		s.pageName="tr - " + document.location.pathname + " - " + document.title;
		
		//remove html
		s.pageName=s.pageName.replace(/<[a-zA-Z\/][^>]*>/g,"");
			
		//remove session id
		s.pageName=s.pageName.replace(/\;jsessionid\=.{23}/g,"");
	}

	if(typeof(tr_channel) != "undefined")
	{
		s.channel=(tr_channel.indexOf("tr - ")>=0)?tr_channel:"tr - " + tr_channel;
	}
	else if(typeof(tr_section) != "undefined")
	{
		s.channel=(tr_section.indexOf("tr - ")>=0)?tr_section.split('/')[0]:"tr - " + tr_section.split('/')[0];
	}
	else if (typeof(tr_hierarchy) != "undefined")
	{	
		s.channel=(tr_hierarchy.indexOf("tr - ")>=0)?tr_hierarchy.split('|')[0]:"tr - " + tr_hierarchy.split('|')[0];
	}
	else
	{
		s.channel="tr - nocategory";
	}

	s.server="theroot.com";
	s.pageType="";
	if (typeof(tr_sectionfront) != "undefined")
	{
		tr_sectionfront=tr_sectionfront.toLowerCase();
		s.prop1=(tr_sectionfront.indexOf("tr - ")>=0)?tr_sectionfront:"tr - " + tr_sectionfront;
	}
	if (typeof(tr_subsection) != "undefined")
	{
		tr_subsection = tr_subsection.toLowerCase();
		s.prop2=(tr_subsection.indexOf("tr - ")>=0)?tr_subsection:"tr - " + tr_subsection;
	}
	if (typeof(tr_content_type) != "undefined")
	{
		s.prop3=tr_content_type.toLowerCase();
	}
	if (typeof(tr_source) != "undefined")
	{
		s.prop4=tr_source.toLowerCase();
	}
	else
	{
		s.prop4="theroot.com";
	}

	if (typeof(tr_author) != "undefined")
	{
		s.prop5=tr_author.toLowerCase();
	}
	if (typeof(tr_search_keywords) != "undefined")
	{
		s.prop6=tr_search_keywords.toLowerCase();
	}
	if (typeof(tr_search_type) != "undefined")
	{
		s.prop7=tr_search_type.toLowerCase();
	}
	s.prop8="";
	s.prop9="";
	s.prop10="";
	s.prop11="";
	if (typeof(tr_content_id) != "undefined")
	{
		s.prop12=tr_content_id;
		if ( typeof(tr_application) != "undefined" && tr_application )
		{
			  s.prop13 = "" ;
		}
		if (typeof(tr_headline) != "undefined" && tr_content_id != "") 
		{
			s.prop13=tr_headline + " - " + tr_content_id;
		}
	}
	if (typeof(tr_page_num) != "undefined")
	{
		s.prop14=tr_page_num;
	}
	if (typeof(tr_printed) != "undefined") {
		s.prop19="printed page";
	}
	if (typeof(tr_search_result_count) != "undefined")
	{
		s.prop21=tr_search_result_count;
	}
	if (typeof(tr_blog_name) != "undefined")
	{
		s.prop25=tr_blog_name;
	}
	if (typeof(tr_application) != "undefined")
	{
		s.prop32=tr_application;
	}
	/* E-commerce Variables */
	s.campaign="";
	s.state="";
	s.zip="";
	s.events="";
	s.products="";
	s.purchaseID="";
	s.eVar1="";
	s.eVar2="";
	s.eVar3="";
	s.eVar4="";
	s.eVar5="";
	s.eVar6="";
	s.eVar7="";
	s.eVar8="";
	s.eVar9="";
	s.eVar10="";
	/* Hierarchy Variables */
	if (typeof(tr_hierarchy) != "undefined")
	{
		s.hier1= tr_hierarchy.toLowerCase();
	}
	else
	{
		s.hier1="nocategory";
	}
	s.hier2="theroot.com|" + s.hier1;
}
