﻿// Attached from CalendarEvent.ascx.vb
var sExportSelection='';

//********* Map link ************
function MapOptChanged(s,sloc){ document.getElementById(sloc).value = s + '';}

function PreviewMap(sloc,smap,uselocddl){
    var sLocation = '';

    if (uselocddl == true) {
        if (typeof (LocationID) != "undefined") {
            sLocation = AthLocations[$('#' + LocationID).val()];
        }
        else {
            sLocation = AthLocations[1];
        }
    }

    else {
        var oLocation = document.getElementById(sloc);
    
        if (oLocation.tagName == 'TEXTAREA') {   // in new or edit mode
            sLocation = trim(oLocation.value);
        }
        else {  // in view detail mode
            if (oLocation.textContent) {
                sLocation = trim(oLocation.textContent);
            }
            else {
                sLocation = trim(oLocation.innerText);
            }
        }
    }
    
    if (sLocation == ''){ 
        return; 
    }
    
    // replace white spaces and newline characters with the plus character
    sLocation = sLocation.replace(/(\s*,\s*)|(\s)/g, '+');
    
    var sLocURL = '';
    switch (document.getElementById(smap).value) {
        case MAP_NONE: 
            return;
        case MAP_GOOGLE: 
            sLocURL = MAP_GOOGLE_URL + sLocation;
            break;
        case MAP_YAHOO: 
            sLocURL = MAP_YAHOO_URL + sLocation;
            break;
        default:
            return;
    }
    window.open (sLocURL,'newwindow', config='toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,status=no');
}

    //When the start date changes, put that date in the end date
    function BindDatePickers() {
        $('#' + DatePickerStartID).change(
            function() {
                $('#' + DatePickerEndID).val(
                    $('#' + DatePickerStartID).val()
                );
            }
        );
    }

    function BindEventNameBuilder() {
        $('#' + CategoryID).change(BuildEventName);
        $('#' + LocationID).change(BuildEventName);
        $('#' + OpponentID).change(BuildEventName);
        $('#' + TeamID).change(BuildEventName);
    }

    function BuildEventName(e) {
        var s="";
        if ($('#' + TeamID + " :selected").text().length > 1) {
            s = s + $('#' + TeamID + " :selected").text().trim()
        }
        else if($('#' + CategoryID + " :selected").text().length > 1) {
            s = s + $('#' + CategoryID + " :selected").text()
        }
        if ($('#' + OpponentID + " :selected").text().length > 1) {
            if(s.length >0) { s = s+" ";}
            s = s + "v. " + $('#' + OpponentID + " :selected").text();
        }
        else if ($('#' + LocationID + " :selected").text().length > 1) {
            if (s.length > 0) { s = s + " at "; }
            s = s + $('#' + LocationID + " :selected").text();
        }
        $('#' + EventNameID).val(s);
    }


//************* Calendar, Category dropdowns changed *******************
function DropDownlistCalendar_OnChange(o,sid){ document.getElementById(sid).value = o.value; }
function DropDownlistCategory_OnChange(o,sid){ document.getElementById(sid).value = o.value; }


//************* Time dropdowns changed ***********
function DropDownlistStartTimeHour_OnChange(o,sid){ document.getElementById(sid).value = o.value; }
function DropDownlistStartTimeMin_OnChange(o,sid){ document.getElementById(sid).value = o.value; }
function DropDownlistStartTimeAMPM_OnChange(o,sid){ document.getElementById(sid).value = o.value; }
function DropDownlistEndTimeHour_OnChange(o,sid){ document.getElementById(sid).value = o.value; }
function DropDownlistEndTimeMin_OnChange(o,sid){ document.getElementById(sid).value = o.value; }
function DropDownlistEndTimeAMPM_OnChange(o,sid){ document.getElementById(sid).value = o.value; }


//************* Event AllDay checkbox effects ************
function ToggleTimes(oValue,timestartTD,timeendTD,tzTR){ 
    if(oValue == true){ 
        document.getElementById(timestartTD).style.display='none';
        document.getElementById(timeendTD).style.display='none';
        document.getElementById(tzTR).style.display='none';
    }else{ 
        document.getElementById(timestartTD).style.display='';
        document.getElementById(timeendTD).style.display='';  
        document.getElementById(tzTR).style.display=''; 
    }
}


//****** Save button (of calendar event) clicked ******
function GatherRecurrence(sHID_RECUR_INFO){
    var sInfo = '';
    sInfo += PARAM_CTL_FREQ + ':' + document.getElementById(GetRecurrenceControlNames(PARAM_CTL_FREQ)).value + EVTCAL_DELIM;
    sInfo += PARAM_CTL_DAILY + ':' + document.getElementById(GetRecurrenceControlNames(PARAM_CTL_DAILY)).value + EVTCAL_DELIM;
    sInfo += PARAM_CTL_DAYOFWEEK + ':';
    for (i=0;i<7;i++){ 
        if (document.getElementById(GetRecurrenceControlNames(PARAM_CTL_DAYOFWEEK) + '_' + i).checked){ 
            sInfo += (i + ','); 
        }
    }    
    sInfo += EVTCAL_DELIM;
    sInfo += PARAM_CTL_MONTHLY + ':' + document.getElementById(GetRecurrenceControlNames(PARAM_CTL_MONTHLY)).value + EVTCAL_DELIM;
    sInfo += PARAM_CTL_BYDAYOF + ':';
    if (document.getElementById(GetRecurrenceControlNames(PARAM_CTL_BYDAYOF) + '_' + 0).checked){
        sInfo += 0;
    }else{
        sInfo += 1;
    }
    sInfo += EVTCAL_DELIM;
    sInfo += PARAM_CTL_UNTIL + ':' + document.getElementById(GetRecurrenceControlNames(PARAM_CTL_UNTIL)).value;
    
    //put a string of recurrence info like below to the hidden control...
    //FREQ:3~DNUM:0~DW:0,3,~MNUM:1~BYDAYOF:0~UNTIL:02/22/2007    
    //be consumed in server-side EventRecurrence class
    document.getElementById(sHID_RECUR_INFO).value = sInfo;
}


// v5.5 add to my calendar (export event)...
function OnEventExportClick(s){ sExportSelection=s; }
function OnEventExportCallback(Result,Context){ 
    window.open(Result); 
}

function ShowHideEventRecurrence(val) {
    elem = $('#' + TRRecurClientID);
    if (elem) {
        if (val == 3) {
            elem.css("display", "none");
        } else {
            elem.css("display", "");
        }
    }
}

function WireCreateLocationDialog(diagID, triggerID, pbfun) {

    //dialog definition
    BLACKBAUD.netcommunity.Dialog("#" + diagID, {
        modal: true,
        autoOpen: false,
        height: 350,
        title: "Add Location",
        width: 400,
        resizable: true,
        overlay: { "background-color": "#000", "opacity": "0.75", "-moz-opacity": "0.75" },
        buttons: {
            "Cancel": function() { $(this).dialog("close"); },
            "Save": function() { $(this).dialog("close"); pbfun(); }
        }
    });

    //clear form and attach location dialog open to link
    $("#" + triggerID).click(function() {
         $("#" + diagID + " :input").each(function() {
            var type = this.type;
            var tag = this.tagName.toLowerCase();
            if (type == 'text' || type == 'password' || tag == 'textarea')
                this.value = "";
            else if (type == 'checkbox' || type == 'radio')
                this.checked = false;
            else if (tag == 'select')
                this.selectedIndex = 0;
        })
        $("#" + diagID).dialog("open");
    });

}

////////////////////////////////////////////
// End of script
if (typeof(Sys) !== 'undefined')
{
    Sys.Application.notifyScriptLoaded();
}
////////////////////////////////////////////
// Do not add any code below this
////////////////////////////////////////////

