// Page postprocessing

// any filename extension will match (usually  or .do)
// leave win/loss out, or custom tag
var cor_suffix = {
  'dob': 'date_of_birth',
  'early': 'coming_soon',
  'error': 'general_error',
  //'front': 'enter_email',
  'front': 'front',
  'info': 'info',
  'infoLB': 'info_light_box',
  'game': 'iwg_game',
  'ineligible': 'ineligibile',
  'limit': 'already_entered',
  'limit_played': 'already_played',
  'limit_reg': 'already_registered',
  'limit_won': 'already_won',
  'overage': 'overage',
  'over': 'end_of_promo',
  'prizes': 'prize_details',
  'recipe': 'recipes',
  'reg': 'registration',
  'rules': 'rules',
  'splash': 'splash',
  'success': 'success',
  'taf_email_template': 'taf_email_html',
  'taf_email_template.txt': 'taf_email_txt',
  'taf': 'taf_splash',
  'taf_preview': 'taf_preview',
  'taf_success': 'taf_success',
  'underage': 'underage',
  'verify': 'prize_verification',
  'winners': 'winners'
};

function cor_getPageName(custom) {
  var l = document.location;
  var h = l.hostname.split('.');
  var client = h[0];
  var domain = h[1];
  var p = l.pathname.substring(1).split('/');
  var promo = p[0];
  var file = p[p.length-1];
  var base = file.split('.')[0];
  //var suffix = (custom != null && custom != '') ? custom : (cor_suffix[base] != undefined && cor_suffix[base] != '') ? cor_suffix[base] : file;
  var suffix = (custom != null && custom != '') ? custom : base;
  suffix = 'html-' + suffix;
  var pg = s.getQueryParam('pg');
  if (pg != null && pg != '') suffix += '-' + pg;
  var page = s.getQueryParam('page');
  if (page != null && page != '') suffix += '-' + page;
  //var name = domain + '|' + client + '|' + promo + '|' + suffix;
  var name = 'monop_us' + '|' + '09' + '|' + suffix;
  return name;
}

function cor_doConversion() {
  s.prop3 = cor_getPageName('Conversion');
}

function cor_sendAnalyticsEvent(eID, tID) {
  if (typeof(tID) == 'undefined' || tID == '') return;
  if (eID == 'view') {
    s.pageName = tID;
    void(s.t());
    s.pageName = '';
  } else if (eID == 'click') {
    s.linkTrackVars = 'prop1';
    s.linkTrackEvents = '';
    s.prop1 = tID;
    void(s.tl(this,'o',tID));
    s.linkTrackVars = 'None';
    s.linkTrackEvents = 'None';
    s.prop1 = '';
  }
}

// PLUGINS BEGIN

/* PageName Plugin Config */
s.siteID=""; // optional
s.defaultPage="index.html";
s.queryVarsList=""; // if list, comma delimit
s.pathExcludeDelim=";";
s.pathConcatDelim="|"; // page name component separator
/* Plugin Config */
s.usePlugins=true;
function s_doPlugins(s) {
  s.prop2 = s.getQueryParam('p_cid');
  if (s.eo||s.lnk) {
    //s.linkName=s.p_gname();
    //s.linkType='o';
  }
}
s.doPlugins=s_doPlugins;

/************************** PLUGINS SECTION *************************/
/* You may insert any plugins you wish to use here.                 */

/*
 * Plugin: Dynamically Generate Page Name Based On Current URL
 */
s.getPageName=new Function(""
+"var s=this,pn=(s.siteID&&(''+s.siteID).length>0)?''+s.siteID:"
+"'',l=location,dp=(s.defaultPage)?''+s.defaultPage:'',e="
+"(s.pathExcludeDelim)?s.pathExcludeDelim:'',cs=(s.pathConcatDelim)?"
+"s.pathConcatDelim:'',q=l.search.substring(1),"
+"p=l.pathname.substring(1),x=p.indexOf(e);p=((x<0)?p:p.substring(0,"
+"x)).split('/');for(j=0;j<p.length;j++){if(p[j].length>0){if(pn."
+"length>0)pn+=cs;pn+=p[j]}else{if(dp.length>0){if(pn.length>0)pn+="
+"cs;pn+=dp}}}if(q.length>0){if(s.queryVarsList){var qpa=new Array()"
+",qv=s.split(s.queryVarsList,','),qp=s.split(q,'&'),tmp,idx;for(i="
+"0;i<qp.length;i++){tmp=s.split(qp[i],'=');qpa[i]=tmp[0]}for(i=0;"
+"i<qv.length;i++){idx=s.ia(qpa,qv[i]);if(idx>=0){if(pn.length"
+">0)pn+=cs;pn+=qp[idx]}}}}return pn");
s.split=new Function("str","sep",""
+"var si=0,sa=new Array(),i;while((str.length>0)&&(sep.length>0)){"
+"i=str.indexOf(sep);if((!i)&&(sep!=str.substring(0,sep.length)))"
+"break;if(i==-1){sa[si++] = str;break;}sa[si++]=str.substring(0,i);"
+"str=str.substring(i+sep.length,str.length)}return sa");
s.ia=new Function("ar","v",""
+"for(var i=0;i<ar.length;i++){if(ar[i]==v)return i}return -1");

/*
 * Plugin: getQueryParam 2.0 - return query string parameter(s)
 */
s.getQueryParam=new Function("p","d","u",""
+"var s=this,v='',i,t;d=d?d:'';u=u?u:(s.pageURL?s.pageURL:''+s.wd.loc"
+"ation);u=u=='f'?''+s.gtfs().location:u;while(p){i=p.indexOf(',');i="
+"i<0?p.length:i;t=s.p_gpv(p.substring(0,i),u);if(t)v+=v?d+t:t;p=p.su"
+"bstring(i==p.length?i:i+1)}return v");
s.p_gpv=new Function("k","u",""
+"var s=this,v='',i=u.indexOf('?'),q;if(k&&i>-1){q=u.substring(i+1);v"
+"=s.pt(q,'&','p_gvf',k)}return v");
s.p_gvf=new Function("t","k",""
+"if(t){var s=this,i=t.indexOf('='),p=i<0?t:t.substring(0,i),v=i<0?'T"
+"rue':t.substring(i+1);if(p.toLowerCase()==k.toLowerCase())return s."
+"epa(v)}return ''");

/*
 * Plugin: linkHandler 0.5 - identify and report custom links
 */
/*********************************************************************
* Function linkHandler(p,t): Sets linkName and linkType based
*                 on the first parameter and the URL of link clicked.
*                 When a link is clicked, bc() is called, which puts
*                 the link object into eo. If p is omitted, '' is
*                 always returned. If t is omitted, linkType is 'o'.
*
*     p = string of pipe delimited [name~]filter pairs
*     t = (optional) link type applied to the list of pairs
* Returns:
*     URL of the link found or ''
*********************************************************************/
s.linkHandler=new Function("p","t",""
	+"var s=this,"
      // href of link clicked
	    +"h=s.p_gh(),"
			+"i,"
			+"l;"

	+"t=t?t:'o';"

	// dont override existing onClick event
	// and dont continue if eo and lnk are empty
	+"if(!h||(s.linkType&&(h||s.linkName)))"
		+"return '';"

	+"i=h.indexOf('?');"

	// URL and match filter may contain the query string
	+"h=s.linkLeaveQueryString||i<0?h:h.substring(0,i);"
	+"l=s.pt(p,'|','p_gn',h.toLowerCase());"

	// if l has a value, set linkType and return the HREF
	+"if(l){"
		+"s.linkName=l=='[['?'':l;"
		+"s.linkType=t;"
		+"return h;"
	+"}"
	+"return '';"
);

/*********************************************************************
* Function p_gn(t,h): Plugin Utility Get Name - pt() callback used to
*                     parse match list
*     t = match pair
*     h = match value (URL)
* Returns:
*     Matched link name, URL or 0
*********************************************************************/
s.p_gn=new Function("t","h",""
	+"var i=t?t.indexOf('~'):-1,"
      +"n,"
      +"x;"
	+"if(t&&h){"
		+"n=i<0?'':t.substring(0,i);"
		+"x=t.substring(i+1);"
		+"if(h.indexOf(x.toLowerCase())>-1)"
			+"return n?n:'[[';"
	+"}"
	+"return 0;"
);
/*********************************************************************
* Function p_gh(): Plugin Utiltiy Get HREF - returns the HREF of a
*                     link clicked or ''. Used by linkHandler,
*                     getExitLink and getDownloadLink.
*     t = match pair
*     m = match value (URL)
* Returns:
*     Matched link name, URL or 0
*********************************************************************/
s.p_gh=new Function(""
	+"var s=this;"

	// required to find the href of a link - set by bc or lc
	+"if(!s.eo&&!s.lnk)"
		+"return '';"

	+"var o=s.eo?s.eo:s.lnk,"
			+"y=s.ot(o),"
			+"n=s.oid(o),"
			+"x=o.s_oidt;"

	// I have no idea what this does
	// 	but it is required for Opera and all browsers on Mac
	//  I do know that this resets the o object
	+"if(s.eo&&o==s.eo){"
		+"while(o&&!n&&y!='BODY'){"
			+"o=o.parentElement?o.parentElement:o.parentNode;"
			+"if(!o)"
				+"return '';"
			+"y=s.ot(o);"
			+"n=s.oid(o);"
			+"x=o.s_oidt"
		+"}"
	+"}"
	+"return o.href@o.href_3A'';"
);
s.p_gname=new Function(""
	+"var s=this;"

	// required to find the name of a link - set by bc or lc
	+"if(!s.eo&&!s.lnk)"
		+"return '';"

	+"var o=s.eo?s.eo:s.lnk,"
			+"y=s.ot(o),"
			+"n=s.oid(o),"
			+"x=o.s_oidt;"

	// I have no idea what this does
	// 	but it is required for Opera and all browsers on Mac
	//  I do know that this resets the o object
	+"if(s.eo&&o==s.eo){"
		+"while(o&&!n&&y!='BODY'){"
			+"o=o.parentElement?o.parentElement:o.parentNode;"
			+"if(!o)"
				+"return '';"
			+"y=s.ot(o);"
			+"n=s.oid(o);"
			+"x=o.s_oidt"
		+"}"
	+"}"
	+"return o.name@o.name_3A'';"
);

// PLUGINS END

// Omniture SiteCatalyst code version: H.9.
// You may give each page an identifying name, server, and channel
// on the next lines.

s.pageName=cor_getPageName();
s.server=""
s.channel=""
s.pageType=""
//s.prop1=""
//s.prop2=""
//s.prop3=""
//s.prop4=""
//s.prop5=""
/* 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=""
/************* DO NOT ALTER ANYTHING BELOW THIS LINE ! **************/
if (document.location.hostname.indexOf('promotions.com') != -1) {
  var s_code=s.t();
  if(s_code)document.write(s_code);
}
