
function add_tov(id,price,count_) 
{
	var count=prompt ("Введите нужное количество товара", "1");
	if(count == 0)
	{
		count=1;
	}

//	if(count > count_)
//	{
//		alert('Такого количества товаров нет в наличии на складе.');
//		count=count_;
//	}
	
//        alert('basket'+id);
//	document.getElementById('basket'+id).src="/images/basket1.jpg";
//	alert(id+','+price);
	updateTov(id, count);	
}

// изменение товаров в заказе
function updateTov(good, count)
{
//	alert('city='+city+'&sklad='+sklad+'&tov='+tov+'&count='+count+'&price1='+price1+'&price2='+price2+'&price3='+price3);
	
	var intValue=parseInt(count);
	
	if (isNaN(intValue)) {
		//alert('not int');
	}
	else {
//alert('ok');
//		$('div#my_recycle').load('/addtov.php?good='+good+'&count='+count);
	$.getJSON('/addtov.php?good='+good+'&count='+count, {}, function(obj) {
            $('#count_tov').text(obj.count_tov);
            $('#summa').text(obj.summa);
            $('#summa_total').text(obj.summa);
        });
//alert('ok');
	}

}

function countTov(id, count_) {

	var count = document.getElementById('count_'+id).value;
	count = parseInt(count);
	count_ = parseInt(count_);

//alert(count +' > '+count_);
	if (count > count_) {
		alert('Такого количества товаров нет в наличии на складе.');
		document.getElementById('count_'+id).value = count_;
		count = count_;
	}

	
// проверка на целое число
//alert(count);

var intValue=parseInt(count);
	
	if (isNaN(intValue)) {
		document.getElementById('count_'+id).value = 1;	
	}
	else {
		document.getElementById('summa_'+id).innerHTML = count*document.getElementById('price_'+id).innerHTML;

//		alert('/updatecount.php?good='+id);
		$.getJSON('/updatecount.php?good='+id+'&count='+count, {}, function(obj) {
        	    $('#count_tov').text(obj.count_tov);
//        	    alert(obj.summa);
	            $('#summa').text(obj.summa);
	            $('#summa_total').text(obj.summa);
        	});
	}
//	$("#recycle b").each(updatePrice); // передаем в each функцию расчета сумм
	
}


// изменение доставки
function updateDelivery(id)
{
//alert('ok');
	$.getJSON('/updateDelivery.php?id='+id, {}, function(obj) {
            $('#summa_total').text(obj.summa);
        });
//alert('ok');

}

function showZayav() {
	if (document.getElementById('div_zayav').style.display=='') {
		document.getElementById('div_zayav').style.display='none'; 
	}
	else {
		document.getElementById('div_zayav').style.display=''; 
	}
}

function showForgotPass() {
	if (document.getElementById('div_enter').style.display=='') {
		document.getElementById('div_enter').style.display='none'; 
		document.getElementById('div_email').style.display=''; 
	}
	else {
		document.getElementById('div_enter').style.display=''; 
		document.getElementById('div_email').style.display='none'; 
	}
}

// изменение способа оплаты в заказе
function updateTypeOrder(id,type)
{

		var req = new Subsys_JsHttpRequest_Js();
		req.onreadystatechange = function()
		{if (req.readyState == 4)
//		alert(req.readyState);
		{if (req.responseJS)
			{
			}
		}
		}
		req.caching = true;
		req.open('POST', '/updatetypeorder.php?id='+id+'&type='+type, true);
//	alert('/updatetypeorder.php?id='+id+'&type='+type);
		req.send({ q: id, test:303 });


}


// регистрация посетителя
function regUser()
{
var fio = document.form_reg.fio.value;
var address = document.form_reg.address.value;
var email = document.form_reg.email.value;
var phone = document.form_reg.phone.value;

if ((fio!='') & (address!='') & (email!='') & (phone!='')) {
		var req = new Subsys_JsHttpRequest_Js();
		req.onreadystatechange = function()
		{if (req.readyState == 4)
//		alert(req.readyState);
		{if (req.responseJS)
			{
				document.getElementById('div_quick_enter').style.display='none';
				document.getElementById('div_order_form').style.display='none';
				document.getElementById('div_form_enter').style.display='';
				document.getElementById('div_registry').style.display='none';
				document.form_enter.email.value = email;
				alert(req.responseJS.list);
			
			}
		}
		}
		req.caching = true;
//		alert('/reg_form.php?fio='+fio+'&address='+address+'&email='+email+'&phone='+phone);
		req.open('POST', '/reg_form.php?fio='+fio+'&address='+address+'&email='+email+'&phone='+phone, true);
		req.send({ q: '', test:303 });
}
else {
	alert('Заполните Ваши данные. \n  Все поля обязательны для заполнения.');
}

}

// регистрация посетителя
function checkUser()
{
var email = document.form_enter.email.value;
var pass = document.form_enter.pass.value;

if ((pass!='') & (email!='')) {
		var req = new Subsys_JsHttpRequest_Js();
		req.onreadystatechange = function()
		{if (req.readyState == 4)
//		alert(req.readyState);
		{if (req.responseJS)
			{
//				alert(req.responseJS.user);
			
				document.getElementById('div_quick_enter').style.display='';
				document.getElementById('div_order_form').style.display='none';
				document.getElementById('div_form_enter').style.display='none';
				document.getElementById('div_registry').style.display='none';
				document.quick_enter.fio.value = req.responseJS.fio;
				document.quick_enter.address.value = req.responseJS.address;
				document.quick_enter.email.value = req.responseJS.email;
				document.quick_enter.phone.value = req.responseJS.phone;
				document.quick_enter.user.value = req.responseJS.user;
			}
		}
		}
		req.caching = true;
//		alert('/check_user.php?email='+email+'&pass='+pass);
		req.open('POST', '/check_user.php?email='+email+'&pass='+pass, true);
		req.send({ q: '', test:303 });

}
else {
	alert('Заполните Email и пароль. \n  Все поля обязательны для заполнения.');
}

}

// регистрация посетителя
function forgotPass()
{
var email = prompt ("Введите Ваш email", "");

		var req = new Subsys_JsHttpRequest_Js();
		req.onreadystatechange = function()
		{if (req.readyState == 4)
//		alert(req.readyState);
		{if (req.responseJS)
			{
				alert(req.responseJS.result);
			
			}
		}
		}
		req.caching = true;
//		alert('/check_user.php?email='+email+'&pass='+pass);
		req.open('POST', '/forgot.php?email='+email, true);
		req.send({ q: '', test:303 });


}


function showDivSendOrder() {
	
		document.getElementById('div_send_order').style.display='';

}


function formEnter() {

//alert(document.form_enter.email.value+' '+document.forms['form_enter'].pass.value);
	if ((document.form_enter.email.value=='') & (document.form_enter.pass.value=='')) {	

		document.getElementById('div_quick_enter').style.display='';
		document.getElementById('div_order_form').style.display='none';
		document.getElementById('div_form_enter').style.display='none';
		document.getElementById('div_registry').style.display='none';
	}
	else {
		checkUser();
	}

	return false;

}

function back4Enter() {
	
		document.getElementById('div_registry').style.display='none';
		document.getElementById('div_quick_enter').style.display='none';
		document.getElementById('div_order_form').style.display='none';
		document.getElementById('div_form_enter').style.display='';

	return false;

}

function showReg() {
	
		document.getElementById('div_registry').style.display='';
		document.getElementById('showhelp').style.display='none';
		document.getElementById('div_quick_enter').style.display='none';
		document.getElementById('div_order_form').style.display='none';
		document.getElementById('div_form_enter').style.display='none';

}

function checkForm() {
	
	if ( (document.orderForm.user.value == 0) & (document.orderForm.user.value == '') ) {
		document.getElementById('div_order_form').style.display='none';
		document.getElementById('div_form_enter').style.display='';
	}
	else {
	}

	return false;

}

function sendOrder() {
	
	if ( (document.quick_enter.fio.value != '') &  (document.quick_enter.address.value != '') &  (document.quick_enter.phone.value != '') ) {
		document.forms['quick_enter'].summa.value = document.forms['recycle'].summa.value;
//		alert(document.quick_enter.summa.value);

		document.quick_enter.submit();
		return true;
	}
	else {
	        alert('Для успешого отправления заказа заполните Ваши ФИО, адрес доставки и телефон.');
		return false;
	}


}


function showHelp() { //v3.0
	document.getElementById('showhelp').style.display=''; 
}

