// -------------------------------------------------------------------------
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";
	}
}

// -------------------------------------------------------------------------
function getCookie(name)
{
	var strCookie = document.cookie;
	var Res = "";
	var arrayStrings, ArrayValues, arStr, key;
	var splitter = ";";
	
	arrayStrings = strCookie.split(splitter);
	path = "/";
	
	for (var i = 0; i < arrayStrings.length; i++) 
	{
		arStr = arrayStrings[i];
		key = arStr.search("=");

		if (key != -1)
		{
			arrayValues = arStr.split("=");
			
			if (trim(arrayValues[0]).toUpperCase() == trim(name).toUpperCase())
			{
				Res = arrayValues[1];
			}
		}
	}

	return Res;
}

// -------------------------------------------------------------------------
function setCookie(name, value, expires, path, domain, secure)
{
	var curCookie = document.cookie;
	var spl = ";";
	var arrayOfStrings = curCookie.split(spl);
	var path = "/";
	
	for (var i = 0; i < arrayOfStrings.length; i++) 
	{
		TarStr = arrayOfStrings[i];
		res = TarStr.search("=");
		
		if (res != -1)
		{
			Arr = TarStr.split("=")
			if (trim(Arr[0]).toUpperCase() == trim(name).toUpperCase())
			{
				Arr[1] = value;
				document.cookie = Arr[0] + "=" + escape(Arr[1]) + ((path) ? "; path=" + path : "")
			}
		}
	}

	window.location.href = window.location.href;
}

// -------------------------------------------------------------------------