
/*-----------------------------------------------------------------------
Created by: Rajendra
Created date: 16 Oct 2008
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, form_name)
{
	var proceed = 1;
	
	if(form_name == null || form_name.length == 0)
		frmsb = 0;
	else
		frmsb = 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)
		{		
				
		if(tmp_rootpath.indexOf('registration')>0)
			{
					//alert('registration');
					shop_tmp_rootpath = tmp_rootpath.replace('registration/','');
					PageFrom	="registration";
			}
			else
			{
				//	alert('here'+tmp_rootpath);
					shop_tmp_rootpath = tmp_rootpath;
					PageFrom	="";
			}
			cart_form.action =  shop_tmp_rootpath +"do_cart.php";	
			//alert(cart_form.action);
			cart_form.cart_action.value = action;
			cart_form.cart_pid.value = pid;
			cart_form.PagecomesFrom.value =PageFrom;
			cart_form.cart_qty.value = qty;
			cart_form.to_id.value = to_id;
			cart_form.submit();
		}
	}
}

function pres_doCart(action, itemid)
{	

	var proceed = 1;
	var cart_form = document.frmcart;
	if (!isWhitespace(action) && !isWhitespace(itemid))
	{
		
		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 pres_doCartnew(action, itemid)
{	


	
	var proceed = 1;

	if ((action=='ADD')&&(itemid>0))
	{
		
		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(qty==0)
	{
		alert("Product Quantity can not be 0");
		return false;
	}
	else if(!isCharsInBag(qty,"0123456789"))
	{
		alert("Enter Only Numeric Value for Quantity");
		return false;
	}
	return true;
}

function remove_wl(itemid)
{
	if (confirm('Do you really want to remove this product?'))
	{
		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.pet_prodcut.uk_practitioner.focus();
			//document.focus('uk_practitioner');
			return false;
		}
		else
		{
			document.pet_prodcut.submit(); 
			return true;	
		}
	}
	else
	{
		document.pet_prodcut.submit(); 
		return true;
	}	
	//return false;
}
