function getRequests()
{
        var request = false;
        
        try
        {
                request = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(Ex)
        {
                try
                {
                        request = new ActiveXObject("Microsoft.XMLHTTP");       
                }
                catch(Ex1)
                {
                        request = false;
                }
        }
        
        if(!request && typeof XMLHttpRequest != 'undefined')
        {
                request = new XMLHttpRequest();
        }
        
        return request;
}
	
	
function getDistricts()
{
		var jsonrpc = null;
		
		if(jsonrpc == null)
		{
			jsonrpc= new JSONRpcClient("/eservices/JSON-RPC");
		}
		
		var Districts = jsonrpc.district.DistrictCombo();
		
		return Districts;
			
}

function getRel(cert)
{
		var jsonrpc = null;
		
		if(jsonrpc == null)
		{
			jsonrpc= new JSONRpcClient("/eservices/JSON-RPC");
		}
		
		var Relations;
		
		if(cert == "birth")
		{
			Relations = jsonrpc.relation.birthRelations();
		}
		if(cert == "death")
		{
			Relations = jsonrpc.relation.deathRelations();
		}
		if(cert == "common")
		{
			Relations = jsonrpc.relation.commonRelations();
		}
		
		return Relations;
}

function gettpTaluks(distcode)	
{
	var jsonrpc =null;
	if(jsonrpc==null)
	{
	jsonrpc= new JSONRpcClient("/eservices/JSON-RPC");
	}
	var talukResult = jsonrpc.taluk.townOptions(distcode);		
	
	var talId = document.getElementById("taluk");
	
	for(i = talId.options.length - 1; i > 0; i--)
	{
		talId.options[i] = null;
	}
	
	for(i = 0; i < talukResult['list'].length; i++)
	{
		var id = talukResult['list'][i]['pvcode'];
		var name = talukResult['list'][i]['pvname'];
		talId.options[i + 1] = new Option(name, id);		
	}
	
}

function getmnTaluks(distcode)	
{
	var jsonrpc =null;
	if(jsonrpc==null)
	{
	jsonrpc= new JSONRpcClient("/eservices/JSON-RPC");
	}
	var talukResult = jsonrpc.taluk.townOptions(distcode);		
	
	var talId = document.getElementById("taluk");
	
	for(i = talId.options.length - 1; i > 0; i--)
	{
		talId.options[i] = null;
	}
	
	for(i = 0; i < talukResult['list'].length; i++)
	{
		var id = talukResult['list'][i]['mcode'];
		var name = talukResult['list'][i]['mname'];
		talId.options[i + 1] = new Option(name, id);		
	}
	
}

function getAdTaluks(distcode)	
{
	var jsonrpc =null;
	if(jsonrpc==null)
	{
	jsonrpc= new JSONRpcClient("/eservices/JSON-RPC");
	}
	//alert(document.getElementById("role").value);
	if(document.getElementById("role").value=='RLU')
	{
		var talukResult = jsonrpc.talukRdo.loadTalukRDO(distcode);
	}else{
		var talukResult = jsonrpc.taluk.TalukCombo(distcode);	
	}
	var talId = document.getElementById("taluk");
	
	
	for(i = talId.options.length - 1; i > 0; i--)
	{
		talId.options[i] = null;
	}
	
	for(i = 0; i < talukResult['list'].length; i++)
	{
		var id = talukResult['list'][i]['talukCode'];
		var name = talukResult['list'][i]['talukName'];
		talId.options[i + 1] = new Option(name, id);		
	}
	
}


	
function getTaluks(distcode)	
{
	var jsonrpc =null;
	if(jsonrpc==null)
	{
	jsonrpc= new JSONRpcClient("/eservices/JSON-RPC");
	}
	var talukResult = jsonrpc.taluk.TalukCombo(distcode);		
	
	var talId = document.getElementById("taluk");
	
	for(i = talId.options.length - 1; i > 0; i--)
	{
		talId.options[i] = null;
	}
	
	for(i = 0; i < talukResult['list'].length; i++)
	{
		var id = talukResult['list'][i]['talukCode'];
		var name = talukResult['list'][i]['talukName'];
		talId.options[i + 1] = new Option(name, id);		
	}
	
}

function getTaluksTamil(distcode)	
{	
	var jsonrpc =null;
	if(jsonrpc==null)
	{
	jsonrpc= new JSONRpcClient("/eservices/JSON-RPC");
	}
	var talukResult = jsonrpc.taluk.TalukCombo(distcode);		
	
	var talId = document.getElementById("taluk");
	
	for(i = talId.options.length - 1; i > 0; i--)
	{
		talId.options[i] = null;
	}
	
	for(i = 0; i < talukResult['list'].length; i++)
	{
		var id = talukResult['list'][i]['talukCode'];
		var name = talukResult['list'][i]['talukTname'];		
		talId.options[i + 1] = new Option(name, id);		
	}
	
}

function getTaluksUnicode(distcode)	
{	
	var jsonrpc =null;
	if(jsonrpc==null)
	{
	jsonrpc= new JSONRpcClient("/eservices/JSON-RPC");
	}
	var talukResult = jsonrpc.taluk.TalukCombo(distcode);		
	
	var talId = document.getElementById("taluk");
	
	for(i = talId.options.length - 1; i > 0; i--)
	{
		talId.options[i] = null;
	}
	
	for(i = 0; i < talukResult['list'].length; i++)
	{
		var id = talukResult['list'][i]['talukCode'];
		var name = talukResult['list'][i]['talukTname'];		
		talId.options[i + 1] = new Option(name, id);		
	}
	
}
	
	
function getVillages(talukcode)
{	

	var villId = document.getElementById("village");
	for(i = villId.options.length - 1; i > 0; i--)
    {
            villId.options[i] = null;
    }

	var jsonrpc =null;
	if(jsonrpc==null)
	{
	jsonrpc= new JSONRpcClient("/eservices/JSON-RPC");
	}

	var districtcode=document.form1.district.value;
	
	var villageResult = jsonrpc.village.VillageCombo(districtcode, talukcode);
	
	
	for(i = 0; i < villageResult['list'].length; i++)
	{
		var id = villageResult['list'][i]['villageCode'];
		var name = villageResult['list'][i]['villageName'];
		villId.options[i + 1] = new Option(name, id);		
	}
	/*var vID = document.getElementById('village');    
    for(i = vID.options.length - 1; i > 0; i--)
    {
            vID.options[i] = null;
    }
		
	var districtCode = document.form1.district.value;	
	var url = "/eservices/VillageServlet?districtCode=" + districtCode +"&talukCode=" + talukcode;
       
    var HttpRequest = getRequests();
    HttpRequest.open("GET", url, true);
    HttpRequest.onreadystatechange = function()
    {
            getVillageNames(HttpRequest);
    }
    HttpRequest.send(null);*/
	
}    
function getVillageNames(HttpRequest)
{
    
        if(HttpRequest.readyState == 4)
        {        		
                if(HttpRequest.status == 200)
                {
                        
                        var data = HttpRequest.responseXML.getElementsByTagName('data')[0];    // get Root tag   
                        var flag = data.getElementsByTagName('flag')[0].firstChild.nodeValue;  // get Child tag of 'data' 
         				     
                        var vCode = new Array();
                        var vName = new Array();
                        var vID = document.getElementById('village');
                        if(flag == 'false')
                        {
                                for(i = vID.options.length - 1; i > 0; i--)
                                {
                                        vID.options[i] = null;
                                }
                        }
                        else
                        {
                                for(i = vID.options.length - 1; i > 0; i--)
                                {
                                        vID.options[i] = null;
                                }
                        
                                var records = data.getElementsByTagName('records'); //get Child tag 'records' of the Root tag 'data';
                                for(i = 0; i < records.length; i++)  // i = 0 to length of the Child tags... 
                                {
                                        var villageCode = records[i].getElementsByTagName('villageCode')[0].firstChild.nodeValue; // get the value of child of records
                                        var villageName = records[i].getElementsByTagName('villageEName')[0].firstChild.nodeValue; // get the value of child of records
                                        
                                        vCode[i] = villageCode; 
                                        vName[i] = villageName; 
                                }
                                for(i = 0; i < vCode.length; i++)
                                {                                     
									var id = vCode[i];
									var name = vName[i];
									vID.options[i + 1] = new Option(name, id);
                                }
                                
                        }
                        
                }
                
        }
        
}

function getVillagesTamil(talukcode)
{	

	var villId = document.getElementById("village");
	
	for(i = villId.options.length - 1; i > 0; i--)
    {
            villId.options[i] = null;
    }
    
	var jsonrpc =null;
	if(jsonrpc==null)
	{
	jsonrpc= new JSONRpcClient("/eservices/JSON-RPC");
	}

	var districtcode=document.form1.district.value;
	
	var villageResult = jsonrpc.village.VillageCombo(districtcode, talukcode);
	
	
	
	for(i = 0; i < villageResult['list'].length; i++)
	{
		var id = villageResult['list'][i]['villageCode'];
		var name = villageResult['list'][i]['villageTname'];
		villId.options[i + 1] = new Option(name, id);		
	}
	/*var vID = document.getElementById('village');    
    for(i = vID.options.length - 1; i > 0; i--)
    {
            vID.options[i] = null;
    }
		
	var districtCode = document.form1.district.value;	
	var url = "/eservices/VillageServlet?districtCode=" + districtCode +"&talukCode=" + talukcode;
       
    var HttpRequest = getRequests();
    HttpRequest.open("GET", url, true);
    HttpRequest.onreadystatechange = function()
    {
            getVillageTamilNames(HttpRequest);
    }
    HttpRequest.send(null);*/
	
}    
function getVillageTamilNames(HttpRequest)
{
    
        if(HttpRequest.readyState == 4)
        {        		
                if(HttpRequest.status == 200)
                {
                        
                        var data = HttpRequest.responseXML.getElementsByTagName('data')[0];    // get Root tag   
                        var flag = data.getElementsByTagName('flag')[0].firstChild.nodeValue;  // get Child tag of 'data' 
         				     
                        var vCode = new Array();
                        var vName = new Array();
                        var vID = document.getElementById('village');
                        if(flag == 'false')
                        {
                                for(i = vID.options.length - 1; i > 0; i--)
                                {
                                        vID.options[i] = null;
                                }
                        }
                        else
                        {
                                for(i = vID.options.length - 1; i > 0; i--)
                                {
                                        vID.options[i] = null;
                                }
                        
                                var records = data.getElementsByTagName('records'); //get Child tag 'records' of the Root tag 'data';
                                for(i = 0; i < records.length; i++)  // i = 0 to length of the Child tags... 
                                {
                                        var villageCode = records[i].getElementsByTagName('villageCode')[0].firstChild.nodeValue; // get the value of child of records
                                        var villageName = records[i].getElementsByTagName('villageTName')[0].firstChild.nodeValue; // get the value of child of records
                                        
                                        vCode[i] = villageCode; 
                                        vName[i] = villageName; 
                                }
                                for(i = 0; i < vCode.length; i++)
                                {                                     
									var id = vCode[i];
									var name = vName[i];
									vID.options[i + 1] = new Option(name, id);
                                }
                                
                        }
                        
                }
                
        }
        
}
	
function getVillagesUnicode(talukcode)
{	

	var villId = document.getElementById("village");
	
	for(i = villId.options.length - 1; i > 0; i--)
    {
            villId.options[i] = null;
    }
    
	var jsonrpc =null;
	if(jsonrpc==null)
	{
	jsonrpc= new JSONRpcClient("/eservices/JSON-RPC");
	}

	var districtcode=document.form1.district.value;
	
	var villageResult = jsonrpc.village.VillageCombo(districtcode, talukcode);
	
	
	
	for(i = 0; i < villageResult['list'].length; i++)
	{
		var id = villageResult['list'][i]['villageCode'];
		var name = villageResult['list'][i]['villageTname'];
		villId.options[i + 1] = new Option(name, id);		
	}
	/*var vID = document.getElementById('village');    
    for(i = vID.options.length - 1; i > 0; i--)
    {
            vID.options[i] = null;
    }
		
	var districtCode = document.form1.district.value;	
	var url = "/eservices/VillageServlet?districtCode=" + districtCode +"&talukCode=" + talukcode;
       
    var HttpRequest = getRequests();
    HttpRequest.open("GET", url, true);
    HttpRequest.onreadystatechange = function()
    {
            getVillageTamilNames(HttpRequest);
    }
    HttpRequest.send(null);*/
	
}    	