    var aAllCountryCheckboxes = new Array();
    var sCountryList;
    var sTypeofCall;
    var sTotalEconomySel = ""; 
    var sSetOnload = "0";
	 
function showEconomyList(index)
{
    var divEconomygrp = $$('div.economygrp');
    // ***  To display all Countries when Show All link is clicked
    if (index == 'all')
    {
        if(document.getElementById("economyLst").className == 'hidden' || document.getElementById("economyLst").className !='')
            showHide("economyLst", "show");
        else
            showHide("economyLst", "hide");
            
        divEconomygrp.each(function(varEconomygrpblock)
        {       
                varEconomygrpblock.style.display = 'block';
        }); 
    }
    else
    {        
        showHide("economyLst", "show");
        
        divEconomygrp.each(function(varEconomygrpnone)
        {       
                varEconomygrpnone.style.display = 'none';
        });
               
        document.getElementById('selectEconomy'+index).style.display = 'block';        
    }
}

	function AllCountries_OnClick()
	{
		 GetDataCountry('GetCountryDataInfo.ashx?Region=&InComeId=', CountryLstHandler);
	}
	
	function Window_OnLoad()
	{	
	    AllCountries_OnClick();	
	    //sSetOnload = "0";
	}
    //if (sSetOnload == '1')
	  
	
    // **  Handler when Region (or Income) checkbox is clicked 
    function CountryGrouping_OnClick(checkboxes, TypeofCall)
    {	
        var acheckboxes = new Array();	    
        acheckboxes = checkboxes.split(',');	    
        var iLength = acheckboxes.length;
        var IsChecked = document.getElementById(TypeofCall + acheckboxes[0]).checked;	    			
        for (var i = 1; i < iLength-1; i++)
        {		    		    		
            if (document.getElementById(acheckboxes[i]).value != null)
            {
	            document.getElementById(acheckboxes[i]).checked=IsChecked; 
	            // Build stream of countries here
	            if (IsChecked == true)
	                sTotalEconomySel = sTotalEconomySel + "," + (acheckboxes[i]).substring(9) + " ";
	            else
	                sTotalEconomySel = sTotalEconomySel.replace("," + (acheckboxes[i]).substring(9)+ " ", ""); 
	        }
        }
        return true;
    }	
	
	function updateCheckboxes(aCheckboxes,  bIsChecked)
	{
	for (var i = 0; i < aCheckboxes.length ; i++)
		{		    		    
		    if (document.getElementById(aCheckboxes[i]).value!=null)
		    {
			    document.getElementById(aCheckboxes[i]).checked=bIsChecked; 
			}
		}	
	}
	
	function cbRegion_OnClick(cbCountry)
	{
	    sTypeofCall = "";
	    sTypeofCall = "cbRegion";
	    GetDataCountry('GetCountryDataInfo.ashx?Region=' + (cbCountry.id).substring(8) + "&InComeId=", CntyHandler);	    
	}
	
function GetDataCountry(url, responseHandler)   
 {   
     if (window.XMLHttpRequest)   
      {   
          // browser has native support for XMLHttpRequest object   
          req = new XMLHttpRequest();   
      }   
      else if (window.ActiveXObject)   
      {   
         // try XMLHTTP ActiveX (Internet Explorer) version   
         req = new ActiveXObject("Microsoft.XMLHTTP");   
      }   
      if(req)   
      {   
          req.onreadystatechange = responseHandler;   
          req.open('GET', url, true);             
          req.setRequestHeader("content-type","application/x-www-form-urlencoded");   
          req.send('');   
      }   
      else  
      {   
          alert('Your browser does not seem to support XMLHttpRequest.');   
      }   
}    

    function CountryLstHandler()   
    {   
     //readyState of 4 or 'complete' represents    
     //that data has been returned    
         if (req.readyState == 4 || req.readyState == 'complete')   
         {            
             var aAllCountryCheckboxes = new Array();
             var sCntyCheckbox = req.responseText; 
             if (sCntyCheckbox == 'error')
             {
                window.location = '/error.aspx';
             }
             else
             {    
                 var aCntyCheckbox = sCntyCheckbox.split(",");
                 //var bIsChecked = document.getElementById("rbShowAll").checked;             
                 var bIsChecked = false;
                 
                 for (var i = 0; i < aCntyCheckbox.length-1; i++)
                 {		    		    
                    var ctlCntry = $(aCntyCheckbox[i]);
                    if (ctlCntry.value != null)
                    {
                        ctlCntry.checked=bIsChecked; 
                        window.aAllCountryCheckboxes[i] = aCntyCheckbox[i];			 
                    }
                 }                 
             }		    
         }            
    }    

    function CntyHandler()   
    {   
         //readyState of 4 or 'complete' represents    
         //that data has been returned    
         if (req.readyState == 4 || req.readyState == 'complete')   
         { 
            if (sTotalEconomySel == undefined)
                sTotalEconomySel = "";
            //Exception handling for ashx page           
            if(req.responseText == 'error')
            {
               window.location = '/error.aspx'; 
            }
            else
            {
                CountryGrouping_OnClick(req.responseText, sTypeofCall); 
            }
         }            
    }
    
    /*   Search Query    */    
	function btnWebReport_OnClick()
	{	
	    var iLength = aAllCountryCheckboxes.length;
	    var aSectorCheckboxes = new Array("1","2","3","4","5","6");
	    var aRegionCheckboxes = new Array("1","2","3","4","6","7");
    	
	    var sCountryList = "";
	    var sSectorList = "";
	    var sRegionList = "";
	    var boolChk = false;
	    var iYearFrom = document.getElementById('ddYearFrom').value;
	    var iYearTo = document.getElementById('ddYearTo').value;
	    
	    if (iYearTo <= iYearFrom)
	    {
	        alert("Year(From) cannot be greater than Year(To). Please check Year !");
	        boolChk = true;
	        return false;
	    }
	    if (boolChk == false)
	    {
	        for (var i = 0; i < iLength; i++)
	        {	    
		        if (document.getElementById(aAllCountryCheckboxes[i]).checked == true)
			        sCountryList += document.getElementById(aAllCountryCheckboxes[i]).value + ", ";	         
	        }
        		
	        if (sCountryList.length > 0)
		        sCountryList = sCountryList.substring(0, sCountryList.length - 2);
        	
	        document.getElementById('hsCountry').value = sCountryList;
    	    
	        //  For Regions as selected     ********
	         for (var i = 0; i < aRegionCheckboxes.length; i++)
	        {	
		        if (document.getElementById("cbRegion" + aRegionCheckboxes[i]).checked == true)
			        sRegionList += document.getElementById("cbRegion" + aRegionCheckboxes[i]).value + ", ";		
	        }
        	
	        if (sRegionList.length > 0)
		        sRegionList = sRegionList.substring(0, sRegionList.length - 2);
    		    
    	    // For Sectors as selected	    ********
	        for (var i = 0; i < aSectorCheckboxes.length; i++)
	        {	
		        if (document.getElementById("cbSector" + aSectorCheckboxes[i]).checked == true)
			        sSectorList += document.getElementById("cbSector" + aSectorCheckboxes[i]).value + ", ";		
	        }
        	
	        if (sSectorList.length > 0)
		        sSectorList = sSectorList.substring(0, sSectorList.length - 2);
        		
	        document.getElementById('hsSector').value = sSectorList; 
	        document.getElementById('hsRegion').value = sRegionList;
            document.getElementById('hsYearFrom').value = iYearFrom ;
            document.getElementById('hsYearTo').value = iYearTo; 
        }
        
        //GetQueryResults('GetQueryResults.ashx?sect='+sSectorList + '&yrFrom=' + document.getElementById('ddYearFrom').value + '&yrTo=' + document.getElementById('ddYearTo').value + '&cnty=' + sCountryList, OutputHandler);		 
	}	
	    
    function GetQueryResults(url, responseHandler) 
    {    
         if (window.XMLHttpRequest)   
          {   
              // browser has native support for XMLHttpRequest object   
              req = new XMLHttpRequest();   
          }   
          else if (window.ActiveXObject)   
          {   
             // try XMLHTTP ActiveX (Internet Explorer) version   
             req = new ActiveXObject("Microsoft.XMLHTTP");   
          }   
             
          if(req)   
          {   
              req.onreadystatechange = responseHandler;   
              req.open('POST', url, true);             
              req.setRequestHeader("content-type","application/x-www-form-urlencoded");   
              req.send('');   
          }   
          else  
          {   
              alert('Your browser does not seem to support XMLHttpRequest.');   
          }   
    }
    
    function OutputHandler()   
    {   
     // readyState of 4 or 'complete' represents that data has been returned    
     if (req.readyState == 4 || req.readyState == 'complete')   
        {            
            // ***  Get the results to the <dvResult> section
            $('mainData').innerHTML = req.responseText; 
        }            
    }
    /*   Till here  - Search Query    */
    
    /*  Radio button click for Proceeds or Transactions      */ 
    function getQuery(typeofcall)
    {
        var strTypeofcall = typeofcall.value;
        var strRegionList;
        var strCountryList;
        var strYearFrom;
        var strYearTo;
        strRegionList = document.getElementById('hsRegion').value;
        strCountryList= document.getElementById('hsCountry').value;
        strYearFrom= document.getElementById('hsYearFrom').value;
        strYearTo= document.getElementById('hsYearTo').value;
            
        // ***  To display querry results when Transactions radio button is clicked
        if (strTypeofcall == 'T')
        {
            strRegionList = document.getElementById('hsRegion').value;
            strCountryList= document.getElementById('hsCountry').value;
            strYearFrom= document.getElementById('hsYearFrom').value;
            strYearTo= document.getElementById('hsYearTo').value;
            
            //GetQueryResults('GetQueryResults.ashx?sect='+sSectorList + '&yrFrom=' + document.getElementById('ddYearFrom').value + '&yrTo=' + document.getElementById('ddYearTo').value + '&cnty=' + sCountryList, OutputHandler);		 
            GetQueryResults('GetQueryResults.ashx?rid='+strRegionList + '&type=' + strTypeofcall, OutputHandler);
        
        }
        
        else if (strTypeofcall == 'P')
        {
        
        }
    
    
    }
    
    function getQueryType(typeofid, id, type)
    {
        if(typeofid == 'rid')
            GetQueryResults('GetQueryResults.ashx?rid='+id + '&type=' + type, OutputHandler);
        else
            GetQueryResults('GetQueryResults.ashx?sid='+id + '&type=' + type, OutputHandler);
    }
     /*   Till here  - Radio button click for Proceeds or Transactions    */
     
     
    function cbAllSectors_OnClick()
	{
		var aSectorCheckboxes = new Array("cbSector1", "cbSector2", "cbSector3",
			"cbSector4", "cbSector5", "cbSector6");

		for (var i = 0; i < aSectorCheckboxes.length ; i++)
		{		    		    
		    if (document.getElementById(aSectorCheckboxes[i]).value!=null)
		    {
			    document.getElementById(aSectorCheckboxes[i]).checked=document.getElementById("cbAllSectors").checked; 
			}
		}
	}
 
 
/*--------------------------------------------------------
	showHide(id)
	This function hides or displays the contents of a given tag.
	Such tag must have the attribute 'expanded'.
--------------------------------------------------------*/
function showHide(id)
{
    var expandableSection = document.getElementById(id);
    if (root.getAttribute("expanded") == "no")
        _show(expandableSection);
    else
        _hide(expandableSection);
}
/*--------------------------------------------------------
	showHide(id, cmd)
	This function implements the show and hide commands
	to hide or display the contents of a given tag.
	Such tag must have the attribute 'expanded'.
--------------------------------------------------------*/
function showHide(id, cmd)
{
    var expandableSection = document.getElementById(id);
    if (cmd == "show")
        _show(expandableSection);
    else
        _hide(expandableSection);
}

/*--------------------------------------------------------
	_show(tag)
	Removes the hidden class from the tag's class list 
	and sets its expanded attribute to 'yes'
--------------------------------------------------------*/
function _show(tag)
{
    removeElementFromClass(tag, "hidden");
    //tag.className = '';
    tag.setAttribute("expanded", "yes");
}
/*--------------------------------------------------------
	_hide(tag)
	Adds the hidden class to the tag's class list 
	and sets its expanded attribute to 'no'
--------------------------------------------------------*/
function _hide(tag)
{
    addElementToClass(tag, "hidden");
    //tag.className = "hidden";
    tag.setAttribute("expanded", "no");
}
//--------------------------------------------------------//

