var CheckPostalCode = Class.create();
Object.extend(CheckPostalCode.prototype, TextValidator.prototype);
Object.extend(CheckPostalCode.prototype,{
	
	initialize:function(input, select_field, select_value, validation_options){
		this.ignore=false;
		this.input = input;
		this.select_field = select_field;
		this.select_value = select_value;
		this.codes = validation_options.codes; // Array;
		this.without = false;
		if(validation_options.without){
			this.without = true;
		}
		//this.inputs = new Array();
		this.options = {
		    highlightId:null,
			noValidColor:'#EE5f19',
			validColor:'#000000'
		};
		this.valid = true;
		this.autoHighlight = true;
		this.errorCode=2;
		/*for(var i=0; i<arguments.length; i++){
			this.inputs.push(arguments[i]);
		}*/
	},
	cancel:function(){
		this.input.cancel();
		this.select_field.cancel();
	
	},
	highlightOn: function(){
		if (this.valid) {
			this.input.highlightOn();
			this.select_field.highlightOn();
			this.valid = false;  
		}
	},
	highlightOff: function(){
		if (!this.valid) {
			this.input.highlightOff();
			this.select_field.highlightOff();
			this.valid = true;	
		}
		
	},
	checkValid:function(){

		if(this.ignore) return true;
		var val=true;
		var select_val = this.select_field.getValue();
		var input_val = this.input.getValue();
		if(!this.without){
			if(this.codes.include(input_val.substr(0,2)) && select_val == this.select_value){
				val = false;										  
			}
		}else{
			if(!this.codes.include(input_val.substr(0,2)) && select_val == this.select_value){
				val = false;										  
			}
		}
		
		return val;
	},

	validate:function(){
		if(this.ignore) return true;
		var val=this.checkValid();
		return val;
		
	}
});						
