// -------------------------------------------------------------------------
var FltrInt = /^[0-9]*$/

// -------------------------------------------------------------------------
function CheckFieldLength(field,length,msg)
{
	if(field.value.length>length)
	{
		alert(msg);
		field.select();
	}
}

// -------------------------------------------------------------------------
function trim(str)
{
	var s = str;

	if (s == null)
		return "";

	while((s.length > 0) && (s.charAt(0) == ' '))
		s = s.substring(1);
	    
	while((s.length > 0) && (s.charAt(s.length - 1) == ' '))
		s = s.substring(0,s.length - 1); 

	return s; 
} 

// -------------------------------------------------------------------------
function CheckAllQty(f)  
{  
	var c;
	var lChecked;
	
	c = 0;
	
	for(i = 1; i <= f.listitems.value; i++)
	{
		lChecked = true;
		if (eval("typeof(f.include" + i + ") != 'undefined'"))
		{
			if (eval("f.include" + i + ".checked == false"))
			{
				lChecked = false;
			}
		}

		if (lChecked)
		{
			if (typeof(eval("f.Prod" + i)) != "undefined" && eval("f.Prod" + i + ".type") == "text")
			{  
				ProdExist = "f.Prod" + i + ".value.length > 0";
			}  
			else  
			{  
				ProdExist = " false ";
			}   
		            
			if (eval("f.Qtty" + i + ".value.length > 0") || eval(ProdExist))  
			{  
				if (!FltrInt.test((eval("f.Qtty" + i + ".value"))) || (eval("f.Qtty" + i + ".value <= 0")) )
				{
					alert("You entered incorrect value!");
					eval("f.Qtty" + i + ".select()")
					return false; 
				}
				
				c = c + 1;
			}
			
			if (eval("f.Qtty" + i + ".value > 10000"))
			{       
				alert("Value of the quantity can't be higher than 10000!");
				eval("f.Qtty" + i + ".select()")
				return false;
			}
		}
	}
	
	if (c > 0)
		return true;
	else
	{
		return false;
	}
}

// -------------------------------------------------------------------------
function PushToQL(f, pItemIndex, pContinueShopping)
{
	var i;
	i = pItemIndex;

	if (eval("f.Qtty" + i + ".value.length > 0"))
	{
		if (!FltrInt.test((eval("f.Qtty" + i + ".value"))) || (eval("f.Qtty" + i + ".value <= 0")) )
		{
			alert("You entered incorrect value!");
			eval("f.Qtty" + i + ".select()");
			return false;
		}
	}

	if (eval("f.Qtty" + i + ".value > 10000"))
	{	
		alert("Value of the quantity can't be higher than 10000!");
		eval("f.Qtty" + i + ".select()");
		return false;
	}

	ql_form.IBA_ITM.value = eval("f.Prod" + i + ".value");
	ql_form.Quantity.value = eval("f.Qtty" + i + ".value");
	ql_form.ContinueShopping.value = pContinueShopping;
	ql_form.submit();
}

// -------------------------------------------------------------------------
function ChangeProductHidden(pForm)
{
	if (pForm.AddProducts != null)
	{
		pForm.AddProducts.value = "1";
	}
}

// -------------------------------------------------------------------------