function parseJsonCategories(response){var categories=eval('('+response+')');var htmlCode='';var hasSubcategories=0;var hasPath=0;if(categories.path.length>0){hasPath=1;}
if(categories.subcategories){hasSubcategories=1;}
var lastCategoryId=1;if(hasPath){for(i=0;i<categories.path.length;i++){htmlCode+='<a href="#" onclick="showSubCategory('+lastCategoryId+'); return false">'+categories.path[i].name+'</a>';if(i<categories.path.length-1)htmlCode+=' / ';lastCategoryId=categories.path[i].category_id;}}
if(hasSubcategories){if(hasPath)htmlCode+=' / ';htmlCode+='<select name="category" onchange="showSubCategory(this.value)">';if(hasPath){htmlCode+='<option value="'+lastCategoryId+'">Choose a subcategory...</option>';}else{htmlCode+='<option value="">Choose a category...</option>';}
for(i=0;i<categories.subcategories.length;i++){htmlCode+='<option value="'+categories.subcategories[i].category_id+'">'+categories.subcategories[i].name+'</option>';}
htmlCode+='</select>';}else{htmlCode+='<input type="hidden" name="category" value="'+lastCategoryId+'" />';}
$("#categories").html(htmlCode);}
function showSubCategory(categoryId){$("#categories").html('<img src="'+static_path+'images/ajax-loader_s.gif" />');$.get(global_path+categoryId+"/categories.json",function(response){parseJsonCategories(response);});}