/*
 * Proyecto 83 - http://proyecto83.com
 * Copyright (C) 2008 Emilio Mariscal
 * 
 * == BEGIN LICENSE ==
 * 
 * Licensed under the terms of any of the following licenses at your
 * choice:
 * 
 *  - GNU General Public License Version 2 or later (the "GPL")
 *    http://www.gnu.org/licenses/gpl.html
 * 
 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
 *    http://www.gnu.org/licenses/lgpl.html
 * 
 * == END LICENSE ==
 * 
 * 	File Name  :
 *
 * 	visualfx.js
 *
 * File Authors :
 * 		Emilio Mariscal ( emi420@gmail.com )
 */
 
var visualFX = {
	
	eMenu : null,
	aMenuList : null,
	cMenu : 0,
	
	loadMenu: function( eId ) {

		/*** Dropdown menu ***/
		
		eMenu = document.getElementById(eId) ;
		aMenuList = eMenu.getElementsByTagName('li') ;
	
		for( var i = 0 ; i < aMenuList.length ; i++ ) {
		
			if( ( aMenuList[i].className == 'dw-menu') || (aMenuList[i].className == 'dw-menu on' ) ) {

			var aMenuListElements = aMenuList[i].getElementsByTagName('li') ;
				
				for( var j = 0 ; j < aMenuListElements.length ; j++ ) {
				
					aMenuListElements[j].onmouseover = function() {
						visualFX.cMenu = 1 ;
					}

					aMenuListElements[j].onmouseout = function() {
						visualFX.cMenu = 0 ;
						setTimeout( "if(visualFX.cMenu==0) visualFX.hideMenus()" , 1400);
					} 						
				
					if( aMenuListElements[j].className == 'dw-submenu' ) {
					
						var aSubMenuListElements = aMenuListElements[j].getElementsByTagName('li') ;
						for( var k = 0 ; k < aSubMenuListElements.length ; k++ ) {
						
							aSubMenuListElements[k].onmouseover = function() {
								this.className = 'on' ;
							}
							
							aSubMenuListElements[k].onmouseout = function() {
								this.className = null ;
							}
							
						}
						
					} else {
						aMenuListElements[0].getElementsByTagName('a')[0].onmouseover = function() {
							visualFX.cMenu = 1 ;
							currentMenu = this.parentNode.parentNode.parentNode ;
							aSubMenu = this.parentNode.parentNode.getElementsByTagName('li') ;
							if( aSubMenu[1].className != 'dw-submenu' ) {
								visualFX.hideMenus() ;
								aSubMenu[1].className = 'dw-submenu' ; 
								this.parentNode.className = 'on' ;
								currentMenu.className = 'dw-menu on' ;
							}
							document.getElementById('cabecera').className = 'cabecera menu-activo' ;
						} 		
						aMenuListElements[0].getElementsByTagName('a')[0].onmouseout = function() {
							visualFX.cMenu = 0
							setTimeout( "if(visualFX.cMenu==0) visualFX.hideMenus()" , 3000);
						} 							
					}
				}
			}
			
		}
	
	},
	
	hideMenus: function() {
		for( var i = 0 ; i < aMenuList.length ; i++ ) {
			if( aMenuList[i].className == 'dw-submenu' ) {
				aMenuList[i].className = 'dw-submenu hidden';
			} else if ( aMenuList[i].className == 'on' ) {
				aMenuList[i].className = '' ;
			} else if ( aMenuList[i].className == 'dw-menu on' ) {
				aMenuList[i].className = 'dw-menu' ;
			}
		}
		document.getElementById('cabecera').className = 'cabecera' ;
	}
}
		
/*** Lightbox ***/

function descargarInforme(){
	MOOdalBox.close() ;
	//document.location= 'http://cicmas.ccd2.com/fileHandler.aspx?file=' + getParm( 'nId' ) ;
	document.location= 'fileHandler.aspx?file=' + getParm( 'nId' ) ;
	
}

/*** Lightbox ***/

function getParm( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

/*** Lightbox ***/

function htmlLightbox(url){
	MOOdalBox.open(url, "", "700 340");
}
