﻿var setStatusSchoolID = null;
var setStatusCallBack = null;
var setStatusState = null;
var setMessageID = null;
var setOrgType = null;
function ShowSetStatus(schoolid, messageid, cb, state) {
    setStatusSchoolID = schoolid;
    setMessageID  = messageid;
    setStatusCallBack = cb;
    setStatusState = state;
    $find("SetStatusSchoolModal").show();
}

function ShowSetStatusOrg(schoolid, messageid, orgtype, cb, state) {
    setStatusSchoolID = schoolid;
    setMessageID  = messageid;
    setStatusCallBack = cb;
    setStatusState = state;
    setOrgType = orgtype;
    if(setOrgType == 29867) 
        {
            $get('divGSGoingToApply').style.display = "block";
            $get('divApplicant').style.display = "block";
        }
    if(setOrgType == 27615)
        {
          $get('divGSGoingToApply').style.display = "none";
          $get('divApplicant').style.display = "none";
        }
    $find("SetStatusOrgModal").show();
}

function SetSchoolStatus(category, schoolid, messageid, cb, state) {

    var flag = true;
    if (category == 11)
        flag = confirm("Committing to this school means that you won’t receive future love messages from other schools. You cool with that?");
    else if (category == 2)
        flag = confirm("All of your messages for this school will now be archived and you will not receive any future messages from this school. Sound good?");
    if (!flag) return;

    ContactRequestShoutOut = false;
    if (schoolid)
        setStatusSchoolID = schoolid;
    if (cb)
        setStatusCallBack = cb;
    if (state)
        setStatusState = state;
    if (messageid)
        setMessageID = messageid;
       
    ShowContactInfoRequest(category, setStatusSchoolID, setMessageID, setStatusCallBack, setStatusState);
    setStatusSchoolID = null;
    setStatusCallBack = null;
    setStatusState = null;
}

function StudentStatusEditComplete(category, obj) {
    var span = $get("description", obj.parentNode);
    if (category == 0) span.innerHTML = "I am excited to learn more about this school";
    else if (category == 1) span.innerHTML = "I am still unsure but I want more info";
    else if (category == 2) {
        span.innerHTML = "I am simply not interested in this school";
        if (rebindGrid)
            rebindGrid("-1");
    }
    else if (category == 3) span.innerHTML = "Want to learn more";
    else if (category == 4) span.innerHTML = "Still unsure";
    else if (category == 5) {
        span.innerHTML = "Not interested";
        if (rebindGrid)
            rebindGrid("-1");
    }
    else if (category == 6) span.innerHTML = "I am definitely going to apply";
    else if (category == 7) span.innerHTML = "I applied...still waiting to hear back";
    else if (category == 8) span.innerHTML = "I applied but I was waitlisted";
    else if (category == 9) span.innerHTML = "I applied and was denied admission";
    else if (category == 10) span.innerHTML = "I applied and was accepted admission";
    else if (category == 11) span.innerHTML = "I was accepted and I'm committed to enroll!";
}

function ShoutOut(schoolid, cb, cbe, state) {
    ContactRequestShoutOut = true;
    ShowContactInfoRequest(null, schoolid, null, cb, state);
}

function ShoutOutCommitted(smeID, ddlCount) {
    var committedLIs = document.getElementsByName("liCommitted");

    if (ddlCount == 9) {
        for (var i = 0; i < committedLIs.length; i++) {
            committedLIs[i].style.display = 'none';
        }
    }
    else {
        for (var i = 0; i < committedLIs.length; i++) {
            committedLIs[i].style.display = '';
        }
    }

    $find(smeID).show();
}

function ModalChangeStatusSO(statusObj, lblID, hideCID) {
    var datakey = statusObj.getAttribute("datakey");
    var newStatus = statusObj.innerHTML.replace(/^\s*|\s*$/g, '');
    var newCat = statusObj.getAttribute("categoryID");
    var label = $get(lblID);
    var labelText = label.innerHTML.replace(/^\s*|\s*$/g, '');
    var committedLIs = document.getElementsByName("liCommitted");

    if (labelText == 'Committed to enroll') {
        for (var i = 0; i < committedLIs.length; i++) {
            committedLIs[i].style.display = '';
        }
    }

    if (newCat == 11) {
        for (var i = 0; i < committedLIs.length; i++) {
            committedLIs[i].style.display = 'none';
        }
    }

    TheLove.SetTheStatus(newCat, datakey);
    SchoolUserCategoryID = datakey;
    ContactRequestNeeded = (newCat == 0 || newCat == 3 || newCat == 6 || newCat == 7 || newCat == 10 || newCat == 11);
    $find(hideCID).hide();

    refreshPage();
}

function ModalChangeStatus(statusObj, lblID, hideCID, datakey) {
    //var datakey = statusObj.getAttribute("datakey");
    var newStatus = statusObj.innerHTML.replace(/^\s*|\s*$/g, '');
    var newCat = statusObj.getAttribute("categoryID");
    var label = $get(lblID);
    var labelText = label.innerHTML.replace(/^\s*|\s*$/g, '');
    var committedLIs = document.getElementsByName("liCommitted");

    if (labelText == 'Committed to enroll') {
        for (var i = 0; i < committedLIs.length; i++) {
            committedLIs[i].style.display = '';
        }
    }

    if (newCat == 11) {
        for (var i = 0; i < committedLIs.length; i++) {
            committedLIs[i].style.display = 'none';
        }
    }

    TheLove.SetTheStatus(newCat, datakey);
    ShowContactInfoRequest(newCat, datakey);
    label.innerHTML = newStatus;

    $find(hideCID).hide();

}

function InboxModalChangeStatus(statusObj, lblID, hideCID) {
    var datakey = statusObj.getAttribute("datakey");
    var newStatus = statusObj.innerHTML.replace(/^\s*|\s*$/g, '');
    var newCat = statusObj.getAttribute("categoryID");
    var label = $get(lblID);
    var labelText = label.innerHTML.replace(/^\s*|\s*$/g, '');
    var committedLIs = document.getElementsByName("liCommitted");

    if (labelText == 'Committed to enroll') {
        for (var i = 0; i < committedLIs.length; i++) {
            committedLIs[i].style.display = '';
        }
    }

    if (newCat == 11) {
        for (var i = 0; i < committedLIs.length; i++) {
            committedLIs[i].style.display = 'none';
        }
    }



    TheLove.SetTheStatus(newCat, datakey);
    ShowContactInfoRequest(newCat, datakey);
    label.innerHTML = newStatus;

    $find(hideCID).hide();

}

function ChangeStatus(statusObj) {
    var ddlIndex = statusObj.selectedIndex;
    var selVal = statusObj.options[ddlIndex].value;
    var CID = statusObj.getAttribute("ID");
    var datakey = statusObj.getAttribute("datakey");
    var label = $get("lblStatus", statusObj.parentNode);
    var status = label.innerHTML;
    var commitedVal = 11;
    var commitedPos = 1;

    if (selVal > -1) {
        TheLove.SetTheStatus(selVal, datakey);
        ShowContactInfoRequest(selVal, datakey);
        label.innerHTML = statusObj.options[ddlIndex].text;
        document.getElementById(CID).style.display = "none";

        if (status == 'Committed to going!') {
            var DDLs = document.getElementsByTagName("SELECT");

            for (i = 0; i < DDLs.length; i++) {
                //only need to change the drop down for schools
                if (DDLs[i].options.length > 4) {
                    //don't want to change the filter dropdown which is the first ddl on the page.  Had to add a fake/invisible ddl list to Messages.aspx & TeamZinch.aspx
                    //I know this is probably not the best way to do this.  Not sure what else to do???
                    if (i != 0) {
                        DDLs[i].options[commitedPos] = new Option("Committed to going!", "11", false, false);
                    }
                }
            }
        }
        else if (selVal == 11) {
            //remove commited option from DDLs            
            var DDLs = document.getElementsByTagName("SELECT");

            for (i = 0; i < DDLs.length; i++) {
                //only need to change the drop down for schools
                if (DDLs[i].options.length > 4) {
                    //don't want to change the filter dropdown which is the first ddl on the page.  Had to add a fake/invisible ddl list to Messages.aspx & TeamZinch.aspx
                    //I know this is probably not the best way to do this.  Not sure what else to do???
                    if (i != 0) {
                        DDLs[i].options[commitedPos] = null;
                    }
                }
            }

        }
    }
}

function ChangeCollegeStatus(statusObj) {
    var ddlIndex = statusObj.selectedIndex;
    var selVal = statusObj.options[ddlIndex].value;
    var CID = statusObj.getAttribute("ID");
    var datakey = statusObj.getAttribute("datakey");
    var scid = statusObj.getAttribute("SchoolId");
    var uid = statusObj.getAttribute("UserId");
    var label = $get("lblStatus", statusObj.parentNode);
    var status = label.innerHTML;

    if (selVal > -1) {
        TheLove.SetStatus(selVal, datakey, scid, uid);
        SchoolUserCategoryID = scid;
        ContactRequestNeeded = (selVal == 0 || selVal == 3 || selVal == 6 || selVal == 7 || selVal == 10 || selVal == 11);
        label.innerHTML = statusObj.options[ddlIndex].text;
        document.getElementById(CID).style.display = "none";

        if (status == 'Committed to going!') {
            var DDLs = document.getElementsByTagName("SELECT");

            for (i = 0; i < DDLs.length; i++) {
                //only need to change the drop down for schools
                if (DDLs[i].options.length > 4) {
                    DDLs[i].options[DDLs[i].options.length] = new Option("Commited to going!", "11", false, false);
                }
            }
        }
        else if (selVal == 11) {
            //remove commited option from DDLs            
            var DDLs = document.getElementsByTagName("SELECT");

            for (i = 0; i < DDLs.length; i++) {
                //only need to change the drop down for schools
                if (DDLs[i].options.length > 4) {
                    DDLs[i].options[DDLs[i].options.length - 1] = null;
                }
            }

        }
    }
    refreshPage();
}

function OnSucceded(result, editBox) {
    alert('You succeded: ' + editBox.ClntID);
}

function showDDL(CID) {
    document.getElementById(CID).style.display = "";
}

function MinMessage(hideCID, maxCID, minCID) {
    document.getElementById(hideCID).style.display = 'none';
    document.getElementById(maxCID).style.display = '';
    document.getElementById(minCID).style.display = 'none';
}

function MaxMessage(showCID, maxCID, minCID) {
    document.getElementById(showCID).style.display = '';
    document.getElementById(maxCID).style.display = 'none';
    document.getElementById(minCID).style.display = '';
}

function ShowReply(replyTxbCID) {
    document.getElementById(replyTxbCID).style.display = '';
}

function MaximizeAll() {
    var objs = document.getElementsByName("theMessage");
    var hlMax = document.getElementsByName("maxMsg");
    var hlMin = document.getElementsByName("minMsg");

    for (var i = 0; i < objs.length; i++) {
        objs[i].parentNode.style.display = '';
        hlMax[i].style.display = 'none';
        hlMin[i].style.display = '';
    }

    document.getElementById("aMaximizeAll").style.display = 'none';
    document.getElementById("aMinimizeAll").style.display = '';
}

function MinimizeAll() {
    var objs = document.getElementsByName("theMessage");
    var hlMax = document.getElementsByName("maxMsg");
    var hlMin = document.getElementsByName("minMsg");

    for (var i = 0; i < objs.length; i++) {
        objs[i].parentNode.style.display = 'none';
        hlMax[i].style.display = '';
        hlMin[i].style.display = 'none';
    }

    document.getElementById("aMaximizeAll").style.display = '';
    document.getElementById("aMinimizeAll").style.display = 'none';
}

function filterConv(filterObj) {
    var ddlIndex = filterObj.selectedIndex;
    var selectedVal = filterObj.options[ddlIndex].value;

    var editBox = {
        SelectedVal: filterObj.options[ddlIndex].value,
        SelectedText: filterObj.options[ddlIndex].text
    }

    rebindGrid(selectedVal);
}

function filterConverstations(filterObj) {
    var ddlIndex = filterObj.selectedIndex;
    var selVal = filterObj.options[ddlIndex].value;
    var selText = filterObj.options[ddlIndex].text;
    var objs = document.getElementsByName('conv-container');

    if (selVal == -1) {
        for (i = 0; i < objs.length; i++) {
            objs[i].parentNode.style.display = '';
        }
    }
    else {
        for (i = 0; i < objs.length; i++) {
            var label = $get("lblStatus", objs[i].parentNode);

            if (label.innerHTML == selText) {
                objs[i].parentNode.style.display = '';
            }
            else {
                objs[i].parentNode.style.display = 'none';
            }
        }
    }
}

function SendReply(replyObj) {
    var msgBody = $get("taReplyBody", replyObj.parentNode);
    var msgID = replyObj.getAttribute("messageID");
    var userID = replyObj.getAttribute("userID");
    var msgSent = $get("msgSent", replyObj.parentNode.parentNode);

    TheLove.ReplyToLove(msgID, userID, msgBody.value);

    replyObj.parentNode.style.display = 'none';
    msgSent.style.display = '';
}

function CancelReply(replyObj) {
    replyObj.parentNode.style.display = 'none';
}

function AOSendReply(replyObj) {
    var msgBody = $get("taReplyBody", replyObj.parentNode);
    var msgID = replyObj.getAttribute("messageID");
    var senderID = replyObj.getAttribute("senderID");
    var receiverID = replyObj.getAttribute("receiverID");
    var msgSent = $get("msgSent", replyObj.parentNode.parentNode);

    //alert('msgBody: ' + msgBody + ' msgID: ' + msgID + ' senderID: ' + senderID + ' receiverID: ' + receiverID);

    TheLove.AOReplyToLove(msgID, senderID, msgBody.value, receiverID);

    //alert("made it");
    replyObj.parentNode.style.display = 'none';
    msgSent.style.display = '';
}