﻿$(document).ready(function(){
	
	$("#call-button").click(function(){
		$("#call-button-popup").css("top",($(this).offset().top + $(this).height() - $("#call-button-popup").height() - 30) + "px");
		$("#call-button-popup").css("left",($(this).offset().left - $("#call-button-popup").width() - 30) + "px");
		if (!$.browser.msie) {
			$("#call-button-popup").css("box-shadow","2px 2px 15px gray");
            $("#call-button-popup").css("-o-box-shadow","2px 2px 15px gray");
            $("#call-button-popup").css("-moz-box-shadow","2px 2px 15px gray");
            $("#call-button-popup").css("-webkit-box-shadow","2px 2px 15px gray");
		}
		$("#call-button-popup").stop(true,true);
		//$("#calculator").find("input, select").fadeOut("fast");
		$("#call-button-popup").fadeIn("normal");
	});
	
	$("#call-button-popup").find("input[name='cancel']").click(function(){
		$("#call-button-popup").stop(true,true);
		//$("#calculator").find("input, select").fadeIn("fast");
		$("#call-button-popup").fadeOut("normal");
	});
	
	$("#call-button-popup").find("input[name='send']").click(function(){
		if ($("#call-button-popup").find("input[name='clName']").val().length == 0) {
			alert("Введите, пожалуйста, Ваше имя!");
		} else if ($("#call-button-popup").find("input[name='clSurname']").val().length == 0) {
			alert("Введите, пожалуйста, Вашу фамилию!!");
		} else if ($("#call-button-popup").find("input[name='clPhone']").val().length == 0) {
			alert("Введите, пожалуйста, номер Вашего телефона!");
		} else if ($("#call-button-popup").find("input[name='clPhone']").val().length != 12) {
			alert("Телефон указан неверно! Правильный формат: +7ХХХХХХХХХХ");
		} else if ($("#call-button-popup").find("textarea").val().length == 0) {
			alert("Введите, пожалуйста, Ваш вопрос! Это позволит нашим специалистам оперативнее Вам помочь.");
		} else {
			var query = $("#call_order").serialize();
			$("#cb_form").fadeOut();
			$("#cb_proceed").fadeIn();
			$.get("/misc/call/result/?"+query,{},function(result){
				$("#cb_proceed").fadeOut();
				if (result == "true") {
					$("#cb_success").fadeIn();
				} else {
					$("#cb_unsuccess").fadeIn();
				}
			});
		}		
	});
	
});
