function ApplyMasks()
{	
	var objs = document.getElementsByTagName("input"),
		obj;
		
	var	i;
	
	if( objs != null )
	{
		for( i = 0; i < objs.length; i++ )
		{
			obj = objs[i];
			
			if( obj.type == null || obj.type == "text" )
			{
				switch( GetTypeMask(obj) )
				{
					case "data":	SetDataMask(obj);
									break;
									
					case "cnpj":	SetCnpjMask(obj);
									break;
									
					case "cpf":		SetCpfMask(obj);
									break;
									
					case "tel":		SetTelMask(obj);
									break;
									
					case "cep":		SetCepMask(obj);
									break;
				}
			}
		}
	}
}

function SetDataMask()
{
	var obj = arguments[0];
	
	obj.onkeypress = function(e)
	{
		if( !isWhiteKey(e) )
		{
			var	newValue = this.value;
			
			if( Number(newValue.charAt(0)) > 3 )
			{
				newValue = "0" + newValue;
			}
			
			if( Number(newValue.substr(0,2)) > 31 )
			{
				newValue = Format("{0}{1}/{2}","0",newValue.charAt(0),newValue.charAt(1));	
			}
			
			if( Number(newValue.charAt(3)) > 1 )
			{
				newValue = Format("{0}{1}{2}",newValue.substr(0,3),"0",newValue.charAt(3));
			}
			
			if( newValue.length == 2 || newValue.length == 5 )
			{
				this.value = newValue + "/";
			}
		}
	}
	
	obj.onkeydown = function(e)
	{
		return BreakWord(e);
	}
}

function SetCnpjMask()
{	
	var obj = arguments[0];
		
	obj.onkeypress = function(e)
	{
		if( !isWhiteKey(e) )
		{				
			if( this.value.length == 2 || this.value.length == 6 )
			{
				this.value += ".";
			}
				
			if( this.value.length == 10 )
			{
				this.value += "/"; 
			}
				
			if( this.value.length == 15 )
			{
				this.value += "-"; 
			}
		}
	}
	
	obj.onkeydown = function(e)
	{
		return BreakWord(e);
	}
}

function SetCpfMask()
{
	var obj = arguments[0];
		
	obj.onkeypress = function(e)
	{
		if( !isWhiteKey(e) )
		{
			if( this.value.length == 3 || this.value.length == 7 )
			{
				this.value += ".";
			}
				
			if( this.value.length == 11 )
			{
				this.value += "-"; 
			}	
		}
	}
	
	obj.onkeydown = function(e)
	{
		return BreakWord(e);
	}
}

function SetTelMask()
{
	var obj = arguments[0];
	
	obj.onkeypress = function(e)
	{
		if( !isWhiteKey(e) )
		{
			if( this.value.length == 1 && this.value.charAt(0) != "(" )
			{
				this.value = "(" + this.value;
			}
			
			if( this.value.length == 3 )
			{
				this.value += ")";
			}
			
			if( this.value.length == 8 )
			{
				this.value += "-";
			}
		}
	}
	
	obj.onkeydown = function(e)
	{
		return BreakWord(e);
	}
}

function SetCepMask()
{
	var obj = arguments[0];
	
	obj.onkeypress = function(e)
	{
		if( !isWhiteKey(e) )
		{
			if( this.value.length == 2 )
			{
				this.value += ".";
			}
			
			if( this.value.length == 6 )
			{
				this.value += "-";
			}
		}
	}
	
	obj.onkeydown = function(e)
	{
		return BreakWord(e);
	}
}