//------------------------------------------------------------------------------------------------------------------------------------
function move_in(img_name,img_src){
	document[img_name].src=img_src;
}
//------------------------------------------------------------------------------------------------------------------------------------
function move_out(img_name,img_src){
	document[img_name].src=img_src;
}
//------------------------------------------------------------------------------------------------------------------------------------
// Funkce provadi kontrolu, zda se hodnota sklada z pozadovanych znaku **/
function checkValue(aValue, strValidChars){
   var strChar;
   var blnResult = true;

   for (i = 0; i < aValue.length && blnResult == true; i++)
      {
      strChar = aValue.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
}
//------------------------------------------------------------------------------------------------------------------------------------
// Funkce vraci, zda se jedna o INTEGER
function isInteger(aValue){
    return checkValue(aValue, "0123456789-");
}
//------------------------------------------------------------------------------------------------------------------------------------
// Funkce vraci, zda se jedna o FLOAT
function isFloat(aValue){
    return checkValue(aValue, "0123456789-.,");
}
//------------------------------------------------------------------------------------------------------------------------------------
// Funkce vraci, zda se jedna o casovy udaj hh:mm:ss
function isTime(aValue){
 var values;
 var hour;
 var min;
 var result = false;

 values = aValue.split(":");
 if (values.length = 2){
  hour = values[0];
  min = values[1];
  if (hour >= 0 && hour <= 24){ 
   if (min >= 0 && min <= 59) result = true;
  }
 }
 return result;
}
//------------------------------------------------------------------------------------------------------------------------------------
// Funkce vraci, zda se jedna o datumovou hodnotu dd.mm.rrrr
function isDate(aValue){
 var values;
 var day;
 var month;
 var year;
 var result = false;

 if (aValue.length <= 10){
	 values = aValue.split(".");
	 if (values.length = 3){
	  day = values[0];
	  month = values[1];
	  year = values[2];
	  if (month >= 1 && month <= 12){ 
	   if (day >= 1 && day <= 31) {
	    if (! ((month==4 || month==6 || month==9 || month==11) && day==31)) result = true;
	   }
	  }
	  if (result && month == 2){
	   var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
	   if (day>29 || (day==29 && !isleap)) result = false;
	  }
	 }
 }
 return result;
}
//------------------------------------------------------------------------------------------------------------------------------------
// Funkce vraci, zda se jedna o datum-cas dd.mm.rrr hh:mm:ss
function isDateTime(aValue){
 var values = aValue.split(" ");
 return (values.length == 2 && isDate(values[0]) && isTime(values[1]));
}
//------------------------------------------------------------------------------------------------------------------------------------
// Funkce vraci, zda se jedna o emailovou adresu
function isEmail(aValue){
 return (aValue.indexOf("@") != -1);
}
//------------------------------------------------------------------------------------------------------------------------------------
// Funkce provadi kontrolu fieldu STRING
function checkString(aMin, aMax, aField){
 var result = false;
 var value = aField.value;

 if (value=="" || value==" ") alert("Není zadána hodnota !!!");
 else if (value.length < aMin || value.length > aMax) alert("Hodnota musí být v rozmezí " + aMin + " - " + aMax + " znaků !!!");
  else result = true;
 
 if (! result) aField.focus();

 return result;
}
//------------------------------------------------------------------------------------------------------------------------------------
// Funkce provadi kontrolu fieldu INTEGER
function checkInteger(aMin, aMax, aField){
 var result = false;
 var value = aField.value;

 if (! isInteger(value)) alert("Hodnota není číselná !!!");
 else if (value < aMin || value > aMax) alert("Hodnota musí být v rozmezí " + aMin + " - " + aMax + " !!!");
  else result = true;
 
 if (! result) aField.focus();

 return result;
}
//------------------------------------------------------------------------------------------------------------------------------------
// Funkce provadi kontrolu fieldu FLOAT
function checkFloat(aMin, aMax, aField){
 var result = false;
 var value = aField.value;

 if (! isFloat(value)) alert("Hodnota není číselná !!!");
 else if (value < aMin || value > aMax) alert("Hodnota musí být v rozmezí " + aMin + " - " + aMax + " !!!");
  else result = true;
 
 if (! result) aField.focus();

 return result;
}
//------------------------------------------------------------------------------------------------------------------------------------
// Funkce pro kontorlu fieldu DATETIME
function checkDateTime(aField){
 var result = false;
 var value = aField.value;

 if (! isDateTime(value)) alert("Hodnota není datumová nebo není ve formátu dd.mm.rrrr hh:mm !!!");
 else result = true;
 
 if (! result) aField.focus();

 return result;
}
//------------------------------------------------------------------------------------------------------------------------------------
// Funkce pro kontrolu fieldu DATE
function checkDate(aField){
 var result = false;
 var value = aField.value;

 if (! isDate(value)) alert("Hodnota není datumová nebo není ve formátu dd.mm.rrrr !!!");
 else result = true;
 
 if (! result) aField.focus();

 return result;
}
//------------------------------------------------------------------------------------------------------------------------------------
// Funkce pro kontrolu fieldu TIME
function checkTime(aField){
 var result = false;
 var value = aField.value;

 if (! isTime(value)) alert("Hodnota není časová nebo není ve formátu hh:mm !!!");
 else result = true;
 
 if (! result) aField.focus();

 return result;
}
//------------------------------------------------------------------------------------------------------------------------------------
// Funkce pro kontrolu emailu
function checkEmail(aField){
 var result = false;
 var value = aField.value;

 if (! isEmail(value)) alert("Hodnota není platná emailová adresa !!!");
 else result = true;
 
 if (! result) aField.focus();

 return result;
}
//------------------------------------------------------------------------------------------------------------------------------------
// Funkce prevede retezec dd.mm.yyyy na cislo int
function cDateToInt(aString){
	var values;
	var datum;
	values = aString.split(".");
	if (values[0].length<2) values[0]="0"+values[0];
	if (values[1].length<2) values[1]="0"+values[1];	
	return parseInt(values[2]+values[1]+values[0]);
}
//------------------------------------------------------------------------------------------------------------------------------------
// Funkce prevede retzec dd.mm.yyyy na datumovou promenou
function strToDate(aString){
	var values;
	var datum;
	values = aString.split(".");
	datum = new Date(parseInt(values[2]), parseInt(values[1]), parseInt(values[0]), 0, 0, 0);
	return datum;
//	return Date.UTC(values[2], values[1], values[0], "0", "0", "0");
}
//------------------------------------------------------------------------------------------------------------------------------------
// Funkce pro kontrolu rodneho cisla
function checkRodneCislo(aField){
 var result = false;
 var value = aField.value;

 if (! checkValue(value, "0123456789")) alert("Hodnota není platné rodné číslo !!!");
 else result = true;
 
 if (! result) aField.focus();

 return result;
}
//------------------------------------------------------------------------------------------------------------------------------------
function openWindow(aURL, aCaption, aTarget, aExtra){
	var win;
	win = window.open(aURL, aTarget, aExtra);
}
//------------------------------------------------------------------------------------------------------------------------------------
// otevre okno s prislusnym souborem
function openWindw(file) {
	var wf = window.open(file, "NewWin", "resizable=yes,toolbar=no,directories=no,menubar=no,scrollbars=yes,status=yes,screenX=50,screenY=50,top=50,left=50,width=800,height=600");
	wf.focus();
	return void(0);
}
//------------------------------------------------------------------------------------------------------------------------------------
// otevre okno s prislusnym souborem a o urcite velikosti
function openWindws(file,fw,fh) {
	var wf = window.open(file, "NewWin", "resizable=yes,toolbar=no,directories=no,menubar=no,scrollbars=yes,status=yes,screenX=50,screenY=50,top=50,left=50,width="+fw+",height="+fh+"");
	wf.focus();
	return void(0);
}
//------------------------------------------------------------------------------------------------------------------------------------
// otevre okno s originalni velikosti fotky
function foto_show_big(foto_id,fw,fh) {
	var wf = window.open("", "Foto", "resizable=yes,toolbar=no,directories=no,menubar=no,scrollbars=no,status=no,screenX=10,screenY=10,top=10,left=10,width="+fw+",height="+fh+"");
	wf.resizeTo (fw,fh);
	wf.document.open();
	wf.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head>'
		+ '<meta http-equiv="Content-Type" content="text/html; charset=windows-1250"><title>Detail náhledu</title>'
		+ '<link rel="STYLESHEET" type="text/css" href="./_css/photodet.css"></head>'
		+ '<body><div onClick="window.close()" style="margin: 0px; text-align: center; cursor:pointer;"'
		+ ' onclick="window.close()"><img src="' + foto_id + '" border="0"'
		+ ' onClick="window.close()" style="cursor:pointer;" onclick="window.close()">');
	wf.document.write('</div></body></html>');
	wf.document.close();
	wf.focus();
	return void(0);
}

//------------------------------------------------------------------------------------------------------------------------------------
// otevre okno s definovanou velikosti s emailem
function show_eml(file_id,fw,fh) {
	var wf = window.open(file_id, "Email", "resizable=no,toolbar=no,directories=no,menubar=no,scrollbars=no,status=no,screenX=300,screenY=300,top=300,left=300,width="+fw+",height="+fh+"");
	wf.resizeTo (fw,fh);
	wf.focus();
	return void(0);
}

//------------------------------------------------------------------------------------------------------------------------------------
//     ENABLE - Move selected widgets from DISABLED to ENABLED
//                     or vice versa
function enable(from,to) {

   for (i=0; i<to.options.length; i++) {
     to.options[i].selected = 0;  // Clear selects.
   }
// Search FROM and move to TO.
   for (i=0; i<from.options.length-1; i++) {
     if (from.options[i].selected) {
        if (from.options[i].value != "") {
           k = to.options.length;
           j = to.options.length - 1;
           to.options.length++;
           to.options[j].value = from.options[i].value;
           to.options[j].text = from.options[i].text;
           to.options[j].selected = 1;
           from.options[i].value = "";
           from.options[i].text = "";
           from.options[i].selected = 0;
        }
     }
   }
   to.options[to.options.length-1].text = "--------------------------------------------------------------------------------------------------";
// Collapse FROM.
   j = 0;
   for (i=0; i<from.options.length; i++) {
     if (from.options[i].text != "") {
        if (i != j) {
// Move entry to new spot.
           from.options[j].value = from.options[i].value;
           from.options[j].text = from.options[i].text;
           from.options[j].selected = from.options[i].selected;
        }
        j++;
     }
   }
   from.options.length = j;
}

//------------------------------------------------------------------------------------------------------------------------------------
//       SAVEIT - Reformat 'f_idctg' before submitting
//
function saveit(f) {
   f.f_idctg.value = "";   // In case they manage to click SAVE twice!
   for (i=0; i<f.f_idctg_desti.options.length - 1; i++) {    
      if (f.f_idctg.value == "") {
         f.f_idctg.value = f.f_idctg_desti.options[i].value;
      } else {
         f.f_idctg.value += ";" + f.f_idctg_desti.options[i].value;
      }
   }
   //if (f.f_idctg.value	== "") {
      //return false;
   //} else {
      //return true;
   //}
}
