﻿function translateToHCode()
{
	if (typeof(nw_section) != "undefined")
	{
		nw_section = nw_section.replace(/\//, " - ");
	}

	if (typeof(nw_subsection) != "undefined")
	{
		nw_subsection = nw_subsection.replace(/\//, " - ");
	}

	if (typeof(nw_page_name) != "undefined")
	{
		s.pageName=nw_page_name.replace(/<[a-zA-Z\/][^>]*>/g,"");
		
		//remove session id
		s.pageName=s.pageName.replace(/\;jsessionid\=.{23}/g,"");
	}
	else
	{
		s.pageName="nw - " + 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(nw_channel) != "undefined")
	{
		s.channel=(nw_channel.indexOf("nw - ")>=0)?nw_channel:"nw - " + nw_channel;
	}
	else if(typeof(nw_section) != "undefined")
	{
		s.channel=(nw_section.indexOf("nw - ")>=0)?nw_section.split('/')[0]:"nw - " + nw_section.split('/')[0];
	}
	else if (typeof(nw_hierarchy) != "undefined")
	{	
		s.channel=(nw_hierarchy.indexOf("nw - ")>=0)?nw_hierarchy.split('|')[0]:"nw - " + nw_hierarchy.split('|')[0];
	}
	else
	{
		s.channel="nw - nocategory";
	}

	s.server="newsweek.com";
	s.pageType="";
	if (typeof(nw_sectionfront) != "undefined")
	{
		nw_sectionfront=nw_sectionfront.toLowerCase();
		s.prop1=(nw_sectionfront.indexOf("nw - ")>=0)?nw_sectionfront:"nw - " + nw_sectionfront;
	}
	if (typeof(nw_subsection) != "undefined")
	{
		nw_subsection = nw_subsection.toLowerCase();
		s.prop2=(nw_subsection.indexOf("nw - ")>=0)?nw_subsection:"nw - " + nw_subsection;
	}
	if (typeof(nw_content_type) != "undefined")
	{
		s.prop3=nw_content_type.toLowerCase();
	}
	if (typeof(nw_source) != "undefined")
	{
		s.prop4=nw_source.toLowerCase();
	}
	else
	{
		s.prop4="newsweek.com";
	}

	if (typeof(nw_author) != "undefined")
	{
		s.prop5=nw_author.toLowerCase();
	}
	if (typeof(nw_search_keywords) != "undefined")
	{
		s.prop6=nw_search_keywords.toLowerCase();
	}
	if (typeof(nw_search_type) != "undefined")
	{
		s.prop7=nw_search_type.toLowerCase();
	}
	s.prop8="";
	s.prop9="";
	s.prop10="";
	s.prop11="";
	if (typeof(nw_content_id) != "undefined")
	{
		s.prop12=nw_content_id;
		if ( typeof(nw_application) != "undefined" && nw_application )
		{
			  s.prop13 = "" ;
		}
		if (typeof(nw_headline) != "undefined" && nw_content_id != "") 
		{
			s.prop13=nw_headline + " - " + nw_content_id;
		}
	}
	if (typeof(nw_page_num) != "undefined")
	{
		s.prop14=nw_page_num;
	}
	if (typeof(nw_printed) != "undefined") {
		s.prop19="printed page";
	}
	if (typeof(nw_search_result_count) != "undefined")
	{
		s.prop21=nw_search_result_count;
	}
	if (typeof(nw_blog_name) != "undefined")
	{
		s.prop25=nw_blog_name;
	}
	if (typeof(nw_application) != "undefined")
	{
		s.prop32=nw_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(nw_hierarchy) != "undefined")
	{
		s.hier1= nw_hierarchy.toLowerCase();
	}
	else
	{
		s.hier1="nocategory";
	}
	s.hier2="newsweek.com|" + s.hier1;
}

