﻿if (typeof window.event != 'undefined')
{
	document.onkeydown = function()
	{
        var intKey = event.keyCode;
        var elementType = event.srcElement.type;

        if ((intKey == 13) && (elementType != 'textarea'))
        {
            event.returnValue=false;
            event.cancel =true;
            return false;
        }
        return true;
	}
}
else
{
	document.onkeydown = function(e)
	{
        var intKey = e.charCode;
        var elementType = e.target.type;

        if ((intKey == 13) && (elementType != 'textarea'))
        {
            e.returnValue=false;
            e.cancel =true;
            return false;
        }
        return true;
	}
}

function ClickOnEnter(defaultButton, e)
{
    var intKey = (e.keyCode)? e.keyCode: e.charCode;

    if (intKey == 13)
    {
        e.returnValue=false;
        e.cancel =true;
        document.getElementById(defaultButton).click();
        return false;
    }
    else
    {
        return true;
    }
}

function NumericOnlyClickOnEnter(defaultButton, e, allowDecimals)
{
    var intKey = (e.keyCode)? e.keyCode: e.charCode;

    if (intKey == 13)
    {
        e.returnValue=false;
        e.cancel =true;
        document.getElementById(defaultButton).click();
        return false;
    }
    else
    {
        if (intKey == 110 || (intKey == 190 && true == allowDecimals) || (intKey <= 57) || (intKey >= 96 && intKey <= 105))
        {
            return true;
        }
        else
        {
            e.returnValue=false;
            e.cancel =true;
            return false;
        }
    }
}

function NumericOnly(e, allowDecimals)
{
    var intKey = (e.keyCode)? e.keyCode: e.charCode;

    if (intKey == 110 || (intKey == 190 && true == allowDecimals) || (intKey <= 57) || (intKey >= 96 && intKey <= 105))
    {
        return true;
    }
    else
    {
        e.returnValue=false;
        e.cancel =true;
        return false;
    }
}

function IgnoreEnter(e)
{
    var intKey;
    if (typeof window.event != 'undefined')
    {
        intKey = e.keyCode;
        if (intKey == 13)
        {
            e.returnValue=false;
            e.cancel =true;
            return false;
        }
        return true;
    }
    else
    {
        intKey = e.charCode;
        if (intKey == 13)
        {
            e.returnValue=false;
            e.cancel =true;
            return false;
        }
        return true;
    }
}

function ClickOnFocusLoss(defaultButton)
{
    document.getElementById(defaultButton).click();
    return true;
}

function SafeInnerHTML(el,content)
{
    if (null != el)
    {
        if (document.all)
        {
            el.innerHTML = content;
        }
        else
        {
            rng = document.createRange();
            rng.setStartBefore(el);
            htmlFrag = rng.createContextualFragment(content);
            while (el.hasChildNodes())
            {
                el.removeChild(el.lastChild);
            }
            el.appendChild(htmlFrag);
        }
    }
}        

function setIframeHeight(iframeName) {
//var iframeWin = window.frames[iframeName];
var iframeEl = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
if (iframeEl) {
iframeEl.style.height = "auto"; // helps resize (for some) if new doc shorter than previous
//var docHt = getDocHeight(iframeWin.document);
// need to add to height to be sure it will all show
var h = alertSize();
iframeEl.style.height = h + "px";
//alertSize();
}
}

function alertSize() {
var myHeight = 0;
if( typeof( window.innerWidth ) == 'number' ) {
//Non-IE
myHeight = window.innerHeight;
} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
//IE 6+ in 'standards compliant mode'
myHeight = document.documentElement.clientHeight;
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
//IE 4 compatible
myHeight = document.body.clientHeight;
}
//window.alert( 'Height = ' + myHeight );
return myHeight;
}

function SetInnerHtml(el,content)
{
    if (null != el)
    {
        if (document.all)
        {
            alert(1);
            el.innerHTML = content;
        }
        else
        {
            rng = document.createRange();
            rng.setStartBefore(el);
            htmlFrag = rng.createContextualFragment(content);
            while (el.hasChildNodes())
            {
                el.removeChild(el.lastChild);
            }
            el.appendChild(htmlFrag);
        }
    }
}        

function SetInnerText(el,content)
{
    if (null != el)
    {
        if (document.all)
        {
            el.innerText = content;
        }
        else
        {
            el.textContent = content;
        }
    }
}        

