﻿var send_boss_form = 
'<div id="toBossForm" class="requestForm">' +
'	<div class="title">Напишите управляющему компании<br>&nbsp;</div>' +
'	<div class="border"></div>' +
'	<form action="sayboss.php" method="post" id="sendBossForm">' +
'	<div>' +
'		<input type="text" class="type" id="sb-name" name="sb-name" />' +
'		<input type="text" class="type" id="sb-email" name="sb-email" />' +
'	</div>' +
'	<div>' +
'		<input type="checkbox" id="sb-wantreply" name="sb-wantreply" />' +
'		<label for="sb-wantreply">Хочу обязательно получить ответ</label>' +
'		<br><br>' +
'	</div>' +
'	<div>' +
'		<textarea id="sb-message" name="sb-message" cols="" rows="8"></textarea>' +
'		<div class="submit"><a href="javascript: sayBoss()">Отправить</a></div>' +
'	</div>' +
'	</form>' +
'	<div class="contacts">Почта: <a href="mailto:salonlanet@mail.ru">salonlanet@mail.ru</a>, тел. для справок: 979-13-79</div>' +
'</div>';

function sayBoss() {
	document.forms["sendBossForm"].submit();
}

function send_request_form_pos2() {
	var windowWidth = 0;
	var windowHeight = 0;

	if (self.innerHeight) {
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	var posX = (windowWidth-452)/2 + 'px';
	/*var posY = (windowHeight-331)/2 + 'px';*/
	var posY = $(window).scrollTop() + 150;
	$('#toBossForm').css('left', posX).css('top', posY);
}
		
(function($){
		  
	$(window).scroll(function() {
		var sv = $(window).scrollTop() + 150;
		$('#requestForm, #sendMail').clearQueue().animate({ top: sv }, 0);
	});
	
	$(window).resize(function() {
		send_request_form_pos2();
	});
		  
	$(document).ready(function(){

		$('body').append('<div id="overlay"></div>');
		$('#overlay').css({ backgroundColor: '#000000', opacity: 0.7, width: '100%', height: '100%', display: 'none', position: 'absolute', top: '0', left: '0', zIndex: '4', padding: '8px', margin: '-8px' });

		$('.sendRequest').bind('click', function(){
			send_request_form_pos2();
			$('#overlay').fadeIn(350);
			$('#requestForm').fadeIn().bind('mousedownoutside', function() {
				$(this).fadeOut(350).unbind('mousedownoutside');
				$('#overlay').fadeOut(350);
			});
		});
											 
		$('body').append(send_boss_form);
		$('#sb-name').inputHint('Имя, Фамилия');
		$('#sb-email').inputHint('e-mail');
		
		$('#callBossForm').bind('click', function(){
			send_request_form_pos2();
			$('#overlay').fadeIn(350);
			$('#toBossForm').fadeIn().bind('mousedownoutside', function() {
				$(this).fadeOut(350).unbind('mousedownoutside');
				$('#overlay').fadeOut(350);
			});
		});
	
		$('#subs_email').inputHint('Напишите свою почту');
	
		$('#subs_submit').click(function(){
			$.ajax({
				type: "POST",
				url: "topbar_wemail.php",
				data: {subs_email:$('#subs_email').val()},
				success: function() {
					alert( "Спасибо! Ваш электронный адрес подписан." );
				}
			});
			$('#subs_email').val('Напишите свою почту');
		});
	
		var elem = $('#element_id');
		var num = 0
		var m = 0; var n = 1;
		setInterval( function() {
			num = parseInt(elem.html()) + Math.floor( Math.random( ) * (n - m + 1) ) + m;
			elem.html(num);
			$.ajax({
				type: "POST",
				url: "topbar_rand.php",
				data: {rand:num},
				success: function() {
				}
			});
		}, 280000);
	
		$('#mail-boss').hover(
			function(){
				$('#mail-boss-popup').slideDown('fast');
			},
			function(){
				$('#mail-boss-popup').slideUp('fast');
			}
		);
		
	});
	
})(jQuery);


