	window.onload = function() 
	{
		if(document.getElementById("total")) calcTotal();
		
		var catList = document.getElementById('catlist');
		if(catList)
		{
			var tblLen=catList.tBodies[0].rows.length;
			for(var i=0; i<tblLen; i++)
			{
				if(checkBrowser('msie'))	{
					catList.tBodies[0].rows[i].attachEvent('onmouseover',light.closure(catList.tBodies[0].rows[i]));
					catList.tBodies[0].rows[i].attachEvent('onmouseout',dark.closure(catList.tBodies[0].rows[i]));
				}
				// Mozilla, Firefox, Opera
				else {
					catList.tBodies[0].rows[i].setAttribute('onmouseover',"javascript:this.style.backgroundColor='#DBD8BC'; ");
					catList.tBodies[0].rows[i].setAttribute('onmouseout',"javascript:this.style.backgroundColor=''; ");				
				}
			}
		}
	}
	function light() { this.style.backgroundColor='#DBD8BC'; }
	function dark() { this.style.backgroundColor='';}
	
	// Browser detect
	function checkBrowser(string)
	{
		var detect = navigator.userAgent.toLowerCase();
		place=detect.indexOf(string)+1;
		return place;
	}

	// Wrapper of this alias of function
	Function.prototype.closure = function(obj)
	{
	  // Init object storage.
	  if (!window.__objs)
		window.__objs = [];

	  // Init closure storage.
	  if (!this.__closureFuncs)
		this.__closureFuncs = [];

	  // Make sure the object has an id and is stored in the object store.
	  var objId = obj.__closureObjId;
	  if (!objId)
		__objs[objId = obj.__closureObjId = __objs.length] = obj;

	  // See if we previously created a closure for this object/function pair.
	  var closureFunc = this.__closureFuncs[objId];
	  if (closureFunc)
		return closureFunc;

	  // Clear reference to keep the object out of the closure scope.
	  obj = null;

	  // Create the closure, store in cache and return result.
	  var me = this;
	  return this.__closureFuncs[objId] = function()
	  {
		return me.apply(__objs[objId], arguments);
	  };
	};

	// Form managment functions -----------------------------------------------------------------------
	function showCompanyForm(flag)
	{
		if(flag){
			 document.getElementById('private').style.display='none';
			 document.getElementById('company').style.display='block';
			 document.getElementById('client_type').value='1'; // Client is company
			 //document.getElementById('company_label').blur();
		}
		else{
			document.getElementById('private').style.display='block';
			document.getElementById('company').style.display='none';
			document.getElementById('client_type').value='2'; // Client is ordinary person
			//document.getElementById('simple_user_label').blur();
		}
	}
	function showSpeedyForm(flag)
	{
		if(flag)
		{
			var clientType= document.getElementById('client_type').value;			
			if(document.getElementById('dcity').value=='' && document.getElementById('daddr').value=='' && document.getElementById('dpostcode').value=='')
			{
				if(clientType==2) // ordinary client
				{
					document.getElementById('dcity').value=document.getElementById('city').value;
					document.getElementById('daddr').value=document.getElementById('addr').value;
					document.getElementById('dpostcode').value=document.getElementById('postcode').value;
				}
				else if(clientType==1) // company
				{
					document.getElementById('dcity').value=document.getElementById('cpcity').value;
					document.getElementById('daddr').value=document.getElementById('cpaddr').value;
					document.getElementById('dpostcode').value=document.getElementById('cppostcode').value;				
				}
			}
			document.getElementById('_delivery_').style.display='block';
			document.getElementById('with_courier').checked='cheked';
		}
		else{
			document.getElementById('_delivery_').style.display='none';
			document.getElementById('without_courier').checked='cheked';
		}
	}

	// 
	function calcTotal()
	{
		var sizeBox = document.getElementById('size');		
		if(sizeBox)
		{
			// Extract price from option value="price;size_id"
			var temp = new Array();
			tmp = sizeBox.options[sizeBox.selectedIndex].value.split('|');
			var price = parseFloat(tmp[0]);
			var quantity=parseFloat(document.getElementById("cnt").value);		
			if(isNaN(quantity)){
				//document.getElementById("cnt").value=quantity=1;
			}
			var total=price*quantity;
			if(!isNaN(total)) document.getElementById("total").innerHTML=moneyFormat(total)+' лв.';
			else document.getElementById("total").innerHTML='0 лв.';			
		}
	}
	/* Format money - returns the amount in the 0.00 format */
	function moneyFormat(amount)
	{
		amount -= 0;
		amount=(Math.round(amount*100))/100;
		return (amount==Math.floor(amount)) ? amount + '.00' : (  (amount*10==Math.floor(amount*10)) ? amount + '0' : amount);
	}