function setCookie(name, value) { 
 var valueEscaped = escape(value); 
 var expiresDate = new Date(); 
 expiresDate.setTime(expiresDate.getTime() + 365 * 24 * 60 * 60 * 1000); // срок - 1 год
 var expires = expiresDate.toGMTString(); 
 var newCookie = name + "=" + valueEscaped + "; path=/; expires=" + expires; 
 if (valueEscaped.length <= 4000) document.cookie = newCookie + ";"; 
} 
function getCookie(name) { 
 var prefix = name + "="; 
 var cookieStartIndex = document.cookie.indexOf(prefix); 
 if (cookieStartIndex == -1) return null; 
 var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length); 
 if (cookieEndIndex == -1) cookieEndIndex = document.cookie.length; 
 return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex)); 
}
function changeStyle() {
 obj=document.getElementById('menustyle');
 numstyle=obj.selectedIndex+1;
 setCookie('user_skin',numstyle);
}

function refreshPage() {
	window.location=window.location.href;
}

function gotoURL(url){
	window.open(url,'_blank');
	return false;
}
function getBodyScrollTop() // координата верхнего левого угла видимой части с учетом скроллинга
{
   return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}
function centerblock (aw) {
			var windowWidth = document.documentElement.clientWidth;  
  			var windowHeight = document.documentElement.clientHeight;  
 			var popupHeight = $(aw).height();  
  			var popupWidth = $(aw).width();
			$(aw).css({  
   			 "position": "absolute", 
   			 "top": getBodyScrollTop()+windowHeight/2-popupHeight/2,  
  			 "left": windowWidth/2-popupWidth/2  
 			}); 
}

function refreshCaptcha(){
	$("#ajaxcaptcha img").attr('src','captcha/index.php?nocache='+Math.random());
}
	
function vote(id) {
	$("#ajaxwind").css({'display' : 'none'});
	$.get("ajax.php",{"act": "checkcanvote", "nocache": Math.random(), "id": id},  function(data) {	
		if (data!="YES") 
		{ 
		 alert("Ошибка: "+data);
		 return false;
		}
		else {
			$("#voteServerId").attr('value',id);
			$("#captchakeystring").attr('value','');
			var aw = $("#ajaxwind");
			centerblock(aw);
			$(aw).fadeIn("slow");
			refreshCaptcha();
			}
		
		});

	return false ;
}

$(document).ready(function(){
 $("#captchakeystring").attr('value','');
 
 $("#ajaxwind :submit").click(function(){
	var id = $("#voteServerId").attr("value");
	var keystring = $("#captchakeystring").attr('value');
//========================	
 	$.get("ajax.php",
		  {		"act": "voteserver",
		  		"id" : id,
				"keystring" : keystring
		  },
		  function(data){
			  if (data=="YES") {
				  alert("Голосование успешно");
 				  var tmp = $("tr[name=srv"+id+"] td:eq(4)");
				  var num = $(tmp).html();
				  if (!(num.indexOf("VIP")+1)) num ++;
				  $(tmp).css('color','#090');
				  $(tmp).html("<b>"+num+"</b>"); 
				  $("#ajaxwind").fadeOut("slow");
			  }
			  else
			  if (data=="INCORRECT") {
				  alert("Код введен неверно");
				  refreshCaptcha();
				  $("#captchakeystring").attr('value','');
			  }
			  else alert ("Ошибка : "+data);
		  }
	);
//========================
 });
//--

document.getElementById('menustyle').options[getCookie('user_skin')-1].selected=true;
});
