var ugcMsnbc = {
    Add: function(o)
    {
        ++this.file;
        var e = document.getElementById("ugcF" + this.file);
        if (e)
        {
            e.style.display = 'block';
            if (this.file == 5) { o.innerHTML = ""; }
        }
    },
    Send: function()
    {

        var f = document.forms["ugcForm"];
        if (f)
        {
            if (this.chkI(f.elements))
            {
                this.setTZ(f.elements);
                document.getElementById("ugcPa").innerHTML = '<iframe style="border:1px solid #888;" src="about:blank" name="ugcIframe" id="ugcIframe" frameborder="0" width="200" height="120"/>';
                var w = window.open("", "ugcIframe");
                w.document.write("<body style='margin:0px;text-align:center;font:80% verdana;'><img src='http://msnbcmedia.msn.com/i/msnbc/Components/UGC/loading.gif'><br>Almost done! Please don't navigate away from this page while we upload your content, it will cause the upload to fail.</body>");
                setTimeout('document.forms["ugcForm"].submit();document.forms["ugcForm"].reset();', 1000);
            }
            else
            {
                alert("You're almost done! Some required information is missing. Please complete all missing fields (in red) and click on the send button again.");
            }
        }
    },
    CkChar: function(o)
    {
        var t, e = document.getElementById(o.name + "char");
        if (e)
        {
            e.innerHTML = t = this.maxChar - o.innerHTML.length;
            e.style.color = (t > 0) ? "#000" : "#c00";
        }
    },
    FillY: function()
    {

        var e = document.forms["ugcForm"].elements["dob"];
        var d = new Date();
        var y = d.getFullYear() - 10;

        for (var i = 0; i < 100; i++)
        {
            var o = document.createElement("option");
            e.options.add(o);
            o.innerHTML = y - i;
        }
    },
    chkI: function(e)
    {
        var b = true;
        for (var x = 0; x < e.length; x++)
        {
            switch (e[x].tagName.toLowerCase())
            {
                case "input":
                    if (e[x].type.toLowerCase() != 'hidden' && e[x].type.toLowerCase() != 'checkbox')
                    {
                        if (this.chkR(e[x].previousSibling) && e[x].value == '')
                        {
                            this.setS(e[x].previousSibling, 0);
                            b = false;
                        }
                        else
                        {
                            this.setS(e[x].previousSibling, 1);
                        }
                    }
                    break;
                case "select":
                    if (this.chkR(e[x].previousSibling) && e[x].selectedIndex == 0)
                    {
                        this.setS(e[x].previousSibling, 0);
                        b = false;
                    }
                    else
                    {
                        this.setS(e[x].previousSibling, 1);
                    }
                    break;
                case "textarea":
                    this.CkChar(e[x]);
                    var ec = document.getElementById(e[x].name + "char");
                    if (ec) { b = (parseInt(ec.innerHTML) > 0); }
                    break;
            }
        }
        for (var x = 1; x < 6; x++)
        {
            if (e["f" + x])
            {
                if (e["f" + x].value != '' && e["fc" + x].value == '')
                {
                    this.setS(e["fc" + x].previousSibling, 0);
                    b = false;
                }
                else
                {
                    this.setS(e["fc" + x].previousSibling, 1);
                }
            }
        }
        return b;
    },
    chkR: function(o)
    {
        return (o.innerHTML.indexOf("*") > -1);
    },
    setS: function(o, b)
    {
        o.style.color = (b) ? "000" : "cc0000";
        o.style.fontWeight = (b) ? "normal" : "bold";
    },
    setTZ: function(e)
    {
        var d = new Date();
        var t = e["tzo"];
        if (t) { t.value = d.getTimezoneOffset(); }
    },
    file: 1,
    failed: false,
    maxChar: 3000
}
