
var hcessf=new Array();
var hcessb=new Array();

var hchttp='http://'; 
hcessb[0]='ho.ultramercial.com';     
hcessb[1]='bliss.ultramercial.com';  
// hcessb[2]='mirror.ultramercial.com/e';  
// hcessb[3]='cache.ultramercial.com/e';  


var hcmgx=new Array(); var hcmgxl=0;
var hcmgxd=0;

function hcerc (hcon) {    var exp = new RegExp (escape(hcon) + "=([^;]+)");
  if (exp.test (document.cookie + ";")) {
    exp.exec (document.cookie + ";");
    return unescape(RegExp.$1);
  } else return false;
}
function hcesc(cn, cv, em) {   var cvs=new Array();
  var tp=0;
  cvs[tp++]=cn+"="+escape(cv);
  if (em) {
    if (em!=parseInt(em)) em=0;
    var rightnow=new Date();
    var cookieExpires=new Date();
    cookieExpires.setTime(rightnow.getTime()+60000*parseInt(em));
    cvs[tp++]="expires=" + cookieExpires.toGMTString();
  } 
  cvs[tp++]="path=/";
  cvs[tp++]='domain=.ultramercial.com';
  document.cookie=cvs.join(';');
}
function hcrs(minrand, maxrand) {   return parseInt(minrand+Math.floor(Math.random()*(maxrand-minrand+1)));
}
function hcrn() {
  return parseInt(10000+Math.floor(Math.random()*9999));
}
function hcgvc() {   var vc=hcerc('VISITOR');
  if (vc.length==32) return vc;
  vc=hcerc('UMLVC');
  if (vc.length==32) return vc;
  vc=hcerc('UMSVC');
  if (vc.length==32) return vc;
  return "";
}
function hcsvc() {   var vc=hcgvc();
  if (vc.length!=32) vc=hcmvc();
  hcesc('UMLVC',vc,60*24*365);
  hcesc('UMSVC',vc);
}
function hcmvc() {   var key='';
  var usethese=new String("0bcd1fgh2jklmn3pqrst4vwxyz5BCD6FGH7JKLMN8PQRST9VWXYZ")
  var thesemany=usethese.length;
  for (var i=0;i<32;i++) key+=usethese.charAt(hcrs(1,thesemany));
}
function hcsvc(cval) {
}
function hcdi() {
  hcmgxd++;
}
function hctodo() {
  return (hcmgxl-hcmgxd);
}
function hci(hcii) {
  hcmgx[hcmgxl]=new Image();
  hcmgx[hcmgxl].src=hcii;
  hcmgx[hcmgxl].onload=hcdi;
  hcmgxl++;
}
function hct(hcpx) {   var hcpxa=new Array();
  try { 
    if (typeof(hcpx)=='undefined') var hcpx="";
  } catch(er) {
    var hcpx="";
  }
  if (typeof(hcpx)=='string') {
    if (hcpx.length>0) hcpxa.push(hcpx);
  } else if (typeof(hcpx)=='object') {
    for (var hces=hcpx.length-1;hces>=0;hces--) if (hcpx[hces].length>0) hcpxa.push(hcpx[hces]);
  } else return;
  if (hcpxa.length==0) return;
  var hreg=new RegExp("timestamp", "i");
  for (var hces=hcpxa.length-1;hces>=0;hces--) {
    hci(hcpxa[hces].replace(hreg,hcrn()));
  }
}
function hcf(hcpxa,hcpn,hcpa) {   if (hcpxa.length==0) return;
  var umphlii; for (umphlii=0;umphlii<40;umphlii++) document.write('<br>');
  for (var hces=hcpxa.length-1;hces>=0;hces--) {
    var hcfdwa=new Array();
    hcfdwa[0]='src="'+hchttp+hcpxa[hces]+'/'+hcpn+'?'+hcpa.join('=')+'"';
    hcfdwa[1]='width='+hcrs(1,3);
    hcfdwa[2]='height='+hcrs(1,3);
    hcfdwa[3]='border=0';
    hcfdwa[4]='style="display:none;"';
    document.write('<img '+hcfdwa.join(' ')+'>');
  }
}
function hcb(hcpxa,hcpn,hcpa) {    if (hcpxa.length==0) return;
  for (var hces=hcpxa.length-1;hces>=0;hces--) {
    hci(hchttp+hcpxa[hces]+'/'+hcpn+'?'+hcpa.join('='));
  }
}

setTimeout('um_groundhogday();',0300); // give time for shadow to load

function um_groundhogday() {  // see the shadow of this page
  um_triggerrecording(location.href);
}
function um_triggerrecording(where) {  // record the event
  if (where.lastIndexOf('/')==-1) where=location.href.substring(0,location.href.lastIndexOf('/')+1)+where;
  var hcea=new Array();
  hcea[0]=escape(where); // hcel
  hcea[1]=hcgvc();
  hcea[2]=hcrn();
  hcea[3]=escape(hcerc('uri')); // hceu
  var hcep='shadow.um';  // hcep
  try { hcf(hcessf,hcep,hcea); } catch(er) { }
  try { hcb(hcessb,hcep,hcea); } catch(er) { }
  try { hct(trackingpixels); } catch(er) { }
}

function mark(wha) {
  phantomshadow(wha);
}
var phantomtargetsloaded=0;  // incremented on each start, decremented on each completion
var phantomtargetsloading=0; // incremented on each start
var phantomshadowhcpp;
function phantomshadow(hcpp) {
  phantomshadowhcpp=hcpp;
  if (hcpp.length>0) setTimeout("phantomshadow_echo()",0010);
  phantomtargetsloaded++;
  phantomtargetsloading++;
}
function phantomshadow_echo() {
  hcpp=phantomshadowhcpp;
  // it's just like being there!
  if (hcpp.lastIndexOf('/')==-1) hcpp=location.href.substring(0,location.href.lastIndexOf('/')+1)+hcpp;
  var hcch=hcpp.split('?');
  if (hcch.length==2) hcpp=hcch[0];
  var hcea=new Array();
  hcea[0]=escape(hcpp); 
  hcea[1]=hcgvc();
  hcea[2]=hcrn();
  if (hcch.length==2) hcea[3]=hcch[1]; else hcea[3]=escape(hcerc('uri')); // hceu
  var hcep='shadow.um';  
  try { hcf(hcessf,hcep,hcea); } catch(er) { }
  try { hcb(hcessb,hcep,hcea); } catch(er) { }
  phantomtargetsloaded--;
}
var phantomgotarget;
var phantomtargetscycling=0; // track retry attempts
function phantomgo(target) { // allows time to ping before redirecting to webpage target
  phantomgotarget=target;
  setTimeout("phantomgo_echo()",phantomtargetsloaded*0100);
}
function phantomgo_echo() {
    if ((phantomtargetscycling<3)&&(phantomtargetsloaded>0)) {
    phantomtargetscycling++;
    setTimeout("phantomgo_echo()",phantomtargetsloaded*0100);
  } else goURL(phantomgotarget);
}
function markandgo(tag,target) { // pings and then redirects to webpage target
  phantomshadow(tag);
  phantomgo(target)
}

// use this in a HREF with an onclick="return proceed('destinationurl')" to fork the Ultramercial
var shadowthere;
function proceed(shadowwhere) {
  shadowthere=shadowwhere;
  window.setTimeout("proceeding()",100); // milliseconds
  return true;
}
function proceeding() {
  location.href=shadowthere;
}


var phantompollhcqu;
var phantompollhcan;
function phantompoll(hcqu, hcan) {
  phantompollhcqu=hcqu;
  phantompollhcan=hcan;
  setTimeout("phantompoll_echo()",0020);
  phantomtargetsloaded++;
  phantomtargetsloading++;
}
function phantompoll_echo() {
  hcqu=phantompollhcqu;
  hcan=phantompollhcan;
  var hcea=new Array();
  hcea[0]=escape(location.href); 
  hcea[1]=escape(hcqu); 
  hcea[2]=escape(hcan); 
  hcea[3]=hcgvc();
  hcea[3]=hcrn();
  var hcep='poll.um';  
  try { hcf(hcessf,hcep,hcea); } catch(er) { }
  try { hcb(hcessb,hcep,hcea); } catch(er) { }
  phantomtargetsloaded--;
}

function sugardestination() { // tries to get the sugardestination from the cookie, or makes it up if it's not set
  var smdc=unescape(getCookie('destination'));
  if (smdc.length<5) smdc='sugarmama.virginmobileusa.com'; // we should crypt this
  return smdc;
}
var sugarratingrating;
function sugarrating(rating) { // records a rating and a poll result
  sugarratingrating=rating;
  setTimeout('sugarrating_echo()',0020);
  phantomtargetsloaded++;
  phantomtargetsloading++;
}
var sugarratingimaged=new Image;
function sugarrating_echo() { // records a rating and a poll result
  rating=sugarratingrating;
  var params=new Array();
  params[0]=sugardestination()+'/sugarmama-rates';
  params[1]=escape(rating);
  params[2]=getCookie('tag'); // adid/accountid
  sugarratingimaged.src=params.join('/');
  sugarpoll('rating',rating);
  phantomtargetsloaded--;
}

var sugarpollhcqu;
var sugarpollhcan;
function sugarpoll(hcqu, hcan) { // stores a poll result
  sugarpollhcqu=hcqu;
  sugarpollhcan=hcan;
  setTimeout('sugarpoll_echo()',0020);
  phantomtargetsloaded++;
  phantomtargetsloading++;
}
var sugarpollimaged=new Image;
function sugarpoll_echo() { // stores a poll result
  hcqu=sugarpollhcqu;
  hcan=sugarpollhcan;
  var params=new Array();
  params[0]=sugardestination()+'/sugarmama-polls';
  params[1]=getCookie('tag'); // adid/accountid
  params[2]=escape(hcqu);
  params[3]=escape(hcan); 
  sugarpollimaged.src=params.join('/');
  phantompoll(hcqu, hcan);
  phantomtargetsloaded--;
}
function sugarminutes() { // returns number of minutes that will be credited
  return parseInt(getCookie('index'));
}
function sugarexitearly() { // flees back to the Web server
  // phantomshadow(hccp);//hccp used to be part of the function call
  var destinationserver=sugardestination();
  if (destinationserver.length>5) phantomgo(destinationserver+'/sm_account.html');
}

function pagecolor(whichColor){
  document.bgColor=whichColor;
}


