// ****************************
// *** External Cobrand Config
// *** Last Updated 10-03-08
// ****************************

// set account info
var wsstag_prodAcct = "DM541222C1EV";

// js to retrieve and Page filename from url
var wsstag_filename = "Indeterminate";

//var wsstag_path = document.location.pathname;
var wsstag_re = new RegExp ('(.*)/(.*)') ;

if(document.referrer.indexOf(".") > -1) {
    var wsstag_hbxLoc = document.referrer;
}
else{
    var wsstag_hbxLoc = document.location.href;
}

var wsstag_matches = wsstag_hbxLoc.match(wsstag_re); 

// need to confirm we have a match
if (wsstag_matches) {
   if (wsstag_matches[2] == "") {
      wsstag_matches[2] = "index.html";
   }
   if(typeof(wsstag_category)=="undefined"){
   		var wsstag_category = wsstag_matches[1];
   }
   var wsstag_re2 = new RegExp ('.*/(.*)/(.*)') ;
   var wsstag_matches2 = document.location.href.match(wsstag_re2);
   wsstag_filename = wsstag_matches2[1] + "/" + wsstag_matches2[2];
}
else{
	var wsstag_re3 = new RegExp ('.*/(.*)') ;
	var wsstag_matches3 = wsstag_hbxLoc.match(wsstag_re3); 
	
	// need to confirm we have a match
	if (wsstag_matches3) {
	      if (wsstag_matches3[1] == "") {
    		  wsstag_matches3[1] = "index.html";
		  }
	   wsstag_filename = wsstag_matches3[1];
	   if(typeof(wsstag_category)=="undefined"){
   	   		var wsstag_category = "Root";
   	   }
	}
}

//Check to see if a querytsring exists
//var wsstag_querystring = wsstag_hbxLoc.search;
//if(wsstag_querystring.indexOf('GP=') != -1 || wsstag_querystring.indexOf('CMP=') != -1){
//	var wsstag_re2 = new RegExp ('.*(GP|CMP)=([^&]*)');
//	var wsstag_qsMatch = wsstag_querystring.match(wsstag_re2);
//	if (wsstag_qsMatch){
//		if((document.cookie.indexOf(wsstag_qsMatch[1]) == -1) && (wsstag_qsMatch[1].indexOf("KNC-") == -1)){
//		var wsstag_campId = wsstag_qsMatch[1];
//			document.cookie = "hbx.dcmp: " + wsstag_campId;
//		}
//		else{
			var wsstag_campId = "";
//		}		
//	}
//}
//else{
//	var wsstag_campId = "";
//}

//Check for a predefined page ID
if (typeof(wsstag_pageId)!="undefined") {
	wsstag_filename = wsstag_pageId;
}
// **************************************
// *** DO NOT MAKE CHANGES BELOW HERE *** 
// **************************************
function _wsstag_clean(input) {
   // replace any html / ascii codes (&xx;)(&#xxx) with spaces
   var re = new RegExp('\&#?\\w+;?', 'g');
   var input = input.replace(re, ' ') ;

   // ensure characters in ascii decimal values of 32 - 126
   // include 32 for spaces
   // maps to hex values of x20 - x7E
   var re = new RegExp ('[^\\x20-\\x7E]', 'g') ;
   var input = input.replace(re, '') ;

   // remove illegal characters
   // ' " & ! # $ % ^ * : | / \ < > ~ ;
   // replace '|' with ' ' 
   var re = new RegExp ('[|]', 'g');
   var input = input.replace(re, '--');
   // replace others with ''
   var re = new RegExp ('[\'\"\&!#\$%^\*:\/\\<>~;]', 'g') ;
   var input = input.replace(re, '') ;

   // replace spaces with the pluses
   // replace spaces in succession with one plus
   var re = new RegExp (' +', 'g') ;
   var input = input.replace(re, '+') ;
   
   return input;
}

var _hbEC=0,_hbE=new Array;
function _hbEvent(a,b){
   b=_hbE[_hbEC++]=new Object();
   b._N=a;b._C=0;return b;
}
var hbx=_hbEvent("pv");

hbx.vpc="HBX0100u";
hbx.gn="wa.mastercard.com";

// set environment specific data
hbx.acct=wsstag_prodAcct;

// page name
hbx.pn = wsstag_filename
// content category 
hbx.mlc = wsstag_category

function _wsstag_swfClick(swflid,swflpos){
	_hbLink(swflid,swflpos);
}

function _wsstag_exitLink(swfexit){
	_hbExitLink(swfexit);
}

function _wsstag_customMetric(cmlid, cmlpos){
	_hbSet('lv.id',cmlid);
	_hbSet('lv.pos',cmlpos);	
	_hbSend();
}

function dynamic_fsCommand(lidlpos, newURL){
//	alert("lidlpos: " + lidlpos)
//	alert("newURL: " + newURL);
	if(lidlpos.indexOf("|") != -1){
		var linkArray = lidlpos.split("|");
		var swflid = linkArray[0];
		var swflpos = linkArray[1];
	}
	else{
		var swflid = lidlpos;
		var swflpos = "Indeterminate";
	}
	_hbLink(swflpos, swflid);
	//Launch the desired URL, if one exists
	if(newURL != null && newURL != "undefined" && newURL != ""){
		if(newURL.indexOf("|") != -1){
			var urlArray = newURL.split("|");
			newURL = urlArray[0];
			var urlMethod = urlArray[1];
		}
		else{
			var urlMethod = "_self";	
		}
		window.open(newURL, urlMethod);
	}
}

//Check for a search
if(typeof(wsstag_searchKeyword)!="undefined"){
	var ev1 = _hbEvent("search");
		ev1.keywords = unescape(wsstag_searchKeyword);
	ev1.results = wsstag_searchResults;
	if(typeof(wsstag_facet1)!="undefined"){ev1.attr1 = wsstag_facet1;}
	if(typeof(wsstag_facet2)!="undefined"){ev1.attr2 = wsstag_facet2;}
}

function dynamic_fsCommand(lidlpos, newURL){
	if(lidlpos.indexOf("|") != -1){
		var linkArray = lidlpos.split("|");
		var swflid = linkArray[0];
		var swflpos = linkArray[1];
	}
	else{
		var swflid = lidlpos;
		var swflpos = "Indeterminate";
	}
	_hbLink(swflpos, swflid);
	
//Launch the desired URL, if one exists
	if(newURL != null && newURL != "undefined" && newURL != ""){
		if(newURL.indexOf("|") != -1){
			var urlArray = newURL.split("|");
			newURL = urlArray[0];
			var urlMethod = urlArray[1];
		}
		else{
			var urlMethod = "_self";	
		}
		window.open(newURL, urlMethod);
	}
	else{
	if(linkArray[2]!=null){
		var newURL = linkArray[2];
		if(linkArray[3]!=null){
			var urlMethod = linkArray[3];
		}
		else{
			var urlMethod = "_self";
		}
	}
	}
	if(newURL != null && newURL != "undefined" && newURL != ""){
		window.open(newURL, urlMethod);
	}
}

if(typeof(wsstag_segId)!="undefined"){
	hbx.seg = wsstag_segId;
} 

if(typeof(wsstag_hbxcmpn)=="undefined"){
	var wsstag_hbxcmpn = "";
} 

// the defaults across the application
hbx.pndef = "title";
hbx.ctdef = "full";
hbx.lt = "auto";  // link tracking setting
hbx.cmp = ""; //placeholder
hbx.cmpn = wsstag_hbxcmpn; // campaign id - in query
hbx.dcmp = wsstag_campId;
hbx.hra = ""; // placeholder 
hbx.hqsp = "ppass_att"; // campaign response attribute - query
hbx.gp = "";  // placeholder
hbx.gpn = "ppass_gp";  // campagin goal - in query
hbx.hcn = ""; // conversion attribute
hbx.hcv = ""; // conversion value
hbx.lvm = "300"; // link views max chars
hbx.dft = "full"; //download link tracking
hbx.dlf = ".sit,.zip,.doc,.xls,.ppt,.pdf,.eps,.psd"; //download file types

// call hbx.js file
document.write("<scr"+"ipt src=http://www.mastercard.com/common/js/hbx.js></scr"+"ipt>");