var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-208343-2']);
  
if (String(document.referrer).search(RegExp(document.location.host)) == 7) {
  //console.log("Реферер — внутренняя страница");
  try {
    a = document.createElement('a');
    a.href = document.referrer;
    var theref = a.pathname.replace(/\?.*$|\/?index\.html?|\.html?|^\//g, "").replace(/\//g, "-")
    if (theref == "") {theref = "root";}
    theref = cut_string(theref);
    _gaq.push(['_setCustomVar', 1, 'Previous page', theref, 3]);
    //console.log("Пользовательская переменная: "+theref );
  } catch(e){
    //console.log("Не удалось осуществить запись данных о предыдущей странице в пользовательскую переменную. Ошибка: "+e);
  }
};

function cut_string(patient){
  if (patient.length > 64){
    patient = patient.replace(/-[^-]*$/,"");
    //console.log("Обрезка. Строка("+patient.length+"): "+patient);
  } else { return patient; }
  return cut_string(patient);
}

_gaq.push(['_trackPageview']);

(function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = '/_lib/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
