function getReq() {
        var req = false;
        try {
            req = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(Ex) {
                try {
                	req = new ActiveXObject("Microsoft.XMLHTTP");
                } catch(ex1) {
                    req = false;
                }
        }
        if(!req && typeof XMLHttpRequest != 'undefined') {
            req = new XMLHttpRequest();
        }        
        return req;
}

function fillTaluk(district) {
	obj = document.forms[0].talukCode;
	var url = "getAjax.html?dcode=" + district + "&type=taluk";
	var HttpRequest = getReq();
    HttpRequest.open("GET", url, true);    
    HttpRequest.onreadystatechange = function(){
            fillCombo(HttpRequest, obj)
    }
    HttpRequest.send(null);

}

function fillVillage(district,taluk) {
	obj = document.forms[0].villageCode;
	var url = "getAjax.html?dcode=" + district + "&tcode=" + taluk + "&type=village";
	var HttpRequest = getReq();
    HttpRequest.open("GET", url, true);    
    HttpRequest.onreadystatechange = function(){
            fillCombo(HttpRequest, obj)
    }
    HttpRequest.send(null);

}

function fillCombo(HttpRequest, obj) {
	if(HttpRequest.readyState == 4){
        if(HttpRequest.status == 200){
        	var root = HttpRequest.responseXML.getElementsByTagName('root')[0];  
            var flag = root.getElementsByTagName('flag')[0].firstChild.nodeValue;
            if(flag == "false") {   
            	for(i = obj.length; i > 0; i--){
					obj.options[i] = null;
				}          
            }
            else {            	
            	var list = root.getElementsByTagName('data');
            	for(i = obj.length; i > 0; i--){
					obj.options[i] = null;
				}
				for(i = 0; i < list.length; i++){				
					var code = list[i].getElementsByTagName('code')[0].firstChild.nodeValue;
					var name = list[i].getElementsByTagName('name')[0].firstChild.nodeValue;
					obj.options[i+1] = new Option(name, code);
				}	            	
            }
        }
    }
}

function showVillage(option) {

	if(option == 'rural') {
		document.getElementById('villageId').className = 'show';		
	} else if(option == 'urban') {
		document.getElementById('villageId').className = 'hide';
		document.forms[0].villageCode.value = '';
	} 

}