
function eventoModal(objetivo){
	try {
		
	
		$.left_panel = $('#left-panel');
		$.shortcut_dropdown = $('#shortcut');
		$.bread_crumb = $('#ribbon ol.breadcrumb');
	
		
		
		$( " a[data-toggle=modal]", objetivo).unbind('click').click(function(){
			var target = undefined;
			var url = $(this).prop('href');
			destino = $(this).attr('data-target');
			if(destino != undefined){
				target = $(destino);
			}
			
			if(target == undefined){
				target = creaModal();
				
				$(target).load(url, {modal: true},function(){
				    $(target).modal({
				        keyboard:true,
				        backdrop:true
				    });
				});	
			}else{
				cargaURL(url, target, false);
				//$(target).load(url, {modalDestino: true},function(){});
				   
				
			}
			
			 
			return false;
			//return false;
		});
		
		//$( " a[data-toggle!=modal][href!='#'][target!='_blank']:not([href^=tel]):not([href^='javascript']):not([class='noajax')", objetivo).unbind('click').click(function(){
		$( " a[data-toggle!=modal][href!='#'][target!='_blank']:not([href^=tel]):not([href^='javascript'])", objetivo).unbind('click').click(function(){
			var url = $(this).prop('href');
			navegaUrl(url);
			return false;
		});
		
		
		$('#guardado_global a').unbind('click').click(function(){
			$('#principal #main form #guardar').click();
			return false;
		});
		
		if($('#guardado_global a').length == 1){
			$('#principal #main form #guardar').hide();
		}
		
		
		
		
		/*
		 * Fire tooltips
		 */
		if ($("[rel=tooltip]", objetivo).length) {
			$("[rel=tooltip]", objetivo).tooltip();
		}
		
		//TODO: was moved from window.load due to IE not firing consist
		nav_page_height()
	
		// INITIALIZE LEFT NAV
		if (!null) {
			$('nav ul', objetivo).jarvismenu({
				accordion : true,
				speed : $.menu_speed,
				closedSign : '<em class="fa fa-expand-o"></em>',
				openedSign : '<em class="fa fa-collapse-o"></em>'
			});
		} else {
			alert("Error - menu anchor does not exist");
		}
		
		
		// COLLAPSE LEFT NAV
		$('.minifyme', objetivo).click(function(e) {
			$('body').toggleClass("minified");
			$(this).effect("highlight", {}, 500);
			e.preventDefault();
		});
		
		// HIDE MENU
		$('#hide-menu >:first-child > a', objetivo).unbind('click').click(function(e) {
			$('body').toggleClass("hidden-menu");
			e.preventDefault();
		});
		
		$('#show-shortcut', objetivo).unbind('click').click(function(e) {
			if ($.shortcut_dropdown.is(":visible")) {
				shortcut_buttons_hide();
			} else {
				shortcut_buttons_show();
			}
			e.preventDefault();
		});
		
		// SHOW & HIDE MOBILE SEARCH FIELD
		$('#search-mobile', objetivo).unbind('click').click(function() {
			$.root_.addClass('search-mobile');
		});
	
		$('#cancel-search-js', objetivo).unbind('click').click(function() {
			$.root_.removeClass('search-mobile');
		});
		
		// ACTIVITY
		// ajax drop
		$('#activity', objetivo).unbind('click').click(function(e) {
			var $this = $(this);
	
			if ($this.find('.badge').hasClass('bg-color-red')) {
				$this.find('.badge').removeClassPrefix('bg-color-');
				$this.find('.badge').text("0");
				// console.log("Ajax call for activity")
			}
	
			if (!$this.next('.ajax-dropdown').is(':visible')) {
				$this.next('.ajax-dropdown').fadeIn(150);
				$this.addClass('active');
			} else {
				$this.next('.ajax-dropdown').fadeOut(150);
				$this.removeClass('active')
			}
	
			var mytest = $this.next('.ajax-dropdown').find('.btn-group > .active > input').attr('id');
			//console.log(mytest)
	
			e.preventDefault();
		});
	
		$('input[name="activity"]', objetivo).change(function() {
			//alert($(this).val())
			var $this = $(this);
	
			url = $this.attr('id');
			container = $('.ajax-notifications');
	
			loadURL(url, container);
	
		});
		
		$('button[data-loading-text]', objetivo).on('click', function() {
			var btn = $(this)
			btn.button('loading')
			setTimeout(function() {
				btn.button('reset')
			}, 3000)
		});
	
		
	
		notification_check();
	
		// RESET WIDGETS
		$('#refresh', objetivo).unbind('click').click(function(e) {
			
			var $this = $(this);
			
			$.widresetMSG = $this.data('reset-msg');
			
			$.SmartMessageBox({
				title : "<i class='fa fa-refresh' style='color:green'></i> Clear Local Storage",
				content : $.widresetMSG || "Would you like to RESET all your saved widgets and clear LocalStorage?",
				buttons : '[No][Yes]'
			}, function(ButtonPressed) {
				if (ButtonPressed == "Yes" && localStorage) {
					localStorage.clear();
					location.reload();
				}
	
			});
			e.preventDefault();
		});
	
		// LOGOUT BUTTON
		$('#logout a#salir', objetivo).unbind('click').click(function(e) {
			//get the link
			var $this = $(this);
			$.loginURL = $this.attr('href');
			$.logoutMSG = $this.data('logout-msg');
	
			// ask verification
			$.SmartMessageBox({
				title : "<i class='fa fa-sign-out txt-color-orangeDark'></i> Salir <span class='txt-color-orangeDark'><strong>" + $('#show-shortcut').text() + "</strong></span> ?",
				content : $.logoutMSG || "Para mejorar la seguridad puedes cerrar el navegador tras pulsar SI",
				buttons : '[No][Si]'
	
			}, function(ButtonPressed) {
				if (ButtonPressed == "Si") {
					$.root_.addClass('animated fadeOutUp');
					setTimeout(logout, 1000)
				}
	
			});
			e.preventDefault();
		});
	
		
		
	
		/*
		* SHORTCUTS
		*/
	
		// SHORT CUT (buttons that appear when clicked on user name)
		$.shortcut_dropdown.find('a').click(function(e) {
	
			e.preventDefault();
	
			window.location = $(this).attr('href');
			setTimeout(shortcut_buttons_hide, 300);
	
		});
	
		// SHORTCUT buttons goes away if mouse is clicked outside of the area
		$(document).mouseup(function(e) {
			if (!$.shortcut_dropdown.is(e.target)// if the target of the click isn't the container...
			&& $.shortcut_dropdown.has(e.target).length === 0) {
				shortcut_buttons_hide()
			}
		});
		
		$('#main', objetivo).resize(function() {
			nav_page_height();
			check_if_mobile_width();
		});
	
		$('nav', objetivo).resize(function() {
			nav_page_height();
		});
		
		
	
		/*
		* APP AJAX REQUEST SETUP
		* Description: Executes and fetches all ajax requests also
		* updates naivgation elements to active
		*/
		if($.navAsAjax)
		{
		    // fire this on page load if nav exists
		    if ($('nav', objetivo).length) {
			    checkURL();
		    };
	
		    $(objetivo).on('click', 'nav a[href!="#"]', function(e) {
			    e.preventDefault();
			    var $this = $(e.currentTarget);
	
			    // if parent is not active then get hash, or else page is assumed to be loaded
				if (!$this.parent().hasClass("active") && !$this.attr('target')) {
	
				    // update window with hash
				    // you could also do here:  $.device === "mobile" - and save a little more memory
	
				    if ($.root_.hasClass('mobile-view-activated')) {
					    $.root_.removeClass('hidden-menu');
					    window.setTimeout(function() {
							if (window.location.search) {
								window.location.href =
									window.location.href.replace(window.location.search, '')
										.replace(window.location.hash, '') + '#' + $this.attr('href');
							} else {
								window.location.hash = $this.attr('href')
							}
					    }, 150);
					    // it may not need this delay...
				    } else {
						if (window.location.search) {
							window.location.href =
								window.location.href.replace(window.location.search, '')
									.replace(window.location.hash, '') + '#' + $this.attr('href');
						} else {
							window.location.hash = $this.attr('href');
						}
				    }
			    }
	
		    });
	
		    // fire links with targets on different window
		    //$(objetivo).on('click', 'nav a[target="_blank"]', function(e) {
		    $(objetivo).on('click', 'a[target="_blank"]', function(e) {
			    e.preventDefault();
			    var $this = $(e.currentTarget);
	
			    window.open($this.attr('href'));
		    });
	
		    // fire links with targets on same window
		    $(objetivo).on('click', 'nav a[target="_top"]', function(e) {
			    e.preventDefault();
			    var $this = $(e.currentTarget);
	
			    window.location = ($this.attr('href'));
		    });
	
		    // all links with hash tags are ignored
		    $(objetivo).on('click', 'nav a[href="#"]', function(e) {
			    e.preventDefault();
		    });
	
		    // DO on hash change
		    $(window).on('hashchange', function() {
			    checkURL();
		    });
		}

	} catch (e) {
		// TODO: handle exception
	}
	
}




/*
 * LOAD SCRIPTS
 * Usage:
 * Define function = myPrettyCode ()...
 * loadScript("js/my_lovely_script.js", myPrettyCode);
 */

var jsArray = {};

function loadScript(scriptName, callback) {
	
	if (!jsArray[scriptName]) {
		
		jsArray[scriptName] = true;

		// adding the script tag to the head as suggested before
		var body = document.getElementsByTagName('body')[0];
		var script = document.createElement('script');
		script.type = 'text/javascript';
		script.src = scriptName;

		// then bind the event to the callback function
		// there are several events for cross browser compatibility
		//script.onreadystatechange = callback;
		script.onload = callback;

		// fire the loading
		body.appendChild(script);

	} else if (callback) {// changed else to else if(callback)
		//console.log("JS file already added!");
		//execute function
		callback();
	}

}

/* ~ END: LOAD SCRIPTS */




//Fonction de retour de la date
function callFromActivity_RetDate(indice, data) {
	$('input:eq( '+ indice +' )').val(data);
	$('input:eq( '+ indice +' )').change();

}

//Fonction d'appel calendrier Android
function f_CallCalendar(indice, valor)
{
	try {
		MSSAndroidFunction.openDatePickerDialog(indice, valor);
	} catch (e) {
		// TODO: handle exception
	}
  
}




$( document ).ready( function() {
	
	$.widget( "custom.catcomplete", $.ui.autocomplete, {
	    _renderMenu: function( ul, items ) {
	      var that = this,
	        currentCategory = "";
	      $.each( items, function( index, item ) {
	        if ( item.category != currentCategory  && item.category != undefined) {
	          ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
	          currentCategory = item.category;
	        }
	        that._renderItemData( ul, item );
	      });
	    }
	  });
	
});