var ValidationForm = function(){
		this.initialize.apply( this, arguments );
	}
ValidationForm.prototype = {
	
	initialize: function( objInput, defaultValue, tipo ){
		this.msgPadrao = 'Voce precisa preencher todos os campos obrigatorios';
		this.objInput = objInput;
		this.tipo = tipo;
		this.defaultValue = defaultValue;
	},
	
	erro: function( msg ){
		Aviso( msg );
	},
	
	notNull: function( msg ){
		if( this.objInput.style.display == 'none' || this.objInput.disabled ){
		return true;
		}
		
		if( ( this.objInput && this.objInput.value == '' || this.objInput.value == this.defaultValue ) ){
		this.erro( msg );
		return false;
	}
	
	return true;
	},
	
	cpf:function( msg ){
		if( this.objInput.style.display == 'none' ){
		return true;
	}
	
	var reCpf = /^([0-9]{3}\.){2}[0-9]{3}-[0-9]{2}$/;
		if (reCpf.test(this.objInput.value)) {
		return true;
		} else{
		this.erro( msg );
		return false;
		}
	},
	
	cnpj:function( msg ){
		if( this.objInput.style.display == 'none' ){
		return true;
		}
		
		var reCnpj = /\d{2}\.?\d{3}\.?\d{3}\/?\d{4}-?\d{2}/
		if (reCnpj.test(this.objInput.value)) {
		return true;
		} else{
		this.erro( msg );
		return false;
		}
	},
	
	cep:function( msg ){
		if( this.objInput.style.display == 'none' ){
		return true;
		}
		
		var reCep = /^[0-9]{5}-[0-9]{3}$/;
		if (reCep.test(this.objInput.value)) {
		return true;
		} else{
		this.erro( msg );
		return false;
		}
	},
	
	data: function( msg ){
		if( this.objInput.style.display == 'none' ){
		return true;
		}
		
		var reDate = /^((0?[1-9]|[12]\d)\/(0?[1-9]|1[0-2])|30\/(0?[13-9]|1[0-2])|31\/(0?[13578]|1[02]))\/(19|20)?\d{2}$/;
		if (reDate.test(this.objInput.value)) {
		return true;
		} else{
		this.erro( msg );
		return false;
		}
		},
		
		notEmpty: function( msg ){
		if( this.objInput.style.display == 'none' ){
		return true;
		}
		
		if( tinyMCE.getContent(this.objInput.id).toUpperCase() == '<P>&NBSP;</P>' || tinyMCE.getContent(this.objInput.id).toUpperCase() == '<BR>' || tinyMCE.getContent(this.objInput.id).toUpperCase() == '' || tinyMCE.getContent(this.objInput.id) == '' ){
		this.erro( msg );
		return false;
		}
		
		return true;
	},
	
	monetary: function( msg ){
		if( this.objInput.style.display == 'none' ){
		return true;
		}
		
		var er = /(\d)*([,.])\d{2}$/;
		
		if( this.objInput.value.search( er ) == -1 ){
		this.erro( msg );
		return false;
		}
		
		return true;
	},
	
	integer: function( msg ){
		if( this.objInput.style.display == 'none' ){
		return true;
		}
		
		var er = /^\d*$/;
		
		if( this.objInput.value.search( er ) == -1 || this.objInput.value == '' ){
		this.erro( msg );
		return false;
		}
		
		return true;
	},
	
	email: function( msg ){
		if( this.objInput.style.display == 'none' ){
		return true;
		}
		
		var er = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
		
		if( this.objInput.value.search( er ) == -1 || this.objInput.value == ''){
		this.erro( msg );
		return false;
		}
		
		return true;
	},
	
	ddd: function( msg ){
		if( this.objInput.style.display == 'none' ){
		return true;
		}
		
		var er = /^\d*$/;
		
		if( this.objInput.value.search( er ) == -1 || this.objInput.value == '' ){
		this.erro( msg );
		return false;
		}
		
		return true;
	},
	
	telefone:function( msg ){
		if( this.objInput.style.display == 'none' ){
		return true;
		}
		
		var er = /^[0-9]{4}-[0-9]{4}$/;
		
		if( this.objInput.value.search( er ) == -1 ){
		this.erro( msg );
		return false;
		}
		
		return true;
	},
	
	validar: function(){
		var s = this.tipo.split( ':' );
		
		var tipo = s[0];
		var msg = s[1] ? s[1] : this.msgPadrao;
		tipo = tipo.replace( ' ', '' );
		tipo = tipo.toLowerCase();
	switch( tipo ){
	
	case 'notnull':
		return this.notNull( msg );
	break;
	
	case 'data':
		return this.data( msg );
	break;
	
	case 'cep':
		return this.cep( msg );
	break;
	
	case 'cpf':
		return this.cpf( msg );
	break;
	
	case 'cnpj':
		return this.cnpj( msg );
	break;
	
	case 'notempty':
		return this.notEmpty( msg );
	break;
	
	case 'email':
		return this.email( msg );
	break;
	
	case 'ddd':
		return this.ddd( msg );
	break;
	
	case 'telefone':
		return this.telefone( msg );
	break;
	
	case 'integer':
		return this.integer( msg );
	break;
	
	case 'monetary':
		return this.monetary( msg );
	break;
	}
	
	return true;
	}
}