
var xPhone = new Class({
	
	initialize: function(id){
		this.id = id;
		
		this.a = $(this.id + "1");
		this.b = $(this.id + "2");
		this.c = $(this.id + "3");

		
		this.a.addEvent('keyup', this.aChange.bind(this));
		this.a.addEvent('focus',function(){this.a.toggleClass('fieldfocus');}.bind(this));	
		this.a.addEvent('blur',function(){this.a.toggleClass('fieldfocus');}.bind(this));
		
		this.b.addEvent('keyup', this.bChange.bind(this));
		this.b.addEvent('focus',function(){this.b.toggleClass('fieldfocus');}.bind(this));	
		this.b.addEvent('blur',function(){this.b.toggleClass('fieldfocus');}.bind(this));
		
		//this.c.addEvent('keyup', this.cChange.bind(this));
		this.c.addEvent('focus',function(){this.c.toggleClass('fieldfocus');}.bind(this));	
		this.c.addEvent('blur',function(){this.c.toggleClass('fieldfocus');}.bind(this));
		
			
		
	},
	
	aChange:function() {
		if(this.a.value.length == 3)
			this.b.focus();
	},
	bChange:function() {
		if(this.b.value.length == 3)
			this.c.focus();
	}



});


var xField = new Class({
	
	initialize: function(id){
		this.xfield = true;
		this.id = id;
		this.obj = $(id);
		this.showHide();
		
		this.obj.addEvent('change', this.showHide.bind(this));
		
	},

	showHide:function (){
		for(x=0; x<this.obj.options.length;x++) {
			
			child = $(this.id + '-' + this.removeSpaces(this.obj.options[x].text));
			
			if (child) {
				if(x == this.obj.selectedIndex) {
					child.setStyle('display','');
					
				}else{
					child.setStyle('display','none');
				}
			}
		}
	},
	
	removeSpaces: function (string) {
		var tstring = "";
		string = '' + string;
		splitstring = string.split(" ");
		for(i = 0; i < splitstring.length; i++)
		tstring += splitstring[i];
		return tstring;
	}

});
	
	
//
// Load the functions we need immediately.
//
window.onDomReady(function() {
    
        
	var NTSDom = new novatexDOM();
	
	// form focus on all fields
	var fields = $$('.field');

	$A(fields).each(function(el){
		if(el.tagName != 'SELECT') {
			el.onfocus = function() {
				this.toggleClass('fieldfocus');
				//console.log('focus: %o',el);
			};
			el.onblur = function() {
				this.toggleClass('fieldfocus');
				//console.log('onblur: %o',el);
			};
		}
	});


	// disable submit button after it is pressed
	form = $("nts-form");
	
	if(form) {
		
		form.onsubmit = function(){
		 	if(document.getElementById('submit').value=='Submit'){
			$('submit').value = "Submitting.. Please wait";
		    $('submit').disabled = true;

		 	}else if(document.getElementById('submit').value=='Continue'){
			$('submit').value = "Submitting.. Please wait";
		    $('submit').disabled = true;
		    
			}else if(document.getElementById('bs_submit').value=='Sign Up'){
			$('bs_submit').value = "Signing Up.. Please wait";
		    $('bs_submit').disabled = true;

			}else if(document.getElementById('msubmit').value=='Print Form Preview'){
			$('msubmit').value = "Submitting.. Please wait";
		    $('msubmit').disabled = true;

			}
			else{ 
			$('submit').value = "Presentación.. Por favor, espere";
		    $('submit').disabled = true;
			}
			return true;
		};
	}
				

});
