﻿function show(element) { document.getElementById(element).style.display = 'block'; }
function showInline(element) { document.getElementById(element).style.display = 'inline'; }
function showRow(element) {
    if (navigator.userAgent.indexOf("MSIE") != -1 && navigator.userAgent.indexOf("Opera") == -1)
    { document.getElementById(element).style.display = 'block'; }
    else
    { document.getElementById(element).style.display = 'table-row'; }
}
function hide(element) { document.getElementById(element).style.display = 'none'; }

//User confirmation when trying to save an empty HTML document in the HtmlBlob control
function checkForEmptyHtml(htmlBlobID)
{
    var editedHtml = document.getElementById(htmlBlobID).getHTML();
    if (editedHtml.length == 0) {
        return confirm('Saving an empty document will simply clear any currently saved draft version.\n\nIf you just wish to not display any contents then you should cancel this edit and then select the \'Hide contents\' option.\n\n Do you still wish to continue with this save?');
    }
    return true;
}

var isTextarea = false;

//Clicks the specified link button when the enter key is hit within the control
function clickButtonOnEnter(linkButtonID, controlID, e)
{
    var key = keyCodeValue(e);
    if (key == 13 && !isTextarea) {
        if ((navigator.appName.indexOf("Microsoft") != -1) || (navigator.appName.indexOf("MSIE") != -1)) {
            var control = document.getElementById(controlID);
            try { window.external.AutoCompleteSaveForm(control); }
            catch (err) { }
        }
        clickLinkButton(linkButtonID, e);
    }
}

function keypressHandler(theButton)
{
 if (event.keyCode==13)
 {
  if(document.getElementById(theButton)) 
  {
	  event.returnValue = false;
	  document.getElementById(theButton).click();							
	 } else {
	  cancelBubble(event);
	 }							
 }
}

function cancelBubble(e)
{
 if(e.stopPropagation)
 {
  e.stopPropagation();
 } else {
	 e.cancelBubble=true;
 }
 if(e.preventDefault)
 {
  e.preventDefault();
 } else {
  e.returnValue=false;
 }
}

//Hides an element
function hide(element)
{
    if (typeof (element) == 'string') element = document.getElementById(element);
    if (element) element.style.display = 'none';
}

//Shows an element
function show(element)
{
    if (typeof (element) == 'string') element = document.getElementById(element);
    if (element) element.style.display = 'block';
}

//Shows an element inline
function showInline(element)
{
    if (typeof (element) == 'string') element = document.getElementById(element);
    if (element) element.style.display = 'inline';
}

//Shows an element as a table row
function showRow(element)
{
    if (typeof (element) == 'string') element = document.getElementById(element);
    if (element) element.style.display = (document.all) ? 'block' : 'table-row';
}

//Show or hide an element
function showOrHide(isShow, element)
{
    if (isShow) show(element);
    else hide(element);
}

//Copy text to clipboard
function copyToClipboard(text)
{
    try {
        var txtHoldText = document.getElementById('txtHoldText');
        txtHoldText.innerText = text.replace(/ /gi, "%20");

        var copied = txtHoldText.createTextRange();
        copied.execCommand("Copy");

        alert('The following link has been copied to the clipboard:\n\n' + txtHoldText.innerText);
    }
    catch (err) {
        alert('Sorry, the copying of the link to the clipboard has failed.\n\nPlease select and copy from below instead:\n\n' + txtHoldText.innerText);
    }
}

//Creates XmlHttp request object
function getXMLHttp()
{
    var xmlHttp = false;

    try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); }
    catch (err1) {
        try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); }
        catch (err2) { xmlHttp = false; }
    }
    // Mozilla...
    if (!xmlHttp && typeof XMLHttpRequest != 'undefined') xmlHttp = new XMLHttpRequest();

    return xmlHttp;
}

//Shows an alert popup
function showAlert(message)
{
    setTimeout(function() { alert(message); }, 250);
}