﻿
var BGRollOver = "pink";
var BGRollOut = "pink";
var BGDarkGray = "pink";
var BGLightGray = "pink";
var BGSuperLightGray = "pink";
var BGColored = "pink";

function Find(targetName){
    return document.getElementById(targetName);
}

function threadVoteButton_OnClick(iKey, bDoFullPostBack) {
    var voteButton;
    voteButton = document.getElementById("threadVoteButton_" + iKey);

    var iCount = $(".PrayerCount_" + iKey).val();
    $(".PrayerCount_" + iKey).val(iCount + 1);

    if (document.getElementById("divCount_" + iKey) != null) {
        iCount = document.getElementById("divCount_" + iKey).innerHTML;
        iCount++;
        document.getElementById("divCount_" + iKey).innerHTML = iCount;
    }

//    if (document.getElementById("divCountB_" + iKey) != null) {
//        iCount = document.getElementById("divCountB_" + iKey).innerHTML;
//        iCount++;
//        document.getElementById("divCountB_" + iKey).innerHTML = iCount;
//    }

//    if (document.getElementById("divTodaysCount_" + iKey) != null) {
//        iCount = document.getElementById("divTodaysCount_" + iKey).innerHTML;
//        iCount++;
//        document.getElementById("divTodaysCount_" + iKey).innerHTML = iCount;
//    }

//    if (document.getElementById("divMyCount_" + iKey) != null) {
//        iCount = document.getElementById("divMyCount_" + iKey).innerHTML;
//        iCount++;
//        document.getElementById("divMyCount_" + iKey).innerHTML = iCount;
//    }

//    if (document.getElementById("divUserCount") != null) {
//        iCount = document.getElementById("divUserCount").innerHTML;
//        iCount++;
//        document.getElementById("divUserCount").innerHTML = iCount;
//    }

//    if (document.getElementById("divCategoryCount") != null) {
//        iCount = document.getElementById("divCategoryCount").innerHTML;
//        iCount++;
//        document.getElementById("divCategoryCount").innerHTML = iCount;
//    }

    if (bDoFullPostBack) {
        jsSend("dove", "on");
        setTimeout(function() { iPrayedReset(document.getElementById("iPrayed_" + iKey)); }, 60000);
        __doPostBack('cmdIPrayed', iKey);
    } else {
        jsSend("dove", "on");
        setTimeout(function() { iPrayedReset(document.getElementById("iPrayed_" + iKey)); }, 60000);
        NPB.UI.Web.Services.Threads.ThreadClient.AddThreadVote(iKey, AddVoteCallBack);
    }
}

function AddVoteCallBack(iThreadId) {
    setTimeout(function() { iPrayedReset(document.getElementById("iPrayed_" + iThreadId)); }, 60000);
}


function rollover(target) {
    if (target.src.indexOf("_active") == -1 && target.src.indexOf("_selected") == -1) {
        var src = target.src;
        src = src.replace(".jpg", "_active.jpg");
        src = src.replace(".gif", "_active.gif");
        src = src.replace(".png", "_active.png");
        target.src = src;
    }
    //target.src = "/images/" + target.name + "_active.gif";
}

function rollout(target) {
    target.src = target.src.replace("_active", "");
    target.src = target.src.replace("_down", "");
    //target.src = "/images/" + target.name + ".gif";
}

function mousedown(target) {
    if (target.src.indexOf("_down") == -1 && target.src.indexOf("_selected") == -1) {
        var src = target.src;
        src = src.replace("_active", "");
        src = src.replace(".jpg", "_down.jpg");
        src = src.replace(".gif", "_down.gif");
        src = src.replace(".png", "_down.png");
        target.src = src;
    }
    //target.src = "/images/" + target.name + "_down.gif";
}

function mouseup(target) {
    if (target.src.indexOf("_active") == -1 && target.src.indexOf("_selected") == -1) {
        var src = target.src;
        src = src.replace("_down", "");
        src = src.replace(".jpg", "_active.jpg");
        src = src.replace(".gif", "_active.gif");
        src = src.replace(".png", "_active.png");
        target.src = src;
    }
    //target.src = "/images/" + target.name + "_active.gif";
}

function divrollover(target) {
    if (target.style.backgroundImage.indexOf("_active") == -1 && target.style.backgroundImage.indexOf("_selected") == -1) {
        var src = target.style.backgroundImage;
        src = src.replace(".jpg", "_active.jpg");
        src = src.replace(".gif", "_active.gif");
        src = src.replace(".png", "_active.png");
        target.style.backgroundImage = src;
    }
    //target.src = "/images/" + target.name + "_active.gif";
}

function divrollout(target) {
    target.style.backgroundImage = target.style.backgroundImage.replace("_active", "");
    target.style.backgroundImage = target.style.backgroundImage.replace("_down", "");
    //target.src = "/images/" + target.name + ".gif";
}

function j_rollover(target) {
    target.src = "/images/" + target.name + "_active.jpg";
}

function j_rollout(target) {
    target.src = "/images/" + target.name + ".jpg";
}

function j_mousedown(target) {
    target.src = "/images/" + target.name + "_down.jpg";
}

function j_mouseup(target) {
    target.src = "/images/" + target.name + "_active.jpg";
}


function iPrayedReset(target) {
    if (target) {
        if (target.src.indexOf('/images/dove_small') <= 0) {
            target.src = '/images/i_prayed.gif';
        } else {
            target.src = '/images/dove_small.gif';
        }
    }
}

function iPrayedOver(target) {
    if (target.src.indexOf('/images/i_prayed_amen.gif') <= 0) {
        target.src = "/images/i_prayed_active.gif";
    }
}

function iPrayedOut(target) {
    if (target.src.indexOf('/images/i_prayed_amen.gif') <= 0) {
        target.src = '/images/i_prayed.gif';
    }
}

function iPrayedDown(target) {
    if (target.src.indexOf('/images/i_prayed_amen.gif') <= 0) {
        target.src = '/images/i_prayed_down.gif';
    }
}

function iPrayedClick(target) {
    if (target.src.indexOf('/images/i_prayed_amen.gif') <= 0) {
        target.src = '/images/i_prayed_amen.gif';
        return true;
    } else {
        return false;
    }
}

function AddToPrayerList(ThreadId, UserName, ReturnURL) {
    if (UserName == "" || UserName == null) {
        window.location.href = ReturnURL;
    } else {
        alert('This Prayer Request is being added to your Prayer List.');
        __doPostBack('cmdReminderList', ThreadId);
    }
}

function iPrayedSmallOut(target) {
    if (target.src.indexOf('/images/dove_small_amen.gif') <= 0) {
        target.src = '/images/dove_small.gif';
    }
}

function iPrayedSmallDown(target) {
    if (target.src.indexOf('/images/dove_small_amen.gif') <= 0) {
        target.src = '/images/dove_small_active.gif';
    }
}

function iPrayedSmallClick(target) {
    if (target.src.indexOf('/images/dove_small_amen.gif') <= 0) {
        target.src = '/images/dove_small_amen.gif';
        return true;
    } else {
        return false;
    }
}


function PrintPage(sContent) {
    var mywin = window.open('', "PrintPreview", "width=680,height=500,status=1,toolbar=1,menubar=1,resizable=0,scrollbars=1");
    var sHeader = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head><link rel="stylesheet" href="/Resources/css/donotprint.css" type="text/css"><link rel="stylesheet" href="/Resources/css/global.css" type="text/css"><script type="text/javascript" src="/Resources/js/swfobject/swfobject.js" language="javascript"></script><script type="text/javascript" src="/Resources/js/PrayerIcons.js" language="javascript"></script></head>';
    mywin.document.write(sHeader + '<body style="font-size:small; background-color:white;">' + sContent + "</body></html>");
    mywin.document.close();
}


//FROM Events.js ///////////////////////////////////////////////////////

// from prototype.js ****************
//function $(element) {
//    if (arguments.length > 1) {
//        for (var i = 0, elements = [], length = arguments.length; i < length; i++)
//            elements.push($(arguments[i]));
//        return elements;
//    }
//    //if (Object.isString(element))
//    element = document.getElementById(element);
//    return element;
//}

// end from prototype.js ****************

function getFlashMovie(movieName) {
    var isIE = navigator.appName.indexOf("Microsoft") != -1;
    return (isIE) ? window[movieName] : document[movieName];
}

function cueDove() {
    jsSend("dove", "on");
}

function jsSend(fn, val) {
    var target = document.getElementById('NPBHeader5');
    if (target != null) {
        target.sendToFlash(fn, val);
    }
}

function setPrayerValues() {
    var t;

    if (tryPrayerValues()) {
        clearTimeout(t);
    }
    else {
        t = setTimeout("setPrayerValues()", 1000);
    }
}

// from voting.js ****************
function AssignTextToLink(linkId, text) {
    var link = document.getElementById(linkId);

    var hasInnerText = (link.innerText != undefined) ? true : false;
    var hasTextContent = (link.textContent != undefined) ? true : false;

    if (hasInnerText) {
        link.innerText = text;
    }

    if (hasTextContent) {
        link.textContent = text;
    }
}

function EnableButton(controlId) {
    var voteButton;
    voteButton = document.getElementById(controlId);
    voteButton.value = PRAY;
    voteButton.disabled = false;
}
// end from voting.js ****************

function checkEnter(e) {
    var characterCode; //literal character code will be stored in this variable

    if (e && e.which) { //if which property of event object is supported (NN4)
        e = e;
        characterCode = e.which; //character code is contained in NN4's which property
    } else {
        e = event;
        characterCode = e.keyCode; //character code is contained in IE's keyCode property
    }

    if (characterCode == 13) { //if generated character code is equal to ascii 13 (if enter key)
        return true;
    } else {
        return false;
    }
}


//NPB.ControlLibrary/IPrayedFlyOut.ascx
function divIPrayedMouseOver(iUniqueIndex) {
    document.getElementById('divPopOut_' + iUniqueIndex).style.display = 'block';
}
function divIPrayedMouseOut(iUniqueIndex) {
    document.getElementById('divPopOut_' + iUniqueIndex).style.display = 'none';
    document.getElementById('imgIPrayed_' + iUniqueIndex).src = '/images/i_prayed_circle.png';
}
function divIPrayedMouseDown(iUniqueIndex) {
    document.getElementById('imgIPrayed_' + iUniqueIndex).src = '/images/i_prayed_circle_down.png';
}
function divIPrayedMouseUp(iUniqueIndex) {
    document.getElementById('imgIPrayed_' + iUniqueIndex).src = '/images/i_prayed_circle.png';
}
function divIPrayedOnClick(target, iUniqueIndex, iThreadId) {
    document.getElementById('divIPrayed_' + iUniqueIndex).style.display = 'none';
    document.getElementById('divAmen_' + iUniqueIndex).style.display = 'block';

    if (document.getElementById("divCount_" + iThreadId) != null) {
        iCount = document.getElementById("divCount_" + iThreadId).innerHTML;
        iCount++;
        document.getElementById("divCount_" + iThreadId).innerHTML = iCount;
    }    
    
    if (document.getElementById('divPrayerCount_' + iUniqueIndex)) {
        document.getElementById('divPrayerCount_' + iUniqueIndex).innerHTML = parseInt(document.getElementById('divPrayerCount_' + iUniqueIndex).innerHTML) + 1;
    }
    __doPostBack('cmdIPrayed', iThreadId);
    target.onclick = function() { event.cancelBubble = true; };
    target.onmousedown = '';
    if (document.getElementById('divTotalPrayerCount')) {
        document.getElementById('divTotalPrayerCount').innerHTML = parseInt(document.getElementById('divTotalPrayerCount').innerHTML) + 1 + '<br />';
    }

    setTimeout(function() { divIPrayedReset(target, iUniqueIndex, iThreadId); }, 60000);
}

function divIPrayedReset(target, iUniqueIndex, iThreadId) {
    document.getElementById('divIPrayed_' + iUniqueIndex).style.display = 'block';
    document.getElementById('divAmen_' + iUniqueIndex).style.display = 'none';
    target.onclick = function() { event.cancelBubble = true; divIPrayedOnClick(this, iUniqueIndex, iThreadId); };
    target.onmousedown = function(){divIPrayedMouseDown(iUniqueIndex);};
}

// Org.Beta/Controls/BulletinIndexItem.ascx
function LinkMouseOver(target, color) {
    target.style.color = color; 
    target.style.textDecoration = 'underline';
}

function LinkMouseOut(target, color) {
    target.style.color = color; 
    target.style.textDecoration = 'none';
}


/* Org.Beta/Controls/BulletinDisplay.ascx */
function InviteClick(itemid) {
    window.location.href = '/postoffice_compose.aspx?action=shareevent&itemid=' + itemid;
}
function ShareClick(itemid) {
    window.location.href = '/postoffice_compose.aspx?action=shareannouncement&itemid=' + itemid;
}
function EditClick(itemid) {
    window.location.href = '/EditAnnouncement.aspx?action=edit&itemid=' + itemid + '&returnurl=editbulletin.aspx?activetab=3';
}
function RemoveClick(itemid) {
    window.location.href = '/postoffice_compose.aspx?action=shareevent&itemid=' + itemid;
}


function ChangeBGColor(targetName, color){
    Find(targetName).style.backgroundColor = color;
}


function AddPageLoadEvent(func){
    Sys.Application.add_load(func);
} 
