
var js_stat_uri = 'http://stat2b.ru/stat2b_new/stat2b2l.php';
var url = escape(document.location);
var ref = escape(document.referrer);

function randomString(string_length) {
    var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz';
    var randomstring = '';
    for (var i=0; i<string_length; i++) {
    	var rnum = Math.floor(Math.random() * chars.length);
    	randomstring += chars.substring(rnum,rnum+1);
    }
    return randomstring;
}

function Get_Cookie( name ) {
    var start = document.cookie.indexOf( name + '=' );
    var len = start + name.length + 1;
    if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ){
        return null;
    }
    if ( start == -1 ) return null;
    var end = document.cookie.indexOf( ';', len );
    if ( end == -1 ) end = document.cookie.length;
    return unescape( document.cookie.substring( len, end ) );
}

function Set_Cookie( name, value, expires, path, domain, secure ) {
    var today = new Date();
    today.setTime( today.getTime() );
    if ( expires ) {
	expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date( today.getTime() + (expires) );
    document.cookie = name + '=' +escape( value ) +
    ( ( expires ) ? ';expires=' + expires_date.toGMTString() : '' ) + //expires.toGMTString()
    ( ( path ) ? ';path=' + path : '' ) + 
    ( ( domain ) ? ';domain=' + domain : '' ) +
    ( ( secure ) ? ';secure' : '' );
}

function Delete_Cookie( name, path, domain ) {
    if ( Get_Cookie( name ) ) document.cookie = name + '=' +
    ( ( path ) ? ';path=' + path : '') +
    ( ( domain ) ? ';domain=' + domain : '' ) +
    ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}

function Test_Cookie (name) {
    rname = 't' + name;
    Set_Cookie(rname,name);
    var t = Get_Cookie(rname);
    Delete_Cookie(rname);
    if ( t != name ) {
        return false;
    }
    return true;
}

id2 = -13277010035635;
said = 'easyhotels.ru';
sid = '';
cid = '';
if ( Test_Cookie(id2) ) {
    sid = Get_Cookie('sid');
    if ( !sid ) {
	sid = randomString(32);
    }
    Set_Cookie( 'sid' , sid );

    cid = Get_Cookie('cid');
    if ( !cid ) {
	cid = randomString(32);
    }
    Set_Cookie( 'cid' , cid ,1300);
}
    


function after(s) {
    img = new Image(1,1);
    img.src = s;
}

function clk(ev) {
    var exiturl = '';
    var mpx = 0;
    var mpy = 0;
    if ( !window.attachEvent ) {
        e=ev.target;
	if (e==null) return;
        if (e.tagName=='A' || e.tagName=='AREA') {
	} else {
    	    if (e.parentNode) {
		ep=e.parentNode;
		if (ep.tagName=='A' || ep.tagName=='AREA') {
	    	    e = ep;
		} else {
	    	    if (ep.parentNode) {
			epp=ep.parentNode;
			if (epp.tagName=='A' || epp.tagName=='AREA') {
			    e = epp;
			}
		    }
		}
	    }
	}
        isA=(e.tagName=='A' || e.tagName=='AREA')?1:0;
	isL=(isA && e.href)?1:0;
        if (!isL) return;
	exiturl = e.href;
	mpx = ev.pageX;
	mpy = ev.pageY;
    } else {
        e=event.srcElement;
	ep=e.parentElement;
        if (ep==null) return;
	if (ep.tagName=='A' || ep.tagName=='AREA')
    	    e = ep; 
        else {
	    if (ep.parentElement) {
	        epp=ep.parentElement;
		if (epp.tagName=='A' || epp.tagName=='AREA') e = epp;
	    }
        }
	isA=(e.tagName=='A' || e.tagName=='AREA')?1:0;
        isL=(isA && e.href)?1:0;
        if (!isL) return;
	exiturl= e.href;
	mpx = event.clientX + document.body.scrollLeft;
	mpy = event.clientY + document.body.scrollTop;
    }
    if (mpx < 0) {mpx = 0}
    if (mpy < 0) {mpy = 0}
    que = 'url=' + url +
    '&sid='+escape(sid) +
    '&cid='+escape(cid) +
    '&sch='+screen.height +
    '&scw='+screen.width +
    '&scc='+screen.colorDepth +
    '&mpx='+escape(mpx) +
    '&mpy='+escape(mpy) +
    '&exi='+escape(exiturl) +
    '&tit='+escape(document.title) +
    '&said='+said +
    '&id2='+id2;
    if (js_stat_uri) {
        setTimeout('after("'+js_stat_uri+ '?' + que+'")',1)
    }
}


if (window.attachEvent ) {
    document.attachEvent ( 'onclick' , clk);
} else {
    document.onclick = clk;
}

que = 'url=' + url +
'&sch=' + screen.height +
'&scw=' + screen.width +
'&scc=' + screen.colorDepth +
'&ref=' + ref +
'&sid=' + escape(sid) +
'&cid=' + escape(cid) +
'&tit=' + escape(document.title) +
'&said=' + said +
'&id2=' + id2;

if (js_stat_uri) {
    img = new Image(1,1);
    img.src = js_stat_uri + '?' + que;
}

