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

function setCookie (name, value, expires, path, domain, secure) {
      document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function show_ban(banner) {

obj = document.getElementById(banner);

obj.style.top = ((document.body.clientHeight/2) + document.body.scrollTop) - 150;
obj.style.left = ((document.body.clientWidth/2) + document.body.scrollLeft) - 150;
obj.style.visibility = "visible";

}

function hide_ban(banner) {

document.getElementById(banner).style.visibility="hidden"

}

function img_() {

return '<img src="/capcha' + get_random() + '.jpg" alt="Включите отобращение картинок!" style="border:1px solid #000000"/>';

}

function reload_captcha() {

document.getElementById("captcha_img").innerHTML = img_();
document.getElementById("r_capcha").value = '';

}

function get_random()
{
    var ranNum= Math.floor(Math.random()*1000) + Math.floor(Math.random()*1000);
    return ranNum;
}

function showlink() {

document.getElementById("link").innerHTML = '<table><tr><td><img src="/capcha' + get_random() + '.jpg" alt="Включите отображение картинок!" style="border:1px solid #000000" /></td><td><input class="capcha" type="text" id="capchaN" maxlength="4" /></td></tr></table><a href="/players" onClick="players(ipserv); starttimer(); return false;" class=menu>Обновить список игроков</a><br><br>';
window.clearTimeout(ttt);

}

function starttimer() {

document.getElementById("link").innerHTML = '';
ttt = window.setTimeout("showlink()",10000);

}

function showcomms() {

document.getElementById("showlink").style.display = "none";
document.getElementById("hiddencomms").style.display = "inline";

}

function copy_map(map) {

document.getElementById("map_").value = map;
document.getElementById("mod_").value = 'anymap';
document.getElementById("slot_").value = 0;
document.getElementById("choose").submit();

}

function move_banners() {

var banners = new Array('captcha','ava_info','ban','err','del_err','liked','edit');

for ( var jj in banners ) {
	if (document.getElementById(banners[jj]) != null)
		{
		if (document.getElementById(banners[jj]).style.visibility=="visible")
			{
			document.getElementById(banners[jj]).style.top = ((document.body.clientHeight/2) + document.body.scrollTop) - 150;
			}
		}
	}
}

function close_all() {
	
setCookie("update", "0", "Mon, 01-Jan-2001 00:00:00 GMT", "/");
hide_ban('upd');

}

function img_set() {

document.getelementbyid('cp4').innerHTML ='<img src="/capcha' + get_random() + '.jpg" alt="Включите отобращение картинок!" />';
window.clearTimeout(fff);

}

function img_timer() {

fff = window.setTimeout("img_set();",1000);

}

function skukojka(block,button) {

el = document.getElementById(block);
el2 = document.getElementById(button);
var display = el.style.display ? '' : 'none';
el.style.display = display;

var plormin = el2.innerHTML;
switch (plormin)
	{
	case '+' : el2.innerHTML = '-'; plormin = '-'; break;
	case '-' : el2.innerHTML = '+'; plormin = '+'; break;
	}

}

function like_switch_mini(id, type)
	{
	block = document.getElementById('liked_'+id);
	switch (type)
		{
		case 'add' :
			block.innerHTML = '<img src="/images/like_out_del.png" onClick="liked(\'' + id + '\'); like_switch_mini(\'' + id + '\',\'del\');"'+
			'onMouseOver="this.src=\'/images/like_on_del.png\'" onMouseOut="this.src=\'/images/like_out_del.png\'" />';
		break;
		case 'del' :
			block.innerHTML = '<img src="/images/like_out.png" onClick="liked(\'' + id + '\'); like_switch_mini(\'' + id + '\',\'add\');"'+
			'onMouseOver="this.src=\'/images/like_on.png\'" onMouseOut="this.src=\'/images/like_out.png\'" />';
		break;
		}
	}

function like_switch_big(id, type)
	{
	block = document.getElementById('liked_'+id);
	switch (type)
		{
		case 'add' :
			block.innerHTML = '<img src="/images/like_out_del_big.png" onClick="liked(\'' + id + '\',1); like_switch_big(\'' + id + '\',\'del\');"'+
			'onMouseOver="this.src=\'/images/like_on_del_big.png\'" onMouseOut="this.src=\'/images/like_out_del_big.png\'" />';
		break;
		case 'del' :
			block.innerHTML = '<img src="/images/like_out_big.png" onClick="liked(\'' + id + '\',1); like_switch_big(\'' + id + '\',\'add\');" '+
			'onMouseOver="this.src=\'/images/like_on_big.png\'" onMouseOut="this.src=\'/images/like_out_big.png\'" />';
		break;
		}
	}

function fixEvent(e) {
	// получить объект событие для IE
	e = e || window.event

	// добавить pageX/pageY для IE
	if ( e.pageX == null && e.clientX != null ) {
		var html = document.documentElement
		var body = document.body
		e.pageX = e.clientX + (html && html.scrollLeft || body && body.scrollLeft || 0) - (html.clientLeft || 0)
		e.pageY = e.clientY + (html && html.scrollTop || body && body.scrollTop || 0) - (html.clientTop || 0)
	}

	// добавить which для IE
	if (!e.which && e.button) {
		e.which = e.button & 1 ? 1 : ( e.button & 2 ? 3 : ( e.button & 4 ? 2 : 0 ) )
	}

	return e
}


var dragMaster = (function() {

	var dragObject
	var mouseOffset

	// получить сдвиг target относительно курсора мыши
	function getMouseOffset(target, e) {
		var docPos	= getPosition(target)
		return {x:e.pageX - docPos.x, y:e.pageY - docPos.y}
	}

	function mouseUp(){
		dragObject = null

		// очистить обработчики, т.к перенос закончен
		document.onmousemove = null
		document.onmouseup = null
		document.ondragstart = null
		document.body.onselectstart = null
	}

	function mouseMove(e){
		e = fixEvent(e)

		with(dragObject.style) {
			top = e.pageY - mouseOffset.y + 'px'
			left = e.pageX - mouseOffset.x + 'px'
		}

		return false
	}

	function mouseDown(e,element) {
		e = fixEvent(e)
		if (e.which!=1) return

		dragObject  = document.getElementById(this.id.substr(5));

		// получить сдвиг элемента относительно курсора мыши
		mouseOffset = getMouseOffset(this, e)

		// эти обработчики отслеживают процесс и окончание переноса
		document.onmousemove = mouseMove
		document.onmouseup = mouseUp

		// отменить перенос и выделение текста при клике на тексте
		 document.ondragstart = function() { return false }
		 document.body.onselectstart = function() { return false }

		return false
	}

	return {
		makeDraggable: function(head){
			head.onmousedown = mouseDown
		}
	}

}())

function getPosition(e){
	var left = 0
	var top  = 0

	while (e.offsetParent){
		left += e.offsetLeft
		top  += e.offsetTop
		e = e.offsetParent
	}

	left += e.offsetLeft
	top  += e.offsetTop

	return {x:left, y:top}
}

function form_price(el,mn) {
	var val;
	val = el.value.replace(/[^0-9]/ig,'');
	el.value = val;
   	
	var price;
	price = parseInt(el.value) * mn;
	document.getElementById('price').innerHTML = price.toString();
}

function pay_ch(type) {
	var fields;
	switch (type)
		{
		case 'vip' : 
			fields = '<tr class="title_add">'+
	'<td>Срок (в днях)</td><td align="right">Цена</td>'+
	'</tr>'+
	'<tr><td>'+
	'<input type="text" class="srok" name="srok" id="srok" '+
		'value="30" onkeyup="form_price(this,5);" maxlength="3"/></td>'+
	'<td class="price" align="right"><span id="price">150</span> руб.</td></tr>';			
		break;
		case 'head' : 
			fields = '<tr class="title_add">'+
	'<td>Срок (в днях)</td><td align="right">Цена</td>'+
	'</tr>'+
	'<tr><td>'+
	'<input type="text" class="srok" name="srok" id="srok" '+
		'value="30" onkeyup="form_price(this,10);" maxlength="3"/></td>'+
	'<td class="price" align="right"><span id="price">300</span> руб.</td></tr>';				
		break;
		case 'up' : 
			fields = '<tr class="title_add">'+
	'<td rowspan="2">Убедитесь, что сервер исправно<br>работает и пингуется!!!<br>' +
	'Наш скрипт не проверяет<br>доступность, а лишь делает<br>его доступным для мониторинга!' +
	'<input type="hidden" name="srok" value="1" /></td><td align="right">Цена</td>'+
	'</tr>'+
	'<tr>'+
	'<td class="price" align="right">10 руб.</td></tr>';				
		break;
		case 'moder' : 
			fields = '<tr class="title_add">'+
	'<td rowspan="2">Убедитесь, что сервер исправно<br>работает и пингуется!!!<br>' +
	'Наш скрипт не проверяет<br>доступность, а лишь делает<br>его доступным для мониторинга!' +
	'<input type="hidden" name="srok" value="1" /></td><td align="right">Цена</td>'+
	'</tr>'+
	'<tr>'+
	'<td class="price" align="right">10 руб.</td></tr>';				
		break;
		}
	document.getElementById('fields').innerHTML = fields;
}
