window.addEvent('domready', function() {
	//Personalizamos las entradas de datos de los formularios
	personalizarEntradasDatos();
	actualizarPedidosNuevos();
	try {
		if ( $('fondoVentana') ) {
			$('fondoVentana').setStyle('top', '0');
			$('fondoVentana').setStyle('left', '0');
			$('ventana').fade('hide');
			$('fondoVentana').fade('hide');
			/*$('fondoVentana').setStyle('width', screen.availWidth);
			$('fondoVentana').setStyle('height', screen.availHeight);*/
			/*$('fondoVentana').setStyle('width', window.innerWidth);
			$('fondoVentana').setStyle('height', window.innerHeight);*/
			$('fondoVentana').setStyle('width', document.body.clientWidth);
			$('fondoVentana').setStyle('height', document.body.clientHeight);
			window.addEvents({
				resize: function() {
					$('fondoVentana').setStyle('width', document.body.clientWidth);
					$('fondoVentana').setStyle('height', document.body.clientHeight);
				},
				scroll: function() {
					if ( Browser.Engine.trident ) { //En caso de IE
						if ( document.body.scrollHeight > document.body.clientHeight)
							$('fondoVentana').setStyle('height', document.body.scrollHeight);
						else
							$('fondoVentana').setStyle('height', document.body.clientHeight);
					} else {
						$('fondoVentana').setStyle('height', window.innerHeight + window.scrollMaxY);
					}
				}
			});
		}
	} catch(e) {}
});

function personalizarEntradasDatos() {
	var formIntroducirDatos = $$('textarea', 'input');

	formIntroducirDatos.each(function(item, index) {
		if ( !item.readOnly )
		{
			item.addEvents({
				focus: function() {
					item.setStyle('background', '#eee');
		
				},
				blur: function() {
					item.setStyle('background', '#fff');
		
				}
			});
		}
	});
}

var colorTR = "";
var estado = 0;
function personalizarTablasDatos() {
	//Personalizamos las tablas de datos
	var filasTablas = $$('.tblfoco');
	filasTablas.each(function(item, index) {
		item.addEvents({
			mouseover: function() {
				colorTR = item.getStyle('background');
				item.setStyle('backgroundColor', '#FFFFCC');
				estado = 0;
			},
			mouseout: function() {
				item.setStyle('backgroundColor', colorTR);
				estado = 1;
			}
		});
	});
}

function actualizarPedidosNuevos() {
	var actualizarNumPedidosRequest = new Request({
		method: 'get',
		url: 'componentes/home/nuevos.php?anticache=' + Math.floor(Math.random()*9999999), //anticache es para evitar la cache en IE
		onRequest: function() { },
		onSuccess: function(texto, xmlrespuesta){
			if ( texto == '0' ) $('spnumnuevos').set('text', '');
			else $('spnumnuevos').set('text', '[' + texto + ']');
		},
		onFailure: function(){ }
	});
	actualizarNumPedidosRequest.setHeader('Expires','0');
	actualizarNumPedidosRequest.setHeader('Last-Modified','0');
	actualizarNumPedidosRequest.setHeader('Cache-Control','no-cache, mustrevalidate');
	actualizarNumPedidosRequest.setHeader('Pragma','no-cache');
	actualizarNumPedidosRequest.send();
}
