//last updated: Ari Koinuma Mar 3, 2011
//global trial code for locale-specific global and trial monitoring campaign.  
//edit the "CHANGE HERE" with various country codes and appropriate cookie name, trial codes to adapt to various locales. 

//drso 1.6.3
var drso={version:'1.6.3',url:location.href.toLowerCase(),setCookie:function(n,v,d,e){var de=new Date();de.setTime(de.getTime()+e*24*60*60*1000);document.cookie=n+'='+escape(v)+((e===null)?'':('; expires='+de.toGMTString()))+'; path=/'+((d===null)?'':(';domain='+d))},getDomain:function(str){if(!str){str=drso.url}else{str=str.toString().toLowerCase()}var domain=new RegExp(/\.?[\w]+\.(net|org|com?\.?[a-zA-Z]{0,2})/g);return str.match(domain)},getCookie:function(c_name){if(document.cookie.length>0){var c_start=document.cookie.indexOf(c_name+'='),c_end;if(c_start!==-1){c_start=c_start+c_name.length+1;c_end=document.cookie.indexOf(';',c_start);if(c_end===-1){c_end=document.cookie.length}return unescape(document.cookie.substring(c_start,c_end))}}return""},deleteCookie:function(name){this.setCookie(name,'',this.getDomain(),-1)},getRefUrl:function(domain,exp){if(!drso.getCookie('op_refUrl')){exp=(typeof(exp)==='undefined')?null:exp;domain=(typeof(domain)==='undefined')?this.getDomain():domain;var refUrl=(document.referrer)?document.referrer.toLowerCase():'none';this.setCookie('op_refUrl',refUrl,domain,exp)}return this.getCookie('op_refUrl')},getQsPval:function(pname,strShort){var pval='',nvnames={n:(typeof(strShort)==='undefined')?'n':'p_name',v:(typeof(strShort)==='undefined')?'v':'p_val'},nvpattern=new RegExp(nvnames.n+'='+pname+'&'+nvnames.v+'=([^&]*)','i'),param=location.search.match(nvpattern);if(param){pval=decodeURIComponent(param[1])}return pval},clickthruRedirect:function(href,clickthru,clickthruUrlArg,extraParams){var hrefParams='',hrefPrefix='',extraParams=(typeof(extraParams)==='undefined')?'':extraParams,loc=location.href;loc=loc.substring(0,loc.lastIndexOf('/'));if(href.indexOf('//')===0){hrefPrefix=location.protocol}else if(href.indexOf('/')===0){hrefPrefix=location.protocol+'//'+location.hostname}else if(href.substring(0,4)!=='http'&&href.substring(0,5)!=='https'){while(/^\.\./.test(href)){loc=loc.substring(0,loc.lastIndexOf('/'));href=href.substring(3)}href=loc+'/'+href}if(href.indexOf('?')!==-1){hrefParams='&'+href.split('?')[1];href=href.split('?')[0]}window.location=clickthru+'?'+clickthruUrlArg+'='+hrefPrefix+href+hrefParams+extraParams},setSessionVar:function(k,v){var w=window.name;v=escape(v);if(w.indexOf(k)!==-1){w=w.replace(w.split(k+'=')[1].split('&')[0],v)}else if(w.length){w=w+'&'+k+'='+v}else{w=k+'='+v}window.name=w},getSessionVar:function(k){var w=window.name;if(w.indexOf(k)!==-1){return unescape(w.split(k+'=')[1].split('&')[0])}else{return''}},log:function(s){if(typeof(console)==='object'){console.log(s)}},getSerializedParam:function(argName,argDelimStart,argDelimEnd,argHaystack,caseInsens){var argHaystack=(typeof(argHaystack)==='undefined')?window.location.href:argHaystack;if(caseInsens){argHaystack=argHaystack.toLowerCase();argName=argName.toLowerCase()}if(argHaystack.indexOf(argName)!==-1){var argPos=argHaystack.indexOf(argName);if(!argDelimStart){argDelimStart=argHaystack.substring(argPos-1,argPos)}if(!argDelimEnd){argDelimEnd=argHaystack.substring(argPos+argName.length,argPos+argName.length+1)}var sPattern=(argHaystack.indexOf(argName)===0)?'':'['+argDelimStart+']';sPattern=sPattern+argName+argDelimEnd+'([^'+argDelimStart+'#?&]*)';var oRegEx=new RegExp(sPattern),aResults=oRegEx.exec(argHaystack);if(!aResults){return false}else{return aResults[1]}}else{return false}},getUrlParam:function(argName,argDelimStart,argDelimEnd,argHaystack,caseInsens){return this.getSerializedParam(argName,argDelimStart,argDelimEnd,argHaystack,caseInsens)},getURLparam:function(argName,argDelimStart,argDelimEnd,argHaystack,caseInsens){return this.getSerializedParam(argName,argDelimStart,argDelimEnd,argHaystack,caseInsens)}};

//optrial
if (typeof(optrial) === 'undefined') {
    var optrial = {};
}


// disable OT completely
if (typeof(ptomodule) === 'object' && (drso.getURLparam('optest') === 'false' || drso.getCookie('optest') === 'false')) {
  ptomodule.Enabled = false;
}


//functions for processing
function getCookieb(c_name) {
  if (document.cookie.length>0){
    c_start=document.cookie.indexOf(c_name + "=");
    if (c_start!=-1) {
      c_start=c_start + c_name.length+1;
      c_end=document.cookie.indexOf(";",c_start);
      if (c_end==-1) c_end=document.cookie.length;
      return unescape(document.cookie.substring(c_start,c_end));
    }
  }
  return "";
}
var expiresa = new Date();
expiresa.setDate(expiresa.getDate() + 1);
var expiresb = new Date();
expiresb.setDate(expiresb.getDate() + 30);


//CHANGE HERE
//capturing the initial referrer if on Microsoft.com 
if (!getCookieb('op_referrerType') && document.location.href.match(/microsoft\.com\/france\/mac/i)){
  var referrer = document.referrer, referrerType = null;
  if (referrer.match(/google/i) || referrer.match(/yahoo/i) || referrer.match(/bing/i)){
    referrerType = 'search';
  } else if (referrer.match(/microsoft\.com/i)){
    referrerType = 'direct';
  } else if (referrer.match(/facebook/i) || referrer.match(/twitter/i) || referrer.match(/linkedin/i)){
    referrerType = 'social-media';
  }
  
  if (referrerType){
    document.cookie = 'op_referrerType='+referrerType+';expires=' + expiresb.toGMTString()+';domain=.microsoft.com;path=/;';
  }
}


//CHANGE HERE
//storing session ID in window.name for cross-domain tracking
if (document.location.href.match(/microsoft\.com/i)) {
  //microsoft.com
  $(document).ready(function() {
    //first, get the session value from the cookie
    var gcv=getCookieb('op390globalmonitorfrance2011liid');
    var tcv=getCookieb('op390trialregthankyoufrance2011liid');
    
    //then surround it with identical identifier values (example: 'home'+sessionID+'home') and store it to window.name
    window.name='global'+gcv+'globaltry'+tcv+'try';
    })
} else {
  //GC -- either officeformac.com or digitalriver.com, with site ID msmactus
  var cstr1 = window.name.split('global');
  var cstr2 = window.name.split('try');
  
  document.cookie = 'op390globalmonitorfrance2011liid='+cstr1[1]+';expires=' + expiresa.toGMTString()+';domain=.officeformac.com;path=/;'
  document.cookie = 'op390globalmonitorfrance2011gum='+cstr1[1]+';expires=' + expiresb.toGMTString()+';domain=.officeformac.com;path=/;'

  document.cookie = 'op390trialregthankyoufrance2011liid='+cstr2[1]+';expires=' + expiresa.toGMTString()+';domain=.officeformac.com;path=/;'
  document.cookie = 'op390trialregthankyoufrance2011gum='+cstr2[1]+';expires=' + expiresb.toGMTString()+';domain=.officeformac.com;path=/;'
}

//CHANGE HERE
//determining the new vs. returning status (new to the 3 main pages -- home, products and buy)
//checking to see if this user is new or returning before the trial code runs
optrial.visitStatus = (getCookieb('op390globalmonitorfrance2011liid')) ? 'returning' : 'new';

//setting the pva for the referring type
optrial.referrerType = getCookieb('op_referrerType');

//CHANGE HERE
//trial code.  Running on all the pages that have the OT code -- home, products and buy
if (document.location.href.match(/microsoft\.com\/france\/mac/i)){
  /*
   * Portfolio: msmacfr (Mactopia France)
Subject: Global Monitor France 2011
Trial: Trial 1
Referenced context:
- Query string: optrial.visitStatus
- JavaScript variables: optrial.referrerType, optrial.sticky
Note: This code should not be included in a secure (https) page.
   */
  
  (function(){var _o=ptomodule;_o.U="http://pto.digitalriver.com/trial/390/p/globalmonitor.ff5/436/content.js";
_o.ST="script";_o.SA={"type":"text/javascript"};_o.B();_o.A["optrial.referrerType"]=(typeof optrial.referrerType!=
"undefined")?optrial.referrerType:null;_o.R(1000,null,null,null);})();
}

