// JavaScript Document

function catalog_firm_detail(id) {
	var obj = document.getElementById(id);	
	var caption = document.getElementById(id+'_caption');	
	
	if(obj.style.display == 'none' || obj.style.display == '') {
		obj.style.display = 'block';
		obj.style.backgroundColor = '#F4F4F4';
		/*
		obj.style.position = 'relative';
		obj.style.top = '7px';
		obj.style.backgroundColor = '#F4F4F4';
		caption.style.backgroundColor = '#F4F4F4';
		caption.style.border = '1px solid #E4E4E4';
		caption.style.borderBottom = '1px solid #F4F4F4';
		caption.style.paddingBottom = '3px';
		caption.style.paddingTop = '3px';
		caption.style.paddingLeft = '10px';
		caption.style.position = 'absolute';
		caption.style.zIndex = '10';
		*/
		
	}
	else {
		obj.style.display = 'none';
		obj.style.backgroundColor = '';
		/*
		caption.style.backgroundColor = '';
		obj.style.backgroundColor = '';
		caption.style.border = '';
		caption.style.paddingBottom = '0px';
		caption.style.paddingTop = '0px';
		caption.style.paddingLeft = '0px';
		obj.style.position = 'relative';
		obj.style.top = '0px';	
		caption.style.position = 'relative';
		*/
	}
}

function ajaxCalendar(direct, timestamp, id) {
	if (!ajaxpack.getAjaxRequest("/calendar.php", "timestamp="+timestamp+"&direct="+direct, getCalendar, "text"))		
	{ 
		return false; 		
	} 
	return true; 
}

function getCalendar() {
	var ajax=ajaxpack.ajaxobj;

	if (ajax.readyState == 4) { 
		if (ajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
				var html = ajax.responseText.toString();
				document.getElementById('calendar_ajax').innerHTML = html;
		}
	}	
}

function ajaxFirstpageStats(key) {
	//setTimeout("ajaxpack.ajaxLocation('firstpage_click.php', 'key_click="+key+"')", 10);

	ajaxpack.ajaxLocation('firstpage_click.php', 'key_click='+key);
	
	for(var i=0; i<99999; i++) var a=i;
	
	return false;
}

function adv_clear_filter(count_sports, count_adv_cat) {
	for(var i=1; i<=count_sports; i++)
		document.getElementById('adv_sport_filter_chbox_'+i).checked=false;
	
	for(var j=1; j<=count_adv_cat; j++)
	document.getElementById('filter_adv_chbox_'+j).checked = false;
		
	document.getElementById('filter_sport_all').checked = true;
	document.getElementById('filter_adv_all').checked = true;
}

function baz_clear_filter(count_sports) {
	
	for(var i=1; i<=count_sports; i++)
		document.getElementById('baz_sport_filter_chbox_'+i).checked=false;
			
	document.getElementById('filter_sport_all').checked = true;

}

function checkdescriptioncharlimit(limit) {

	var limitHTML = document.getElementById('descriptioncharlimit');
	var description = document.getElementById('description');
	//alert( description.value );
	var charcount = description.value.length;
	var charcount = description.value.length;
	
	//if(charcount > limit ) description.value = description.value.substr(0,limit);
	//else 
	limitHTML.innerHTML = limit-charcount;
	
}

function checksecuritycode() {
	if(document.getElementById('seccode').value != document.getElementById('securitycode').value) {
		alert('Neplatný bezpečnostní kód.');
		return false;
	}
	
	return true;
}

function changefotoingalery(src, id) {
	document.getElementById(id).src = src;	
}

function fultextfind() {
	if(document.getElementById('fultextstr').value.length > 2) {
		ajaxFirstpageStats('fultext');document.getElementById('fultext_form').submit();
		return true;
	} 
	else { 
		alert('Vyhledávané slovo musí mít nejméně 3 znaky.'); 
		return false;
	}	
}

function fillforico(ico) {
	//alert("Proběhne vypňování podle ičo. Zvolte 'Ok' a vyčkejte 5-10 vteřin.");
	
	if(ico == "") {
			alert("Vyplňte nejprve ičo.");
			return false;
	}
	else if (!ajaxpack.getAjaxRequest("/fill_ico.php", "ico="+ico, fillIco, "text"))		
	{ 
		return false; 		
	} 
		
	alert("Proběhne vypňování podle ičo. Vyčkejte 5-10 vteřin.");
	return true; 
}

function fillIco() {
	var ajax=ajaxpack.ajaxobj;

	if (ajax.readyState == 4) { 
		if (ajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
			var name = document.getElementById('firm_name');
			var address = document.getElementById('address');
			//var lokalita = document.getElementById('');			
			
			var html = ajax.responseText.toString();
			var result = html.split(";");
			
			if(result[0] == 'true') {
				//alert(html);
				name.value = result[1];
				address.value = result[2]+', '+result[3]+', '+result[4];
			}
			else alert('Subjekt nenalezen. Pravděpodobně chybné ičo.');
		}
	}	
}
