// <!--
//
//

function upload_start(upload_target)
{
    var statusStart = document.getElementById("upload_start");
    var statusEnd = document.getElementById("upload_complete");
    //    document.getElementById("upload_target").onload = upload_complete(end_callback);
    document.getElementById(upload_target).onload = function() {
        upload_complete();
    }
    statusStart.style.display = "inline";
    statusEnd.style.display = "none";
}

function upload_complete()
{
    var statusStart = document.getElementById("upload_start");
    var statusEnd = document.getElementById("upload_complete");
    statusStart.style.display = "none";
    statusEnd.style.display = "inline";
    document.getElementById("file").value="";

}


//function upload_start(end_callback)
function article_upload_start(listfilter, listid)
{
    var statusStart = document.getElementById("upload_start");
    var statusEnd = document.getElementById("upload_complete");
    //    document.getElementById("upload_target").onload = upload_complete(end_callback);
    document.getElementById("upload_target").onload = function() {
        article_upload_complete(listfilter, listid);
    }
    statusStart.style.display = "inline";
    statusEnd.style.display = "none";
}

function login_form()
{
    var pwd = document.loginform.pw.value;
    if(pwd != "")
    {
        var w = document.loginform.speaktheword.value;
        document.loginform.pw.value = hex_sha512(w+pwd);
        document.loginform.submit();
    }
    else
    {
        alert("Password can not be blank.");
    }
}

function user_change_password()
{
    var pwd = document.useradminform.password.value;
    alert("here");
    if(pwd != "")
    {
        var w = document.useradminform.speaktheword.value;
        document.useradminform.password.value = hex_sha512(w+pwd);
        document.useradminform.speaktheword.value = "";
    }
    document.useradminform.submit();
}

//function upload_complete(end_callback)
function article_upload_complete(listfilter, listid)
{
    var statusStart = document.getElementById("upload_start");
    var statusEnd = document.getElementById("upload_complete");
    statusStart.style.display = "none";
    statusEnd.style.display = "inline";
    document.getElementById("file").value="";

    //now do jquery to update the list
    ImageSelectRefresh(listid, listfilter);
}

function updateArticleEditImgLst()
{
    alert("I did it!");
}

function imagePopupList()
{
    myWindow=window.open('index.php?jq=imageList','_blank','');
}

function ImageSelectRefresh(id, f, n)
{
    $.get("index.php", {
        jq: "imageSelect",
        filter: f,
        name: id,
        allowNone: n
    },
    function(result){
        $('#' + id).empty().html(result);
        console.log(result);
    });

}

/**
 * convenience function to allow javascript events to link to a url
 */
function buttonClick(url, w)
{
    if(w==1)
    {
        window.open(url, "_blank");
    }
    else
    {
        window.location.href=url;//replace current with with new contents
    }
}
function setUserMessage(msg, severity)
{
    //alert("here!");
    //quick and dirty severity
    //0 is good: class = contact_good
    //1 is bad class = contact_error
    //2 is warning class = .contact_warning

    var T = document.getElementById("usermessage");
    var newtext = document.createTextNode(msg);
    T.appendChild(newtext);

    var classname = "message_good";
    if(severity == 1)
        classname = "message_error";
    if(severity == 2)
        classname = "message_warning";
    T.setAttribute("class", classname);

}
function hideRightBar()
{
    var T = document.getElementById("rightsidebarcontainer");
    T.style.display = "none";
    //when hiding the right side bar, also
    //have to expand the main content section
    var TT = document.getElementById("maincontent");
    TT.style.marginRight = "0";
}

function changeSelectedBGColor(id)
{
    var T = document.getElementById(id);
    var d = T.selectedIndex;
    var color = T.options[d].value;
    T.style.backgroundColor = color;
}

function changeColorByClass(classname, color)
{
    var T = getElementsByClass(classname);
    for(i=0; i<T.length;++i)
    {
        T[i].style.color = color;
    }
}

function getElementsByClass(theClass)
{
    //Create Array of All HTML Tags
    var allHTMLTags=document.getElementsByTagName("*");
    var classElements = new Array();
    //Loop through all tags using a for loop
    for (i=0; i<allHTMLTags.length; ++i)
    {
        //Get all tags with the specified class name.
        if (allHTMLTags[i].className==theClass)
        {
            classElements.push(allHTMLTags[i]);
        }
    }
    return classElements;
}
/**
     * Google +1 code for +1 button
     */
(function() {
    var po = document.createElement('script');
    po.type = 'text/javascript';
    po.async = true;
    po.src = 'https://apis.google.com/js/plusone.js';
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(po, s);
})();
    // -->

