
// JavaScript Document



function showModelImage(src,width,height){

			m_top = document.body.scrollTop+20;
			m_left = (document.body.clientWidth-width-44)/2;
			
			
			$("#i-dialog").css("width",width+44);
			$("#i-dialog").css("height",height+44);

			$("#i-dialog").css("left",m_left);
			$("#i-dialog").css("top",m_top);	
			$("#i-dialog-content").html("<img src='"+src+"'>")
			$("#i-dialog").css("display","block");	
}




function showDiv(id,obj){
	$('#'+id).toggle("blind");
	$(obj).toggleClass("open");
}

function showNews(id){
	$('#'+id).toggle("clip");
}




function hideCallDialog() {
		if (($("#i-dialog").css("display")== 'block')) {
			$("#i-dialog").css("display","none");	
		}
}

function showCallDialog() {
var text="<form  method='post' id='call-form' ENCTYPE='multipart/form-data' class='call-form' onSubmit='return sendCall();'>"+
"<div class='login-index'><h3 align='center'>Мы сами вам перезвоним!</h3><div id='i-dialog-message'></div>"+
"<table cellpadding='0' cellspacing='0' width='450'>"+
"<tr><td></td><td align='center' colspan='3'><label for='title_s' class='overlabel'>Ваше имя</label></td></tr>"+
"<tr><td></td><td colspan='3'><label for='title_s' class='overlabel'></label><input type='text' id='title_s' class='type-text' value='' name='title_s' maxlength='100' style='width:100%;'/></td></tr>"+
"<tr><td><br></td></tr>"+
"<tr align='center'><td></td><td><label for='ext_s' class='overlabel'>Код</label></td><td><label for='phone_s' class='overlabel'>Номер телефона</label></td><td><label for='time_s' class='overlabel'>Время</label></td></tr>"+
"<tr><td style='font-size:33px;color:#999999; padding-top:5px;' width='50'>+7</td>"+
"<td width='82'><input type='text' id='code_s' class='type-text' value='' name='code_s' maxlength='5' style='width:80px;'/></td>"+
"<td ><input type='text' id='phone_s' class='type-text' value='' name='phone_s' maxlength='20' style='width:236px;'/></td>"+
"<td width='80'><input type='text' id='time_s' class='type-text' value='00:00' name='time_s' maxlength='5' style='width:80px;'/></td></tr></table>"+
"<div align='center'><br><input type='submit' class='type-button' value='Отправить &rarr;' ></div></form>";

			var width=536;
			var height=310;
			m_top = document.body.scrollTop+30;
			m_left = (document.body.clientWidth-width)/2;
			
			
			$("#i-dialog").css("width",width);
			$("#i-dialog").css("height",height);

			$("#i-dialog").css("left",m_left);
			$("#i-dialog").css("top",m_top);	
			
			$("#i-dialog-content").html(text)
			$("#i-dialog").css("display","block");	

}



function showSendMessageForm(){
	var text="<form  method='post' id='message-form' ENCTYPE='multipart/form-data' class='message-form' onSubmit='return sendMessage();'>"+
"<div align='center'><h3>Обратная связь</h3><div id='i-dialog-message'></div>"+
"<dl class='field-mail'><dd><label for='title_s' class='overlabel'>Ваше имя</label><input type='text' id='title_s' class='type-text' value='' name='title_s' maxlength='100' style='width:366px;'/></dd></dl>"+
"<dl class='field-mail'><dd><label for='email_s' class='overlabel'>Эл.адрес</label><input type='text' id='email_s' class='type-text' value='' name='email_s' maxlength='100' style='width:366px;'/></dd></dl>"+
"<dl class='field-pwd'><dd><label for='text_s' class='overlabel'>Сообщение</label><textarea id='text_s' class='type-text' name='text_s'  style='width:366px;height:135px'></textarea></dd></dl>"+
"<div><input type='submit' class='type-button' value='Отправить' ></div></form>";

			var width=516;
			var height=530;
			m_top = document.body.scrollTop+30;
			m_left = (document.body.clientWidth-width)/2;
			
			
			$("#i-dialog").css("width",width);
			$("#i-dialog").css("height",height);

			$("#i-dialog").css("left",m_left);
			$("#i-dialog").css("top",m_top);	
			
			$("#i-dialog-content").html(text)
			$("#i-dialog").css("display","block");	


}

function showKuponForm(){
	var text="<form  method='post' id='message-form' ENCTYPE='multipart/form-data' class='message-form' onSubmit='return sendKupon();'>"+
"<div align='center'><h3>Купон на скидку 20%</h3><div id='i-dialog-message'></div>"+
"<dl class='field-mail'><dd><label for='title_s' class='overlabel'>Фамилия</label><input type='text' id='lname_s' class='type-text' value='' name='lname_s' maxlength='30' style='width:366px;'/></dd></dl>"+
"<dl class='field-mail'><dd><label for='title_s' class='overlabel'>Имя</label><input type='text' id='fname_s' class='type-text' value='' name='fname_s' maxlength='30' style='width:366px;'/></dd></dl>"+
"<dl class='field-mail'><dd><label for='title_s' class='overlabel'>Отчество</label><input type='text' id='mname_s' class='type-text' value='' name='mname_s' maxlength='30' style='width:366px;'/></dd></dl>"+
"<dl class='field-mail'><dd><label for='title_s' class='overlabel'>Модель</label><input type='text' id='model_s' class='type-text' value='' name='model_s' maxlength='100' style='width:366px;'/></dd></dl>"+
"<dl class='field-mail'><dd><label for='email_s' class='overlabel'>Гос.номер</label><input type='text' id='number_s' class='type-text' value='' name='number_s' maxlength='15' style='width:366px;'/></dd></dl>"+

"<div><input type='submit' class='type-button' value='Отправить' ></div></form>";

			var width=516;
			var height=560;
			m_top = document.body.scrollTop+30;
			m_left = (document.body.clientWidth-width)/2;
			
			
			$("#i-dialog").css("width",width);
			$("#i-dialog").css("height",height);

			$("#i-dialog").css("left",m_left);
			$("#i-dialog").css("top",m_top);	
			
			$("#i-dialog-content").html(text)
			$("#i-dialog").css("display","block");	


}

function sendMessage(){
		$.each($("#message-form :input"),function() {  
				$(this).removeClass('error');
		}); 
		
		JsHttpRequest.query(
			'/include/js_back.php', // backend
			{
				// pass a text value 
				'a': 'sendmessage',
				'form':document.getElementById('message-form')	
			},
			// Function is called when an answer arrives. 
			function(result, errors) {
						if (result["error"]>0){
							$('#i-dialog-message').html(result["message"]);
							$('#i-dialog-message').show();
							if (result["error"]==3)
								$("#email_s").addClass('error') ;
						}else{
								hideCallDialog();
						}

			},
			true  // do not disable caching
		);
		return false;
}

function sendCall(){
		$.each($("#call-form :input"),function() {  
				$(this).removeClass('error');
		}); 
		
		JsHttpRequest.query(
			'/include/js_back.php', // backend
			{
				// pass a text value 
				'a': 'sendcall',
				'form':document.getElementById('call-form')	
			},
			// Function is called when an answer arrives. 
			function(result, errors) {
						if (result["error"]>0){
							$('#i-dialog-message').html(result["message"]);
							$('#i-dialog-message').show();
						}else{
								hideCallDialog();
						}

			},
			true  // do not disable caching
		);
		return false;
}

function sendKupon(){
		$.each($("#message-form :input"),function() {  
				$(this).removeClass('error');
		}); 
		
		JsHttpRequest.query(
			'/include/js_back.php', // backend
			{
				// pass a text value 
				'a': 'sendkupon',
				'form':document.getElementById('message-form')	
			},
			// Function is called when an answer arrives. 
			function(result, errors) {
						if (result["error"]>0){
							$('#i-dialog-message').html(result["message"]);
							$('#i-dialog-message').show();
						}else{
								hideCallDialog();
								var x = (screen.availWidth - 900)/2;	
								window.open('/kupon.php','changecat','height=600,width=700,top=20,left='+x+',toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no,titlebar=no');
						}

			},
			true  // do not disable caching
		);
		return false;
}

function sendTestDrive(){
		$.each($("#message-form :input"),function() {  
				$(this).removeClass('error');
		}); 
		
		JsHttpRequest.query(
			'/include/js_back.php', // backend
			{
				// pass a text value 
				'a': 'sendtestdrive',
				'form':document.getElementById('message-form')	
			},
			// Function is called when an answer arrives. 
			function(result, errors) {
						if (result["error"]>0){
							$('#i-dialog-message').html(result["message"]);
							$('#i-dialog-message').show();
						}else{
								hideCallDialog();
						}

			},
			true  // do not disable caching
		);
		return false;
}

function showTestdriveForm(){
	var text="<form  method='post' id='message-form' ENCTYPE='multipart/form-data' class='message-form' onSubmit='return sendTestDrive();'>"+
"<div align='center'><h3>Запись на Тестдрайв</h3><div id='i-dialog-message'></div>"+
"<dl class='field-mail'><dd><label for='title_s' class='overlabel'>Имя</label><input type='text' id='fname_s' class='type-text' value='' name='fname_s' maxlength='30' style='width:366px;'/></dd></dl>"+
"<dl class='field-mail'><dd><label for='title_s' class='overlabel'>Телефон</label><input type='text' id='phone_s' class='type-text' value='' name='phone_s' maxlength='30' style='width:366px;'/></dd></dl>"+
"<dl class='field-mail'><dd><label for='title_s' class='overlabel'>Модель</label><input type='text' id='model_s' class='type-text' value='' name='model_s' maxlength='100' style='width:366px;'/></dd></dl>"+
"<dl class='field-mail'><dd><label for='email_s' class='overlabel'>Дата дд.мм.гггг</label><input type='text' id='date_s' class='type-text' value='' name='date_s' maxlength='20' style='width:366px;'/></dd></dl>"+

"<div><input type='submit' class='type-button' value='Отправить' ></div></form>";

			var width=516;
			var height=490;
			m_top = document.body.scrollTop+30;
			m_left = (document.body.clientWidth-width)/2;
			
			
			$("#i-dialog").css("width",width);
			$("#i-dialog").css("height",height);

			$("#i-dialog").css("left",m_left);
			$("#i-dialog").css("top",m_top);	
			
			$("#i-dialog-content").html(text)
			$("#i-dialog").css("display","block");	


}

function showProkatForm(){
	var text="<form  method='post' id='message-form' ENCTYPE='multipart/form-data' class='message-form' onSubmit='return sendProkat();'>"+
"<div align='center'><h3>Запись на прокат автомобиля</h3><div id='i-dialog-message'></div>"+
"<div class='scroll' id='scroll-content' style='height:350px; margin-top:10px'>"+
"<dl class='field-mail'><dd><label for='title_s' class='overlabel'>Фамилия</label><input type='text' id='lname_s' class='type-text' value='' name='lname_s' maxlength='30' style='width:366px;'/></dd></dl>"+
"<dl class='field-mail'><dd><label for='title_s' class='overlabel'>Имя</label><input type='text' id='fname_s' class='type-text' value='' name='fname_s' maxlength='30' style='width:366px;'/></dd></dl>"+
"<dl class='field-mail'><dd><label for='title_s' class='overlabel'>Отчество</label><input type='text' id='mname_s' class='type-text' value='' name='mname_s' maxlength='30' style='width:366px;'/></dd></dl>"+
"<dl class='field-mail'><dd><label for='title_s' class='overlabel'>Дата рождения</label><input type='text' id='bday_s' class='type-text' value='' name='bday_s' maxlength='30' style='width:366px;'/></dd></dl>"+
"<dl class='field-mail'><dd><label for='title_s' class='overlabel'>Адрес места жительства</label><input type='text' id='address_s' class='type-text' value='' name='address_s' maxlength='255' style='width:366px;'/></dd></dl>"+
"<dl class='field-mail'><dd><label for='title_s' class='overlabel'>Паспорт №</label><input type='text' id='passport_s' class='type-text' value='' name='passport_s' maxlength='30' style='width:366px;'/></dd></dl>"+
"<dl class='field-mail'><dd><label for='title_s' class='overlabel'>Когда и кем выдан</label><input type='text' id='passportdate_s' class='type-text' value='' name='passportdate_s' maxlength='255' style='width:366px;'/></dd></dl>"+
"<dl class='field-mail'><dd><label for='title_s' class='overlabel'>Водительское удостоверение №</label><input type='text' id='license_s' class='type-text' value='' name='license_s' maxlength='30' style='width:366px;'/></dd></dl>"+
"<dl class='field-mail'><dd><label for='title_s' class='overlabel'>Когда и кем выдан</label><input type='text' id='licensedate_s' class='type-text' value='' name='licensedate_s' maxlength='255' style='width:366px;'/></dd></dl>"+
"<dl class='field-mail'><dd><label for='title_s' class='overlabel'>Телефон</label><input type='text' id='phone_s' class='type-text' value='' name='phone_s' maxlength='100' style='width:366px;'/></dd></dl>"+
"<dl class='field-mail'><dd><label for='title_s' class='overlabel'>Эл.почта</label><input type='text' id='email_s' class='type-text' value='' name='email_s' maxlength='100' style='width:366px;'/></dd></dl>"+
"<dl class='field-mail'><dd><label for='title_s' class='overlabel'>Модель</label><input type='text' id='model_s' class='type-text' value='' name='model_s' maxlength='100' style='width:366px;'/></dd></dl>"+
"<dl class='field-mail'><dd><label for='title_s' class='overlabel'>С какого числа</label><input type='text' id='datefrom_s' class='type-text' value='' name='datefrom_s' maxlength='20' style='width:366px;'/></dd></dl>"+
"<dl class='field-mail'><dd><label for='email_s' class='overlabel'>По какое число</label><input type='text' id='dateto_s' class='type-text' value='' name='dateto_s' maxlength='20' style='width:366px;'/></dd></dl>"+

"</div><div><input type='submit' class='type-button' value='Отправить' ></div></form>";

			var width=516;
			var height=490;
			m_top = document.body.scrollTop+30;
			m_left = (document.body.clientWidth-width)/2;
			
			
			$("#i-dialog").css("width",width);
			$("#i-dialog").css("height",height);

			$("#i-dialog").css("left",m_left);
			$("#i-dialog").css("top",m_top);	
			
			$("#i-dialog-content").html(text)
			$("#i-dialog").css("display","block");	


}
function sendProkat(){
		$.each($("#message-form :input"),function() {  
				$(this).removeClass('error');
		}); 
		
		JsHttpRequest.query(
			'/include/js_back.php', // backend
			{
				// pass a text value 
				'a': 'sendprokat',
				'form':document.getElementById('message-form')	
			},
			// Function is called when an answer arrives. 
			function(result, errors) {
						if (result["error"]>0){
							$('#i-dialog-message').html(result["message"]);
							$('#i-dialog-message').show();
						}else{
								hideCallDialog();
						}

			},
			true  // do not disable caching
		);
		return false;
}

function sendZapis(){
		$.each($("#message-form :input"),function() {  
				$(this).removeClass('error');
		}); 
		
		JsHttpRequest.query(
			'/include/js_back.php', // backend
			{
				// pass a text value 
				'a': 'sendzapis',
				'form':document.getElementById('message-form')	
			},
			// Function is called when an answer arrives. 
			function(result, errors) {
						if (result["error"]>0){
							$('#i-dialog-message').html(result["message"]);
							$('#i-dialog-message').show();
						}else{
								hideCallDialog();
						}

			},
			true  // do not disable caching
		);
		return false;
}

function showZapisForm(){
	var text="<form  method='post' id='message-form' ENCTYPE='multipart/form-data' class='message-form' onSubmit='return sendZapis();'>"+
"<div align='center'><h3>Запись на ремонт и ТО</h3><div id='i-dialog-message'></div>"+
"<div class='scroll' id='scroll-content' style='height:420px; margin-top:10px'>"+
"<dl class='field-mail'><dd><label for='title_s' class='overlabel'>Имя</label><input type='text' id='fname_s' class='type-text' value='' name='fname_s' maxlength='30' style='width:366px;'/></dd></dl>"+
"<dl class='field-mail'><dd><label for='title_s' class='overlabel'>Телефон</label><input type='text' id='phone_s' class='type-text' value='' name='phone_s' maxlength='40' style='width:366px;'/></dd></dl>"+
"<dl class='field-mail'><dd><label for='email_s' class='overlabel'>Дата</label><input type='text' id='data_s' class='type-text' value='' name='data_s' maxlength='15' style='width:366px;'/></dd></dl>"+
"<dl class='field-mail'><dd><label for='title_s' class='overlabel'>Модель</label><input type='text' id='model_s' class='type-text' value='' name='model_s' maxlength='100' style='width:366px;'/></dd></dl>"+
"<dl class='field-mail'><dd><label for='email_s' class='overlabel'>VIN</label><input type='text' id='number_s' class='type-text' value='' name='number_s' maxlength='100' style='width:366px;'/></dd></dl>"+
"<dl class='field-mail'><dd><label for='email_s' class='overlabel'>Описание неисправности</label><textarea id='description_s' class='type-text' name='description_s' style='width:366px;height:100px;'></textarea></dd></dl>"+

"</div><div><input type='submit' class='type-button' value='Записаться' ></div></form>";

			var width=516;
			var height=560;
			m_top = document.body.scrollTop+30;
			m_left = (document.body.clientWidth-width)/2;
			
			
			$("#i-dialog").css("width",width);
			$("#i-dialog").css("height",height);

			$("#i-dialog").css("left",m_left);
			$("#i-dialog").css("top",m_top);	
			
			$("#i-dialog-content").html(text)
			$("#i-dialog").css("display","block");	


}


function numfor(n,d)
{
	var i=0;
	var _i=0;
	var p=0;
	var pp=0;
	var t=0;
	t=n;

	if (t=='') return '';

	t=Math.round(t*Math.pow(10,d))/Math.pow(10,d);
	
	t=t.toString();
	p=t.indexOf('.');
	if (p==-1)
		if (d>0)
		{
			t=t+'.';
			for (i=0;i<d;i++) t=t+'0';
			pp=t.length-d-1;
		}
		else
			pp=t.length;
	else
	{
		for (i=t.length-p-1;i<d;i++) t=t+'0';
		pp=p;
	}

	if (t.charAt(0)=='-') _i=1;
	for (i=pp-3;i>_i;i=i-3) t=t.substr(0,i)+' '+t.substring(i); 
	return t.replace('.',',');
}