// ADMIN RELATED

// Delete confirmation messages.
// cancelMessage example: "Not deleted." if it was being used as a delete confirmation dialogue.
function confirmIt(message, cancelMessage, acceptURL){
    var confirmed = confirm(message);
    if(!confirmed){
        alert(cancelMessage);
    } else {
        window.location = acceptURL;
    }
    return;
}

// delete confirmation
function delConf(message, acceptURL){
    var confirmed = confirm(message);
    if(!confirmed){
        alert("Not deleted.");
    } else {
        // go to URL.
        window.location = acceptURL;
    }
    return;
}


// EFFECTS
// presumes SpryEffects.js is included.

// BLIND TOGGLING

/* Use this to reveal areas */

var blindToggles = new Object();

/*TD set default state param*/
function addBlindToggle(containerID, startHidden){
    if(blindToggles[containerID] == null){
        var container = document.getElementById(containerID);
        if(startHidden){
            // TD: set visiblity: hidden
            // container.style.height = "220px";
            blindToggles[containerID] = new Spry.Effect.Blind(containerID, {duration: 500, from: '0%', to: '100%', toggle: true}); 
        } else {
            // TD: set visiblity: visible
            // container.style.height = "220px";
            container.style.visibility = "visible";
            blindToggles[containerID] = new Spry.Effect.Blind(containerID, {duration: 500, from: '100%', to: '0%', toggle: true});
        }
    }    
}

function toggleBlind(containerID){
    blindToggles[containerID].start();
}

// FADES  

 /*Call this on page load to add  notifiction fades to success and error messages.*/
function feedbackFade(){
    feedbackSuccessFade();
    feedbackWarnFade(); 
    feedbackErrorFade();
}

function successSetupFunc(){}
function successFinishFunc(){
     oElement = document.getElementById("success");
     if(oElement != null){
            // do the final
            sfade = Spry.Effect.DoHighlight('success', {duration: 2000, from:'#2BBF23', to:'#BFFFC2'});
     }
}

function feedbackSuccessFade(){
    oElement = document.getElementById("success");
    if(oElement != null){
        // do the fade
        sfade = Spry.Effect.DoHighlight('success', {duration: 400, from:'#BFFFC2', to:'#2BBF23', toggle: false, setup:successSetupFunc, finish:successFinishFunc});
    }
}

function errorSetupFunc(){}
function errorFinishFunc(){
     oElement = document.getElementById("error");
     if(oElement != null){
            // do the final
            sfade = Spry.Effect.DoHighlight('error', {duration: 2000, from:'#FF7474', to:'#FFDDDD'});
     }
}

function feedbackErrorFade(){
    oElement = document.getElementById("error");
    if(oElement != null){
        // do the fade
        sfade = Spry.Effect.DoHighlight('error', {duration: 400, from:'#FFDDDD', to:'#FF7474', toggle: false, setup:errorSetupFunc, finish:errorFinishFunc});
    }
}


function warnSetupFunc(){}
function warnFinishFunc(){
     oElement = document.getElementById("warn");
     if(oElement != null){
            // do the final
            sfade = Spry.Effect.DoHighlight('warn', {duration: 2000, from:'#FFCF4F', to:'#FFE08F'});
     }
}

function feedbackWarnFade(){
    oElement = document.getElementById("warn");
    if(oElement != null){
        // do the fade
        sfade = Spry.Effect.DoHighlight('warn', {duration: 400, from:'#FFC62F', to:'#FFCF4F', toggle: false, setup:warnSetupFunc, finish:warnFinishFunc});
    }
}

function navOutEffect(){
   hE = Spry.Effect.DoHighlight(this, {duration: 300, from:'#B8E4FF', to:'#EFEFEF'});
}

function navOverEffect(){
   hE = Spry.Effect.DoHighlight(this, {duration: 300, from:'#EFEFEF', to:'#B8E4FF'});
}

function setNavigationEffects(ulID, applyToAnchor){
     var ulObject = document.getElementById(ulID);
     var outStr = "";
     if(ulObject != null){
        var liObjects = ulObject.getElementsByTagName("li");
        for(i = 0; i < liObjects.length; i++){
            outStr += liObjects[i].innerHTML +"\n";
            var applyToObj = null;
            if(applyToAnchor){
               tmp = liObjects[i].getElementsByTagName("a");
               applyToObj = tmp[0];
               outStr += applyToObj.innerHTML +"\n";    
            } else {
                applyToObj = liObjects[i];
            }
            applyToObj.onmouseover = navOverEffect; 
            applyToObj.onmouseout = navOutEffect;
            
        }     
     }
     //alert(outStr);
}

// init to be called on page load by using AddOnload(init); 
function init(){
    // multiple level nav. if no nav is found nothing is done :)
    setNavigationEffects("nav1", true);
    setNavigationEffects("nav2", true);
    setNavigationEffects("nav3", true);
    setNavigationEffects("nav4", true);
    }

function AddOnload(myfunc){
    if(window.addEventListener)
        window.addEventListener('load', myfunc, false);
    else if(window.attachEvent)
        window.attachEvent('onload', myfunc);
}

/* Eval version so args can be passed too! */
function AddOnloadEval(myfuncString){
    myfunc = function(){
        eval(myfuncString);
    }
    AddOnload(myfunc);
}

AddOnload(init);