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 getTown(province){
	var strURL="/includes/signup.city.inc.php?province="+province;
	var req = getXMLHTTP();
	if(req){
		req.onreadystatechange = function(){
			if(req.readyState == 4){
				if (req.status == 200){
					if(province == 'METRO MANILA'){ 
						var row = document.getElementById("brgy_row");
						row.style.display = '';
					} else {
						var row = document.getElementById("brgy_row");
						row.style.display = 'none';
					}
					
					document.getElementById('city_list').innerHTML=req.responseText;
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}
		}
   		req.open("GET", strURL, true);
    	req.send(null);
   }
}

function getBrgy(city){
	var strURL="/includes/signup.brgy.inc.php?city="+city;
	var req = getXMLHTTP();
	if(req){
		req.onreadystatechange = function(){
			if(req.readyState == 4){
				if (req.status == 200){
					document.myForm.town_city_value.value = city;
					document.getElementById('brgy_list').innerHTML=req.responseText;
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}
		}
   		req.open("GET", strURL, true);
    	req.send(null);
   }
}

function assignZipCode(city){
	var strURL="/includes/signup.zipcode.inc.php?city="+city;
	var req = getXMLHTTP();
	if(req){
		req.onreadystatechange = function(){
			if(req.readyState == 4){
				if (req.status == 200){
					document.myForm.town_city_value.value = city
					document.getElementById('zipcode').innerHTML=req.responseText;
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}
		}
   		req.open("GET", strURL, true);
    	req.send(null);
   }
}

function assignBrgyZipCode(brgy){
	var strURL="/includes/signup.zipcode.inc.php?brgy="+brgy;
	var req = getXMLHTTP();
	if(req){
		req.onreadystatechange = function(){
			if(req.readyState == 4){
				if (req.status == 200){
					document.myForm.brgy_value.value = brgy
					document.getElementById('zipcode').innerHTML=req.responseText;
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}
		}
   		req.open("GET", strURL, true);
    	req.send(null);
   }
}

function setValueToHidden(zipcode){
	document.myForm.zipcode_value.value = zipcode
}