var Util = {
	isNumeric: function(el){
		var validChars = "1234567890";
		var isNumber = true;
		var elChar;
		for( i = 0; i < el.length && isNumber == true; i++){
			elChar = el.charAt(i);
			if(validChars.indexOf(elChar) == -1) isNumber = false;
		}
		return isNumber;
	}
}
function LnpCheck() {
	var npacode = "";
	var nxxcode = "";
	var number = "";
	var numtoval = "";
	this.init = function(){
		this.npacode = $('lnp-check-npacode').value;
		this.nxxcode = $('lnp-check-nxxcode').value;
		this.number = $('lnp-check-number').value;
	}
	this.validate = function(){
		var valid = true;
		if(this.npacode.length < 3 || !Util.isNumeric(this.npacode) ){
			this.borderChange($('lnp-check-npacode'),"#FF0000");
			$('lnp-check-npacode').focus();
			valid = false;
		}
		if(this.nxxcode.length < 3 || !Util.isNumeric(this.nxxcode) ){
			this.borderChange($('lnp-check-nxxcode'),"#FF0000");
			if(valid) 
			{
				$('lnp-check-nxxcode').focus();
				valid = false;
			}
		}
		if(this.number.length < 4 || !Util.isNumeric(this.number) ){
			this.borderChange($('lnp-check-number'),"#FF0000");
			if(valid)
			{
				$('lnp-check-number').focus();
				valid = false;
			}
		}
		return valid;
	}
	this.valid = function(el,len){
		if(el.value.length == len && Util.isNumeric(el.value)){
			return true;
		} else {
			return false;
		}
	}
	this.borderReset = function(){
		this.borderChange($('lnp-check-npacode'));
		this.borderChange($('lnp-check-nxxcode'));
		this.borderChange($('lnp-check-number'));
	}
	this.borderChange = function(el,color){
		if(color == null) color = "";
		el.style.borderColor = color;
	}
	this.doSubmit = function(){
		$('lnp-check-numtoval').value = this.npacode + this.nxxcode + this.number;
		$('lnp-check-form').submit();
	}
	this.doCheck = function(){
		this.init();
		this.borderReset();
		if(!this.validate())
		{ 
			return false; 
		} else {
			this.doSubmit();
			return false;
		}
	}
	this.init();
}