//====================================================================================================
//	Function Name	:	UpdateCart()
//----------------------------------------------------------------------------------------------------
function UpdateCart(frm)
{
	with(frm)
    {
		var flg = true;
		
		if(document.all('product_quantity[]').length)
		{
			for(i=0; i<document.all('product_quantity[]').length; i++)
			{
				product_qty	= +document.all['product_quantity[]'][i].value;	
				
				if(product_qty < product_minqty[i].value && product_qty != 0)
				{
					flg = false;
					alert("Minimum order limit is " +product_minqty[i].value+" for "+product_title[i].value);
					document.all['product_quantity[]'][i].focus();
					return false;
				}
			}
		}
		else
		{
			product_qty	= +document.all['product_quantity[]'].value;	
			
			if(product_qty < product_minqty.value && product_qty != 0)
			{
				flg = false;
				alert("Minimum order limit is " + product_minqty.value+" for "+product_title.value);
				document.all['product_quantity[]'].focus();
				return false;
			}
		}
		
		if(flg == true)
    	{
			Action.value = 'Update';
			submit();
    	}
	}
}

//====================================================================================================
//	Function Name	:	AddCart()
//----------------------------------------------------------------------------------------------------
function AddCart(frm)
{
	with(frm)
    {
		var flg = true;
		
		product_qty = +document.all['product_quantity'].value;	
		pstock 		= +document.all['product_stock'].value;	
		
		if(pstock <= 0)
		{
			alert("Oppsss!!! Product is out of stock!");
			return false;
		}
		if(product_qty == 0)
		{
			alert("Enter product quantity");
			document.all['product_quantity'].focus();
			return false;
		}
		if(product_qty < product_minqty.value && product_qty != 0)
		{
			flg = false;
			alert("Minimum order limit is " + product_minqty.value+" for "+product_title.value);
			document.all['product_quantity'].focus();
			return false;
		}
		
		if(flg == true)
    	{
			Action.value = 'Add';
			submit();
    	}
	}
}

//====================================================================================================
//	Function Name	:	ClearCart()
//----------------------------------------------------------------------------------------------------
function ClearCart()
{
	with(document.frmCart)
    {
		Action.value = 'Clear';
		submit();
    }
}

//====================================================================================================
//	Function Name	:	DeleteCart()
//----------------------------------------------------------------------------------------------------
function DeleteCart(prod_id)
{
	with(document.frmCart)
    {
		pid.value	 =	prod_id;
		Action.value = 'Delete';
		submit();
    }
}

//====================================================================================================
//	Function Name	:	Checkout_Click()
//----------------------------------------------------------------------------------------------------
function Checkout_Click()
{
	with(document.frmCart)
    {
		action = "checkout.php";
		submit();
    }
}

//====================================================================================================
//	Function Name	:	Add_Coupon()
//----------------------------------------------------------------------------------------------------
function Add_Coupon(redirectUrl)
{
	with(document.frmCoupon)
    {
		action = redirectUrl;
		submit();
    }
}

//====================================================================================================
//	Function Name	:	Checkout_Click()
//----------------------------------------------------------------------------------------------------
function AddtoCart_Click(frm,pid)
{
	with(frm)
    {
		var pstock	=	+document.all['product_stock['+pid+']'].value;
		
		if(pstock <= 0)
		{
			alert("Oppsss!!! Product is out of stock!");
			return false;
		}
		else
		{
			action="cart.php"
			submit();
		}
    }
}
