/**
 * function for fee calculator
 */
jQuery(document).ready(function($) {
/*  $('#type_select').change(function() {
      send();
  });
  $('#turnover_select').change(function() {
      send();
  });
*/
  $('#submit_button').click(function() {
      send();
  });

function send() {
	//var email_pattern = new RegExp('/^([0-9a-zA-Z]+([_.-]?[0-9a-zA-Z]+)*@[0-9a-zA-Z]+[0-9,a-z,A-Z,.,-]*(.){1}[a-zA-Z]{2,4})+$/');
	var phone_pattern = new RegExp('^([0-9 ]{10,})$');
	var name_pattern = new RegExp('^([a-zA-Z -]{3,})$');

	//console.log($('#phone').val());
	if (  $('#phone').val() != ''  &&  $('#name').val() != ''  ) {
		if ( ! phone_pattern.test( $('#phone').val() ) ) {
			alert( 'Please enter a 10/11 digit phone number' );
			return false;
		}
		if ( ! name_pattern.test( $('#name').val() ) ) {
			alert( 'Please enter a contact name' );
			return false;
		}
		/*if ( ! email_pattern.test( $('#phone').val() ) ) {
			alert( 'Invalid email address' );
			return false;
		}
		*/

    	if ( $('#type_select').val() != 0 && $('#turnover_select').val() != 0 ) {
        	//alert($('#type_select').val() + $('#turnover_select').val() + $('#contact').val() );
        	$.ajax({
           	 type: 'POST',
           	 url:'/wp-content/themes/ColdStone/fee.php',
           	 dataType:'json',
           	 data: {
           	     type: $('#type_select').val()
           	    ,turnover: $('#turnover_select').val()
           	    //,email: $('#email').val()
           	    ,phone: $('#phone').val()
           	    ,name: $('#name').val()
           	 },
           	 success:function(data) {
           	     $('#answer').html('<h3>Our standard fee is &pound;' + data.fee + '</h3><span style="font-size:10px;">The quote provided is an indication of the likely fee. The actual fee may differ based on personal circumstances.</span>');
           	 }
        	});
    	}
    }
    else {
    	alert('Please enter your contact details');
    	return false;
    }
}
});

