function OmnitureParams() {
	this.pageName = ""; 
	this.channel = ""; 
	this.prop1 = "";
	this.prop2 = "";
	this.prop3 = "";
	this.hier1 = "";
	this.prop4 = "";
	this.prop5 = "";
	this.prop6 = "";
}
var delimiter = ":" ;

function getOmnitureParamsNews(channel, linkArr, contentType, title, contentID, customPageName ){
	var p = new OmnitureParams();
	p.channel = channel.toLowerCase();
	contentType = contentType > "" ? contentType.toLowerCase() : "" ;
	title = title > "" ? title.toLowerCase() : "";
	customPageName = customPageName > "" ? customPageName.toLowerCase() : "";
	linkArr = processLinkArr(linkArr, p.channel);
	for ( i = 0 ; i < linkArr.length ; i++ ){ linkArr[i] = linkArr[i].toLowerCase();  }

	if ( linkArr.length == 1 ){
		p.pageName = [channel, linkArr[0] ].join(delimiter) ; 
		p.prop1 = [ channel, linkArr[0] ].join(delimiter) ;
		p.prop2 = [ channel, linkArr[0] ].join(delimiter) ;
		p.prop3 = [ channel, linkArr[0] ].join(delimiter) ;
		p.hier1 = p.prop1; 

	} else if ( linkArr.length == 2 ){
		if ( !isNaN( parseInt( linkArr[1] ) ) ){
			var contentPageName = getContentPageName(contentType);
			p.pageName = [channel, linkArr[0], contentPageName, contentID + urlEscape(title) ].join(delimiter) ; 
			p.prop1 = [ channel, linkArr[0] ].join(delimiter) ;
			p.prop2 = [ channel, linkArr[0], contentPageName ].join(delimiter) ;
			p.prop3 = [ channel, linkArr[0], contentPageName ].join(delimiter) ;
			p.hier1 = p.prop2 ; 
			p.prop4 = contentType ; 
			p.prop5 = title ; 
			p.prop6 = parseInt(contentID) ; 	
		} else {
			p.pageName = [channel, linkArr[0], linkArr[1] ].join(delimiter) ; 
			p.prop1 = [ channel, linkArr[0] ].join(delimiter) ;
			p.prop2 = [ channel, linkArr[0], linkArr[1] ].join(delimiter) ;
			p.prop3 = [ channel, linkArr[0], linkArr[1] ].join(delimiter) ;
			p.hier1 = p.prop2 ; 
		}

	}
	p.prop15 = getUserInfoString();
	p.eVar15 = s.prop21;	
	return p;
}

function processLinkArr(arr, channel ){
	if ( channel == "news" ){
		if ( arr[0] == "police" ){
			arr.shift();			
		}
	}
	return arr;
}
function getContentPageName(ct){
	var h = {
		"articles" : "article", 
		"news reports" : "news report", 
		"member submissions" : "article"
	}
	return h[ct] + " page" ; 
}
function getOmnitureParams( pageType, channel, section, category, contentType, title, contentID, customPageName, source1, source2, source3, columnist, vcTip, vucTip) {
	var p = new OmnitureParams();

	pageType = pageType.toLowerCase() ;  
	channel = channel.toLowerCase() ;  
	section = section.toLowerCase() ;  
	category =  ( category > "" ? category.toLowerCase() : "" )  ;  
	contentType = ( contentType > "" ? contentType.toLowerCase() : contentType );  
	title = ( title > "" ? title.toLowerCase() : "" );  
	contentID = ( contentID > "" ? contentID.toLowerCase()  : contentID ) ;    
	source1 = ( source1 > "" ? source1.toLowerCase()  : source1 ) ;    
	source2 = ( source2 > "" ? source2.toLowerCase()  : source2 ) ;    
	source3 = ( source3 > "" ? source3.toLowerCase()  : source3 ) ;    
	columnist = ( columnist > "" ? columnist.toLowerCase()  : columnist ) ;    
	vcTip = ( vcTip > "" ? vcTip.toLowerCase()  : vcTip ) ;    
	vucTip = ( vucTip > "" ? vucTip.toLowerCase()  : vucTip ) ;    

	switch ( pageType ){
		case "main_page" :
			p = mainPageParams(channel, section );
		break;
		case "cat_page" :
			p = catPageParams(channel, category, contentType, title, contentID );
		break;
		case "cat_all_content_page" :
			p = catAllContentPageParams( channel, section, category,  contentType, title, contentID );
		break;
		case "cat_content_page" :
			p = catContentPageParams( channel, section, category,  title, contentID, source1, source2, source3, columnist, vcTip, vucTip );
		break;
		default : p = null;
	}
	if ( typeof customPageName != "undefined" ) {
		p.pageName = customPageName.toLowerCase() ; 
	}
	p.prop15 = getUserInfoString();
	p.eVar15 = s.prop21;	
	
	return p;
}
function mainPageParams(channel, section ){
	var params = new OmnitureParams();
	params.pageName = [channel, section].join(delimiter);
	params.channel = channel ; 
	params.prop1 = [channel, section].join(delimiter) ; 
	params.hier1 = [channel, section].join(delimiter) ; 
	return params ;
}
function catPageParams(channel, category, contentType, title, contentID ){
	var params = new OmnitureParams();
	category = clearCategoryUrl( category );
	params.pageName = [channel, category].join(delimiter);
	params.channel = channel ; 
	params.prop1 = [channel, category].join(delimiter) ; 
	params.prop2 = [channel, category].join(delimiter) ; 
	params.prop3 = [channel, category].join(delimiter) ;
	params.hier1 = [channel, category].join(delimiter) ; 
	params.prop4 = contentType ; 
	params.prop5 = title ; 
	params.prop6 = contentID ; 	

	return params ;
}
function catAllContentPageParams( channel, section, category, contentType, title, contentID ){
	var params = new OmnitureParams();

	category = clearCategoryUrl( category );
	params.pageName = [channel, category, section].join(delimiter);
	params.channel = channel ; 
	params.prop1 = [channel, category].join(delimiter) ; 
	params.prop2 = [channel, category, section].join(delimiter) ; 
	params.prop3 = [channel, category, section].join(delimiter); 
	params.hier1 = [channel, category, section].join(delimiter); 
	params.prop4 = contentType ; 
	params.prop5 = title ; 
	params.prop6 = contentID ; 	
	
	return params ; 
}
function catContentPageParams( channel, section, category, title, contentID, source1, source2, source3, columnist, vcTip, vucTip ){
	var params = new OmnitureParams();
	category = clearCategoryUrl( category );
	var contentPageName = getContentNameBySection( section ) + " page" ; 
	var contentItemTitle = contentID + urlEscape(title);
	params.pageName = [channel, category, contentPageName, contentItemTitle].join(delimiter);
	params.channel = channel ; 
	params.prop1 = [channel, category].join(delimiter) ; 
	params.prop2 = [channel, category, contentPageName].join(delimiter) ; 
	params.prop3 = [channel, category, contentPageName].join(delimiter); 
	params.hier1 = [channel, category, contentPageName].join(delimiter); 
	params.prop4 = getContentNameBySection(section) ; 
	params.prop5 = title ; 
	params.prop6 = contentID ; 	
  params.prop14 = source1; 	
  params.prop17 = source2; 	
  params.prop18 = source3; 	
  params.prop16 = columnist;
  params.prop19 = vcTip;
  params.prop20 = vucTip;
	
	return params ; 
}

function getContentNameBySection( section ){
	if (section == "articles" ) return "article" ; 
	else if (section == "links") return "resource";
	else if (section == "preview_articles") return "preview article";
	else if (section == "preview_tips") return "preview tip";
	else if ( section == "tips" ) return "tip";
	else if ( section == "official-announcements" || section == "press-releases" || section == "newdeliveries") return "press release";
	else if ( section == "clip" || section == "videos" || section == "comingsoon" ) return "video";
	else if ( section == "job listings" ) return "job listing";
	else if ( section == "interest-request" ) return "interest requests";
	else if ( section == "grants" ) return "grant";
	else if ( section == "alerts" ) return "alert";
	else if ( section == "events" ) return "training event";
	else if ( section == "providers" ) return "customer";
	else if ( section == "products" ) return "product";
	else if ( section == "policeone team" ) return "policeone team";
	else if ( section == "member submissions" ) return "member submission";
	else if ( section == "news reports") return "news report";
	else if ( section == "manufacturers" || section == "technology-providers" || section == "service-providers" || section == "distributors") return "sponsor";
}

function getUserInfoString(){
	return ( userInfo ? userInfo.toLowerCase(): "anonymous" );
}

function clearCategoryUrl( url ){
	var reMinus = /-/ig
	var reSlash = /\//ig
	url = url.replace(reMinus, " ");
	url = url.replace(reSlash, " "); // replace slashes into url to spaces
	return trim(url) ; 
}

function trim(string){ return string.replace(/(^\s+)|(\s+$)/g, ""); }

function urlEscape(str) {
//-- replace all but letters and numbers by "-"
	if(!(str > "")) str = "";

	str = str.replace(/"/gi,"");
	str = removeHTML(str);
	str = str.replace(/ /gi,"-");
	
	str = str.replace(/['`’]/gi,"");
	str = str.replace(/[^a-z0-9-]/gi,"-");
	while(str != str.replace(/--/gi,"-")) str = str.replace(/--/gi,"-");
	
	str = trim(str.replace(/-/gi," ")).replace(/ /gi,"-");

	return "-" + str;	
}
function removeHTML (t) {

	var str = String(t).replace(/&nbsp;/gi," ");
	str = str.replace(/(<\s*[^>]*\s*>)/gi, "");
	return str;
	
}

