// JavaScript Document
/*
Banner selection from profile - Created by Peter

This code cannot be reposted anywhere other than SSDesigns or ProBoards Support.

This header must stay intact.
*/
/* http://support.proboards.com/index.cgi?board=codedatabase&action=display&thread=1117972689 */
// PLACE IN MAIN FOOTER.  There is a corresponding piece of code in the GLOBAL HEADER.

var iBBDesTxt = "Select a banner you wish to have show in the welcome table instead of the default one.";

function setCookie(name,value,expires,domain){
document.cookie = name + "=" + encodeURI(value) + ((expires == null) ? "" : "; expires=" + expires.toGMTString()) + ((domain == null) ? "" : "; domain=" + domain);

}

function doBanSelect(){
    var iTable = document.getElementsByTagName("table");
    var bSel = document.createElement("select");
    var iBFont = document.createElement("font");
    var bDesc = document.createTextNode("Banner:");

    iBFont.size = "-2";
    var iBBDes = iBFont.cloneNode(true).appendChild(document.createTextNode(iBBDesTxt));
    iBFont.size = "-1";
    iBFont.appendChild(bDesc);

    bSel.onchange = function(){
        var iDomain = location.hostname;
        var ExpDate = new Date ();

        ExpDate.setTime(ExpDate.getTime() + (180 * 24 * 3600 * 1000));

        setCookie("banid", this.selectedIndex, ExpDate, iDomain);
    }

    for(b = 0; b < iBanners.length; b ++){
        bSel.options[bSel.options.length] = new Option(iBanners[b][0], b);
        if(b == parseInt(getCook())){
            bSel.options[b].selected = true;
        }
    }

    for(t = 0; t < iTable.length; t ++){
        if(iTable.item(t).width == "650" && iTable.item(t).innerHTML.match(/Show Age:/)){
            var nRow = iTable.item(t).insertRow(iTable.item(t).rows.length);
            var nCell = nRow.insertCell(0);
            nCell.appendChild(iBFont);
            nCell = nRow.insertCell(1);
            nCell.appendChild(bSel);
            nCell = nRow.insertCell(2).appendChild(iBBDes);
        }
    }
}

if(location.href.match(/=modifyprofile&user=/) && document.modifyForm){
    doBanSelect();
}
