﻿$(document).ready( function(){
            $('#uiSendRequest').click( function(){
                $('#uiRFFirstName').trigger('blur');
                $('#uiRFLastName').trigger('blur');
                $('#uiPhone1').trigger('blur');
                $('#uiPhone2').trigger('blur');
                $('#uiPhone3').trigger('blur');
                $('#uiRFEmail').trigger('blur');

		if ( ($('.fl-error').length > 0) || ( $('.phone-error').length > 0 ) || ( $('.email-error').length > 0 ) ){
			return false;
		}
            });
            
            $('#uiRFFirstName').blur( function(){
                if ( $(this).val().length == 0 ){
                    $(this).parent().parent().find('.requestText').css('color', '#f20000');
                    $('#rfvFirstName').css('color', '#f20000');
                    $(this).addClass('invalid');
                    if( $('.fl-error').length == 0 ){
                        $('#rfvLastName').after('<p class="fl-error" style="color: #f20000; font-weight: bold; clear: both;">This field is required. Please enter a value.</p>');
                    }
                } else {
                    $(this).removeClass('invalid');
                    $('#rfvFirstName').css('color', '#FFF');
                }
                
                if ( ($('#uiRFFirstName').val().length > 0) && ($('#uiRFLastName').val().length > 0) ){
                    $(this).parent().parent().find('.requestText').css('color', '#FFF');
                    
                    $('.fl-error').remove(); 
                }
            });
            
            $('#uiRFLastName').blur( function(){
                if ( $(this).val().length == 0 ){
                    $(this).parent().parent().find('.requestText').css('color', '#f20000');
                    $(this).addClass('invalid');
                    
                    $('#rfvLastName').css('color', '#f20000');
                    
                    if( $('.fl-error').length == 0 ){
                        $('#rfvLastName').after('<p class="fl-error" style="color: #f20000; font-weight: bold; clear: both;">This field is required. Please enter a value.</p>');
                    }
                } else {
                    $(this).removeClass('invalid');
                    $('#rfvLastName').css('color', '#FFF');
                }
                
                if ( ($('#uiRFFirstName').val().length > 0) && ($('#uiRFLastName').val().length > 0) ){
                    $(this).parent().parent().find('.requestText').css('color', '#FFF');
                    $('.fl-error').remove(); 
                }
            });
            
            
            $('#uiPhone1').blur(function(){
                if ( $(this).val().length != 3 ){
                    	$(this).parent().find('.requestText').css('color', '#f20000');
		    	$(this).addClass('invalid');
			if( $('.phone-error').length == 0 ){
                        	$('#uiPhone3').after('<p class="phone-error" style="color: #f20000; font-weight: bold;">This field is required. Please enter a value.</p>');
			} 
                } else {
			$(this).removeClass('invalid');
		}
                if ( ($('#uiPhone1').val().length == 3) && ($('#uiPhone2').val().length == 3) && ($('#uiPhone3').val().length == 4) ){
			$(this).parent().find('.requestText').css('color', '#FFF');
			$('.phone-error').remove(); 
                }
            });
            
            $('#uiPhone2').blur(function(){
                if ( $(this).val().length != 3 ){
			$(this).parent().find('.requestText').css('color', '#f20000');
			$(this).addClass('invalid');
			if( $('.phone-error').length == 0 ){
                        	$('#uiPhone3').after('<p class="phone-error" style="color: #f20000; font-weight: bold;">This field is required. Please enter a value.</p>');
			} 
                } else {
			$(this).removeClass('invalid');
		}
                if ( ($('#uiPhone1').val().length == 3) && ($('#uiPhone2').val().length == 3) && ($('#uiPhone3').val().length == 4) ){
                    $(this).parent().find('.requestText').css('color', '#FFF');
                    $('.phone-error').remove();
                }
            });
            
            $('#uiPhone3').blur(function(){
                if ( $(this).val().length != 4 ){
                    	$(this).parent().find('.requestText').css('color', '#f20000');
			$(this).addClass('invalid');
                    	if( $('.phone-error').length == 0 ){
                        	$('#uiPhone3').after('<p class="phone-error" style="color: #f20000; font-weight: bold;">This field is required. Please enter a value.</p>');
                    	}
                } else {
			$(this).removeClass('invalid');
		}
                if ( ($('#uiPhone1').val().length == 3) && ($('#uiPhone2').val().length == 3) && ($('#uiPhone3').val().length == 4) ){
                    $(this).parent().find('.requestText').css('color', '#FFF');
                    $('.phone-error').remove(); 
                }
            });
            
            $('#uiRFEmail').blur(function(){
                var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
                
                if( re.test( $(this).val() ) == false ){
                    $(this).parent().find('.requestText').css('color', '#f20000');
                    $(this).addClass('invalid');
                    if( $('.email-error').length == 0 ){
                        $('#RegularExpressionValidator2').after('<p class="email-error" style="color: #f20000; font-weight: bold;">This field is required. Please enter a valid value.</p>');
                    }
                } else {
                    $(this).parent().find('.requestText').css('color', '#FFF');
                    $(this).removeClass('invalid');
                    $('.email-error').remove();
                }
                
            });
        });
            

