var ARCRAGING={
	init:function(){
		ARCRAGING.hacerBlank();
		if ($chk($('home')))
			swfobject.embedSWF("/flash/index.swf", "cnt_flash", "882", "386", "9.0.0", "expressInstall.swf");
		else if ($chk($('facilidades')))
			swfobject.embedSWF("/flash/facilidades.swf", "cnt_flash", "882", "244", "9.0.0", "expressInstall.swf");
		else if ($chk($('sobre')))
			swfobject.embedSWF("/flash/sobrearc.swf", "cnt_flash", "882", "244", "9.0.0", "expressInstall.swf");
		else if (($chk($('noticias'))) || ($chk($('marcas'))))
			swfobject.embedSWF("/flash/noticias.swf", "cnt_flash", "882", "244", "9.0.0", "expressInstall.swf");
		else if ($chk($('reparacion')))
			swfobject.embedSWF("/flash/reparacion.swf", "cnt_flash", "882", "244", "9.0.0", "expressInstall.swf");
		else if ($chk($('llantas')))
			swfobject.embedSWF("/flash/llantas.swf", "cnt_flash", "882", "244", "9.0.0", "expressInstall.swf");
		else if ($chk($('cuaxcua')))
			swfobject.embedSWF("/flash/4x4.swf", "cnt_flash", "882", "244", "9.0.0", "expressInstall.swf");

		if ($chk($('txt_phone'))){
			$('txt_phone').addEvents({
				'mouseover': function(){
					$('txt_phone').set('text','91 501 78 87');
				},
				'mouseout' : function(){
					$('txt_phone').set('text','TELÉFONO');
				},
				'click' : function(){
					return false;
				}
			});
		}
		if ($chk($('newsletter'))){
			$('frnewsletter').addEvent('submit',function(){
				var sMsg = '';
				var filter=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
				if ($('emailnews').value == '')
					sMsg += 'Debe indicar un email \n';
				else if (!filter.test($('emailnews').value))
					sMsg += 'Debe indicar un email válido \n';
				if (sMsg != '')
					alert(sMsg);
				else
					ARCRACING.llamadaAjax();
				return false;
			});
		}
	},
	llamadaAjax : function(){
		var myAjax = new Request({
			url : location.protocol+'//'+location.hostname+'/includes/processor.php',
			method : 'post',
			data : 	{
				'seccion' : 'newsletter',
				'emailnews' : $('emailnews').value
			},
			onComplete : function(element){
				datos = JSON.decode(element);
				if (datos['existe']){
					if (datos['creado'])
						$('emailnews').value = 'Alta OK';
					else						
						$('emailnews').value = 'Vuelva a intentarlo';
				}
				else
					$('emailnews').value = 'Usuario Incorrecto';
			}
		});
		myAjax.send();
	},
	hacerBlank : function(){
		$$('a.hacerblank').addEvent('click',function(element){
			window.open(this.href, this.title, "scrollbars=1,width=1024,height=768,target=blank");
			return false;
		});
	}

	
};
	
			
/* LOAD */

function addLoadEvent(fn){
var old = window.onload;
	if(typeof window.onload != 'function')
		window.onload = fn;
	else
	window.onload = function(){
		old();
		fn();
	}
}

addLoadEvent( function() { ARCRAGING.init(); } );
