function validateQuantity1()
{	
	frm = document.frmCart;
	for(var i=0;i<frm.elements.length;i++) 
	{ 
		if(frm.elements[i].type == 'text')
		{
		   if( ! isValidNumber(frm.elements[i].value) )
		   {
				alert('Please enter a valid quantity');
				frm.elements[i].focus();
				return false;
		   }
		}
	}
	return true;
}

//Function to check valid quantity
function validateQuantity()
{
	var frm 		   = document.frmCart;
	var minPurchaseQty = '';
	var regex		   = /^[0-9]+$/;	
	for(var i=0;i<frm.elements.length;i++) 
	{ 
		if(frm.elements[i].type == 'text')
		{
		   var mat = regex.test(frm.elements[i].value);				
		   if(!mat)
		   {
				alert('Please enter a valid quantity');
				frm.elements[i].focus();
				return false;
		   }
		}
	}
    
	/** if dealer is logged in **/
	if(document.getElementById('logged_user').value == 'dealer')
	{
		/** check if min purchase limi is enables **/
		if(document.getElementById('enable_min_purchase').value == 'enabled')
		{
		 	/** check the quantity **/
			if(! checkDealerQty())
				return false;
		}
	} 
	
	return true;
}

function checkDealerQty()
{
	frm = document.frmCart;
	
	if(document.getElementById('min_purchase_qty'))
		var minPurchaseQty = document.getElementById('min_purchase_qty').value;
		
	for(var i=0;i<frm.elements.length;i++) 
	{ 
		if(frm.elements[i].type == 'text')
		{
		   if( (frm.elements[i].value < parseInt(minPurchaseQty)) )
		   {
				alert('The minimum quantity to be purchased for each item is '+minPurchaseQty+'.');
				frm.elements[i].focus();
				return false;
		   }
		}
	} // end of for
	
	return true;
}

function checkOut()
{
	location.href= SECURE_SITE_PATH+'index.php?file=checkout';
}

function processToPayment()
{
	document.frmCart.action = SECURE_SITE_PATH+'index.php?file=checkout_address';
	document.frmCart.submit();
	document.frmCart.action  = '';
}

function validateShipping()
{
    document.frmShippingDetails.hdnAction.value = 'setShipping';
    document.frmShippingDetails.action = SECURE_SITE_PATH+'index.php?file=shipping';
    document.frmShippingDetails.submit();
    document.frmShippingDetails.action  = '';
}

function showTotalPrice(upsValue)
{
  if(!isBlank(upsValue)) 
  {
     /* split the method and the price */     
     arrShipDetails  = upsValue.split('##');
     shippingRate    = arrShipDetails[1];
     
     if(document.getElementById('span_shipRate'))
     {
        document.getElementById('span_shipRate').innerHTML = shippingRate;
     }
     
     if(document.getElementById('hdnCartTotal'))
     {
        cartTotal = document.getElementById('hdnCartTotal').value;
        finalcartTotal = parseFloat(cartTotal) + parseFloat(shippingRate);
        document.getElementById('span_cartTotal').innerHTML =  finalcartTotal.toFixed(2);
     }
  }
}
