var url_artworks="http://www.sublimesupport.com/briantuniversity/artworks/";
var vecCategorias = new Array();

// Defino el Vector de Categorias
// Defino la clase categoria
function categoria(id,nombre,path) {
   this.id = id;
   this.nombre = nombre;
   this.path = path;

   function getid() {
      var ret;
	  ret = id;
	  return ret;
   }

   function getnombre() {
      var ret;
	  ret = nombre;
	  return ret;
   }

   function getpath() {
      var ret;
	  ret = path;
	  return ret;
   }

   function get_vpath() {
      var ret;
	  ret = path+'.'+id;
	  return ret;
   }

   function getident() {
      var ret;
	  ids=path+'.'+id;
	  vret=ids.split(".");
	  ret=vret.length;
	  return ret;
   }

   function getobj() {
      var ret;
	  ret = new categoria(this.id, this.nombre, this.path);
	  return ret;
   }


   this.getid = getid;
   this.getnombre = getnombre;
   this.getpath = getpath;
   this.getident = getident;
   this.get_vpath = get_vpath;
   this.getobj = getobj;
}

function create_cat(id, nombre, path) {
	if (id!="" && nombre!="" && path!="") {
		var new_obj = new categoria(id, nombre, path);
		return new_obj;
	} else {
	alert(id+'-'+nombre+'-'+path);
		alert("Error Al crear el objeto parametro");
		return null;
	}
}

function get_subcats(vpath, vec) {

	var actual_vpath="",index_vret=0, id_truepath=0;
	var vec_return = new Array();

	vec_truepath = vpath.split(".");
	size_truepath = vec_truepath.length;
	id_truepath=vec_truepath[size_truepath-1];

	for (i=0;i<vec.length;i++) {
		actual_vpath=vec[i].getpath()+'.'+vec[i].getid();
		if (vpath==actual_vpath) {
			while (i < vec.length && vec[i].get_vpath().split(".")[size_truepath-1]==id_truepath) {
				if (vec[i].getid()!=id_truepath) {
					if (vec[i].get_vpath().split(".")[size_truepath+1]==null) {
						vec_return[index_vret]=vec[i];
						index_vret++;
					}
				}
				i++;
			}
			break;
		}
	}
	return vec_return;
}

function auto_expand(path,id) {

	if (path=="") {return;}

	var ids=path.split(".");

	for (i=1;i<ids.length;i++) {
		expand(ids[i])
	}

	for (i=0;i<vecCategorias.length;i++) {
		oCat=vecCategorias[i];
		if (path+'.'+id==oCat.getpath()) {
			expand(i);
		}
	}

}

function expand(id) {

	if (vecCategorias[id]==null) {return;}

	var oCat=vecCategorias[id];
	var objcat = getObj('cat'+id);
	var str_output=new String();

	str_output=str_output+"<table width=100% cellspacing=0 cellpadding=0 border=0>";
	str_output=str_output+"<tr onMouseOver=mOvr(this,'#EAF2F7'); onMouseOut=mOut(this);>";
		str_output=str_output+"<td>&nbsp;&nbsp;<img src='"+url_artworks+"arrow4.gif' width='8' height='5' hspace='4' vspace='2' border='0'><a class='link5' href=\"javascript:expand_subcats("+oCat.getid()+",'"+oCat.getpath()+"."+oCat.getid()+"', vecCategorias);\"><img src='"+url_artworks+"blank.gif' height='1' width='"+((oCat.getident()-2)*7)+"' border='0'>"+oCat.getnombre()+"</a></td>";
	str_output=str_output+"</tr>";

	str_output=str_output+"<tr>";
		str_output=str_output+"<td>";
			str_output=str_output+"<span id='cat"+oCat.getid()+"' name='cat"+oCat.getid()+"'></span>";
		str_output=str_output+"</td>";
	str_output=str_output+"</tr>";

	str_output=str_output+"</table>";

	objcat.innerHTML=str_output;
}

function in_vector(id,vec) {
	for (i=0;i<vec.length;i++) {
		if (vec[i]==id) {return true;}
	}
	return false;
}

function expand_subcats(id, vpath, vecori) {

	var str_output="";
	var vec_ids=vpath.split(".");

	vec = get_subcats(vpath, vecori);
	tiene_productos=in_vector(id,vec_cats_prods);

	if (vec.length!=0 && !tiene_productos) {
		eval("var objcat = getObj('cat'+id);");
		if (objcat.innerHTML.length==0) {
			for (i=0;i<vec.length;i++) {
				str_output=str_output+"<table width=100% cellspacing=0 cellpadding=0 border=0>";
				str_output=str_output+"<tr onMouseOver=mOvr(this,'#EAF2F7'); onMouseOut=mOut(this);>";
					str_output=str_output+"<td>&nbsp;&nbsp;<img src='"+url_artworks+"arrow4.gif' width='8' height='5' hspace='4' vspace='2' border='0'><a class='link5' href=\"javascript:expand_subcats("+vec[i].getid()+",'"+vec[i].getpath()+"."+vec[i].getid()+"', vecCategorias);\"><img src='"+url_artworks+"blank.gif' height='1' width='"+((vec[i].getident()-2)*7)+"' border='0'>"+vec[i].getnombre()+"</a></td>";
				str_output=str_output+"</tr>";

				str_output=str_output+"<tr>";
					str_output=str_output+"<td>";
						str_output=str_output+"<span id='cat"+vec[i].getid()+"' name='cat"+vec[i].getid()+"'></span>";
					str_output=str_output+"</td>";
				str_output=str_output+"</tr>";

				str_output=str_output+"</table>";
			}
			objcat.innerHTML=str_output;
		} else {
			objcat.innerHTML="";
		}
	} else {
		location.href="products_list.php?idc="+id;
	}
}

function expand_subcats_LUIS(id, vpath, vecori) {

	var str_output="";
	var vec_ids=vpath.split(".");

	vec = get_subcats(vpath, vecori);

	if (vec.length!=0) {
		eval("var objcat = getObj('cat'+id);");
		if (objcat.innerHTML.length==0) {
			for (i=0;i<vec.length;i++) {
				str_output=str_output+"<table width=100% cellspacing=0 cellpadding=0 border=0>";
				str_output=str_output+"<tr onMouseOver=mOvr(this,'#EAF2F7'); onMouseOut=mOut(this);>";
					str_output=str_output+"<td>&nbsp;&nbsp;<img src='"+url_artworks+"arrow4.gif' width='8' height='5' hspace='4' vspace='2' border='0'><a class='link5' href=\"javascript:expand_subcats("+vec[i].getid()+",'"+vec[i].getpath()+"."+vec[i].getid()+"', vecCategorias);\"><img src='"+url_artworks+"blank.gif' height='1' width='"+((vec[i].getident()-2)*7)+"' border='0'>"+vec[i].getnombre()+"</a></td>";
				str_output=str_output+"</tr>";

				str_output=str_output+"<tr>";
					str_output=str_output+"<td>";
						str_output=str_output+"<span id='cat"+vec[i].getid()+"' name='cat"+vec[i].getid()+"'></span>";
					str_output=str_output+"</td>";
				str_output=str_output+"</tr>";

				str_output=str_output+"</table>";
			}
			objcat.innerHTML=str_output;
		} else {
			objcat.innerHTML="";
		}
	} else {
		location.href="products_list.php?idc="+id;
	}
}