// JavaScript Document
	var shortcutOn = 0;
	
	var keyCommand = "";
	var loudKeys = false; //zapina vypina indikator zkratek
	
	document.onkeypress = keyPress;

function sf(skore) {
	FB.ensureInit(function() {
          //FB.Connect.showFeedDialog(101164985397, {"scr":"18"});
          FB.Connect.showFeedDialog(101164985397, {"scr":skore}, null, null, FB.FeedStorySize.shortStory, FB.RequireConnect.promptConnect);
    });
	return false;      
};


var newwindow;
function poptastic(url) {
	newwindow=window.open(url,'name','height=300,width=300 scrollbars=no');
	if (window.focus) {newwindow.focus()}
}

function facebook_onlogin() {
	window.location='http://www.protenis.cz/connect/connect.php';
}


function togg(id) {
		$("#"+id).toggle();
		return false;
}

function toggleComments() {
		$("#past-comments").toggle();
		if($("#past-comments").data('switched')) {
			//var c = $("#comments-toggler").html();
			$("#past-comments").data('switched',false);
			$("#comments-toggler").html($("#comments-toggler").data('content'));
		} else {
			var c = $("#comments-toggler").html();
			$("#past-comments").data('switched',true);
			$("#comments-toggler").data('content',c);
			$("#comments-toggler").html('Zobraz pouze dnešní komentáře');		
		}
		return false;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function send_email_info(eid) {
	$("#b-send").attr("disabled", "true"); 
	var to = $("#eto").val();
	var from = $("#efrom").val();
	var text = $("#etext").val();
	$.get("http://www.protenis.cz/friends/ajax.mail.send.php", {eid: eid, efrom: from, eto: to, etext: text}, function(data){
  		$("#e-report").addClass('yel-2');
		if(data == 1) {
			$("#e-report").html('Zkontroluj prosím email adresáta');
		} else if(data == 2) {
			$("#e-report").html('Zkontroluj prosím svůj email');
		} else if(data == 3) {
			$("#e-report").html('Email by neměl být prázdný, ne?');	
		} else if(data == 4) {
			$("#e-report").html('Email se nepodařilo odeslat.');		
		} else {
			$("#e-report").html('Email byl úspěšně odeslán na adresu <b>'+ to +'<\/b>');
			$("#eto").val('');
		}	
		$("#b-send").removeAttr("disabled");

		

	});
	return false;
}

function likeThis(id,t) {
	$("#c-"+id).fadeOut('slow');
	$.get("http://www.protenis.cz/friends/ajax.news.like.php", {nid: id, type: t}, function(data){
  		$("#d-"+id).slideUp('slow', function(){
			$("#d-"+id).html(data).slideDown('slow');
		});
	});
	return false;
}

function likeHer(id,ranks) {
	$.get("http://www.protenis.cz/friends/ajax.tag.like.php", {tid: id}, function(data){
		$(".vote").fadeOut('slow');
		jQuery.noticeAdd({
        	text: 'Váš hlas byl zapsán. Děkujeme.',
        	stayTime: 6000,  
            stay: false
        });
	});
	if(ranks) {
		$.get("http://www.protenis.cz/friends/ajax.sps.ranks.php", {}, function(data){
			$("#superstar-ranks").html(data);
		});
	}
	return false;
}


function seedOver(id) {
	$("#r-"+id).addClass('ova');
	$("#det-"+id).addClass('bl');
	$("#add-"+id).show();
	$("#d-"+id).show();
}

function seedLeft(id) {
	$("#r-"+id).removeClass('ova');
	$("#det-"+id).removeClass('bl');
	$("#add-"+id).hide();
	$("#d-"+id).hide();
}

function switchAlbumMode(album_id) {
	$.get("http://www.protenis.cz/fotobook/ajax.album.mode.php", {aid: album_id}, function(data){
  		$("#am-"+album_id).html(data);
	});
	return false;
}

function challenge_live() {
	var uid = 0;
	$.get("http://www.protenis.cz/challenge/x.live.php", null, function(data){
  		$("#ch-live").html(data);
  		//$(".finished").fadeOut("slow").fadeIn("slow");
	});
	return false;
}

function rsp(cut,uid) {
	
	$.get("http://www.protenis.cz/friends/ajax.rsp.php", { uid: uid, cut: cut }, function(data){
  		$("#rsp").html(data);
	});
	return false;
}

function rspr(cut,rspid) {
	
	$.get("http://www.protenis.cz/friends/ajax.rspr.php", { rspid: rspid, cut: cut }, function(data){
  		$("#rsp-"+rspid).html(data);
	});
	return false;
}

function rsprev(cut,uid,rspid) {
	
	$.get("http://www.protenis.cz/friends/ajax.rsp.php", { uid: uid, cut: cut }, function(data){
  		$("#rsp-"+rspid).html(data);
	});
	return false;
}

function rsp_show(rspid) {
	$("#rsp-reply").show();
}

function no_friend(fid) {
	$("tr#ymn-"+fid).remove();
	
		$.get("http://www.protenis.cz/friends/ajax.no.friend.php", { nfid: fid }, function(data){
	  	
	});
	return false;
}


function save_status() {
	var status = $("#a-status").val();
	if(status == "") {
	  	$("#user-status-form").hide();
		return false;
	}
	$("#user-status").html('Ukládám...');
	$.get("http://www.protenis.cz/friends/save-status.php", { user_status: status }, function(data){
	  	$("#user-status-form").hide();
		$("#user-status").html(data);
	});
	return false;
}

function save_status_no_hide() {
	var status = $("#a-status").val();
	if(status == "") {
		return false;
	}
	$("#user-status").html('Ukládám...');
	$.get("http://www.protenis.cz/friends/save-status.php", { user_status: status, mode: 1 }, function(data){
		$("#user-status").html(data);
		$("#a-status").addClass("status-gray");
		$("#a-status").val('Co děláte právě teď?');
	});
	return false;
}


function status_prepare() {
		switchKp(0);
		$("#a-status").removeClass("status-gray");
		$("#a-status").val('');
}

function status_form() {
	$("#user-status-form").toggle();
	$("#a-status").focus();

}
function topInfo()
{
  	$.get("a.topinfo.php", { imode: 1 }, function(data){
		   $("#top-info").html(data);
	});
}

function topInfoNew()
{
  	$.get("http://www.protenis.cz/sazky/a.topinfo2.php", { imode: 1 }, function(data){
		   $("#sts").html(data);
	});
}


function newUpdates() {
	var last = $("#last-update").val();
	$.get("http://www.protenis.cz/friends/ajax.new_updates.php", { last: last }, function(data){
		   if(data != 'x') {
		   		$("#updates-notifier").show();
		   		
			   $("#updates-notifier").html(data);
		   }
	});
}


function showOdds(id,d) {
	 $("#bi"+d+"_"+id).toggle();
}




function show(id) {
			var cur,master;
			cur = $("#cur").val();
			master = $("#master").val();
			//alert(cur);
			$("#sub-"+id).show();
			$("#top-"+id).addClass("active");
			$("#top-"+id).addClass("active");
			$("#l-"+id).addClass("l");
			$("#r-"+id).addClass("r");
			if(id != cur) {
				$("#sub-"+cur).hide();
				if(cur != master) {
					$("#top-"+cur).removeClass("active");
					$("#l-"+cur).removeClass("l");
					$("#r-"+cur).removeClass("r");
				}
			}
			$("#cur").val(id);
		}
		
		function reset() {
			var cur = $("#cur").val();
			var	master = $("#master").val();

			if(master != cur) {
				$("#sub-"+cur).hide();
				$("#top-"+cur).removeClass("active");
				$("#l-"+cur).removeClass("l");
				$("#r-"+cur).removeClass("r");
				$("#sub-"+master).show();
				$("#l-"+master).addClass("l");
				$("#r-"+master).addClass("r");
				$("#cur").val(master);
			}	
		}
		
	

//set hover class for anything
$(document).ready(function() {
	
  
  
  $('#t-footer td').hover(function() {
    $(this).addClass('footer-hover');
  }, function() {
    $(this).removeClass('footer-hover');
  });
  var cur,master;
	master = $("#master").val();
	cur = $("#cur").val(master);
			
});

//livekontrola zadavaneho nicku
function nickCheck()
{
	var newnick = $('new_nick').value;
	var re = new RegExp("^[_a-zA-Z0-9\.\-]*$");
	
	if (!newnick.match(re)) {
		$('nick_info').innerHTML = "<span style=\"color: red;\">Nick obsahuje nepovolené znaky</span>";
		$('odeslat').disabled = true;
		return;
	}
	
	if (newnick.length > 3 && newnick.match(re)) {

		var url = 'ax.nick-check.php';
		var pars = 'newnick='+newnick;

		//kontrola nicku proti databazi
		new Ajax.Request(url,
	  {
	    method:'get', parameters: {newnick: newnick},
	    onSuccess: function(transport){
	      var response = transport.responseText || "no response text";
	      if (response == '1') {
			$('odeslat').disabled = false;
			  $('nick_info').innerHTML = "<span style=\"color: green;\">Nick je volný</span>";
		  } else {
		  	$('odeslat').disabled = true;
			  $('nick_info').innerHTML = "<span style=\"color: red;\">Přezdívka je obsazena</span>";
		  }
	    },
	    onFailure: function(){ alert('Something went wrong...') }
	  });
	
	} else {
		$('nick_info').innerHTML = "<span style=\"color: red;\">Přezdívka je příliš krátká</span>";
		$('odeslat').disabled = true;
	}

}

function butt_ch(post_id,uname)
    {
     var hodnota=document.getElementById("r_id").value;
     if (hodnota != post_id) {
	    document.getElementById("d_post").value = 'Reagovat na '+uname;
	    document.getElementById("r_id").value = post_id;
	    document.getElementById("ta").focus();
	    
     } else {
	     document.getElementById("d_post").value = 'Vložit příspěvek';
	    document.getElementById("r_id").value = 0;
	    document.getElementById("ta").focus();
	    
     }
     
    }

function keyPress(ev)
{
ev || (ev = window.event);
var code = (ev.keyCode ? ev.keyCode: (ev.charCode ? ev.charCode: ev.which));
if (shortcutOn) {
	if (code == 27) { keyCommand = "";}
	keyCommand = keyCommand + String.fromCharCode(code);
	if (keyCommand == "g") {
		if (loudKeys) {
			$("message").innerHTML = "Go to ";
			$("message").style.visibility = 'visible';
		}
	}
	//alert ("this key code is: "+code);
	if (keyCommand.length > 1) {
		//alert ("this is: " + keyCommand);
		shortcutGo(keyCommand);
		keyCommand = "";
		}
	}

}

function switchKp (v) {
	shortcutOn = false;
}

function send (loc) {
	//promennou nastavit podle localhostu nebo live serveru
	var path ="http://www.protenis.cz/";
	window.location = path + loc;
}

function shortcutGo(loc) {
	var m = "";
	if (loudKeys) { m = $("message").innerHTML;}
	if (loc == 'gg') {
		if (loudKeys) {$("message").innerHTML = m + "<b>Sázkovka</b>";}
		send("sazky/index.php");
	}
	if (loc == 'gh') {
		if (loudKeys) {$("message").innerHTML = m + "<b>Duely</b>";}
		send("sazky/duel.php");
	}
	if (loc == 'gf') {
		if (loudKeys) {$("message").innerHTML = m + "<b>Friends</b>";}
		send("friends/index.php");
	}
	if (loc == 'gn' || loc == 'gk') {
		if (loudKeys) {$("message").innerHTML = m + "<b>Nabíka</b>";}
		send("sazky/kancelar.php");
	}
	if (loc == 'gb') {
		if (loudKeys) {$("message").innerHTML = m + "<b>Breakpoints</b>";}
		send("sazky/breakpoint.php");
	}
	if (loc == 'gz') {
		if (loudKeys) {$("message").innerHTML = m + "<b>Žebříčky</b>";}
		send("sazky/best.php");
	}
	if (loc == 'gd') {
		if (loudKeys) {$("message").innerHTML = m + "<b>Diskuse</b>";}
		send("diskuse.php");
	}
	if (loc == 'gs') {
		if (loudKeys) {$("message").innerHTML = m + "<b>Search</b>";}
		send("search/index.php");
	}
	if (loc == 'gk') {
		if (loudKeys) {$("message").innerHTML = m + "<b>Komentare</b>";}
		send("diskuse.php");
	}
	if (loc == 'gv') {
		if (loudKeys) {$("message").innerHTML = m + "<b>Vysledky</b>";}
		send("sazky/vysledky.php");
	}
	if (loc == 'gp') {
		if (loudKeys) {$("message").innerHTML = m + "<b>Přehled</b>";}
		send("sazky/index.php");
	}
	if (loc == 'gi') {
		if (loudKeys) {$("message").innerHTML = m + "<b>Inbox</b>";}
		send("inbox/index.php");
	}
	if (loc == 'gx') {
		if (loudKeys) {$("message").innerHTML = m + "<b>Tournament</b>";}
		send("sazky/tournament.php");
	}
	//admin shortcuts
	if (loc == 'aa') {
		send("sazky/admin/admin.php");
	}
	if (loc == 'ap') {
		send("sazky/admin/pv2.php");
	}
	if (loc == 'ah') {
		send("sazky/admin/houston.php");
	}
	if (loc == 'ae') {
		send("sazky/admin/a.players.php?a=a");
	}
	if (loc == 'an') {
		send("sazky/admin/a.news.php");
	}
	if (loc == 'ac') {
		send("sazky/admin/a.comments.php");
	}
	if (loc == 'ks') {
		$("#live-info").toggle();
	}
}

function notiDelete(id,type,ord) {
	$("#dico-" + ord).html('<img src=\"http://www.protenis.cz/img/ex/load.gif\" alt=\"working\" class=\"vam\">');
	$.get('http://www.protenis.cz/sazky/ajax.delete.noti.php', { id: id, type: type }, function(data){
			$("#noti-" + ord).remove();
			var fill = '<a class=\"big-not-link\" href=\"http://www.protenis.cz/notifikace\">'+ data +'</a>';
			$("#noty").html(fill);
	});
}

function tenisRelation(i) {
	if(i == 0 || i > 5) {
		$("#racquet,#hand,#backhand").hide();
	} else {
		$("#racquet,#hand,#backhand").show();
	}

}


function pollAjaxAction(id,r)
   {
     var divik = document.getElementById("sik_"+id);
     //alert(id+" "+r);
     //document.getElementById("sik_"+id).style.display="block";
     
     
     if (id > 0)
     {
        var link;
        link = "http://www.protenis.cz/includes/ajax.poll_vote.php?pollid="+id+"&r="+r;
	
	//alert(link);
        if (window.ActiveXObject)
        {
          httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else
        {
          httpRequest = new XMLHttpRequest();
        }
        httpRequest.open("get", link, true);
        httpRequest.onreadystatechange= function () {pollProcessRequest("anketa"); } ;
        httpRequest.send(null);
      }
      else
      {
        // just delete the content when no article selected
        //document.getElementById(session-tags).innerHTML = "";
        
      }
      
   }
   
   function pollProcessRequest(targetDiv)
   {
	var loading = document.getElementById("wip");
	   
      if (httpRequest.readyState == 4)
      {
        if(httpRequest.status == 200)
        {
          var contentViewer = document.getElementById(targetDiv);
          contentViewer.innerHTML = httpRequest.responseText;
	  loading.innerHTML = "";
	  
        }
        else
        {
            //alert("Error loading page\n"+ httpRequest.status +":"+ httpRequest.statusText);
        }
      } else {
        //loading.innerHTML = "<img src='img/wait.gif'>";
        loading.innerHTML = "Ukládám váš hlas&nbsp;<img src='images/wait.gif'>";
        }      
      
   }


