$(function() {
		$( "#dialog:ui-dialog" ).dialog( "destroy" );
		
		var name = $( "#name" ),
			phone = $( "#phone" ),
			password = $( "#password" ),
			allFields = $( [] ).add( name ).add( phone ).add( password ),
			tips = $( ".validateTips" );
		
		$( "#dialog-form" ).dialog({
			autoOpen: false,
			height: 350,
			width: 350,
			modal: true,
			buttons: {
				"Послать заказ": function() {
					var bValid = true;
					var clientName = $( "#name" );
					var phone = $( "#phone" );
					var subject = $( "#order_subject" );
					var requestParam = "client_name=" + clientName.val() + "&" + "client_phone=" + phone.val() + "&" + "subject=" + subject.val();
					//alert(requestParam);
          $.ajax({
      		url: 'http://visionsecurity.ru/orderform/send_order.php',
      		type: "POST",
      		data: requestParam
    			}); 
					$( this ).dialog( "close" );	
				},
				Cancel: function() {
					$( this ).dialog( "close" );
				}
			},
			close: function() {
				allFields.val( "" ).removeClass( "ui-state-error" );
			}
		});
    $( "#dialog-form" ).dialog({
   				open: function(event, ui) {
   					
						var order_subject = $( "#order_subject" );
   					//$( "#dialog-form" ).style.visibility = "visible";
						order_subject.val($( "#create-order" ).val());
   					document.getElementById("name").style.visibility = "visible";
   					document.getElementById("phone").style.visibility = "visible";
						document.getElementById("order_subject").style.visibility = "visible";
						document.getElementById("validateTips").style.visibility = "visible";
						document.getElementById("label_for_name").style.visibility = "visible";
						document.getElementById("label_for_phone").style.visibility = "visible";
						document.getElementById("label_for_order_subject").style.visibility = "visible";
					}
			});

		$( "#create-order" )
			.button()
			.click(function() {
				$( "#dialog-form" ).dialog( "open" );
			});
	});
$(document).ready(function () {
	$("#phone").keypress(function (e)  
    { 
      if( e.which!=8 && e.which!=0 && (e.which<48 || e.which>57))
      { 
        return false;
      }    
    });
});
	
function create_order(subject)
{
	$( "#dialog-form" ).dialog( "open" );
	var order_subject = $( "#order_subject" );
	order_subject.val(subject);
}

function body_onload()
{
	//$( "#dialog-form" ).style.visibility = "visible";
}
