function changeComplect(con, num, firstPrice) {
	if ($('complectCost'+num)) {

		cost = $('complectCost'+num).innerHTML;
		cost = cost.replace('`','');
		cost = cost.replace('р.','');
		cost = cost.replace(' ','');
		cost = cost*1;
		alert(cost);
	}
}

function calcComplect(firstPrice) {
	var i = 0;
	while($('complectCheck'+i)) {
		if ($('complectCheck'+i).checked) {
			cost = $('complectCost'+i).innerHTML;
			cost = cost.replace('`','');
			cost = cost.replace('р.','');
			cost = cost.replace(' ','');
			cost = cost*1;
			firstPrice += cost;
		}
		i++;
	}
	i=0;
	while($('optionCheck'+i)) {
		if ($('optionCheck'+i).checked) {
			cost = $('optionCost'+i).innerHTML;
			cost = cost.replace('`','');
			cost = cost.replace('р.','');
			cost = cost.replace(' ','');
			cost = cost*1;
			firstPrice += cost
		}
		i++;
	}
	if (firstPrice>999999) {
		tmp = Math.floor(firstPrice/1000);
		t = tmp%1000;
		if (t<10) t = '00'+t;
		else if (t<100) t = '0'+t;
		firstPrice = Math.floor(tmp/1000)+'`'+t+'`'+(firstPrice%1000);
	} else if (firstPrice>999) firstPrice = Math.floor(firstPrice/1000)+'`'+(firstPrice%1000);
	
	$('itemPrice').innerHTML = firstPrice;
}


Event.observe(window, 'load', initializeBasket, false);

function initializeBasket(){
	basketForms = document.getElementsByClassName('addBasketForm');
	for(i = 0; i < basketForms.length; i++) {
		
		Event.observe(basketForms[i], 'submit', addBasket.bindAsEventListener(this), false);
		basketForms[i].onsubmit = function(){return false;};
	}
}

function addBasket(useForm) {
	var myAjax = new Ajax.Request(
		 'tools.php',
		{method: 'post', parameters: useForm.target.serialize(), onComplete: changeBasket.bindAsEventListener(this)}
   );
}

function changeBasket(response) {
//	alert(response.responseText);
	data = response.responseText.evalJSON();
	$('basket_cnt').innerHTML = data.basket_cnt;
	$('basket_sum').innerHTML = data.basket_sum;
	alert('Товар успешно добавлен в корзину');
}

function showBrand(a, url) {
	if (a.value) {
		document.location=url+'brand/'+a.value+'.html';
	}
}
