function register () {
	document.location.href = "http://"+cities[Math.floor(Math.random()*cities.length)]+"."+domain+"/reg.pl";
}

function forum () {
	document.location.href = "http://"+cities[Math.floor(Math.random()*cities.length)]+"."+domain+"/forum.pl";
}

var url = window.location + "";
var addr = '';

if ((url.indexOf('r.'+domain)>=0) || (url.indexOf('www.'+domain)>=0) || (url.indexOf('http://'+domain)>=0)) {
	addr = 'http://'+cities[0]+'.'+domain+'/';
}

function MM_openBrWindow(theURL,winName,features) {
	window.open(theURL, winName, features);
}

function login(domain,user,pass) {
    MM_openBrWindow('http://'+domain+'/enter.pl?action=enter&carnageuser='+user+'&carnagepass='+pass,'','scrollbars=yes,resizable=yes,width='+screen.availWidth+',height='+screen.availHeight+',left=0,top=0');
}

function loginpost() {
	MM_openBrWindow('about:blank', 'loginwindow', 'height=' + screen.availHeight + ', left=0, resizable=1, top=0, width=' + screen.availWidth + '');
}

var timerID = null;
var timerRunning = false;

if(document.referrer && !getCookie('rf')) {
    document.cookie = "rf="+escape(document.referrer)+"; expires=Tue, 28 Dec 2010 00:00:00; domain=carnage.ru;";
}

if (url.indexOf('r.carnage.ru') >= 0) {
	var newid = window.location.search;
	newid = newid.replace("?","");
	if (newid.length>0) {
		document.cookie = "newid="+newid+"; expires=Tue, 28 Dec 2010 00:00:00; domain="+domain+";";
		document.location.href = "/";
	}
}

function getCookie(Name) {
	var search = Name + '=';
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = document.cookie.indexOf(';', offset);
			if (end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(offset, end));
		}
	}
}

$(function(){
	if($.cookie('no-maximize') == 1) {
		$('#maximize')[0].checked = false;
	}
	
	$('#auth-form').submit(function() {
		if(this['maximize'].checked) {
			$.cookie('no-maximize', null, { path: '/', domain: '.' + domain });
			loginpost();
			this.target='loginwindow';
			this.submit();
			return false;
		} else {
			$.cookie('no-maximize', '1', { expires: 365, path: '/', domain: '.' + domain });
		}
	});
});