// Roshan\'s Ajax dropdown code with php
// This notice must stay intact for legal use
// Copyright reserved to Roshan Bhattarai - nepaliboy007@yahoo.com
// If you have any problem contact me at http://roshanbh.com.np
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{
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e1){
					xmlhttp=false;
				}
			}
		}
		return xmlhttp;
    }
	
	function getCountry(continentId) {		
		var strURL="/_common/geo_finder.php?continentId="+continentId;
		var req = getXMLHTTP();
		if (req) {
		  //alert (continentId);
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {			
            var children = document.getElementById('continentdiv').getElementsByClassName('geo_continent_selector_active');
            for (var i = 0; i < children.length; i++)
            document.getElementById(children.item(i).getAttribute('id')).setAttribute("class", "geo_continent_selector");
            document.getElementById(continentId).setAttribute("class", "geo_continent_selector_active");
            document.getElementById('statediv').innerHTML= 'Selecteaza tara mai intai...';
            document.getElementById('citydiv').innerHTML= 'Selecteaza regiunea mai intai...';
						document.getElementById('countrydiv').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}		
	}
	
	function getState(countryId) {		
		var strURL="/_common/geo_finder.php?countryId="+countryId;
		var req = getXMLHTTP();
		if (req) {
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {			
            var children = document.getElementById('countrydiv').getElementsByClassName('geo_selector_active');
            for (var i = 0; i < children.length; i++)
            document.getElementById(children.item(i).getAttribute('id')).setAttribute("class", "geo_selector");
            document.getElementById(countryId).setAttribute("class", "geo_selector_active");
            document.getElementById('citydiv').innerHTML= 'Selecteaza regiunea mai intai...';
						document.getElementById('statediv').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}		
	}
	function getCity(stateId) {		
		var strURL="/_common/geo_finder.php?stateId="+stateId;
		//alert (strURL);
		var req = getXMLHTTP();
		if (req) {
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById('citydiv').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}
	}

	function setValues(cityId,stateId) {		
		var strURL="/_common/geo_finder.php?set=1&cityId="+cityId+"&stateId="+stateId;
		//alert(strURL);
    var req = getXMLHTTP();
		if (req) {
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById('selected_values').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}
	}

