// This script uses the Mootools Fx.Slide function to show or hide various parts of the RI/RA Request forms depending upon the selections made.
window.addEvent('domready', function(){
	new InputMask.Date($('customer_DOP'), {
	  onError: function(element, key){
		  element.highlight('#f88');
		}
	});
	new InputMask.Phone($('contact_phone'), {
		onError: function(element, key){
		  element.highlight('#f88');
	  }
	});
	if( $('contact_fax') ) { 
	  new InputMask.Phone($('contact_fax'), {
		  onError: function(element, key){
			  element.highlight('#f88');
		  }
	  }); 
	}
	if( $('phone') ) {
	  new InputMask.Phone($('phone'), {
		  onError: function(element, key){
			  element.highlight('#f88');
		  }
	  });
	}
	if( $('fax') ) { 
	  new InputMask.Phone($('fax'), {
		  onError: function(element, key){
			  element.highlight('#f88');
		  }
	  }); 
	}

 	// Add some Fx.Slide classes to show/hide parts of the RA form as needed.
  if($('credit_row')) {
	  var creditSlide = new Fx.Slide('credit_row').hide();
	  $('request_type').addEvent('change', function(e){
		  e.stop();
		  if(this.value == 'credit'){
		    creditSlide.slideIn();
			}
		  else {
		    creditSlide.slideOut();
			}
	  });
	}
	
	// Create Fx.Slide for form sections as needed.  Some exist only in dealer or customer so check before trying
  if($('customer_row1')) { var custSlide1 = new Fx.Slide('customer_row1'); }
	if($('customer_row2')) { var custSlide2 = new Fx.Slide('customer_row2'); }
	if($('upload-receipt')) { var custSlide3 = new Fx.Slide('upload-receipt'); }
	if($('fax-receipt')) { var custSlide4 = new Fx.Slide('fax-receipt').hide(); }
	if($('preapproval')) { var preapproveSlide = new Fx.Slide('preapproval').hide(); }
	
	// If status exists, this is the dealer form, set appropriate events for dealer form below
	if ($('status')) {
	  $('inwarranty').addEvent('click', function(e){
		  if ($('status').value == 'storestock') {
		    custSlide1.slideOut();
		    custSlide2.slideOut();
		    custSlide3.slideOut();
		    custSlide4.slideOut();
			  preapproveSlide.slideOut();
		  }
		  else {
		    custSlide1.slideIn();
		    custSlide2.slideIn();
        if($('upload-radio').checked) {
		      custSlide3.slideIn();
					custSlide4.slideOut();
				}
			  else {
          custSlide3.slideOut();
				  custSlide4.slideIn();
				}
			  preapproveSlide.slideOut();
		  }
		});
	
	  $('nowarranty').addEvent('click', function(e){
		  if ($('status').value == 'storestock') {
		    custSlide1.slideOut();
		    custSlide2.slideOut();
		    custSlide3.slideOut();
		    custSlide4.slideOut();
			  preapproveSlide.slideIn();
		  }
		  else {
		    custSlide1.slideIn();
		    custSlide2.slideOut();
		    custSlide3.slideOut();
		    custSlide4.slideOut();
			  preapproveSlide.slideIn();
		  }
	  });
	
	  $('status').addEvent('change', function(e){
		  if ($('status').value == 'storestock') {
		    custSlide1.slideOut();
		    custSlide2.slideOut();
		    custSlide3.slideOut();
		    custSlide4.slideOut();
		  }
		  else if ($('inwarranty').checked){
			  custSlide1.slideIn();
		    custSlide2.slideIn();
        if($('upload-radio').checked) {
		      custSlide3.slideIn();
					custSlide4.slideOut();
				}
			  else {
          custSlide3.slideOut();
				  custSlide4.slideIn();
				}			  
				preapproveSlide.slideOut();
		  }
		  else {
		    custSlide1.slideIn();
		    custSlide2.slideOut();
		    custSlide3.slideOut();
		    custSlide4.slideOut();
			  preapproveSlide.slideIn();
		  } 
	  });
	}
	// Set customer RI form slide events here
	else {
	  $('inwarranty').addEvent('click', function(e){
		  custSlide2.slideIn();
        if($('upload-radio').checked) {
		      custSlide3.slideIn();
					custSlide4.slideOut();
				}
			  else {
          custSlide3.slideOut();
				  custSlide4.slideIn();
				}			  
			preapproveSlide.slideOut();
		});  
	  $('nowarranty').addEvent('click', function(e){
		  custSlide2.slideOut();
		  custSlide3.slideOut();
		  custSlide4.slideOut();
			preapproveSlide.slideIn();
		});
	}

  // Receipt fax/upload toggle events	
	$('upload-radio').addEvent('click', function(e){
		custSlide3.slideIn();
	  custSlide4.slideOut();
	});  
	$('fax-radio').addEvent('click', function(e){
	  custSlide3.slideOut();
	  custSlide4.slideIn();
	});  		
});
