function MM_preloadImages(){var d=document;if(d.images){if(!d.MM_p)d.MM_p=new Array();var i,j=d.MM_p.length,a=MM_preloadImages.arguments;for(i=0;i<a.length;i++)if(a[i].indexOf("#")!=0){d.MM_p[j]=new Image;d.MM_p[j++].src=a[i];}}}
function MM_swapImgRestore(){var i,x,a=document.MM_sr;for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++)x.src=x.oSrc;}
function MM_findObj(n,d){var p,i,x;if(!d)d=document;if((p=n.indexOf("?"))>0&&parent.frames.length){d=parent.frames[n.substring(p+1)].document;n=n.substring(0,p);}if(!(x=d[n])&&d.all)x=d.all[n];for(i=0;!x&&i<d.forms.length;i++)x=d.forms[i][n];for(i=0;!x&&d.layers&&i<d.layers.length;i++)x=MM_findObj(n,d.layers[i].document);if(!x&&d.getElementById)x=d.getElementById(n);return x;}
function MM_swapImage(){var i,j=0,x,a=MM_swapImage.arguments;document.MM_sr=new Array;for(i=0;i<(a.length-2);i+=3)if((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x;if(!x.oSrc)x.oSrc=x.src;x.src=a[i+2];}}
function MM_jumpMenu(targ,selObj,restore){ eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'"); if (restore) selObj.selectedIndex=0; }

/*
	@ Funciones especiales de la pagina 
	@ Author: Jorge D. Silveira
	@ Email: jorge.silveira [at] newlink-group [dot] com
	@ Company Page: www.newlink-group.com
	@ Personal page: www.aboyon.com.ar
	@ Date: Ago, 08 of 2008
	@
	@ ---------------------------------------------------------------------------------
	@
	@ script para capturar el click sobre el form de busqueda. 
	@ get the ENTER event on the search box
*/
Event.observe(window, 'load', function() {
	var absEngine = 'http://'+document.domain+'/web/search.php';
	Event.observe('buscar', 'click', function() {
		if ($('textfield').value=="") {
			alert("Por favor ingrese un criterio de busqueda valido");
		} else {
			location.href=absEngine+'?q='+encodeURIComponent($('textfield').value);
		}
	});
	Event.observe('textfield', 'keydown', function(event) { 
		if (event.keyCode==13 && $('textfield').value!="") {
			location.href=absEngine+'?q='+encodeURIComponent($('textfield').value);
		}
	});

});

Event.observe(window, 'load', function() {
	rateme('1');
	/*
		@Create the mask (black with transparency)
	*/
	var dark_layer = new Element('div',{ 'id': 'darklayer' ,'class' : 'dark_layer'});
	
	/*
		@ in order to fix the IE6 bug (combo box over any object of the page)
		@ create an iframe 
	*/
	var vifr = new Element('iframe',{ 'id':'iframe_layer', 'src': 'about:blank', 'frameborder':'0'});
	
	/*
		@ "Hagalo Online" window
	*/
	var vwin = new Element('div',{ 'id': 'virtual_window'});
	
	/*
		@ Close button
	*/	
	
	dark_layer.addClassName('dark_layer');						// attach the CSS class defined on estilos.css
	vwin.setStyle({'display':'none' , 'z-index':1009 });		// seting up the display and z-index (for window)
	vifr.setStyle({'display':'none' , 'z-index':1008 });		// seting up the display and z-index (for iframe fixer)
	vwin.insert('<div class="header"><div class="logo"></div><a id="closebtn" class="closevwin" href="javascript:restore_screen()">&nbsp;</a></div>');									// logo of "hagalo online"
	
	/*
		@ in this HTML load the ajax "online_window.php"
	*/
	vwin.insert('<div id="ajax_virtual_window"><p class="loader">Cargando por favor espere<br><a href="javascript:;" onClick="javascript:restore_screen();">cerrar</a></p></div>');
	
	
	$(document.body).insert(dark_layer);
	$(document.body).insert(vifr);
	$(document.body).insert(vwin);
	
	var embeds = document.getElementsByTagName('embed');		//Deprecated 
	var fhelp = embeds[1];										//Deprecated 
	
	
	/*
		@ add listeners / attach event to the "hagalo_online" gif image
		@ on click this image, display the mask, the iframe and the online windows
		@ IMPORTANT: this behavior is available only after the window/document loads
	*/
	if ($('boton_hagalo')) {
		$('boton_hagalo').observe('click', function(){
		
		/*
		 @ calculates the coordinates in order to center the window and the iframe
		 */
			var aut_x = Math.round((document.viewport.getWidth() / 2) - (vwin.getWidth() / 2));
			var aut_y = Math.round((document.viewport.getHeight() / 2) - (vwin.getHeight() / 2));
			var super_heigth = parseInt($(document.body).getHeight() + 250);
			dark_layer.setStyle({
				'opacity': '0.8',
				'-moz-opacity': '0.8',
				'filter': 'Alpha(Opacity=80)',
				'background': '#000000',
				'position': 'absolute',
				'top': 0,
				'left': 0,
				'display': 'block',
				'width': $(document.body).getWidth() + 'px',
				'height': super_heigth + 'px',
				'z-index': '9999997'
			});
			vwin.setStyle({
				'display': 'block',
				'opacity': '1',
				'-moz-opacity': '1',
				'filter': 'Alpha(Opacity=100)',
				'z-index': 1010,
				'margin-top': 100,
				'left': aut_x + 'px',
				'top': aut_y + 'px',
				'z-index': '9999999'
			});
			
			vifr.setStyle({
				'display': 'inline',
				'left': aut_x + 'px',
				'top': aut_y + 'px',
				'width': '700px',
				'height': '390px',
				'position': 'absolute',
				'z-index': '9999998'
			});
			
			/*
		 @ Create the news scroller...
		 */
			// build_news_scroll();
			
			
			/*
		 @ Call to the online_window.php
		 */
			call_virtual_window();
			
		});
	}
});


/*
	@ restore_screen function hide the dark layer, the iframe and the online window
*/
function restore_screen() {
	$('virtual_window').setStyle({'display':'none'});
	$('darklayer').setStyle({'display':'none'});
	$('iframe_layer').setStyle({'display':'none'});
}


/*
	@ AJAX loader of the online_window.php, the document with the windows links
	@ and navigation options
*/

function call_virtual_window() {
	var abs_file = 'http://'+document.domain+'/web/ajax/online_window.php';
	var ajax = new Ajax.Updater('ajax_virtual_window',abs_file,{method:'GET',paramenters:'_'});
}

function build_news_scroll() {
	var abs_file = 'http://'+document.domain+'/web/ajax/get_online_news.php';
	var ajax = new Ajax.Request(
			abs_file,
				{
				 	method:'GET',
					parameters:'_', 
					onSuccess: load_marquee,
					onFailure: function() {
						$('rotate_text').innerHTML = 'No se pudieron cargar noticias presione <a href="javascript:;" onClick="javascript:build_news_scroll();">aqui</a> para intentar nuevamente';
					}
					});
}

function load_marquee(ajax) {
	var txt = ajax.getResponseHeader("STRING-NEWS");
	build_scroll(100,1,'730px','20px',txt);
}

function build_scroll(speed,sa,w,h,txt) {
	$('rotate_text').innerHTML = '<marquee behavior="scroll" scrolldelay="'+speed+'" direction="up"  onmouseover="this.stop();" onmouseout="this.start();" scrollAmount='+sa+' style="overflow:hidden; width:'+w+';height:'+h+'">'+txt+'</marquee>';
}

function rateme(a) {
	var here = location.href;
	var abs_file = 'http://'+document.domain+'/web/sys/webalizer/rate';
	var ajax = new Ajax.Request(
			abs_file,
				{
				 	method:'POST',
					parameters:'_&ref='+document.referrer+'&location='+encodeURIComponent(here)+'&a='+a
				});
}

function loadMenu(id,tplPath,container,s) {
	var ajax = new Ajax.Updater(container,'/contents/components/menu/'+tplPath+'/' + container + s +'.html?id=' + Math.round(Math.random()*11000000),{method:'POST',paramenters:'_'});
}


staying_in_site = false;
Event.observe(document, 'click', function(event) {
  if (Event.element(event).tagName == 'A') {
    staying_in_site = true;
  }
});
Event.observe(window, 'beforeunload', function() {
  if(staying_in_site) {
    return;
  }
  rateme('0');
});