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