function Produto()
{
	this.request = new Request();
	this.awaitingXML = false; 
	this.xmlType = null;
	this.loadingDiv = new Array();
}

Produto.prototype.startLoad = function(srcObj, obj)
{
	var id = srcObj.getAttribute('id').substr(2,srcObj.getAttribute('id').length);
	this.loadingDiv[id] = true;
	var f = function() { oProduto.subMenus(srcObj, obj) };
	setTimeout(f, 150);
}

Produto.prototype.stopLoad = function(srcObj, obj)
{
	var id = srcObj.getAttribute('id').substr(2,srcObj.getAttribute('id').length);
	this.loadingDiv[id] = false;
}

Produto.prototype.subMenus = function(srcObj, obj)
{
	var id = srcObj.getAttribute('id').substr(2,srcObj.getAttribute('id').length);
	if(this.loadingDiv[id])
	{
		var a = 'ulSubCategories_'+id;
		var liObj = document.getElementById(a);
		if (liObj && liObj.innerHTML != "")
		{
			liObj.style.display = '';
			return;
		}
	
		this.request.url = '/Category/view';
		this.request.method = 'post';
		this.request.data = 'id='+id+'&obj='+obj;
		this.request.addRequestListener(this);
		this.awaitingXML = true;
		this.xmlType = 'xmlCategory';
		this.request.open();
	}
}

Produto.prototype.finishSubMenu = function()
{
	var parser = new XMLParser(this.request.getResponseXML());
	var response = parser.getNodeValue('response');
	var idCategory = parser.getNodeValue('idCategory');
	var sub = parser.getNodeValue('sub');
	var a = 'ulSubCategories_'+idCategory;
	var ul = document.getElementById(a);
	var obj = parser.getNodeValue('obj');
	
	if(obj == 1)
	{
		oDOMUtils.removeChilds(ul);	
	}	
	else if(obj == 2 && response)
	{
		var a = 'liSubCategories_'+idCategory;
		var liSub = document.getElementById(a);
		var ulSub = document.createElement('ul');
		var a = 'ulSubCategories_'+idCategory;
		ulSub.setAttribute('id',a);
		liSub.appendChild(ulSub);
	}
	if(response)
	{
		for (var i = 0;i < response.length; i++)
		{
			var responseParser = new XMLParser(response[i]);
			var id = responseParser.getNodeValue('id');
			var categoryName = responseParser.getNodeValue('name');
			var controller = responseParser.getNodeValue('controller');
			if(obj == '1')
			{
				var li = document.createElement('li');
				li.setAttribute('id', 'liSubCategories_'+id);
				ul.appendChild(li);
				
				var a = document.createElement('a')
				a.setAttribute('href', '/Category/viewSub/'+id);
				if(controller !="")
				{
					a.setAttribute('href', '/'+controller+'/getAll/'+id);			
				}
				else
				{
					a.setAttribute('href', '/Category/viewSub/'+id);
					
				}
				
				var anchorId = 'a_'+id;
				a.setAttribute('id', anchorId);
				
				a.onmouseover = function() { oProduto.startLoad(this,2) };
				a.onmouseout = function() { oProduto.stopLoad(this,2) };
				
				a.innerHTML = categoryName;
				
				li.appendChild(a);
			}
			else if(obj == 2)
			{
				var subLi = document.createElement('li');
				ulSub.appendChild(subLi);
				
				var aSub = document.createElement('a')
				aSub.setAttribute('href', '/'+controller+'/getAll/'+id);
				aSub.innerHTML = categoryName;
				subLi.appendChild(aSub);
			}
		}
	}
}

Produto.prototype.ajaxRequestFinished = function()
{
	if (this.awaitingXML)
	{		
		switch (this.xmlType)
		{
			case 'xmlCategory':
				this.finishSubMenu();
			break;
		}
	}
}

Produto.prototype.accountType = function(obj)
{
	if(obj == '2')
	{
		var type = document.getElementById('operation');
		var nameType = document.getElementById('buscaAvancadaLogin');
		var userType = document.getElementById('buscaProdutosLogin');
		var form = document.getElementById('formSerach');
		nameType.style.color  =  '#FFFFFF';
		userType.style.borderBottom = 'none' ;
		form.setAttribute('action','/Produtos/search');
		userType.style.color  = '#FFFFFF';
		type.value = "similaridade";
		nameType.className = "abaUnSelected";		
		userType.className = "abaSelected";
	}
	else if(obj == '1')
	{
		var type = document.getElementById('operation');
		var nameType = document.getElementById('buscaAvancadaLogin');
		var userType = document.getElementById('buscaProdutosLogin');
		var form = document.getElementById('formSerach');
		nameType.style.borderBottom = 'none' ;
		userType.style.color  = '#FFFFFF';
		type.value = "produto";
		form.setAttribute('action','/Produtos/searchSimilaridade');
		nameType.className = "abaSelected";
		userType.className = "abaUnSelected";
	}
}

var oProduto = new Produto();