﻿$(document).ready(function(){
	$("#pagerank").html('<img src="images/button_pagerank.jpg" class="pagerank" width="90" height="19" alt="Zjistit PageRank" />');
	$(".pagerank").hover(
		function(){
			$(this).attr({src:"images/button_pagerank_hover.jpg"});
		},
		function(){
			$(this).attr({src:"images/button_pagerank.jpg"});
		}
	);
	$("#reklama").html('<img src="images/button_reklama.jpg" class="reklama" width="67" height="19" alt="Reklama" />');
	$(".reklama").hover(
		function(){
			$(this).attr({src:"images/button_reklama_hover.jpg"});
		},
		function(){
			$(this).attr({src:"images/button_reklama.jpg"});
		}
	);
	$("#create_web_page").html('<img src="images/button_create_web_page.jpg" class="create_web_page" width="120" height="19" alt="Vytvořit web stránku" />');
	$(".create_web_page").hover(
		function(){
			$(this).attr({src:"images/button_create_web_page_hover.jpg"});
		},
		function(){
			$(this).attr({src:"images/button_create_web_page.jpg"});
		}
	);
	$("#text_links").html('<img src="images/button_text_links.jpg" class="text_links" width="97" height="19" alt="Textové odkazy" />');
	$(".text_links").hover(
		function(){
			$(this).attr({src:"images/button_text_links_hover.jpg"});
		},
		function(){
			$(this).attr({src:"images/button_text_links.jpg"});
		}
	);
	$("#rules").html('<img src="images/button_rules.jpg" class="rules" width="75" height="19" alt="Podmínky" />');
	$(".rules").hover(
		function(){
			$(this).attr({src:"images/button_rules_hover.jpg"});
		},
		function(){
			$(this).attr({src:"images/button_rules.jpg"});
		}
	);
	$("#services").html('<img src="images/button_services.jpg" class="services" width="66" height="22" alt="Služby" />');
	$(".services").hover(
		function(){
			$(this).attr({src:"images/button_services_hover.jpg"});
		},
		function(){
			$(this).attr({src:"images/button_services.jpg"});
		}
	);
	$("#my_account").html('<img src="images/button_my_account.jpg" class="my_account" width="91" height="22" alt="Moje konto" />');
	$(".my_account").hover(
		function(){
			$(this).attr({src:"images/button_my_account_hover.jpg"});
		},
		function(){
			$(this).attr({src:"images/button_my_account.jpg"});
		}
	);
	$("#toplist").html('<img src="images/button_toplist.jpg" class="toplist" width="75" height="22" alt="Žebříček" />');
	$(".toplist").hover(
		function(){
			$(this).attr({src:"images/button_toplist_hover.jpg"});
		},
		function(){
			$(this).attr({src:"images/button_toplist.jpg"});
		}
	);
	$("#add_web_page").html('<img src="images/button_add_web_page.jpg" class="add_web_page" width="133" height="22" alt="Přidat web stránku" />');
	$(".add_web_page").hover(
		function(){
			$(this).attr({src:"images/button_add_web_page_hover.jpg"});
		},
		function(){
			$(this).attr({src:"images/button_add_web_page.jpg"});
		}
	);
	$("#contact").html('<img src="images/button_contact.jpg" class="contact" width="75" height="22" alt="Kontakt" />');
	$(".contact").hover(
		function(){
			$(this).attr({src:"images/button_contact_hover.jpg"});
		},
		function(){
			$(this).attr({src:"images/button_contact.jpg"});
		}
	);
	$("#login").html('<img src="images/button_login.jpg" class="login" width="76" height="22" alt="Přihlásit" />');
	$(".login").hover(
		function(){
			$(this).attr({src:"images/button_login_hover.jpg"});
		},
		function(){
			$(this).attr({src:"images/button_login.jpg"});
		}
	);
	$("#register").html('<img src="images/button_register.jpg" class="register" width="86" height="22" alt="Registrace" />');
	$(".register").hover(
		function(){
			$(this).attr({src:"images/button_register_hover.jpg"});
		},
		function(){
			$(this).attr({src:"images/button_register.jpg"});
		}
	);
	$("#logout").html('<img src="images/button_logout.jpg" class="logout" width="76" height="22" alt="Odhlásit" />');
	$(".logout").hover(
		function(){
			$(this).attr({src:"images/button_logout_hover.jpg"});
		},
		function(){
			$(this).attr({src:"images/button_logout.jpg"});
		}
	);
	$("#my_stat").html('<img src="images/button_my_stat.jpg" class="my_stat" width="110" height="22" alt="Moje statistiky" />');
	$(".my_stat").hover(
		function(){
			$(this).attr({src:"images/button_my_stat_hover.jpg"});
		},
		function(){
			$(this).attr({src:"images/button_my_stat.jpg"});
		}
	);
	var s_value = 0;
	$("#most_searched").hide();
	$("#search_text").blur(function(){
		s_value = $(this).attr("value");
		search_bar(s_value,"b");
		$("#most_searched").fadeOut('normal');
	});
	$("#search_text").focus(function(){
		s_value = $(this).attr("value");
		search_bar(s_value,"f");
		$("#most_searched").fadeIn('normal');
	});
	// modify global settings
	$.extend($.fn.Tooltip.defaults, {
		track: true,
		delay: 0,
		showURL: false
	});
	$('a, input, img').Tooltip();
	$('.bad_link').html('Oznámit nefunkční odkaz');
	$('.bad_link').click(function(){
		$(this).fadeOut('normal',function(){
			$(this).html('<img src="images/ajax-loader2.gif" />');							  
		});
		$(this).fadeIn('normal');
		var pid = $(this).attr('id');
		$.post("bad_link.php",{ pid:""+pid } ,function(data)
		{
			if(data == 'ok'){
				$('#'+pid).fadeOut('normal',function(){
					$(this).html('Děkujeme');
					$(this).removeAttr('class');
					$(this).attr('class','link_ok');
				});
				$('#'+pid).fadeIn('normal');
			}
			if(data == 'bad'){
				$('#'+pid).fadeOut('normal',function(){
					$(this).html('Problém s komunikací. Zkuste znovu.');							  
				});
				$('#'+pid).fadeIn('normal');
			}
		});
	});
});
function search_bar(x,y){
	if(y == "b"){
		if(!x){
			$("#search_text").css({background:"url('images/input_search.jpg')"});
		}
	}else if(y == "f"){
		$("#search_text").css({background:"none"});
	}
}
function submit_search(){
	var s_text;
	s_text = $('#search_text').attr("value");
	if(s_text){
		$('#search_form').attr({action: s_text+'-hledat.htm'});
		return true;
	}else{
		return false;
	}
}
function win_open(url){
	window.open(url,"new","width=800,height=600,scrollbars=yes,resizable=yes");
}
function confirmation(url,str) {
	var answer = confirm("Opravdu chcete zmazat stránku "+str+"?")
	if (answer){
		window.location = url;
	}
}
function _info(param,mode){
	if(mode != 'close'){
		$("#ajax_loader").fadeIn('fast');
		$("#_info_content").hide();
		$("._info").fadeIn('normal');
		$("._info").load("_info.php?param="+param+"&mode="+mode);
		$().ajaxStop(function(r,s){
			$("#ajax_loader").fadeOut("fast");
			$("#_info_content").show();
		});
	}else{
		$("._info").fadeOut('normal');
	}
}
function change_text(v,name){
	if(v == 1){
		var text = 'Vaše stránka &lt;b&gt;'+name+'&lt;/b&gt;, kterou jste vložili do katalogu Best-top.sk byla zkontrolována a úspěšně zařazena do katalogů.&lt;br /&gt;S pozdravem Best-top.cz tím.';
	}else{
		var text = 'Vaše stránka &lt;b&gt;'+name+'&lt;/b&gt;, kterou jste vložili do katalogu Best-top.sk byla zkontrolována a nebyla zařazena do katalogů. Na Vaší úvodní stránce jsme nenašli umiestnenú naši ikonu/odkaz. Kontrola proběhne ještě v následujících pěti dnech. Pokud do této doby ikonu/odkaz nenajdeme, Vaši stránku ze systému vymažeme. &lt;br /&gt;S pozdravem Best-top.cz tím.';
		document.getElementById('valid').checked = false;
	}
	$("#form_page_text").html(text);
}
function form_die(){return false;}
function page_submit(pid,uid,mode){
	if(mode == 'mail'){
		$(".table_valid").fadeOut('fast');
		$("#ajax_loader").fadeIn('normal');
		if(document.form_page.valid[0].checked){
			var valid = 1;
		}else{
			var valid = 0;
		}
		var text = document.form_page.text.value;
		$.post("mail.php",{ pid:""+pid,uid:""+uid,text:""+text,valid:""+valid } ,function(data)
		{
			if(data == 'ok'){
				$("#ajax_loader").fadeOut('normal');
				$("#output").html("Úspech");
				//setTimeout( "refresh()", 1*1000 );
				if(valid == 1){
					$('#valid_img_'+pid).attr({src:'images/icons/accept.png'});
				}else{
				
				}
				setTimeout( "_info('','close')", 1*1000 );
			}
			if(data == 'zle'){
				$("#ajax_loader").fadeOut('normal');
				$("#output").html("Chyba!");
			}
		});
	}
	if(mode == 'stat_set'){
		$(".stat_set").fadeOut('fast');
		$("#ajax_loader").fadeIn('normal');
		var modes = ['hn', 'dn', 'br', 'os', 'rz', 'fh', 'do', 'pr', 'pro', 'fr', 'ob', 'zs', 'ok', 'valid'];
		var maxi = modes.length;
		var i=0;
		var modes_jointed = '';
    	for(i=0;i<maxi;i++) {
			if(document.getElementById(modes[i]).checked && modes[i] != 'ok' && modes[i] != 'valid'){
        		modes_jointed = modes_jointed+''+modes[i]+',';
			}
			if(modes[i] == 'ok'){
				if(document.getElementById("ok").checked){
					modes_jointed = modes_jointed+'^1';
				}else{
					modes_jointed = modes_jointed+'^0';
				}
			}
			if(modes[i] == 'valid'){
				if(document.getElementById("valid").checked){
					modes_jointed = modes_jointed+'v1';
				}else{
					modes_jointed = modes_jointed+'v0';
				}
			}
    	}
		$.post("stat_set.php",{ pid:""+pid,stat_set:""+modes_jointed } ,function(data)
		{
			if(data == 'ok'){
				$("#ajax_loader").fadeOut('normal');
				$("#output").html("Úspech");
				//setTimeout( "refresh()", 1*1000 );
				setTimeout( "_info('','close')", 1*1000 );
			}
			if(data == 'zle'){
				$("#ajax_loader").fadeOut('normal');
				$("#output").html("Chyba!");
			}
		});
	}
}
function refresh(){
	location.reload(true);
	//window.location.href = unescape(window.location.pathname);	
}
