﻿// JScript File
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
function getWindow_TotalWidth()
{
    return window.screen.availWidth;
}
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
function getWindow_TotalHeight()
{
    return window.screen.availHeight;
}
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
function Trim(TrimString)
{	var tempObj;
	if(TrimString){tempObj = TrimString;TrimString = tempObj.value;}
	if(TrimString == "undefined" || TrimString == null) return null;
	if(TrimString.length == 0)TrimString="";
	else
	{	var Lcont=0,TempStrArray=TrimString.split(" "),Rcont=TempStrArray.length-1;
		while(TempStrArray[Lcont] == "")Lcont++;while(TempStrArray[Rcont] == "")Rcont--;
		if(Rcont<Lcont)TrimString="";else
		for(TrimString = TempStrArray[Lcont], Lcont++ ; Lcont <= Rcont ; Lcont++) TrimString += " " + TempStrArray[Lcont];
	}
	if(tempObj && TrimString != "undefined" && TrimString != null) 
	{	tempObj.value = TrimString;	return tempObj	  }
	else return TrimString;
}

/*---------------------- To Trim all elementes in the form  ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
// Param 1 : Form object
function FormTrim(oForm)
{	for (i=0; i<=oForm.length-1; i++)
	{	if (oForm[i].type == "text" || oForm[i].type == "textarea")		
			Trim(oForm[i])
	}
}

/*----------------------- To Check integer value -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
// Param 1 : Value to check
function IsNumeric(val)
{   if (isNaN(val)) return false;
    if (val.indexOf(".") >= 1) return false
    return true;
}

/*------------------------ To Check decimal part or currency  ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
// Param 1 : Value to check
// Param 2 : number of fractinal points after dot(.) 
function isDecimal(val, FractionalPart)
{   var Postition = val.indexOf(".")
    if (Postition <= 0) return false;
    var left = val.split(".")[0];
    var right = val.split(".")[1];
    if (!IsNumeric(left)) return false;
    if (!IsNumeric(right)) return false;
    if ((Postition+FractionalPart) != val.length-1) return false
    return true;
}

/*------------------------ To Get Query string variable by passing name  ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
// Param 1 : Pass QueryString name to get value.
function getQueryVariable(variable)
{	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++)
	{	var pair = vars[i].split("=");
		if (pair[0] == variable) return pair[1];
	}
}

/*------------------------ To check valid formatted date enterd by the user ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
// Param 1 : Date value (fortmat dd/MM/yyyy)
function IsDate(val)
{   if (val.split("/").length == 3) 
    {   var DD = val.split("/")[0];
        var MM = val.split("/")[1];
        var YY = val.split("/")[2];
        if (IsNumeric(DD) == false) return false;
        if (IsNumeric(MM) == false) return false;
        if (IsNumeric(YY) == false) return false;
        if (DD > 31) return false;
        if (MM > 12) return false;
        if (YY < 1901) return false;
        if (isLeapYear(DD,MM,YY) == false) return false; else return true;
    }   
    else
        return false;
}
        
/*------------------------ To check valid date, LeapYear (eg-:feb 31) ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/        
// Param 1 : DD - Day of the Date (format : 02)
// Param 2 : MM - Month of the Date (format : 04)
// Param 3 : YY - Year of the Date (format : 2007)
function isLeapYear(DD,MM,YY)
{   if(MM == 4 || MM == 6 || MM == 9 || MM == 11) {	if(DD > 30) return false; }
    if(MM == 2)
    {	var modval = parseInt(YY)%4;
	    if(modval == 0)
	    {	if(parseInt(DD) > 29) return false;
	    }
	    else
	    {	if(parseInt(DD) > 28) return false;
	    }
    }; return true;
}

/*------------------------ To check valid date, LeapYear (eg-:feb 31) ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/        
// Param 1 : Date1 (format should be dd/MM/yyyy)
// Param 2 : Date2 (format should be dd/MM/yyyy)
// Param 3 : Operator ("<" or "<=" or "==" or ">" or ">=")
// Eg :- DateCompare("01/05/2005", "05/05/2005", "<")
function DateCompare(Date1, Date2, Operator)
{    var FromDate = new Date(Date1)
     var ToDate = new Date(Date2)
     if (Operator == "<") return (FromDate < ToDate)
     if (Operator == "<=") return (FromDate <= ToDate)
     if (Operator == ">") return (FromDate > ToDate)
     if (Operator == ">=") return (FromDate >= ToDate)
     if (Operator == "==") return (FromDate == ToDate)
}


function FnDetailedDisplay(Code, Type, Group)
{   
    var width = 1004;
    var height = 545;
    var left = (screen.width - width)/2;
    var top = (screen.height - height)/2;
    var params = 'width='+width+', height='+height;
    params += ', top='+top+', left='+left;
    params += ', directories=no';
    params += ', location=no';
    params += ', menubar=no';
    params += ', resizable=1';
    params += ', scrollbars=1';
    params += ', status=no';
    params += ', toolbar=no';
    var dFromDate = document.getElementById('ctl00_HidStartDate').value 
    var dToDate = document.getElementById('ctl00_HidEndDate').value   
    var CompanyID = document.getElementById('ctl00_HidCompanyID').value 
    oDrilDownWindow = window.open ("../Reports/Drildown.aspx?Type="+Type+"&Code="+Code+"&Group="+Group+"&From="+dFromDate+"&To="+dToDate+"","mywindow",params); 
    oDrilDownWindow.focus();
}
function FnDetailedDisplay1(Code, Type, Group)
{   
    var width = 1004;
    var height = 545;
    var left = (screen.width - width)/2;
    var top = (screen.height - height)/2;
    var params = 'width='+width+', height='+height;
    params += ', top='+top+', left='+left;
    params += ', directories=no';
    params += ', location=no';
    params += ', menubar=no';
    params += ', resizable=1';
    params += ', scrollbars=1';
    params += ', status=no';
    params += ', toolbar=no';
    var dFromDate = document.getElementById('ctl00_ContentPlaceHolder1_TxtFromDate_txtDate1').value 
    var dToDate = document.getElementById('ctl00_ContentPlaceHolder1_TxtToDate_txtDate1').value   
    var CompanyID = document.getElementById('ctl00_HidCompanyID').value 
    oDrilDownWindow = window.open ("../Reports/Drildown.aspx?MainMenu=Flow&Type="+Type+"&Code="+Code+"&Group="+Group+"&From="+dFromDate+"&To="+dToDate+"","mywindow",params); 
    oDrilDownWindow.focus();
}
function FnDisplay_DetailedCostCentre(CostCentreID, Code, Type, Particulars)
{   //alert(CostCentreID+" "+Code+" "+Type+" "+Particulars)
    oDrilDownWindow = window.open ("../Reports/TrailBalance_CostCentre.aspx?CostCentreID="+CostCentreID+"&Code="+Code+"&Type="+Type+"&Particulars="+Particulars+"","mywindow","location=0,status=0,scrollbars=1,width=1004,height=545,resizable=1"); 
    oDrilDownWindow.focus();
}



//---------------------------------------- Numeric validations - Start ----------------------------------------
var keycodes = new Array();
function get_keyboard_codes() {
    keycodes = {
        8: "backspace",
        9: "tab",
        13: "enter",
        16: "shift",
        17: "ctrl",
        18: "alt",
        19: "pause/break",
        20: "caps lock",
        27: "escape",
        33: "page up",
        34: "page down",
        35: "end",
        36: "home",
        37: "left arrow",
        38: "up arrow",
        39: "right arrow",
        40: "down arrow",
        45: "insert",
        46: "delete",
        48: "0",
        49: "1",
        50: "2",
        51: "3",
        52: "4",
        53: "5",
        54: "6",
        55: "7",
        56: "8",
        57: "9",
        91: "left window",
        92: "right window",
        93: "select key",
        96: "0",
        97: "1",
        98: "2",
        99: "3",
        100: "4",
        101: "5",
        102: "6",
        103: "7",
        104: "8",
        105: "9",
        106: "multiply",
        107: "add",
        109: "subtract",
        110: ".",
        111: "divide",
        112: "F1",
        113: "F2",
        114: "F3",
        115: "F4",
        116: "F5",
        117: "F6",
        118: "F7",
        119: "F8",
        120: "F9",
        121: "F10",
        122: "F11",
        123: "F12",
        144: "num lock",
        145: "scroll lock",
        186: ";",
        187: "=",
        188: ",",
        189: "-",
        190: ".",
        191: "/",
        192: "`",
        219: "[",
        220: "\\",
        221: "]",
        222: "'"
    };
    return keycodes;
}
function NumericValidations(event, obj, enableDecimal, maxDecPoint, maxLength, minValue, maxValue, errMsg) {    
    value = obj.value;
    if (!e) var e = event;
    if (e.keyCode) code = e.keyCode; else if (e.which) code = e.which;
    
    if (code == 16 ) { return false; }
    if (code == 8 || code == 46) { return true; }    
    if ((code >= 48 && code <= 57) || (code >= 96 && code <= 105) || code == 8 || code == 9 || code == 17 || code == 18 || code == 35 || code == 36 || code == 37 || code == 39 || code == 46 || code == 116 || (enableDecimal == true && (code == 110 || code == 190))) {
        keycodes = get_keyboard_codes();        
        var sCharacter;
        for (key in keycodes) {
            if (code == key) {
                sCharacter = keycodes[key];
                if (sCharacter == ".") {
                    for (i = 0; i < value.length; i++) {
                        c = value.substring(i, i + 1);
                        if (c == ".") { return false; }
                    }
                }
                value = ConcatenateValues(value, sCharacter, code);                
                if ((value.split(".").length == 2) && (maxDecPoint > 0)) {
                    if (value.split(".")[1].length > maxDecPoint) return false;
                }
                if (value > maxValue && maxValue != 0) {
                    value = value.substring(0, value.length - 1);
                    if(errMsg != "") alert(errMsg);
                    return false;
                }
                if (value.length > maxLength && maxLength != 0) {
                    value = value.substring(0, value.length - 1);
                    if(errMsg != "") alert(errMsg);
                    return false;
                }               
                break;
            }
        }
        if ((event.shiftKey == 1) && ((code >= 48 && code <= 57) || (code >= 96 && code <= 105) || (code == 110 || code == 190))) return false;
        return true;
    }
    else {
        if (errMsg.trim() != "") alert(errMsg);
        obj.focus();
        return false;
    }

}
function ConcatenateValues(value, character, code) {
    if ((code >= 48 && code <= 57) || (code >= 96 && code <= 105) || (code == 110 || code == 190))
        value = value + character;
    return value;
}
function AddNumericValidations(event, obj, enableDecimal, maxDecPoint, maxLength, minValue, maxValue, errMsg) {
    if (obj != null) {
        obj.onkeydown = function() {
            var event = window.event;
            return NumericValidations(event, obj, enableDecimal, maxDecPoint, maxLength, minValue, maxValue, errMsg);
        }

        obj.onpaste = function() {
            return NumericValidation_OnPaste(event, obj, enableDecimal, maxDecPoint, maxLength, minValue, maxValue, errMsg);
        }

        obj.ondrop = function() {
            return false;
        }
    }
}
function NumericValidation_OnPaste(event, obj, enableDecimal, maxDecPoint, maxLength, minValue, maxValue, errMsg){   
    return false;
    var val = window.clipboardData.getData("Text");    
    if(enableDecimal==0 && !isNaN(val))
    {        
        obj.value = parseInt(val);
        return false;
    }
    if(enableDecimal==1 && !isNaN(val))
    {
        if(maxDecPoint > 0) obj.value = parseFloat(val).toFixed(maxDecPoint);        
        else obj.value = parseFloat(val); 
        return false;     
    }
    return false;
}
function LimitTextLength(obj, maxLength) {    
    obj.onpaste = function() {
        return LimitTextLength_OnPaste(obj, maxLength);}

    obj.ondrop = function() {
        return LimitTextLength_OnDrop(obj, maxLength);
    }   
    obj.onkeydown = function() {        
        return LimitTextLength_OnKeyDown(event, obj, maxLength);    }
        
}

function LimitTextLength_OnKeyDown(event, obj, maxLength) {    
    value = obj.value;
    if (!e) var e = event;
    if (e.keyCode) code = e.keyCode; else if (e.which) code = e.which;

    if (parseInt(obj.value.length) >= parseInt(maxLength)) {
        var Arr = new Array(8, 9, 13, 17, 18, 33, 34, 35, 36, 37, 38, 39, 40, 46, 144);
        return CheckArray(Arr,code);
    }
}
function CheckArray(Arr,code) {
    for (var a in Arr) {
        if(Arr[a] == code)
            return true;
    }
    return false;
}
function LimitTextLength_OnPaste(obj, maxLength) {    
    var val = window.clipboardData.getData("Text");
    if (val.length > maxLength) {
        val = val.substring(maxLength, 0);
        obj.value = val;
        return false;
    }
    else {
        return true;
    }    
}
function LimitTextLength_OnDrop(obj, maxLength) {
    return false;
}
function DisplayErrorMsg(Msg,LblID)
{    
    var Lbl = document.getElementById(LblID);
    Lbl.innerHTML = Msg;
    return false;
}
//---------------------------------------- Numeric validations - End ----------------------------------------


function Set_Value_Set_EditText_By_TypeAndId_For_Input(cell, type, id, value) {
    for (j = 0; j < cell.childNodes.length; j++) {
        if ((cell.childNodes[j].type == type)) {
            var ArrId = cell.childNodes[j].id.split("_");
            if (ArrId[ArrId.length - 1] == id) {
                cell.childNodes[j].value = "Edit";
                cell.childNodes[j].id = value;
                break;
            }

        }
    }
}

function Set_Value_By_TypeAndId_For_Input(cell, type, id, value) {
    for (j = 0; j < cell.childNodes.length; j++) {
        if ((cell.childNodes[j].type == type)) {
            var ArrId = cell.childNodes[j].id.split("_");
            if (ArrId[ArrId.length - 1] == id) {
                cell.childNodes[j].value = value;
                break;
            }
        }
    }
}

function Set_All_By_TypeAndId_For_Input(cell, type, id, valChecked, valVisibility, valDisabled) {
    for (j = 0; j < cell.childNodes.length; j++) {
        if ((cell.childNodes[j].type == type)) {
            var ArrId = cell.childNodes[j].id.split("_");
            if (ArrId[ArrId.length - 1] == id) {
                cell.childNodes[j].checked = valChecked;
                cell.childNodes[j].style.visibility = valVisibility;
                cell.childNodes[j].disabled = valDisabled;break;
                //alert(cell.childNodes[j].checked);
            }
            
        }
    }
}
function Get_Value_By_TypeAndId_For_Input(cell, type, id) {    
    for (j = 0; j <= cell.childNodes.length; j++) {
        if ((cell.childNodes[j].type == type)) {            
            var ArrId = cell.childNodes[j].id.split("_");
            if (ArrId[ArrId.length - 1] == id) {                 
                return cell.childNodes[j].value;
            }            
        }
    }
}
function Get_Value_By_TypeAndId_For_Lables(cell, type, id) {
    for (j = 0; j < cell.childNodes.length; j++) {
        if (cell.childNodes[j].nodeName.toUpperCase() == type) {
            var ArrId = cell.childNodes[j].id.split("_");
            if (ArrId[ArrId.length - 1] == id) {
                return cell.childNodes[j].innerHTML;
            }
            
        }
    }
}
function Get_Value_For_Cell(cell) {
    return cell.innerHTML;
}
function GetRadioButtonSelectedValue(oID) {
    var o = document.getElementById(oID).getElementsByTagName("INPUT")
    var SelectedValue = '';
    for (i = 0; i < o.length; i++) {        
        if (o[i].checked && o[i].type == "radio") {
            SelectedValue = o[i].value;break;
        }
    }
    return SelectedValue;
}
function GetCheckBoxSelectedValue(oID) {
    var o = document.getElementById(oID).getElementsByTagName("INPUT")
    var SelectedValue = '';
    for (i = 0; i < o.length; i++) {        
        if (o[i].checked && o[i].type == "checkbox") {
            SelectedValue = o[i].value;break;
        }
    }
    return SelectedValue;
}
function IsAnyChecked(oID)
{
    var o = document.getElementById(oID).getElementsByTagName("INPUT")
    var SelectedValue = '';
    for (i = 0; i < o.length; i++) {        
        if (o[i].checked && o[i].type == "checkbox") {
            return true;break;
        }
    }
    return false;
}
function MyValidatorEnable(obj,bool)
{
    ValidatorEnable(obj,bool);
    obj.style.display = "none";
}


function Open_PopUp(Url)
{   var width = 1004;
    var height = 545;
    var left = (screen.width - width)/2;
    var top = (screen.height - height)/2;
    var params = 'width='+width+', height='+height;
    params += ', top='+top+', left='+left;
    params += ', directories=no';
    params += ', location=no';
    params += ', menubar=no';
    params += ', resizable=1';
    params += ', scrollbars=1';
    params += ', status=no';
    params += ', toolbar=no';
    oDrilDownWindow = window.open (Url,"mywindow",params); 
    oDrilDownWindow.focus();
}
function Report_PopUp(Url, Value)
{   var width = 1004;
    var height = 545;
    var left = (screen.width - width)/2;
    var top = (screen.height - height)/2;
    var params = 'width='+width+', height='+height;
    params += ', top='+top+', left='+left;
    params += ', directories=no';
    params += ', location=no';
    params += ', menubar=no';
    params += ', resizable=1';
    params += ', scrollbars=1';
    params += ', status=no';
    params += ', toolbar=no';
    oDrilDownWindow = window.open (Url,Value,params); 
    oDrilDownWindow.focus();
}
