function ida(id){return document.getElementById(id);}
var font = 1;
function resizeFont()
{
	switch(font)
	{
		case 0:
			font = 1;
			ida('body').style.fontSize = '10px';
		break;
		
		case 1:
			font = 2;
			ida('body').style.fontSize = '12px';
		break;
		
		case 2:
			font = 0;
			ida('body').style.fontSize = '14px';
		break;
	}	
}

function ida(id){ return document.getElementById(id);}
function sh(id)
{
	if(ida(id).style.display == "none") ida(id).style.display = "block";
	else ida(id).style.display = "none";
}
function shm(id, arr)
{
	for(i=0;i<arr.length;i++){ida(arr[i]).style.display = "none"}
	ida(id).style.display = "block";
}
function hole(a){};
var counter;
function raiting(id, module, action, ch, col)
{
	counter = ch;
	var AJAX = new AjaxRequest(nL + '/ucp/raiting/');
	AJAX.OnComplete(raitingResult);
	var data = {'id':id,'module':module,'action':action,'col':col};
	AJAX.Post(data);
}

function raitingResult(text)
{
//	alert(text);
	af = text.split("<xmltager>");
//	alert(af[2]);
	if(af[0] == "false") alert("Вы уже меняли рейтинг");
	else
	{
	//	alert(ida("r_num_" + counter).innerHTML);
		if(af[1] == "minus") ida("r_num_" + counter).innerHTML = Number(ida("r_num_" + counter).innerHTML) - 1;
		else if(af[1] == "plus") ida("r_num_" + counter).innerHTML = Number(ida("r_num_" + counter).innerHTML) + 1;
	}
}
var hcb = 0;
function toComments(id)
{
	if(ida('commentsbox'+id).style.display == 'none')
	{
		ida('commentsbox'+id).style.height = 0;
		ida('commentsbox'+id).style.display = 'block';
		hcb = 0;
		openComment(id, "open");
		ida('commentsbox'+id).innerHTML = "<img src=\"/style/original/imageset/css/loading.gif\" />";
		var AJAX = new AjaxRequest(nL + '/ucp/raiting/');
		AJAX.OnComplete(raitingResult);
		var data = {'id':id,'module':module,'action':action,'col':col};
		AJAX.Post(data);
	}else{
		hcb = 300;
		openComment(id, "close");
		
	}
}

function openComment(id, type)
{
	ida('commentsbox'+id).style.height = hcb + 'px';
	if(type == "open")
	{
		hcb = hcb+14;
		if(hcb < 300) setTimeout("openComment(" + id + ", '" + type + "')", 20);
	}else{
		hcb = hcb-14;
		if(hcb > 0) setTimeout("openComment(" + id + ", '" + type + "')", 20);
		else ida('commentsbox'+id).style.display = 'none';
	}
}
var trackLast = "";
function pPlay(url, id)
{
	if(trackLast != "")
	{
		ida('pl'+trackLast).style.display = "inline";
		ida('pa'+trackLast).style.display = "none";	
	}
	ida('playerbox').style.display = "block";
	ida('pl'+id).style.display = "none";
	ida('pa'+id).style.display = "inline";
	ida('playera').SetVariable("player:jsUrl", url);
	ida('playera').SetVariable('player:jsPlay', '');
	trackLast = id;
}

function pPause(id)
{
	ida('pl'+id).style.display = "inline";
	ida('pa'+id).style.display = "none";
	ida('playera').SetVariable("player:jsPause", "");
}


//Функция, которая делает видимым наш слой и вкладывает в него необходимый текст.
function helpBox(title, text) {
//Вкладываем текст
        document.getElementById('helpTitle').innerHTML = title;
        document.getElementById('helpText').innerHTML = text;

//Делаем видимым\невидимым
        if(document.getElementById('help').style.display == 'none'){ 
                document.getElementById('help').style.display = 'block';
        }else{
                document.getElementById('help').style.display = 'none';
        }
}

function musicInfo(id, type)
{
	
	var AJAX = new AjaxRequest(nL + '/music/getcontent/');
	AJAX.OnComplete(toBox);
	var data = {'id':id,'type':type};
	AJAX.Post(data);
	
}

function toBox(result)
{
	var aaa = result.split("<xml>");
	ida('helpTitle').innerHTML = aaa[0];
	ida('helpText').innerHTML = aaa[1];
	ida('help').style.display = 'block';
}

function closeHelp()
{
	ida('helpTitle').innerHTML = '';
	ida('helpText').innerHTML = '';
	ida('help').style.display = 'none';
}


document.captureEvents(Event.KEYPRESS);
document.onkeypress = ctrlEnter;

function ctrlEnter(event)
{
if((event.ctrlKey) && ((event.keyCode == 0xA)||(event.keyCode == 0xD)))
    {
        if(document.activeElement.id == "dsd") submitCumment();
        if(document.activeElement.id == "forumpost") ida('postform').submit();
    }
}

function submitCumment()
{
	var AJAX = new AjaxRequest(ida('comTo').value);
	AJAX.OnComplete(submitCummentResult);
	var data = {'text':ida('dsd').value};
	AJAX.Post(data);
}

function submitCummentResult(result)
{
	ida('commentBox').innerHTML = result;
	ida('commentBox').scrollTo(0,0); 
	
	var obj = ida('commentBox');
	if(!obj.maxVert) init(ida('commentBox'));
	obj.scrollTop = 0;
}

function deleteComments(id)
{
	var AJAX = new AjaxRequest("/ucp/comment_delete/" + id + "/");
	AJAX.OnComplete(deleteCummentResult);
	var data = {'id':id};
	AJAX.Post(data);
}

function deleteCummentResult(result)
{
	ida('comment'+result).style.display = 'none';
}

function init(obj) {
	  if (obj) {
	    obj.state = 0;//инициализируем состояние
	    obj.timer = null;
	    obj.maxVert = obj.scrollHeight - obj.offsetHeight;//максимальная высота прокрутки
	  }
	}

function ucp_getpanel(id)
{
	ida('ucp_panel').style.display = 'block';
	ida('panelregistration').style.display = 'none';
	ida('panellogin').style.display = 'none';
	ida('panelrecovery').style.display = 'none';
	
	ida(id).style.display = 'block';
}

var files = 3;
function addFiles()
{
	if(files < 5)
	{
		ida('_files').innerHTML += '<input type="file" name="_file[]" /><br />';
		files++;
	}
}


function defPosition(event) {
    var x = y = 0;
    if (document.attachEvent != null) { // Internet Explorer & Opera
        x = window.event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
        y = window.event.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
    } else if (!document.attachEvent && document.addEventListener) { // Gecko
        x = event.clientX + window.scrollX;
        y = event.clientY + window.scrollY;
    } else {
        // Do nothing
    }
    return {x:x, y:y};
}

var indxp = 0;
var indyp = 0;
var flag = false;
var flag2 = false;

document.onmousemove = function(event)
{
    var event = event || window.event;
    if(flag == true)
    {
    	if(flag2 == false)
    	{
    		wx = absPosition(document.getElementById('help')).x;
    		wy = absPosition(document.getElementById('help')).y;
    		cx = defPosition(event).x;
    		cy = defPosition(event).y;
    		indxp = cx - wx - 350;
    		indyp = cy - wy;
    		flag2 = true;
    	}
        document.getElementById('help').style.left = (defPosition(event).x - indxp) + "px";
        document.getElementById('help').style.top  = defPosition(event).y - indyp + "px";
    }
}

function absPosition(obj) { 
    var x = y = 0; 
    while(obj) { 
          x += obj.offsetLeft; 
          y += obj.offsetTop; 
          obj = obj.offsetParent; 
    } 
    return {x:x, y:y}; 
}

function onDropWindow()
{
	flag = true;
}

function offDropWindow()
{
	indxp = 0;
	indyp = 0;
	flag = false;
	flag2 = false;
}
