// *************************
// *** MAKE CHANGES HERE *** 
// *************************

// set ON/OFF flag
var wsstag_enabled = "true";
var wsstag_debug   = 0;

// set prod env value
var wsstag_prodEnv = "prod";

// setup paths 
// wsstag_jsConfigURL and wsstag_jsImplURL are declared and stage in footer.ssi 

if (wsstag_debug == 1) alert ("Config Files: \n" + wsstag_jsConfigURL + "\n" + wsstag_jsImplURL);

// **************************************
// *** DO NOT MAKE CHANGES BELOW HERE *** 
// **************************************
var myURL = "";
var myTitle = "";

var bangIndex = document.title.indexOf("|");

if (bangIndex != -1) {
   myTitle = document.title.substring(0,bangIndex);  // remove anything after the exclamation point.     
    myTitle.replace(/^\s*/, '').replace(/\s*$/, '');  // remove leading and trailing space.
} else {
 myTitle = document.title;
}

if ( (myTitle == '') || (myTitle == null) ) {
  myTitle = "No Title";
}

var quesIndex = document.URL.indexOf("?");
if (quesIndex != -1) {
	 myUrl = document.URL.substring(0,quesIndex);  // remove anything after the question mark
} else {
	 myUrl = document.URL;
}
var reg_expr = new RegExp(".*//*(.*)");   // this looks for the content after the last slash
var page_matches = myUrl.match(reg_expr);

var wsstag_pageId = myTitle;

if ( (page_matches[1] != '') && (page_matches[1] != null) ) {
     wsstag_pageId = myTitle + " - " + page_matches[1];
}

// determine current environment
var wsstag_hostname = location.hostname;
// check for typical non-prod domains as well as IP addresses 
// note: for teamsite preview the domain would start with mbe which is the mol proxy...
var wsstag_regex = new RegExp("\\b(dev|stage|test|localhost|(mbe.*)|\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})\\b", "i");
var wsstag_matches = wsstag_hostname.match(wsstag_regex);

var wsstag_envResult = "";
if(wsstag_matches == null) {  
   wsstag_envResult = "prod";
} else {
   wsstag_envResult = wsstag_matches[1].toLowerCase();
}

if (wsstag_debug == 1) alert ("Hostname: " + wsstag_hostname + " Env Result: " + wsstag_envResult);

//WSS Content Category						
if ( (typeof(wsstag_category) == "undefined") || (wsstag_category == '') || (wsstag_category == null) ) { 						   
   wsstag_category = "No Category";
}
wsstag_contentCategory = wsstag_category + ';' + wsstag_region;		

if (wsstag_debug == 1) {
	 alert ("content Category: " + wsstag_contentCategory + "\ncontent Page Id: " + wsstag_pageId)
}

if ((wsstag_envResult == wsstag_prodEnv) || (wsstag_enabled == "true")) {
   document.write("<scr"+"ipt src=\""+wsstag_jsConfigURL+"\"></scr"+"ipt>");
   document.write("<scr"+"ipt defer src=\""+wsstag_jsImplURL+"\"></scr"+"ipt>");
   if (wsstag_debug == 1) alert ("WSS Complete.");   
} 

