﻿var popupStatus = 0;

var error='';

function loadPopup(type){
	
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		if(type=='ent')
			$("#popupAuth").fadeIn("slow");
		if(type=='reg')
			$("#popupReg").fadeIn("slow");
		if(type=='metro')
			$("#popupMetro").fadeIn("slow");
		if(type=='google')
			$("#googleMap").fadeIn("slow");
		if(type=='addOffer')
			$("#addOffer").fadeIn("slow");
		popupStatus = 1;
	}
}


function disablePopup(){
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$(".popup").fadeOut("slow");
		popupStatus = 0;
	}
}

function centerPopup(){

	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $(".popup").height();
	var popupWidth = $(".popup").width();
	
	$(".popup").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

function send_order(id)
{
var ajax1= new ajax_class();
ajax1.get_access("http://flatozery.ru/?par1=user&par2=send_offer&par3="+id,get_last_request);
}

function send_on_mail(id)
{
	error='';
	text= /\d{5,12}/;
	if (document.getElementById("telephone").value=='') error=error+'Укажате контактный телефон\n';
	else
		if (result=text.test(document.getElementById("telephone").value)) error=error;
		else error=error+'Ошибка при заполнении контактного телефона\n';

	if (document.getElementById("person").value=='') error=error+'Укажите контактное лицо\n';
		
	if (document.getElementById("capcha1").value==document.getElementById("capcha_right").value) error=error;
		else error=error+'Вы неверно ответили на контрольный вопрос\n';

		
	if (error==''){
		var tel1 = $("#telephone").val();
		var per = $("#person").val();
		var str = $("#street").val();
		var hou = $("#house").val();
		var n_r = $("#num_rooms").val();
		if (document.getElementById('room').checked)  var roo = document.getElementById('room').value; else  var roo = '';
		var sto = $("#storey").val();
		if (id!=3) var n_s = $("#num_storeys").val(); else var n_s = '';
		var h_t = $("#house_type").val();
		if (id!=3) var tot = $("#total_area").val(); else var tot ='';
		if (id!=3) var liv = $("#living_space").val(); else  var liv = '';
		if (id!=3) var kit = $("#kitchen").val(); else var kit = '';
		if (document.getElementById('tel').checked)  var tel2 = document.getElementById('tel').value; else  var tel2 = '';
		var n_b = $("#num_bath").val();
		var t_b = $("#type_bath").val();
		var bal = $("#balcon").val();
		if (id!=2) var sec = $("#security").val(); else var sec = '';
		if (document.getElementById('refuse').checked)  var ref = document.getElementById('refuse').value; else  var ref = '';
		if (document.getElementById('lift').checked)  var lif = document.getElementById('lift').value; else  var lif = '';
		var abo = $("#about").val();
		if (id!=2) var pri = $("#price").val(); else var pri = '';
		if (id==2) var par = $("#params").val(); else  var par = '';
		var cap = $("#capcha1").val();
		if (id==3 || id==4) var sos = $("#sost").val(); else var sos = '';
		if (id==3 || id==4) var meb = $("#mebel").val(); else var meb = '';
		$.post(	"http://flatozery.ru/?par1=user&par2=send_offer&par3="+id,
			{telephone: tel1, person:per, street:str, house:hou, num_rooms:n_r, room:roo, storey:sto, num_storeys:n_s, house_type:h_t, total_area:tot,living_space:liv, kitchen:kit, tel:tel2, num_bath:n_b, type_bath:t_b, balcon:bal, security:sec,refuse:ref, lift:lif, about:abo, price:pri, params:par, sost:sos, mebel:meb}, 
			function(data){$("#send_offer").text(data)}
	   );
	   
	   
	}else {
		var ajax2= new ajax_class();
		ajax2.get_access("http://flatozery.ru/?par1=user&par2=set_capcha",get_last_request1);
		alert(error);
	}
}


function get_last_request1()
{
document.getElementById('capcha').innerHTML=respText;
document.getElementById('capcha1').value='';
document.getElementById('popupAuth').style.top='200px';
}

function get_last_request()
{
document.getElementById('send_offer').innerHTML=respText;
}


/*function f_login(t){
	text= /\A\[А-Я|а-я|( )]+\b/;
	if (t=='') document.getElementById("3").innerHTML="Заполните";
	else
	if (result=text.test(t))
		document.getElementById("3").innerHTML="";
	else document.getElementById("3").innerHTML="Ошибка";
}
	
*/

// events
$(document).ready(function(){
	
	/* enable */
	
	
	$("#termins li").mouseover(function(){
		//alert ("hgfshf");
		//$(this).children(".info").css({display: "block"});
	});

	$("#termins li").mouseout(function(){
		$(this).children(".info").css({display: "none"});
	});
	
	$("#enter1").click(function(){
		centerPopup();
		loadPopup('ent');
	});
	$("#enter2").click(function(){
		centerPopup();
		loadPopup('ent');
	});
	$("#enter3").click(function(){
		centerPopup();
		loadPopup('ent');
	});
	$("#enter4").click(function(){
		centerPopup();
		loadPopup('ent');
	});
	
	$("#popupAuthClose").click(function(){
		disablePopup();
	});	
	
	$("#example_j button").click(function(){
		var aaa = $("#example_j input:first").val();
		var bbb = $("#example_j input:last").val();
		$.post(
			"ajax/load/post.php",
			{a: aaa, b: bbb}, 
			function(data){$("#example_j span").text(data)}
	   )
							});

	/* news admin insets */

	

});




