var domain = {
	checkformat: function (dominio)
	{
		formato = new RegExp (/^\w+([\.-]?\w+)*(\.\w{2,3})+$/);
		if (!formato.test(dominio))
		{
			alert ('Su busqueda no cumple con el formato de un dominio');
			return false;
		}
		
		return true;
	}
}

function init ()
{
	myTabs = new mootabs ('content_tab', {
		height: '200px',
		width: '250px',
		duration: 1000,
		activateOnLoad: 'first',
		useAjax: true,
		ajaxMethod: 'post',
		ajaxUrl: '/index/plans',
		useHistoryManager: false
	})
}

var roar = new Roar ({position: 'lowerRight', duration: 5000});

window.addEvent ('domready', function ()
{
	init();
	
	$('btnGo').addEvent ('click', function ()
	{
		if ($('s').value != "")
		{
			if ($('messages'))
			{
				$('messages').empty();	
			}
			
			if (domain.checkformat($('s').value)) 
			{
				$('searchform').submit();
			}
		}
		else
		{
			roar.alert ('Mensaje del Sistema','Debe de escribir un dominio, ej: midominio.com');
		}
	});
	
	$('searchform').addEvent ('submit', function (e)
	{
		e.stop();
		$('btnGo').fireEvent ('click');
	});
	
	if ($("dsearch"))
	{
		$('btn').addEvent ('click', function ()
		{
			if ($('search_domain').value != "")
			{
				if (domain.checkformat($('search_domain').value))
				{
					$('dsearch').submit();
				}
			}
			else
			{
				roar.alert ("Mensaje del Sistema", "Debe de escribir un dominio, ej: midominio.com");
			}
		});
		
		$("dsearch").addEvent ('submit', function (e)
		{
			e.stop();
			$('btn').fireEvent ('click');
		});
	}
	
	if ($('lnk'))
	{
		$('lnk').addEvent('click', function(e)
		{
			Event.stop(e);
			$('2CO').submit();
		});
		
		$$('.tips').store('tip:title', 'Buy from 2CO');
		$$('.tips').store('tip:text', '2CheckOut.com Inc. (Ohio, USA)<br /> is an authorized retailer for goods and services<br /> provided by DWD&Solutions.  ');
	}
	
	if ($('hosting-plans'))
	{
		$$('.tips').each (function(valor, index)
		{
		    $(valor.id).addEvent ('click', function(e)
		    {
		    	Event.stop(e);
		    	var formulario = '2CO'+(index+1);
		    	$(formulario).submit();
		    });
		    
		    $(valor.id).store('tip:title', 'Buy from 2CO');
			$(valor.id).store('tip:text', '2CheckOut.com Inc. (Ohio, USA)<br /> is an authorized retailer for goods and services<br /> provided by DWD&Solutions.  ');
		});
	}
	
	if($('Enviar'))
	{
		$('Enviar').addEvent('click', function(e)
		{
			Event.stop(e);
			
			if ($('name').value != "")
			{
				var name = $('name').value;	
				
				if ($('email').value != "")
				{
					var email = $('email').value;
					
					if ($('comentario').value != "")
					{
						var comment = $('comentario').value;	
					}
					else
					{
						roar.alert ("Mensaje del Sistema", "Debe de escribir un comentario");
					}	
				}
				else
				{
					roar.alert ("Mensaje del Sistema", "Debe de escribir un email");
				}
			}
			else
			{
				roar.alert ("Mensaje del Sistema", "Debe de llenar el campo nombre");
			}
			
			var jsonRequest = new Request.JSON ({url: "/contactus/send", onSuccess: function (json, text)
			{
				if (json!=null)
				{
					roar.alert ("Mensaje del Sistema", "Su mensaje se ha enviado. Gracias por contactarnos!");
					$('contacto').reset();
				}		
				else
				{
					roar.alert ("Mensaje del Sistema", "Error al enviar su comentario")
				}
			}}).send('name='+name+'&email='+email+'&comentario='+comment);
		});
	}
	
	var Tips1 = new Tips('.tips',{
        showDelay: 400,
        hideDelay: 400,
        fixed:false
    });
	Tips1.addEvent('onShow', function(tip){
		tip.fade('in');
	});
	Tips1.addEvent('onHide', function(tip){
		tip.fade('out');
	});

});