function wr(code)
{
		document.fr.box.value=document.fr.box.value+code;				
}

function pod(id)
{
	document.getElementById(id).style.border="#c0cb8d double 3px";
}
function ubr(id)
{
	document.getElementById(id).style.border="0px";
}


function openwin(hero)
{
	url="nwgaids.php?hero="+hero;
	window.navigate='';
	window.location=url;
}


function openWin2(item) 
		{
			winurl="view.php?item="+item;
			myWin= open(winurl,"displayWindow","width=600,height=200,left=350,top=200,status=no,scrolling=yes,toolbar=no,menubar=yes");
		}
function openWin2big(item) 
		{
		winurl="view.php?item="+item;
	myWin= open(winurl,"displayWindow","width=600,height=265,left=350,top=200,scrolling=yes,status=no,toolbar=no,menubar=yes");
	}
	function openWin2big1(item) 
		{
		winurl="view.php?item="+item;
	myWin= open(winurl,"displayWindow","width=600,height=400,left=350,top=200,scrolling=yes,status=no,toolbar=no,menubar=yes");
	}
		function openWin2big2(item) 
		{
		winurl="view.php?item="+item;
	myWin= open(winurl,"displayWindow","width=600,height=480,left=350,top=200,scrolling=yes,status=no,toolbar=no,menubar=yes");
	}
	function openWin2big3(item) 
		{
		winurl="view.php?item="+item;
	myWin= open(winurl,"displayWindow","width=600,height=620,left=350,top=200,scrolling=yes,status=no,toolbar=no,menubar=yes");
	}
	

function pod1(id)
{
	document.getElementById(id).style.border="#ce6b4d solid 1px";
}
function ubr1(id)
{
	document.getElementById(id).style.border="0px";
}
function ur1(id)
{
	document.getElementById(id).style.border="1px solid #000";
}
function ursub(id)
{
	document.getElementById(id).style.border="1px solid #c2b7aa";
}
 function elem(code)
{
		document.fr.box.value=document.fr.box.value+"["+code+"]";				
}

function storeCaret(element)
{
   if (document.selection && document.selection.createRange){
      element.caretPos=document.selection.createRange().duplicate();
   }else if(element && element.selectionStart){
      element.caretPosNN=element.selectionStart;
   }
}

function wr1(text){
   if (document.fr.box && document.fr.box.caretPos){
      document.fr.box.caretPos.text=text; 
   }else if (document.fr.box && document.fr.box.caretPosNN+1 && document.fr.box.selectionEnd+1){
      document.fr.box.value=document.fr.box.value.substring(0,document.fr.box.selectionStart)+text+document.fr.box.value.substring(document.fr.box.selectionEnd,document.fr.box.value.length); 
      document.fr.box.setSelectionRange(document.fr.box.caretPosNN+text.length,document.fr.box.caretPosNN+text.length);
   }else if (document.fr.box){
      document.fr.box.value+=text;
   }
} 
function del(f,id_theme,post)
{
	window.location="del.php?f="+f+"&id_theme="+id_theme+"&post="+post;
}
function red(f,id_theme,post)
{
	window.location="edittopic.php?f="+f+"&id_theme="+id_theme+"&post="+post;
}
function quet(f,id_theme,post)
{
	window.location="viewtopic.php?f="+f+"&id_theme="+id_theme+"&quet="+post;
}

function delt(f1,id_theme1)
{
	window.location="deltheme.php?f="+f1+"&id_theme="+id_theme1;
}

function redgaid(f,id_theme,post)
{
	window.location="editgaid.php?f="+f+"&id_theme="+id_theme+"&post="+post;
}
function poll(hero)
{
	window.location="poll.php?hero="+hero;
}

function over1(dota)
{
	if (dota=="dota")
	{
	document.getElementById(dota).style.background=" url(../picture/menu6.jpg)";
	}
	else
	{
		document.getElementById(dota).style.background=" url(../picture/menu6.jpg)";
	}
}
function out1(dota)
{
	document.getElementById(dota).style.background="#231013";
}

function anchor()
{	
	Adress=window.prompt("Введите ссылку пример:dotawar.ru! Без http://!!!","");
	tt=window.prompt("Введите тескт который будет отображаться ссылкой","Посетите мою домашнюю страницу");
	text="[url="+Adress+"]"+tt+"[/url]";
	if (Adress!=null)
	{
	if (document.fr.box && document.fr.box.caretPos){
      document.fr.box.caretPos.text=text; 
   }else if (document.fr.box && document.fr.box.caretPosNN+1 && document.fr.box.selectionEnd+1){
      document.fr.box.value=document.fr.box.value.substring(0,document.fr.box.selectionStart)+text+document.fr.box.value.substring(document.fr.box.selectionEnd,document.fr.box.value.length); 
      document.fr.box.setSelectionRange(document.fr.box.caretPosNN+text.length,document.fr.box.caretPosNN+text.length);
   }else if (document.fr.box)
   {
      document.fr.box.value+=text;
   }
   }
}
function fileedit(id_theme1)
{
	window.location="fileedit.php?file="+id_theme1;
}
function than(id_forum,id_theme,aut)
{
	window.location="than.php?aut="+aut+"&id_theme="+id_theme+"&f="+id_forum;
}
function click1()
{
	document.getElementById("help1").style.visibility="hidden";
	document.getElementById("href").style.visibility="visible";
}

function load_rate(file_id,rate_type)
{
	//AJAX	
	var request = new Request.JSON({
      'url' : '../html/ajax.php',
      'method' : 'get',
      'data' : {
        'task'  : 'get_rate',
		'file_id'  : file_id,
		'rate_type' : rate_type
      },
      'onComplete' : function(filerate)
      {
	  if (filerate["is_rate"])
	 {
		if (filerate["all_rate"]["0"])rate_1000=filerate["all_rate"]["0"];else rate_1000=0;
		if (filerate["all_rate"]["1"])rate_500=filerate["all_rate"]["1"];else rate_500=0;
		if (filerate["all_rate"]["2"])rate_300=filerate["all_rate"]["2"];else rate_300=0;
		
		rate_str1='голоса';
		rate_str2='голоса';
		rate_str3='голоса';
		if (rate_1000==1)
		{ rate_str1="голос"; }
		else
		{
			if(rate_1000==0)
			{
				rate_str1="голосов";	
			}
		}		
		if (rate_500==1)
		{ rate_str2="голос"; } 
		if (rate_300==1)
		{ rate_str3="голос"; } 
		all_rate=parseInt(rate_1000)+parseInt(rate_500)+parseInt(rate_300);
		
			$('rate_div').innerHTML="<table align='center' width='100%'><tr><td colspan='3' align='center'><font class='mes'>Спасибо за ваш голос!<br/> Всего голосов:"+all_rate+"<br/><font class='red'>Рейтинг файла:"+filerate["average_rate"]+"</font></font></td></tr><tr><td valign='middle' align='right'><img src='../picture/rate/1000.jpg'><br>("+rate_1000+" "+rate_str1+")</td><td valign='bottom' align='center'><img src='../picture/rate/500.jpg'><br>("+rate_500+" "+rate_str2+")</td><td valign='bottom' ><img src='../picture/rate/300.jpg'><br>("+rate_300+" "+rate_str3+")</td></tr></table>";
		}
		else
		{
			$('rate_div').innerHTML="<table align='center' width='100%'><tr><td colspan='3' align='center'>Голосуем за файл.(просто нажимая картинку)</td></tr><tr><td align='right'><img src='../picture/rate/1000.jpg' onclick='rate_file("+file_id+",1000,\""+rate_type+"\")' class='rate_img' title='Поставить оценку 1000'></td><td align='center' valign='bottom'><img src='../picture/rate/500.jpg' onclick='rate_file("+file_id+",500,\""+rate_type+"\")'  class='rate_img' title='Поставить оценку 500'></td><td valign='bottom'><img src='../picture/rate/300.jpg' onclick='rate_file("+file_id+",300,\""+rate_type+"\")'  class='rate_img' title='Поставить оценку 300'> </td></tr><tr><td align='center' colspan='2'></td></tr></table>";
		}
	  }
    });
   request.send();
}
function rate_file(file_id,file_rate,rate_type)
{
	//AJAX	
	var request = new Request.JSON({
      'url' : '../html/ajax.php',
      'method' : 'get',
      'data' : {
        'task'  : 'rate_file',
		'file_id'  : file_id,
		'file_rate'  : file_rate,
		'rate_type' : rate_type
      },
      'onComplete' : function(filerate)
      {
		load_rate(file_id,rate_type);
	  }
    });
   request.send();
}

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 add_num_d(file_id)
{
	//AJAX	
	var request = new Request.JSON({
      'url' : '../html/ajax.php',
      'method' : 'get',
      'data' : {
        'task'  : 'add_num_d',
		'file_id'  : file_id
      },
      'onComplete' : function(filerate)
      {
		
	  }
    });
   request.send();
}
