// JavaScript Document
var Tim;
var Tim2;

function smallCalc(id) {
	
	var pl = $('kolvo'+id).value;
	var price = $('prc'+id).value;
	var koef; // = $('koefic'+id).value;
	var allKoef = $A($$('input[name="radioButton'+id+'"]'));
	
	allKoef.each(function(item) {
		if (item.checked) {
			koef = item.value;
		}
	});
	
	if (isFinite(pl)) {
		var summ   = pl*koef*price;
		var valueId= $('allID').value;
		var sumAll = $('allPriceNested').value;
		sumAll = sumAll.replace(' руб.','');
		var sumOne = $('price'+id).value;
		sumOne = sumOne.replace(' руб.','');
		var pos    = valueId.indexOf(id);
		
		if (pos) {
			sumAll -= sumOne;
			sumAll += summ;
		} else {
			valueId += ', '+id;
		}
		
		$('allID').value = valueId;
		$('price'+id).value = summ.toFixed(2)+' руб.';
		$('allPriceNested').value = sumAll.toFixed(2)+' руб.';
		
/*
	var myAjax = new Ajax.Request(
 
    url+'catalog/count/', 
 
	{	method: 'post', 
		parameters: {period: period, marka: marka },
		onComplete: showResponse}
    );
   /**/ 
	} 
}


function checkRadio(id) {
	$(id).checked = true;
}

function checkDiv(id) {
	if ($(id).style.display == 'none') {
		$(id).style.display = 'block';
	} else 	{
		$(id).style.display = 'none';
	}	
}

function checkDiv2(id) {
	var allKoef = $A($$('div[name="description"]'));
	allKoef.each(function(item) {
		if (item.id != id) {
			if (item.style.display == 'block') {
				item.style.display = 'none';
			}	
		}	
	});
	
	if ($(id).style.display == 'none') {
		$(id).style.display = 'block';
	} else 	{
		$(id).style.display = 'none';
	}	
}

function checkSubscribeForm(){
	var email = document.getElementById('email');
	if(!checkEmail(email.value)){
			alert('Не введен или введен некорректный e-mail');
			email.focus();
			return false;
		}
	else return true;
}


function checkEmail(email) {
	if(!email) return email;
	if(!email.match(/^[\w\.\-]+@[\w\.\-]+\.[a-zA-Z]{2,}$/i, "")) return false;
	return true;
}

function checkFeedbackForm(){
	var required = {
		"name"		:	"Вы не ввели Ваше ФИО",
		"email"		:	"Не введен или введен некорректный e-mail",
		"msg"		:	"Вы не ввели сообщение"
	};

	for (i in required) {
		var el = document.getElementById(i);
		if(el.id == 'email' && el.value && !checkEmail(el.value)){
			alert(required['email']);
			el.focus();
			return false;
		};
		if (!el.value) {
			alert(required[i]);
			el.focus();
			return false;
		}
	}
	return true;
}


function checkStrSearch() {
	var str = document.getElementById('srch');
	if((str.value.length) < 3) {
		alert('Длина поисковой фразы должна быть больше 3 символов');
		str.focus();
		return false;
	} 
	else return true;
}
