
function populateCity(zip,country_select_id,city_id){
   
   city_field = document.getElementById(city_id);
   country_select_field = document.getElementById(country_select_id);
   
   if(country_select_field.options[country_select_field.selectedIndex].value=='US'){
   new Ajax.Request('query_state_code.php?field=city&zip='+zip,{
       asynchronous:true,
       onComplete:function(req) {
 	    //alert(req.readyState);
  		if (req.readyState == 4) {
  		    //alert(req.status);
  			if (req.status == 200){  											
  				//alert(req.responseText);
  				if(!(req.responseText == '' || !req.responseText)) {
                   city_field.value=req.responseText;
				}// end if response
  			}// end if status
  		}// end if ready State
      }// end if function
   })// end ajax
  }// end country
}// end function 

function populateState(zip,country_select_id,state_select_id){

state_select_field = document.getElementById(state_select_id);
country_select_field = document.getElementById(country_select_id);
	
if(country_select_field.options[country_select_field.selectedIndex].value=='US' || country_select_field.options[country_select_field.selectedIndex].value=='USD'){
   new Ajax.Request('query_state_code.php?zip='+zip, {
     asynchronous:true,
     onComplete:function(req) {
 	    //alert(req.readyState);
  		if (req.readyState == 4) {
  		    //alert(req.status);
  			if (req.status == 200){  											
  				//alert(req.responseText);
  				if(!(req.responseText == '' || !req.responseText)) {
  			  	   for (i=0; i<state_select_field.options.length; i++) {
					    if (req.responseText == state_select_field.options[i].value) {
						    state_select_field.selectedIndex = i;
						    continue;
						 }// end if
				   }// end for
				}// end if
  			}// end if
  		}// end if
      }// end if
   })// end function;
  }// end if
}