/*-----------------------------------------------------------------------
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;
		if(document.getElementById('qty_'+itemid))
		{
			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 = tmp_rootpath + "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 pres_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 = "pres_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();
		}
		/* Prescription product is added through search_medicine page only
		if(action == 'ADD')  
		{ 
			form1.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();
}
function negvalue()
{
	
	var qty = document.getElementById('qty_1').value;
	if(isNaN(qty))
	{
		alert("Enter Only Numeric Value for Quantity");
	}
}

function check_pet_practitioner()
{
	if(document.pet_prodcut.uk_practitioner)
	{
		if(document.pet_prodcut.uk_practitioner.checked != true)
		{
			alert("Please confirm you have or intend to obtain a prescription signed by a Vet. We cannot supply prescription medicine without one.");
			document.focus('uk_practitioner');
			return false;
		}
		else
		{
			document.pet_prodcut.submit(); 
			return true;	
		}
	}
	else
	{
		document.pet_prodcut.submit(); 
		return true;
	}	
	//return false;
}
