
function notif(){
	alert('Пожалуйста, не забудьте оставить свой отзыв о приложении. Для этого просто кликните на звезды под ссылкой на файл.');
}


function newForm(url,name,w,h,f){
	try{
		var g=(screen.availWidth-w)/2;
		var t=(screen.availHeight-h)/2;
		f+='width='+w+',height='+h+',top='+t+',left='+g+', toolbar=no, status=no, menubar=no';
		var newwindow=window.open(url,name,f);
		if (window.focus){
			newwindow.focus();
		}
	}catch(e){
		alert(e);
	}
}

function nac(id){
	newForm('viewcomments.php?a='+id,'vc',600,1000,'scrollbars=yes,resizable=no,');
}

function del_comment(aid,p){
	if (confirm('Вы точно хотите удалить комментарий?')) {
		if(document.getElementById("p"+p)){
			ajax('attach_comments','mode','del&p='+p+'&aid='+aid);
		}
	}
}

function show_ac(obj){
	if(document.getElementById('attach_comments')){
		var ac = document.getElementById('attach_comments');
		if(ac.style.display == 'none'){
			document.attach_form.text.value = '';
			document.attach_form.aid.value = obj.id;
			var x = y = 0;
			while(obj) {
				x+=obj.offsetLeft;
				y+=obj.offsetTop;
				obj=obj.offsetParent;
			}
			with (ac.style) {display = ''; position='absolute'; left=x; top=y+20;}
		} else {
			ac.style.display = 'none';		
		}
	}
}

function send_attach_comment(){
	var error='';
	if(document.attach_form.text.value.length <10) {
		  error = error+"Слишком короткий комментарий. \n";
	}	
		
	if(document.attach_form.vote.value == 0) {
		  error = error+"Не выбрана оценка. \n";
	}
	
	if(error!=''){
		error = "Вами были допущены следующие ошибки: \n"+error;	
		alert(error);
		return false;
	}else{
		return true;
	}
}

function menushow(menunum)
  {
    var currentmenu = document.getElementById("nav" + menunum);
	if(currentmenu.style.visibility == 'visible'){
	    currentmenu.style.visibility = 'hidden';
	    currentmenu.style.display = 'none';	
	}else{
	    currentmenu.style.display = 'block';
	    currentmenu.style.visibility = 'visible';	
	}
  }


function ref(object)
{
	if (document.getElementById)
	{
		return document.getElementById(object);
	}
	else if (document.all)
	{
		return eval('document.all.' + object);
	}
	else
	{
		return false;
	}
}

function expand(object)
{
	object = ref(object);
	
	if( !object.style )
	{
		return false;
	}
	else
	{
		object.style.display = '';
	}

	if (window.event)
	{
		window.event.cancelBubble = true;
	}
}

function contract(object)
{
	object = ref(object);
	
	if( !object.style )
	{
		return false;
	}
	else
	{
		object.style.display = 'none';
	}

	if (window.event)
	{
		window.event.cancelBubble = true;
	}
}

function toggle(object, path)
{
	image = ref(object + '_img');
	object = ref(object);

	if( !object.style )
	{
		return false;
	}
	
	if( object.style.display == 'none' )
	{
		object.style.display = '';
		image.src = path + 'contract.gif';
	}
	else
	{
		object.style.display = 'none';
		image.src = path + 'expand.gif';
	}
}


function show_hidden(object)
{
	image = ref(object + '_img');
	object = ref(object);
	if( !object.style || !image.src)
	{
		return false;
	}

	if( object.style.display == 'none' )
	{
		object.style.display = '';
		image.src = '/templates/subSilver/images/mini_contract.gif';
	}
	else
	{
		object.style.display = 'none';
		image.src = '/templates/subSilver/images/mini_expand.gif';		
	}
}

function cards(mode, post_id, user_id)
{
	var errors = 0;

	if(mode=='ban' || mode=='warn') {
		var desc4card  = prompt('Введите обоснование к карточке', '');
		if(desc4card.length <=10) {
			alert('ОШИБКА! - Очень короткое описание к карте');
			errors = 1;
			return;
		}
		if(mode!='ban'){
			var readonly  = prompt('Введите количестов дней продолжительности режима ReadOnly (0 - без режима, макс. 30)', 0);
			if(!readonly) {
     			errors = 1;
     			alert('ОШИБКА - Неверные данные о режиме ReadOnly');
     			return;
			}
		}

	}else if(mode=='addp_rank'){
			readonly  = prompt('Введите количество штрафных дней (От 1 - 30)', 7);
	} else {
		errors = 1;	
	}

	if (errors == 0) {
	parent.location='card.php?mode='+mode+'&desc='+desc4card+'&ro_date='+readonly+'&post_id='+post_id+'&user_id='+user_id;
	}
}


function desc4del(url)
{
	var msg  = prompt('Введите описание причины удаления', '');
	parent.location=url+'&msg='+msg;
}


function set_curator(s,u,t)
{
	var id  = parseInt(prompt('Введите ID нового куратора темы. Если куратор уже назначен, он будет заменен на нового. Для удаления введите 0.', (u==0)?'':u));
	if(!isNaN(id) && id >= 0){
		ajax('set_curator','u',id+'&t='+t+'&sid='+s);
	}else{
		alert('Вы должны ввести число большее 0');	
	}
}


function send2moder(postid)
{
	if (confirm('Сообщить модераторам о нарушении в этом сообщении?')) 
	{
		var msg  = prompt('Введите описание нарушения', '');
		if(msg.length <=10) {
			alert('ОШИБКА! - Очень короткое описание нарушения');	
		}else{
			ajax('send2moder','p',postid+'&msg='+msg);
		}
	}
}


function addrate(p, u, t, f)
{
	if (confirm('Вы уверены?')) {
		var myDate=new Date();
		myDate.setTime(myDate.getTime()+2*1000);
		document.cookie = "f_id =" + escape(f) + ("; expires=" + myDate.toGMTString()) ;	
		if(document.getElementById('r'+p)){
			ajax('addvote','p',p+'&r='+u+'&t='+t+'&f='+f);
		}
	}
}

function addmedal(mode, post_id, user_id)
{
	if (confirm('Вы уверены?')) {
	parent.location='medals.php?p='+post_id+'&u='+user_id+'&mode='+mode;
	}
}

function ajax(go_, for_, to_) {
	var today = new Date();
	var script = document.createElement('script');
	with(script){
		setAttribute("type", "text/javascript", 0);
		setAttribute("charset", "windows-1251", 0);
		setAttribute("src", '/ajax/' + go_ + '.php?' + for_ + '=' + to_ + '&time=' + today.getTime(), 0);
	}
	var head = document.getElementsByTagName("head")[0] || document.documentElement;
	head.insertBefore(script, head.firstChild);
	script.onload = function(){head.removeChild(script);};
}