////////////////////////////////////////
// ALL RIGHTS RESERVED COMTRON d.o.o. //
// COPY OR REDISTRIBUTION OF THIS     //
// CONTENT IS NOT ALLOWED.            //
//									  //
// QUICK BUY BASKET 				  //
// Dejan Božič                        //
////////////////////////////////////////

// Quick buy basket class
function QuickBuy_Basket(classRef)
{
	// CONSTRUCTORS
	this.Customer				= new QuickBuy_Customer(classRef);
	this.Articles				= new QuickBuy_Articles(classRef);
	this.Article				= new QuickBuy_Article(classRef);
	this.Data					= new QuickBuy_Data(classRef);
	this.GUI					= new QuickBuy_GUI(classRef);
	
	// ATTRIBUTES SETTINGS
	this.CookieName				= "QuickBuyArticles";
	this.BasketValid			= 7;
	this.TrimTitle				= 15;
	this.IncludeCustomer		= false;
	this.Parent					= false;
	this.GUI.Window				= true;		
	this.GUI.BasketHTMLContainer= "divQuickBuy_BasketArticles";	
	this.GUI.Preview.MaxAlpha	= 100;
	this.GUI.Preview.MinAlpha	= 0;
	this.GUI.Preview.FadeInTime	= 500;
	this.GUI.Preview.FadeOutTime= 100;
	this.GUI.Preview.Offset		= 300;
	this.GUI.WindowAlign		= "right,top";
	this.GUI.WindowOffset		= "-38,20";	
	this.GUI.DragAndDrop		= true;
	this.GUI.Toggled			= true;
	this.Active					= true;
	this.ArticlePreview			= false;
	
	// ATTRIBUTES 
	this.CookiePath				= "/";
	this.CookieDomain			= shopDomain;
	this.isSecure				= false;
	this.BasketType				= shopTYPE;
	this.URL					= shopURL;
	this.Customer.CustomerID	= shopCustomerID;
	this.Customer.FirstName		= shopFirstName;
	this.Customer.LastName		= shopLastName;
	this.Customer.LawForm		= shopLawForm;


	// LOAD
	this.LoadBasket = LoadBasket
	function LoadBasket()
	{
		if (!eval(classRef).Active) return;
		eval(classRef).Customer.Set("" + shopCustomerID + "", "" + shopFirstName + "", "" + shopLastName + "", "" + shopLawForm + "", "" + shopCustomerIsLogged + "");
		eval(classRef).Customer.Process();	
		eval(classRef).Load();
	}
	Events.Register("onload", classRef + ".LoadBasket()");

	
	// METHODS
	this.LoginTransfer = LoginTransfer;
	function LoginTransfer(oldCustomerID, newCustomerID)
	{
		eval(classRef).LoadBasket();
		var tmpArticles = eval(classRef).Articles;
		eval(classRef).Reset();
		eval(classRef).Customer.OldCustomerID	= oldCustomerID;
		eval(classRef).Customer.CustomerID		= newCustomerID;
		eval(classRef).Customer.SetLogged("True");
		eval(classRef).Articles = tmpArticles;
		eval(classRef).Save();
	}
	
	this.LogoutTransfer = LogoutTransfer;
	function LogoutTransfer(oldCustomerID, newCustomerID)
	{
		eval(classRef).Customer.SetLogged("True");
		eval(classRef).LoadBasket();
		var tmpArticles = eval(classRef).Articles;
		eval(classRef).Reset();
		eval(classRef).Customer.OldCustomerID	= oldCustomerID;
		eval(classRef).Customer.CustomerID		= newCustomerID;
		eval(classRef).Customer.SetLogged("False");
		eval(classRef).Articles = tmpArticles;
		eval(classRef).Save();
	}
	
	this.Save = Save;
	function Save()
	{
		var cookie = eval(classRef).CookieName
		try { this.UpdateBasket(); } catch(ex) {}
		this.Data.GetData();
		
		// anon and logged customers
		if (eval(classRef).Customer.IsLogged())
			cookie += eval(classRef).Customer.CustomerID;

		set_cookie(cookie + "ID",		this.Data.IDs, this.BasketValid, this.CookiePath, this.CookieDomain, this.isSecure);
		set_cookie(cookie + "Title",	this.Data.Titles, this.BasketValid, this.CookiePath, this.CookieDomain, this.isSecure);
		set_cookie(cookie + "Price",	this.Data.Prices, this.BasketValid, this.CookiePath, this.CookieDomain, this.isSecure);
		set_cookie(cookie + "Quantity",	this.Data.Quantities, this.BasketValid, this.CookiePath, this.CookieDomain, this.isSecure);
		set_cookie(cookie + "Image",	this.Data.Images, this.BasketValid, this.CookiePath, this.CookieDomain, this.isSecure);
	}

	this.Load = Load;
	function Load()
	{
		var cookie = eval(classRef).CookieName
		// anon and logged customers
		if (eval(classRef).Customer.IsLogged())
			cookie += eval(classRef).Customer.CustomerID;

		this.Data.IDs			= get_cookie(cookie + "ID");
		this.Data.Titles		= get_cookie(cookie + "Title");
		this.Data.Prices		= get_cookie(cookie + "Price");
		this.Data.Quantities	= get_cookie(cookie + "Quantity");
		this.Data.Images		= get_cookie(cookie + "Image");
		this.Data.SetData();	
		
		try { this.UpdateBasket(); this.GUI.Preview.Create(); } catch(ex) {}
	}
	
	this.RefreshBasket = RefreshBasket
	function RefreshBasket(strArticleIDs, strArticleQuantities)
	{
		var arrArticleIDs = strArticleIDs.split(',');
		var arrQuantities = strArticleQuantities.split(',');
		var arrArticles = this.Articles.Articles;

		for (i in this.Articles.Articles)
		{
			if ((this.Articles.Articles[i].ID != "") && (this.Articles.Articles[i].ID != "undefined"))
			{
				var exists = -1;
				for (j in arrArticleIDs)
				{
					if (arrArticleIDs[j] == this.Articles.Articles[i].ID)
					{
						exists = j;
						break
					}
				}
			
				if (exists > -1)
				{
					var NewArticle = new QuickBuy_Article(classRef);
						NewArticle.ID = arrArticles[i].ID;
						NewArticle.Quantity = arrQuantities[exists];
						NewArticle.Price = "";
						NewArticle.Title = "";
						NewArticle.Image = "";

					this.Articles.UpdateArticle(NewArticle);
				}
				else
				{
					this.Articles.RemoveArticle(arrArticleIDs[i]);
				}
			}
		}
	}
	
	this.Reset = Reset;
	function Reset()
	{
		var cookie = eval(classRef).CookieName
		// anon and logged customers
		if (eval(classRef).Customer.IsLogged())
			cookie += eval(classRef).Customer.CustomerID;
			
		this.Articles.DeSelectAll();
		this.Articles = new QuickBuy_Articles(classRef);
		
		set_cookie(cookie + "ID",		"", this.BasketValid, this.CookiePath, this.CookieDomain, this.isSecure);
		set_cookie(cookie + "Title",	"", this.BasketValid, this.CookiePath, this.CookieDomain, this.isSecure);
		set_cookie(cookie + "Price",	"", this.BasketValid, this.CookiePath, this.CookieDomain, this.isSecure);
		set_cookie(cookie + "Quantity",	"", this.BasketValid, this.CookiePath, this.CookieDomain, this.isSecure);
		set_cookie(cookie + "Image",	"", this.BasketValid, this.CookiePath, this.CookieDomain, this.isSecure);
		
		delete_cookie(cookie + "ID", this.CookiePath, this.CookieDomain);
		delete_cookie(cookie + "Title", this.CookiePath, this.CookieDomain);
		delete_cookie(cookie + "Price", this.CookiePath, this.CookieDomain);
		delete_cookie(cookie + "Quantity", this.CookiePath, this.CookieDomain);
		delete_cookie(cookie + "Image", this.CookiePath, this.CookieDomain);
		try { this.UpdateBasket(); } catch(ex) {}
	}

	this.UpdateBasket = UpdateBasket;
	function UpdateBasket()
	{
		this.GUI.CreateGUI(this.Articles.Articles, this.Customer);
		this.GUI.SetArticlesInBasket();
		
		var tmpArticles = eval(classRef).Articles.Articles;
		for (i in tmpArticles)
		{
			if (parseInt(tmpArticles[i].Quantity) > 0)
			{
				if (GetElement("RemoveFromBasketIco" + tmpArticles[i].ID))
					GetElement("RemoveFromBasketIco" + tmpArticles[i].ID).style.display = "";
			}
		}
	}
	
	this.Submit = Submit
	function Submit()
	{
		if (eval(classRef).Articles.Articles.length < 1)
		{
			alert("Vaša nakupovalna košarica je prazna");
			return;
		}
	
		if (eval(classRef).Articles.Articles.length > 0)
		{
			var articleid = "";
			var tmpArticles = eval(classRef).Articles.Articles;
			
			for (i in tmpArticles)
				articleid += "," + tmpArticles[i].ID + ":" + tmpArticles[i].Quantity;

			document.location = shopURL + "/itc_order_additem.asp?ArticleID=" + articleid.substring(1, articleid.length);
		}
	}
	
	this.Basket = Basket
	function Basket()
	{
		if (eval(classRef).Articles.Articles.length < 1)
		{
			alert("Vaša nakupovalna košarica je prazna");
			return;
		}
	
		if (eval(classRef).Articles.Articles.length > 0)
		{
			var articleid = "";
			var tmpArticles = eval(classRef).Articles.Articles;
			
			for (i in tmpArticles)
				articleid += "," + tmpArticles[i].ID + ":" + tmpArticles[i].Quantity;

			document.location = shopURL + "/itc_order_additem.asp??GoTo=" + shopURL + "/Basket.asp&ArticleID=" + articleid.substring(1, articleid.length);
		}
	}
	
	this.UpdateItems = UpdateItems
	function UpdateItems(sURL)
	{
		if (eval(classRef).Articles.Articles.length > 0)
		{
			var articleid = "";
			var tmpArticles = eval(classRef).Articles.Articles;
			
			for (i in tmpArticles)
				articleid += "," + tmpArticles[i].ID + ":" + tmpArticles[i].Quantity;

			document.location = shopURL + "/itc_order_additem.asp?GoTo=" + sURL + "&ArticleID=" + articleid.substring(1, articleid.length);
		}
		else
		{
			document.location = shopURL + "/itc_order_additem.asp?GoTo=" + sURL;	
		}
	}
	
	this.SubmitServiceOrder = SubmitServiceOrder
	function SubmitServiceOrder()
	{
		if (eval(classRef).Articles.Articles.length > 0)
		{
			var articleid = "";
			var tmpArticles = eval(classRef).Articles.Articles;
			
			for (i in tmpArticles)
				articleid += "," + tmpArticles[i].ID + ":" + tmpArticles[i].Quantity;

			var frmServiceOrderSubmit  = GetElement("frmServiceOrderSubmit");
				frmServiceOrderSubmit.action = frmServiceOrderSubmit.action + "?ArticleID=" + articleid.substring(1, articleid.length);
				frmServiceOrderSubmit.submit();
		}
	}
	
	this.SubmitQuick = SubmitQuick
	function SubmitQuick()
	{
		if (eval(classRef).Articles.Articles.length > 0)
		{
			var articleid = "";
			var tmpArticles = eval(classRef).Articles.Articles;
			
			for (i in tmpArticles)
				articleid += "," + tmpArticles[i].ID + ":" + tmpArticles[i].Quantity;

			document.location = shopURL + "/itc_order_additem.asp?gotobuy=true&ArticleID=" + articleid.substring(1, articleid.length);
		}
	}
}


// Quick Buy data container
function QuickBuy_Data(classRef)
{
	this.IDs		= null;
	this.Titles		= null;
	this.Prices		= null;
	this.Quantities = null;
	this.Images		= null;
	
	this.Get = Get;
	function Get()
	{
		return this;
	}
	
	this.GetData = GetData
	function GetData()
	{
		this.IDs		= eval(classRef).Articles.IDsToString();
		this.Titles		= eval(classRef).Articles.TitlesToString();
		this.Prices		= eval(classRef).Articles.PricesToString();
		this.Quantities	= eval(classRef).Articles.QuantitiesToString();
		this.Images		= eval(classRef).Articles.ImagesToString();
	}
	
	this.SetData = SetData
	function SetData()
	{
		if ((this.IDs == "") || (this.IDs == null)) return;
	
		var arrIDs			= this.IDs.split(';')
		var arrTitles		= this.Titles.split(';')
		var arrPrices		= this.Prices.split(';')
		var arrQuantities	= this.Quantities.split(';')
		var arrImages		= this.Images.split(';')
		var tmpArticles		= eval(classRef).Articles;
		var tmpArticle		= eval(classRef).Article;
		
		for (i in arrIDs)
			tmpArticles.AddArticle(tmpArticle.Create(arrIDs[i], arrPrices[i], arrTitles[i], arrQuantities[i], arrImages[i]));
	}
	
	this.ResetData = ResetData;
	function ResetData()
	{
		delete_cookie(eval(classRef).CookieName + "ID", this.CookiePath, this.CookieDomain);
		delete_cookie(eval(classRef).CookieName + "Title", this.CookiePath, this.CookieDomain);
		delete_cookie(eval(classRef).CookieName + "Price", this.CookiePath, this.CookieDomain);
		delete_cookie(eval(classRef).CookieName + "Quantity", this.CookiePath, this.CookieDomain);
		delete_cookie(eval(classRef).CookieName + "Image", this.CookiePath, this.CookieDomain);
	}
}


// Quick Buy basket user interface
function QuickBuy_GUI(classRef)
{
	// ATTRIBUTES
	this.Preview				= new QuikcBuy_Preview(classRef);
	this.BasketHTMLContainer	= null;
	this.PreviewImages			= new Array();
	this.HTMLContainer			= null;
	this.Customer				= null;
	this.Articles				= null;
	this.Window					= false;
	this.WindowContainer		= null;
	this.WindowHeaderContainer	= null;
	this.WindowAlign			= null;
	this.WindowOffset			= null;
	this.DragAndDrop			= null;
	this.BasketDrag				= null; 
	this.CloseBasket			= null;
	this.BasketBody				= null;
	this.Toggled				= true;
	this.isDraggable			= false;
	
	// METHODS
	this.CreateGUI = CreateGUI
	function CreateGUI(objArticles, objCustomer)
	{
		try
		{
			
			this.GetContainer();
			this.Customer = objCustomer;
			this.Articles = objArticles;
			this.SetArticlesInBasket();
			this.SetTotal();
			this.HTMLContainer.innerHTML = this.GetHTML();
			this.MakeWindow();
			
		}
		catch(ex){}
		
	}
	
	this.MakeWindow = MakeWindow;
	function MakeWindow()
	{
		if (!this.Window)
		{
			GetElement("UserBasket_Close").style.display = "none";
			return;
		}
	
		if (eval(classRef).Parent)
		{
			this.WindowContainer		= GetParentElement("divQuickBuy_Basket");
			this.WindowHeaderContainer	= GetParentElement("divQuickBuy_BasketHeader");
			this.CloseBasket			= GetParentElement("UserBasket_Close");
			this.BasketBody				= GetParentElement("UserBasket_Body");
			return;
		}
		else
		{
			this.WindowContainer		= GetElement("divQuickBuy_Basket");
			this.WindowHeaderContainer	= GetElement("divQuickBuy_BasketHeader");
			this.CloseBasket			= GetElement("UserBasket_Close");
			this.BasketBody				= GetElement("UserBasket_Body");
		}

		if (Settings.GetSetting("Basket_Toggled") == "true")
			this.BasketBody.style.display = "none";
		else
			this.BasketBody.style.display = "";

		//Events.ElementRegister(this.CloseBasket, "onmousedown", eval(classRef).GUI.ToggleBasket);
		this.MakeDraggable();
	}
	
	this.MakeDraggable = MakeDraggable
	function MakeDraggable()
	{
		if (!eval(classRef + ".GUI.DragAndDrop"))
			return;
	
		this.BasketDrag					= new DragElement(classRef + ".GUI.BasketDrag");
		this.BasketDrag.DragItemHeader	= this.WindowHeaderContainer;
		this.BasketDrag.DragItem		= this.WindowContainer;
		SetElementPosition(this.WindowContainer, this.WindowAlign, this.WindowOffset);
		this.BasketDrag.Init();
	}
	
	this.ToggleBasket = ToggleBasket
	function ToggleBasket()
	{
		if (eval(classRef).GUI.BasketBody.style.display == "")
		{
			eval(classRef).GUI.BasketBody.style.display = "none";
			eval(classRef).GUI.Toggled = true;
		}
		else
		{
			eval(classRef).GUI.BasketBody.style.display = "";
			eval(classRef).GUI.Toggled = false;
		}
			
		Settings.AddSetting("Basket_Toggled", eval(classRef).GUI.Toggled);
		Settings.Save();
		eval(classRef).GUI.BasketDrag.Stop();
	}

	this.SetTotal = SetTotal
	function SetTotal()
	{
		try
		{
			var fTotal = 0.0;
			var tmpArticles = eval(classRef).Articles.Articles;
		
			for (i in tmpArticles)
				fTotal += parseFloat(tmpArticles[i].Price) * parseFloat(tmpArticles[i].Quantity);

			if (eval(classRef).Parent)
				GetParentElement("QuickBuy_BasketTotal").innerHTML = Math.round(fTotal * 100) / 100;
			else
				GetElement("QuickBuy_BasketTotal").innerHTML = Math.round(fTotal * 100) / 100;
		}
		catch(ex){}
	}
	
	this.SetArticlesInBasket = SetArticlesInBasket
	function SetArticlesInBasket()
	{
		try
		{
			if (eval(classRef).Customer.IsLogged)
			{
				GetParentElement("QuickBuy_Logout").style.display = '';
			}
			else
			{
				GetParentElement("QuickBuy_Logout").style.display = 'none';
			}
		
			if (eval(classRef).Articles.Articles.length == 0)
			{
				if (eval(classRef).Parent)
				{
					GetParentElement("QuickBuy_Basket").style.display = 'none';
					GetParentElement("QuickBuy_BasketEmpty").style.display = '';
				}
				else
				{
					GetElement("QuickBuy_Basket").style.display = 'none';
					GetElement("QuickBuy_BasketEmpty").style.display = '';
				}
			}
			else
			{
				if (eval(classRef).Parent)
				{
					GetParentElement("QuickBuy_Basket").style.display = '';
					GetParentElement("QuickBuy_BasketEmpty").style.display = 'none';
					GetParentElement("QuickBuy_ArticlesInBasket").innerHTML = eval(classRef).Articles.Articles.length;
				}
				else
				{
					GetElement("QuickBuy_Basket").style.display = '';
					GetElement("QuickBuy_BasketEmpty").style.display = 'none';
					GetElement("QuickBuy_ArticlesInBasket").innerHTML = eval(classRef).Articles.Articles.length;
				}
			}
		}
		catch(ex){}
	}
	
	this.GetContainer = GetContainer
	function GetContainer()
	{
		if (eval(classRef).Parent)
			this.HTMLContainer = GetParentElement(this.BasketHTMLContainer);
		else
			this.HTMLContainer = GetElement(this.BasketHTMLContainer);
	}

	this.GetHTML = GetHTML
	function GetHTML()
	{
		var HTML = "";
		HTML += this.Table();
		
		for (i in this.Articles)
		{
			HTML += this.Row();
			HTML += this.Cell('20', '', this.ArticlePreview(this.Articles[i]) + ";" + "Hand(this)") + this.HTMLImage(this.Articles[i].Image, "PreviewImage_" + this.Articles[i].ID) + this.Cell(true);
			HTML += this.Cell('*', this.ArticleClick(this.Articles[i]), "Hand(this)") + this.Span() + this.Articles[i].Title + this.Span(true) + this.Cell(true);
			HTML += this.Cell('20', '') + this.Span() + " x " + this.Articles[i].Quantity + this.Span(true) + this.Cell(true);
			HTML += this.Cell('20', '') + this.Span() + ButtonRemove(this.Articles[i]) + this.Span(true) + this.Cell(true);
			HTML += this.Row(true);
		}
		
		HTML += this.Table(true);
		
		return HTML;
	}

	this.Table = Table;
	function Table(isTagEnd)
	{
		if ((isTagEnd == null) || (isTagEnd = false))
			return "<table cellpading=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\">";
		else
			return "</table>";
	}
	
	this.Row = Row;
	function Row(isTagEnd)
	{
		if ((isTagEnd == null) || (isTagEnd = false))
			return "<tr>";
		else
			return "</tr>";
	}
	
	this.Cell = Cell;
	function Cell(width, clickEvent, overEvent, outEvent, isTagEnd)
	{
		if ((isTagEnd == null) || (isTagEnd = false))
			return "<td width=\"" + width + "\" onClick=\"" + clickEvent + "\" onMouseOver=\"" + overEvent + "\" onMouseOut=\"" + outEvent + "\">";
		else
			return "</td>";
	}
	
	this.HTMLImage = HTMLImage
	function HTMLImage(src, id, width, height)
	{
		return "<img src=\"" + src + "\" border=\"0\" class=\"QuickBuy_BasketArticleImage\" id=\"" + id + "\" width=\"20\" height=\"20\">";
	}
	
	this.Span = Span;
	function Span(isTagEnd)
	{
		if ((isTagEnd == null) || (isTagEnd = false))
			return "<span class=\"QuickBuy_BasketArticleText\">";
		else
			return "</span>";
	}
	
	this.Link = Link
	function Link(src, isTagEnd)
	{
		if ((isTagEnd == null) || (isTagEnd = false))
			return "<a href=\"" + src + "\">";
		else
			return "</a>";
	}
	
	this.ButtonRemove = ButtonRemove;
	function ButtonRemove(objArticle)
	{
		return "<img src=\"" + shopURL + "/Images/" + shopPrefix + "_QuickBuyDel.gif\" border=\"0\" onClick=\"javascript:" + classRef + ".Articles.RemoveArticle('" + objArticle.ID + "')\" onmouseover=\"javascript:this.style.cursor='pointer';\" alt=\"Odstrani iz košarice\" title=\"Odstrani iz košarice\">";
	}
	
	this.ArticlePreview = ArticlePreview
	function ArticlePreview(objArticle)
	{
	}
	
	this.ArticleClick = ArticleClick
	function ArticleClick(objArticle)
	{
		return "javascript:" + classRef + ".Article.Click('" + objArticle.ID + "')";
	}
}


//
function QuikcBuy_Preview(classRef)
{
	// ATTRIBUTES
	this.PreviewContainer	= null;
	this.Article			= new QuickBuy_Article(classRef);
	this.isMouseOver		= false;
	this.isMouseOut			= true;
	this.MouseEvent			= false;
	this.mousePos			= new Array();
	this.SelectedArticle	= null;
	this.MaxAlpha			= 0;
	this.MinAlpha			= 0;
	this.FadeInTime			= 0;
	this.FadeOutTime		= 0;
	this.Offset				= 0;

	// METHODS
	this.Create = Create
	function Create()
	{
		if (eval(classRef).ArticlePreview)
		{
			if (eval(classRef).Paretn)
				this.PreviewContainer = GetParentElement("divQuickBuy_ArticlePreview");
			else
				this.PreviewContainer = GetElement("divQuickBuy_ArticlePreview");
			
			if (this.PreviewContainer == null)
			{
				this.PreviewContainer					= document.createElement("div");
				this.PreviewContainer.Id				= "divQuickBuy_ArticlePreview";
				this.PreviewContainer.style.position	= "absolute";
				this.PreviewContainer.style.zIndex		= 9999;
				this.PreviewContainer.style.left		= "100px";
				this.PreviewContainer.style.top			= "100px";
				this.PreviewContainer.style.opacity		= 0;
				document.body.appendChild(this.PreviewContainer);
				this.RegisterMouse();
			}
		}
	}
	
	this.RegisterMouse = RegisterMouse;
	function RegisterMouse()
	{
		Events.Register("onmousemove", classRef + ".GUI.Preview.TraceMouse(e)");
	}
	
	this.Show = Show;
	this.arrOverTimeouts = new Array();
	function Show()
	{
		this.ClearTimeouts();
		var speed = Math.round(this.FadeInTime / 100);
		var timer = 0;

		this.PreviewContainer.innerHTML = "	<iframe src=\"/Include/QuickBuy_ArticleNewPreview.asp?ArticleID=" + eval(classRef).GUI.Preview.SelectedArticle.ID + "&Price=" + (eval(classRef).GUI.Preview.SelectedArticle.Price + '').replace('.', ',') + "&SaleStock=" + eval(classRef).GUI.Preview.SelectedArticle.Quantity + "\" class=\"QuickBuyNewArticlePreview\"  marginheight=\"0px\" marginwidth=\"0\" scrolling=\"no\" frameborder=\"0\">";
		for (i = (this.PreviewContainer.style.opacity * 100); i <= this.MaxAlpha; i++)
		{
			var t = setTimeout(classRef + ".GUI.Preview.changeOpac(" + i + ",'" + this.PreviewContainer.Id + "', true)",(timer * speed))
			this.arrOverTimeouts.push(t);
			timer++;
		}
	}
	
	this.Hide = Hide;
	this.arrOutTimeouts = new Array();
	function Hide()
	{
		this.ClearTimeouts();
		var speed = Math.round(this.FadeOutTime / 100);
		var timer = 0;

		for (i = (this.PreviewContainer.style.opacity * 100); i >= this.MinAlpha; i--) 
		{
			var t = setTimeout(classRef + ".GUI.Preview.changeOpac(" + i + ",'" + this.PreviewContainer.Id + "', false)",(timer * speed))
			this.arrOutTimeouts.push(t);
			timer++;
		}
	}
	
	this.changeOpac = changeOpac;
	function changeOpac(opacity, id, direction) 
	{
		if (GetElement(id) != null)
		{
			if (direction)
			{
				if (opacity < this.MaxAlpha)
					this.PreviewContainer.style.display = "";
			}
			else
			{
				if (opacity <= this.MinAlpha)
					this.PreviewContainer.style.display = "none";
			}
		
			var object = GetElement(id).style;
				object.opacity = (opacity / 100);
				object.MozOpacity = (opacity / 100);
				object.KhtmlOpacity = (opacity / 100);
				object.filter = "alpha(opacity=" + opacity + ")";
		}
	} 
	
	this.ClearTimeouts = ClearTimeouts
	function ClearTimeouts()
	{
		for (i = 0; i <= this.arrOverTimeouts.length; i++)
			clearTimeout(this.arrOverTimeouts[i]);
			
		for (i = 0; i <= this.arrOutTimeouts.length; i++)
			clearTimeout(this.arrOutTimeouts[i]);
			
		this.arrOutTimeouts = new Array();
		this.arrOverTimeouts = new Array();
	}
	
	this.TraceMouse = TraceMouse
	function TraceMouse(e)
	{
		if (typeof e != "undefined") { eval(classRef).GUI.Preview.mousePos[0] = e.pageX; eval(classRef).GUI.Preview.mousePos[1] = e.pageY; } 
		if (typeof window.event != "undefined") { eval(classRef).GUI.Preview.mousePos[0] = event.clientX; eval(classRef).GUI.Preview.mousePos[1] = event.clientY; }

		if (e.pageX == undefined) // IE
		{
			eval(classRef).GUI.Preview.mousePos[0] += truebody().scrollLeft;
			eval(classRef).GUI.Preview.mousePos[1] += truebody().scrollTop;
		}
		/*else if (event == "undefined") // MOZ, OP
			;*/

		// check if any item has mouse over and store it
		if (!eval(classRef).GUI.Preview.isMouseOver)
		{
			var tmpArticles = eval(classRef).Articles.Articles;
			var tmpPreview = eval(classRef).GUI.Preview;
			for (i in tmpArticles)
			{
				if (isMouseBound("PreviewImage_" + tmpArticles[i].ID, tmpPreview.mousePos))
				{
					tmpPreview.isMouseOver	= true;
					tmpPreview.SelectedArticle = tmpArticles[i];
					tmpPreview.MouseOver();
					break;
				}
			}
		}
		
		// Check if the current mouse over item is still active
		if (eval(classRef).GUI.Preview.isMouseOver)
		{
			if (!isMouseBound("PreviewImage_" + eval(classRef).GUI.Preview.SelectedArticle.ID, eval(classRef).GUI.Preview.mousePos))
			{
				eval(classRef).GUI.Preview.isMouseOver	= false;
				eval(classRef).GUI.Preview.MouseOut();
			}
		}
	}
	
	this.MouseOver = MouseOver
	function MouseOver()
	{
		this.SnapToArticle();
		this.Show();
	}
	
	this.MouseOut = MouseOut
	function MouseOut()
	{
		this.Hide();
	}
	
	this.SnapToArticle = SnapToArticle
	function SnapToArticle()
	{
		var pos = getElementPosition(GetElement("PreviewImage_" + eval(classRef).GUI.Preview.SelectedArticle.ID));
		this.PreviewContainer.style.left	= pos[0] - this.Offset;
		this.PreviewContainer.style.top		= pos[1];
	}
	
	this.UnSnapToArticle = UnSnapToArticle
	function UnSnapToArticle()
	{
		this.PreviewContainer.style.left	= -300;
		this.PreviewContainer.style.top		= -300;
	}
}


// Quick buy customer class
function QuickBuy_Customer(classRef)
{
	// ATTRIBUTES
	this.OldCustomerID	= null;
	this.CustomerID		= null;
	this.FirstName		= null;
	this.LastName		= null;
	this.LawForm		= null;
	this.LoginStatus	= "false";

	// METHODS
	this.Get = Get;
	function Get()
	{
		return this;
	}
	
	this.Set = Set;
	function Set(intCustomerID, strFirstName, strLastName, strLawForm, bIsLogged)
	{
		eval(classRef).CustomerID	= intCustomerID;
		eval(classRef).FirstName	= strFirstName;
		eval(classRef).LastName		= strLastName;
		eval(classRef).LawForm		= strLawForm;
		eval(classRef).LoginStatus	= bIsLogged + '';
	}
	
	this.IsLogged = IsLogged;
	function IsLogged()
	{
		if (eval(classRef).Customer.LoginStatus + '' == "True")
			return true;
		
		return false;
	}
	
	this.SetLogged = SetLogged;
	function SetLogged(bLooged)
	{
		eval(classRef).Customer.LoginStatus = bLooged;
	}
	
	this.Process = Process;
	function Process()
	{
		eval(classRef).Customer.SetLogged(shopCustomerIsLogged);
	
		if (!eval(classRef).IncludeCustomer)
			return;
	
		if (eval(classRef).Customer.IsLogged())
		{
			GetElement("QuickBuy_ArticlesInBasketCustomer").style.display = "";
			GetElement("QuickBuy_ArticlesInBasketCustomerName").innerHTML = this.FirstName + " " + this.LastName;
		}
		else
		{
			GetElement("QuickBuy_ArticlesInBasketAnonymous").style.display = "";
		}
	}
	
	this.Login = Login
	function Login()
	{
		location = shopURL + "/Login.asp";
	}
	
	this.Logout = Logout
	function Logout()
	{
		location = shopURL + "/Logout.asp";
	}
	
	this.Account = Account
	function Account()
	{
		location = shopURL + "/myaccount.asp";
	}
}


// Quick buy articles class
function QuickBuy_Articles(classRef)
{
	// ATTRIBUTES
	this.Articles = new Array();

	// METHODS
	this.AddArticle = AddArticle;
	function AddArticle(objArticle)
	{
		if ((objArticle.ID == "") || (objArticle.ID == "undefined") || (objArticle.ID == null) || (objArticle.ID == "NaN") || (objArticle.Title == "") || (objArticle.Title == "undefined") || (objArticle.Title == null) || (objArticle.Title == "NaN"))
		{
			;
		}
		else
		{
			var oArticle = this.ArticleExists(objArticle);

			if (oArticle != null)
				oArticle.IncrementQuantity();
			else
				this.Articles.push(objArticle);
		}
		
		eval(classRef).Save();
	}
	
	this.UpdateArticle = UpdateArticle;
	function UpdateArticle(objNewArticle)
	{
		for(i in this.Articles)
			if ('' + this.Articles[i].ID == '' + objNewArticle.ID)
			{
				if (objNewArticle.Title != "")
					this.Articles[i].Title = objNewArticle.Title;
					
				if (objNewArticle.Price != "")
					this.Articles[i].Price = objNewArticle.Price;
					
				if (objNewArticle.Image != "")
					this.Articles[i].Image = objNewArticle.Image;
					
				if (objNewArticle.Quantity != "")
					this.Articles[i].Quantity = objNewArticle.Quantity;
				break;
			}

		eval(classRef).Save();
	}
	
	this.GetArticle = GetArticle;
	function GetArticle(intArticleID)
	{
		for(i in this.Articles)
			if ('' + this.Articles[i].ID == '' + intArticleID)
				return this.Articles[i];

		return null;
	}
	
	this.RemoveArticle = RemoveArticle;
	function RemoveArticle(intArticleID)
	{
		for(i in this.Articles)
			if ('' + this.Articles[i].ID == '' + intArticleID)
			{
				if (parseFloat(parseInt(this.Articles[i].Quantity)) <= 1)
				{
					if (GetElement("RemoveFromBasketIco" + intArticleID))
						GetElement("RemoveFromBasketIco" + intArticleID).style.display = "none";
					this.Articles.splice(i,1);
				}
				else
				{
					this.Articles[i].Quantity--;
				}
				break;
			}
			
		eval(classRef).Save();
	}
	
	
	this.DeleteArticle = DeleteArticle;
	function DeleteArticle(intArticleID)
	{
		for(i in this.Articles)
			if ('' + this.Articles[i].ID == '' + intArticleID)
			{
				if (GetElement("RemoveFromBasketIco" + intArticleID))
					GetElement("RemoveFromBasketIco" + intArticleID).style.display = "none";
					
				this.Articles.splice(i,1);
				break;
			}
			
		eval(classRef).Save();
	}
	
	this.DeSelectAll = DeSelectAll;
	function DeSelectAll()
	{
		for(i in this.Articles)
		{
			if (GetElement("RemoveFromBasketIco" + this.Articles[i].ID))
				GetElement("RemoveFromBasketIco" + this.Articles[i].ID).style.display = "none";
		}
	}
	
	this.DecrementArticleQuantity = DecrementArticleQuantity;
	function DecrementArticleQuantity(intArticleID)
	{
		var oArticle = this.GetArticle(intArticleID);

		if (oArticle == null)
			return;
			
		oArticle.DecrementQuantity();

		if (oArticle.GetQuantity() <= 0)
				this.RemoveArticle(oArticle.ID);
				
		eval(classRef).Save();
	}
	
	this.ArticleExists = ArticleExists;
	function ArticleExists(objArticle)
	{
		for(i in this.Articles)
		{
			if ('' + this.Articles[i].ID == '' + objArticle.ID)
				return this.Articles[i];
		}
				
		return null;
	}
	
	this.Print = Print
	function Print()
	{
		var strArticleIDs = "";
		
		for(i in this.Articles)
		{
			strArticleIDs += this.Articles[i].ID + "\n";
			strArticleIDs += this.Articles[i].Title + "\n";
			strArticleIDs += this.Articles[i].Price + "\n";
			strArticleIDs += this.Articles[i].Quantity + "\n";
			strArticleIDs += this.Articles[i].Image + "\n\n";
		}
			
		alert(strArticleIDs);
	}
	
	this.IDsToString = IDsToString
	function IDsToString()
	{
		var newArray = new Array();
		for (i in this.Articles)
			newArray.push(this.Articles[i].ID);

		return newArray.join(';');
	}
	
	this.PricesToString = PricesToString
	function PricesToString()
	{
		var newArray = new Array();
		for (i in this.Articles)
			newArray.push(this.Articles[i].Price);

		return newArray.join(';');
	}
	
	this.TitlesToString = TitlesToString
	function TitlesToString()
	{
		var newArray = new Array();
		for (i in this.Articles)
			 newArray.push(this.Articles[i].Title);

		return newArray.join(';');
	}
	
	this.QuantitiesToString = QuantitiesToString
	function QuantitiesToString()
	{
		var newArray = new Array();
		for (i in this.Articles)
			newArray.push(this.Articles[i].Quantity);

		return newArray.join(';');
	}
	
	this.ImagesToString = ImagesToString
	function ImagesToString()
	{
		var newArray = new Array();
		for (i in this.Articles)
			newArray.push(this.Articles[i].Image);

		return newArray.join(';');
	}
}


// Article class
function QuickBuy_Article(classRef)
{
	// ATTRIBUTES
	this.ID				= null;
	this.Price			= null;
	this.Title			= null;
	this.Quantity		= null;
	this.Image			= null;
	this.isPreview		= false;
	
	
	// METHODS
	this.Create = Create;
	function Create(_ID, _Price, _Title, _Quantity, _Img)
	{
		this.Article			= new QuickBuy_Article(classRef);
		this.Article.ID			= _ID;
		this.Article.Price		= parseFloat(_Price);
		try { this.Article.Title= _Title.substr(0, eval(classRef).TrimTitle) + ".."; } catch(ex) { this.Article.Title = ""; }
		this.Article.Quantity	= _Quantity;
		this.Article.Image		= _Img;

		return this.Article;
	}
	
	this.IncrementQuantity = IncrementQuantity;
	function IncrementQuantity()
	{
		this.Quantity++;
	}
	
	this.DecrementQuantity = DecrementQuantity;
	function DecrementQuantity()
	{
		this.Quantity--;
	}
	
	this.SetQuantity = SetQuantity;
	function SetQuantity(intQuantity)
	{
		this.Quantity = parseInt(intQuantity);
	}
	
	this.GetQuantity = GetQuantity;
	function GetQuantity()
	{
		return parseInt(this.Quantity);
	}
	
	this.Print = Print;
	function Print()
	{
		alert(this.ID + "\n" + this.Price + "\n" + this.Title + "\n" + this.Quantity);
	}
	
	this.Click = Click
	function Click(intArticleID)
	{
		location = shopURL + "/Article.asp?ArticleID=" + intArticleID;
	}
}
