var timerID = false;

function setFocus(what) {
	var f = document.getElementById(what);
	f.focus();
}

//odstrani vsechny mezery v textu
String.prototype.remsp = function() {
    return this.replace(/\s/g, "");
}

function showHideTime(what,how) {
	o = document.getElementById(what);
	if (how == 1) {
		timerID = setTimeout("showit('"+what+"')",400);
	}
	else if (how == 2) {
		clearTimeout(timerID);
		hideit(what);
	}	
}

function windowOpenProgHelp(poj,par) {
	var file = './_help-programy.php?pojistovna='+poj+'&help='+par;
	var wleft = (screen.width-500)/2;
	var wtop = (screen.height-250)/2;
	window.open(file, "_blank", "width=500,height=250,left="+wleft+",top="+wtop+",scrollbars=yes");
}

function windowHelpOpen(arg1,arg2) {
	doc = "_help.php?skupina=" + arg1 + "&help=" + arg2;
	var wleft = (screen.width-500)/2;
	var wtop = (screen.height-450)/2;
	window.open(doc, "_blank", "width=500,height=450,left="+wleft+",top="+wtop+",scrollbars=yes");
}

function windowCalcOpen(arg1,arg2) {
	var doc = "_postup_vypoctu.php?pojistovna=" + arg1 + "&program=" + arg2;
	var wleft = (screen.width-500)/2;
	var wtop = (screen.height-450)/2;
	window.open(doc, "_blank", "width=500,height=450,left="+wleft+",top="+wtop+",scrollbars=yes");
}

//globalni promenne pro ulozeni predchozi otevrene informace
 var lastblockid = '';
 var lastidimg = '';
 var lastimgname = '';
 var lastimgext = '';

//otvirani - zavirani dodatecnych informaci vcetne zmen ikon
function showhideitimg(what,idimg,imgname,imgext) {
	var o = document.getElementById(what);
	var oa = document.getElementById(idimg);

	//zavre predchozi informaci
	if (lastidimg > '' && lastidimg != idimg) {
		var lo = document.getElementById(lastblockid);
		var loa = document.getElementById(lastidimg);

		lo.style.display = 'none';
		loa.src = './img/'+lastimgname+'off.'+lastimgext;
	}

	lastblockid = what;
	lastidimg = idimg;
	lastimgname = imgname;
	lastimgext = imgext;

	if (o.style.display == 'none') {
		o.style.display = '';
		oa.src = './img/'+imgname+'on.'+imgext;
		return;
	}
	if (o.style.display == '') {
		o.style.display = 'none';
		oa.src = './img/'+imgname+'off.'+imgext
		return;
	}
}

function showit(what) {
	var o = document.getElementById(what);
	o.style.display = '';
}

function hideit(what) {
	var o = document.getElementById(what);
	o.style.display = 'none';
}

function visOn(what) {
	var o = document.getElementById(what);
	o.style.visibility = 'visible';
}

function visOf(what) {
	var o = document.getElementById(what);
	o.style.visibility = 'hidden';
}

function onRadio(id) {
	var o = document.getElementById(id);
	o.checked = true;
}

function changeText(id,text) {
	var o = document.getElementById(id);
	o.innerHTML = text;
}

function showitinline(what) {
	var o = document.getElementById(what);
	o.style.display = 'inline';
}


function dateJump(e,idjump) {
	if (navigator.appName.toLowerCase() != 'opera') {
		if (e == 190 || e == 188 || e == 191 || e == 109 || e == 219) {
			document.getElementById(idjump).focus();
			return false;
		}
	}
	return true;			
}

//vyplnenou cenu vozidla v EUR zobrazi jako informativni sk
function eurosk(iname,hname,ivalue,blur) {
    var o = document.getElementById(iname);
    var h = document.getElementById(hname);
    ivalue = ivalue.remsp();
    if (ivalue > '') {
        //musi se jednat o ciste cele cislo
        var rtext=/^\d{1,}$/;
        if (rtext.test(ivalue)) {
          h.innerHTML = Math.round(ivalue*30.126);
        } else {
          if (blur == true) {
            h.innerHTML = "0";
          }
        }
    } else {
       h.innerHTML = "0";
    }
}

function radio_changed(typ) {
	//alert(typ);
	
	if (typ=='kup-ojazdene') {
		//alert("zobrazuj");
		showit('container-evidencia');
	} else {
		//alert("schovaj");
		hideit('container-evidencia');
	}

}

