function gotolink(link){
	document.location=link;
}


function show_div(id)
{
	var div;
	div = document.getElementById(id);
	if ( div.style.display == "none" ) div.style.display = "block";
		else div.style.display = "none";
}


////////////////------считает общую цену и количество единиц товара
function Count(form, infoprice, infoamount)
{
	var Amount = 0;
	var Price = 0;
	var ss = "";

	InputsCollection = document.getElementsByTagName("INPUT");

	for (i=0; i<InputsCollection.length; i+=1)
	{
		CurrentInputID = InputsCollection[i].id;
		if (CurrentInputID.indexOf('count_id') >= 0)
		{
			eval('CurrentCount = document.getElementById(\'' + CurrentInputID + '\');');

			ss = new String(CurrentInputID); //определяем id инпута
			ss = ss.substr(8,ss.length);

			eval('var CurrentCheck = document.getElementById(\'check_id' + ss + '\');');

			if ( parseInt(CurrentCount.value) > 0 )
			{
				eval('var CurrentPrice = document.getElementById(\'price_id' + ss + '\');');
				
				if (!CurrentCheck.checked)
				{//если выделили (поставили флажок), то приплюсовывать цену и количество
					Amount += parseInt(CurrentCount.value);
					Price += (CurrentPrice.value) * (CurrentCount.value);
//					eval('document.getElementById(\'prcount_id'+ss+'\').innerHTML = (CurrentPrice.value * CurrentCount.value);');
					
					eval('document.getElementById(\'prcount_id'+ss+'\').innerHTML = \'\'+(CurrentPrice.value * CurrentCount.value).toFixed()+\'\'');

/*					CurrentCount.style.color = "#DB0A56";
					CurrentCount.style.backgroundColor = "#EEEEEE";
					CurrentCount.style.fontWeight = "bold";*/
				}
			}
		}
	}

	Price = Price.toFixed();

	eval('document.'+form+'.'+infoprice+'.value = Price;');
	eval('document.'+form+'.'+infoamount+'.value = Amount;');
	$('#itogo').html('Итого: '+Price+'');
}




function post_to_del()
{
	document.getElementById("show_table").value=1;
	document.cartlist.submit();
}


function check_count(id, count)
{
	var c = parseInt(document.getElementById("count_id"+id).value);
	if( document.getElementById("kolonfirm_id"+id).value < c)
	{
		document.getElementById("count_id"+id).value = count;
		alert("Количество товара недопустимо, для заказа необходимо связаться с менеджером");
	}
}
///////


var sex_param = "0";
var reason_param = "";
var search_link = "";

function generate_search_link(){
	return "/search/"+sex_param+"/"+reason_param+"/";
}

function init()
{
	$('.cat_logo').click(
		function(){
			id = $(this).attr('num');
			prod = $(this).attr('prod');
			$('.start_prod_block').hide();
			$('#start_prod_block'+prod).show();
			
			$("#logos_block p").removeClass('mact');
			$(this).parent().addClass('mact');
			
			$('.cat_logo').each(function(){
				$(this).attr('src', $(this).attr('hout') );
			});
			$(this).attr('src', $(this).attr('hover') );
			
			$.ajax({
				url: "/inc/refresh_colors.php?cat_id="+id,
				cache: false,
				success:refresh_colors_block
			});
		}
	);

	function refresh_colors_block(data)
	{
		$("#colors_block").html(data);
		init();
	}
	
	$('.color_selector').click(
		function(){			
			id = $(this).attr('num');
			$('.start_prod_block').hide();
			$('#start_prod_block'+id).show();
			$("#colors_block p").removeClass('cact');
			$(this).parent().addClass('cact');
		}
	);
	
}


$(document).ready(function(){
//	reason_param = $('#reason_select option:selected').val();
	
	jQuery("a[rel^='prettyPhoto']").prettyPhoto({theme:'facebook'});



	$('.only_nums').keypress(function(evt){
		 var charCode = (evt.which) ? evt.which : event.keyCode;
		 if (charCode!=13 && charCode!=9 && charCode!=8 && /*charCode!=46 && */charCode!=36 && charCode!=35 && charCode!=37  && charCode!=39 && charCode!=0 && (charCode<48 || charCode>57) )
			 return false;
		 return true;
	});

	$('#but_show_form').click(
		function(){
			gotolink('/cart/#order_form');
			$('#form_block').fadeIn(200);
	});

	
	init();







});


