var adp_img, adp_ref, adp_num , adp_title;

adp_ref = (parent.frames.length > 0) ? parent.document.referrer+'' : document.referrer+'';
adp_ref = encodeString(adp_ref);
adp_num = (new Date()).getTime();
adp_title = document.title;
adp_title = encodeString(adp_title);
adp_pnm = encodeString(adp_pnm);

function f() {
  return true;
}
window.onerror = f;

adp_img = new Image(1,1);
adp_img.src = adp_header + '://' + adp_counter_domain + '/adpCnt/d?aid=' + adp_aid + '&dom=' + adp_domain + '&ref=' + adp_ref  + '&pnm=' + adp_pnm + '&ttl=' + adp_title +'';

function encodeString(str) {
	var adp_enc = "";
	for (var i = 0; i < str.length; i++) {
		var s = str.charAt(i);
		var u = str.charCodeAt(i);
		if (s == "") {
			adp_enc += "+";
		}
		else {
			if (u == 0x2a || u == 0x2d || u == 0x2e || u == 0x5f || ((u >= 0x30) && (u <= 0x39)) || ((u >= 0x41) && (u <= 0x5a)) || ((u >= 0x61) && (u <= 0x7a))) {	// escape check
				adp_enc = adp_enc + s;
			}
			else {
				if ((u >= 0x0) && (u <= 0x7f)) {	// for single byte
                    s = "0"+u.toString(16);
                    adp_enc += "%"+ s.substr(s.length-2);
                }
                else if (u > 0x1fffff) {	// for quaternary byte
                    adp_enc += "%" + (0xf0 + ((u & 0x1c0000) >> 18)).toString(16);
                    adp_enc += "%" + (0x80 + ((u & 0x3f000) >> 12)).toString(16);
                    adp_enc += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
                    adp_enc += "%" + (0x80 + (u & 0x3f)).toString(16);
                }
                else if (u > 0x7ff){	// for triple byte
                    adp_enc += "%" + (0xe0 + ((u & 0xf000) >> 12)).toString(16);
                    adp_enc += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
                    adp_enc += "%" + (0x80 + (u & 0x3f)).toString(16);
                }
                else {	// for double byte
                    adp_enc += "%" + (0xc0 + ((u & 0x7c0) >> 6)).toString(16);
                    adp_enc += "%" + (0x80 + (u & 0x3f)).toString(16);
                }
            }
        }
    }
    return adp_enc;
}


