/********************************
*	DEVELOPED BY ANTONY ACUÑA	*
*********************************/
var currentShowedMenu;

var arrayOfImages = new Array();

function checkBrowser(){
	var browserName = navigator.appName;
	var browserVersion = navigator.appVersion;
	var browserAgent = navigator.userAgent;
	var intVersion = parseInt( browserVersion );
	
	this.ns = this.ie = this.moz = this.opera = this.opera6 = false;
	
	switch( browserName ){
		case "Netscape":
			this.ns = true;
			this.ns3 = ( intVersion >= 3 && intVersion < 4 );
			this.ns4 = ( intVersion >= 4 && intVersion < 5 );
			this.ns5 = ( intVersion >= 5 && intVersion < 6 );
			this.ns6 = ( browserAgent.indexOf('Netscape6') != -1 );
			this.ns7 = ( browserAgent.indexOf('Netscape7') != -1 || browserAgent.indexOf('Netscape/7') != -1 );
			break;
		case "Microsoft Internet Explorer":
			this.ie = true;
			this.ie4 = ( browserVersion.indexOf("MSIE 4") != -1 );
			this.ie5 = ( browserVersion.indexOf("MSIE 5") != -1 );
			this.ie6 = ( browserVersion.indexOf("MSIE 6") != -1 );						
			break;
		default:
			this.moz = ( browserVersion.substring(0,1) >= "5" );
			if( browserName == "Opera" || browserAgent.indexOf("Opera") != -1 ){
				this.opera = true;
				this.opera6 = ( browserVersion.substring(0,1) >= "6" || navigator.userAgent.indexOf("Opera 6") != -1 );
			}else{
				alert( "Lo sentimos este Navegador de intenet puede no soportar la aplicación correctamente." );
			}
			break;
	}
	
	this.DOM = ( this.moz || this.opera );
	this.min = ( this.ie || this.ns );
	this.win = ( browserAgent.indexOf("Windows") != -1 );
}
					
function createMenu( strItem ){
	var catTable = "";
	
	var regExp1 = new RegExp( '^(img):([^;]+);([^;]+);([^;]+);([^;]+);([^;]*);([0-1]{1})$', 'i' );
	var regExp2 = new RegExp( '^(txt):([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);([^;]*);([0-1]{1})$', 'i' );
	
	var matches = regExp1.exec( strItem );
	matches = ( !matches || matches == null )? regExp2.exec( strItem ) : matches;
	
	if( matches || matches != null ){
		
		catTable = addCatItem( matches );
	}
	try{
		document.writeln(catTable);
	}catch( e ){
		alert( e.message );
	}
}

function addCatItem( $item ){
	var cell = '';
	var action = "";
	switch( $item[1] ){
		case "img":
			action = ( $item[6] != '' )? ' onclick="location.href=\'' + $item[6] + '\'"' : '';
			action += ' onmouseover="showSubMenu(\'' + $item[2] + '\', this);"';
			if( $item[7] == 1 ){
				cell += '<td' + action + '><img border="0" src="' + $item[5] + '"></td>';
			}else{
				try{
					key = arrayOfImages.length
					arrayOfImages[ key ] = new Image();
					arrayOfImages[ key ] = $item[3];
					
					key = arrayOfImages.length
					arrayOfImages[ key ] = new Image();
					arrayOfImages[ key ] = $item[4];
				}catch( e ){
					alert( e.message );
				}
				
				cell += '<td' + action + '><img border="0" src="' + $item[3] + '" onmouseover="this.src=\'' + $item[4] + '\';" onmouseout="this.src=\'' + $item[3] + '\'"></td>';
			}
			break;
		case "txt":
			action = ( $item[7] != '' )? ' onclick="location.href=\'' + $item[7] + '\'"' : '';
			if( $item[8] == 1 ){
				cell += '<td' + action + ' class="' + $item[6] + '" onmouseover="showSubMenu(\'' + $item[2] + '\', this);" onmouseout="">' + $item[3] + '</td>';
			}else{
				cell += '<td' + action + ' class="' + $item[4] + '" onmouseover="showSubMenu(\'' + $item[2] + '\', this); this.className=\'' + $item[5] + '\';" onmouseout="this.className=\'' + $item[4] + '\';">' + $item[3] + '</td>';
			}
			break;
	}
	return cell;
}



var wb = new checkBrowser();
var regExp4SubItems = new RegExp('([^:]+):([^;]+);([^;]*);([^;]*)');
var subMenuIdName = "SubMenu_";
var flagPrefix = "flag_";
var blankSpace = "/tmp_img/ecblank.gif";

function showSubMenu( idCat, $obj ){
	var subMenu = null;
	if( wb.ie || wb.moz || wb.opera || wb.opera6 ){
		$obj.style.cursor = 'hand';
		if( currentShowedMenu ){
			currentShowedMenu.style.visibility = 'hidden';
		}
		subMenu = document.all[ subMenuIdName + idCat ];
		if( subMenu ){
			with( subMenu ){
				style.left = /*parseInt(document.body.leftMargin) +*/ parseInt($obj.offsetLeft) - 1;
				style.top = 90/*parseInt($obj.parentElement.offsetTop) + parseInt($obj.offsetHeight)*/;
				window.status = $obj.offsetParent.offsetTop;
				style.visibility = 'visible';
			}
		}
	}else{
		$obj.style.cursor = 'default';
		if( currentShowedMenu ){
			currentShowedMenu.visibility = 'hidden';
		}
		subMenu = document.getElementById(subMenuIdName + idCat );
		if( subMenu ){
			with( subMenu ){
				//style.left = /*parseInt(document.body.leftMargin) + */parseInt($obj.offsetLeft) - 1;
				//style.top = 91/*parseInt($obj.parentElement.offsetTop) + parseInt($obj.offsetHeight)*/;
				//window.status = $obj.offsetParent.offsetTop;
				visibility = 'show';
			}
		}
		//alert( $obj.style.cursor );
	}
	
	currentShowedMenu = subMenu;
	/*document.all['content'].value = "";
	for(var i in $obj ){
		document.all['content'].value += i + "\n";
	}*/
}

function subMenuItem( $arrayOfData ){
	this.name = flagPrefix + $arrayOfData[1];
	this.Text = $arrayOfData[2];
	this.href = $arrayOfData[3];
	this.target = $arrayOfData[4];
}

function subMenu( parentCat, bgColor, lineColor, css, arrow ){
	this.items = new Array();
	this.add = addSubMenu;
	this.create = createSubMenu;
	
	this.name = subMenuIdName + parentCat;
	this.parentCat = parentCat;
	this.cssName = css;
	this.bgColor = bgColor;
	this.lineColor = lineColor;
	this.arrow = arrow;
	
	this.imgArrow = new Image();
	this.imgArrow.src = this.arrow;
}

function addSubMenu( settings ){
	try{
		var matches = regExp4SubItems.exec( settings );
		if( matches != null && matches.length > 1 ){
			this.items[ this.items.length ] = new subMenuItem( matches );
		}
	}catch( e ){
	}
}

function createSubMenu(){
	if( this.items.length > 0 ){
		var content = '';
		if( wb.ie || wb.moz || wb.opera || wb.opera6 ){
			content += '<div id="' + this.name + '" style="position:absolute;visibility:hidden;" onmouseover="this.style.visibility=\'visible\';" onmouseout="this.style.visibility=\'hidden\'">';
			content += '<table cellpadding="0" cellspacing="0" border="0" bgcolor="' + this.lineColor + '"><tr><td>';
			content += '<table cellpadding="0" cellspacing="1" border="0">';
			for( n in this.items ){
				var i = this.items[n];
				content += '<tr><td>';
				content += '<table cellpadding="0" cellspacing="0" border="0" bgcolor="' + this.bgColor + '">';
				content += '<tr height="' + this.imgArrow.height + '" onclick="location.href=\'' + i.href + '\'" onmouseover="onSubItemFocus(this, \'' + i.name + '\', \'' + this.arrow + '\')" onmouseout="onLeaveSubItem(this, \'' + i.name + '\');">';
				content += '<td id="' +  i.name + '"><img id="img_' + i.name + '" width="' + this.imgArrow.width + '" border="0" src="' + blankSpace + '"></td>';
				content += '<td class="' +  this.cssName + '" nowrap><label>' + i.Text + '</label></td>';
				content += '<td width="100%"><img border="0" src="' + blankSpace + '"></td>';
				content += '</tr>';
				content += '</table>';
				content += '</td></tr>';
			}
			content += '</table>';
			content += '</td></tr></table>';
			content += '</div>';
		}else{
			content += '<layer name="' + this.name + '" visibility="hidden" onmouseover="this.visibility=\'visible\';" onmouseout="this.visibility=\'hidden\'">';
			content += '<table cellpadding="0" cellspacing="0" border="0" bgcolor="' + this.lineColor + '"><tr><td>';
			content += '<table cellpadding="0" cellspacing="1" border="0">';
			for( n in this.items ){
				var i = this.items[n];
				content += '<tr><td>';
				content += '<table cellpadding="0" cellspacing="0" border="0" bgcolor="' + this.bgColor + '">';
				content += '<tr height="24" onclick="location.href=\'' + i.href + '\'" onmouseover="onSubItemFocus(this, \'' + i.name + '\', \'' + this.arrow + '\')" onmouseout="onLeaveSubItem(this, \'' + i.name + '\');">';
				content += '<td id="' +  i.name + '"><img id="img_' + i.name + '" width="' + this.imgArrow.width + '" border="0" src="' + blankSpace + '"></td>';
				content += '<td nowrap><font class="' +  this.cssName + '">' + i.Text + '</font></td>';
				content += '<td width="100%"><img border="0" src="' + blankSpace + '"></td>';
				content += '</tr>';
				content += '</table>';
				content += '</td></tr>';
			}
			content += '</table>';
			content += '</td></tr></table>';
			content += '</layer>';
		}
		try{
			document.writeln( content );
		}catch( e ){
			alert( e.message );
		}
	}
}

function onSubItemFocus( $sender, cell2Change, arrow ){
	$sender.style.cursor = 'hand';
	document.getElementById('img_' + cell2Change).src = arrow;
}

function onLeaveSubItem($sender, cell2Change){
	document.getElementById('img_' + cell2Change).src = blankSpace;
}
