/*-----------------------------------------------------------------------
Created by: Ketan
Created date: 16 July 2007
File description: Shopping Cart Javascript Functions to Add/Update/Remove product from shopping cart
Special instructions-notes:Java script
Tables used: none
Stored procedures: none
Triggers used: none
-----------------------------------------------------------------------*/
function doCart(action, itemid)
{	
	var proceed = 1;
	if (!isWhitespace(action) && !isWhitespace(itemid))
	{
		cart_form = document.frmcart;
		
		var pid=document.getElementById('pid_'+itemid).value;		
		var qty=document.getElementById('qty_'+itemid).value;
		var to_id = 0;
		if(document.getElementById('to_id_'+itemid))		//to_id_ is Temp Order ID
		{
			to_id=document.getElementById('to_id_'+itemid).value;
		}		
		
		//if Action is to Add/Update a cart listing then validate qty else 
		//if user want to remove an item from cart then no need to validate qty field
		if(action != 'REMOVE')
		{
			if(!validateQty(qty))
			{
				proceed = 0;
			}
		}
		if(proceed == 1)
		{
			cart_form.action = "do_cart.php";
			cart_form.cart_action.value = action;
			cart_form.cart_pid.value = pid;
			cart_form.cart_qty.value = qty;
			cart_form.to_id.value = to_id;

			cart_form.submit();
		}
	}
}

function doCart(action, itemid)
{	
	var proceed = 1;
	if (!isWhitespace(action) && !isWhitespace(itemid))
	{
		cart_form = document.frmcart;
		
		var pid=document.getElementById('pid_'+itemid).value;		
		var qty=document.getElementById('qty_'+itemid).value;
		var to_id = 0;
		if(document.getElementById('to_id_'+itemid))		//to_id_ is Temp Order ID
		{
			to_id=document.getElementById('to_id_'+itemid).value;
		}		
		
		//if Action is to Add/Update a cart listing then validate qty else 
		//if user want to remove an item from cart then no need to validate qty field
		if(action != 'REMOVE')
		{
			if(!validateQty(qty))
			{
				proceed = 0;
			}
		}
		if(proceed == 1)
		{
			cart_form.action = "do_cart.php";
			cart_form.cart_action.value = action;
			cart_form.cart_pid.value = pid;
			cart_form.cart_qty.value = qty;
			cart_form.to_id.value = to_id;
			
			cart_form.submit();
		}
	}
}

function validateQty(qty)
{		
	if(isWhitespace(qty))
	{
		alert("Please Enter Quantity");
		return false;
	}
	else if(isNaN(qty))
	{
		alert("Enter Only Numeric Value for Quantity");
		return false;
	}
	else if(qty==0)
	{
		alert("Product Quantity can not be 0");
		return false;
	}
	return true;
}

function remove_wl(itemid)
{
	
	var pid = document.getElementById('pid_'+itemid).value;
	document.frmremovewl.wl_pid.value = pid;
	document.frmremovewl.action = "do_wishlist.php";
	document.frmremovewl.submit();
}