/*
Externe musi byt nadefinovano:

BASE_LOC_PATH
*/

function getObj(id) {
	if (document.getElementById) {
		return document.getElementById(id);
	}
	return null;
}

function setCookie(name, value, hours, path)
{
	var expires = null;
	
	if (hours) {
		d = new Date();
		d.setTime(d.getTime() + (hours*60*60*1000));
		expires = d.toGMTString();
	}
	document.cookie = name+"="+escape(value)+
		(expires ? "; expires="+expires : "")+
		"; path="+path;
}

function getCookie(name)
{
	var namefind = name+"=";
	var cookies = document.cookie.split(";");
	
	for(var i=0; i<cookies.length; i++) {
		var c = cookies[i];
		
		while (c.charAt(0) == " ") {
			c = c.substring(1, c.length);
		}
		if (c.indexOf(namefind) == 0) {
			return unescape(c.substring(namefind.length, c.length));
		}
	}
	return null;
}

function delCookie(name, path)
{
	if (getCookie(name)) {
		var d = new Date();
		d.setTime(d.getTime() - (2*24*60*60*1000));
		document.cookie = name+"=; expires="+d.toGMTString()+"; path="+path;
	}
}

// Najde prvni input s moznosti focus a nastavi
function setFormFocus() {
	if (!document.forms || !document.forms.length) return;

	var obj = $(':input', document.forms);
	
	$.each( obj, function(i, n) 
	{
		// Projdi kazdy input=text nebo textareu
		if ($(n).is('input:text:visible:enabled') || $(n).is('textarea:visible:enabled')) 
		{
			// pokud jeho predci nejsou skryti(tudiz neskryvaji i samotny prvek)
			if ($(n).parents(':hidden').size() == 0 && !n.readOnly) 
			{
				try {
					n.focus();
					return false;
				} catch (ex) {}
			}
		}
	});	
}

/** IE neodesila formular pri jednom inputu po stisknuti Enter. */
function fixIEForms() {
	if (!$.browser.msie || !document.forms || !document.forms.length) return;
	
	$('form').each(function() {
		if ($(this).find('input:text').size() == 1) {
			$(this).append('<input type="text" name="IEFixSubmitText" value="" style="display:none;" />');
		}
   	});
}
