$(document).ready(function(){
  // form ineraction
  $("#callerNumber, #name").focus(function () {
    if (this.value == this.defaultValue){ 
     this.value = '';
    }
    if(this.value != this.defaultValue){
     this.select();
    }
  });
  $("#callerNumber, #name").blur(function () {
    if (this.value == ''){ 
     this.value = this.defaultValue;
    }
  });
  
  //var keepPrivate = $('#keepPrivate').attr('checked');      
  $('#keepPrivate').click(function() {
    var keepPrivate = $('#keepPrivate').attr('checked');
    if (keepPrivate) {
      $('#showCallerNumber').attr("value", "0");
    } else {
      $('#showCallerNumber').attr("value", "1");
    }
  });
  
  $('.call-us, .our-services').click( function() {
    $('#VoiceBoxContainer').show();
  });
  $('#done').click( function() {
		$('#googleVoiceBox #messageBox').html('');
		$('#VoiceBoxContainer').hide();
	});
  
  
  //contact form stuff
  $(function() {
     $('#voiceBoxForm').submit(function() {
       var inputs = [];
       $(':input', this).each(function() {
         inputs.push(this.name + '=' + escape(this.value));
       });
       
       var postData = inputs.join('&');
       var url = 'voice-box.php';
       $.ajax({
         type: "POST",
         url: url,
         data: postData,
         success: function(data){
           var success = data.indexOf("Calling");
           if (success > 0) {
             $('#googleVoiceBox #messageBox').fadeOut('fast');
             $('#voiceBoxForm').fadeOut('slow', function() {
               $('#googleVoiceBox #messageBox').html(data);
             });
           } else {
             $('#googleVoiceBox #messageBox').html(data);
           }           
         }
       });
       return false;
     });
   });
});