    jQuery(function($) {
        $.mask.definitions['~']='[+-]';
        $('#call_tel').mask('+380 (99) 999-99-99');
    });

$(document).ready(function(){
	    	
    $('.call').click(function(event) {
	    $('#oe_overlay').addClass("oe_max");
	    $('#oe_overlay').stop(true,true).fadeTo(200, 0.6);
//	    var winH = $(this).offset().top;
	    var winH = $(window).height();
	    var winW = $(window).width();
	    			    
	    $(".form_call").css('top',winH/2-$(".form_call").height()/2);
	    $(".form_call").css('left',winW/2-$(".form_call").width()/2);
	    $(".form_call").fadeIn(500);
	    $(".form_call").focus();
	    return false;
    });

    $('.form_call .close').click(function(event) {
	    $('.form_call').fadeOut(300);
	    $('#call_err').hide();
	    $('#oe_overlay').stop(true,true).fadeTo(100, 0);
	    $('#oe_overlay').removeClass("oe_max");
    });

    $('#call_submit').click(function(event) {
	    login=$('#call_login').val();
	    tel=$('#call_tel').val();
	    if (empty(login) || empty(tel)) 
		$('#call_err').show();
	    else {
		$('#call_err').hide();
    
		JsHttpRequest.query(
			    'hr_gate.php?test=500&r='+Math.random(),
			    {
				'sp': "callback"
			       ,'login': login
			       ,'tel': tel
			       ,'href': location.href
			    },
				function(result, errors) {
					if (errors) alert(errors);
					if (result) {
					    $('.form_call').fadeOut(300);
					    $('#call_err').hide();
					    $('#oe_overlay').stop(true,true).fadeTo(100, 0);
					    $('#oe_overlay').removeClass("oe_max");
					} else {
					    $('#call_input').html('<p style="margin-top:15px;"><center>Извините.<br /> Сервис временно не доступен</center></p>');
					}
				},
			    true  //disable caching
			    );
		}
    });
	    

});

