﻿function translateToHCode()
{
	if (typeof(sp_section) != "undefined")
	{
		sp_section = sp_section.replace(/\//, " - ");
	}

	if (typeof(sp_subsection) != "undefined")
	{
		sp_subsection = sp_subsection.replace(/\//, " - ");
	}

	if (typeof(sp_page_name) != "undefined")
	{
		s.pageName=sp_page_name.replace(/<[a-zA-Z\/][^>]*>/g,"");
		
		//remove session id
		s.pageName=s.pageName.replace(/\;jsessionid\=.{23}/g,"");
	}
	else
	{
		s.pageName="sp - " + 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(sp_channel) != "undefined")
	{
		s.channel=(sp_channel.indexOf("sp - ")>=0)?sp_channel:"sp - " + sp_channel;
	}
	else if(typeof(sp_section) != "undefined")
	{
		s.channel=(sp_section.indexOf("sp - ")>=0)?sp_section.split('/')[0]:"sp - " + sp_section.split('/')[0];
	}
	else if (typeof(sp_hierarchy) != "undefined")
	{	
		s.channel=(sp_hierarchy.indexOf("sp - ")>=0)?sp_hierarchy.split('|')[0]:"sp - " + sp_hierarchy.split('|')[0];
	}
	else
	{
		s.channel="sp - nocategory";
	}

	s.server="sprig.com";
	s.pageType="";
	if (typeof(sp_sectionfront) != "undefined")
	{
		sp_sectionfront=sp_sectionfront.toLowerCase();
		s.prop1=(sp_sectionfront.indexOf("sp - ")>=0)?sp_sectionfront:"sp - " + sp_sectionfront;
	}
	if (typeof(sp_subsection) != "undefined")
	{
		sp_subsection = sp_subsection.toLowerCase();
		s.prop2=(sp_subsection.indexOf("sp - ")>=0)?sp_subsection:"sp - " + sp_subsection;
	}
	if (typeof(sp_content_type) != "undefined")
	{
		s.prop3=sp_content_type.toLowerCase();
	}
	if (typeof(sp_source) != "undefined")
	{
		s.prop4=sp_source.toLowerCase();
	}
	else
	{
		s.prop4="sprig.com";
	}

	if (typeof(sp_author) != "undefined")
	{
		s.prop5=sp_author.toLowerCase();
	}
	if (typeof(sp_search_keywords) != "undefined")
	{
		s.prop6=sp_search_keywords.toLowerCase();
	}
	if (typeof(sp_search_type) != "undefined")
	{
		s.prop7=sp_search_type.toLowerCase();
	}
	s.prop8="";
	s.prop9="";
	s.prop10="";
	s.prop11="";
	if (typeof(sp_content_id) != "undefined")
	{
		s.prop12=sp_content_id;
		if ( typeof(sp_application) != "undefined" && sp_application )
		{
			  s.prop13 = "" ;
		}
		if (typeof(sp_headline) != "undefined" && sp_content_id != "") 
		{
			s.prop13=sp_headline + " - " + sp_content_id;
		}
	}
	if (typeof(sp_page_num) != "undefined")
	{
		s.prop14=sp_page_num;
	}
	if (typeof(sp_printed) != "undefined") {
		s.prop19="printed page";
	}
	if (typeof(sp_search_result_count) != "undefined")
	{
		s.prop21=sp_search_result_count;
	}
	if (typeof(sp_blog_name) != "undefined")
	{
		s.prop25=sp_blog_name;
	}
	if (typeof(sp_application) != "undefined")
	{
		s.prop32=sp_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(sp_hierarchy) != "undefined")
	{
		s.hier1= sp_hierarchy.toLowerCase();
	}
	else
	{
		s.hier1="nocategory";
	}
	s.hier2="sprig.com|" + s.hier1;
}
