/*****************************************************************************************************/
/*                                                                                                   */
/*                                     'CATEGORIES PANEL' CLASS                                      */          
/*                                                                                                   */
/*****************************************************************************************************/

function CATEGORIES_GINFO(parent){
	var JSObject = this;
	var container = "categories_container";
	
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                           FUNCTION INIT                                           */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.init = function(){
		for (var i=0; i<categoriesJSON.length; i++){
			var category = categoriesJSON[i];
			
			if (category.subLevel != null) {
				for (var j=0; j<category.subLevel.length; j++){
					var subcategory = category.subLevel[j];
					var treeBtn = document.getElementById("tree_"+i+"_"+j);
					
					//daca subcategoria are subsubcategorii
					if (subcategory.subLevel != null){
						
						//alert(subcategory.opened)
						if (subcategory.opened == "true"){
							treeBtn.innerHTML = "<img src='"+LOCALPATH+"includes/images/buttons/btn_minus.gif' border='0' style='cursor:pointer'>";
							var img = treeBtn.getElementsByTagName('img')[0];
							img.status = "open";
						}
						else{
							treeBtn.innerHTML = "<img src='"+LOCALPATH+"includes/images/buttons/btn_plus.gif' border='0' style='cursor:pointer'>";
							var img = treeBtn.getElementsByTagName('img')[0];
							img.status = "close";
						}
						
						
						
						img.indexCategory = category.id;
						img.indexSubcategory = subcategory.id;
						//alert(img.indexSubcategory)
						img.divContainer = document.getElementById("subcategory_container_"+i+"_"+j);
						img.onclick = function(){
							//alert("da");
							if (this.status == "close"){
								this.status = "open";
								this.divContainer.style.display = "block";
								this.src = LOCALPATH+"includes/images/buttons/btn_minus.gif";
								
								//alert(LOCALPATH+"setcookie_category.php?"+'category='+this.indexSubcategory+'&'+'status='+"opened");
								www.post(LOCALPATH+"setcookie_category.php",
								 'category='+this.indexSubcategory+'&'+
								 'status='+"opened", 
								 function(response) {
									//alert(response)
									 
								 }
								 );	
							}
							else{
								this.status = "close";
								this.divContainer.style.display = "none";
								this.src = LOCALPATH+"includes/images/buttons/btn_plus.gif";
								
								//alert(LOCALPATH+"setcookie_category.php?"+'category='+this.indexSubcategory+'&'+'status='+"closed");
								www.post(LOCALPATH+"setcookie_category.php",
								 'category='+this.indexSubcategory+'&'+
								 'status='+"closed", 
								 function(response) {
									//alert(response)
									 
								 }
								 );	
							}
						}
						
						
						
						
						//afisam si subsubcategoriile
						for (var k=0; k<subcategory.subLevel.length; k++){
							var subsubcategory = subcategory.subLevel[k];
						}
					}
				}
				
			}
		
		}
	}
	
	
}