$(document).ready(
    function() {

	    $(".contact_link").click(function() {
		    $('body').css('overflow', 'hidden');
		    $("#dialog").dialog("open");
		    return false;
	    });

	    $('textarea').click(function() {
		    if (this.value == this.defaultValue) {
			    this.select();
		    }
	    });

	    $('textarea').keyup(function() {

		    if (!$.browser.msie) { // ie textarea has scrollbars by default so this
			      // only runs in other browsers.
			      if (this.clientHeight < this.scrollHeight) {
				      $(this).css("background-image",
				          "url(images/popups/form_text_area_bkg_ie.jpg)");
				      if ($.browser.mozilla) { // mozilla puts padding above scrollbar
					      // so we get rid of it here.
					      $(this).css("height", "212px");
					      $(this).css("padding-top", "0px");
				      }
			      } else {

				      $(this).css("background-image",
				          "url(images/popups/form_text_area_bkg.jpg)");
				      if ($.browser.mozilla) {
					      $(this).css("height", "205px");
					      $(this).css("padding-top", "7px");
				      }
			      }
		      }
	      });

	    // Hide the form error messages from view on page load.
	    $('.thanks').hide();
	    $('.error').hide();

	    $("#dialog").dialog( {
	      autoOpen : false,
	      width : 494,
	      height : 565,
	      modal : true,
	      show : {
	        effect : 'fade',
	        duration : 500
	      },
	      hide : {
	        effect : 'clip',
	        duration : 250
	      },
	      title : 'Hippie Geek Franchise Information Request',
	      resizable : false,
	      buttons : {
	        "Send Message" : function() {
		        $("label.error").hide();

		        // get form data
		      var name = $('form input#name').val();
		      var email = $('form input#email').val();
		      var phone = $('form input#phone').val();
		      var message = $('form textarea#message').val();

		      // validate the form and hide the errors by placing them nowhere
		      $("form").validate( {
			      errorPlacement : function(error, element) {
			      }
		      });
		      if ($("form").validate().form() == true) {
			      $("button:contains('Send')").fadeOut('fast');
			      $('form').fadeOut(500);
			      $.post("./popups/send_mail.php", {
			        send_mail : true,
			        name : name,
			        email : email,
			        phone : phone,
			        msg : message
			      }, function(data) {
				      // alert(data);

				        $('span.ui-dialog-title').fadeTo('slow', 0.0, function() {
					        if (data == 'sent') {
						        titleText = "Message Sent", messageClassName = '.thanks';

					        } else {
						        titleText = "Error";
						        messageClassName = '.error';

					        }
					        $('span.ui-dialog-title').text(titleText);
					        $('span.ui-dialog-title').fadeTo('slow', 1);
					        $(messageClassName).delay(500).fadeIn(500);
				        });

				        // alert(data);
			        });
		      } else {
			      $("label.error").hide();
		      }

	      },
	      Close : function() {
		      $(this).dialog("close");
		      $('body').css('overflow', 'visible');
		      // $('form')[0].reset();
	      }
	      }

	    });

    });
