

$(function() {

  // load specials onto home page and sub page side columns
  $('#load-special-home').load('/specials/ .special-offer div',function () {
    $('#load-special-home div:gt(0)').remove();  
  });
  
  $('#load-special-sub').load('/specials/ .special-offer',function () {
    $('#load-special-sub .special-offer:gt(0)').remove();  
  });
  
  
  // load teritary page content into services pages
  
  $('.btn-view-programs,.btn-view-maintenance,.btn-view-repairs').addClass('slide-toggle-closed');
  
  $('#programs-content').load('/programs/ .singlePostCS',function () {
    $(this).find('.singlePostCS').hide();
  });
  
  $('.btn-view-programs').click(function() {
    $(this).toggleClass('slide-toggled');
    $('#programs-content').find('.singlePostCS').slideToggle('normal');
  });
  
  $('#maintenance-content').load('/maintenance/ .singlePostCS',function () {
    $(this).find('.singlePostCS').hide();
  });
  
  $('.btn-view-maintenance').click(function() {
    $(this).toggleClass('slide-toggled');
    $('#maintenance-content').find('.singlePostCS').slideToggle('normal');
  });
  
  $('#repairs-content').load('/repairs/ .singlePostCS',function () {
    $(this).find('.singlePostCS').hide();
  });
  
  $('.btn-view-repairs').click(function() {
    $(this).toggleClass('slide-toggled');
    $('#repairs-content').find('.singlePostCS').slideToggle('normal');
  });
  
  
  /* launch modal from link click */
  $('.directions').click(function(event) {
    event.preventDefault();  
    $("#modal-form").modal({
      opacity:80
    });
  });
     
  //if submit button is clicked
  $('#submit').click(function () {        
       
    //Get the data from all the fields
    var number  = $('input[name=number]');
    var carrier = $('select[name=carrier]');

    //Simple validation to make sure user entered something
    //If error found, add hightlight class to the text field
    if (number.val()=='') {
      number.addClass('highlight');
      return false;
    } else number.removeClass('highlight');
     
    if (carrier.val()=='Select Carrier') {
      carrier.addClass('highlight');
      return false;
    } else carrier.removeClass('highlight');
     
    //organize the data properly
    //var data = 'number=4806352650&carrier=txt.att.net';
    var data = 'number=' + number.val() + '&carrier=' + carrier.val();
     
    //disabled all the text fields
    $('.text').attr('disabled','true');
     
    //show the loading sign
    $('.loading').show();
    
    //start the ajax
    $.ajax({
      //this is the php file that processes the data and send mail
      url: "http://masterwerks.com/wp-content/themes/CircloSquero/modal/sms.php", 
       
      //GET method is used
      type: "GET",

      //pass the data         
      data: data,
   
      //Do not cache the page
      cache: false,
       
      //success
      success: function (html) {              
          //if process.php returned 1/true (send mail success)
         // if (html==1) {                  
              //hide the form
        $('#directions-form').hide();                 
        
        //show the success message
        $('#success_page').hide().append('<h3>Email Sent Successfully.</h3> <p>Check your phone for directions to our location.</p>' ).fadeIn('slow');
               
               
          //if process.php returned 0/false (send mail failed)
          //} else alert('Sorry, unexpected error. Please try again later.');               
      }       
    });
     
    //cancel the submit button default behaviours
    return false;
  }); 
  
  
   
});





