﻿// JScript File
/**************************************************************************
Description : This script can be used to create the Tree view structure based on the Geneology type.
But its an unlimited downline for that sponsor
Created By  : Vasanth
Created On  : 12 May , 2008
Modified by : Senthil balaji R - 27/08/2009 - For Renewal Eligible 
	          Ganesh Balaji S - 10/09/2009 - For Address Proof Not Submitted Report 
	          sreenivasulu J -  11/09/2009  - For PV/BV information
**************************************************************************/
/*

1.ID         --> nodeValues[0]                      
2.sponsorID  --> nodeValues[1]
3.NAME       --> nodeValues[2]
4.STATUS     --> nodeValues[3]
DOWNLINE is available or not 
5.DOWNLINE   --> nodeValues[4] 
IDs with Seperator --> If id is 3 , its returns (5,6,)
6.GROUP LEADERS --> Whether he is platinum or some  nodeValues [5] 
7.ABO Level --> Level of the ABOs [6]
8.ABO Info  -- > Catch the ABO Address ,PV,EMail ,AutoRenewied  [7] 
9.ABO Status -- > Active , Inactive or Else  [8]
*/

// Arrays for nodes and icons

var strMasterPageName = 'ctl00_ContentPlaceHolder1_'
//Other Common Controls in that page
var strddlCriteria = strMasterPageName + 'ddlCriteria';
var strddlLOSState = strMasterPageName + 'ddlLOSState';
var strddlLOSCity = strMasterPageName + 'ddlLOSCity';
var strtxtSpecifyValue = strMasterPageName + 'txtSpecifyValue';
var strddlGroupLeaders = strMasterPageName + 'ddlGroupLeaders';
var strtxtNewSpecifiedABOs = strMasterPageName + 'txtNewSpecifiedABOs';
var strtxtRangeFrom = strMasterPageName + 'txtRangeFrom';
var strtxtRangeTo = strMasterPageName + 'txtRangeTo';
var strdivTree = strMasterPageName + 'divTree';
var strcABOStatusOptions = strMasterPageName + 'cABOStatusOptions';
var strhdnFilterABONumber = strMasterPageName + 'hdnFilterABONumber';
var strhdnMainLeg = strMasterPageName + 'hdnMainLeg';
var strlblSuccess = strMasterPageName + 'lblSuccess';
var strhdnExpandABO = strMasterPageName + 'hdnExpandABO';
var strhdnFilterString = strMasterPageName + 'hdnFilterString';
//Dynamic control creation
var strdivHideFilter = 'divHideFilter';
var strdivSpecificABO = 'divSpecificABO';
var strdivSpecificABO1 = 'divSpecificABO1';
var strdivSpecifyValue = 'divSpecifyValue';
var strdivGroupLeaders = 'divGroupLeaders';
var strdivPVBVRanges = 'divPVBVRanges';
var strdivNewSpecifiedABOs = 'divNewSpecifiedABOs';
var strdivPVBVHisMon ='divPVBVHisMonth';
var strddlPVBVHisMon  =strMasterPageName + 'ddlPVBVHisMonth';

/*Added for FPO Report*/

var strdivFPOFilters = 'divFPOPromoSection';
var id4='ctl00_ContentPlaceHolder1_txtStartDate';
var id5='ctl00_ContentPlaceHolder1_txtEndDate';
var strFPOPromotions='ctl00_ContentPlaceHolder1_ddlFPOFilters';
//To fix the bug ID 242
 var strdivPopup = 'ctl00_ContentPlaceHolder1_pnlOpenDeal';
//Call the function when button click or page init
function ViewControls() {
    document.getElementById(strdivHideFilter).style.display = '';
    document.getElementById(strdivSpecificABO).style.display = '';
    document.getElementById(strdivSpecificABO1).style.display = '';
    document.getElementById(strdivSpecifyValue).style.display = 'none';
    document.getElementById(strdivGroupLeaders).style.display = 'none';
    document.getElementById(strdivPVBVRanges).style.display = 'none';
    document.getElementById(strdivNewSpecifiedABOs).style.display = 'none';
    //Clear the Filters
    document.getElementById(strddlLOSState).selectedIndex = 0;
    document.getElementById(strddlLOSCity).selectedIndex = 0;
    document.getElementById(strtxtSpecifyValue).value = "";
    document.getElementById(strtxtNewSpecifiedABOs).value = "";
    document.getElementById(strddlGroupLeaders).selectedIndex = 0;
    document.getElementById(strtxtRangeFrom).value = "";
    document.getElementById(strtxtRangeTo).value = "";
    //Hide the loading info
    
    //FPO
     document.getElementById(id5).value = "";
      document.getElementById(id4).value = "";
      document.getElementById(strFPOPromotions).selectedIndex = 0;
      
      document.getElementById(strddlPVBVHisMon).selectedIndex = 0;
}
function PopupView(UserId) {

    try {
        ShowMessage('Loading...');
        //Call the page methods and get the ABO Info
        PageMethods.GetABODetails(UserId, OnSucceededDetails, OnFailedDetails);
    }
    catch (err) 
    {
        location.replace('../Users/Login.aspx');
    }
}
//This method is to get the last three months PVBV information for an ABO.
function PopupGVPVView(UserId, pvbvMonth) {

    try {   
   var userID=UserId + "~" + pvbvMonth;
        ShowMessage('Loading...');
        //Call the page methods and get the ABO Info
        PageMethods.GetABODetails(userID , OnSucceededDetails, OnFailedDetails);
    }
    catch (err) 
    {
        location.replace('../Users/Login.aspx');
    }
}
//IF the server side code execute true its return the array of the value
function OnSucceededDetails(result, userContext, methodName) {

    try 
    {
    //Sreenivasuluj:tofix the Support issue 242
     var resolution=screen.width +' x '+ screen.height;
   var objpopup = document.getElementById(strdivPopup);
     var objinnerdiv = document.getElementById("divABOInfo");
     var totalheight=(screen.height/100)*70;
    objpopup.style.height=totalheight +'px';
   objinnerdiv.style.height=totalheight-100+'px';
    //Add the PV/BV Orders bind list
		  var arrPVBV = new Array(4); 
		  arrPVBV[0] = "Personal PV";
		  arrPVBV[1] = "Personal BV";
		  arrPVBV[2] = "Group PV";
		  arrPVBV[3] = "Group BV";
        //Create an temp array
        var arrTemp = new Array();
        var arrHist =new Array();
        //Get the div Objects
        var objABODetails = document.getElementById("divABODetails");
        objABODetails.innerHTML = "";
        objABODetails.style.height=totalheight-85+'px';
        //ABO Number
        objABODetails.innerHTML += "<div><span><strong>ABO Number : </strong></span></div><div style=\"margin-top:5px;\">" + result[0] + "</div><hr />";
        //ABO Name
        objABODetails.innerHTML += "<div class=\"los_hdr\"  ><span '><strong>ABO Name : </strong></span></div><div style=\"margin-top:5px;\">" + result[1] + "</div><hr />";
        //Address
        objABODetails.innerHTML += "<div class=\"los_hdr\"><span><strong>Address : </strong></span></div>"
        arrTemp = result[2].split("~"); //Split
        for (iRowCount = 0; iRowCount < arrTemp.length; iRowCount++)
            if (arrTemp[iRowCount].length > 0)
            objABODetails.innerHTML += "<div style=\"margin-top:5px;\">" + arrTemp[iRowCount] + "</div>";
        //Phone Number 
        objABODetails.innerHTML += "<hr /><div class=\"los_hdr\" ><span><strong>Phone Number :  </strong></span></div>";
        arrTemp = result[3].split("!"); //Split
        for (iRowCount = 0; iRowCount < arrTemp.length; iRowCount++)
            if (arrTemp[iRowCount].length > 0)
            objABODetails.innerHTML += "<div style=\"margin-top:5px;\">" + arrTemp[iRowCount] + "</div>";
        //PV/BV Information
        //Modified by: sreenivasuluj
        //description: To show the last three months pv/bv history if the user select the PV/BVhistory from the selection criteria.
        objABODetails.innerHTML += "<hr /><div class=\"los_hdr\" ><span ><strong>PV/BV Information :  </strong></span></div>"
        if( result[4].indexOf('hist')==0)
        {
        objABODetails.innerHTML += "<div class=\"divCurrentReport\" style=\"margin-top:5px;\">";
        
         if (result[4].indexOf('PVorBV') < 0) 
        {
        objABODetails.innerHTML +="<TABLE  class=\"tblAlign\" border=\"0\"><TBODY><TR class=\"PvHeader\" ><TD class=\"PvWidth\" ></TD><TD class=\"PvWidth2\" >PV</TD><TD class=\"PvWidth3\" >BV</TD><TD class=\"PvWidth4\" >% Bonus Level</TD><TD class=\"PvWidth5\" >AR</TD><TD class=\"PvWidth\" >Award Legs</TD><TD class=\"PvThird\" >Order</TD><TD class=\"PvWidth PvAward\" >Award</TD></TR></TBODY></TABLE>";
           
        arrTemp = result[4].split("!"); 
         for (iCount = 1; iCount < arrTemp.length; iCount++)
          {
          //objABODetails.innerHTML +="<TABLE><TBODY>";
                if (arrTemp[iCount].length > 0) 
                  {
                arrHist=arrTemp[iCount].split("~");

                objABODetails.innerHTML +="<TABLE class=\"tblAlign\" border=\"0\"><TBODY><TR ><TD ><B><SPAN >" + arrHist[0]  + "</SPAN> </B></TD></TR><TR ><TD ><B><SPAN >Personal</SPAN> </B></TD><TD ><SPAN >"+ arrHist[1]+"</SPAN></TD><TD ><SPAN>"+ arrHist[2] +"</SPAN></TD><TD ><SPAN >"+ arrHist[5] +"</SPAN><SPAN > %</SPAN></TD><TD ><SPAN >"+ arrHist[6] +"</SPAN></TD><TD ><SPAN >" + arrHist[8] + "</SPAN></TD><TD ><SPAN >" + arrHist[9] + "</SPAN></TD><TD ><SPAN >"+ arrHist[7] +"</SPAN></TD></TR><TR class=\"PvMonth\" ><TD class=\"PvMonth\" ><B><SPAN>Group</SPAN> </B></TD><TD class=\"PvMonth\" ><SPAN>"+ arrHist[3] +"</SPAN></TD><TD class=\"PvMonth\"><SPAN>"+ arrHist[4] +"</SPAN></TD><TD class=\"PvMonth\" ><SPAN></SPAN></TD><TD class=\"PvMonth\"><SPAN ></SPAN></TD><TD class=\"PvMonth\" ><SPAN></SPAN></TD><TD class=\"PvMonth\" ><SPAN>"+arrHist[10]+"</SPAN></TD><TD class=\"PvMonth\" ><SPAN ></SPAN></TD></TR></TBODY></TABLE>";
                }
                }
                 objABODetails.innerHTML += "</div>"; 
                }
                else
                {
                //There is no PV/Bv info in DB 
            objABODetails.innerHTML += "<div style=\"margin-top:5px;\">No PVorBV</div>";
                }
        }
        else
        {
        arrTemp = result[4].split("~"); //Split
        
        if (result[4].indexOf('PVorBV') < 0) 
        {
            for (iRow = 0; iRow < arrTemp.length; iRow++) {
                if (arrTemp[iRow].length > 0)
                    objABODetails.innerHTML += "<div style=\"margin-top:5px;\"><strong>" + arrPVBV[iRow] + "    :   </strong>" + arrTemp[iRow] + "</div>";
            }
        }
        else //There is no PV/Bv info in DB 
        {
            objABODetails.innerHTML += "<div style=\"margin-top:5px;\">No PVorBV</div>";
        }
        }
        //Email ID
        objABODetails.innerHTML += "<hr /><div class=\"los_hdr\" ><span><strong>EmailID :  </strong></span></div><div style=\"margin-top:5px;\">" + result[5] + "</div>";
        //Auto Renewal
        objABODetails.innerHTML += "<hr /><div class=\"los_hdr\"><span><strong>Auto Renewal :  </strong></span></div><div style=\"margin-top:5px;\">" + result[6] + "</div>";
        //Date of Expiry
        objABODetails.innerHTML += "<hr /><div class=\"los_hdr\"><span><strong>Date of Expiry :  </strong></span></div><div style=\"margin-top:5px;\">" + result[7] + "</div>";
        //Finally  open the modal popup
        $find('mdlPopupOpenBehaviourId').show();
        //Hide Loading Message
        HideMessage();

    }
    catch (err) 
    {
       location.replace('../Users/Login.aspx');
    }
}
function OnFailedDetails(error, userContext, methodName)
{
    location.replace('../Users/Login.aspx');
}

function fnFilter() {
    //Create an instance for the controls
    var ddlCriteria = document.getElementById(strddlCriteria);
    var ddlState = document.getElementById(strddlLOSState);
    var ddlCity = document.getElementById(strddlLOSCity);
    var txtSpecifyValue = document.getElementById(strtxtSpecifyValue);
    var ddlGroupLeaders = document.getElementById(strddlGroupLeaders);
    var txtPVRangeFrom = document.getElementById(strtxtRangeFrom);
    var txtPVRangeTo = document.getElementById(strtxtRangeTo);
    var txtNewSpecifiedABOs = document.getElementById(strtxtNewSpecifiedABOs);
    var sFilter = "";
    /*Check the filter option based on the Creteria
    1.Selection Criteria   [0]
    2.PV Range from        [1]
    3.PV Range TO          [2]
    4.Group Leaders Level  [3]
    5.State                [4]
    6.City                 [5]
    7.Status               [6]
    8.Initial Value        [7]
    */
    //1
    sFilter = "|" + ddlCriteria.selectedIndex + "|";
    //2,3  --Using Ternary operator to check the values condition
    if (ddlCriteria.selectedIndex == 1)  // For Specified NEw ABOs with in a days
        sFilter += (txtNewSpecifiedABOs.value.length <= 1) ? "7" : txtNewSpecifiedABOs.value;
    else if (ddlCriteria.selectedIndex == 5) //For Specified ABO 
        sFilter += txtSpecifyValue.value;
    else //For others
        sFilter += (txtPVRangeFrom.value.length <= 1) ? (isNumeric(txtPVRangeFrom.value)) ? txtPVRangeFrom.value : "0" : txtPVRangeFrom.value;
    sFilter += "|";
    sFilter += (txtPVRangeTo.value.length <= 1) ? (isNumeric(txtPVRangeTo.value)) ? txtPVRangeTo.value : "0" : txtPVRangeTo.value;
    sFilter += "|";
    //4,5
    sFilter += ddlGroupLeaders.options[ddlGroupLeaders.selectedIndex].value + "|" + ddlState.options[ddlState.selectedIndex].value + "|";
    //6,
    sFilter += ddlCity.options[ddlCity.selectedIndex].value + "|";
    //7,8
    sFilter += getCheckedRadio() + "|";
    //Return the value('Filter will take care of SP
    return sFilter;
}
//Get the Radio Button List Value
function getCheckedRadio() 
{
    if (document.getElementById(strcABOStatusOptions).checked) return 1;
    else return 0;
}

/**************************************************************************************************
Retrieve the ABO Number from the Cookies
*/
function fnGetABONumber() 
{
    var objErrorMessage = document.getElementById(strlblSuccess);
    objErrorMessage.innerHTML = "";
    try 
    {
         var SelectedIndex = document.getElementById(strddlCriteria).selectedIndex;
			var StateIndex = document.getElementById(strddlLOSState).selectedIndex;
			var CityIndex = document.getElementById(strddlLOSCity).selectedIndex;
			var hdnFilterString = document.getElementById(strhdnFilterString);
			hdnFilterString.value =""; 
			if(SelectedIndex > 0 || StateIndex > 0 || CityIndex > 0)
			{
				 //Validate the selection criteria
				 var vResult = isValidateFilterCriteria(SelectedIndex);				 
				 if (vResult != null) 
				 {
					  //Bind the error message .
					  objErrorMessage.innerHTML = vResult;
					  return false;
				 }
				 else
				 {  //Append looged in ABO in code behind , and directly get the filter value and highlight
					 hdnFilterString.value = fnFilter();
					 return true;
				 }
			}
			else
			{
				//Read the Leg,Indv and expanded ABOs and assigned the Hidden and there is no filter condition
				//fnReadHighlightABO();
				return true;
			}
         return false;
    }
    catch (err) 
    {
        //Hide the loading info
        return false;
    }
}
function isValidateFilterCriteria(CheckSelectedIndex) { //Validate the filter criteria when display
    try {     
		  if(CheckSelectedIndex == 1) //Check specified days between 1 to 90 , if null by default 7
		  {
				var txtNewSpecifiedABOs = document.getElementById(strtxtNewSpecifiedABOs);
				if(txtNewSpecifiedABOs.value == "" || txtNewSpecifiedABOs.value == null)
				{
					return null;
				}
				else if(!isNumeric(txtNewSpecifiedABOs.value))
				{
					txtNewSpecifiedABOs.value = "";
					txtNewSpecifiedABOs.focus();
					return "Required numeric value";
				}
				else 
				{
					var Days = parseInt(txtNewSpecifiedABOs.value);
					if(Days < 1 || Days > 90)
					{
						txtNewSpecifiedABOs.focus();
						return "Entry days between 1 to 90";
					}
				}
				return null;
		  }
        else if (CheckSelectedIndex == 3) //PV BV validation 
        {
            var txtPVRangeFrom = document.getElementById(strtxtRangeFrom);
            var txtPVRangeTo = document.getElementById(strtxtRangeTo);
            var RangeFrom = 0;
            var RangeTo = 0;
            if (txtPVRangeFrom.value == "") {
                txtPVRangeFrom.focus();
                return "Select PV/BV range";
            }
            //Check range from                 
            if (txtPVRangeFrom.value.match(/^\d+$|^\d+\.\d{2}$/)) {
                RangeFrom = parseFloat(txtPVRangeFrom.value);
                //Check range to 
                if (txtPVRangeTo.value != "") {
                    if (txtPVRangeTo.value.match(/^\d+$|^\d+\.\d{2}$/))
                        RangeTo = parseFloat(txtPVRangeTo.value);
                    else {
                        txtPVRangeTo.focus();
                        return "Required decimal value";
                    }
                }
            }
            else {
                txtPVRangeFrom.focus();
                return "Required decimal value";
            }
            //Check from > To 
            if (RangeFrom > RangeTo && RangeTo != 0) {
                txtPVRangeTo.value = '';
                txtPVRangeTo.focus();
                return "PV/BV Range from-value not greater than to-value";
            }
            if(txtPVRangeFrom.value.length > 11)
				{
					txtPVRangeFrom.focus();
					return "Length not exceeds more than 11 characters.";
				}
				if(txtPVRangeTo.value.length > 11)
				{
					txtPVRangeTo.focus();
					return "Length not exceeds more than 11 characters.";
				}
            return null;
        }
        else if (CheckSelectedIndex == 4) //For the Group leaders
        {
            var ddlGroupLeaders = document.getElementById(strddlGroupLeaders);
            //check the user selected the group leaders
            if (ddlGroupLeaders.selectedIndex == 0) {
                ddlGroupLeaders.focus();
                return "Required to select group leaders";
            }
        }
        else if (CheckSelectedIndex == 9) //For the PVBVHistory
        {
            var ddlpvbvHisMonth = document.getElementById(strddlPVBVHisMon);           
            //check the user selected the group leaders
            if (ddlpvbvHisMonth.selectedIndex == 0) {
                ddlpvbvHisMonth.focus();
                return "Required to select Month";
            }
        }
        else if(CheckSelectedIndex == 5)
        {
		     var txtValue = document.getElementById(strtxtSpecifyValue);
		    if (txtValue.value == "" || txtValue.value == null) 
             {//Check whether the ABO is available in the text box or not.
                 return "Required ABO Number";
             }
             else if(!isNumeric(txtValue.value))
				 {
					txtValue.value = "";
					txtValue.focus();
					return "Required numeric value";
				 }
				 else if(txtValue.value.length > 11)
				 {
					txtValue.focus();
					return "Length not exceeds more than 11 characters.";
				 }
				 else
					return null;
        }
        else if(CheckSelectedIndex == 6)
        {
         /*Added for FPO Report*/
           document.getElementById('errorFromDOB').style.display = 'none';    
          document.getElementById('errorToDOB').style.display = 'none';
        if(document.getElementById(id4).value == "")
        {
        document.getElementById('errorFromDOB').style.display = 'block';
         document.getElementById('errorFromDOB').className = "showmandatory2";
        document.getElementById('errorFromDOB').innerHTML = "From Date is Required";
        document.getElementById(id4).focus();
        return "";
        }
        else if(document.getElementById(id5).value == "")
        {
        document.getElementById('errorToDOB').style.display = 'block';
         document.getElementById('errorToDOB').className = "showmandatory2";
        document.getElementById('errorToDOB').innerHTML = "To Date is Required";
        document.getElementById(id5).focus();
        return "";
        }
        else if (document.getElementById(id4).value != "" && document.getElementById(id5).value != "")
        {
        
          var str1  = document.getElementById(id4).value;
          var str2  = document.getElementById(id5).value;
        var noOfSlash = str1.lastIndexOf("/");
        var yearLength = str1.substring(noOfSlash + 1, str1.length);
        var noOfSlash1 = str2.lastIndexOf("/");
        var yearLength1 = str2.substring(noOfSlash1 + 1, str2.length);
        var regex = /^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((1[9]|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((1[9]|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((1[9]|[2-9]\d)\d{2}))|(29\/02\/((1[9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$/;
        
        var dt1   = parseInt(str1.substring(0,2),10); 
           var mon1  = parseInt(str1.substring(3,5),10);
           var yr1   = parseInt(str1.substring(6,10),10); 
           var date1 = new Date(yr1, mon1, dt1); 
       
        var dt2   = parseInt(str2.substring(0,2),10); 
           var mon2  = parseInt(str2.substring(3,5),10); 
           var yr2   = parseInt(str2.substring(6,10),10); 
           var date2 = new Date(yr2, mon2, dt2); 
       
       
       var PrevSixDate = new Date(); 
       PrevSixDate.subtract("month", 5);
       
            
        if (!regex.test(str1))
         {
         
            document.getElementById(id4).value ="";
            document.getElementById(id4).focus();
             return "Start date is not correct. Please enter date in DD/MM/YYYY format";
            
        }
        else if (!regex.test(str2))
         {
         
            document.getElementById(id5).value ="";
            document.getElementById(id5).focus();
             return "End date is not correct. Please enter date in DD/MM/YYYY format";
            
        }
        else if (yearLength.length < 4) {        
             document.getElementById(id4).value ="";
            document.getElementById(id4).focus();
            return "Start date is not correct. Please enter date in DD/MM/YYYY format";
                 
        }   
         else if (yearLength1.length < 4) {        
             document.getElementById(id5).value ="";
            document.getElementById(id5).focus();
            return "End date is not correct. Please enter date in DD/MM/YYYY format";
                 
        }  
        else if(yearLength<1900)
        {
        
            document.getElementById(id4).value ="";
            document.getElementById(id4).focus();
            return "Please enter a date greater than 1/1/1900";
           
        }
         else if(yearLength1<1900)
        {
        
            document.getElementById(id5).value ="";
            document.getElementById(id5).focus();
            return "Please enter a date greater than 1/1/1900";
           
        }
        else if(date1 > date2)
        {
          return "From date should not be greater than To Date";
            
        }
        else if(date1 < PrevSixDate)
        {
        return "Please enter a date from last 6 months";
        }
        else
        return null;
        
    }
        
        }
        else
            return null;
        return null;
    }
    catch (err) 
    {
        return null;
    }
}



//Checked the checkbox when the time of click
function CheckedDownLine(chkId, chkChecked) 
{
    try {
        var getUserId = "";
        if (chkId.indexOf('chkH') == 0) 
        {//For Single Row
            getUserId = chkId.replace("chkH", ""); //UserID
            if (chkChecked)
                document.getElementById('div' + getUserId).style.backgroundColor = "#ffdda7"; //Activate the color of the div
            else 
                document.getElementById('div' + getUserId).style.backgroundColor = "White";
            return false;
        }
        else //For Total Div activate
            getUserId = chkId.replace("chk", ""); //UserID
        try 
        {
            selall('divH' + getUserId, chkChecked);
            selall('div' + getUserId, chkChecked);
             return false;
        }
        catch (err) 
        {
            selall('div' + getUserId, chkChecked);
             return false;
        }
    }
    catch (err) 
    {
        return false;
    }
}
//Select the Checkbox
function selall(pnlObj, chkVal) {
    try 
    {
        var allcntls = document.getElementById(pnlObj);
        var cntls = allcntls.getElementsByTagName("*");
        var getUserId = "";
        for (i = 0; i < cntls.length; i++) {
            if (cntls[i].type == "checkbox") {
                cntls[i].checked = chkVal; //Activate the Checkbox
                try {
                    getUserId = cntls[i].id.replace("chk", ""); //UserID 
                    if (chkVal) {
                        document.getElementById('div' + getUserId.replace("H", "")).style.backgroundColor = "#ffdda7";
                        document.getElementById('div' + getUserId).style.backgroundColor = "#ffdda7"; //Activate the color of the div
                    }
                    else {
                        document.getElementById('div' + getUserId.replace("H", "")).style.backgroundColor = "White";
                        document.getElementById('div' + getUserId).style.backgroundColor = "White";
                    }
                }
                catch (err) {
                }
            }
        }
        return;
    }
    catch (err) 
    {
        return;
    }
}

function isNumeric(x) {
    // I use this function like this: if (isNumeric(myVar)) { } 
    // regular expression that validates a value is numeric 
    var RegExp = /^[-+]?[0-9]*\.?[0-9]+(?:[eE][-+]?[0-9]+)?$/; // Note: this WILL allow a number that ends in a decimal: -452. 
    // compare the argument to the RegEx 
    // the 'match' function returns 0 if the value didn't match 
    if (x.match(RegExp) == null) return false;
    else return true;
}


function PrinterFriendlyView()
{ 
    try
    {
        var prtContent = document.getElementById(strdivTree); 
        var html = '<HTML><TITLE> Amway India :- LOS </TITLE><HEAD>'; 
	    if (document.getElementsByTagName != null) 
	    { 
		    var headTags = document.getElementsByTagName("head"); 
		    if (headTags.length > 0) html += headTags[0].innerHTML; 
	    } 
		    html += '<style>  '
		    html += '.loschk,.imgExt,.rowDetText,.loschkLeg { float:left; } .loschkLeg { clear:left } .divExtLine{padding-left:22px; background:url(../Images/Common/dot.gif) repeat-y;height:auto;float:left;} '
		    html += ' .tree {	font-family: Verdana;font-size: 6.75pt;white-space: nowrap;}'
		    html += ' .tree img {	border: 0px;vertical-align: text-bottom;float:left;}'
		    html += ' .tree a {color: #000;text-decoration: none;	float:left; }'
		    html += ' .tree a:hover { color: #345373; }'
		    html += ' .loschk {float:left; }'
		    html += ' .loschkLeg { visibility:hidden;float:left; }'
		    html += ' .divLeg { width:100%;float:left;border-bottom:1px solid #b29a75; }'
		    html += ' .rowDet{float:left;margin-left:2px;width:auto;margin-top:3px;}'
		    html += ' .imgPop {padding-left:2px;width:auto;height:auto;cursor:pointer;}'
		    html += ' .divgc{text-align:left;margin-top:10px;float:right;} .imgExt {margin-left:-7px}'
		    html += ' .divExtLineEmpty{margin-left:8px; height:auto;float:left;}'
		    html += ' .divExtLineEmpty .divExtLineEmpty{margin-left:20px;float:none;}'
		    html += ' .divExtLineEmptyInitial {height:auto;float:left;} '
		    html += ' .divExtLine{padding-left:22px; background:url(../Images/Common/dot.gif) repeat-y;height:auto;float:left;}'
		    html += ' .divExtLineAppend { background:url(../Images/Common/dot.gif) repeat-y;height:auto;float:left; }'
		    html += ' .faddr{width:300px;}'
		    html += ' .divExtLineNotAppend {height:auto;float:left;}'
		    html += ' .divExtLineNotAppendLastABO {height:auto;float:left;}'
		    html += ' .rowDet strong{float:left;}'
		    html += ' .rowDetText{float:left;}'
		    html += ' .losdetails{width:100%;}'
		    html += ' .divEnlargeRowLeg .divExtLineAppend{padding-bottom:5px;padding-top:2px; }'
		    html += ' .RowAddDet {padding-top:3px;padding-left:2px;width:auto;position:relative;height:auto;font-family:Verdana;font-size:6.75pt;color:#3366cc;float:left;clear:left;}'
		    //Check if the browser is IE7 append the styles
		    if(BrowserVersion() == "IE7")
		    {
		       html += ' .loschkChild{float:left;margin-right:28px;} '
				 html += ' .imgExt { position:relative;left:-3px !important; }'
				 html += ' .loschkChild { margin-right:8px !important; }' 
				 html += ' .divExtLineEmptyInitial { margin-left:5px; }'
				 html += ' .rowDet { margin-left:0px !important; padding-left:0px !important;}'
				 html += ' .divExtLineNotAppendLastABO {margin-left:0 !important;}'
		    }
		    else if(BrowserVersion() == "IE6")
		    {
			    html += ' .loschkChild{float:left;margin-right:28px;} '
				 html += ' .imgExt { position:relative;left:-3px !important;margin-right:-2px !important; }'
				 html += ' .rowDet { margin-left:0px !important; padding-left:0px !important;}'
		    }
		    else
		    {
				html += ' .divExtLineNotAppendLastABO {margin-left:10px;}'
		    }
		    html += '</style></HEAD><BODY id=\"printbody\">'; 
		      html += '<div style=\"width:2000px;font:6.75pt Verdana;\">' + prtContent.innerHTML + '</div>';
			html += '</BODY></HTML>'; 
			//Open the new window
			var WinPrint = window.open('','','letf=0,top=0,width=1600,height=500000,toolbar=2,scrollbars=1,status=1'); 
			//Write the content
			WinPrint.document.write(html);
         WinPrint.document.close(); 
         WinPrint.focus(); 
         WinPrint.print(); 
         WinPrint.close(); 
    }
    catch(err)
    {
    }
}
//Check the browser version , which browser we are currently using
function BrowserVersion() 
{
	try
	{
		 //For the IE
		 if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
			  var ieversion = new Number(RegExp.$1) // capture x.x portion and store as a number
			  if (ieversion >= 8)       //You're using IE8 or above
					return "IE8";
			  else if (ieversion >= 7)  //You're using IE7.x
					return "IE7";
			  else if (ieversion >= 6) //You're using IE6.x
					return "IE6";
			  else if (ieversion >= 5) //You're using IE5.x
					return "IE5";
			  else
					return "IE0";
		 }
		 else if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)) //For Mozilla
		 { //test for Firefox/x.x or Firefox x.x (ignoring remaining digits);
			  var ffversion = new Number(RegExp.$1) // capture x.x portion and store as a number
			  if (ffversion >= 3) //You're using FF 3.x or above
					return "FF3";
			  else if (ffversion >= 2) //You're using FF 2.x
					return "FF2";
			  else if (ffversion >= 1) //You're using FF 1.x
					return "FF1";
			  else
					return "FF0";
		 }
		 else
			  return null;
	 }
	 catch(err)
	 {
		return null;
	 }
}
function fnHideActiveCheckBox() {
    try 
    {
        document.getElementById("divHideFilter").style.display = 'none';
        return true;
    }
    catch (err) {
        return;
    }
}
//Read the Leg , Indv and expand ABO and assigned the Hidden 
function fnReadHighlightABO() 
{
    try 
    {
			var theJoin = null;
        //Here first we select only the selected leg in the LOS and then export
        var allcntls = document.getElementById(strdivTree);
        //Leg ABO
        var hdnMainLeg = document.getElementById(strhdnMainLeg); 
        //Indv ABO
        var hdnFilterABONumber =document.getElementById(strhdnFilterABONumber); 
        //Expand ABO
        var hdnExpandABO = document.getElementById(strhdnExpandABO);
        //All controls 
        var cntls = allcntls.getElementsByTagName("*");
        var UserID = "";
        var getUserId = "";
        var ControlLength = cntls.length;
        var sMainLeg = "";
        var sExpandABO = "";
        var objControl = null;
        for (i = 0; i < ControlLength; i++) 
        {//Check the control is chkbox
				objControl = cntls[i];
            if (objControl.type == "checkbox") 
            {//if the checkbox is not a header , then true
                if (objControl.checked) //Onlu active Checkbox
                {
                    UserID = objControl.id;
                    if (UserID.indexOf('chkH') != -1)//Select the individual ABO , and assigned.
                    {
                         getUserId += UserID.replace("chkH", "") + ',';
                    }
                    else if (UserID.indexOf('chk') != -1)//Select the Main Leg ABO , and assigned.
                    {
                        sMainLeg += UserID.replace("chk", "") + ','; 
                    }
                }
            }
            else if (objControl.id.indexOf('join') != -1 && objControl.alt.indexOf('Collapse') != -1)//Select the individual ABO , and assigned.
            {
					 sExpandABO += objControl.id.replace("join", "") + ','; 
            }
        }
        if (getUserId.length > 1) 
        {
            hdnFilterABONumber.value = getUserId;
            hdnMainLeg.value = sMainLeg;
            hdnExpandABO.value = sExpandABO;
            return true;
        }
        else
         {
            hdnFilterABONumber.value = "";
            hdnMainLeg.value.value = "";
            hdnExpandABO.value = "";
            return false;
        }
    }
    catch (err) 
    {
         return false;
    }
}
//If we need what are all IDs are selected in the LOS  and also append the previous filter, Call the function and get the ID from  document.getElementById(strhdnFilterABONumber)
function fnExportABoNumber() 
{
    try {
        //Here first we select only the selected leg in the LOS and then export
        var allcntls = document.getElementById(strdivTree);
        var cntls = allcntls.getElementsByTagName("*");
        var UserID = "";
        var getUserId = "";
        var ControlLength = cntls.length;
        var sMainLeg = "";
        var objControl = null;
        for (i = 0; i < ControlLength; i++) 
        {//Check the control is chkbox
				objControl = cntls[i];
            if (objControl.type == "checkbox") 
            {//if the checkbox is not a header , then true
                if (objControl.checked) //Onlu active Checkbox
                {
                    UserID = objControl.id;
                    if (UserID.indexOf('chkH') != -1)//Select the individual ABO , and assigned.
                    {
                         getUserId += UserID.replace("chkH", "") + ','; ;
                    }
                    else if (UserID.indexOf('chk') != -1)//Select the Main Leg ABO , and assigned.
                    {
                        sMainLeg += UserID.replace("chk", "") + ','; ;
                    }
                }
            }
        }
        if (getUserId.length > 1) 
        {
            document.getElementById(strhdnFilterABONumber).value = getUserId;
            document.getElementById(strhdnMainLeg).value = sMainLeg;
            return true;
        }
        else
         {
            document.getElementById(strlblSuccess).innerHTML = "Select atleast one ABO";
            document.getElementById(strhdnFilterABONumber).value = "";
            document.getElementById(strhdnMainLeg).value = "";
            return false;
        }
    }
    catch (err) 
    {
        return false;
    }
}


//Hide the Active/Inactive Control based on the selection criteria process
function fnFilterControlHide(HideControl, EventControl) 
{

    try {
        document.getElementById(strlblSuccess).innerHTML = "";
        var EventFireControlIndex = document.getElementById(EventControl).selectedIndex;       
        ViewControls();
        if (EventFireControlIndex == 1) {
            document.getElementById(strdivNewSpecifiedABOs).style.display = 'block';
            document.getElementById(strdivFPOFilters).style.display = 'none';
            document.getElementById(strtxtNewSpecifiedABOs).focus();
            document.getElementById(strdivPVBVHisMon).style.display = 'none'; 
        }
        else if (EventFireControlIndex == 2) {
            //document.getElementById(HideControl).style.display = "none";
            document.getElementById(strdivFPOFilters).style.display = 'none';
            document.getElementById(strddlLOSState).focus();
            document.getElementById(strdivPVBVHisMon).style.display = 'none'; 
        }
        else if (EventFireControlIndex == 4) {
            document.getElementById(strdivGroupLeaders).style.display = 'block';
            document.getElementById(strdivFPOFilters).style.display = 'none';
            document.getElementById(strdivPVBVHisMon).style.display = 'none'; 
            document.getElementById(strddlGroupLeaders).focus();
        }
        else if (EventFireControlIndex == 5) {//Hide all the divs
            //document.getElementById(HideControl).style.display = 'none';
      
            document.getElementById(strdivSpecifyValue).style.display = '';
            document.getElementById(strdivFPOFilters).style.display = 'none';
            document.getElementById(strdivSpecificABO).style.display = 'none';
            document.getElementById(strdivSpecificABO1).style.display = 'none';
            document.getElementById(strdivPVBVHisMon).style.display = 'none'; 
            document.getElementById(strtxtSpecifyValue).focus();
        }
        // Newly added code FPO
        else if (EventFireControlIndex == 6) {//Hide all the divs
            //document.getElementById(HideControl).style.display = 'none';
            document.getElementById(strdivFPOFilters).style.display = 'block';
            document.getElementById(strdivFPOFilters).style.visibility = 'visible';
            document.getElementById(strdivSpecificABO).style.display = 'none';
            document.getElementById(strdivSpecificABO1).style.display = 'none';
            document.getElementById(strdivPVBVHisMon).style.display = 'none'; 
            document.getElementById('divFPOFilter').focus();
            
            // strt
            var MinusDays=-30;
       var CurrentDate= new Date();          
        var Day =  CurrentDate.getDate();
         if(Day <10)
            {
            Day="0"+Day;
            }
            var Year =  CurrentDate.getFullYear();
            var Month = CurrentDate.getMonth()+1;// because months in JS start with 0  
            if(Month <10)
            {
            Month="0"+Month;
            }
            var VarValidDate=Day + "/" + Month + "/" + Year;  
           
           var prevDate=new Date(CurrentDate.getTime() + MinusDays*24*60*60*1000);
            var PrevDay =  prevDate.getDate();
         if(PrevDay <10)
            {
            PrevDay="0"+PrevDay;
            }
            var PrevYear =  prevDate.getFullYear();
            var PrevMonth = prevDate.getMonth()+1;// because months in JS start with 0  
            if(PrevMonth <10)
            {
            PrevMonth="0"+PrevMonth;
            }
            var VarValidPrevMonth=PrevDay + "/" + PrevMonth + "/" + PrevYear;  
    
           document.getElementById(id4).value = VarValidPrevMonth;
           document.getElementById(id5).value = VarValidDate;
     
            
        }
        else if (EventFireControlIndex == 0) {
        document.getElementById(strdivFPOFilters).style.display = 'none';
        document.getElementById(strdivPVBVHisMon).style.display = 'none'; 
            document.getElementById(strddlLOSState).focus();
            return;
        }
         //Condition code for Renewal Eligible selection & Address Proof Not Submitted - Starts
          else if (EventFireControlIndex == 7 || EventFireControlIndex == 8) {
              document.getElementById(strdivPVBVHisMon).style.display = 'none'; 
              document.getElementById(strdivPVBVRanges).style.display = 'none';
              if (EventFireControlIndex == 7)
                document.getElementById(strdivHideFilter).style.display = 'none'; 
              document.getElementById(strdivFPOFilters).style.display = 'none'; 
              document.getElementById(strdivSpecificABO).style.display = 'none';
              document.getElementById(strdivSpecificABO1).style.display = 'none';                          
              return;
        }
         //Condition code for Renewal Eligible selection & Address Proof Not Submitted - Starts
          else if (EventFireControlIndex == 9) {          
              document.getElementById(strdivPVBVHisMon).style.display = 'block'; 
              document.getElementById(strdivPVBVRanges).style.display = 'none';             
              document.getElementById(strdivFPOFilters).style.display = 'none'; 
              document.getElementById(strdivSpecificABO).style.display = 'none';
              document.getElementById(strdivSpecificABO1).style.display = 'none';                          
              return;
        }
        //Condition code for Renewal Eligible selection & Address Proof Not Submitted - Ends
        else {//PV/BV Ranges
        document.getElementById(strdivFPOFilters).style.display = 'none';
            document.getElementById(strdivPVBVRanges).style.display = '';
            document.getElementById(strtxtRangeFrom).focus();
            document.getElementById(strdivPVBVHisMon).style.display = 'none'; 
        }
    }
    catch (err) {
        //Hide the loading info
        return;
    }
}


////Selected ABO number for the renewal
function fnRenewal() 
{
    try {
        //Catch the Main Div Obj and check
        var allcntls = document.getElementById(strdivTree);
        var cntls = allcntls.getElementsByTagName("*");
        var getUserId = "";
        for (i = 0; i < cntls.length; i++) {//Check the control is chkbox
            if (cntls[i].type == "checkbox") {//if the checkbox is not a header , then true
                if (cntls[i].checked) //Only active Checkbox
                {
                    if (cntls[i].id.indexOf('chkH') != -1)//false
                        getUserId += cntls[i].id.replace("chkH", "") + ',';
                }
            }
        }
        //Here we redirect to renewal page to auto renewal the ABO's          
        location.replace('../Users/Renewal.aspx?rl=' + getUserId);
        return false;
    }
    catch (err) {
        return false;
    }
}


// Opens or closes a node
function ocEC(node, bottom) 
{
	try
	{
	   var icons = new Array(6);
	   icons[0] = new Image();
	   icons[0].src = "../Images/Common/minus.gif";
	   icons[1] = new Image();
	   icons[1].src = "../Images/Common/plus.gif";
		var theDiv = document.getElementById("divH" + node);
		var theJoin	= document.getElementById("join" + node);
		if (theDiv.style.display == 'none') 
		{
			theJoin.src = icons[0].src;
			theDiv.style.display = '';
			theJoin.alt = "Collapse";
		} 
		else 
		{
			theJoin.src = icons[1].src;
			theDiv.style.display = 'none';
			theJoin.alt = "Expand";
		}
	}
	catch(err)
	{
		return;
	}
}

/*Added for FPO Report*/
function isDOB(e, id) {
    var key_code = (window.event) ? event.keyCode : e.which;
    document.getElementById(id).style.color = 'Black';
    if ((key_code > 47 && key_code < 58)) {
        return true;
    }
    else if ((key_code == 8 || key_code == 0 || key_code == 47)) {
        return true;
    }
    else {
        return false;
    }

}


/*Added for FPO Report*/

 Date.prototype.subtract = function( unit, value ) {   
  
   unit = unit.replace( /s$/ ).toLowerCase();   
  
   switch ( unit ) {   
      case "year":   
         this.setYear( this.getYear() - value );   
         break;   
      case "month":   
         this.setMonth( this.getMonth() - value );   
//         alert(this.setMonth( this.getMonth() - value));
         break;   
      case "week":   
         this.setTime( this.getTime() - value * 604800000 );   
         break;   
      case "day":   
         this.setTime( this.getTime() - value * 86400000 );   
         break;   
      case "hour":   
         this.setTime( this.getTime() - value * 3600000 );   
         break;   
      case "minute":   
         this.setTime( this.getTime() - value * 60000 );   
         break;   
      case "second":   
         this.setTime( this.getTime() - value * 1000 );   
         break;   
      case "nanosecond":   
         // Fall Through   
      default:   
         this.setTime( this.getTime() - value );   
         break;   
   }   
}; 