
$(document).ready(function(){
	$('input.rf').keyup(function(){checkfields('rf')});
	
	
/* goods image preview */	
$('ul img').click(function(){
  var path = $(this).parent().attr('href');
  
//  var maxImgUrl = $(this).parent().attr('maxImgUrl');
//  alert($('maxImgUrl').attr('href'));
//  if (maxImgUrl!='') $('maxImgUrl').attr('href') = maxImgUrl;
  
  var alt = $(this).attr('alt');
  var thisImg = $(this);
  $('#goodImgHolder').animate({opacity: 0},100,function(){
	var img =  $(this).html('<img src=' + path + ' />').find('img');														
	$('ul img').show();
	$(thisImg).hide();
    $(img).bind('load',function(){
	  if (alt=="")																			  
	  	$(this).parent().animate({opacity: 1},100);
		else
      $(this).parent().append('<em>' + alt + '</em>').animate({opacity: 1},100);
    });
  });
  return false;
});
//$('ul img:first').hide();
	
});

/*********************************************************************************/
/*********************************************************************************/
/*********************************************************************************/

	


function showRequest(formData, jqForm, options) { 
    var queryString = $.param(formData); 
    alert('передаем: \n\n' + queryString); 
    return true; 
} 

/*********************************************************************************/
/*********************************************************************************/
/*********************************************************************************/

	function checkfields(elcl)
	{
		var empty = false;
		$('input.'+elcl).each(function(n,element){
			if ($(element).val()=='') empty = true;
		});
		if (!empty) $('button.submit').attr("disabled",""); else $('button.submit').attr("disabled","disabled");
	}
	

/*********************************************************************************/

/*********************************************************************************/
function cart_show(step)
{
	var qString = $("#cartOrder").formSerialize();  
	$.get('/script/magazine.script.php','act=show&step='+step+'&'+qString,
			 function (data)
			 {
				$("#cartDetails").html(data);
			 }
		 )
}

function cart_order()
{
//	$("#cartDetails").hide();
	$.get('/script/magazine.script.php','act=order',
			 function (data)
			 {
				$("#cartDetails").html(data);
			 }
		 )
}


function cart_reset()
{
	if (!confirm('Удалить все товары из корзины?')) return;
	$.get('/script/magazine.script.php','act=reset',
			 function (data)
			 {
				$("#cartDetails").html(data);
			 }
		 )
	$.get('/script/magazine.script.php','act=getpreview',
		function (data){$("#cartPreview").html(data);})
}

function cart_change_count(id)
{
	var itemcount  = '#itemcount'+id;
	var count_summ = '#count_summ'+id;
	var count = $(itemcount).val();
	var p = 'act=setcount&id='+id+'&count='+count;
	$.get('/script/magazine.script.php',p,
		function (data){$(count_summ).html(data);})	
	$.get('/script/magazine.script.php','act=recalc',
		function (data){$("#amount").html(data);})	
	$.get('/script/magazine.script.php','act=getpreview',
		function (data){$("#cartPreview").html(data);})
}


function cart_recalc()
{
	$.get('/script/magazine.script.php','act=recalc',
		function (data){$("#amount").html(data);})	
	$.get('/script/magazine.script.php','act=getpreview',
		function (data){$("#cartPreview").html(data);})
}




function cart_del_item(id)
{
	if (!confirm('Удалить товар из корзины?')) return;
	$.get('/script/magazine.script.php','act=delitem&id='+id,
		function (data){$("#cartDetails").html(data);})
	$.get('/script/magazine.script.php','act=getpreview',
		function (data){$("#cartPreview").html(data);})
}

function cart_add(good)
{
	var qString = $("#"+good).formSerialize();  
	$.get('/script/magazine.script.php',qString+'&act=add',
			 function (data)
			 {
				$("#cartDetails").html(data);
				alert('Товар добавлен в корзину. \n\n Количество товара можно изменить в корзине.');
			 }
		 )
	$.get('/script/magazine.script.php','act=getpreview',
		function (data){$("#cart").html(data);})
	
    return false;
}





