var CurPage=1;

function OpenCart(Lang)
{
	CurPage=1;
	$('#overlay').removeAttr('style').hide().fadeIn();
	$('#cart_content').load('/index.php?obj=site&cmd=cart_list&lng='+Lang);
	$('#cart_container').removeAttr('style').hide().fadeIn();
}

function OpenCartEnd(Status, Lang)
{
	CurPage=7;
	$('#overlay').removeAttr('style').hide().fadeIn();
	$('#cart_content').load('/index.php?obj=site&cmd=cart_end&status='+Status+'&lng='+Lang);
	$('#cart_container').removeAttr('style').hide().fadeIn();
}

function CloseCart()
{
	//$('#overlay').effect('fade');
	//$('#cart_container').effect('fade');
	$('#overlay').fadeOut();
	$('#cart_container').fadeOut();
}

function DeleteItem(idprod)
{
	$('#item_'+idprod).fadeOut();
	jQuery.get('/index.php?obj=service&cmd=cart_update&action=del&idprod='+idprod, function() {
		jQuery.get('/index.php?obj=service&cmd=cart_info&info=hp', function(data) {
			Ret=eval('(' + data + ')');
			$('#cart_pricebox_total_value').html(Ret['header']['total']);
			$('#cart_item_number').html(Ret['header']['nItems']);
		});
	});
}

function AddItem(idprod, item_qty, item_price)
{
	jQuery.get('/index.php?obj=service&cmd=cart_update&action=add&idprod='+idprod, function() {
		jQuery.get('/index.php?obj=service&cmd=cart_info&info=hp&idprod='+idprod, function(data) {
			Ret=eval('(' + data + ')');
			$('#cart_qty_'+idprod).html(Ret['item']['qty']);
			$('#cart_price_'+idprod).html(Ret['item']['total']);
			$('#cart_pricebox_total_value').html(Ret['header']['total']);
			$('#cart_item_number').html(Ret['header']['nItems']);
		});
	});	
}

function SubItem(idprod, item_qty, item_price)
{
	if ($('#cart_qty_'+idprod).html()=='1')
	{
		DeleteItem(idprod);
	}
	else
	{
		jQuery.get('/index.php?obj=service&cmd=cart_update&action=sub&idprod='+idprod, function() {
			jQuery.get('/index.php?obj=service&cmd=cart_info&info=hp&idprod='+idprod, function(data) {
				Ret=eval('(' + data + ')');
				$('#cart_qty_'+idprod).html(Ret['item']['qty']);
				$('#cart_price_'+idprod).html(Ret['item']['total']);
				$('#cart_pricebox_total_value').html(Ret['header']['total']);
				$('#cart_item_number').html(Ret['header']['nItems']);
			});
		});	
	}
}

function CheckServices()
{
	$('#cart_services_form').submit();
}

function CheckPayType(ErrMsg, Lang)
{
	if ($('#cart_paytype_cc').attr('checked') || 
			$('#cart_paytype_pp').attr('checked') || 
			$('#cart_paytype_bt').attr('checked') || 
			$('#cart_paytype_cash').attr('checked'))
	{
		$('#cart_paytype_form').submit();
		CartMove('next', Lang);
		return true;
	}
	else
	{
		alert(ErrMsg);
		return false;
	}	
}

function CheckBilling()
{
	if (ValidateForm(document.getElementById('cart_billing_form')))
	{
		$('#cart_billing_form').submit();
		if ($('#delivery_specify').attr('checked'))
		{
			//CartMove('next');
		}
		else
		{
			CurPage++;
			//CartMove('next');
		}
	}
	else
	{
		CurPage--;
		return false;
	}
}

function CheckDelivery(ErrMsg)
{
	if (ValidateForm(document.getElementById('cart_delivery_form')))
	{
		$('#cart_delivery_form').submit();
	}
}

function CheckSummary(ErrMsg, Lang, PayType)
{
	if ($('#cart_condiction1').attr('checked'))
	{
		if (PayType=='cc')
		{
			jQuery.get('/index.php?obj=site&cmd=cart_pay&lng='+Lang, function(data) {
				document.location.href=data;
				});
		}
		else
		{
			CartMove('next', Lang);
		}
	}
	else
	{
		alert(ErrMsg);
		return false;		
	}
}

function CartMove(dir, Lang)
{
	$('#cart_content').html('');
	switch(dir)
	{
		case 'prev':
			CurPage--;
			break;
		case 'next':
			CurPage++;
			break;
		default:
			exit();
	}

	if (CurPage<=0 || CurPage>7)
	{
		CurPage=1;
	}

	switch(CurPage)
	{
		case 1:
			$('#cart_content').css('width', '570px');
			$('#cart_content').load('/index.php?obj=site&cmd=cart_list&lng='+Lang);
			break;
		case 2:
			$('#cart_content').css('width', '570px');
			$('#cart_content').load('/index.php?obj=site&cmd=cart_services&lng='+Lang);
			break;
		case 3:
			$('#cart_content').css('width', '570px');
			$('#cart_content').load('/index.php?obj=site&cmd=cart_paytype&lng='+Lang);
			break;
		case 4:
			$('#cart_content').css('width', '100%');
			$('#cart_content').load('/index.php?obj=site&cmd=cart_billing&lng='+Lang);
			break;
		case 5:
			$('#cart_content').css('width', '100%');
			$('#cart_content').load('/index.php?obj=site&cmd=cart_delivery&lng='+Lang);
			break;
		case 6:
			$('#cart_content').css('width', '570px');
			$('#cart_content').load('/index.php?obj=site&cmd=cart_summary&lng='+Lang);
			break;
		case 7:
			$('#cart_content').css('width', '570px');
			$('#cart_content').load('/index.php?obj=site&cmd=cart_pay&lng='+Lang);
			break;
	}
	return true;
}

function OpenInfoPopup(Content, Lang)
{
	$('#cart_infopopup_content').html('');
	$('#overlay').css('z-index', 30);
	$('#cart_infopopup_container').removeAttr('style').hide().fadeIn();
	switch(Content)
	{
		case 'delivery':
			$('#cart_infopopup_content').load('/index.php?obj=site&cmd=delivery&lng='+Lang);
			break;
		case 'payment':
			$('#cart_infopopup_content').load('/index.php?obj=site&cmd=payment&lng='+Lang);
			break;
	}
}

function CloseInfoPopup()
{
	//$('#cart_infopopup_container').effect('fade');	
	$('#cart_infopopup_container').fadeOut();
	if ($('#overlay').css('z-index')==20)
	{
		$('#overlay').fadeOut();
	}
	else
	{
		$('#overlay').css('z-index', 20);
	}
}

function OpenInfo(Content, Lang)
{
	$('#cart_infopopup_content').html('');
	$('#overlay').removeAttr('style').hide().fadeIn();
	$('#cart_infopopup_container').removeAttr('style').hide().fadeIn();
	switch(Content)
	{
		case 'company':
			$('#cart_infopopup_content').load('/index.php?obj=site&cmd=company&lng='+Lang);
			break;
		case 'etiquette':
			$('#cart_infopopup_content').load('/index.php?obj=site&cmd=etiquette&lng='+Lang);
			break;
		case 'legal':
			$('#cart_infopopup_content').load('/index.php?obj=site&cmd=legal&lng='+Lang);
			break;
		case 'contacts':
			$('#cart_infopopup_content').load('/index.php?obj=site&cmd=contacts&lng='+Lang);
			break;
		case 'customers':
			$('#cart_infopopup_content').load('/index.php?obj=site&cmd=customers&lng='+Lang);
			break;
		case 'delivery':
			$('#cart_infopopup_content').load('/index.php?obj=site&cmd=delivery&lng='+Lang);
			break;
		case 'payment':
			$('#cart_infopopup_content').load('/index.php?obj=site&cmd=payment&lng='+Lang);
			break;
		case 'storelocator':
			$('#cart_infopopup_content').load('/index.php?obj=site&cmd=storelocator&lng='+Lang);
			break;
		case 'myashanti':
			$('#cart_infopopup_content').load('/index.php?obj=site&cmd=myashanti&lng='+Lang);
			break;

	}
}

function CheckContacts()
{
	if (ValidateForm(document.getElementById('contacts_form')))
	{
		$('#contacts_form').submit();
	}
}

function ChangeVariant(Lang)
{
	$('#price').html(Variants[$('#idprod').val()]);
	$('#box_descr_price').html(Variants[$('#idprod').val()]);
	$('#prod_optionals').load('/index.php?obj=service&cmd=prod&lng='+Lang+'&action=optionals&idprod='+$('#idprod').val());
	initfb();
}
