﻿function showCal(txt, tp, lft)
{

    var objTxt = document.getElementById(txt);
    var objTp = document.getElementById(tp);
    var objLft = document.getElementById(lft);

    var pos = findPos(objTxt);

    objLft.value = pos[0];
    objTp.value = pos[1];

    //    alert(pos[0]);
    //    alert(pos[1]);
    //    alert(objLft.value);
    //    alert(objTp.value);

}

function findPos(obj)
{
    var curleft = curtop = curhigh = 0;
    if (obj.offsetParent)
    {
        curleft = obj.offsetLeft;
        curtop = obj.offsetTop;
        while (obj = obj.offsetParent)
        {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        }
    }
    return [curleft, curtop];
}

function ValueUp(ctrl)
{
    var val;
    val = parseFloat(document.getElementById(ctrl).value);
    val = val + 1;
    if (val <= 100 && val >= 0)
    {
        document.getElementById(ctrl).value = val;
    }
}
function ValueDown(ctrl)
{
    var val;
    val = parseFloat(document.getElementById(ctrl).value);
    val = val - 1;
    if (val <= 100 && val >= 0)
    {
        document.getElementById(ctrl).value = val;
    }
}

function EnableDisableContr(ctrl1, ctrl2)
{
    var obj1;
    var obj2;
    var sCursor = null;
    var sBgClr = null;
    //check box
    obj1 = document.getElementById(ctrl1);
    //Control to enable or disable
    obj2 = document.getElementById(ctrl2);
    if (obj1.checked == true)
    {

        //        switch (obj2.tagName)
        //        {
        //            case "A": sCursor = "hand"; sBgClr = ""; break;
        //            case "INPUT": sCursor = ""; sBgClr = "#FFFFFF"; break;           
        //        }
        //        obj2.style.cursor = sCursor;
        //        obj2.style.backgroundColor = sBgClr;
        obj2.disabled = false;
    }
    else
    {
        //        obj2.style.cursor = "";
        obj2.disabled = true;
    }
}

function OpenCalendar(ctrlName, calPath, initval)
{
    var height = 200;
    var width = 200;
    var left = (screen.availWidth - width) / 2;
    var top = (screen.availHeight - height) / 2;

    if (window.showModelessDialog)
    {
        var _R = window.showModelessDialog(calPath + "calendar.aspx?form=" + document.forms[0].name + "&control=" + ctrlName + "&initval=" + initval, window, "dialogWidth=180px;dialogHeight=180px;scroll=no;status=no;");
        _R.focus();

    }
    else	//NS
    {
        var left = (screen.width - width) / 2;
        var top = (screen.height - height) / 2;
        window.open(calPath + "calendar.aspx?form=" + document.forms[0].name + "&control=" + ctrlName + "&initval=" + initval, window.document.forms[0].name, "toolbar=false,location=false,directories=false,status=false,menubar=false,scrollbars=no,resizable=no,left=" + left + ",top=" + top + ",width=" + width + ",height=" + height);
    }

}

function fnUpCalenderValue(NewCalenderVal, ctrlName)
{
    document.getElementById(ctrlName).value = NewCalenderVal;
}

var screenWidth
var screenHeight

function OpenModelPopup()
{
    GetScreenSize();

    var PopupHeight;
    PopupHeight = document.getElementById('ModalPopupDiv').style.pixelHeight;

    var PopupWidth;
    PopupWidth = document.getElementById('ModalPopupDiv').style.pixelWidth;

    //        alert('screenWidth:' + screenWidth);
    //        alert('screenHeight:' + screenHeight);
    //        
    //        alert('ModalPopupDiv Height:' + document.getElementById('ModalPopupDiv').style.height);
    //        alert('ModalPopupDiv Width:' + document.getElementById('ModalPopupDiv').style.width);
    //        
    //        alert('Scroll width:' + getScrollWidth());
    //        alert('Scroll height:' + getScrollHeight());

    document.getElementById('ModalPopupDiv').style.visibility = 'visible';
    document.getElementById('ModalPopupDiv').style.display = '';
    document.getElementById('ModalPopupDiv').style.top = (((screenHeight / 2) - (PopupHeight / 2)) + getScrollHeight()) + 'px';
    document.getElementById('ModalPopupDiv').style.left = ((screenWidth / 2) - (PopupWidth / 2) + getScrollWidth()) + 'px';

    document.getElementById('MaskedDiv').style.display = '';
    document.getElementById('MaskedDiv').style.visibility = 'visible';
    document.getElementById('MaskedDiv').style.top = '0px';
    document.getElementById('MaskedDiv').style.left = '0px';
    document.getElementById('MaskedDiv').style.width = screenWidth + 1000;
    document.getElementById('MaskedDiv').style.height = screenHeight + 1000;

    document.body.scroll = "no";

}
function CloseModelPopup()
{
    document.getElementById('MaskedDiv').style.display = 'none';
    document.getElementById('ModalPopupDiv').style.display = 'none';
    document.body.scroll = "yes";

}
function Submit()
{
    if (document.getElementById('txtName').value != '')
    {
        document.getElementById('MaskedDiv').style.display = 'none';
        document.getElementById('ModalPopupDiv').style.display = 'none';
        document.getElementById('tdDisplayName').innerHTML = '<H1> Hi ' + document.getElementById('txtName').value + ' !</H1>';
    }
    else
    {
        alert('Please enter your name');
    }
}

function GetScreenSize()
{
    screenWidth = 0;
    screenHeight = 0;
    if (typeof (window.innerWidth) == 'number')
    {
        //Non-IE
        screenWidth = window.innerWidth;
        screenHeight = window.innerHeight;
    }
    else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
    {
        //IE 6+ in 'standards compliant mode'
        screenWidth = document.documentElement.clientWidth;
        screenHeight = document.documentElement.clientHeight;
    }
    else if (document.body && (document.body.clientWidth || document.body.clientHeight))
    {
        //IE 4 compatible
        screenWidth = document.body.clientWidth;
        screenHeight = document.body.clientHeight;
    }
}

function getScrollWidth()
{
    var w = window.pageXOffset ||
           document.body.scrollLeft ||
           document.documentElement.scrollLeft;

    return w ? w : 0;
}

function getScrollHeight()
{
    var h = window.pageYOffset ||
           document.body.scrollTop ||
           document.documentElement.scrollTop;

    return h ? h : 0;
}
function setHdnFldVal(val, hdn)
{
    document.getElementById(hdn).value = val;
}

function rangeValidate(source, arguments)
{
    arguments.IsValid = true;
    
    var grp = source.id;
    var grpName = grp.replace(/RngVal/, "Range");

    grpName = grpName.replace(/_/g, "$");

    var rdo = document.getElementsByName(grpName);
    var valid

    for (var x = 0; x < rdo.length; x++)
    {
        valid = rdo[x].checked
        if (valid) { break }
    }
    if (!valid)
    {
        arguments.IsValid = false;
    }


    //Range
    //    if (document.getElementById("ctl00_ContentPlaceHolder1_hidPayeeSeleted").value == 'yes')
    //    {
    //        arguments.IsValid = true;
    //    }
    //    else
    //    {
    //        arguments.IsValid = false;
    //    }

}

function rangeValidateDecimal(source, arguments)
{
    arguments.IsValid = true;

}


