	function ge(nid) { return document.getElementById(nid); }

function newPopup(url) {
	popupWindow = window.open(
		url,'Преглед на фиш','height=250,width=650,left=200,top=200,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,status=no')
}

function bet(mid, bet) 
{
        $.ajax({
            type: "POST",
            data: 'mid='+mid+'&bet='+bet,
            url: '/modules/dobavi_match.php',
            cache: false,
            success: function(resp){
                var divArray = $("#tmp_matches").html();
                if(resp==2) {
                    $("#errors").html("Това събитие вече е добавено във фиша.");
                } else {
                    $("#tmp_matches").html(resp+divArray);
                    $("#k_"+mid+"_"+bet).css("background", "yellow");
                    $("#errors").html('');
                }
                update_koef();
                howmany();
            }
            }); 

}

	function delmatch(mid, match) {
        $.ajax({
            type: "POST",
            data: 'mid='+mid+'match'+match,
            url: '/modules/iztrii_match.php',
            cache: false,
            success: function(resp){
                $("#table_"+mid).hide();
                for(var i=1;i<8;++i) {
                    $("#k_"+match+"_"+i).css("background", "#F5F5F5");
                    update_koef();
                    howmany();
                }
            }
            });

	}
	function update_koef() {
        
        $.ajax({
            type: "POST",
            data: 'mid=1',
            url: '/modules/update.php',
            cache: false,
            success: function(resp){
                $('#koef123').html('Коеф.: <b>'+resp+'</b>');
            }
            });        

	}
	function howmany() {
        $.ajax({
            type: "POST",
            data: 'mid=1',
            url: '/modules/howmany.php',
            cache: false,
            success: function(resp){
                if(parseInt(resp)==1) {
                    $('#forbet').show();
                    $('#bet_msg').html('');
                } else {
                    $('#forbet').hide();
                    $('#bet_msg').html('Вашият фиш е празен.');
                }
            }
            }); 	
	}
	function fish() {
                var koef = $("#koef123").html();
                var zalog = $("#zalogvalue").val();
          $.ajax({
            type: "POST",
            data: 'zalog='+zalog+'&koef='+koef,
            url: '/modules/fish.php',
            cache: false,
            success: function(resp){
                if(parseInt(resp)==1) {
                    $("#errors").html('Нямате достатъчно кредити.');
                } else if(parseInt(resp)==2) {
                    $("#errors").html('Залога трябва да е по-голям от 0.');
                } else if(parseInt(resp)==3) {
                    $("#errors").html('Максималният залог за деня е 100.');
                } else if(parseInt(resp)==4) {
                    $("#errors").html('Максималният залог за деня е 1000.');
                }                
                 else {
                    howmany();
                    $("#tmp_matches").html('');
                    $("#errors").html('Фиша е добавен успешно.');
                }
            }
            }); 

			function showResponse(req){
				if(parseInt(req.responseText)==1) {
					ge("errors").innerHTML="Нямате достатъчно кредити..";
				} else if(parseInt(req.responseText)==2) {
					ge("errors").innerHTML="Залога трябва да е по-голям от 0.";
				} else if(parseInt(req.responseText)==3) {
					ge("errors").innerHTML="Максималният залог за деня е 100.";
				} else if(parseInt(req.responseText)==4) {
                    ge("errors").innerHTML="Максималният залог за деня е 1000.";
                }                
                 else {
					howmany();
					ge("tmp_matches").innerHTML = "";
					ge("errors").innerHTML="Фиша е добавен успешно.";
				}

			}

			}
			function selectnews(nid) {
				var news = nid;
						for(i=1;i<=4;++i) {
						ge("btn"+i).setAttribute("class", "current");
						ge("content"+i).style.display="none";
						}
						ge("btn"+news).setAttribute("class", "selected");
						ge("content"+news).style.display="inline";
				}
				
			function selectnews2(nid3) {
				var news3 = nid3;
						for(i=1;i<=2;++i) {
						ge("btns"+i).setAttribute("class", "current");
						ge("contents"+i).style.display="none";
						}
						ge("btns"+news3).setAttribute("class", "selected");
						ge("contents"+news3).style.display="inline";
				}
			function select_hard(nid4) {
				var news4 = nid4;
						for(i=1;i<=2;++i) {
						ge("h_btn"+i).setAttribute("class", "current");
						ge("hard_content"+i).style.display="none";
						}
						ge("h_btn"+news4).setAttribute("class", "selected");
						ge("hard_content"+news4).style.display="inline";
				}
