﻿// Attached from CalendarEvent.ascx.vb
var sExportSelection='';

//********* Map link ************
function MapOptChanged(s,sloc){ document.getElementById(sloc).value = s + '';}

function PreviewMap(sloc,smap){
    var sLocation = '';
    var oLocation = document.getElementById(sloc);
    
    if (oLocation.tagName == 'TEXTAREA'){   // in new or edit mode
        sLocation = trim(oLocation.value); 
    }else{  // in view detail mode
        sLocation = trim(oLocation.innerHTML); 
    }
    
    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');
}


//************* 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 printing...
function PrintThisPage() 
{ 
    //CR296918-040108
    function properlyFormat(match)
    {
        return match.toLowerCase();
    }
    
    var sOption="toolbar=yes,location=no,directories=yes,menubar=yes,status=no,"; 
    sOption+="scrollbars=yes,resizable=yes,width=750,height=400,left=100,top=25"; 

    var sWinHTML = document.getElementById('printStartDV').innerHTML; 
    //.innerHTML screws up and strips " " from type="text/javascript" so remove it and manually add it
    sWinHTML = sWinHTML.substring(sWinHTML.indexOf('>')+1,sWinHTML.length);
    
    //Let's make this properly formatted for XHTML
    //Finds all <TAGNAME and all /TAGNAME>
    //An additional check back be done for <TAGNAME> just add |<[A-Z]+>, but we assume only <BR> is like that
    //BR needs its own custom formatting
    var regExp = new RegExp('<[A-Z]+\\s|/[A-Z]+>', 'g');
    sWinHTML = sWinHTML.replace(regExp, function(match){return properlyFormat(match);}); 
    sWinHTML = sWinHTML.replace(/<BR>/g, "<br />");

    var winprint=window.open("","",sOption); 
    winprint.document.open();
    winprint.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
    winprint.document.write('<html><head><title>Print Calendar</title><LINK href="' + PRINT_CSS + '" rel="Stylesheet"></head>');
    winprint.document.write('<body style="background-color:white;margin:5px;" onload="DisableLinks();">'); 
    winprint.document.write('<table width="100%"'); 
    winprint.document.write('<tr><td style="width: 100%; font-weight: bold;">' + PRINT_TITLE + '</td></tr></table>');
    winprint.document.write('<script type="text/javascript">');
    winprint.document.write(sWinHTML);
    winprint.document.write('</body></html>'); 
    winprint.document.close(); 
    winprint.focus(); 
}

// v5.5 add to my calendar (export event)...
function OnEventExportClick(s){ sExportSelection=s; }
function OnEventExportCallback(Result,Context){ 
    window.open(Result); 
}