function fillCountryStateCity (){
	this.mainDiv = "success_registration";
	this.countryId = 0;
	this.stateId = 0;
	this.cityId = 0;

	this.state_name = "";
	this.city_name = "";

	this.page = SITEROOT + "countrystatecity.php";
	
	/****************************************/
	// send request for get ctates from db
	this.fillState = function(cId,id){
		this.state_name = id
		var obj = document.getElementById(this.state_name);
		var selectede='';
		obj.options.length = 0;
		obj[0] = new Option('- - Select State - - - ', 0, '', '');

		if(document.getElementById(this.mainDiv) != null){
			document.getElementById(this.mainDiv).appendChild = MyIndicator();
		}
		ajax.sendrequest( "GET", this.page, { type:'state', countryId:cId }, 'csc.callBackState', '' );
		//var obj = document.getElementById("state");
		//obj.disabled = true;
		if(this.stateId){
				csc.fillCity(this.stateId);
		}
	}
	
	/****************************************/
	// callback function for fill state	
	this.callBackState = function (data) {
		var obj = document.getElementById(this.state_name);
		//obj.disabled = false;
		var j=1;
		var selected = '';
		obj.options.length = 1;

		if(data.success > 0) {
			for(i=0; i < data.row.length; i++) {
				selected = (this.stateId ==  data.row[i].id) ? "selected" : '';
				obj[j] = new Option(data.row[i].state_name, data.row[i].id, selected,selected);
				j+=1;
			}
		}
/*
		var obj = document.getElementById("city");
		obj.options.length = 0;
		obj[0] = new Option('- - Select City - - - ', 0, '','');	
*/
	}
	
	
	this.fillCity = function (sId,id){
		this.city_name = id;
		ajax.sendrequest( "GET", this.page, { type:'city', stateId:sId }, 'csc.callBackCity', '' );
	}
	
		/***************************************************************************/
	
	this.callBackCity = function (data) {
		var obj = document.getElementById(this.city_name);
		var j=1;
		var selectedd = "";
		
		if(data.success > 0) {
			for(i=0; i < data.row.length; i++) {
				selectedd = (this.cityId ==  data.row[i].id ? "selected" : "");
				obj[j] = new Option(data.row[i].name, data.row[i].id, selectedd, selectedd);
				j+=1;
			}
		}else{
		 	obj.options.length = 0;
			obj[0] = new Option('No City Found', 0, selectedd, selectedd);	
		}
	}

	this.autoFillState = function(country_id,state_id,selectName){
		this.countryId = country_id;
		this.stateId = state_id;
		this.state_name = selectName;
		if(this.countryId > 0) {
			var t = setTimeout("csc.fillState(" + this.countryId + ",'" + selectName +"');",1000);
		}
	}

	this.autoFillCity = function(state_id,city_id,selectName){
		this.stateId = state_id;
		this.cityId = city_id;
		this.city_name = selectName;
		if(this.stateId > 0) {
			var t = setTimeout("csc.fillCity(" + this.stateId + ",'" + selectName + "');",1500);
		}
	}
	
	
	this.autoFill = function(cId,sId,cityId) {
		this.countryId = cId;
		this.stateId = sId;
		this.cityId = cityId;
		
		if(cId > 0) {
			var t = setTimeout("csc.fillState(" + cId + ");",1000);
		}
		if(sId > 0) {
			var t = setTimeout("csc.fillCity(" + sId + ");",1500);
		}
	}

} // fillCountryStateCity

var csc = new fillCountryStateCity();