                function format_email(e, obj)
                {
                        var key = false;
                        if (e.keyCode) key = e.keyCode;
                        if (e.which) key = e.which;
                        if (key)
                        {
                                key = parseInt(key,10);
                                if (key == 32)
                                {
                                        // trim spaces
                                        obj.value = obj.value.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");

                                        if (obj.value.indexOf('@') <= 0)
                                                obj.value += '@';
                                        else
                                                obj.value += '.';
                                        return false;
                                }
                        }
                        return true;
                }

            var currentWidth = 0;


            function updateLayout()
            {
                if (window.innerWidth != currentWidth)
                {
                    currentWidth = window.innerWidth;

                        var orient;
                        if (currentWidth == 320)
                        {
                                orient = "profile";
                                width = 320;
                        }
                        else
                        {
                                orient = "landscape";
                                width=480;
                        }
                    document.body.setAttribute("orient", orient);
                    setTimeout(function()
                    {
                        window.scrollTo(0, 1);
                    }, 100);
                }
            }


        if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
            addEventListener("load", function()
            {
                setTimeout(updateLayout, 0);
            }, false);
            setInterval(updateLayout, 400);
        }

        function onchange_submit(control, form) {

            if (document.getElementById(control) && document.getElementById(form)) {

                document.getElementById(control).addEventListener('change', function() {
                    document.getElementById(form).submit();
                }, false);
            }
        }

        // When we don't have jQuery, use this to stop (eg) click events from
        // bubbling in an event handler

        function kill_event(e) {

            e=e||event;
            e.preventDefault ? e.preventDefault() : e.returnValue = false;
            return false;
        }


