var sbc_r=GetCookieValueByName("sbc");

function GetCookieValueByName(name)
{
 var beg = document.cookie.indexOf(name+"=");
 if(beg==-1)  
   return "c_"+Math.random();
  
 var end = document.cookie.indexOf(";", beg + name.length);
 if(end==-1)
  end = document.cookie.length;
  
return unescape(document.cookie.substring(beg + name.length + 1, end));
}

var today = new Date();
expires = new Date(today.getTime() + 365*1*24*60*60*1000);

document.cookie="sbc="+sbc_r+"; expires="+expires.toGMTString();


function all_a_tags()
 {
 var str;
  getATags = document.getElementsByTagName('a');
  for(i=0; i<getATags.length; i++)
  {

  str=getATags[i].href;
  if (/javascript/.test(str) )
   {
   }
   else
   {
   if (/mailto/.test(str) )
    {
    }
    else
    {
        getATags[i].onclick=getURL;
    }
   }

  }
 }


function getURL()
{
  get_a_tag = event.srcElement;
//  var a;
//  a='';

     while ("HTML" != get_a_tag.tagName) {
               if ("A" == get_a_tag.tagName) break;
//               a=get_a_tag.tagName+'>'+a;
               get_a_tag = get_a_tag.parentElement;
            }

//  a=get_a_tag.tagName+'>'+a;
//  rez.value=a;
//  rez2.value=get_a_tag.tagName;
//  rez3.value=get_a_tag.href;
//  rez4.value=sbc_r;

//  rez4.value=get_a_tag.target;

  if (get_a_tag.target == "_blank")
   {
    window.open("http://www.rootle.ru/trgt?url="+escape(get_a_tag.href)+"&ref="+escape(document.referrer)+"&unic="+sbc_r+"&now="+escape(window.location.href));
//    getATags[i].href='javascript:window.open("http://www.rootle.ru/trgt?url='+escape(getATags[i].href)+'&ref='+escape(document.referrer)+'&unic='+sbc_r+'&now='+escape(window.location.href)+'")';
//    document.location.href='javascript:window.open("http://www.rootle.ru/trgt?url='+escape(get_a_tag.href)+'&ref='+escape(document.referrer)+'&unic='+sbc_r+'&now='+escape(window.location.href)+'")';
   }
   else
  {
    document.location.href = "http://www.rootle.ru/trgt?url="+escape(get_a_tag.href)+"&ref="+escape(document.referrer)+"&unic="+sbc_r+"&now="+escape(window.location.href);
  }
//   document.location.href = "http://www.rootle.ru/trgt?url="+escape(get_a_tag.href)+"&ref="+escape(document.referrer)+"&unic="+sbc_r+"&now="+escape(window.location.href);
  
  return false;

//  get_a_tag = event.srcElement;
//  get_a_tag_id = get_a_tag.id;
//  get_a_tag_url = get_a_tag.href; //silka
//  get_a_tag_name = get_a_tag.name; //imya <a name="top"> znachenie top
//  get_a_title = get_a_tag.title; //title <a title="titles"> znachenie titles
//  get_a_alt = get_a_tag.alt; //title <a title="titles"> znachenie titles
//  get_a_value = get_a_tag.innerText; // <a>Hallo</a> //Hallo
//  rez.value=get_a_tag_url;
//  alert(sbc_r);
} 

//  alert(sbc_r);

all_a_tags();