


	function CForm()
	{
		this.NS = (document.layers) ? 1 : 0;
		this.IE = (document.all)    ? 1 : 0;
	}



	CForm.prototype.isMail = function(vs_mail)
	{
		var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
		return (re.test(vs_mail));
	}



	CForm.prototype.isURL = function(vs_url)
	{
		var re = /^(http\:\/\/)?[a-zA-Z0-9\~\_\-\.]+\.[a-zA-Z]{2,}[a-zA-Z0-9\/\_\-\.\?\&\=\~]*$/;
		return (re.test(vs_url));
	}



	CForm.prototype.isDate = function(vs_date)
	{
		var re = /^(3[01]|[1-9]|0[1-9]|[12]\d)\/(0[1-9]|[1-9]|1[012]|[1-12])\/\d{4}/;
		return (re.test(vs_date))
	}



	CForm.prototype.isHour = function(vs_hour)
	{
		if (!(/^\d{1,2}:\d{2,2}$/.test(vs_hour))) { return false; }
		var a = vs_hour.split(":");
		a[0] = Number(a[0]);
		a[1] = Number(a[1]);
		return(a[0] >= 0 && a[0] <= 23 && a[1] >= 0 && a[1] <= 59);
	}



	CForm.prototype.isNumber = function(vs_value)
	{
		var re = /^[0-9]+$/;
		return (re.test(vs_value));
	}



	CForm.prototype.isNumberOrDots = function(vs_value)
	{
		vs_value = vs_value.replace(/\./g, '');
		var re = /^[0-9]+$/;		
		return (re.test(vs_value));
	}


	CForm.prototype.trimField = function(vu_field)
	{
		vu_field.value = vu_field.value.trim();
	}



	CForm.prototype.trimInput = function(vu_form, vs_input)
	{
		vu_form.elements[vs_input].value = vu_form.elements[vs_input].value.trim();
		return(vu_form.elements[vs_input]);
	}



	CForm.prototype.onKeyDownNumber = function(e)
	{
		if (document.all) 	var li_code = window.event.keyCode;
		else		 		var li_code = e.which;
		return (li_code == 13 || li_code == 16 || li_code == 35 || li_code == 36 || li_code == 9 || li_code == 8 || li_code == 46 || (li_code >= 37 && li_code <= 40) || (li_code >= 96 && li_code <= 105) || (li_code >= 48 && li_code <= 57));
	}



	CForm.prototype.onKeyDownNumberDot = function(e)
	{
		if (document.all) 	var li_code = window.event.keyCode;
		else		 		var li_code = e.which;
		return (li_code == 190 || li_code == 110 || li_code == 13 || li_code == 16 || li_code == 35 || li_code == 36 || li_code == 9 || li_code == 8 || li_code == 46 || (li_code >= 37 && li_code <= 40) || (li_code >= 96 && li_code <= 105) || (li_code >= 48 && li_code <= 57));
	}



	CForm.prototype.onlyNumbers = function(vu_field, vb_dot)
	{
		var ls_value = '';
		var lb_change = false;
		for (var i=0, n = vu_field.value.length; i < n; i++)
		{
			var ls_char = vu_field.value.substr(i, 1);
			if (ls_char == '.' && vb_dot) ls_value += ls_char;
			else if (this.isNumber(ls_char)) ls_value += ls_char;			
			else lb_change = true;
		}
		if (lb_change) vu_field.value = ls_value;
	}
	


	CForm.prototype.formatDottedCurrency = function(vs_value)
	{
		vs_value = vs_value.replace(/\./g, '');
		for (var i = 0, n = vs_value.length, ls_value = ''; i < n; i++) ls_value = vs_value.substr(n - i - 1, 1) + ((((i % 3) == 0) && (i != 0))? '.' : '') + ls_value;
		return(ls_value);
	}



	CForm.prototype.checkExtensionJPG = function(vs_value)
	{
		var re = /\.jpg$/i;
		return(re.test(vs_value));
	}



	CForm.prototype.selectClear = function(vu_select, vi_first)
	{
		if (vu_select.length > 0)
		{
			for (var i = vi_first; i < vu_select.options.length; i++)
			{
				vu_select.options[i].text = '';
				vu_select.options[i].value = '';
				vu_select.options[i] = null;
			}

			vu_select.options.length = vi_first;
			vu_select.selectedIndex = 0;
		}
	}



	CForm.prototype.selectFill = function(vu_select, vu_array, vs_selected, vi_first)
	{
		var li_row = vi_first;
		var li_sel = -1;
		for (var i = 0; i < vu_array.length; i++)
		{
			if (vs_selected == vu_array[i][0]) li_sel = li_row;
			vu_select.options[li_row] = new Option(vu_array[i][1], vu_array[i][0], false, false);
			li_row++;
		}

		if (vu_select.length > 0) vu_select.selectedIndex = (li_sel == -1)? 0 : li_sel;
	}



	CForm.prototype.msgError = function(vu_field, vs_message)
	{
		alert(vs_message);
		vu_field.focus();
		return false;
	}



	var Form = new CForm();
