function gid(name) {
	return document.getElementById(name);
}

function dirtypop(src,w,h) {
	w=w?w:750;
	h=h?h:550;
	var o=window.open(src, 'img','left='+((screen.width-w)/2)+',top='+((screen.height-h)/2)+',toolbar=0,location=0,scrollbars=0,resizable=yes,width='+w+', height='+h);
	var win=o.document;
	win.write('<!DOCTYPE html PUBLIC \'-//W3C//DTD XHTML 1.0 Strict//EN\' \'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\'>');
	win.write('<html><head>');
	win.write('<style type="text/css">html,body{margin:0;padding:0}</style>');
	win.write('</head><body onclick="self.close();">');
	win.write('<img src="' + src + '" alt="" />');
	win.write('</body></html>');
	win.close();
	if (window.focus) o.focus();
	return false;
}

function openWindow(src,w,h) {
	w=w?w:750;
	h=h?h:550;
	var win = window.open(src, 'img','toolbar=0,location=0,scrollbars=yes,resizable=yes,left='+((screen.width-w)/2)+',top=0,width=' + (w + 50) + ', height=' + (h + 150));
	if (window.focus) win.focus();
	return false;
}

function photogallery(src,w,h) {
	w=w?w:840;
	h=h?h:790;
	var win = window.open(src, "img",'left='+((screen.width-w)/2)+',top=0,toolbar=0,scrollbars=yes,resizable=yes,width='+w+',height='+h);
	if (window.focus) win.focus();
	return false;
}

function zmen_platbu( pole ) {
	var platba_text;
	var platba_descr;
	var platba_radio;

	if( pole ){
		for( var i=0; i < document.obj_form.platba.length; i++ ){
			platba_text = gid('name_'+document.obj_form.platba[i].id);
			platba_descr = gid('descr_'+document.obj_form.platba[i].id);
			platba_radio = document.obj_form.platba[i];

			if( platba_radio ) platba_radio.disabled = true;
			if( platba_text ) platba_text.className = 'inactive';
			if( platba_descr ) platba_descr.className = 'inactive';
		}

		for( i=0; i<pole.length; i++ ){
			platba_text = gid('name_platba'+pole[i]);
			platba_descr = gid('descr_platba'+pole[i]);
			platba_radio = gid('platba'+pole[i]);

			if( platba_radio ) platba_radio.disabled = false;
			if( platba_text ) platba_text.className = 'active';
			if( platba_descr ) platba_descr.className = 'active';
		}
	}
}


function check(idForm,language) {

	var inputs = gid(idForm).getElementsByTagName('input');
	var data_ok = true;

	if( inputs ) {
		for( i = 0; i < inputs.length; i++ ) {
			if ( /f-req/.test( inputs[i].className )) {
				if( inputs[i].value == '' ) {
					if( gid( inputs[i].id )) {
						gid( inputs[i].id ).className = 'f-req f-empty';
					}
					if ( data_ok ) {
						gid( inputs[i].id ).focus();
					}
					data_ok = false;
				}
				else {
					if( gid( inputs[i].id )) {
						gid( inputs[i].id ).className = 'f-req';
					}
				}
			}
		}
	}

	if( !data_ok ) {
		if( language == 'en' ) {
			alert( 'Please fill in all required fields' );
		}
		else if (language == 'sk') {
			alert( 'Vyplňte prosím všetky povinné políčka' );
		}
		else {
			alert( 'Vyplňte prosím všechna povinná pole' );
		}
	}

	return data_ok;
}


function mailto_fc( box, domain ) {
 var proto=String.fromCharCode( 109,97,105,108,116,111,58 )
 w=window.open(proto+box+String.fromCharCode(64)+domain);
 if (w!=null) w.close(); //FF
}

function mailto( name, domain, attributes ) {
 if( typeof(attributes)=='undefined' ) attributes = '';
 document.write("<a href=\"javascript:mailto_fc('"+name+"', '"+domain+"')\""+(attributes.length > 0 ? ' ' : '')+attributes+'>'+name+String.fromCharCode(64)+domain+'</a>');
}

/* Image preview */
function imagePreview(missingImageName, thumbFolder, detailFolder)
{
	var xOffset = 10;
	var yOffset = 30;

	$("a.preview").hover(
		function(e){
			this.t = this.title;
			this.title = "";
			var c = (this.t != "") ? "<br/>" + this.t : "";
			var imgsrc = new String($("img", this)[0].src);
			if (imgsrc.indexOf(missingImageName) != -1)
				return;

			$("body").append('<p id="preview"><img src="'+ imgsrc.replace("/" + thumbFolder + "/", "/" + detailFolder + "/") +'" alt="Image preview" />'+ c +'</p>');

			$("#preview")
				.css("top",(e.pageY + xOffset) + "px")
				.css("left",(e.pageX + yOffset) + "px")
				.css("position", "absolute")
				.fadeIn("fast");
			}
		,
		function(){
			this.title = this.t;
			$("#preview").remove();
		}
	);

	$("a.preview").mousemove(function(e){
		if ($("#preview").css("bottom") < $(document).clientHeight) {
			$(document.write('test'));
		}

		var container = $("#preview");
		var nwh = $(window).height() + $(window).scrollTop();
		var top = container.offset().top;
		if (top + container.outerHeight() > nwh || top < 0){
			var t =(container.offset().top + container.outerHeight()) > nwh ? nwh - container.outerHeight() - 20 : container.offset().top < 0 ? 20 : container.offset().top;
			container.animate({top:t},550,function(){});
		} else {
			/*
			if (top + container.outerHeight() < nwh) {
				container
					.css("top", e.pageY - xOffset + "px")
					.css("left",(e.pageX + yOffset) + "px");
			}
			*/
		}
	});
}

