// Crux IT; Milan Gvozdik; 11.8.2005 10:17:07; gob_inc_utils.js 2.03

//----------------------------------------------------------------------------------------
// GENERAL SECTION
//----------------------------------------------------------------------------------------

//----- LS - open detail page from overview table


function openDetailPage(detail_page_name,detail_key_name_1,keyval1,detail_key_name_2,keyval2,detail_params)
{
  //alert(detail_page_name+"?"+detail_key_name_1+"="+keyval1+"&"+detail_key_name_2+"="+keyval2+"&"+detail_params);
  document.location=detail_page_name+"?"+detail_key_name_1+"="+keyval1+"&"+detail_key_name_2+"="+keyval2+"&"+detail_params;
}

//-----show / hide <div> -----
function roll(id)
{
	var obj= document.getElementById(id);
	if (obj.className == "unrollh") obj.className = "unrolls";
	else obj.className = "unrollh";
}

function help(scr){
 	newWindow= self.open('HLP_ShowHelp.do?screen='+scr, "Help", "height=400,width=300");
	if (newWindow) newWindow.focus();
}

function getPageFromUrl(u)
{//return pagename from url
	idx= u.lastIndexOf("/");
	idx2= u.lastIndexOf("?") - idx;
	idx2= idx2<2?60:idx2;
	return u.substr(idx+1,idx2);
}


//-----button-----

//btn_enabled="black";
//btn_enabled="white";
//btn_selected="red";
//btn_highlighted="#007777";
var btn_last;
var link_last;
var time_count= 0;
var time_buttonid= "";


function btnselect(buttonid){

if (buttonid == null && time_buttonid != "") buttonid= time_buttonid;
if (btn_last) btn_last.className="btnenabled";
objbutton= document.getElementById(buttonid);
if (objbutton == null)
{
	if ( time_count < 10)
	{
		time_count++;
		time_buttonid= buttonid;
		setTimeout('btnselect()', (300*time_count));
	}
	else alert("Internal error in function btnselect in page "+getPageFromUrl(document.URL)+"!\nButton ID="+buttonid+" not found!");

	return;
}
objbutton.className="btnselected";
btn_last=objbutton;
time_count= 0;
time_buttonid= "";
}

function btnclck(objbutton){


if (btn_last) btn_last.className="btnenabled";
objbutton.className="btnselected";
btn_last=objbutton;

}

function linkclck(objlink){
/*

if (link_last) link_last.className="linkenabled";
objlink.className="linkselected";
link_last=objlink;
alert(link_last.className);
*/
}


function btnover(objbutton){

if (objbutton.style.color!="red") objbutton.style.color=btn_highlighted;
}

function btnout(objbutton){

if (objbutton.style.color!=btn_selected) objbutton.style.color=btn_enabled;

}

//-----button-----

//-----help-----

function openPage(path, name, w, h, scroll, center)
{/*Open new window with specified path, name, width and height. Parameters path and name are required.
  scroll=['Y','N'] default N- window with vertical scrollbar; center=['Y','N'] default N - center on screen*/
//alert(path+" ,  "+name+" , "+w+" , "+h+" , "+scroll+" , "+center);
	var sw= screen.width;
	var sh= screen.height;

	center = 'Y';
	if (w == null) w= 300;
	if (h == null) h= 300;
	if (scroll == 'Y') scroll= ",scrollbars=yes";
	else scroll= "";

	x= sw - w - 13;
	y= sh - h - 33;

	if(center == 'Y'){
		x = sw/2 - w/2;
		y = sh/2 - h/2;
	}
	newWindow= self.open(path,name,"top="+y+",left="+x+",dependent,resizable=yes"+scroll+",height="+h+",width="+w);

	if (newWindow) newWindow.focus();
	return newWindow;
}

function viewattach(path)
{
	openPage(path,"Attachnent",600,400,'Y','Y');
}

function gotorep(path)
{
	openPage(path,"Report",600,400,'Y','Y');
}


function gotohelp()
{
	if(helpPageURL=="")
		helpPageURL= "content_"+top.lang_id+".htm";

	helppage=top.AppRoot+"/hlp/"+helpPageURL;
	openPage(helppage,"help",300,400,'Y');
}

/*
function setHelpPage(myhelppage)
{
	document.formhelp.helppage.value=myhelppage;
}
//-----help-----
*/


//-----error-----
function showError(back)
{//back= 'Y'...history.back OR back= 'page_name'  go to page_name

	if(document.errorForm.msg.value != "")
	{
		alert(document.errorForm.msg.value);
		if(back != null && typeof back == "string" && document.errorForm.event_class.value!='I')
		{
			if (back == 'Y') history.back();
			else if (back.indexOf("javascript::") != -1)
			{
				i= back.lastIndexOf(":");
				//alert(back.substr(i+1));
				eval(back.substr(i+1));
			}
			else
			{
				n= parseInt(back,10);
				if( !isNaN(n) ) history.go(-n);
			}
		}
	}
}

function isError(){

	if(document.errorForm.msg.value != "") return true
	return false
}
//-----error-----

//-----parse URL-----
function parseUrl(url)
{//parse variables from URL into associative array. Each variable value acessed by ret["variable name"], number of variables assesed by ret.lenght

	var ret= new Object();
	var i= 0;
	var p;
	var odd= "?";
	var name, value;

	while ((p= url.indexOf(odd)) > -1)
	{
		odd= "&";
		url= url.substr(p+1);
		p= url.indexOf('=');
		name= url.substr(0,p);
		url= url.substr(p+1);
		p= url.indexOf(odd);
		if (p == -1) p= url.length;
		value= url.substr(0,p);
		ret[name]= value;
		i++;
	}
	ret["length"]= i;
	return ret;
}

//-----parse String-----
function leftFrom(str, deli)
{//return left part of string with deli delimiter
	var i= str.indexOf(deli);

	if (i == -1) return str;
	return str.substr(0, i);
}

function rightFrom(str, deli)
{//return right part of string with deli delimiter
	var i= str.indexOf(deli);

	if (i == -1) return str;
	return str.substr(i+1);
}

//M.O


function tree_click(item)
{
	var old;
	var old_selected_item;


	old_selected_item=document.tree.sel_item_id.value;
	if (old_selected_item) {
		old= document.getElementById(old_selected_item);
		if (old && old.className) old.className= old.className.replace(/ sel/,"");
	}
	item.className+= " sel";

	document.tree.sel_item_id.value = item.id;
}

//----------------------------------------------------------------------------------------
// UTILITY SECTION
//----------------------------------------------------------------------------------------

/*
var    operator = new Array();
    operator[0] = "";
    operator[101] = "";
    operator[201] = "";
    operator[301] = "";
    operator[401] = "";
    operator[102] = "<>";
    operator[202] = "<>";
    operator[302] = "!";
    operator[402] = "!";
    operator[103] = ">";
    operator[203] = "";
    operator[303] = "";
    operator[403] = ">";
    operator[104] = ">=";
    operator[204] = "<>";
    operator[304] = "<>";
    operator[404] = ">=";
    operator[105] = "<";
    operator[205] = "x*";
    operator[305] = "x*";
    operator[405] = "<";
    operator[106] = "<=";
    operator[206] = "!x*";
    operator[306] = "!x*";
    operator[406] = "<=";
    operator[111] = "x..y";
    operator[207] = "*x";
    operator[307] = "*x";
    operator[407] = "";
    operator[112] = "!x..y";
    operator[208] = "!*x";
    operator[308] = "!*x";
    operator[408] = "";
    operator[411] = "x..y";
    operator[412] = "!x..y";
    operator[121] = "$ISNULL";
    operator[221] = "$ISNULL";
    operator[321] = "$ISNULL";
    operator[421] = "$ISNULL";
    operator[122] = "$ISNOTNULL";
    operator[222] = "$ISNOTNULL";
    operator[322] = "$ISNOTNULL";
    operator[422] = "$ISNOTNULL";

*/

/**********************************************************************
 *        VALIDATE SECTION  MSIE5.+,  Gecko 0.9+ and Opera 7+ compatible
 * version 1.26  ;  + added functionality  *bug
 * Hitory: 1.03 - basic varion
 *         1.24 advanced version + validated form can't have strict form (vlabel attribute added, <label> tag is possible etc)
 *                               + #ma and #mi special constants in error texts was replaced by (more logic) #max and #min
 *                               + first bad item receive focus
 *                               * select multiple has been validated correctly
 *
 *         1.25 * small bug fix - attributes emax ans emin has been renamed to max ans min (as before)
 *         1.26 * small bug fix - types PASS and CONFIRM have script error if PASS is empty and CONFIRM have value.
 *
 *************************************/


var gLIST_DELIMITER= ';'; //global constant, delimiter character in list of item (required for functions validate() and convertListItem )

//Global Form Error msg  0                                  1                       2                3                  4                  5                 6                                     7                                                8                                        9                              10                             11                                          12        13                            14                              15                    16
var gaFormErr= new Array("Upozornění! Formulář obsahuje následující chyby. (#page)!"
,"Hodnota musí být vyplněna."
,"Špatný formát čísla."
,"Špatný formát čísla."
,"Špatný formát emailu."
,"Bad Word format"
,"Špatný formát hesla. Nepoužívejte apostrofy."
,"Zadaná hodnota je příliš dlouhá. Maximální počet znaků je #max."
,"Min #min charakters max #max charakters."
,"Minimum number value is #min."
,"Maximum number value is #max."
,"Number value must be between #min and #max."
,"Bad URL","Only asterisk (*) or Integer"
,"Heslo a potvrzovací heslo musí být stejné!"
,"Bad list of emails!","Bad list of phone numbers!");
var gPasswordItem= null;


function setFormErr(e0,e1,e2,e3,e4,e5,e6,e7,e8,e9,e10,e11,e12,e13,e14,e15,e16)
{ /*Set Form error string.
  val=
  0 - alert first line;
  1 - value required;
  2 - int value;
  3 - float value;
  4 - email;
  5 - word;
  5 - password;
  7 - text too long;
  8 - min max text chars;
  9 - min number;
  10 - max number;
  11 - number between min and max;
  12 - url value;
  13 - * or int value;
  14 - password not same as confirm;
  15 - email list;
  16 - phone list
  */
	gaFormErr= new Array(e0,e1,e2,e3,e4,e5,e6,e7,e8,e9,e10,e11,e12,e13,e14,e15,e16);
}

function getFormErr(val)
{ //Return Form error string.
	if ( val < gaFormErr.length) return gaFormErr[val];
	return "Internal error: Bad value '"+val+"' in getFormErr() function!";
}

//-----validation----
function myTrim(t)
{//remove white chars from string
	var i= 0;

	if (!t || t == null || t == "") return "";

	while (/[\s]/.test(t.charAt(i))) i++;
	t= t.substr(i);
	//alert("i="+i+"      t='"+t+"'");
	i= t.length - 1;
	while (/\s/.test(t.charAt(i))) i--;
	t= t.substring(0,i+1);
	return t;
}

function myParseInt(s)
{//return Integer number from string
	if (!/^\s*[-+]?\d+\s*$/.test(s)) return NaN;
	var num= parseInt(s,10);
	if (isNaN(num)) return NaN;
	return num;
}

function myParseFloat(s)
{//return Float number from string
	if (!/^\s*[-+]?\d+\s*$|^\s*[-+]?\d+[\.,]\d+([eE][-+]?\d+)?\s*$/.test(s)) return NaN;
	var num= parseFloat(s);
	if (isNaN(num)) return NaN;
	return num;
}

function validate(obj, type, req, from, to, base, trim)
{ /* Validate form object. type=["TEXT" text,"WORD" word only,"INT" integer,"FLOAT" float,"EMAIL" email, "PASS" password, "CONFIRM" confirm password,"URL" URL, "AINT" Asterisc or Int, "PHONE" phone number, "EMAIL_LIST" list of emails, "PHONE_LIST" list of phone numbers, "DATE_PICK" date from date picker(three input boxes)],
    WORD - text without white spaces. Phone number can contain char + at begin and some numbers and spaces
    In list of items delimiter are ;
	req - true if value is requied (obligatory);
    from,to - range (in text min and max number of chars); base - range base(multiplier); trim - FLOAT ONLY number of numbers afref decimal point
    Return 1 if OK,
    0 if value is requied and value is empty,
    -1 if bad format,
    -2 if value lower that min;
    -3 value greater that max;
    -4 value not between min and max.
    -10 if password not same as confirm password

*/
	var text,num,pom,item;
	var argc= arguments.length;

	if (from == null || from == "") from= Number.NaN;
	if (to == null || to == "") to= Number.NaN;

	function range(x)
	{
		var e=0;
		var pom2= true;
		if (! isNaN(from))
		{
			pom2= x >= from; e= -1;
		}
		if (! isNaN(to))
		{
			pom2= pom2&&(x <= to);
			e-= 2;
		}
		//alert(f+"\n   max je null? "+isNaN(to)+"   max="+to);
		return pom2?1:--e;
	}

	text= obj.value!=null?obj.value:obj;
	
	if (type == "PASS")	gPasswordItem= obj; // save password item object - CONFIRM uses this

	//test obligatory - item must have any value!
  if (text == "")
	{
		if (req) return 0;
		else return 1;
	}
	//test of each type
  if (type == "TEXT")
	{
		return range(text.length);
	} else
	if (type == "INT")
	{
		num= myParseInt(text);
		if (isNaN(num)) return -1;
		obj.value= num;
		if (argc < 6) base= 1;
		from*= base; to*= base;
		return range(num);
	} else
	if (type == "AINT")
	{
		if (text == "*") return 1;
		num= myParseInt(text);
		if (isNaN(num)) return -1;
		obj.value= num;
		if (argc < 6) base= 1;
		from*= base; to*= base;
		return range(num);
	} else
	if (type == "FLOAT")
	{
		if (argc > 6) decimal= trim;
		else decimal= text.length;
		pom= text.search(/[,\.]/);
		if (pom != -1) text= text.substring(0,pom) + "." + text.substr(pom+1, decimal);
		num= myParseFloat(text);
		if (isNaN(num)) return -1;
		obj.value= num;
		if (argc < 6) base= 1;
		from*= base; to*= base;
		return range(num);
	} else
	if (type == "EMAIL")
	{
		if (!/^[^@]+@[^.]+\..+$/.test(text)) return -1;
	} else
	if (type == "URL")
	{
		if (!/^((http|https|ftp)\:\/\/)((\d{1,3}(\.\d{1,3}){3})|(([A-Z%#&][\w\.\-%\?#&]*))+)(:\d+)?(\/[^\s]*)*$/i.test(text)) return -1;

		//if (!/^((aa)|(bb)).*$/.test(text)) return -1;

	} else
	if (type == "WORD")
	{
		if (!/^[^\s]+$/.test(text)) return -1;
		return range(text.length);
	} else
	if (type == "PASS")
	{
		if (!/^[^\'\s]+$/.test(text)) return -1;
		if ( (pom= range(text.length)) != 1) return pom;
		return 1;
	} else
	if (type == "CONFIRM")
	{
    if (gPasswordItem == null || text != gPasswordItem.value) return -10;
		else return 1;
	} else
	if (type == "PHONE")
	{
		if (!/^\+?([ ]*\d+)+$/.test(text)) return -1;
	} else
	if (type == "EMAIL_LIST")
	{
		while ( (pom= text.indexOf(gLIST_DELIMITER)) > -1)
		{
			item= myTrim(text.substr(0,pom));
			if ( (item.length > 0) && (validate(item, "EMAIL", false) < 0) ) return -1;
			text= text.substr(pom+1);
		}
		item= myTrim(text);
		if ( (item.length > 0) && (validate(item, "EMAIL", false) < 0) ) return -1;
		return 1;
	} else
	if (type == "PHONE_LIST")
	{
		while ( (pom= text.indexOf(gLIST_DELIMITER)) > -1)
		{
			item= myTrim(text.substr(0,pom));
			if ( (item.length > 0) && (validate(item, "PHONE", false) < 0) ) return -1;
			text= text.substr(pom+1);
		}
		item= myTrim(text);
		if ( (item.length > 0) && (validate(item, "PHONE", false) < 0) ) return -1;
		return 1;
	} else
	if (type == "DATE_PICK")
	{
		return 1;
	} else
		{
			alert("Internal	error! Unknown type	'"+type+"' in function validate()!\n");
			return -1;
		}
	return 1;
}

function filterBadChars(val)
{//return filtere string - change apostrophe to double apostrophe
	if ( (val != null)&&(val != "") )
	{
		val= myTrim(val);
		//change apostrophes
		val= val.replace(/\'?\'/g,"''");
		//val= val.replace(/\'/g,"`");
		return val;
	}
	else return val;

}

function filterForm(f)
{ //Trim and filter (change apostrophe) all items in form f
	var items= f.elements;

	for(var i= 0; i < items.length; i++)
	{
		if ( ((items[i].tagName == "INPUT")&&((items[i].type == "text" || items[i].type == null)))||(items[i].tagName == "TEXTAREA") )
		{
			items[i].value= filterBadChars(items[i].value);
		}
	}
}

/**
 * Function get form and validate all inputs in this form.
 *
 * Automatically valid all form f items
 */
 function autoValid(f) {
	//alert('aa');
	var err="";
	var iType= "";
	var child,iVal,iLabel,iMin,ret;
	var iMax= 0;
	var doc;
	var firstItem = null;
	/* Function do special formating to array which it get in argument.*/
/*	function arr(x)
	{
		var r="";
		for(var i= 0; i < x.length; i++)
      if (x[i] != null)
        r+= "\n"+i+":"+x[i];
		return r;
	}*/

	//call validate function and create error message, change item class
	// function is called on the bottom of autoValid
	function test(item, val, type, label, min, max)	{
		var req= false;
		var str;
		var icn= item.className;
		var pom;
		//alert(item + " - " + val + " - " + type + " - " + label + " - " + min + " - " + max);

		function setItemTitle(t, reset)
		{//nastavi elementu titulek s textem chyby. Pokud uz element titulem ma, zalohuje jej do atributu cruxoldtitle.
			var n= item.name;
			var i;

			if (reset)
			{//resetuj titulek (na puvodni hodnotu)
				if (item.getAttribute("cruxoldtitle"))
				{
					item.title= item.getAttribute("cruxoldtitle");
				}
				else item.title= "";
				return true;
			}

			if (type == "DATE_PICK")
			{
				i= doc.getElementsByName(n+"_d").item(0);
				if (i != null) i.title= t;
				i= doc.getElementsByName(n+"_m").item(0);
				if (i != null) i.title= t;
				i= doc.getElementsByName(n+"_y").item(0);
				if (i != null) i.title= t;
			}
			else
			{
				//zezalohuj titulek, pokud jeste neni
				if (!item.getAttribute("cruxoldtitle") || item.getAttribute("cruxoldtitle") == "") item.setAttribute("cruxoldtitle", item.title);
				item.title= t;
			}
		}

		function setItemClass(c)
		{
			var n= item.name;
			var i;
			if (type == "DATE_PICK")
			{
				i= doc.getElementsByName(n+"_d").item(0);
				if (i != null) i.className= c;
				i= doc.getElementsByName(n+"_m").item(0);
				if (i != null) i.className= c;
				i= doc.getElementsByName(n+"_y").item(0);
				if (i != null) i.className= c;
			}
			else item.className= c;
		}
		if ( (icn.indexOf("inpdis") != -1) || ( icn.indexOf("inpro") != -1 && icn.indexOf("inprobl") == -1) ) return;
		if ( (icn.indexOf("inpobl") != -1) || (icn.indexOf("inprobl") != -1) ) req= true; //item is obligatory
		//alert("label="+label+" class="+icn+" requed="+req+" min="+min+"   max="+max);
		if (type == "PASS" || type == "CONFIRM")
			var ret= validate(item, type, req, min, max);
		else{
			var ret= validate(val, type, req, min, max);
		}
		if (ret < 1)
		{ //Error in item
			if (ret == 0) ret= 1;
			else
				if (ret == -1)
				{ //Bad item format
					switch (type)
					{
						case "INT": ret= 2; break;
						case "FLOAT": ret= 3; break;
						case "EMAIL": ret= 4; break;
						case "WORD": ret= 5; break;
						case "PASS": ret= 6; break;
						case "URL": ret= 12; break;
						case "AINT": ret= 13; break;
						case "EMAIL_LIST": ret= 15; break;
						case "PHONE_LIST": ret= 16; break;
					}
				}
				else
				if (ret == -10) ret= 14; //password not confirmed
				else
				{//Out of range
					//alert("type="+type+"  ret="+ret);
					if ( (type == "INT")||(type == "FLOAT")||(type == "AINT") ) ret= ret==-2?9:(ret==-3?10:11);
					else ret= ret==-3?7:8;
				}
			str= getFormErr(ret);
			if (max != null && max != "") str= str.replace(/#max/,max);
			if (min != null && min != "") str= str.replace(/#min/,min);
			err+= "\n-------------------------------------------\n" + label + ": " + str;
			setItemTitle(str);
			if (firstItem == null) firstItem= item; //save item for  focus.
			//change class to err class type
			if ( icn.indexOf("inpobl") != -1 && icn.indexOf("inpoblerr") == -1) setItemClass(icn.replace(/inpobl/,"inpoblerr"));
			else if ( (icn.indexOf("inpdef") != -1 && icn.indexOf("inpdeferr") == -1) ) setItemClass(icn.replace(/inpdef/,"inpdeferr"));
			else if ( icn.indexOf("inprobl") != -1 && icn.indexOf("inproblerr") == -1) setItemClass(icn.replace(/inprobl/,"inproblerr"));
			else if (icn == "" ) setItemClass("inpdeferr");
			if (ret == 14)
			{//bad confirmed password
				gPasswordItem.title= str;
				var pcn= gPasswordItem.className;
				if ( pcn.indexOf("inpobl") != -1 && pcn.indexOf("inpoblerr") == -1) gPasswordItem.className= pcn.replace(/inpobl/,"inpoblerr");
				else if ( (pcn.indexOf("inpdef") != -1 && pcn.indexOf("inpdeferr") == -1) ) gPasswordItem.className= pcn.replace(/inpdef/,"inpdeferr");
				else if ( pcn.indexOf("inprobl") != -1 && pcn.indexOf("inproblerr") == -1) gPasswordItem.className= pcn.replace(/inprobl/,"inproblerr");

			}
		}
		else
		{//not error in item
			setItemClass(icn.replace(/err/,""));
			setItemTitle("", true); //reset item title
		}
	}// end of test function

	gPasswordItem= null;

	//get the window of f form and call ou function (for animate logo)
	if (f.ownerDocument) doc= f.ownerDocument; //standart DOM1
	else doc= f.document; //only ms explorer
	if (f.ownerDocument) formWin=  f.ownerDocument.defaultView?f.ownerDocument.defaultView: f.ownerDocument.parentWindow; //standart DOM1 defaultView for Mozilla, parentWindow for Explorer 6.0
	else formWin= f.document.parentWindow; //only ms explorer 5.0/5.5


	filterForm(f);

	var allElem= f.elements;

	//alert("Autovalid: form="+f+"\n allElem="+allElem+"\n pocet allElem="+allElem.length);
	for (var i= 0; i < allElem.length; i++)
	{//for all form elements
		if ( allElem[i] )
		{
			child= allElem[i];
			//alert("FIRST Child\nNodeName="+child.nodeName+"\nnodeType="+child.nodeType+"\nnodeValue"+child.nodeValue);
			if ( ( (child.nodeName == "INPUT")&&(child.type == "text" || child.type == "password") )||(child.nodeName == "TEXTAREA")||(child.nodeName == "SELECT") )
			//if ( ( (child.nodeName == "INPUT") )||(child.nodeName == "TEXTAREA")||(child.nodeName == "SELECT") )
			{//zjisti label(textovy nazev) elementu
				iLabel= false;
				//nejdrive zkusim zda neni attribut vlabel
				if (child.hasAttribute)
				{ //standart DOM way
					if (child.hasAttribute("vlabel")) iLabel= child.getAttribute("vlabel");
				}
				else
				{//ONLY MS Explorer way
					if (child.vlabel) iLabel= child.vlabel;
				}
				//zkusim, zda neni label primo pred elementem
				if (!iLabel && child.previousSibling && child.previousSibling.nodeType == 3)
				{//sourozenec je text
					var pom= myTrim(child.previousSibling.nodeValue);
					if (pom.length > 1) iLabel= pom;
				}
				//zkusim, zda neni label v parent tagu <label>
				if (!iLabel && child.parentNode && child.parentNode.nodeName == "LABEL" && child.parentNode.hasChildNodes())
				{//parent je label
					var pom= myTrim(child.parentNode.firstChild.nodeValue);
					if (pom.length > 1) iLabel= pom;
				}
				//zkusim, zda neni label v predchozim tagu <label>
				if (!iLabel && child.previousSibling && child.previousSibling.nodeName == "LABEL" && child.previousSibling.hasChildNodes())
				{//sourozenec je label
					var pom= myTrim(child.previousSibling.firstChild.nodeValue);
					if (pom.length > 1) iLabel= pom;
				}
				if (!iLabel)
				{//zkusim tabulkovy design
					if (child.parentNode && child.parentNode.nodeName == "TD")
					{//najdi predchozi TD
						pomNode= child.parentNode;
						while (pomNode.previousSibling && pomNode.previousSibling.nodeName != "TD")
						{
							pomNode= pomNode.previousSibling;
						}
						if (pomNode.previousSibling && pomNode.previousSibling.nodeName == "TD" && pomNode.previousSibling.hasChildNodes())
						{	//predchozi TD existuje a ma potomky
							var pom= myTrim(pomNode.previousSibling.firstChild.nodeValue);
							if (pom.length > 1) iLabel= pom;
						}
					}
				}
				if (!iLabel) iLabel= "";
				//alert("iLabel="+iLabel+"  tag="+child.name);

				if (child.getAttribute)
				{ //standart DOM way
					iType= child.getAttribute("vtype");
					if ( (iType == "INT")||(iType == "FLOAT")||(iType == "AINT") )
					{
						iMax= child.getAttribute("max");
					}
					else
					{//get TEXT maxlength
						iMax= child.getAttribute("maxlength");
					}
					iMin= child.getAttribute("min");
				}
				else
				{//ONLY MS Explorer way
					iType= child.vtype;
					if ( (iType == "INT")||(iType == "FLOAT")||(iType == "AINT") ) iMax= child.max;
					else iMax= child.maxlength!=null?child.maxlength:child.maxLength;
					iMin= child.min;
					//alert("  type="+iType+"  maxlength="+child.attributes.toString());
				}

				//Get item value
				if (child.nodeName == "SELECT")
				{
					if (child.multiple)
					{//get the mutliple select value
						iVal= child.selectedIndex == -1?"":"OK";//at least one item must be selected
					}
					else iVal= child.length>0?"OK":"";//Single Select is OK if have length>0
					if (iType == "MULTIPLE_LIST") iType= "TEXT";//MULTIPLE_LIST type is not necessary
				}
				else iVal= child.value;

				//alert("\n Label="+iLabel+"  type="+iType+"  value="+iVal+"  max="+iMax+"  tag="+child.nodeName);
				if ( (iType == "INT")||(iType == "TEXT")||(iType == "EMAIL")||(iType == "URL")||(iType == "FLOAT")||(iType == "WORD")||(iType == "PASS")||(iType == "CONFIRM")||(iType == "AINT")||(iType == "EMAIL_LIST")||(iType == "PHONE_LIST")||(iType == "DATE_PICK") ) test(child, iVal, iType, iLabel, iMin, iMax);
			}
		}
	}//END of FOR all elements


	var pageName,idx, idx2;

	if (f.ownerDocument) pageName= f.ownerDocument.URL; //standart DOM1
	else pageName= f.document.URL; //only ms explorer
	//get only pagename from URL
	pageName= getPageFromUrl(pageName);

	//make Error msg and call alert
	if (err == "") return true;
	err= getFormErr(0).replace(/#page/,pageName)+err; //make first line
	//focus first bad form item
	if (firstItem && firstItem.focus) firstItem.focus();
	formWin.alert(err);
	return false;
}

/*************************************
 *        UTILITY  SECTION           *
 *************************************/

// ************ Overview functions BEGIN
// Otevre okno s filtrem
// operatorID - ID naposledy nastaveneho operatoru filtru sloupce, pro ktery se dany filtr vola
// dataType - datovy typ operatoru
// value1,2	- hodnoty pro filtr
// columnCode - kod sloupce
function openFilter(operatorID, dataType, operandCount, value1, value2, columnCode, filter_type)
{
	if (dataType == 'D')
	{
				gDF= new DateFilter('gDF', setFilter, operatorID, value1, value2, columnCode, filter_type);
				gDF.show();
	}
	else
	{
		window.open("FILTER_ShowFilter.do?operatorID=" + operatorID +
			"&dataType=" + dataType +
			"&operandCount=" + operandCount +
			"&value1=" + value1 +
			"&value2=" + value2 +
			"&columnCode=" + columnCode +
			"&filter_type=" + filter_type,
			"Filter", "height=200,width=500,scrollbars=no,status=yes,toolbar=no,menubar=no,location=no,left=200,top=100");
	}
}



// Funkce volana z okna filtru po kliknuti na tlacitko "OK"
// operatorID - ID nastaveneho operatoru
// value1,2 - hodnoty filtru
// columnCode - kod sloupce
// operatorName - nazev nastaveneho Operatoru
function setFilter(operatorID, value1, value2, columnCode, operatorName, filter_type)
{
	if (operatorID == 0 && filter_type == 'O' || operatorID == -5)
		document.getElementById(columnCode).value = '';
	else
		document.getElementById(columnCode).value = operatorName + " " + value1 + " " + value2;

	document.getElementById(columnCode+'_operatorID').value = operatorID;
	document.getElementById(columnCode+'_operator_name').value = operatorName;
	document.getElementById(columnCode+'_value1').value = value1;
	document.getElementById(columnCode+'_value2').value = value2;
	document.getElementById(columnCode+'_filter_type').value = filter_type;
}

// funkce volana po kliku na tlacitko "NEXT PAGE"
function nextListPage()
{
	document.getElementById('page_move').value = 'N';
	applyFilter(0);
}
// funkce volana po kliku na tlacitko "PREVIOUS PAGE"
function prevListPage()
{
	document.getElementById('page_move').value = 'P';
	applyFilter(0);
}

// Funkce pro refresh screenu se specifikaci trideni
// sortColumn - index sloupce, podle ktereho se provede trideni
function applyFilter(sortColumn)
{
	document.getElementById('orderby').value = sortColumn;
	listForm.submit();
}
// ************ Overview functions END


function fillZeroes(x, n)
{//Return number x with defined count of zeroes bellow its value. Examples: n=2, x=0 return 00; n=3, x=12 return 012
	var ret= "";
	if (n < 2) return x;
	for(var i=x.toString().length; i < n; i++) ret+= "0";
	return ret+x.toString();
}

function getInputBoxState(obj)
{//Get state of INPUT TEXT obj= name of input box (document.editForm.text)
	var type= obj.type;

	switch(myTrim(obj.className))
	{
		case "inpro":    return "READONLY";   break;
		case "inpdis":   return "DISABLED";  break;
		case "inpobl":   return "OBLIGATORY";  break;
		case "inprobl":  return "OBLIGATORY_READONLY"; break;
		case "inpoblerr":return "OBLIGATORY_ERR"; break;
		case "inpdeferr":return "DEFAULT_ERR"; break;
		default: if (obj.readOnly) return "READONLY"; else return "DEFAULT";
	}
}

function setInputBoxState(obj, newstate)
{//Change state of INPUT TEXT obj= name of input box (document.editForm.text)
	newstate= newstate.toUpperCase();
	var type= obj.type;
	switch(newstate)
	{
		case "READONLY":				obj.readOnly= true;  if (obj.disabled != null) obj.disabled= false; if (type == "text" || type == "password") obj.className= "inpro";   break;
		case "DISABLED":				obj.readOnly= true;  if (obj.disabled != null) obj.disabled= true;  if (type == "text" || type == "password") obj.className= "inpdis";  break;
		case "OBLIGATORY":			obj.readOnly= false; if (obj.disabled != null) obj.disabled= false; if (type == "text" || type == "password") obj.className= "inpobl";  break;
		case "OBLIGATORY_READONLY":obj.readOnly= true;  if (obj.disabled != null) obj.disabled= false; if (type == "text" || type == "password") obj.className= "inprobl"; break;
		case "OBLIGATORY_ERR":		obj.readOnly= false; if (obj.disabled != null) obj.disabled= false; if (type == "text" || type == "password") obj.className= "inpoblerr"; break;
		case "DEFAULT_ERR":			obj.readOnly= false; if (obj.disabled != null) obj.disabled= false; obj.className= "inpdeferr"; break;
		case "DEFAULT":
		default: obj.readOnly= false; if (obj.disabled != null) obj.disabled= false; obj.className= "inpdef"; break;
	}
}

function show_props(ob, objName, newWindow)
{  //show all object property  obj may be any object or string ie "document.MyForm".
  //obj type string is need for display subobject of object
  //newWindow is window id for target atribute
	var result = "";
	var okno, j, i, obj;
	var a= new Array()

	function format_item(x)
	{
		if ( isFinite(x) ) return '['+x+']';
		return "."+x;
	}

	newWindow+= "a";
	if ( objName == null ) objName= String(ob);
	if (typeof ob != "object")
	{obj= eval(ob);}
	else obj= ob;
	j= 0;
	for (i in obj)
	{
		if (typeof obj[i] == "object" && obj[i] != null)
			a[j]= "<span class='click' onclick=\"opener.show_props('"+ob+format_item(i)+"','"+objName+"'+'.'+'"+i+"','"+newWindow+"')\">"+objName + format_item(i) + "</span> = " + obj[i] + "<br>\n";
		else
			a[j]= "<span class='b'>"+objName + format_item(i) + "</span> = " + obj[i] + "<br>\n";
		j++;
	}
	a.sort();
	for (i= 0; i < a.length; i++) result+= a[i];
	okno= window.open("","Object_property"+newWindow);
	if (okno)
	{
		okno.document.writeln("<html><title>Object "+objName+"</title><style>.b{color: green} .item{margin-left: 40px; color: red} .click {color: blue; text-decoration: underline; cursor: pointer; cursor: hand}</style><body>");
		okno.document.writeln(result);
		okno.document.writeln("</body></html>");
		okno.document.close();
	}
	else alert("Can not open window");
}

function convertListItem(val)
{ /*return list of items delimited by constant gLIST_DELIMITER character.
   val ... string of items, each item delimited by , or ; character*/
	var p;
	var item, ret;

	ret= "";

	function my_min(a,b)
	{
		if (a < 0) return b;
		if (b < 0) return a;
		return Math.min(a,b);
	}

	while ( (p= my_min(val.indexOf(','), val.indexOf(gLIST_DELIMITER))) > -1)
	{
		item= myTrim(val.substr(0,p));
		//alert("p="+p+" val="+val+" item="+item);

		if (item.length > 0) ret+= item + gLIST_DELIMITER;
		val= val.substr(p+1);

	}

	//add last item
	item= myTrim(val);
	if (item.length > 0) ret+= item;
	else ret= ret.substr(0,ret.length-1); //remove last delimiter char

	return ret;
}

function filterPhone(item)
{//filter phone number of form item. Chars / - # has been changed to space
	item.value= item.value.replace(/[\/\-#]/g," ");
}

function filterToSearch(val)
{//return filtered string for search page - remove dot, comma, one byte words...
	val= val.replace(/[\.\,\;]/g,"");
	val= filterBadChars(val.replace(/\s+.\s+/g," "));
	return val;
}

//----------------------------------------------------------------------------------------
// DATE TIME SECTION  version 2.0
//----------------------------------------------------------------------------------------

//am, pm texts
var gaAmPm= ["AM","PM"];

// Non-Leap year Month day numbers
var gDOMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
// Leap year Month day numbers
var gLDOMonth = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

function getDaysOfMonth(monthNo, p_year) {
	/*
	Check for leap year ..
	1.Years evenly divisible by four are normally leap years, except for...
	2.Years also evenly divisible by 100 are not leap years, except for...
	3.Years also evenly divisible by 400 are leap years.
	*/
	monthNo--;

	if (p_year == null || p_year == "") return 31;

	if ((p_year % 4) == 0) {
		if ((p_year % 100) == 0 && (p_year % 400) != 0)
			return DOMonth[monthNo];

		return lDOMonth[monthNo];
	} else
		return DOMonth[monthNo];
}

function formatUserDate(date, format)
{//Return  string contains date converted according gFormat. The format parameter is optional.
 //date is Javascript Date
	var vData= (typeof format == "undefined" || format == null)?gDateFormat:format;
	var vMM = fillZeroes(date.getMonth() + 1, 2);
	var vYYYY = new String(date.getFullYear());
	var vYY = new String(date.getFullYear().toString().substr(2,2));
	var vDD = fillZeroes(date.getDate(), 2);

	if (vData.indexOf("DD") != -1) vData= vData.replace(/DD/,vDD);
	if (vData.indexOf("MM") != -1) vData= vData.replace(/MM/,vMM);
	if (vData.indexOf("YYYY") != -1) vData= vData.replace(/YYYY/,vYYYY);
	else if (vData.indexOf("YY") != -1) vData= vData.replace(/YY/,vYY);

	return vData;
}

function parseUserDate(text, format)
{//Transform string contains date in user format (gFormat) to Javascipt Date. The format parameter is optional.
	var ret= new Date();
	var i;
	var pom;
	if (typeof format == "undefined" || format == null) format= gFormat;

	if ( (i= format.indexOf("DD")) != -1 ) ret.setDate(parseInt(text.substr(i,2),10));
	if ( (i= format.indexOf("MM")) != -1 ) ret.setMonth(parseInt(text.substr(i,2),10) - 1);
	if ( (i= format.indexOf("YYYY")) != -1 ) ret.setFullYear(parseInt(text.substr(i,4),10));
	else if ( (i= format.indexOf("YY")) != -1 )
		{
			pom= parseInt(text.substr(i,2),10);
			if (pom < 60) pom+= 2000;
			else pom+= 1900;
			ret.setFullYear(pom);
		}
	return ret;
}

function formatUserTime(p_hour, p_min, p_sec, p_ampm)
{
	var vTime= gTimeFormat;

	var vHH= fillZeroes(p_hour,2);
	var vMI= fillZeroes(p_min,2);

	var isSeconds= p_sec != null && (typeof p_sec == "string" || typeof p_sec == "number");

	var vSS= isSeconds?fillZeroes(p_sec,2):00;

	if (vTime.indexOf("HH24") != -1) vTime= vTime.replace(/HH24/,vHH);
	else if (vTime.indexOf("HH") != -1) vTime= vTime.replace(/HH/,vHH);
	if (vTime.indexOf("MI") != -1) vTime= vTime.replace(/MI/,vMI);
	if ( vTime.indexOf("SS") != -1) vTime= vTime.replace(/SS/,vSS);
	if ( !isTime24 && vTime.indexOf("AM") != -1) vTime= vTime.replace(/AM/,p_ampm);

	return vTime;
}

function parseUserTime(text)
{
	var ret= new Object();
	var i;

	ret.hour= null; ret.mim= null; ret.sec= null; ret.pm= null;
	if (text == null || typeof text != "string" || text == "") return null;

	i= text.indexOf(":");
	ret.hour= parseInt(text.substr(0,i),10);
	ret.min= parseInt(text.substr(i+1,2),10);
	if (  (i= text.indexOf(":",i+1)) != -1 ) ret.sec= parseInt(text.substr(i+1,2),10);
	if (!isTime24) ret.pm= text.indexOf("AM") != -1?gaAmPm[0]:gaAmPm[1];
	return ret;
}

function validDate(d,m,y)
{
	//d= d-0; m= m-0; y= y-0;
	if ( y != "" &&( isNaN(y) || y < 1800) ) return false;
	if ( m != "" &&( isNaN(m) || m > 12 || m < 1) ) return false;
	if ( d != "" &&( isNaN(d) || d > getDaysOfMonth(m, y) || d < 1) ) return false;
	return true;
}

function getElementsByClassName(className){
  var arr = new Array();
  var elems = document.getElementsByTagName("*");
  for(var i = 0; i < elems.length; i++){
    var elem = elems[i];
    var id = elem.getAttribute("id");
    var cls = elem.getAttribute("class");
    if(cls == className){
      arr[arr.length] = id;
    }
  }
  return arr;
}

