
function openPopup(url,name,width,height) {
	var popupWin = top[name];
	if (popupWin != null && typeof(popupWin) == 'object' && !popupWin.closed) {
		if (popupWin.document.location.href != url) {
			popupWin.document.location.href = url;
		}
	} else {
		popupWin = window.open(url, name, 'width=' + width + ',height=' + height + 'status=yes,menubar=yes,resizable=yes,scrollbars=no,left=0,top=0');
	}
	popupWin.focus();
}

function closePopup(url) {
	if (opener) {
		if (opener.closed) window.open(url, "");
		self.close();
		return false;
	}
	return true;
}

var last_id = 0;

function show_id(id){
	
	if(last_id != 0){
		document.getElementById('id'+last_id).style.display = 'none';
		document.getElementById('id_'+last_id).style.display = 'block';
	}
	
	document.getElementById('id'+id).style.display = 'block';
	document.getElementById('id_'+id).style.display = 'none';
	
	last_id = id;
}

function check() {
	p_name = document.reg_form.name.value.toString();
	if(p_name != "") {
		if(p_name.length<4 || p_name.length>120) {
			alert ("Укажите ваше имя фамилию отчество !");
			document.reg_form.name.focus();
		}
	} else {
		alert("Необходимо ввести имя!");
		document.reg_form.name.focus();
		return false;
	}
	p_email = document.reg_form.email.value.toString();
	if (p_email != "") {
		t = p_email.indexOf("@");
		if((p_email.indexOf(".") == -1) || (t == -1) || (t < 1) || (t > p_email.length - 5) || (p_email.charAt(t - 1) == '.') || (p_email.charAt(t + 1) == '.')) {
			alert("Некорректно указан E-mail !");
			document.reg_form.email.focus();
			return false;
		}
	} else {		
		alert("Необходимо ввести E-mail !");
		document.reg_form.email.focus();
		return false;
	}
	return true;
}

function sendmail(){   
	$.ajax({
	   type: "POST",
	   url: "/sendmail.php",
	   data: "name="+$("#nm").val()+"&phone="+$("#ph").val()+"&comment="+$("#cm").val()+"&count="+$("#kv").val()+"&money_from="+$("#mon1").val()+"&money_to="+$("#mon2").val(),
	   success: function(msg){
		  if(msg==1) alert('Ваше сообщение отправлено');
	   }
	 });
	 return false;
}

function sendmail2(){
	name = document.getElementById('cname').value;
	phone = document.getElementById('cphone').value;
	if( name == '' || phone == ''){
		alert('Не заполнены поля!');
		return false;
	} else {
		alert('Отправка заявки!');
		$("#csend").html('<font color="red">Ваша заявка принята.</font>');
		$.ajax({
		type: "POST",
		url: "/sendmail.php?calc=1",
		data: "name="+name+"&phone="+phone,
		success: function(msg){
			//
			if(msg == 1){
				$("#csend").html('<font color="red">Ваша заявка принята.</font>');
			} else {
				$("#csend").html('<font color="red">Ошибка отправления заявки!</font>');
			}	
		}
	 });

	}
	document.ff2.submit();
	return true;
}
jQuery(document).ready(function(){
	$(".lightbox").lightbox({
			 overlayOpacity : 0.75,
			 borderSize : 10,
			 navbarOnTop: true,
			 strings : {
			 help: ' \u2190 / P - предыдущее фото\u00a0\u00a0\u00a0\u00a0\u2192 / N - следующее фото\u00a0\u00a0\u00a0\u00a0ESC / X - закрыть фото',
			 prevLinktitle: 'предыдущее фото',
			 nextLinktitle: 'следующее фото',
			 prevLinkText: '&laquo; Назад',
			 nextLinkText: 'Вперёд &raquo;',
			 closetitle: 'закрыть фото',
			 image: 'Фото ',
			 of: ' из '
			 },
			 fitToScreen: false
		 });
	jQuery('.autoriz').click(function(){
		jQuery('#autForm').toggle();
		return false;
	});
	jQuery('#autForm input').focus(function(){
		siv=jQuery(this).val();
		if(jQuery(this).val()==siv)
		jQuery(this).attr("value","");
	})
	.blur(function(){
		if(!jQuery(this).val())
			jQuery(this).attr("value",siv);
	});

	jQuery('.li_class').click(function() {				
		v=$(this);
		if (v.parent().hasClass('active')){
			return true;
			v.parent().removeClass("active"); 
			v.parent().find('.sub-menu').slideUp('fast');										
		} else {
			jQuery('.menua .active').find('.sub-menu').hide();
			jQuery('.menua .active').removeClass("active");					
			v.parent().addClass("active");
			v.parent().find('.sub-menu').slideDown();				
		} 
	});
	/*var vvvold = null;
	$(".menua li a").hover(function() {
		vvv2 =$(this); 
		vvv2.addClass("hover");
		if(vvvold){vvvold.removeClass("hover")};	
		vvvold = vvv2; 
	});*/
	$('#faqBtn').click(function(){
		$(this).parent().hide();
		$('#frmOrder').show();
	});
});
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-17296535-1']);
_gaq.push(['_addOrganic', 'go.mail.ru', 'q']);
_gaq.push(['_trackPageview']);

(function() {
 var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async  = true;
ga.src = ('https:' == document.location.protocol ?  'https://ssl' : 'http://www')  + '.google-analytics.com/ga.js';
 var s = document.getElementsByTagName('script')[0];  s.parentNode.insertBefore(ga, s);
})();

//Отправка почты из раздела "Дилерам"
$(document).ready(function() {
	$('#form-dealers').submit(function() {
		$.ajax({
		   type: "POST",
		   url: "./",
		   data: $(this).serialize(),
		   success: function(msg){
				if(msg == 'error') {
					$('#sendError').text('Пожалуйста проверьте заполнение полей.');
				} else if(msg == 'ok') {
					$('#form').html('<p>Ваша заявка отправлена!</p>');
				}
		   }
		 });
		return false;	
	});
});

