function getObject(objectId) { return document.getElementById(objectId); }
function getObjectStyle(objectId) { var obj = getObject(objectId); return obj.style;}

var page_loaded = true;

function kpe_generate() { document.profile.submit(); }

function kpe_update(property, value)
{
        if (page_loaded) {
        
                var ms_body                = getObjectStyle("fullbody");
                var ms_table1        = getObjectStyle("infotbl");
                var ms_table2        = getObjectStyle("linktbl");
                var ms_name                = getObjectStyle("infoname");
                var ms_title        = getObjectStyle("infotitle");
                var ms_text                = getObjectStyle("infotext");
                var ms_link                = getObjectStyle("infolink");

                switch(property)
                {
                        // Body Background
                        case 'backgroundColor':                                ms_body.backgroundColor = value; break;
                        case 'backgroundImage':                                ms_body.backgroundImage = "url(" + value + ")"; break;
                        case 'backgroundPosition':                        ms_body.backgroundPosition = value; break;
                        case 'backgroundRepeat':                        ms_body.backgroundRepeat = value; break;
                        case 'backgroundAttachment':                ms_body.backgroundAttachment = value; break;
                        // Sections (tables)
                        case 'sectionBackgroundColor':                ms_table1.backgroundColor = ms_table2.backgroundColor = value; break;
                        case 'sectionBorderColor':                        ms_table1.borderColor = ms_table2.borderColor = value; break;
                        case 'sectionBorderWidth':                        ms_table1.borderWidth = ms_table2.borderWidth = value + "px"; ms_table1.width = ms_table2.width = (350 - (value * 2)) + "px"; break;
                        case 'sectionBorderStyle':                        ms_table1.borderStyle = ms_table2.borderStyle = value; break;
                        case 'sectionOpacity':                                if (navigator.appName.indexOf("Netscape")!=-1 && parseInt(navigator.appVersion) >= 5) { ms_table1.MozOpacity = ms_table2.MozOpacity = value/100; } else if (navigator.appName.indexOf("Microsoft") != -1 && parseInt(navigator.appVersion)>=4) { ms_table1.filter = ms_table2.filter = "alpha(opacity=" + value + ")"; } break;
                        // Name Text
                        case 'nameFontFamily':                                ms_name.fontFamily = value; break;
                        case 'nameFontSize':                                ms_name.fontSize = value + "px"; break;
                        case 'nameFontColor':                                ms_name.color = value; break;
                        case 'nameFontWeight':                                if (getObject("sp_nameFontWeight").value == "normal") { ms_name.fontWeight = value; getObject("nfso1").className = "selected"; } else { value = "normal"; ms_name.fontWeight = value; getObject("nfso1").className = ""; } break;
                        case 'nameFontStyle':                                if (getObject("sp_nameFontStyle").value == "normal") { ms_name.fontStyle = value; getObject("nfso2").className = "selected"; } else { value = "normal"; ms_name.fontStyle = value; getObject("nfso2").className = ""; } break;
                        case 'nameFontDecoration':                        if (getObject("sp_nameFontDecoration").value == "none") { ms_name.textDecoration = value; getObject("nfso3").className = "selected"; } else { value = "none"; ms_name.textDecoration = value; getObject("nfso3").className = ""; } break;
                        // Headings
                        case 'headingFontFamily':                        ms_title.fontFamily = value; break;
                        case 'headingFontSize':                                ms_title.fontSize = value + "px"; break;
                        case 'headingFontColor':                        ms_title.color = value; break;
                        case 'headingFontWeight':                        if (getObject("sp_headingFontWeight").value == "normal") { ms_title.fontWeight = value; getObject("hfso1").className = "selected"; } else { value = "normal"; ms_title.fontWeight = value; getObject("hfso1").className = ""; } break;
                        case 'headingFontStyle':                        if (getObject("sp_headingFontStyle").value == "normal") { ms_title.fontStyle = value; getObject("hfso2").className = "selected"; } else { value = "normal"; ms_title.fontStyle = value; getObject("hfso2").className = ""; } break;
                        case 'headingFontDecoration':                if (getObject("sp_headingFontDecoration").value == "none") { ms_title.textDecoration = value; getObject("hfso3").className = "selected"; } else { value = "none"; ms_title.textDecoration = value; getObject("hfso3").className = ""; } break;
                        // Main Text
                        case 'fontFamily':                                        ms_text.fontFamily = ms_link.fontFamily = value; break;
                        case 'fontSize':                                        ms_text.fontSize = ms_link.fontSize = value + "px"; break;
                        case 'fontColor':                                        ms_text.color = value; break;
                        case 'fontWeight':                                        if (getObject("sp_fontWeight").value == "normal") { ms_text.fontWeight = value; getObject("fso1").className = "selected"; } else { value = "normal"; ms_text.fontWeight = value; getObject("fso1").className = ""; } break;
                        case 'fontStyle':                                        if (getObject("sp_fontStyle").value == "normal") { ms_text.fontStyle = value; getObject("fso2").className = "selected"; } else { value = "normal"; ms_text.fontStyle = value; getObject("fso2").className = ""; } break;
                        case 'fontDecoration':                                if (getObject("sp_fontDecoration").value == "none") { ms_text.textDecoration = value; getObject("fso3").className = "selected"; } else { value = "none"; ms_text.textDecoration = value; getObject("fso3").className = ""; } break;
                        // Links
                        case 'linkFontColor':                                ms_link.color = value; break;
                        case 'linkFontWeight':                                if (getObject("sp_linkFontWeight").value == "normal") { ms_link.fontWeight = value; getObject("lso1").className = "selected"; } else { value = "normal"; ms_link.fontWeight = value; getObject("lso1").className = ""; } break;
                        case 'linkFontStyle':                                if (getObject("sp_linkFontStyle").value == "normal") { ms_link.fontStyle = value; getObject("lso2").className = "selected"; } else { value = "normal"; ms_link.fontStyle = value; getObject("lso2").className = ""; } break;
                        case 'linkFontDecoration':                        if (getObject("sp_linkFontDecoration").value == "none") { ms_link.textDecoration = value; getObject("lso3").className = "selected"; } else { value = "none"; ms_link.textDecoration = value; getObject("lso3").className = ""; } break;
                        // Links (hover)
                        case 'linkHoverFontColor':                        /* */ break;
                        case 'linkHoverFontWeight':                        if (getObject("sp_linkHoverFontWeight").value == "normal") { getObject("lhso1").className = "selected"; } else { value = "normal"; getObject("lhso1").className = ""; } break;
                        case 'linkHoverFontStyle':                        if (getObject("sp_linkHoverFontStyle").value == "normal") { getObject("lhso2").className = "selected"; } else { value = "normal"; getObject("lhso2").className = ""; } break;
                        case 'linkHoverFontDecoration':                if (getObject("sp_linkHoverFontDecoration").value == "none") { getObject("lhso3").className = "selected"; } else { value = "none"; getObject("lhso3").className = ""; } break;
                }
                getObject("sp_" + property).value = value;
        }
}

function kpe_link(status)
{
        var status = (status != "") ? "Hover" : "";
        
        var ms_link = getObjectStyle("infolink");
        
        ms_link.color                        = getObject("sp_link" + status + "FontColor").value;
        ms_link.fontWeight                = getObject("sp_link" + status + "FontWeight").value;
        ms_link.fontStyle                = getObject("sp_link" + status + "FontStyle").value;
        ms_link.textDecoration        = getObject("sp_link" + status + "FontDecoration").value;
}

function kpe_align_bg(id)
{
        var options = new Array("", "left top", "center top", "right top", "left center", "center center", "right center", "left bottom", "center bottom", "right bottom");
        var selected = parseFloat(id.substring(4));
        var selected_value = options[selected];
        
        for(i=1; i < options.length; i++) getObject("bgao" + i).className = null;
        
        getObject(id).className = "selected";
        
        kpe_update('backgroundPosition', selected_value);
}

function kpe_transparent_section()
{
        var color = getObject("in_sectionBackgroundColor");
        var picker = getObject("s_sbgc-wrapper");
        
        if(color.value == "transparent")
        {
                var rgb = c_sbgc.getRgb();
                kpe_update("sectionBackgroundColor", "rgb(" + rgb.r + ", " + rgb.g + ", " + rgb.b + ")");
                picker.style.display = "block";
        }
        else
        {
                kpe_update("sectionBackgroundColor", "transparent");
                picker.style.display = "none";
        }
}
