﻿
function modalPopup(url, w, h)
{
    window.scrollTo(0, 0);
    var width = document.documentElement.clientWidth + document.documentElement.scrollLeft;
    var height = document.documentElement.clientHeight + document.documentElement.scrollTop;

    var layer = document.createElement('div');
    layer.style.zIndex = 2;
    layer.id = 'layer';
    layer.style.position = 'absolute';
    layer.style.top = '0px';
    layer.style.left = '0px';
    layer.style.height = document.documentElement.scrollHeight + 'px';
    layer.style.width = width + 'px';
    layer.style.backgroundColor = 'black';
    layer.style.opacity = '.6';
    layer.style.filter += ("progid:DXImageTransform.Microsoft.Alpha(opacity=60)");
    document.body.style.position = 'static';
    document.body.appendChild(layer);  

    var size = { 'height': h, 'width': w };
    var iframe = document.createElement('iframe');
    iframe.name = 'modal popup';
    iframe.id = 'modalpopup';
    iframe.src = KEYwebRoot + url
    iframe.style.height = size.height + 'px';
    iframe.style.width = size.width + 'px';
    iframe.style.position = 'fixed';
    iframe.style.zIndex = 3;
    iframe.style.backgroundColor = 'white';
    iframe.style.border = 'none'; //'4px solid silver';
    iframe.frameborder = '0';	

    iframe.style.top = ((height + document.documentElement.scrollTop) / 2) - (size.height / 2) + 'px';
    iframe.style.left = (width / 2) - (size.width / 2) + 'px';	
	
    document.body.appendChild(iframe);  
}

function closePopup()
{
  var editor = document.getElementById('modalpopup');
  var layer = document.getElementById('layer');
  document.body.removeChild(editor);
  document.body.removeChild(layer);
  document.body.style.position = '';
}

function setLabelText(label, text)
{
    if(label){
        label.innerHTML = text;
    }
}

function getLabelText(label)
{
    return label.innerHTML.replace(',', '').replace(',', '').replace(',', '').replace(',', '').replace(',', '').replace(',', '').replace(',', '').replace(',', '');
}

function AllowOnlyNumeric()
{
    // Get the ASCII value of the key that the user entered
    var key = window.event.keyCode;

    // Verify if the key entered was a numeric character (0-9) or a decimal (.)
    if ( (key > 47 && key < 58) || key == 46 )
        // If it was, then allow the entry to continue
        return;
    else
        // If it was not, then dispose the key and continue with entry
        window.event.returnValue = null; 
}

function AllowOnlyNumericPositiveInteger(textbox)
{
    var key = window.event.keyCode;
    if ( (key > 47 && key < 58)){
        if(textbox.value == "" && (key == 48)){
            window.event.returnValue = null; 
        }else{
            return;
        }
    }else{
        window.event.returnValue = null; 
    }
}

function tryParseFloat(label){
    var text = getLabelText(label);
    var retval = parseFloat(text);
    if(isNaN(retval))return 0;
    else return retval;
}

function addCommas(nStr)
{
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return x1 + x2;
}

















