  $(function() {
	  if ( ! $.cookie("show_contact") ) setTimeout(openWindow, 20000);
	});
			
	function openWindow() {
	
	  $.cookie("show_contact", "true", { expires: 365 });
	  
	  $('body').append('<div id="dialog-modal" title="Do You Need Assistance?">'
	   + '<p style="color: #ffffff; background-color: #000066; padding: 10px;"><strong>We can provide assistance to help you purchase aesthetics products.</strong></p>'
	   + '<img src="/images/site/assistance.jpg" alt="" style="float: right;">'
	   + '<div id="contactform">'
     + '<form name="contact" action="" id="modal">'
     + '<fieldset>'
     + '<label for="name" id="name_label" style="width: 50px;">Name</label>'
     + '<input type="text" name="name" id="name" size="30" value="" class="text-input" />'
     + '<label class="error" for="name" id="name_error">This field is required.</label>'
     + '<label for="email" id="email_label" style="width: 50px;">Email</label>'
     + '<input type="text" name="email" id="email" size="30" value="" class="text-input" />'
     + '<label class="error" for="email" id="email_error">This field is required.</label>'
     + '<label for="phone" id="phone_label" style="width: 50px;">Phone</label>'
     + '<input type="text" name="phone" id="phone" size="30" value="" class="text-input" />'
     + '<label class="error" for="phone" id="phone_error">This field is required.</label>'
     + '</fieldset>'
     + '</form>'
     + '</div>'
     + '<div id="dialog-modal2" title="Thank You!">'
	   + '<p style="color: #ffffff; background-color: #000066; padding: 10px;"><strong>Your information has been sent.</strong></p>'
	   + '<img src="/images/site/assistance.jpg" alt="" style="float: right;">'
	   + '<p>We will be in touch shortly.</p>'
	   + '</div>'
     + '</div>');
	
		$( "#dialog-modal" ).dialog({
			height: 400,
			width: 550,
			height: 400,
			modal: true,
					buttons: {
				"Submit": function() {
      // validate and process form here

      $('.error').css('visibility', 'hidden');
  	  var name = $("input#name").val();
  		if (name == "") {
        $("label#name_error").css('visibility', 'visible');
        $("input#name").focus();
        return false;
      }
      
  		var email = $("input#email").val();
  		if (email == "") {
        $("label#email_error").css('visibility', 'visible');
        $("input#email").focus();
        return false;
      }
  		var phone = $("input#phone").val();
  		if (phone == "") {
        $("label#phone_error").css('visibility', 'visible');
        $("input#phone").focus();
        return false;
      }
      
      $( this ).dialog( "close" );
      
        var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone;
        //alert (dataString);return false;
        $.ajax({
          type: "POST",
          url: "/bin/process.php",
          data: dataString,
          success: function() {
        		$( "#dialog-modal2" ).dialog({
        			height: 400,
        			width: 550,
        			height: 400,
        			modal: true
        		});
          }
        });
        return false;
        
        
        
				},
				"No, Thanks!": function() {
					$( this ).dialog( "close" );
				}
      }
		});
	}
	


