function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function drawCircle(center, radius, nodes, liColor, liWidth, liOpa, fillColor, fillOpa) 
{ 
	var latConv = center.distanceFrom(new GLatLng(center.lat()+0.1, center.lng()))/100; 
	var lngConv = center.distanceFrom(new GLatLng(center.lat(), center.lng()+0.1))/100; 
	var points = []; 
	var step = parseInt(360/nodes)||10; 
	for(var i=0; i<=360; i+=step) {
		var pint = new GLatLng(center.lat() + (radius/latConv * Math.cos(i * Math.PI/180)), center.lng() + (radius/lngConv * Math.sin(i * Math.PI/180))); 
		points.push(pint); 
		bounds.extend(pint); 
	} 
	points.push(points[0]); 
	fillColor = fillColor||liColor||"#0055ff"; 
	liWidth = liWidth||2; 
	var poly = new GPolygon(points,liColor,liWidth,liOpa,fillColor,fillOpa); 	map.addOverlay(poly); 
} 
function fit(){ 
	map.panTo(bounds.getCenter()); 
	map.setZoom(map.getBoundsZoomLevel(bounds));
} 

function popup(adresa, w, h, scr){
	var l=(screen.availWidth-w)/2 , t=(screen.availHeight-h)/2;
	win=window.open(adresa,"_blank","width="+w+",height="+h+",left="+l+",top="+t+",statusbar=no,toolbar=no,scrollbars="+scr+",navbar=no");
	win.focus();
}

// Creates a marker whose info window displays the letter corresponding
// to the given index.
function createMarker(point, html, letter) {
 	// Create a lettered icon for this point using our icon class
	var baseIcon = new GIcon();
	baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
	baseIcon.iconSize = new GSize(20, 34);
	baseIcon.shadowSize = new GSize(37, 34);
	baseIcon.iconAnchor = new GPoint(9, 34);
	baseIcon.infoWindowAnchor = new GPoint(9, 2);
	baseIcon.infoShadowAnchor = new GPoint(18, 25);
  	var icon = new GIcon(baseIcon);
  	icon.image = "http://www.google.com/mapfiles/marker" + letter + ".png";
  	var marker = new GMarker(point, icon);

	GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(html);});
  	return marker;
}

function InitSteps(lat, long, marktxt){
	Step1(lat, long);
	Step2(lat, long);
	Step3(lat, long);
	Step4(lat, long);
	Step5(lat, long, marktxt);
}

function Step1(lat, long){
	window.setTimeout(function() {
		map.panTo(new GLatLng(lat, long));
	}, 2000);
}

function Step2(lat, long){
	window.setTimeout(function() {
		map.panTo(new GLatLng(lat, long));
		map.setZoom(7);
	}, 4000);
}

function Step3(lat, long){
	window.setTimeout(function() {
		map.panTo(new GLatLng(lat, long));
		map.setZoom(10);
	}, 6000);
}

function Step4(lat, long){
	window.setTimeout(function() {
		map.panTo(new GLatLng(lat, long));
		map.setZoom(13);
	}, 8000);
}

function Step5(lat, long, marktxt){
	window.setTimeout(function() {
		map.panTo(new GLatLng(lat, long));
		marker.openInfoWindowHtml(marktxt);
		
		if(document.getElementById('det') != null){
			document.getElementById('det').style.width="400px";
			document.getElementById('det').style.display="block";
		}
		
		if(document.getElementById('searchingdiv') != null)
			document.getElementById('searchingdiv').style.display="none";
		
		if(document.getElementById('map') != null)
			document.getElementById('map').style.width="370px";
			document.getElementById('map').style.height="300px";
		
		if(document.getElementById('info_left') != null){
			document.getElementById('info_left').style.display="block";
			if(document.getElementById('map') != null)
				document.getElementById('map').style.width="350px";
		}
		
		if(document.getElementById('sign_in') != null)
			document.getElementById('sign_in').style.display="block";
		
		map.checkResize();
		map.setCenter(new GLatLng(lat, long), 16, G_NORMAL_MAP);
	}, 10000);
}

function Step6(lat, long, marktxt){
	marker.openInfoWindowHtml(marktxt);
	document.getElementById('det').style.width="290px";
	document.getElementById('searchingdiv').style.display="none";
	document.getElementById('map').style.width="480px";
	map.checkResize();
	map.setCenter(new GLatLng(lat, long), 16, G_NORMAL_MAP);
}

function PhoneSearch(){
	search_url = 'results.php?number=';
	input1 = document.getElementById('input1').value;
	input2 = document.getElementById('input2').value;
	input3 = document.getElementById('input3').value;
	
	if( (input1 == '') && ((input2 == '') || (input3 == '')) ) alert('Please complete all the fields!');
	else{
		document.location = search_url + input1 + input2 + input3;
	}
}

function PhoneSearchAtEnd(){
	search_url = 'results.php?number=';
	input1 = document.getElementById("input4").value;
	input2 = document.getElementById("input5").value;
	input3 = document.getElementById("input6").value;
	
	if( (input1 == '') && ((input2 == '') || (input3 == '')) ) alert('Please complete all the fields!');
	else{
		document.location = search_url + input1 + input2 + input3;
	}
}

function ShowPopup(URL) {
	day = new Date();
	id = day.getTime();
	w = 700;
	h = 700;
	var l=(screen.availWidth-w)/2 , t=(screen.availHeight-h)/2;
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=" + w + ",height=" + h + ",left = " + l + ",top = " + t + " ');");
}

function submitViaEnter(evt) {
	evt = (evt) ? evt : event;
	var target = (evt.target) ? evt.target : evt.srcElement;
	var form = target.form;
	var charCode = (evt.charCode) ? evt.charCode :
	((evt.which) ? evt.which : evt.keyCode);
	if (charCode == 13) {
		form.submit();
		return false;
	}
	return true;
}

