$(document).ready(function(){
   $(".cta").on('click',function(){
      var url = $(location).attr("href");
      var id = $(this).html();
      _gaq.push(["_trackEvent","cta-clicks",id,url]);
   });
   $('.alert').hide();
   $('ul.sub1').hide();
   $('ul.sub2').hide();
   $(".message").hide();
   $("#slider").easySlider({
       auto: true,
       continuous: true,
       controlsShow: false,
       pause: 4000
   });
   $('a#sub1').bind('click',function(){
    $('ul.sub2').slideUp("fast");
    $('ul.sub1').slideToggle("slow");
   });
   $('a#sub2').bind('click',function(){
    $('ul.sub1').slideUp("fast");
    $('ul.sub2').slideToggle("slow");
   });
   $(".bottom").hide().delay(1000).slideDown(1000);
   //form parsing below
   $("#review-click").on('click', function(e){
      e.preventDefault();
      var name = $("[name=rname]").val();
      var email = $("[name=remail]").val();
      var svcs = $("[name=rservice]").val();
      var comment = $("[name=rdesc]").val();
      //alert(name);
      if(name == '' || name == 'Enter Your Name'){
         $(".alert").html("<h3>Please Enter Your Name</h3>").slideDown("slow").delay(1000).slideUp("slow");
      }else if(email == '' || email == 'Enter Your Email@'){
         $(".alert").html("<h3>Please Enter Your Email</h3>").slideDown("slow").delay(1000).slideUp("slow");
      }else if(svcs == 'no'){
         $(".alert").html("<h3>Please Select Your Service</h3>").slideDown("slow").delay(1000).slideUp("slow");
      }else if(comment == '' || comment == 'Tell Us Here'){
         $(".alert").html("<h3>Please Enter Your Comment</h3>").slideDown("slow").delay(1000).slideUp("slow");
      }else{
         var dataString = $(".review-form").serialize();
         //alert(dataString);
         $.ajax({
            type: "POST",
            data: dataString,
            url: "php/get_reviews.php",
            success: function(){
               $(".alert").html("<h3>Thank You For Your Review</h3><p>We will review your comment as soon as possible</p>").slideDown("slow").delay(1000).slideUp("slow");
               $("[name=rname]").val("");
               $("[name=rdesc]").val("");
               $("[name=remail]").val("");
            }
         });
      }
   });
   $("#qquote-submit").on('click',function(e){
      e.preventDefault();
      //$(".message").fadeIn(500);
      //var dataString = $("form.qquote").serialize();
      var name = $(".qq-name").val();
      var email = $(".qq-email").val();
      var phone = $(".qq-phone").val();
      var zip = $(".qq-zip").val();
      if(name == "" || name == "Enter Your Name"){
         $(".alert").slideDown(1000).html("<h3>Please Enter Your Name.</h3>").delay(1000).slideUp(1000);
      }else if(email == "" || email == "Enter Your Email@"){
         $(".alert").slideDown(1000).html("<h3>Please Enter an Email</h3>").delay(1000).slideUp(1000);
      }else if(zip == "" || zip.length < 5 || zip == "Enter Your Zip Code"){
         $(".alert").slideDown(1000).html("<h3>Please Enter Your 5 digit Zip Code.</h3>").delay(1000).slideUp(1000);
      }else{
         var dataString = "name=" + name + "&email=" + email + "&phone=" + phone + "&zip=" + zip + "&serv=" + $("input[name=serv]:checked").val();
         //alert(dataString);
      $.ajax({      
         type: "POST",
         data: dataString,
         url: "../php/get_quote.php",
         success: function(html){
            $(".message").html(html).fadeIn(500);
            //$(".alert").slideDown(1000).html("<h3>Our Instant Quote Function is Still Under Construction,</h3><p>We apologise for the delay, but you will be contacted soon by one of our representatives</p>").delay(1000).slideUp(1000);
         }
      });
      }
   });
   $("#hourly-submit").on('click',function(e){
      e.preventDefault();
      var email = $(".qq-email").val();
      var vehicle = $(".qq-vehicle").val();
      if(email == "" || email == "Enter Your Email@"){
         $(".alert").slideDown(1000).html("<h3>Please Enter an Email</h3>").delay(1000).slideUp(1000);
      }else if(vehicle == '0'){
         $(".alert").slideDown(1000).html("<h3>Please Select A Vehicle from the List</h3>").delay(1000).slideUp(1000);
      }else{
         var dataString = "email=" + email + "&car=" + vehicle;
         //alert(dataString);
      $.ajax({      
         type: "POST",
         data: dataString,
         url: "../php/get_hourly.php",
         success: function(html){
            $(".message").html(html).fadeIn(500);
            //$(".alert").slideDown(1000).html("<h3>Our Instant Quote Function is Still Under Construction,</h3><p>We apologise for the delay, but you will be contacted soon by one of our representatives</p>").delay(1000).slideUp(1000);
         }
      });
      }
   });
   $("#m-close").on('click',function(e){
      e.preventDefault();
      $(".message").fadeOut(1000);
   });
   $("#fbtest").on('click',function(){
      alert("test");
   });
   $("#broch").on('click',function(e){
      e.preventDefault();
      $(this).attr("href","http://cnsexec.com/C&SExecutiveTransportationServicesBrochure.pdf");
      $(this).attr("target","_blank");
      window.open($(this).attr('href'));
      return false;
   });
   $("#reserve-site").on('click',function(e){
      e.preventDefault();
      $(".alert").slideDown(1000).html("<h3>We Are Currently Working on Our Resevation Site Area, Please Contact Us Directly for Any Questions</h3>").delay(1000).slideUp(1000);
   });
   $("#tell-us").on('click',function(e){
      e.preventDefault();
      var name = $(".te-name").val();
      var email = $(".te-email").val();
      var phone = $(".te-phone").val();
      var date = $(".te-date").val();
      var com = $(".te-desc").val();
      if(name == "" || name == "Enter Your Name"){
         $(".alert").slideDown(1000).html("<h3>Please Enter Your Name.</h3>").delay(1000).slideUp(1000);
      }else if((email == "" || email == "Enter Your Email@") && (phone == "" || phone == "Enter Your Phone#")){
         $(".alert").slideDown(1000).html("<h3>Please Enter Either a Phone or Email.</h3>").delay(1000).slideUp(1000);
      }else if((date == "" || date == "Event Date") && (com == "" || com == "Tell Us Here")){
         $(".alert").slideDown(1000).html("<h3>Did you forget your date or comment?</h3>").delay(1000).slideUp(1000);
      }else{
      var dataString = "name=" + name + "&email=" + email + "&phone=" + phone + "&date=" + date + "&desc=" + com;
         //alert(dataString);
      $.ajax({      
         type: "POST",
         data: dataString,
         url: "../php/tell_us.php",
         success: function(html){
            $(".alert").slideDown(1000).html(html).delay(1000).slideUp(1000);
            $(".te-name").val("");
            $(".te-email").val("");
            $(".te-phone").val("");
            $(".te-date").val("");
            $(".te-desc").val("");
         }
      });
      }
      //$(".alert").slideDown(1000).html("<h3>We Are Currently Working on this Function, Please Contact Us Directly for Any Questions</h3>").delay(1000).slideUp(1000);
   });
   $("#contact-us").on('click',function(e){
      e.preventDefault();
      var name = $(".cu-name").val();
      var email = $(".cu-email").val();
      var message = $(".cu-message").val();
      if((name == "" || name == "Enter Your Name") || (email == "" || email == "Enter Your Email@") || (message == "" || message == "Please leave your message here.")){
         $(".alert").slideDown(1000).html("<h3>All Fields Are Required, Thank You.</h3>").delay(1000).slideUp(1000);
      }else{
         var dataString = "name=" + name + "&email=" + email + "&message=" + message;
         //alert(dataString);
         $.ajax({      
            type: "POST",
            data: dataString,
            url: "../php/contact_us.php",
            success: function(html){
               $(".alert").slideDown(1000).html(html).delay(1000).slideUp(1000);
               $(".cu-name").val("");
               $(".cu-email").val("");
               $(".cu-message").val("");
            }
         });         
      }
   });
});

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-27284751-1']);
  _gaq.push(['_setDomainName', '.cnsexec.com']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
