//Get parameters
var page_id = getParameter("pid");
var banner_id = getParameter("adid");
var creative_id = getParameter("rid");
var buy_id = getParameter("bid");
var mktprgm = getParameter("mktprgm");
var pricing = getParameter("pref");

//if the bid has a value then concatenate it with the adid (delimited by an underscore)
if((buy_id != null) && (buy_id != "")){
	banner_id = banner_id + "_" + buy_id;
}

if((page_id == "") || (page_id == null)){
  var id_val = "nothing";
  }

if(page_id == null || page_id == "")page_id = " ";
if(banner_id == null || banner_id == "")banner_id = " ";
if(creative_id == null || creative_id == "")creative_id = " ";
if(mktprgm == null || mktprgm == "" || "".equals( mktprgm ))mktprgm = "unset";
if(pricing == null || pricing == "")pricing = " ";


//Set cookie if needed
if(id_val != "nothing"){
  var name = "mktcodes";
  var myDate = new Date();
  var value = "|" + unescape(page_id) + "|" + unescape(banner_id) + "|" + unescape(creative_id) + "|" + unescape(mktprgm) + "|" + myDate.valueOf() + "|" + unescape(pricing);
  var expires = new Date(); //Cookie expires in 45 days
  expires.setDate(expires.getDate() + 45);
  var path = "/";
  // get the full url string, http://www..com/dir/page.html?x=y...
  var curUrl = new String( window.location );
  // strip off the leading protocol ("http://") and strip any trailing file-path and query string
  var domain = curUrl.substring(7, curUrl.indexOf( ".com/"));
  // strip off any preceding subdomains (www.sub.subsub...)
  domain = domain.substring(domain.lastIndexOf(".") + 1, domain.length) + ".com";
  //set the domain for the cookie
  var cookieDomain = curUrl.substring(7, curUrl.indexOf( ".com/"))+".com";
  document.cookie = name+"="+value+";expires="+expires.toGMTString()+";path="+path+";host="+cookieDomain+";false";
}

// WWS code
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="ehg-chrysler.hitbox.com";
var cleanPN = document.title.replace(/[^a-zA-Z0-9,\s,+,-]/g,'').replace(/\s+/g,"+");
var cv = _hbEvent("cv");

// fill in 
var country = "china";
var brand = "chrysler";
//------------------------------------------

var lL = new Array(2);
              
  lL[0] = "cn";

  lL[1] = "en";

var temp = new Array();
var count = 0;
var url = "";
var qS = location.pathname;
var directory = qS.split("/");

if ( qS.indexOf("htdocs") != -1 ){
  for(var s = directory.length-1; s > 0; s--){
    if (directory[s] == "htdocs"){
      htdocsPos = s;
      break;
    }
  }
  var directory = directory.splice(htdocsPos,directory.length-(htdocsPos));
}

for(var i = directory.length-1; i > 0; i--){
  for(var j = 0; j < 3; j++){
    if(directory[i] == lL[j]){
      var cur_lang = lL[j];
      var language = cur_lang;
      for(var d = directory.length-1; d > 0; d--){
        if (directory[d] == cur_lang){
          langPos = d;
          break;
        }
      }
      // for path with language in path with file name in path
      if(location.pathname.indexOf(".html") != -1 || location.pathname.indexOf(".jsp") != -1){
        var stripPath = directory.splice(langPos+1,directory.length-(langPos+2));
        var path = stripPath.join("/");
        // if page is at the root level "home" will become the pathname
        if ( path == "" ) { path = "home" }
        } else {
          // for path with language in path without file name in path
          var stripPath = directory.splice(langPos+1,directory.length-langPos);
          var path = stripPath.join("/");
          var path = path.replace(/\/$/,"");
          if ( path == "" ) { path = "home" }
      }
    }
  }
}
if (cur_lang == "") { language = "en" }

//------------------------------------------

if (path != "" && path != "undefined"){
  var mlc = "/"+path
  var mlc = mlc.toLowerCase();
  } 
  else if(location.pathname.indexOf(".html") != -1 || location.pathname.indexOf(".jsp") != -1 || location.pathname.indexOf(".php") != -1){
   var path = location.pathname;
   if (path.indexOf('htdocs') != -1) {
   var parts = path.split('htdocs');
   path = parts[1];
   }
    var mlcSplit = path.split("/");
    if(cur_lang != ""){
      var mlcSplice = mlcSplit.splice(0, mlcSplit.length -1);
      } else {
        var mlcSplice = mlcSplit.splice(1, mlcSplit.length -2);
      }
    
    var mlcJoin = mlcSplice.join("/");
    var mlc = mlcJoin.toLowerCase();
    var mlc = "/"+mlcJoin;
    } else {
      var mlc = location.pathname.toLowerCase();
      var mlc = mlc.replace(/\/$/,"");
    }
    if ( mlc == "/" || mlc == "" ) { mlc = "/home" }
  
var country = country.toLowerCase();
var language = language.toLowerCase();
var brand = brand.toLowerCase();

hbx.pn=cleanPN;
if ((curVehicle == "brand") || (curVehicle == "") || (curVehicle == null)) {
  hbx.mlc="/"+brand+"/"+language+mlc+";/"+country+"/"+language+"/"+brand+mlc;
} else {
  hbx.mlc="/"+brand+"/"+language+"/vehicles"+mlc+";/"+country+"/"+language+"/"+brand+"/vehicles"+mlc;
}

hbx.pndef="title";
hbx.ctdef="full";
hbx.dcmpn="bid";
hbx.hqsp="adid";
//hbx.hrf="hrf";

//Optional Variables
hbx.lt="auto";
hbx.dlf=".pdf,.zip,.hqx!.jsp,.htm,.html";
cv.c21=location.protocol+'//'+location.host+location.pathname;
cv.c22=location.search.substring(1, location.search.length);

// WSS Account Codes
var host = location.hostname;
if (host.indexOf("53.28.38.192") != -1 || host.indexOf("test") != -1 || host.indexOf("uat") != -1){
  // test account
    hbx.acct="DM550803GNAM";
  } else {
  // live account
    hbx.acct="DM560731IPMW;DM550803F9DZ";
}