<!--

function checkForm(fname, action)
{
	this.add = checkForm_add_field;
	this.change = checkForm_change_field;
	this.msg = checkForm_message;
	this.send = checkForm_send;
	this.validate = checkForm_validate_fld;
	this.validate_r = checkForm_validate_require;
	this.validate_b = checkForm_validate_between;
	this.validate_bval = checkForm_validate_between_val
	this.blink_fld = checkForm_blink_field;
	this.deleteAll =checkForm_clear_fields;
	this.add_list = checkForm_addFromList;
	
	this.groups = new Array();
	this.chg = checkForm_chgrp_form;
		
	//parse functions
	this.vVerifyPasswd = checkForm_verify_paswd;
	this.vChangePasswd = checkForm_change_passwd;
	this.vChange = checkForm_change_value;
	//end functions

	this.regxpObj = new Array();
	this.regxpObj["all"] = /.*/;
	this.regxpObj["int"] = /^[\-0-9]{1,}$/i;
	this.regxpObj["float"] = /^[\-0-9]{1,}(\.[0-9]{1,})?$/i;
	this.regxpObj["date"] = /^[0-9]{4}\-[01]{1}[0-9]{1}\-[0123]{1}[0-9]{1}$/i;
	this.regxpObj["time"] = /^[0-9]{2}\:[0-9]{2}\:[0-9]{2}$/i;
	this.regxpObj["date_time"] = /^[0-9]{4}\-[0-9]{2}\-[0-9]{2}\ [0-9]{2}\:[0-9]{2}\:[0-9]{2}$/i;
	this.regxpObj["post_code"] = /^[0-9]{2}\-[0-9]{3}$/i;
	this.regxpObj["phone"] = /^[0-9 \(\)\.\-wewn\/]{6}$/i;
	this.regxpObj["www"] = /^(http:\/\/)?www[0-9_a-z._-]+\.[a-z]{2,3}([\/0-9_a-z\.]{1,})?(\/?.*)?$/i;
	this.regxpObj["email"] = /^[0-9_a-z.-]+(@|\(at\))+(([0-9_a-z._-]+\.[a-z]{2,3})|(localhost))$/i;
	this.regxpObj["price"] = /^[0-9]{1,}([\.]{1})?([0-9]{2})?$/i;
	this.regxpObj["text"] = /^[^\|]{1,}$/i;
	this.regxpObj["passwd"] = /^[a-zA-Z0-9_\-\+\.\@]{1,}$/i;
	

	action = ''+action;
	this.fObj = document.forms[fname];
	this.oldAction = this.fObj.action;
	this.action = (action.length == 0 || action == "undefined")? "index.php" : action ;
	this.target = false;
	this.ok = true;
	this.formName = fname;
	this.box = new Array();
	this.is_prompt = false;
	this.submit_function = false;

	if(typeof(checkFormCss) == "object")
	{
		this.defaultBorderStyle = checkFormCss[0];
		this.selectBorderStyle = checkFormCss[1];
	}
	else
	{
		this.defaultBorderStyle = "1px solid #999999";
		this.selectBorderStyle = "1px solid #000000";
	}		
	this.msg_function = (typeof(display_message) == "function")? display_message : false ;
	
	this.messages =
	{
		"no_fld" : "There are no fields with the given name (%1) .",
		"no_type" : "Unknown type (%1) variable in the form of the name (%2).",
		"no_fill" : "Field (%1) has no value entered .",
		"no_option" : "Field (%1) has no chosen any of the options .",
		"no_between_fill" : "Value of field (%1) should contain between (%2) a (%3).",
		"no_between_option" : "Field (%1) should be marked with the minimum (%2) and maximum (%3) options.",
		"bad_fill" : "Pole (%1) zosta�o b��dnie wype�nione.",
		"send" : "Are you sure to send the form ?",
		"err" : "The form can not be sent due to previous errors."
	};
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function checkForm_add_field(n, t, d, r, m)
{
	var i = this.box.length;
	var tmp;
	var tmp_reg;
	var j;

	if(this.ok)
	{
		var tmp = this.fObj.elements[n];

		if(tmp == null || ''+tmp == "undefined" || ''+tmp.length == 0)
		{
			//this.msg("no_fld", n);
			this.msg([this.messages["no_fld"], n]);
			//this.messages["no_fld"]
			this.ok = false;
		}
		else
		{
			for(j=0; j<i; j++)
			{
				if(''+this.box[j]["name"] == n)
				{
					i = j;
					break;
				}
			}

			this.box[i] = new Array();
			this.box[i]["name"] = n;
		}

		if(this.ok)
		{
			t = (t == "" || t == "all")? "all": t ;
			
			if(typeof(this.regxpObj[t]) == "undefined")
			{
				this.msg("no_type", t, n);
				this.ok = false;
			}
			else
				this.box[i]["reg"] = t ;
		}

		if(this.ok)
		{
			//this.box[i]["require"] = (!isNaN(parseInt(r)) || r.length > 0)? true : false ;
			this.box[i]["require"] = (parseInt(r) == 1)? true : false ;

			if(typeof(m) != "undefined")
			{
				m = m.split(",");
				this.box[i]["between"] = [(m[0].length > 0)? m[0] : false, (typeof(m[1]) != "undefined" && m[1].length > 0)? m[1] : false];
			}
			else
				this.box[i]["between"] = false;
		}

		if(this.ok)
		{
			tmp = ''+this.fObj.elements[n].type;
			tmp = tmp.toLowerCase();
			
			if(tmp == "text" || tmp == "textarea" || tmp == "password" || tmp == "file" || tmp == "hidden")
			{
				this.box[i]["type"] = tmp ;
				this.box[i]["length"] = 1;
			}
			else
			{
				if(isNaN(parseInt(this.fObj.elements[n].length)))
					this.box[i]["length"] = 1;
				else
					this.box[i]["length"] = this.fObj.elements[n].length;	
			
				this.box[i]["type"] = (this.box[i]["length"] > 1) ? ''+this.fObj.elements[n][0].type : ''+tmp ;
			
			}

			if(tmp.match(/select/) || this.box[i]["type"].match(/select/))
				this.box[i]["type"] = "select";		

			this.box[i]["display"] = (d.length == 0)? 0 : d ;
		}
	}
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function checkForm_change_field(n, f, v)
{
	var i;
	for(i=0; i<this.box.length; i++)
	{
		if(''+this.box[i]["name"] == n)
		{
			this.box[i][f] = v;
			break;
		}
	}	
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function checkForm_addFromList()
{
	var tmp_l = checkForm_addFromList.arguments;
	var k;

	for(k=0; k<tmp_l.length; k++)
		this.add(tmp_l[k], "", 0, 1);
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function checkForm_clear_fields()
{
	this.box = "";
	this.box = new Array();
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function checkForm_message()
{
	var farg = checkForm_message.arguments;
	var msgtext;

	if(typeof(farg[0]) == "object")
	{
		msgtext = farg[0][0];
		for(i=1; i<farg[0].length; i++)
			msgtext = msgtext.replace("%"+i, farg[0][i]);
	}
	else
		msgtext = farg[0];

	if(typeof(this.msg_function) == "function")
	{
		if(farg.length > 1 && farg[1].indexOf("javascript") != -1)
			this.msg_function(msgtext, farg[1]);
		else
			this.msg_function(msgtext);		
	}
	else
		alert(msgtext);
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function checkForm_send()
{
	var result = 1;
	var i = 0;
	var tmp;

	if(this.ok)
	{
		for(i=0; i< this.box.length; i++)
		{
			result = this.validate(i);

			if(result != 1)
			{
				tmp = this.box[i]["type"];

				if(tmp == "text" || tmp == "textarea" || tmp == "password")
					this.blink_fld(this.fObj.name, 1, this.box[i]["name"], this.defaultBorderStyle, this.selectBorderStyle, 0);
				else if((tmp == "radio" || tmp == "checkbox") && this.box[i]["length"] > 1)
					this.blink_fld(this.fObj.name, 2, this.box[i]["name"], "", "", 0);
			
				this.msg(result);
				break;
			}
		}

		if(result == 1)
		{
			if(this.is_prompt)
			{
				if(typeof(this.msg_function) == "function")
					this.msg("send", "javascript:document."+this.formName+".action='"+this.action+"'; document."+this.formName+".submit()");
				else
				{
					if(confirm(""+this.messages["send"]))
					{
						if(this.target && this.action.indexOf("javascript") == -1)
							this.fObj.target = this.target;					
						
						if(this.submit_function)
						{
							if(typeof(this.submit_function) == "object")
								eval(this.submit_function[0]+"('"+this.submit_function[1]+"')");
							else
								eval(this.submit_function+"()");
						}

						this.fObj.action = this.action;
						this.fObj.submit();
					}
				}
			}
			else
			{
				if(this.target && this.action.indexOf("javascript") == -1)
					this.fObj.target = this.target;

				if(this.submit_function)
				{
					if(typeof(this.submit_function) == "object")
						eval(this.submit_function[0]+"('"+this.submit_function[1]+"')");
					else
						eval(this.submit_function+"()");
				}

				this.fObj.action = this.action;
				this.fObj.submit();
			}
		}
	}
	else
		this.msg("err");
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function checkForm_validate_fld(i)
{
	var _type = this.box[i]["type"];
	var _fname = this.box[i]["name"];
	var _dname = this.box[i]["display"];
	var _length = this.box[i]["length"];
	var _require = this.box[i]["require"];
	var _between = this.box[i]["between"];
	var _reg = this.box[i]["reg"];
	var _value;
	var vr, vb, ret = 1;

	vr = this.validate_r(this.fObj.elements[_fname], _type, _length);

	if(_require == true && !vr)
	{
		if(_type == "checkbox" || _type == "radio" || _type == "select")
			return [this.messages["no_option"], _dname];
		else
			return [this.messages["no_fill"], _dname];
	}

	if(_type == "text" || _type == "textarea" || _type == "password")
	{
		if(vr && !vr.match(this.regxpObj[_reg]))
			return [this.messages["bad_fill"], _dname];
	}	

	if(vr && (_between[0] || _between[1]) && !this.validate_b(vr, _between, _type, _reg, _length))
	{
		if(!_between[0]){_between[0] = "---";}
		if(!_between[1]){_between[1] = "---";}
	
		if(_type == "checkbox" || _type == "radio" || _type == "select")
			return [this.messages["no_between_option"], _dname, _between[0], _between[1]];
		else
			return [this.messages["no_between_fill"], _dname, _between[0], _between[1]];
	}

	return ret;
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function checkForm_validate_require(obj, ftype, flength)
{
	var i;
	var cnt = 0;

	switch (ftype)
	{
		case "checkbox":
		case "radio":

			if(flength == 1)
				return (obj.checked)? 1 : false ;
			else
			{
				for(i=0; i<flength; i++)
				{
					if(obj[i].checked)
						cnt++;
				}
				return (cnt == 0)? false : cnt;
			}

		break;

		case "select":
			return (obj.options[obj.selectedIndex].value.length > 0)? 1 : false ;
		break;

		default:
			return (obj.value.length > 0)? obj.value : false ;
	}
	return false;
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function checkForm_validate_between(uinput, between, ftype, reg, flength)
{
	if(!between[0] && !between[1])
		return true;

	switch (ftype)
	{
		case "checkbox":
		case "radio":
		case "select":
			return this.validate_bval(uinput, between);
		break;
		
		case "text":
			if(reg == "int")
				return this.validate_bval(parseInt(uinput), between);
			else if(reg == "float")
				return this.validate_bval(parseFloat(uinput), between);
			else if(reg == "date")
			{
				var dt = uinput.split("-");
				dt = new Date(dt[0], dt[1], dt[2]);
				dt = dt.getTime();

				if(between[0])
				{
					var btw1 = between[0].split("-");
					btw1 = new Date(btw1[0], btw1[1], btw1[2]);
					btw1 = btw1.getTime();
				}
				else
					btw1 = false;

				if(between[1])
				{
					var btw2 = between[1].split("-");
					btw2 = new Date(btw2[0], btw2[1], btw2[2]);
					btw2 = btw2.getTime();
				}
				else
					btw2 = false;

				return this.validate_bval(dt, [btw1, btw2]);
			}
			else
				return this.validate_bval(uinput.length, between);

		break;

		default:
			return true;
	}
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function checkForm_validate_between_val(val, btw)
{
	var result = true;

	if(btw[0] && val < btw[0])
		result = false;

	if(result && btw[1] && val > btw[1])
		result = false;

	return result;
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function checkForm_blink_field(f, t, fl, bd, bs, i)
{
	var i;
	i = i+1;

	if(t == 1)
	{
		if(i < 9)
			setTimeout("checkForm_blink_field('"+f+"', "+t+", '"+fl+"', '"+bd+"', '"+bs+"', "+i+")", 200);

		if((document.all || (!document.all && !document.layers)) && navigator.userAgent.indexOf("Opera") == -1)
			document.forms[f].elements[fl].style.border = (i%2 == 1)? bd : bs ;
	}
	else if(t == 2)
	{
		if(i < 8)
			setTimeout("checkForm_blink_field('"+f+"', "+t+", '"+fl+"', '"+bd+"', '"+bs+"', "+i+")", 200);

		document.forms[f].elements[fl][0].checked = (i%2 == 1)? true : false ;
	}
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function checkForm_verify_paswd(a)
{
	if(this.fObj.passwd.value != this.fObj.passwd_reply.value)
		alert("B��dne powt�rzenie has�a.");
	else	
	{
		if(this.fObj.passwd.value.length > 0)
			this.fObj.passwd_hidden.value = hex_md5(this.fObj.passwd.value);
		
		if(this.target)		
			this.fObj.target = this.target;
		
		if(this.fObj.passwd_hidden_use_norm.value == 1)
			this.fObj.passwd_hidden_norm.value = this.fObj.passwd.value;
		
		this.fObj.passwd.value = "";
		this.fObj.passwd_reply.value = "";
		this.fObj.action = a;
		this.fObj.submit();
	}
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function checkForm_change_passwd(a, key)
{
	this.fObj.passwd_hidden.value = hex_md5(hex_md5(this.fObj.passwd.value)+""+key);
				
	this.fObj.passwd.value = "";
	this.fObj.action = a;

	if(this.target)		
		this.fObj.target = this.target;
	
	this.fObj.submit();
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function checkForm_change_value(t, obj)
{
	var tmp;
	switch(t)
	{
		case "date":
			if(obj.value.match(/^([0-9]{4})+(\-[0-9]{2})?$/g))
				obj.value += "-";
		break;
		case "time":
			if(obj.value.match(/^([0-9]{2})+(\:[0-9]{2})?$/g))
				obj.value += ":";
		break;		
		case "float":
		case "price":
			obj.value = obj.value.replace(/,/g, ".");
		break;
	}
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function checkForm_chgrp_form(g, t)
{
	var i, j, n = -1;
	
	if(typeof(g) == "number")
		n = g;
		
	for(i=0; i<this.groups.length; i++)
	{
		document.getElementById(this.groups[i]).style.display =  (g == this.groups[i] || n == i+1)? ((document.all)? "block" : "table-cell") :"none" ;
		
		if(t == "adm")
			document.getElementById("form_zak_link_"+this.groups[i]).className = (g == this.groups[i] || n == i+1)? "form_zak_act" :"form_zak_none" ;
	}
}

//-->
