/* ----------------------------------
| $RCSfile: streets_acmpl.js,v $
| $Date: 2007/10/21 16:15:46 $
| $Revision: 1.3 $
 ---------------------------------- */

function g_get_streets(place_id, uifc) {
    xmlhttp = g_http_obj();
    xmlhttp.open('GET', WEB_ROOT_RELATIVE+'ajax/sstreets.php?place_id='+place_id+"&uifc="+encode64(uifc)+'&streets_gis_version='+STREETS_GIS_VERSION, false);
    xmlhttp.send(null);        
    if (xmlhttp.readyState == 4) {
        if (xmlhttp.status == 200) {
			resp = xmlhttp.responseText;
			return resp;		
        }
    }	
}    

function g_get_street_coordinates() {
    xmlhttp = g_http_obj();
    xmlhttp.open('GET', WEB_ROOT_RELATIVE+'ajax/sstreet_location.php?street_id='+STRTACMPLT['g_street_id']+'&streets_gis_version='+STREETS_GIS_VERSION, false);
    xmlhttp.send(null);        
    if (xmlhttp.readyState == 4) {
        if (xmlhttp.status == 200) {
		    resp = xmlhttp.responseText;
			tmp = resp.split("\t");
			resp = {"lat" : tmp[0], "lon" : tmp[1], "zoom" : tmp[2]};
		    return resp;
        }
    }		
}    

// region select element name is global var declared prior including this file (some kind of config)
// this is because this JS file is included from browse.php page also, and there it has different name
function get_search_place_id() {
    frm = document.forms[0];
    if (frm.elements[STRTACMPLT['region_elem']].value == ZG_REGION_ID) return "1"; // Constant for ZG streets
    else if (frm.elements[STRTACMPLT['region_elem']].value == 0 
             || frm.elements['g_object[area_id]'].value == 0
             || frm.elements['g_object[place_id]'].value == 0) {
        return 0;    
    } else if (frm.elements['g_object[place_id]'].value > 0) {
        return frm.elements['g_object[place_id]'].value;
    }
}
    
// this function is called  from activateCurrentSmartInputMatch()
function g_cache_street_id(street_id) {
	if (street_id > 0) {
		STRTACMPLT['g_street_id'] = street_id;
		// enable Locate button
        if (STRTACMPLT['show_bttn_color'])
		    document.getElementById("locate_street_btn").style.backgroundColor = STRTACMPLT['show_bttn_color'];
		document.getElementById("locate_street_btn").disabled = "";
	} else {
		//alert("Could not get street id from name "+street_name);
	}
	return;
}

function g_invalidate_street_id() {
	STRTACMPLT['g_street_id'] = 0;
	// disable Locate button
	document.getElementById("locate_street_btn").style.backgroundColor="";
	document.getElementById("locate_street_btn").disabled = "disable";
}
    