$(function(){

	// Dialog			
	$('#dialog').dialog({
		autoOpen: false,
		width: 400,
		modal:true,
		show: 'blind',
		hide: 'explode',
		focus: function(event, ui) { $("#phone").trigger("focus"); },
		buttons: {
			"���������": function() { 
				var uphone = $('#phone').val();
				var form_call = $('#dialog').html();
				if (document.form1.select_type[1].checked && uphone) uphone = '99910' + uphone;
				if (uphone) {
				$(this).dialog("close"); 
				$('#dialog1').dialog("open");
				$.post('callme.php', 
				{
					phone:uphone,
					e1_number:'99982006656',
					call:1
				},
				function(data) {
					$('#phone').val('');
						//alert(form_call);
						$('#dialog1').append(data);
						});
					
				}
				else {
				$(this).dialog("close"); 
				}
			}
		}
	});
	$('#dialog1').dialog({
		autoOpen: false,
		width: 400,
		modal:true,
		show: 'blind',
		hide: 'explode',
		buttons: {
			"Ok": function() { 							
				$(this).dialog("close"); 
				$('#dialog1').html('<img src="/js/jquery-ui-1.8rc3/loader.gif"><br/>');
				
				}
		}
	});
	//$('#phone').mask('+9(999)999-99-99', {placeholder:'*'});
	//$('#skype').mask('(99999)', {placeholder:'*'});
	
	// Dialog Link
	$('#dialog_link').click(function(){
		go_dialog();
		return false;
	});

	//hover states on the static widgets
	$('#dialog_link, ul#icons li').hover(
		function() { $(this).addClass('ui-state-hover'); }, 
		function() { $(this).removeClass('ui-state-hover'); }
	);

	$('#form1').bind("keypress", function(e) {
		if (e.keyCode == 13) {
		//alert('asdasdasdas');
		//go_dialog();
		return false;
		}
	});
	
});
function select_opt(param) {
	var phone_val = document.getElementById('prefix');
	if (param == 'skype') {
		$('#prefix').html('99910');
		//$('#example_num').html('&nbsp;');
		$('#text_phone').css('display','none');
		$('#text_skype').css('display','block');
	}
	else {
		$('#prefix').html('+');
		//$('#example_num').html('������ ��� ������: 74959957013');
		$('#text_phone').css('display','block');
		$('#text_skype').css('display','none');
	}
};
//Main funct
function go_dialog() {
	$('#prefix').html('+');
	$('#phone').val('');
	//$('#example_num').html('������ ��� ������: 74959957013');
	$('#text_phone').css('display','block');
	$('#text_skype').css('display','none');
	document.form1.select_type[0].checked = true;
	$('#dialog').dialog('open');
	//document.getElementById('phone').focus();
	$("#phone").trigger("focus");
};

