/* Run function only when main lib is loaded */
Event.observe(document, 'core:loaded', function()
{
    // run only if rot13 is defined
    /*if (typeof rot13 == "function")
    {
        // process scrobled emails
        $$('a.email-scrambled').each(function(el)
        {
            if (el.readAttribute('rel'))
            {
                el.innerHTML = rot13(el.readAttribute('rel'));
                el.writeAttribute('href', 'mailto:' + el.innerHTML);
            }
        });

        $$('a.image-scrambled').each(function(el)
        {
            if (el.readAttribute('rel'))
            {
                el.writeAttribute('href', 'mailto:' + rot13(el.readAttribute('rel')));
            }
        });
    }*/

    // disable links with action
    $$('a.nolink').invoke('observe', 'click', function(e)
    {
        Event.stop(e);
    });

    // do dropdown menu
    $$('ul.ia_dropdown').each(function(el)
    {
        // should be LI elememnts
        el.childElements().each(function(child)
        {
            // if there is a submenu
            var submenu = child.down('ul');

            if(submenu)
            {
                // make sub-menu invisible
                submenu.hide();

                child.observe('mouseover', function()
                {
                    this.addClassName('active');
                    submenu.toggle();

                }.bind(child));

                child.observe('mouseout', function()
                {
                    this.removeClassName('active');
                    submenu.toggle();

                }.bind(child));

            }
        });
    });

    // {{{ add some cosmetics to HTML

    // add divs to dd elements
    /*$$('dd, #center_column h2, fieldset legend').each(function(el)
    {
        var d = new Element('span');

        d.innerHTML = el.innerHTML;

        el.update(d);
    });

    // }}}

    // Add interactivity to the map
    $$('a.map.controller').each(function(el)
    {
        el.observe('click', function(e)
        {
            Event.stop(e);

            var panel;

            var el = Event.element(e);

            if ($('contacts_map_panel'))
            {
                panel = $('contacts_map_panel');
            }

            if (el.readAttribute('rel'))
            {
                googleMapShowRoute(contactMap, el.readAttribute('rel'), panel);
            }

        });
    });*/

});



function submit_class_request()
{
	var params=$('class_form').serialize();
	var url='/submit_class_request.php';
	
	var fields=['first_name', 'last_name', 'contact_email', 'contact_phone', 'address_postal'];
	
	
	for(i=0;i<fields.length;i++)
	{
		if ($F(fields[i])=='')
		{
			alert('Please complete all fields');
			$(fields[i]).focus();
			return false;
		}
	}

	if ($F('ofage') != 1)
	{
		alert('Please confirm you\'re over 18 years of age');
		return false;
	}
	
	
	new Ajax.Request (url, {method:'post', parameters: params, onSuccess: function (transport){
		var rsp=transport.responseText;
	
		alert('Thank you!.  Your information was received succesfully. A representative from Extreme Fitness will contact you shortly');
		//alert(rsp);
		
	}})
	
	

}
