var wait_message = "<img src='/img/ajax-loader3.gif' alt='' align='absmiddle' style='margin:-2px 5px 0px 0px;' />Подождите, пожалуйста&#133;";
var wait_buttons = "<img src='/img/ajax-loader2.gif' alt='' />";
var wait_icon = "<img src='/img/ajax.gif' alt='' align='absmiddle' />";
var wait2 = "<img src='/img/ajax-loader3.gif' alt='' align='absmiddle' style='margin:-2px 5px 0px 0px;' />";

var img_error = "";
var img_ok = "";

var email_not_valid = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;
var email_valid = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
var login_valid = /^[A-Za-z0-9-_]+?$/;
// ..................................................................

 function explode(seporator, str) {
   var aa;  
   aa=str.toString().split(seporator.toString());    
   return aa;
 }
// ..................................................................
 function lib_open_img_window(src,width,height){ 
   if(width==0)
     width=500;
   width+=20;
   if(height==0)
     height=400;
   height+=20;
   if(height>600)
     height=600;
   var left = (screen.availWidth/2) - (width/2);
   var top = (screen.availHeight/2) - (height/2);
   info=window.open('/img_preview.php?src='+src,'info','resizable=1, scrollbars=1, toolbar=0, status=0, width='+width+', height='+height+', left='+left+', top='+top);
   info.focus();
 }
var lastReplyBoxId = 0;
// ..................................................................
function showReplyForm(id) {
    var replyBox = document.getElementById('reply_box' + id);
    var replyForm = document.getElementById('form' + id);
    if (lastReplyBoxId) {
        document.getElementById('reply_box' + lastReplyBoxId).style.display = 'none';
    }
    replyBox.style.display = 'block';
    lastReplyBoxId = id;
    if (replyForm.elements['author'].value == '') {
        replyForm.elements['author'].focus();
    } else {
        replyForm.elements['text'].focus();
    }
}
// ..................................................................
 function open_descr(id){
   width=450;
   height=500;
   var left = (screen.availWidth/2) - (width/2);
   var top = (screen.availHeight/2) - (height/2);
   info=window.open('/stats_table/'+id,'info','resizable=1, scrollbars=1, toolbar=0, status=0, width='+width+', height='+height+', left='+left+', top='+top);
   info.focus();
 }
 // ..................................................................
  function open_members(id){
   width=600;
   height=700;
   var left = (screen.availWidth/2) - (width/2);
   var top = (screen.availHeight/2) - (height/2);
   info=window.open('/users.php?popup=Y&id='+id,'info','resizable=1, scrollbars=1, toolbar=0, status=0, width='+width+', height='+height+', left='+left+', top='+top);
   info.focus();
 }
 // ..................................................................
  function OpenMatchStat(id){
   width=800;
   height=500;
   var left = (screen.availWidth/2) - (width/2);
   var top = (screen.availHeight/2) - (height/2);
   info=window.open('http://www4.marathonbet.com/tab_3t.phtml?event='+id,'info','resizable=1, scrollbars=1, toolbar=0, status=0, width='+width+', height='+height+', left='+left+', top='+top);
   info.focus();
 }
 // ..................................................................
 
 function windowPopup(wUrl, wWidth, wHeight, wScrolls) 
{
    var xPos = (screen.availWidth  / 2) - (wWidth / 2);
    var yPos = (screen.availHeight / 2) - (wHeight / 2);
    if (!wScrolls) {
        wScrolls = 'yes';        
    } else {
        wScrolls = 'no';
    }
    window.open(wUrl, '', 'directories=no,location=no,menubar=no,resizable=yes,scrollbars='+wScrolls+',status=no,toolbar=no,width='+wWidth+',height='+wHeight+',left='+xPos+',top='+yPos);
}

// ..................................................................

function open_komand(id){
   width=600;
   height=700;
   var left = (screen.availWidth/2) - (width/2);
   var top = (screen.availHeight/2) - (height/2);
   info=window.open('/komand_get.php?popup=Y&id='+id,'info','resizable=1, scrollbars=1, toolbar=0, status=0, width='+width+', height='+height+', left='+left+', top='+top);
   info.focus();
 }
 
 
// ..................................................................

function order_add(user_id, turnir_id)
{
	var content = $("#" + turnir_id).html();
	$("#" + turnir_id).html(wait_message);

	$.ajax({
		type: "POST",
		url: "/jx/order.php",
		data: "act=add&user_id=" + user_id +"&turnir_id=" + turnir_id,
		success: function(msg)
		{
			if(msg == "ok")
			{
				$("#" + turnir_id).hide().html("<img src='/img/apply.gif' alt='' align='absmiddle' style='margin:-2px 5px 0px 0px;' />&nbsp;Заявка на участие отправлена.");
				$("#" + turnir_id).fadeIn(200);
			}
			else if(msg == "limit")
			{
			    $("#" + turnir_id).hide();
				$("#" + turnir_id).find("span").html("Ошибка. Запрос не принят.");
				$("#" + turnir_id).fadeIn(200);
			}
			else
			{
				$("#" + turnir_id).html(content);
			}
		}
	});

	return false;
}
 
 function messageW(user_id) {

	this_top = (screen.height - 650) / 2;
	this_left = (screen.width - 550) / 2;

	var window_id = "message_" + user_id;
	var xx = window.open("/message/?user_id=" + user_id, window_id, "toolbar=no,scrollbars=yes,menubar=no,directories=no,status=no,resizable=yes,width=" + 550 + ",height=" + 680 + ",top=" + this_top + ",left=" + this_left);
	xx.focus();

	return false;
}



// ..................................................................

function confirma(msg, callback) {

	$("#confirm").jqmShow()
	.find("div.jqmConfirmMsg").html(msg)
	.end()
	.find("div.modalButtons").html("").html("<div class='yes'>Да</div><div class='no'>Отмена</div>")
	.end()
	.find("div.yes")
		.removeAttr("click")
		.click(function() {
			window.location.href = callback;
			$("#confirm").jqmHide();
		})
	.end()
	.find("div.no")
		.removeAttr("click")
		.click(function() {
			$("#confirm").jqmHide();
		});

	return false;
} 

function order_del(user_id, turnir_id)
{
	var content = $("#" + turnir_id + "_" + user_id).html();
	$("#" + turnir_id + "_" + user_id).html(wait2);

	$.ajax({
		type: "POST",
		url: "/jx/order.php",
		data: "act=del&user_id=" + user_id +"&turnir_id=" + turnir_id,
		success: function(msg)
		{
			if(msg == "ok")
			{
				$("#" + turnir_id + "_" + user_id).hide().html("<img src='/img/apply.gif' alt='' align='absmiddle' style='margin:-2px 5px 0px 0px;' />");
				$("#" + turnir_id + "_" + user_id).fadeIn(200);
			}
			else if(msg == "limit")
			{
			    $("#" + turnir_id + "_" + user_id).hide();
				$("#" + turnir_id + "_" + user_id).find("span").html("Ошибка.");
				$("#" + turnir_id + "_" + user_id).fadeIn(200);
			}
			else
			{
				$("#" + turnir_id + "_" + user_id).html(content);
			}
		}
	});

	return false;
}