function CheckQuantity(txtQuantity, hdnAvailableQuantity, ddlControl)
{
	if ( ddlControl )
	{
		if ( !CheckNumber(txtQuantity) && !CheckDropDown(ddlControl) )
		{
			alert("Please enter a valid quantity");
			return false;
		}
	}
	else
	{
		if ( !CheckNumber(txtQuantity) )
		{
			alert("Please enter a valid quantity");
			return false;
		}
	}
	
	var iQuantity = 0;
	
	if ( ddlControl )
	{
		iQuantity = (1 * document.getElementById(txtQuantity).value) + (1 * document.getElementById(ddlControl).value);
	}
	else
	{
		iQuantity = 1 * document.getElementById(txtQuantity).value;
	}
		
	if ( hdnAvailableQuantity )
	{
		// alert(document.getElementById(hdnAvailableQuantity));
		var iAvailableQuantity = document.getElementById(hdnAvailableQuantity).value;
		
		if (  iQuantity > iAvailableQuantity )
		{
			alert("Quantity not available.\r\nOnly " + parseInt(document.getElementById(hdnAvailableQuantity).value) + " available.");
			return false;
		}
	}
	
	return true;
}

function CheckQuantityNoZeros(txtQuantity, hdnAvailableQuantity, ddlControl)
{

	if ( ddlControl )
	{
		if ( !CheckNumberNoZeros(txtQuantity) && !CheckDropDown(ddlControl) )
		{
			alert("Please enter a valid quantity");
			return false;
		}
	}
	else
	{
		if ( !CheckNumberNoZeros(txtQuantity) )
		{
			alert("Please enter a valid quantity");
			return false;
		}
	}
	
	var iQuantity = 0;
	
	if ( ddlControl )
	{
		iQuantity = (1 * document.getElementById(txtQuantity).value) + (1 * document.getElementById(ddlControl).value);
	}
	else
	{
		iQuantity = 1 * document.getElementById(txtQuantity).value;
	}
		
	if ( hdnAvailableQuantity )
	{
		// alert(document.getElementById(hdnAvailableQuantity));
		var iAvailableQuantity = document.getElementById(hdnAvailableQuantity).value;
		
		if (  iQuantity > iAvailableQuantity )
		{
			alert("Quantity not available.\r\nOnly " + parseInt(document.getElementById(hdnAvailableQuantity).value) + " available.");
			return false;
		}
	}
	
	return true;





}

function CheckValue(txtQuantity)
{
	if ( !CheckNumber(txtQuantity) )
	{
		alert("Please enter a valid quantity");
		return false;
	}
}

function CheckValueNoZeros(txtQuantity)
{
	if ( !CheckNumberNoZeros(txtQuantity) )
	{
		alert("Please enter a valid quantity");
		return false;
	}
}

function CheckNumberNoZeros(txtQuantity){

	var qty = document.getElementById(txtQuantity).value;
	if( qty == "" )
	{
		
		return false;
	}
		
	exp = /^\s*[-\+]?\d+\s*$/;
	
    if ( qty.match(exp) == null ) 
		return false;
    
    if (isNaN(qty))
		return false;
    
    if ( 1 * qty <= 0 )
		return false;
       
   	return true;

}

function CheckNumber(txtQuantity)
{
	var qty = document.getElementById(txtQuantity).value;
	if( qty == "" )
	{
		document.getElementById(txtQuantity).value = 0;
		return true;
	}
		
	exp = /^\s*[-\+]?\d+\s*$/;
	
    if ( qty.match(exp) == null ) 
		return false;
    
    if (isNaN(qty))
		return false;
    
    if ( 1 * qty <= 0 )
		return false;
       
   	return true;
}

function CheckDropDown(ddlControl)
{
	if ( (1 * document.getElementById(ddlControl).value) < .5 )
		return false;
	else
		return true;
}