
//For type of dropdown
function getXMLHTTP() { //fuction to return the xml http object
		var xmlhttp=false;	
		try{
			xmlhttp=new XMLHttpRequest();
		}
		catch(e)	{		
			try{			
				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e){
				try{
				req = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e1){
					xmlhttp=false;
				}
			}
		}
		 	
		return xmlhttp;
    }
	
	function getState(countryId,stateDropdownName,cityDropdownName) {	
	
		var strURL="dropdownajax/findState.php?countryId="+countryId+"&stateDropdownName="+stateDropdownName+"&cityDropdownName="+cityDropdownName;
		var req = getXMLHTTP();
		
		if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById('statediv1').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}
				
	}
	
	function getCity(stateId,cityDropdownName) { 
var strURL="dropdownajax/findCity.php?stateId="+stateId+"&cityDropdownName="+cityDropdownName;
		var req = getXMLHTTP();
		if (req) {
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById('citydiv1').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}
				
	}
function addNewState(){
var valOtherState=document.getElementById('otherState').value;
var valCountry=document.getElementById('user_country_id').value;
	if(valOtherState==''){
	alert("Please Enter Correct State Name");
	}else{
	
	insertNewState(valCountry, valOtherState);
	
	}
}

function insertNewState(CountryId, OtherState){
var strURL="dropdownajax/insertState.php?CountryId="+CountryId+"&OtherState="+OtherState;
		var req = getXMLHTTP();
		if (req) {
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById('statediv1').innerHTML=req.responseText;
						hiddeStateDiv();						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}
}

function showStateDiv(){
document.getElementById('addOtherState').style.display = "block"

}

function hiddeStateDiv(){
document.getElementById('addOtherState').style.display = "none"

}




function addNewCity(){
var valOtherCity=document.getElementById('otherCity').value;
var valState=document.getElementById('user_state_id').value;
	if(valOtherCity===''){
	alert("Please Enter Correct City Name");
	}else{
	
	insertNewCity(valState, valOtherCity);
	
	}
}

function insertNewCity(StateId, OtherCity){
var strURL="dropdownajax/insertCity.php?StateId="+StateId+"&OtherCity="+OtherCity;
		var req = getXMLHTTP();
		if (req) {
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById('citydiv1').innerHTML=req.responseText;
						hiddeCityDiv();						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}
}

function showCityDiv(){
document.getElementById('addOtherCity').style.display = "block"

}

function hiddeCityDiv(){
document.getElementById('addOtherCity').style.display = "none"

}

