﻿function showFindLocation()
{
    var link = PathToRoot + "LocationLookup.aspx"
    showPopWin(link, 400, 525, reloadLocations, true);
    
    return false; 
}

function reloadLocations()
{
    return false;
}

var eventTypeTipShowing = false;
function showFindEventTypes() {
    if (!eventTypeTipShowing) {
        hideLocationFilters();
        hideCalendarFilters();
        var o = Dea.Get(eventTypesDiv);
        SetCurrentPos(eventTypesDiv);
        o.style.visibility = "visible";
        eventTypeTipShowing = true;
    }
    return false;
}

function showAddEventType() {
    var o = Dea.Get(eventTypeDiv);
    SetCurrentPos(eventTypeDiv);
    o.style.visibility = "visible";
    return false;
}


function hideAddEventType() {
    var o = Dea.Get(eventTypeDiv);
    o.style.visibility = "hidden";
    return false;

}
var locationTipShowing = false;
function showFindLocation() {
    if (!locationTipShowing) {
        hideEventTypeFilters();
        hideCalendarFilters();
        var o = Dea.Get(locationsDiv);
        SetCurrentPos(locationsDiv);
        o.style.visibility = "visible";
        locationTipShowing = true;
    }
    return false;
}

function showAddLocation() {
    var o = Dea.Get(showlocationDiv);
    SetCurrentPos(showlocationDiv);
    o.style.visibility = "visible";
    return false;
}

function hideAddLocation() {
    var o = Dea.Get(showlocationDiv);
    o.style.visibility = "hidden";
    return false;

}

function showAddCustomHint() {
    var o = Dea.Get(showCusotmFieldDiv);
    SetCurrentPos(showCusotmFieldDiv);
    o.style.visibility = "visible";
    return false;
}

function hideAddCustomHint() {
    var o = Dea.Get(showCusotmFieldDiv);
    o.style.visibility = "hidden";
    return false;

}
var calTipShowing = false;
function showFindCalendars() {
    if (!calTipShowing) {
        hideEventTypeFilters();
        hideLocationFilters();
        hideLocationLookupFilters();
        hideCustomFieldLookupFilters();
        var o = Dea.Get(calendarsDiv);
        SetCurrentPos(calendarsDiv);
        o.style.visibility = "visible";
        calTipShowing = true;
    }
    return false;
}

var locationLookupTipShowing = false;
function showFindLocationLookup() {
    if (!locationLookupTipShowing) {
        hideCalendarFilters();
        hideCustomFieldLookupFilters();
        var o = Dea.Get(locationLookupDiv);
        SetCurrentPos(locationLookupDiv);
        o.style.visibility = "visible";
        Dea.setDisplay(locationLookupId, "");
        locationLookupTipShowing = true;
    }
    return false;
}

var customFieldTipShowing = false;
function showFindCustomFieldsLookup(fieldNum) {
    if (!customFieldTipShowing) {
        hideLocationLookupFilters();
        hideCalendarFilters();
        customFieldNum = fieldNum;
        var o = Dea.Get(customFieldLookupDiv);
        SetCurrentPos(customFieldLookupDiv);
        o.style.visibility = "visible";
        Dea.setDisplay(customFieldLookupId, "");
        customFieldTipShowing = true;
    }
    return false;
}

var locationLookupDiv = "";
function hideLocationLookupFilters() {
    if (locationLookupDiv !== "" && Dea.Get(locationLookupDiv)) {
        var o = Dea.Get(locationLookupDiv);
        o.style.visibility = "hidden";
        Dea.setDisplay(locationLookupId, "none");
        locationLookupTipShowing = false;
    }
    return false;
}

var customFieldLookupDiv = "";
function hideCustomFieldLookupFilters() {
    if (customFieldLookupDiv !== "" && Dea.Get(customFieldLookupDiv)) {
        var o = Dea.Get(customFieldLookupDiv);
        o.style.visibility = "hidden";
        Dea.setDisplay(customFieldLookupId, "none");
        customFieldTipShowing = false;
    }
    return false;
}

/*** EventType Lookups ***/
var mcEventTypeIds = "";
var eventTypesDiv = "";
function hideEventTypeFilters() {

    if (eventTypesDiv !== "" && Dea.Get(eventTypesDiv)) {
        var o = Dea.Get(eventTypesDiv);
        o.style.visibility = "hidden";
        eventTypeTipShowing = false;
    }
   return false;

}

function checkEventType(cbid,eventTypeId)
{   
    if(Dea.Get(cbid.id).checked)
        addEventTypeId(eventTypeId);
    else
    {
        var eventTypeIds = mcEventTypeIds.split(",");
        mcEventTypeIds = "";
        for(var i = 0; i < eventTypeIds.length; i++)
        {
            if(eventTypeIds[i] !== eventTypeId){
                addEventTypeId(eventTypeIds[i]);
            }
        }
    }
        
    return false;
}

function addEventTypeId(eventTypeId)
{
    
   if(mcEventTypeIds.length == 0) {
        mcEventTypeIds = eventTypeId;
    }
    else {
        var eventTypeIds = mcEventTypeIds.split(",");
        var eventTypeExists = false;
        for (var i = 0; i < eventTypeIds.length; i++) {
            if (eventTypeIds[i] == eventTypeId)
                eventTypeExists = true;  
        }
        if (!eventTypeExists)
            mcEventTypeIds += "," + eventTypeId;
    }
    Dea.Get(sEventTypeIds).value = mcEventTypeIds;
    
}


/*** Location Lookup ***/
var mcLocations = "";
function checkLocations(cbid,locationId)
{   
    if(Dea.Get(cbid.id).checked)
        addLocationId(locationId);
    else
    {
        var locationIds = mcLocations.split(",");
        mcLocations = "";
        for(var i = 0; i < locationIds.length; i++)
        {
            if(locationIds[i] !== locationId){
                addLocationId(locationIds[i]);
            }
        }
    }
        
    return false;
}

function addLocationId(locationId)
{
    
   if(mcLocations.length == 0) {
        mcLocations = locationId;
    }
    else {
        var locationIds = mcLocations.split(",");
        var locationExists = false;
        for (var i = 0; i < locationIds.length; i++) {
            if (locationIds[i] == locationId) 
                locationExists = true;
        }
        if(!locationExists)
            mcLocations += "," + locationId;
        
    }
    Dea.Get(sLocationIds).value = mcLocations;
}

var locationsDiv = "";
function hideLocationFilters() {
    if (locationsDiv !== "" && Dea.Get(locationsDiv)) {
        var o = Dea.Get(locationsDiv);
        o.style.visibility = "hidden";
        locationTipShowing = false;
    }
   return false;
}
/*** End Location Lookup ***/


/*** Calendars Lookup ***/
var mcCalendars = "";
var mcCalendarNames = "";
function checkCalendars(cbid, calendarId) {
    if (Dea.Get(cbid.id).checked) {
        addCalPopId(calendarId);
    }
    else {
        var calendarIds = mcCalendars.split(",");
        mcCalendars = "";
        for (var i = 0; i < calendarIds.length; i++) {
            if (calendarIds[i] !== calendarId) {
                addCalPopId(calendarIds[i]);
            }
        }
    }

    return false;
}

function checkCalendars(cbid, calendarId, calendarName) {
    if (Dea.Get(cbid.id).checked) {
        addCalPopId(calendarId);
        addCalName(calendarName);
    }
    else {
        var calendarIds = mcCalendars.split(",");
        mcCalendars = "";
        mcCalendarNames = "";
        for (var i = 0; i < calendarIds.length; i++) {
            if (calendarIds[i] !== calendarId) {
                addCalPopId(calendarIds[i]);
                addCalName(calendarName);
            }
        }
    }

    return false;
}

function addCalPopId(calendarId) {
    if (mcCalendars.length == 0) {
        mcCalendars = calendarId;
    }
    else {
        var calendarIds = mcCalendars.split(",");
        var calendarExists = false;
        for (var i = 0; i < calendarIds.length; i++) {
            if (calendarIds[i] == calendarId)
                calendarExists = true;
        }
        if (!calendarExists)
            mcCalendars += "," + calendarId;

    }
    Dea.Get(scalendarIds).value = mcCalendars;
}


function addCalName(calName) {
    if (mcCalendarNames.length == 0) {
        mcCalendarNames = calName;
    }
    else {
        var calendarnames = mcCalendarNames.split(",");
        var calendarExists = false;
        for (var i = 0; i < calendarnames.length; i++) {
            if (calendarnames[i] == calName)
                calendarExists = true;
        }
        if (!calendarExists)
            mcCalendarNames += "," + calName;

    }
}
var calendarsDiv = "";
function hideCalendarFilters() {
    if (calendarsDiv !== "" && Dea.Get(calendarsDiv))
    {
     var o = Dea.Get(calendarsDiv);
     o.style.visibility = "hidden";
     calTipShowing = false;
    }
    return false;
}
/*** End Calendars Lookup ***/



function selectValueSet(selectName, value) {
  var o = Dea.Get(selectName);
  for(index = 0; index < o.length; index++) {
    if(o[index].value == value)
        o.selectedIndex = index;
  }
}

function addMultipleSelected(selectName, text) {
    var o = Dea.Get(selectName);
    for (i = 0; i < o.length; i++)
    {
        if (o[i].value == -2)
            return;
    }
    o.options[o.options.length] = new Option(text, -2, false, false);
    for (index = 0; index < o.length; index++) {
        if (o[index].value == -2)
            o.selectedIndex = index;
        
    }
}

function removeSelectValue(selectName, value) {
    var o = Dea.Get(selectName);
    for (index = 0; index < o.length; index++) {
        if (o[index].value == value)
            o.options[index] = null;
    }
}

function showRemindersLookup() {
    var o = Dea.Get(eventReminderDiv);
    SetCurrentPos(eventReminderDiv);
    o.style.visibility = "visible";
    return false;
}

function hideReminderLookup() {
    var o = Dea.Get(eventReminderDiv);
    o.style.visibility = "hidden";
    return false;
}
