


   var esIE6 = (window.external && typeof window.XMLHttpRequest == "undefined");


    var cargando = false;

    this.historyListener = function(historyHash) {
		//stateVar = historyHash;
	   if (!cargando){
		   cargando = true;
		 if (historyHash == ''){
		   cargando = false;
		   location.href='index.php';
		 }
		 else{    
			 linkAjax2(historyHash,$('contenidoAjax'));
		 }
	   }
    };
                
// subscribe to unFocus.History
unFocus.History.addEventListener('historyChange', this.historyListener);



         function botonVolver(){
             if(!esIE6){
               window.history.back();
             }
         }


	 var progressBar = new Class({
	 	initialize: function(){
			this.destino = $('contenidoAjax');
			var tam = this.destino.getSize();
			this.MyBarra=new Element('div',{
				'id':'barra',
				'styles':{
					'width': tam.x,
					'height':tam.y,
					'background': 'url(./templates/montecatini/images/estructura/carga.gif) center no-repeat #000',
					'position':'absolute',
					'opacity': 0
				}
			});
		},
		mostrar: function(){
			$$('body').adopt(this.MyBarra);
			var pos = this.destino.getPosition();
			this.MyBarra.setStyle('z-index','99');
			this.MyBarra.setStyles({
				top: pos.y,
				left: pos.x,
				opacity: 0.6
			});
		},
		ocultar: function(){
			this.MyBarra.setStyle('opacity',0);
			this.MyBarra.destroy();
		}
	})

	     function linkAjax(link, destino,tmpl,nohistorial)
		  {   
	       var linkoriginal = link;
               
               if(tmpl){
                  link = link + tmpl;
                }
                if((!nohistorial) && (!esIE6)){                    
                  //alert('antes');
				  unFocus.History.addHistory(link);


                   //CODIGO SEGUIMIENTO GOOGLE
	               _gaq.push(['_trackPageview',link]); 

				   linkAjax2(link, destino);
                }else{   
					
                    linkAjax2(link, destino);
                }

         }


function linkAjax2(link, destino){
			
			   var barra = new progressBar(destino);
				
				barra.mostrar();  
				new Request.HTML({
					url:link,
					update:destino,
                    useWaiter: true,
					evalScripts: true,
					onSuccess: function (responseTree, responseElements, responseHTML, responseJavaScript){
                        barra.ocultar();  
						cargando = false;
                        //pageTracker._trackPageview(link);
					}		   
				}).post();
          }

         function FormAjax(formulario,destino,tmpl){
			//alert('aca2');
			//var barra = new progressBar(destino);
			//alert(barra);
				//barra.mostrar();  
			new Request.HTML({
			   url:formulario.action,
			   update:destino,
               useWaiter: true,
               waiterOptions:{
                    fxOptions:{duration: 500}
               },
			   evalScripts: true,
			   onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
						//	barra.ocultar();  	  
				}
			}).post(formulario);
		
			return false;
          }    
		
		
	
    
	  

