var objValid = new Validate();

function ValidateForm()
{
	if(!objValid.IsValid())
	{
		alert(objValid.message);
		return false;		
	}
	return true;
}

function Validate()
{
	this.arrItems = new Array();
	this.message = "";
	
	this.Add = function(idControl,validateType,caption,correctValue,regex)
	{		
		this.arrItems.push(new Array(idControl,validateType,caption,correctValue,regex));
	}
	
	this.MarkControl = function(obj)
	{
		obj.className = "txterr";
		obj.onclick = function(){this.className = "txt";};
	}
	
	this.IsValid = function()
	{
		
		for(var i=0; i < this.arrItems.length; i++)
		{
			var obj = document.getElementById(this.arrItems[i][0]);
			
			if(this.arrItems[i][1] == "float0plusORempty")
			{
				var t = obj.value.replace(/,/g,".");
				
				if (t.length > 0 && (t.match(/^-?\d+(\.\d+)?$/) == null || t < 0))
				{
					this.message = language.Get("key5")+' "' + this.arrItems[i][2] + '" '+language.Get("key6");
					if(this.arrItems[i][3]!= null && this.arrItems[i][3].length > 0)
					{
						this.message += language.Get("key6a") + ' ' + this.arrItems[i][3]
					}	
					this.MarkControl(obj);
					return false;
				}
			}			
			else if(this.arrItems[i][1] == "floatplus")
			{
				var t = obj.value.replace(/,/g,".");
				
				if (t.length == 0 || t.match(/^-?\d+(\.\d+)?$/) == null || t <= 0)
				{
					this.message = language.Get("key5")+' "' + this.arrItems[i][2] + '" '+language.Get("key6");
					if(this.arrItems[i][3]!= null && this.arrItems[i][3].length > 0)
					{
						this.message += language.Get("key6a") + ' ' + this.arrItems[i][3]
					}
					this.MarkControl(obj);
					return false;
				}
			}
			else if(this.arrItems[i][1] == "float0plus")
			{
				var t = obj.value.replace(/,/g,".");
				
				if (t.length == 0 || t.match(/^-?\d+(\.\d+)?$/) == null || t < 0)
				{
					if(this.arrItems[i][2]!= null && this.arrItems[i][2].length > 0)
					{
						this.message = language.Get("key5")+' "' + this.arrItems[i][2] + '" '+language.Get("key6");
					}
					else
					{
						this.message = language.Get("key5")+' '+language.Get("key6");
					}
					
					if(this.arrItems[i][3]!= null && this.arrItems[i][3].length > 0)
					{
						this.message += language.Get("key6a") + ' ' + this.arrItems[i][3]
					}
					this.MarkControl(obj);
					return false;
				}
			}
			else if(this.arrItems[i][1] == "intplus")
			{
				var t = obj.value;
				
				if (t.length == 0 || t.match(/^\d+$/) == null || t <= 0)
				{
					this.message = language.Get("key5")+' "' + this.arrItems[i][2] + '" '+language.Get("key6");
					if(this.arrItems[i][3]!= null && this.arrItems[i][3].length > 0)
					{
						this.message += language.Get("key6a") + ' ' + this.arrItems[i][3]
					}
					this.MarkControl(obj);
					return false;
				}
			}
			else if(this.arrItems[i][1] == "int0plus")
			{
				var t = obj.value;
				
				if (t.length == 0 || t.match(/^\d+$/) == null || t < 0)
				{
					this.message = language.Get("key5")+' "' + this.arrItems[i][2] + '" '+language.Get("key6");					
					if(this.arrItems[i][3]!= null && this.arrItems[i][3].length > 0)
					{
						this.message += language.Get("key6a") + ' ' + this.arrItems[i][3]
					}
					this.MarkControl(obj);
					return false;
				}
			}			
			else if(this.arrItems[i][1] == "text")
			{
				var t = obj.value;
				
				if (t.length == 0 || t.replace(/ /g,"")=='')
				{
					this.message = language.Get("key7")+' "' + this.arrItems[i][2] + '" '+language.Get("key8");
					this.MarkControl(obj);
					return false;
				}
			}
			else if(this.arrItems[i][1] == "email")
			{
				var t = obj.value;
				
				if (t.length == 0 || t.match(/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/) == null)
				{
					this.message = language.Get("key9")+' "' + this.arrItems[i][2] + '" '+language.Get("key10");
					this.MarkControl(obj);
					return false;
				}
			}	
			else if(this.arrItems[i][1] == "regex")
			{
				var t = obj.value;//alert(this.arrItems[i][4]);
				
				if (t.length == 0 || t.match(this.arrItems[i][4]) == null)
				{
					this.message = language.Get("key11")+' "' + this.arrItems[i][2] + '" '+language.Get("key6");
					if(this.arrItems[i][3]!= null && this.arrItems[i][3].length > 0)
					{
						this.message += language.Get("key6a") + ' ' + this.arrItems[i][3]
					}
					this.MarkControl(obj);
					return false;
				}
			}				
		}
				
		return true;
	}
}