var nsx;
var nsy;
if (!document.all) {
	document.captureEvents(Event.MOUSEMOVE);
	document.onmousemove=get_mouse;
}
function get_mouse(e) {
	nsx=e.pageX-10;
	nsy=e.pageY+5;
}
function layer(id){
	var res
	if(document.getElementById) res=document.getElementById(id)
	if(document.all) res=document.all[id]
	if (res) return res.style
	return null
}
function t_i(id) {
	var hlp=layer(id)
	if (hlp) {
	if (document.all) {
	 nsy=event.y+document.body.scrollTop
	 nsx=event.x+document.body.scrollLeft
	}
	hlp.top=nsy+20
	hlp.left=nsx-20
	hlp.visibility='visible'
}}
function t_o(id) {
	var hlp=layer(id)
	if(hlp) hlp.visibility='hidden'
}


function createMarker2(point, message) {
  var marker = new GMarker(point);
  GEvent.addListener(marker, "click", function() {
	marker.openInfoWindowHtml(message);
  });

  return marker;
}


var gcontinent; var gcountry; var gregion; var gdistrict; var gcity;

function createMarker(point, zoom_in, continent,country,region,district,city,lat,lng,z_level, title,city_level,map) {

	var icon = new GIcon();

	if(city_level==2)
	{
		icon.image = "images/mm_20_yellow.png";
	}
	else if(zoom_in==1)
	{
		icon.image = "images/mm_20_green.png";
	}
	else
	{
		icon.image = "images/mm_20_red.png";
	}
	//icon.shadow = "images/mm_20_shadow.png";
	icon.iconSize = new GSize(12, 20);
	icon.shadowSize = new GSize(22, 20);
	icon.iconAnchor = new GPoint(6, 20);
	icon.infoWindowAnchor = new GPoint(5, 1);

	var marker = new GMarker(point, icon);

	if(zoom_in==1)
	{		
		GEvent.addListener(marker, "click", function() {	
			if(gcontinent==continent && gcountry==country && gregion==region && gdistrict==district && gcity==city)
			{}else{showNews(continent,country,region,district,city,0);	}
			load(continent,country,region,district,lat,lng,z_level,0,map);
			
		});
	}
	else
	{
		GEvent.addListener(marker, "click", function() {
			if(gcontinent==continent && gcountry==country && gregion==region && gdistrict==district && gcity==city){}else {showNews(continent,country,region,district,city,0);}	
		});	
	}
	GEvent.addListener(marker, "mouseover", function() {
		//closeAllPopUps();
		header_title_in(title);
	});
	GEvent.addListener(marker, "mouseout", function() {
		//closeAllPopUps();
		header_title_out();
	});
	return marker;
}

function header_title_in(title) {
	document.getElementById("header_title").innerHTML="<B>"+title+"&nbsp;&nbsp;</B>";
}

function header_title_out() {
	document.getElementById("header_title").innerHTML="";
}

function parse_load(str) {
	var bar = str.split(",");

	load(bar[0],bar[1],bar[2],bar[3],bar[4],parseInt(bar[5]));
}

var totalSpan=0

function loadnew(continent,country,region,district,lat,lng,z_level,show_all,rid) {
	load(continent,country,region,district,lat,lng,z_level,show_all,0);
	showNews(0,0,0,0,0,rid)
}

function loadWindow(continent,country,region,district,lat,lng,z_level,show_all) {
	window.location.href = "?continent="+continent+"&country="+country+"&region="+region+"&district="+district+"&show_all="+show_all+"&lat="+lat+"&lng="+lng+"&z_level="+z_level;
}


function load(continent,country,region,district,lat,lng,z_level,show_all,map) {
	GUnload();
	document.getElementById("hidden_span").innerHTML ="";
	if (GBrowserIsCompatible()) {
		
		map = new GMap2(document.getElementById("map"));

		map.addControl(new GSmallMapControl());
		map.setCenter(new GLatLng(lat,lng), parseInt(z_level));
		


		GDownloadUrl("location_markers.php?continent="+continent+"&country="+country+"&region="+region+"&district="+district+"&show_all="+show_all+"&sid="+Math.random(), function(data) {
			var xml = GXml.parse(data);
			var markers = xml.documentElement.getElementsByTagName("marker");
			for (var i = 0; i < markers.length; i++) {

				var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
								parseFloat(markers[i].getAttribute("lng")));
				
				map.addOverlay(createMarker(point, markers[i].getAttribute("zoom_in"),markers[i].getAttribute("z_continent"), markers[i].getAttribute("z_country"), markers[i].getAttribute("z_region"), markers[i].getAttribute("z_district"), markers[i].getAttribute("z_city"), markers[i].getAttribute("lat"), markers[i].getAttribute("lng"), markers[i].getAttribute("z_level"),markers[i].getAttribute("marker_title"), markers[i].getAttribute("city_level"), map));


				loadPopUp(markers[i].getAttribute("marker_title"),markers[i].getAttribute("message"),i);
			}
			totalSpan = i;
	});
	}
	showheader(continent,country,region,district,show_all);
	
}




var newsXmlHttp

var headerXmlHttp

var zipXmlHttp

function showNews(continent,country,region,district,city,rid)
{

	gcontinent=continent;
	gcountry=country;
	gregion=region;
	gdistrict=district;
	gcity=city;

	document.getElementById("news").innerHTML="<table align='center' cellspacing='0' cellpadding='0' border='0' width='100%'><tr><Td class='bar_title'>&nbsp;Loading News</td></tr></table><BR/><BR/><BR/><BR/><center><img src='images/loading.gif'/><BR/><center><img src='images/px1.gif' width=405 height=1/></center>"
	
	var objXMLHttp=null
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}

	newsXmlHttp=objXMLHttp
	
	if (newsXmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}
	var url="news.php?continent="+continent+"&country="+country+"&region="+region+"&district="+district+"&city="+city+"&rid="+rid+"&sid="+Math.random()
	newsXmlHttp.onreadystatechange=newsStateChanged
	newsXmlHttp.open("GET",url,true)
	newsXmlHttp.send("")
	
	setTimeout('fixCopyImg()',100)
}

function fixCopyImg(){
  for (var n=0; n<document.images.length; n++)
  {   
	if(document.images[n].width>240 && document.images[n].name=="img_copy")
	{
		 document.images[n].width=240
	} 
  }
}

function showheader(continent,country,region,district,show_all)
{
	document.getElementById("header").innerHTML="&nbsp;"

	var objXMLHttp=null
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}

	headerXmlHttp=objXMLHttp
	
	if (headerXmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}
	var url="get_headers.php?continent="+continent+"&country="+country+"&region="+region+"&district="+district+"&show_all="+show_all+"&sid="+Math.random()
	headerXmlHttp.onreadystatechange=headerStateChanged
	headerXmlHttp.open("GET",url,true)
	headerXmlHttp.send("")
}

function showzip(zip)
{
	document.getElementById("zip_label").innerHTML="Loading .... "

	var objXMLHttp=null
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}

	zipXmlHttp=objXMLHttp
	
	if (zipXmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}
	var url="get_zip.php?zip="+zip+"&sid="+Math.random()
	zipXmlHttp.onreadystatechange=zipStateChanged
	zipXmlHttp.open("GET",url,true)
	zipXmlHttp.send("")
}


function loadPopUp(title,message, id)
{
	if(message.length==0)
	{
		message = "<small>"+message+"</small>";
	}
	var temp = document.getElementById("hidden_span").innerHTML;
	document.getElementById("hidden_span").innerHTML=temp+"<span id='hs"+id+"' class='hide'><B>"+title+"</B><br>"+message+"</span>";
}

function closeAllPopUps()
{
	for (var i = 0; i < totalSpan; i++) {
		t_o("hs"+i);
	}

}

function newsStateChanged()
{
	if (newsXmlHttp.readyState==4 || newsXmlHttp.readyState=="complete")
	{
		document.getElementById("news").innerHTML=newsXmlHttp.responseText
	}
}

function headerStateChanged()
{
	if (headerXmlHttp.readyState==4 || headerXmlHttp.readyState=="complete")
	{
		document.getElementById("header").innerHTML=headerXmlHttp.responseText
	}
}

function zipStateChanged()
{
	if (zipXmlHttp.readyState==4 || zipXmlHttp.readyState=="complete")
	{
	
		var str = zipXmlHttp.responseText;
	
		if(str.substring(0,1)=="<")
		{
			document.getElementById("zip_label").innerHTML = "nope!!"
		}
		else
		{
			document.getElementById("zip_label").innerHTML="";

			eval(zipXmlHttp.responseText);
		}
	}
}



function showFlickr(continent,country,region,district,city)
{
	document.getElementById("news").innerHTML="<table align='center' cellspacing='0' cellpadding='0' border='0' width='100%'><tr><Td class='bar_title'>&nbsp;Loading News</td></tr></table><BR/><BR/><BR/><BR/><center><img src='images/loading.gif'/><BR/><center><img src='images/px1.gif' width=405 height=1/></center>"
	
	var objXMLHttp=null
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}

	newsXmlHttp=objXMLHttp
	
	if (newsXmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}
	url="news.php?flickr=1&continent="+continent+"&country="+country+"&region="+region+"&district="+district+"&city="+city+"&sid="+Math.random()
	newsXmlHttp.onreadystatechange=newsStateChanged
	newsXmlHttp.open("GET",url,true)
	newsXmlHttp.send("")
}