function Folder(ID,parentID,Order,Level,SubFolders,EditNav,WebNav,IsUrl,IsSelected,Title,Link,Target,Html,Description,ImageReferens,LinkImageReferens){
	this.name = "folder"+ID	// Id	
	this.id = ID
	this.parentid = parentID
	this.parent =  (ID>0)? eval("folder"+parentID):null;			
	this.order = Order
	this.level = Level
	this.subfolders = SubFolders
	this.editnav = (EditNav==0||EditNav==false)? false:true
	this.webnav = (WebNav==0||WebNav==false)? false:true	
	this.isurl = (IsUrl == 0||IsUrl==false)? false:true
	this.selected = (IsSelected==0||IsSelected==false)? false:true
	this.title = Title
	this.link = Link
	this.target = Target
	this.description = Description
	this.html = Html
	this.imgRef = ImageReferens
	this.linkImgRef = LinkImageReferens		
	this.subfoldercount = 0
	this.subfolderArray = new Array();
	this.selectedfoldersArray = new Array();
	
	this.obj = this.name + "FolderObject"
	eval(this.obj + "=this")
	this.addToParent = FolderAddToParentFolder		
	this.IsParent = FolderIsParent
	this.IsChildren = FolderIsChildren
	this.getParentsArray = FolderParentsArray
	this.getChildrensArray = FolderChildrensArray
	this.getSubFoldersTree = FolderSubFoldersTree
	this.setSelectedFolders = FolderSelectedFolders
	this.getSubFoldersImages = FolderSubFoldersWithImages
	
	this.addToParent();
	this.setSelectedFolders();
	
	//Array global con todos los folder ordenados!!
	
	foldersObjArray[foldersObjArrayCount] = this
	foldersObjArrayCount++
	
	this.subFoldersHTML = ""
	this.getSubFoldersHTML = FolderSubFoldersHTML
	this.getSubFolders = FolderSubFolders	
	
	this.build = FoldersBuild
	this.dropdown = FolderDropDown
	this.setBgColor = FolderSetBgColor	
	this.loadLocation = FolderLoadLocation;
	this.getHistory = FolderHistory;	
	
	this.show = FolderShow
	this.hide = FolderHide	
	
	this.subFoldersTopHTML = "";
	this.subFoldersSubHTML = "";
	this.getSubFoldersDropDownHTML = FolderSubFoldersDropDownHTML	
	
}

function FolderAddToParentFolder(){
	if(this.parentid>-1 && this.webnav){
		parentFolder = eval('folder'+this.parentid)
		parentFolder.subfolderArray[parentFolder.subfoldercount] = this;
		parentFolder.subfoldercount = parentFolder.subfolderArray.length;
	}
}

function FolderSelectedFolders(){
	if(this.selected==1){
		this.selectedfoldersArray = this.getParentsArray();
		this.selectedfoldersArray[this.selectedfoldersArray.length] = this;
		for(var i=0; i<this.selectedfoldersArray.length;i++){
			this.selectedfoldersArray[i].selected = true;
		}
	}
}

function FolderIsParent(oFolder){
	var vIsTrue = 0
	for (var i = oFolder.level; i > 0; i--){
		if(this.id == oFolder.parentid) {
			vIsTrue = 1;
			break
		} 
		else {
			oFolder = eval('folder'+oFolder.parentid);
		}
	}
	return (vIsTrue == 1)? true:false
}

function FolderIsChildren(oFolder){
	return oFolder.IsParent(this)
}

function FolderParentsArray(){
	var oParentsArray = new Array();
	oFolder = this
	for (var i = this.level; i > 0; i--){
		oFolder	= eval('folder' + oFolder.parentid);
		oParentsArray[i-1] = oFolder;
	} 	
	return oParentsArray;
}

function FolderChildrensArray(){}

function FoldersBuild(){
	this.dropdown();
}	

function FolderHistory(vStartLevel, sLinkClass, sSpanClass){
	var sHistoryHtml = "";
	var startlevel = (vStartLevel!=null)? vStartLevel:0;
	var linkClass = (sLinkClass!=null)? sLinkClass:"";
	var spanClass = (sSpanClass!=null)? sSpanClass:"";
	for(var i=vStartLevel; i< this.selectedfoldersArray.length-1; i++) {
		sHistoryHtml = sHistoryHtml + '<a title="'+this.selectedfoldersArray[i].description+'" href="javascript:'+this.selectedfoldersArray[i].name+'.loadLocation()" class="'+linkClass+'">' + this.selectedfoldersArray[i].title + '</a>&nbsp;&raquo; '
	}
	if(this.selectedfoldersArray.length-1>vStartLevel||this.selectedfoldersArray.length-1==vStartLevel) sHistoryHtml = sHistoryHtml + '<span class="'+spanClass+'">' + this.selectedfoldersArray[this.selectedfoldersArray.length-1].title + '</span>'
	return sHistoryHtml;
}

function FolderSubFoldersHTML(bCase){
	var tableHeight = 20;
	var tableWidth = 20;
	var tdHeight = 28	
	var sClass = "";
	var sBgImg = "";	
	var sLeftBg = "";
	var sMiddleLeftBg = "";
	var sMiddleRightBg = "";
	var sRightBg = "";	
	var sTarget = "";
	this.subFoldersHTML = "";
	
	if(this.level==0){
		sStartTable = '<table cellpadding="0" cellspacing="0" border="0"><tr>';
		for(var i=0; i< this.subfolderArray.length; i++) {
			if(this.subfolderArray[i].selected==1||this.subfolderArray[i].IsParent(eval("folder"+currentFolderID))){
				this.subFoldersHTML = this.subFoldersHTML + '<td><a href="'+hostPath+this.subfolderArray[i].link+'" style="border: 1px solid #FFFFFF"><img src="'+this.subfolderArray[i].linkImgRef+'" border="0" hspace="2" alt="'+this.subfolderArray[i].description+'" vspace="1" /></a></td>';
			}
			else{
				this.subFoldersHTML = this.subFoldersHTML + '<td><a href="'+hostPath+this.subfolderArray[i].link+'" style="border: 1px solid #457770" onmouseover=" this.style.border = \'1px solid #FFFFFF\'" onmouseout=" this.style.border = \'1px solid #457770\'"><img src="'+this.subfolderArray[i].linkImgRef+'" border="0" hspace="2" alt="'+this.subfolderArray[i].description+'"  vspace="5" /></a></td>';
			}
		}
		sEndTable = "</tr></table>";
		this.subFoldersHTML = sStartTable + this.subFoldersHTML + sEndTable;
		//alert(this.subFoldersHTML)
		
	}
	else{
		if(this.level==1){
			if(bCase){
				for(var i=0; i< this.subfolderArray.length; i++) {	
					sClass = (this.subfolderArray[i].selected==1||this.subfolderArray[i].IsParent(eval("folder"+currentFolderID)))? 'bmenuSelected':'bmenu'; 
					sStartTable = '<table><tr>';
					this.subFoldersHTML = this.subFoldersHTML + '<td style="padding-left: 10px; padding-right: 10px;"><a href="javascript:'+this.subfolderArray[i].name+'.loadLocation()" style="" class="'+sClass+'" title="' + this.subfolderArray[i].description + '">' + this.subfolderArray[i].title + '</a></td>';
					sEndTable = "</tr></table>";
				}
			}
			else{
				sStartTable = '<table cellpadding="0" cellspacing="0" border="0" height="100%" align="left" width="199">';
				for(var i=0; i< this.subfolderArray.length; i++) {		
					sClass = (this.subfolderArray[i].selected==1||this.subfolderArray[i].IsParent(eval("folder"+currentFolderID)))? 'menuSelected':'menu'; 
					sTDClass = (this.subfolderArray[i].selected==1||this.subfolderArray[i].IsParent(eval("folder"+currentFolderID)))? 'TDMenuSelected':'TDMenu'; 
					sTdRight = (i==0)? '':'';
					sTdMiddle = '</tr><tr><td height="1" class="lineBGColor" colspan="2"></td>';
					sTdLeft = (this.subfolderArray[i].selected==1||this.subfolderArray[i].IsParent(eval("folder"+currentFolderID)))? '<td width="30" class="TDPil" align="right" valign="middle"><img src="media/site/menupil.gif" width="9" height="7"></td>':'<td width="30" class="TDPil" align="center" valign="middle"><img src="media/site/menupil.gif" width="9" height="7"></td>';
					if(!is.ns4){
						this.subFoldersHTML = this.subFoldersHTML + '<tr>'+ sTdLeft + '<td id="'+this.subfolderArray[i].name+'" align="left" height="'+tdHeight+'" style="" width="166" class="'+sTDClass+'" title="' + this.subfolderArray[i].description + '" onmouseover="fnToggle(this)" onmouseout="fnToggle(this)" onclick="'+this.subfolderArray[i].name+'.loadLocation()">' + this.subfolderArray[i].title + '</td>'+sTdRight+sTdMiddle+'</tr>';
					}
					else{
						this.subFoldersHTML = this.subFoldersHTML + '<tr>'+ sTdLeft + '<td align="left" height="'+tdHeight+'" width="166" class="'+sTDClass+'" onclick="'+this.subfolderArray[i].name+'.loadLocation()">' + this.subfolderArray[i].title + '</td></td>'+sTdMiddle+sTdRight+'</tr>';
					}
					if(this.subfolderArray[i].subfolders>0&&(this.subfolderArray[i].selected==1||this.subfolderArray[i].IsParent(eval("folder"+currentFolderID)))){
						this.subFoldersHTML = this.subFoldersHTML + '<tr><td colspan="2">';
						this.subFoldersHTML = this.subFoldersHTML + this.subfolderArray[i].getSubFoldersHTML();
						this.subFoldersHTML = this.subFoldersHTML + '</td></tr>'
					}
				}
				sEndTable = "</table>";
			}
			this.subFoldersHTML = sStartTable + this.subFoldersHTML + sEndTable;
			//alert(this.subFoldersHTML)	
		}			
		else{
			if(this.level==3){
				if(this.subfolders>0){
					
					sStartTable = '<table cellpadding="0" cellspacing="0" border="0">';
					for(var i=0; i< this.subfolderArray.length; i++) {
						sTdMiddle = '</tr><tr><td height="1" class="lineBGColor" colspan="2"></td>';
						sTdLeft = (this.subfolderArray[i].selected==1||this.subfolderArray[i].IsParent(eval("folder"+currentFolderID)))? '<td width="40" height="16" class="TDSubPil" align="right" valign="middle"><img src="media/site/submenupil.gif" width="8" height="5"></td>':'<td width="40" height="16" class="TDSubPil" align="center" valign="middle"><img src="media/site/submenupil.gif" width="8" height="5"></td>';
						sClass = (this.subfolderArray[i].selected==1||this.subfolderArray[i].IsParent(eval("folder"+currentFolderID)))? 'submenuSelected':'submenu'; 
						sTDClass = (this.subfolderArray[i].selected==1||this.subfolderArray[i].IsParent(eval("folder"+currentFolderID)))? 'TDSubMenuSelected':'TDSubMenu'; 
						if(!is.ns4){
							this.subFoldersHTML = this.subFoldersHTML + '<tr>'+ sTdLeft + '<td id="'+this.subfolderArray[i].name+'" align="left" height="16" style="" width="170" class="'+sTDClass+'" title="' + this.subfolderArray[i].description + '" onmouseover="fnToggle(this)" onmouseout="fnToggle(this)" onclick="'+this.subfolderArray[i].name+'.loadLocation()">' + this.subfolderArray[i].title + '</td>'+sTdMiddle+'</tr>';
						}
						else{
							this.subFoldersHTML = this.subFoldersHTML + '<tr>'+ sTdLeft + '<td align="left" height="16" width="170" class="'+sTDClass+'">' + this.subfolderArray[i].title + '</td></td>'+sTdMiddle+sTdRight+'</tr>';
						}
					}
					sEndTable = "</tr></table>";
					this.subFoldersHTML = sStartTable + this.subFoldersHTML + sEndTable;
				}
			}	
		}
	}
	//alert(this.subFoldersHTML)
	return this.subFoldersHTML
}	

function FolderSubFolders(){
	if(this.subfolders>0){
		tdHeight = 16;
		sStartTable = '<table cellpadding="0" cellspacing="0" border="0" height="'+tdHeight+'"><tr>';
		for(var i=0; i< this.subfolderArray.length; i++) {
			sRightBg = '<td><img src="media/site/pixel.gif" width="10" height="1"></td>';
			sClass = (this.subfolderArray[i].selected==1||this.subfolderArray[i].IsParent(eval("folder"+currentFolderID)))? 'GalleryMenuSelected':'GalleryMenu'; 
			this.subFoldersHTML = this.subFoldersHTML + '<td id="'+this.subfolderArray[i].name+'" nowrap align="left" height="'+tdHeight+'" class="TD'+sClass+'" onclick="'+this.subfolderArray[i].name+'.loadLocation()" onmouseover="this.style.backgroundColor=\'#034EA2\'" onmouseout="this.style.backgroundColor=\'\'"><a href="javascript:'+this.subfolderArray[i].name+'.loadLocation()" class="'+sClass+'">&nbsp;&raquo;' + this.subfolderArray[i].title + '&nbsp;</a></td>';
		}
		sEndTable = "</tr></table>";
		this.subFoldersHTML = sStartTable + this.subFoldersHTML + sEndTable;
	}
}	

function FolderSubFoldersTree(oFolder){}

function FolderFoldersTree(oFolder, vStartLevel){}

function FolderSubFoldersWithImages(){}

//DropDown Metoder
function FolderDropDown(){
	if (is.ns) {
		if (is.ns4) {
			this.css = eval("document.Box_"+this.parentid+".document.Ilayer_"+this.id+".document."+this.name)
			this.elm = this.event = this.css
			this.doc = this.css.document
		}
		else {
			this.elm = document.getElementById(this.name)
			this.css = this.elm.style
			this.doc = document
		}
		this.x = (is.ns4)? this.css.left:parseInt(this.css.left)
		this.absx = (is.ns4)? this.css.pageX:parseInt(this.elm.offsetLeft)+parseInt(this.elm.offsetParent.offsetLeft)+ parseInt(this.elm.offsetParent.offsetParent.offsetLeft);
		
		this.y = (is.ns4)? this.css.top:parseInt(this.css.top)
		this.absy = (is.ns4)? this.css.pageY:parseInt(this.elm.offsetTop)
		this.w = (is.ns5)? this.elm.offsetWidth:this.css.clip.width
		this.h = (is.ns5)? this.elm.offsetHeight:this.css.clip.height
	}
	else {
		this.elm = this.event = document.all[this.name]
		this.css = (is.ie4)? document.all[this.name].style:document.getElementById(this.name).style
		this.doc = document
		this.x = this.elm.offsetLeft
		this.absx = (is.ie4)? this.elm.offsetLeft+ this.elm.offsetParent.offsetLeft + this.elm.offsetParent.offsetParent.offsetLeft:this.elm.offsetLeft + this.elm.offsetParent.offsetLeft+ this.elm.offsetParent.offsetParent.offsetLeft;
		this.y = this.elm.offsetTop
		this.absy = (is.ie4)? this.elm.offsetTop+ this.elm.offsetParent.offsetTop + this.elm.offsetParent.offsetParent.offsetTop:this.elm.offsetParent.offsetParent.offsetParent.offsetTop;
		this.cy = this.elm.clientTop
		this.p = 	this.elm.offsetParent
		this.w = (is.ie4)? this.css.pixelWidth : this.elm.offsetWidth
		this.h = (is.ie4)? this.css.pixelHeight : this.elm.offsetHeight
	}
}

function FolderSubFoldersTopHTML(){}

function FolderSubFoldersDropDownHTML(sCase){
	TopFolderStartTop = document.getElementById("mainTable").offsetTop + 119;		
	if(sCase=="top"){
		sTable = '<table border="0" cellpadding="0" cellspacing="0" height="18"><tr><td width="5"></td>'
		for(var i=0; i< this.subfolderArray.length; i++) {
			this.subFoldersSubHTML = this.subFoldersSubHTML + '<td height="18" width="'+(this.subfolderArray[i].w)+'" class="TopDDTD" onclick="javascript:'+this.subfolderArray[i].name+'.loadLocation()" onmouseover="fnToggle(\''+this.subfolderArray[i].name+'\'); " onmouseout="fnToggle(\''+this.subfolderArray[i].name+'\'); "><img src="'+emptyImg+'" border="0" alt="'+this.subfolderArray[i].title+'" width="'+(this.subfolderArray[i].w)+'" height="18"></td><td width="2"></td>'
		}
		var eTable = '</table>';
		sLayer = '<div id="'+this.name+'DDBox" style="position: absolute; left: 0px; top: '+(TopFolderStartTop)+'px; height: 20px;">';
		sEndLayer = '</div>'
		this.subFoldersSubHTML = sLayer + sTable + this.subFoldersSubHTML + eTable + sEndLayer;
		//alert(this.subFoldersSubHTML)
	}
	else{
		var sLayer = '<div id="'+this.name+'DDBox" style="position:absolute;  left: 0px; top: '+(TopFolderStartTop+19)+'px; visibility: hidden;">';
		var sEndLayer = '</div>';
		var sTable = sLayer + '<table cellpadding="0" cellspacing="2" border="0" class="DDTable" width="'+SubFoldersSubWidth+'"></tr>';
		for(var i=0; i< this.subfolderArray.length; i++) {
			if(this.subfolderArray[i]!=null){
				sBgColor = (this.subfolderArray[i].selected==1)? SubFoldersSubBGSelected:SubFoldersSubBGNormal;
				sClass = (this.subfolderArray[i].selected==1)? 'MenuSelected':'Menu';
				this.subFoldersSubHTML = this.subFoldersSubHTML + '<tr><td id="'+this.subfolderArray[i].name+'" class="SubTD'+sClass+'" height="16" onmouseover="if('+this.subfolderArray[i].name+'.selected!=1) this.className=\'SubTDMenuSelected\'" onmouseout="if('+this.subfolderArray[i].name+'.selected!=1) this.className=\'SubTDMenu\'" onclick="'+this.subfolderArray[i].name+'.loadLocation()"><span class="Item'+sClass+'">' + this.subfolderArray[i].title + '</span></td></tr>';
			}
		}
		var eTable = '</table>' + sEndLayer;
		this.subFoldersSubHTML = sTable + this.subFoldersSubHTML + eTable;
	}
	return this.subFoldersSubHTML;
}

	var foldersObjArray = new Array();
	var foldersObjArrayCount = 0;
	
	var currentTopFolderID = "";
	var emptyImg = hostPath + "/images/pixel.gif"
	var sHTML = "";	
	
	// BrowserCheck Object
	function BrowserCheck() {
		var u = navigator.userAgent.toLowerCase();
		this.u = u
		var b = navigator.appName
		if (b=="Netscape") this.b = "ns"
		else if (b=="Microsoft Internet Explorer") this.b = "ie"
		else this.b = b
		if(this.b=="ie" && this.u.indexOf('opera')!=-1) 
		this.b = "op"
		this.version = navigator.appVersion
		this.v = parseInt(this.version)
		this.op = (this.b=="op")
		//alert(this.op)
		this.op4 = (this.b=="op" && this.v==4)
		this.ns = (this.b=="ns" && this.v>=4)
		this.ns4 = (this.b=="ns" && this.v==4)
		this.ns5 = (this.b=="ns" && this.v==5)
		this.ie = (this.b=="ie" && this.v>=4)
		this.ie4 = (this.version.indexOf('MSIE 4')>0)
		this.ie5 = (this.version.indexOf('MSIE 5')>0)
		this.ie6 = (this.version.indexOf('MSIE 6')>0)			
		this.min = (this.ns||this.ie)
	}
	is = new BrowserCheck();
	//alert(is.b)
	
	//Netscape
	function setBgColorNS(oLayer,id,vColor){
		if(!eval("folder"+id).selected) oLayer.bgColor = vColor;
	}

function FolderSetBgColor(vColor){
	if(this.selected!=1){
		if (is.ns){
			if (is.ns4) this.css.bgColor = vColor;
			else this.css.backgroundColor = vColor;
		} 
		else{
			this.css.backgroundColor = vColor;
		}
	}
}	
	
function FolderLoadLocation(){
	if(this.link!=""){
		var sHostPath = (this.link.slice(0,7)=="http://"||this.link.slice(0,4)=="www."||this.link.slice(0,6)=="mailto:")? "":hostPath; 
		if(this.target!=""){
			switch(this.target){
				case "_blank":
					window.open(sHostPath+this.link)
				break	
				case "_top":
					top.document.location.href =  sHostPath+this.link;
				break	
				case  "_self":
					self.document.location.href =  sHostPath+this.link;
				break	
				case "_parent":
					parent.document.location.href =  sHostPath+this.link;
				break	
				default:
					document.location.href =  sHostPath+this.link;
				break																	
			}
		}
		else document.location.href =  hostPath+this.link;
	}
}

	
function FolderShow(){
	if (is.ns){
		if (is.ns4){
			eval("document.Box_"+this.id+".left = "+this.absx);
			eval("document.Box_"+this.id+".visibility = 'show'");
		}
		else {
			document.getElementById(this.name+'DDBox').style.left = (this.absx+5)+'px';
			document.getElementById(this.name+'DDBox').style.visibility = "visible";
		}
	} 
	else{
		if(is.ie4){
			eval(this.name+'DDBox').style.visibility = "visible";
			eval(this.name+'DDBox').style.left = this.absx;
		}
		else {
			//alert(this.absy)
			document.getElementById(this.name+'DDBox').style.left = this.absx + 5;
			document.getElementById(this.name+'DDBox').style.visibility = "visible";
		}
	}
	 if (is.ns){
	 	if(is.ns4) document.hideLayer.visibility = "show"
		else document.getElementById('hideLayer').style.visibility = "visible"
	}
	 else document.all['hideLayer'].style.visibility = "visible"
 }

function FolderHide(){
	if (is.ns){
		if (is.ns4) eval("document.Box_"+this.name+".visibility = 'hide'");
		else document.getElementById(this.name+'DDBox').style.visibility = "hidden";
	} 
	else{
		if(is.ie4)	eval(this.name+'DDBox').style.visibility = "hidden";
		else document.getElementById(this.name+'DDBox').style.visibility = "hidden";
	}
}

function DynLayerGetRelativeX() {
	return (is.ns)? this.css.pageX : this.elm.offsetLeft
}

function DynLayerGetRelativeY() {
	return (is.ns)? this.css.pageY : this.elm.offsetTop
}	

function hideFolder(){
	if(currentTopFolderID!=""){
		eval('folder'+currentTopFolderID+'.hide()');
		currentTopFolderID = "";
		if (is.ns){
		 	if(is.ns4) document.hideLayer.visibility = "hide"
			else document.getElementById('hideLayer').style.visibility = "hidden"
		}
		 else document.all['hideLayer'].style.visibility = "hidden"
	}
}	
	
function showSubMenu(id){
	eval('folder'+id+'.show()');
}
