
String.prototype.encodeHTML = function() {
	return this.replace(/([^\x01-\x7E])/g, function(c){
		return '&#'+c.charCodeAt(0)+';'
	});
}

var $host = location.hostname;
if((/^(.*\.)?referer\.us$/i).test($host))$host='referer.us';

function $(i){return document.getElementById(i)};

function $map(){
	if($host!='referer.us'){
		document.write('<div class="m"><ul class="menu"><li><a href="/own-referring-domain.html">Domain Mapping</a>: <strong class="error">'+$host+'</strong></li>');
		document.write('<li><a href="/make-long-urls-short.html"><strong class="error">Shorten an URL</strong></a></li>');
		document.write('<li><a href="/hide-http-referer.html"><strong class="error">Create a No-Referer Url</strong></a></li>');
		document.write('<li><a href="/spoof-http-referer.html"><strong class="error">Create a Fake-Referer Url</strong></a></li>');
		document.write('</ul></div>');
	}
}

function $domain(){
	var d = ['referer.us','access.im','asylum.name','cctv.ws','emap.ws','exel.us','freepl.us','ly9.net','mug.gs','owned.name','plugin.name','shortme.ws','yogift.us'];
	d.push($host);
	for(var i=0;i<d.length;i++){
		var s = d[i];
		document.write('<option value="'+s+'"'+((s==$host)?' selected="selected"':'')+'>'+s+'</option>');
	}
}

function $get(u, d){
	var x;
	try{x=new XMLHttpRequest()}
	catch(e){try{x=new ActiveXObject('Msxml2.XMLHTTP')}
	catch(e){try{x=new ActiveXObject('Microsoft.XMLHTTP')}
	catch(e){return d('{Error: XMLHTTPRequest Unsupported, Cannot Read Data}')}}}
	try{
		x.open('GET', u, true);
		x.onreadystatechange = function(){
			if(x.readyState==4)d(x.responseText);
		};
		x.send(null);
	}catch(e){d('{Error: XMLHTTPRequest Read Error}')}
}

function createShortLink(url, uri, anchor, Link, HTML, UBB, se){
	Link.value = 'Please wait...';
	HTML.value = UBB.value = '';
	function showShortLink(code){
		if(code.substr(0,7)!='{Error:'){
			var d = $('rDomain'), h='referer.us';
			if(d)h=d.options[d.selectedIndex].value;
			if(h=='referer.us'){
				code = ((/^https:\/\//i).test(url)?'https':'http')+'://referer.us'+code;
			}else{
				code = location.protocol+'//'+h+code;
			}
			Link.value = code;
			var a = anchor||code;
			HTML.value = '<a href="'+code+'">'+a+'</a>';
			UBB.value = '[URL='+code+']'+a+'[/URL]';
		}else{
			Link.value = code;
		}
	}
	$get('/s/?url='+encodeURIComponent(url)+'&uri='+encodeURIComponent(uri||'')+'&se='+(se?1:0), showShortLink);
	return false;
}