/**
 * klihovna JavaScriptových fcí
 *
 * @author mirek@multimedia.cz
 */


/**
 * vypíná 'probublávání' uivatelské události na dceřiínné objekty
 */
function stop_spreading(e)
{
	if (!e) var e = window.event;
	e.cancelBubble = true;

	if (e.stopPropagation) e.stopPropagation();
}


/**
 * zoomovací okno s obrázkem
 */
function zoom(url, w, h, title, alt)
{
	l = screen.width/2-w/2;
	t = screen.height/2-h/2-50;
	if (l<0) l = 0;
	if (t<0) t = 0;
	o = window.open('','fotka','status=no,width='+w+',height='+h+',resizable=no,menubar=no,location=no,scrollbars=no,toolbar=no,left='+l+',top='+t+'');
	d = o.document;
	d.writeln('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">');
	d.writeln('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs">');
	d.writeln('<head><meta http-equiv="Content-Type" content="text/html; charset=windows-1250"/>');
	d.writeln('<title>'+title+'</title>');
	d.writeln('<style type="text/css" media="screen">');
	d.writeln('BODY{margin: 0px; padding: 0px;}');
	d.writeln('IMG{margin: 0px; padding: 0px; border: 0px solid black; display:block;}');
	d.writeln('</style>');
	d.write('<body >');
	d.write  ('<a href="javascript:close()">');
	d.write  ('<img src="'+url+'" width="'+w+'" height="'+h+'" border="0" hspace="0" vspace="0" alt="" title="'+alt+'">');
	d.write('</a>');
	d.write('</body>')
	d.writeln('</html>');
	d.close();
	d.title = title;
}



/**
 * testuje, jestli je číslo float a má max povolený
 * počet des míst(0 = libovolné)
 */
function isPosFloat(s, decimals)
{
  s += '';
  if (decimals)
	var reg = new RegExp('(^[0-9]*$)|(^[0-9]*[,.]{1}[0-9]{1,'+decimals+'}$)');
  else
	var reg = new RegExp('(^[0-9]*$)|(^[0-9]*[,.]{1}[0-9]{1,}$)');
  if (!reg.test(s))
    return false;
  return true;
}



/**
 * testuje číslo na integer
 */
function isInt(s)
{
  s += "";
  if (s.indexOf('0') == 0)
    return false;
  var reg = new RegExp("^[0-9]*$");
  if (!reg.test(s))
    return false;
  return true;
}



/**
 * testuje validní email
 */
function isEMail(s)
{
	s += "";
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)");
	var r2 = new RegExp("^[a-zA-Z0-9\\-\\.]+\\@[a-zA-Z0-9\\-\\.]+\\.[a-zA-Z]{2,4}$");
	if (r1.test(s) || !r2.test(s))
    	return false;
	return true;
}



/**
 * testuje platný telefon
 */
function isTel(s)
{
  var reg = new RegExp("^[+]{1}[0-9]{12}$|^[123456789]{1}[0-9]{8}$");
  if (!reg.test(s))
    return false;
  return true;
}



/**
 * platné řetězcové id
 */
function isCharId(s)
{
	s += "";
	//var r = new RegExp("^[a-zA-Z]{1}[a-zA-Z0-9_]{0,}$");
	var r = new RegExp("^[a-zA-Z0-9_]{0,}$");
	if (!r.test(s))
    	return false;
	return true;
}


/**
 * obdoba number_format z php
 */
function number_format(number, decimals, dec_point, thousands_sep)
{
	var dec, i, arr;
	number *= 1;
	num = number.toFixed(decimals);

	dec = num.substr(-decimals, decimals);
	num = num.substr(0, num.length-decimals-1);

	num = num+'';

	arr = new Array('');

	for (i = 0; i < num.length; i++)
	{
		arr[i] = num.charAt(i);
	}
	arr.reverse();
	for (i = 1; i < arr.length; i++)
	{
		if (i % 3 == 0)
			arr[i] += thousands_sep;
	}

  arr.reverse();
  num = arr.join('');

	return (num + dec_point + dec);

}


// mredkj.com
// created: 2001-07-11
// last updated: 2001-09-07
var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);

function addOption(theSel, theText, theValue)
{
var newOpt = new Option(theText, theValue);
var selLength = theSel.length;
theSel.options[selLength] = newOpt;
}

function deleteOption(theSel, theIndex)
{
var selLength = theSel.length;
if(selLength>0)
{
theSel.options[theIndex] = null;
}
}

function moveOptions(theSelFrom, theSelTo)
{

var selLength = theSelFrom.length;
var selectedText = new Array();
var selectedValues = new Array();
var selectedCount = 0;

var i;

// Find the selected Options in reverse order
// and delete them from the 'from' Select.
for(i=selLength-1; i>=0; i--)
{
if(theSelFrom.options[i].selected)
{
selectedText[selectedCount] = theSelFrom.options[i].text;
selectedValues[selectedCount] = theSelFrom.options[i].value;
deleteOption(theSelFrom, i);
selectedCount++;
}
}

// Add the selected text/values in reverse order.
// This will add the Options to the 'to' Select
// in the same order as they were in the 'from' Select.
for(i=selectedCount-1; i>=0; i--)
{
addOption(theSelTo, selectedText[i], selectedValues[i]);
}

if(NS4) history.go(0);
}


/**
 * odtranění diakritiky
 */

sdiak="áäčďéěíĺžňóôőöŕúůűüýřÁÄČĎÉĚÍĹźŇÓÔŐÖŔÚŮŰÜÝŘ";
bdiak="aacdeeillnoooorstuuuuyrzAACDEEILLNOOOORSTUUUUYRZ";

function bezdiak(txt)
{
	tx="";
	for(p=0;p<txt.length;p++)
	{ 
		if (sdiak.indexOf(txt.charAt(p))!=-1) 
		tx+=bdiak.charAt(sdiak.indexOf(txt.charAt(p)));
		else tx+=txt.charAt(p);
	}
	return tx;
}


/**
 * převádí normální string na str id
 */
function strId(val)
{
	s = '';
	val = val.toLowerCase();
	val = bezdiak(val);
	for (i=0;i < val.length;i++)
	{
		d = val.charCodeAt(i);
		if ((d > 96 && d < 123) || (d > 47 && d < 58)|| d == 45 || d == 95)
			c = val.charAt(i);
		else
			c = '_';
		s += c;
	}
	return s;
}

