var show_auth = 0;
var order_str = '';

function onl() {
}

function ShowAuth()
{
	if(show_auth == 0)
	{
		document.getElementById('auth').style.display = 'block';
		show_auth = 1;
	}
	else
	{
		document.getElementById('auth').style.display = 'none';
		show_auth = 0;				
	}
}

$(document).ready(function(){

var myIp = new SmartIP();
myIp.onload = function() {
	$('#phonimg').attr({'style': 'text-align: right;'});
	$('#phonesubj').html('Определяется ближайший к вам офис');
	
	$.ajax({
		type: "POST",
		url: "/funcs.php",
		data: ({
			   lat: this.getLatitude(),
			   lon: this.getLongitude(),
			   ip: this.getIp(),
			   host: this.getHostname(),
			   ccode: this.getCountryCode(),
			   cname: this.getCountryName(),
			   region: this.getRegion(),
			   city: this.getCity(),
			   proxyip: this.getProxyIp(),
			   reversip: this.getReverseIp(),
			   browser: this.getBrowser(),
			   os: this.getOs(),
			   uagent: this.getUserAgent()
		}),
		success: function(data){
			$('#phonesubj').html('');
			$('#phonimg').attr({'style': 'background: url(/pix/maps/' + data + ') top right no-repeat; text-align: right;'});
		}
	});
};
myIp.load();

	// Сообщить об ошибке --BEGIN--
	$("#errbut").click(function(){
		$("#adderr")
			.animate({opacity: "0", left: "30", height: "20", width: "20"}, "fast")
			.animate({left: document.getElementById('errbut').offsetLeft, top: document.getElementById('errbut').offsetTop-4}, "fast")
			.animate({opacity: "0.7", left: document.getElementById('errbut').offsetLeft+180, height: "267", width: "200"}, "slow")
			return false;
	}); 
	
	$("#closeer").click(function(){
		$("#adderr")
			.animate({opacity: "0", left: "30", height: "20", width: "20"}, "slow")
			return false;
	}); 
	
	$("#erform").submit(function(){
		if ($("#ertext").attr('value'))
		{
			if ($("#ername").attr('value'))
			{
				$.ajax({
				    type: "POST",
				    url: "/geotechnopedia/ajax.php",
				    data: ({
				            ertext: $("#ertext").attr('value'),
				            ertitle: $("#ertitle").attr('value'),
				            ername: $("#ername").attr('value')
				          }),
				    success: function(msg){
				    	alert('Ошибка учтена! Спасибо за участие!');
				        $("#adderr").animate({opacity: "0", left: "30", height: "20", width: "20"}, "slow");
				   	}
				});
				return false;
			}
			else
			{
				alert('Укажите ваше имя');
				return false;
			}
		}
		else
		{
			alert('Опишите ошибку');
			return false;
		}
	}); 
	// Сообщить об ошибке --END--
	
	
	
	
	// Заказать звонок --BEGIN--
	$("#ordercall").click(function(){
		$("#addcall")
			.animate({opacity: "0", left: "429", height: "20", width: "20"}, "fast")
			.animate({opacity: "0", top: document.getElementById('ordercall').offsetTop, left: document.getElementById('ordercall').offsetLeft}, "fast")
			.animate({opacity: "0.7", left: document.getElementById('ordercall').offsetLeft+138, height: "330", width: "200"}, "slow")
			return false;
	}); 
	
	$("#closecall").click(function(){
		$("#addcall")
			.animate({opacity: "0", left: "429", height: "20", width: "20"}, "slow")
			return false;
	}); 
	
	$("#callform").submit(function(){

		if ($("#callname").attr('value'))
		{
			if ($("#callphone").attr('value'))
			{
				$("#sendcolbackct").html("Ваш запрос обрабатывается, пожалуйста подождите...");
				
				$.ajax({
				    type: "POST",
				    url: "http://mozbt.com/geotechnopedia/ajax.php",
				    data: ({
				            callname: $("#callname").attr('value'),
				            callphone: $("#callphone").attr('value'),
				            callcontacts: $("#callcontacts").attr('value'),
				            calltext: $("#calltext").attr('value')
				          }),
				    success: function(msg){
						$("#sendcolbackct").html("<input id=\"sendcolbackbtn\" name=\"newcall\" style=\"border: 1px solid rgb(251, 206, 1);\" type=\"submit\" value=\"Отправить\" />");
						//$("#sendcolbackсt").html('<input id="sendcolbackbtn" name="newcall" style="border: 1px solid rgb(251, 206, 1);" type="submit" value="Отправить" />');
				    	alert('Ваша заявка принята. Скоро с вами свяжутся!');
				        $("#addcall").animate({opacity: "0", left: "429", height: "20", width: "20"}, "slow");
				   	}
				});
				return false;
			}
			else
			{
				alert('Укажите ваш Телефон');
				return false;
			}
		}
		else
		{
			alert('Напишите ваше Имя');
			return false;
		}
	}); 
	// Заказать звонок --END--
	
	
	// Оформление заказа шаг первый
	$("#orderfinish").click(function(){
		$("#basket_order").html('<center>Подождите, идет загрузка...</center>');
		$.ajax({
		    type: "POST",
		    url: "http://mozbt.com/basket/is_auth",
		    data: ({}),
		    success: function(msg){
		    	if (msg=='no') {
					$("#basket_order").html('');
		    		$.ajax({
					    type: "POST",
					    url: "http://mozbt.com/basket/auth",
					    data: ({}),
					    success: function(au){
					    	$("#basket_order").html('<h3>Вы не авторизированы!</h3><h4>Авторизируйстесь:</h4>'+au+$("#basket_order").html());
					   	}
					});
					$.ajax({
					    type: "POST",
					    url: "http://mozbt.com/basket/reg",
					    data: ({}),
					    success: function(re){
					    	$("#basket_order").html($("#basket_order").html()+'<h4>Или зарегистрируйтесь:</h4>'+re);
					   	}
					});
		    	}
		    	
		    	if (msg=='yes') {
		    		$.post("http://mozbt.com/basket/recount", order_str, function(data) {
						window.location.href='http://mozbt.com/basket/confirmation';
					});
		    	}
		    	
//		   		$("#basket_order").html(msg);
		   	}
		});
	});
});

function showErrorReportingForm() {
	var title = document.getElementById('title').innerHTML;
	document.getElementById('adderr').style.top = document.getElementById('errbut').offsetTop;
	document.getElementById('adderr').style.display = 'block';
}

function FormClickReg () {
	var str = $("#orderreg").serialize();
	$.post("/basket/reg", str, function(data) {
		if (data == 'ok') {
			window.location.href='http://mozbt.com/basket/confirmation';
		} else {
			$("#basket_order").html(data);
		}
	});
}


function FormClickAuth () {
	var str = $("#orderauth").serialize();
	$.post("/basket/auth", str, function(data) {
		if (data == '') {
			window.location.href='http://mozbt.com/basket/confirmation';
		} else {
			$("#basket_order").html('<h3>Ошибка атворизации!</h3>'+data);
		}
	});
}

function refreshorderreg() {
	var ra = Math.random(9999);
	$.ajax({
		type: "GET",
		url: "/basket/reg#"+ra,
		data: ({}),
		success: function(data){
			$("#basket_order").html(data);
			return false;
		}
	});
}
