function createXHR()
{
	try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
	try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
	try { return new XMLHttpRequest(); } catch (e) {}
	alert("XHR not supported");
	return null;
}

function $(id) { return document.getElementById(id); }

function _check_exists($e)
{
	var x = createXHR();
	res=0;
	x.onreadystatechange = function()
	{
		if ( x.readyState==4 )
		{
			if ( x.status==200 )
			{
				res=x.responseText;
				//alert(res);
				if ( res=="1" ){ window.location="myforgot.php?send=1&act=already&email="+$e; }
			}
			else
			{
				res=-1;
			}

		}
	}
	var url="../xhr/xhr_pub.php?a=exist&e="+$e;
	x.open("GET",url,true);
	x.send(null);
	return res;
}

function str( arr )
{
	var s="";
	for (var i = 0; i < arr.length ; i++) 
	{
		s=s+arr[i]+", ";
	}
	return s;
}

function index_in_array(needle, haystack)
{
	for (var i = 0; i < haystack.length ; i++) 
	{
		if (haystack[i] == needle) 
		{
		return i;
		}
	}
	return -1;
}
function stat(s)
{
	document.getElementById('status').innerHTML = s + '<br>'+document.getElementById('status').innerHTML;
}
  
function _path(tid,lats,lons)
{
	var x = createXHR();
	res=0;
	x.onreadystatechange = function()
	{
		if ( x.readyState==4 )
		{
			//alert(4);
			if ( x.status==200 )
			{
				res=x.responseText;
				//alert(res);

				//if ( res.charAt(0)=='*')
				//	stat(res+' '+ x.iid );
				//else
					if ( res.indexOf('lats')==-1)
					{
						stat(res+' '+ x.iid );
					}
					else
				{
					my_path = eval("(" + res + ")");
					
					//alert( my_path.lats[2] );
					path_line( my_path,0 );
					//if ( res=="1" ){ window.location="myforgot.php?send=1&act=already&email="+$e; }
				//	document.getElementById('status').innerHTML = 'DONE';
					stat( 'DONE '+ x.iid );
				}
			}
			else
			{
				res=-1;
// Bug : NULL_PATH errors dont come thru here...why?
				s( 'ERROR' );
			}

		}
	}
	slat=lats.join('~');
	slon=lons.join('~');
	var url="../xhr/xhr_rt.php?tripid="+tid+"&lats="+slat+"&lons="+slon;
	// if ( lons.length()==0 )document.write(url);
	//alert(url);
	x.open("GET",url,true);
	x.send(null);
	x.iid=point_markers;

	stat('SENT '+ x.iid );

	return res;
}


