<?php
// $enotes3_ref = 
foreach($clog_activity->qa as $qa) { 
if (trim($qa->qs) != null) {
  echo "<li>".$qa->qs."</li>";
if ($qa->ans != null) {
$enotes3_ref = preg_replace("/[^A-Za-z0-9]/", '', $qa->ans);
$enotes3_ref = trim($enotes3_ref);

echo "<button style=\"float: left;\" id=\"button_toggle_visibility_edit_notes03\" onclick=\"toggle_visibility('toggle_edit_notes3_".$enotes3_ref."_".$activity->activity_id."');\"><img src=\"pix/icons8-communicate-100.png\" width=\"35em\" border=\"0\" alt=\"Add notes\" /><!--Add some notes here--></button>";
echo "<span class=\"show_key_sbook\">".$qa->ans."</span>";

if (trim($qa->hint) != null) {
echo "<span class=\"sbook_instructions02\">".$qa->hint."</span>\n";
}


echo "<div id='toggle_edit_notes3_".$enotes3_ref."_".$activity->activity_id."' style=\"display:none;\">";
echo "<div class=\"edit_notes\">";
?>
<?php // echo `date +%Y%m%d-%H%M%S`."_{$sbook_ref}_notes_{$member}.txt"; ?> <!-- http://cssdeck.com/labs/7bx7mmcm -->

<textarea id="inputTextToSave3" style="color: blue; font-size: 250%; width: 90%; height: 5em;"><?php echo $qa->ans; ?></textarea>
<br />
<div class="tooltip2"><label for="fileToLoad3" class="sbook_btn_browse"><div class="tooltiptext2">Browse</div></label><input id="fileToLoad3" type="file"/></div><div class="tooltip2"><button class="sbook_btn_load_file" onclick="loadFileAsText()"><div class="tooltiptext2">Load selected file</div></button></div><div class="tooltip2"><label for="inputFileNameToSaveAs3" class="sbook_btn_save_as"></label> <div class="tooltiptext2">Save as:<input id="inputFileNameToSaveAs3" placeholder="<?php echo `date +%Y%m%d-%H%M%S`."_{$sbook_ref}_notes_{$member}.txt"; ?>"/></div></div> <div class="tooltip2"><button class="sbook_btn_save" onclick="saveTextAsFile()"><div class="tooltiptext2">Save text to file</div></button></div>

<?php
echo "</div><!-- /class edit_notes -->";
echo "</div><!-- /toggle_visibility_edit_notes -->";

}
}
}
?>

<script>
function saveTextAsFile()
{
var textToWrite = document.getElementById("inputTextToSave3").value;
var textFileAsBlob = new Blob([textToWrite], {type:'text/plain'});
var fileNameToSaveAs = document.getElementById("inputFileNameToSaveAs3").value;

var downloadLink = document.createElement("a");
downloadLink.download = fileNameToSaveAs;
downloadLink.innerHTML = "Download File";
if (window.webkitURL != null)
{
// Chrome allows the link to be clicked
// without actually adding it to the DOM.
downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
}
else
{
// Firefox requires the link to be added to the DOM
// before it can be clicked.
downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
downloadLink.onclick = destroyClickedElement;
downloadLink.style.display = "none";
document.body.appendChild(downloadLink);
}
downloadLink.click();
}

function destroyClickedElement(event)
{
document.body.removeChild(event.target);
}


function loadFileAsText()
{
var fileToLoad3 = document.getElementById("fileToLoad3").files[0];

var fileReader = new FileReader();
fileReader.onload = function(fileLoadedEvent) 
{
var textFromFileLoaded = fileLoadedEvent.target.result;
document.getElementById("inputTextToSave3").value = textFromFileLoaded;
};
fileReader.readAsText(fileToLoad3, "UTF-8");
}
</script>

