var countries = new Array();
countries["Afghanistan"]="60.50526,29.394159,74.898827,38.453041,Afghanistan";
countries["Albania"]="19.28249,39.667759,21.053049,42.661369,Albania";
countries["Algeria"]="-8.669294,18.976379,11.98645,37.083599,Algeria";
countries["American Samoa"]="-170.823931,-14.376303,-170.560398,-14.25428,American Samoa";
countries["Andorra"]="1.435247,42.4361,1.781667,42.65387,Andorra";
countries["Angola"]="11.73111,-18.01173,24.06221,-4.388889,Angola";
countries["Antigua and Barbuda"]="-61.891102,16.9897,-61.666401,17.725,Antigua and Barbuda";
countries["Argentina"]="-73.58168,-55.04528,-53.65028,-21.78751,Argentina";
countries["Armenia"]="43.47324,38.844219,46.622501,41.298599,Armenia";
countries["Aruba"]="-70.06,12.4,-69.863,12.63,Aruba";
countries["Australia"]="112.908302,-43.64806,153.619995,-10.71056,Australia";
countries["Austria"]="9.54041,46.387489,17.179899,49.01582,Austria";
countries["Azerbaijan"]="44.77858,38.390541,50.384991,41.896702,Azerbaijan";
countries["Bahamas"]="-78.80307,22.256941,-73.829453,26.928329,Bahamas";
countries["Bahrain"]="50.466099,25.79055,50.613041,26.24028,Bahrain";
countries["Bangladesh"]="88.043297,20.7486,92.669418,26.625271,Bangladesh";
countries["Barbados"]="-59.65918,13.05694,-59.429169,13.33194,Barbados";
countries["Belarus"]="19.636511,51.2528,32.741402,56.167801,Belarus";
countries["Belgium"]="2.541667,49.5061,6.400277,51.502769,Belgium";
countries["Belize"]="-89.217773,15.88972,-88.08223,18.48971,Belize";
countries["Benin"]="0.776667,6.210679,3.855,12.39332,Benin";
countries["Bermuda"]="-64.858299,32.260601,-64.6717,32.382198,Bermuda";
countries["Bhutan"]="88.750549,26.70138,92.11441,28.32333,Bhutan";
countries["Bolivia"]="-69.652496,-22.901119,-57.45861,-9.682777,Bolivia";
countries["Bosnia - Herzegovina"]="15.7364,42.564522,19.619699,45.276901,Bosnia - Herzegovina";
countries["Botswana"]="19.995819,-26.89468,29.370529,-17.797661,Botswana";
countries["Brazil"]="-74.009453,-33.74773,-34.79945,5.273609,Brazil";
countries["British Virgin Island"]="-64.522117,18.016647,-63.0033,18.450594,British Virgin Island";
countries["Brunei"]="114.091003,4.027776,115.360199,5.053054,Brunei";
countries["Bulgaria"]="22.35944,41.254429,28.60638,44.243061,Bulgaria";
countries["Burkina Faso"]="-5.52066,9.396385,2.401563,15.08305,Burkina Faso";
countries["Burundi"]="28.98749,-4.454723,30.85388,-2.299445,Burundi";
countries["Cambodia"]="102.351402,10.00972,107.636398,14.70496,Cambodia";
countries["Cameroon United Republic"]="8.502497,1.654166,16.206409,13.08472,Cameroon United Republic";
countries["Canada"]="-141.001404,41.913319,-52.616669,83.113327,Canada";
countries["Cape Verde"]="-25.36056,14.81222,-22.6725,17.19166,Cape Verde";
countries["Central African Republic"]="14.41444,2.221102,27.45805,11.00139,Central African Republic";
countries["Chad"]="13.46222,7.457776,23.99971,23.45055,Chad";
countries["Chile"]="-75.715561,-55.72057,-67.001106,-17.50528,Chile";
countries["China"]="73.623863,18.168881,134.772201,53.553871,China";
countries["Colombia"]="-79.051681,-4.224228,-66.873383,12.45833,Colombia";
countries["Comoros"]="43.214432,-12.37084,44.526661,-11.37111,Comoros";
countries["Congo"]="11.14151,-5.020615,18.642219,3.710833,Congo";
countries["Congo, Democratic Republic"]="12.20966,-13.45195,31.277451,5.347498,Congo, Democratic Republic";
countries["Costa Rica"]="-85.89862,8.026709,-82.565193,11.21361,Costa Rica";
countries["Cote D'ivoire"]="-8.606667,4.347776,-2.488056,10.73495,Cote D'ivoire";
countries["Croatia"]="13.49639,42.398319,19.4261,46.541698,Croatia";
countries["Cuba"]="-84.953339,19.821939,-74.131943,23.18638,Cuba";
countries["Cyprus"]="32.269161,34.56332,34.581661,35.67165,Cyprus";
countries["Czech Republic"]="12.09347,48.57555,18.871652,51.031368,Czech Republic";
countries["Denmark"]="8.091389,54.570271,12.61806,57.74416,Denmark";
countries["Djibouti"]="41.759708,10.97083,43.419991,12.70889,Djibouti";
countries["Dominica"]="-61.490009,15.2,-61.25362,15.62805,Dominica";
countries["Dominican Republic"]="-71.991524,17.61833,-68.322243,19.928329,Dominican Republic";
countries["Ecuador"]="-91.666122,-5.003335,-75.218613,1.437926,Ecuador";
countries["Egypt"]="24.706381,21.99666,35.813042,31.63933,Egypt";
countries["El Salvador"]="-90.105827,13.15666,-87.695267,14.45166,El Salvador";
countries["Equatorial Guinea"]="9.357498,1.001944,11.35389,2.346065,Equatorial Guinea";
countries["Eritrea"]="36.443859,12.36389,43.12331,18.0089,Eritrea";
countries["Estonia"]="21.83194,57.522202,28.195299,59.66832,Estonia";
countries["Ethiopia"]="32.989429,3.406666,47.98943,14.867343,Ethiopia";
countries["Falkland Islands"]="-61.030811,-52.339451,-57.731392,-51.25861,Falkland Islands";
countries["Faroe Islands, Denmark"]="-7.2325,61.933319,-6.5675,62.330269,Faroe Islands, Denmark";
countries["Fiji"]="177.256302,-19.1614,179.989502,-16.152691,Fiji";
countries["Finland"]="19.648331,59.804989,31.587299,70.079422,Finland";
countries["France"]="-4.790556,41.366379,9.543055,51.091099,France";
countries["French Guiana"]="-54.61536,2.113055,-51.649441,5.750277,French Guiana";
countries["French Polynesia"]="-149.641693,-17.87084,-149.148895,-17.499451,French Polynesia";
countries["French Southern and Antarctic Lands"]="68.751373,-49.720558,70.568588,-48.652779,French Southern and Antarctic Lands";
countries["Gabon"]="8.706387,-3.922898,14.51861,2.317276,Gabon";
countries["Gambia"]="-16.826389,13.03709,-13.79861,13.82638,Gambia";
countries["Gaza Strip"]="34.21748,31.216261,34.55859,31.596661,Gaza Strip";
countries["Georgia"]="40.006512,41.046101,46.7108,43.584702,Georgia";
countries["Germany"]="5.869443,47.281101,15.03805,54.9174,Germany";
countries["Ghana"]="-3.249166,4.727777,1.20385,11.16666,Ghana";
countries["Greece"]="19.627501,34.929989,28.24222,41.744431,Greece";
countries["Greenland, Denmark"]="-73.043083,59.7911,-12.15528,83.623032,Greenland, Denmark";
countries["Grenada"]="-61.789699,11.9964,-61.596401,12.2378,Grenada";
countries["Guadeloupe"]="-61.783619,15.95,-61.10992,16.513611,Guadeloupe";
countries["Guatemala"]="-92.245941,13.74547,-88.213059,17.82111,Guatemala";
countries["Guinea"]="-15.07861,3.21361,8.961386,12.66603,Guinea";
countries["Guinea-Bissau"]="-16.677811,10.92389,-13.64417,12.68472,Guinea-Bissau";
countries["Guyana"]="-61.389999,1.185555,-56.470909,8.533598,Guyana";
countries["Haiti"]="-74.476959,18.02277,-71.62944,19.93277,Haiti";
countries["Heard Island and McDonald Islands"]="73.234421,-53.199169,73.719422,-52.96418,Heard Island and McDonald Islands";
countries["Honduras"]="-89.354874,12.98741,-83.130867,16.020269,Honduras";
countries["Hong Kong"]="113.896599,22.2775,114.389999,22.548849,Hong Kong";
countries["Hungary"]="16.106701,45.760349,22.894859,48.575821,Hungary";
countries["Iceland"]="-24.515,63.40276,-13.49778,66.534416,Iceland";
countries["India"]="68.139977,6.748887,97.394127,35.986099,India";
countries["Indonesia"]="95.198593,-10.93,141.008301,5.653888,Indonesia";
countries["Iran"]="44.034161,25.07527,63.341931,39.78054,Iran";
countries["Iraq"]="38.794552,29.10416,48.545181,37.38443,Iraq";
countries["Ireland"]="-10.47278,51.44582,-5.994722,55.377209,Ireland";
countries["Isle of Man"]="-4.784167,54.056931,-4.308612,54.409161,Isle of Man";
countries["Israel"]="34.267078,29.49379,35.669708,33.290272,Israel";
countries["Italy"]="6.620172,36.650829,18.51083,47.090542,Italy";
countries["Jamaica"]="-78.372787,17.696659,-76.188606,18.52194,Jamaica";
countries["Japan"]="127.652801,26.07888,145.818298,45.50552,Japan";
countries["Jordan"]="34.88443,29.188881,39.303081,33.377232,Jordan";
countries["Kazakhstan"]="46.499199,40.591099,87.345329,55.444698,Kazakhstan";
countries["Kenya"]="33.951382,-4.673122,41.913639,4.622081,Kenya";
countries["Kiribati"]="-157.5681,1.705,-157.191101,2.026666,Kiribati";
countries["Korea, North"]="124.323601,37.680271,130.694794,42.980541,Korea, North";
countries["Korea, South"]="126.123596,33.190269,129.5858,38.622532,Korea, South";
countries["Kosovo"]="19.9753,41.855598,21.8183,43.268101,Kosovo";
countries["Kuwait"]="46.541611,28.544359,48.419731,30.083879,Kuwait";
countries["Kyrgyzstan"]="69.248901,39.191898,80.285477,43.2686,Kyrgyzstan";
countries["Laos"]="100.0923,13.92,107.695198,22.50083,Laos";
countries["Latvia"]="20.986941,55.674999,28.237801,58.0844,Latvia";
countries["Lebanon"]="35.097061,33.063042,36.624981,34.689152,Lebanon";
countries["Lesotho"]="27.014721,-30.65889,29.455549,-28.56945,Lesotho";
countries["Liberia"]="-11.4987,4.351451,-7.367778,8.569677,Liberia";
countries["Libya"]="9.303886,19.497761,25.13423,33.165779,Libya";
countries["Liechtenstein"]="9.47583,47.049641,9.640949,47.266979,Liechtenstein";
countries["Lithuania"]="20.93203,53.8881,26.8197,56.450802,Lithuania";
countries["Luxembourg"]="5.731111,49.448318,6.522222,50.172211,Luxembourg";
countries["Macau"]="113.527496,22.0917,113.603897,22.214399,Macau";
countries["Macedonia"]="20.46249,40.857021,23.031389,42.361401,Macedonia";
countries["Madagascar"]="43.2211,-25.600281,50.499439,-11.94778,Madagascar";
countries["Malawi"]="32.689701,-17.135811,35.92416,-9.373335,Malawi";
countries["Malaysia"]="99.646927,0.853333,119.275803,7.356666,Malaysia";
countries["Maldives"]="72.683601,-0.6908,73.753601,7.0964,Maldives";
countries["Mali"]="-12.24575,10.14194,4.2525,25.000271,Mali";
countries["Malta"]="14.1808,35.799999,14.57,36.075001,Malta";
countries["Martinique"]="-61.22945,14.40305,-60.810009,14.88028,Martinique";
countries["Mauritania"]="-17.05435,14.72555,-4.806389,27.280199,Mauritania";
countries["Mauritius"]="57.306381,-20.50584,57.78582,-20.00112,Mauritius";
countries["Mexico"]="-117.123596,14.54808,-86.74501,32.718319,Mexico";
countries["Moldova"]="26.635,45.4482,30.134199,48.486698,Moldova";
countries["Mongolia"]="87.759407,41.581379,119.928001,52.14201,Mongolia";
countries["Montenegro"]="18.4533,41.849319,20.382799,43.556099,Montenegro";
countries["Morocco"]="-13.176931,27.665079,-1.010556,35.915272,Morocco";
countries["Mozambique"]="30.21277,-26.860279,40.839161,-10.48045,Mozambique";
countries["Myanmar"]="92.193298,9.985552,101.161598,28.54694,Myanmar";
countries["Namibia"]="11.73333,-28.960831,25.265751,-16.968889,Namibia";
countries["Nepal"]="80.055801,26.347771,88.195801,30.41971,Nepal";
countries["Netherlands"]="3.363889,50.756069,7.209444,53.509299,Netherlands";
countries["Netherlands Antilles"]="-70.284912,12.033213,-68.499046,12.863099,Netherlands Antilles";
countries["New Caledonia"]="163.992203,-22.39473,168.146103,-20.087231,New Caledonia";
countries["New Zealand"]="165.566357,-50.85445,178.559693,-33.069679,New Zealand";
countries["Nicaragua"]="-87.690292,10.70972,-83.130867,15.02472,Nicaragua";
countries["Niger"]="0.166667,11.69169,15.99666,23.52232,Niger";
countries["Nigeria"]="2.682129,4.281943,14.67416,13.89313,Nigeria";
countries["Northern Mariana Islands"]="144.623001,13.2375,144.953293,13.63472,Northern Mariana Islands";
countries["Norway"]="-9.120001,57.996101,33.624989,80.513313,Norway";
countries["Oman"]="51.904148,16.64386,59.836101,25.039221,Oman";
countries["Pakistan"]="60.866871,23.688049,77.831413,37.062759,Pakistan";
countries["Panama"]="-83.031677,7.205832,-77.146668,9.620277,Panama";
countries["Papua New Guinea"]="140.849899,-11.62028,153.776306,-1.950556,Papua New Guinea";
countries["Paraguay"]="-62.63866,-27.586121,-54.243061,-19.296671,Paraguay";
countries["Peru"]="-81.3564,-18.34799,-68.6875,-0.0375,Peru";
countries["Philippines"]="117.1744,5.051388,126.598,18.647499,Philippines";
countries["Poland"]="14.13333,49.006351,24.14471,54.836651,Poland";
countries["Portugal"]="-28.54945,32.637489,-6.194444,42.15221,Portugal";
countries["Puerto Rico"]="-67.25917,17.928049,-65.625839,18.511391,Puerto Rico";
countries["Qatar"]="50.752491,24.55559,51.61166,26.152769,Qatar";
countries["Reunion"]="55.221371,-21.373619,55.85138,-20.86556,Reunion";
countries["Romania"]="20.261141,43.624699,29.701111,48.253319,Romania";
countries["Russian Fed."]="26.970313,41.196098,180,83.271366,Russian Fed.";
countries["Rwanda"]="28.853319,-2.826667,30.876381,-1.061622,Rwanda";
countries["Saint Helena"]="-5.793568,-16.021259,-5.643567,-15.892676,Saint Helena";
countries["Samoa"]="-172.774994,-14.05306,-171.436707,-13.46056,Samoa";
countries["San Marino"]="12.405131,43.894595,12.508419,43.988895,San Marino";
countries["Sao Tome And Principe"]="6.464999,0.02,7.4642,1.7019,Sao Tome And Principe";
countries["Saudi Arabia"]="34.603039,15.10555,56.51305,32.237339,Saudi Arabia";
countries["Senegal"]="-17.52,12.30139,-11.35833,16.69305,Senegal";
countries["Serbia"]="18.8281,42.232201,23.006941,46.174992,Serbia";
countries["Seychelles"]="55.374699,-4.7892,55.792801,-4.28,Seychelles";
countries["Sierra Leone"]="-13.298431,6.913198,-10.26652,9.997496,Sierra Leone";
countries["Singapore"]="103.648002,1.259722,103.998001,1.425287,Singapore";
countries["Slovakia"]="16.84083,47.740822,22.558001,49.605259,Slovakia";
countries["Slovenia"]="13.38305,45.425598,16.60924,46.872479,Slovenia";
countries["Solomon Islands"]="154.5336,-11.84584,162.386597,-5.018613,Solomon Islands";
countries["Somalia"]="40.986309,-1.674361,54.5336,12.71278,Somalia";
countries["South Africa"]="16.469721,-34.814999,32.893089,-22.13611,South Africa";
countries["South Georgia and the South Sandwich Isl"]="-38.0289,-54.889721,-35.782791,-54.00333,South Georgia and the South Sandwich Isl";
countries["Spain"]="-17.99501,27.73472,4.336666,43.774429,Spain";
countries["Sri Lanka"]="79.698303,5.943609,81.890533,9.826109,Sri Lanka";
countries["St Kitts Nevis"]="-62.863899,17.0917,-62.534199,17.410801,St Kitts Nevis";
countries["St Lucia"]="-61.079731,13.71778,-60.892231,14.10472,St Lucia";
countries["St Vincent and the Grenadines"]="-61.459309,12.57705,-61.1203,13.3842,St Vincent and the Grenadines";
countries["Sudan"]="21.828251,3.49214,38.621319,23.128,Sudan";
countries["Suriname"]="-58.071671,1.849444,-53.98444,5.997499,Suriname";
countries["Swaziland"]="30.80222,-27.31667,32.13422,-25.72834,Swaziland";
countries["Sweden"]="11.10694,55.001099,24.16707,69.063141,Sweden";
countries["Switzerland"]="5.965833,45.823879,10.48861,47.80637,Switzerland";
countries["Syria"]="35.590542,32.313599,42.373852,37.322182,Syria";
countries["Taiwan"]="120.053299,21.903049,121.999199,25.284161,Taiwan";
countries["Tajikistan"]="67.3647,36.672211,75.18747,41.050301,Tajikistan";
countries["Tanzania"]="29.59055,-11.72695,40.45332,-0.997581,Tanzania";
countries["Thailand"]="97.34581,5.631942,105.634399,20.455271,Thailand";
countries["Togo"]="-0.150955,6.099102,1.799956,11.13927,Togo";
countries["Tonga"]="-175.360596,-21.454201,-173.906097,-18.5681,Tonga";
countries["Trinidad And Tobago"]="-61.92445,10.03805,-60.928341,10.83861,Trinidad And Tobago";
countries["Tunisia"]="7.491666,30.236059,11.58333,37.338039,Tunisia";
countries["Turkey"]="26.03331,35.821659,44.82193,42.107208,Turkey";
countries["Turkmenistan"]="52.443321,35.145538,66.672501,42.797798,Turkmenistan";
countries["Turks and Caicos Islands"]="-73.706124,20.91527,-73.002792,21.332491,Turks and Caicos Islands";
countries["Tuvalu"]="178.842178,-8.128861,179.383103,-7.568621,Tuvalu";
countries["Uganda"]="29.578329,-1.464444,35.026089,4.22176,Uganda";
countries["Ukraine"]="22.151449,44.39526,40.179699,52.3797,Ukraine";
countries["United Arab Emirates"]="50.826099,22.057159,56.37582,26.083599,United Arab Emirates";
countries["United Kingdom"]="-8.164723,49.955269,1.7425,60.6311,United Kingdom";
countries["United States"]="-178.214203,18.536892,-48.466812,71.406647,United States";
countries["Uruguay"]="-58.438621,-34.977779,-53.095001,-30.100559,Uruguay";
countries["Uzbekistan"]="55.9972,37.185261,73.172997,45.57066,Uzbekistan";
countries["Vanuatu"]="165.777496,-19.64028,169.483902,-10.67167,Vanuatu";
countries["Venezuela"]="-73.383903,0.649722,-59.801392,12.19528,Venezuela";
countries["Viet Nam"]="102.140503,8.574163,109.459099,23.37582,Viet Nam";
countries["Western Sahara"]="-17.07361,20.770069,-8.667223,27.66885,Western Sahara";
countries["Yemen"]="42.61388,12.59972,53.078251,18.99888,Yemen";
countries["Zambia"]="21.998329,-18.075279,33.693039,-8.220806,Zambia";
countries["Zimbabwe"]="25.23666,-22.41614,33.07304,-15.61611,Zimbabwe";
function getCountry(lat, lng) {
var country = "none";
var best_area=99999999;
 for (c in countries) {
		parts=countries[c].split(",");
		p0 = parseFloat(parts[0]);
		p1 = parseFloat(parts[1]);
		p2 = parseFloat(parts[2]);
		p3 = parseFloat(parts[3]);
		if ((lng>p1) && (lng<p3)) {
			if ((lat>p0) && (lat<p2)) {
				var area = (p2-p0) * (p3 - p1);
				if (area<best_area) {
					best_area = area;
					country = c;
			  }
			}
		}
	}
	return country;
}

var hist=new Array();
var histsize=10;
var slot=-1;
var current=-1;
var reload=0;
var map;

function load() {
  if (GBrowserIsCompatible()) {
          map = new GMap2(document.getElementById("map"), {draggableCursor: 'pointer', draggingCursor: 'move'});
	    map.setCenter(new GLatLng(2.0, 17.0), 3);
			map.addControl(new GLargeMapControl());
			map.addControl(new GMapTypeControl());
			map.addControl(new GScaleControl());
			map.addControl(new GOverviewMapControl());
			GEvent.addListener(map, "click", function(marker, point) {
			    var lat_point;
			    var lng_point;
			    if (marker) {
			        map.removeOverlay(marker);
			        lng_point = 0;
			        lat_point = 0;
			    } else {
			        map.clearOverlays();
			        var marker2 = new GMarker(point)
			        map.addOverlay(marker2);
			        lat_point = point.lat();
			        lng_point = point.lng();

			    }


//			    var country1 = getCountry(lng_point, lat_point); ;
//			    alert(country1);
			    var strCountryName = getCountry(lng_point, lat_point); ;
//			    location.href = "List.aspx?CountryName=" + strCountryName;
			    location.href = "CountryMap.aspx?Country=" + strCountryName;

			});
	
  }
}

function getRequestObj() {
	req = false;
	if(window.XMLHttpRequest) {
		try {
			req = new XMLHttpRequest();
		} catch(e) {
			req = false;
		}
	}
	else
		if(window.ActiveXObject) {
			try {
				req = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				try {
					req = new ActiveXObject("Microsoft.XMLHTTP");
				} catch(e) {
					req = false;
				}
			}
		}
	return req
}

function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element =
				document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}
function makeHandleOnReadyStateChange(XmlHttp,div) {
	return function() {
		if (XmlHttp.readyState == 4) {
			if (XmlHttp.status == 200) {
				$(div).innerHTML=XmlHttp.responseText;
			}
		}
	}
}

function makeResponseFunction(XmlHttp,func) {
	return function() {
		if (XmlHttp.readyState == 4) {
			if (XmlHttp.status == 200) {
				func(XmlHttp)
			}
		}
	}
}

function asyncLoadDiv(url, postdata, div) {
	this.req=getRequestObj();
	if (this.req) {
		if (div!=null) {
			$(div).innerHTML='<div style="text-align: center; vertical-align\
:center"><br><br><br><br><img src="ajax-loader.gif"></div>'			
			this.req.onreadystatechange = makeHandleOnReadyStateChange(this.req,div);
		}
		this.req.open("POST", url, true);
		this.req.setRequestHeader('Content-Type',
			'application/x-www-form-urlencoded');
		this.req.send(postdata);
	}
}




function ajax(url,postdata,returnFunc) {
	this.req=getRequestObj();
	if (this.req) {
		if (returnFunc!=null) {
			this.req.onreadystatechange = makeResponseFunction(this.req,returnFunc);
		}
		this.req.open("POST", url, true);
		this.req.setRequestHeader('Content-Type',
			'application/x-www-form-urlencoded');
		this.req.send(postdata);
	}
}

function get_header() {
}

function get_host(url) {
	var host = ''
        var urlparts = url.split('://')
        if (urlparts.length>1) {
                    urlparts = urlparts[1].split('/')
                    host = urlparts[0]
	}
        return host; 
}


function get_news_items_html(news) {
	var retval = ''
	for (var n in news) {
		var clickurl = news[n]['ClickUrl'];
		var title = news[n]['Title'];
		retval += sprintf('<a class="story" href="%s">%s</a>',clickurl,title);
		retval += '<br>';
		var host = get_host(clickurl);
		retval += sprintf('<span class="sublabel">(%s)</span> ',host);               
		retval += sprintf('<a class="newtab" href="%s" target="_blank">%s</a><br>',clickurl,'open in new window');
	}
	return retval;
}

function get_wiki_link(country, quote_country) {
	return sprintf('Wikipedia link: <a href="http://en.wikipedia.org/wiki/%s">%s</a>',
		quote_country, country);
}

function hist_back() {
	ajax('/ajax_log','msg=back+clicked',null);
	if (current>0) current--;
	generate_content();
}

function hist_forward() {
	ajax('/ajax_log','msg=forward+clicked',null);
	if (current<slot) current++;
	generate_content();
}

function refresh() {
	ajax('/ajax_log','msg=reload+clicked',null);
	reload=1;
	var x = hist[current]['x'];
	var y = hist[current]['y'];
	var z = hist[current]['z'];
	$('message').innerHTML='<div style="text-align: center; vertical-align\
:center"><br><br><br><br><img src="ajax-loader.gif"></div>'
	ajax('/get_news_xyz_json','x='+x+'&y='+y+'&z='+z,country_callback);
}

function home() {
	ajax('/ajax_log','msg=home+clicked',null);
	slot=-1;
	current=-1;
	var message='<div><div class="ctryhdr">'
	message+='Welcome to Newsmap<br>'
        message+='<span class="sublabel">an experimental news site combining Google Maps with Yahoo&nbsp;News.</span>'
	message+='</div>'
	message+='<span class="gray">'
        message+='<ul>'
          message+='<li>Clicking on a country/region retrieves news about that country.</li>'
          message+='<li>Switch clickly to another continent by clicking on the continent links in the header.</li>'
          message+='<li>Zooming in one level will retrieve news at the state/provincial level.</li>'
          message+='<li>Currently state level news is available for US, Canada, UK(Home Nations) and Australia.</li>'
          message+='<li>Zooming in a second time will retrieve city news for large cities.</li>' 
          message+='<li>Over 3000 large cities are in the database.</li>'
          message+='<li>Zooming out again will retrieve news at the respective level.</li>'
        message+='</ul>'
      message+='</span><br>'
      message+='<center>Click on a country to start.</center>'
    message+='</div>'
    $('message').innerHTML=message;
}

function get_nav_buttons() {
	retval='';
	if (current>0) {
		retval+='<img src="/images/left-green.png" onclick="hist_back()" />';
	} else {
		retval+='<img src="/images/left-grey.png"/>';
	}
	if (current<slot) {
		retval+='<img src="/images/right-green.png" onclick="hist_forward()"/>';
	} else {
		retval+='<img src="/images/right-grey.png"/>';
	}
	if (slot>-1) {
		retval+='<img src="/images/reload-small.png" onclick="refresh()"/>';
	}
	retval+='<img src="/images/home.png" onclick="home()"/>';
	return '<div id="toolbar">'+retval+'</div>';
}

function generate_content(t) {
	var rsp = hist[current];
	var country=rsp['country'];
	var quote_country=rsp['quote_country'];
	var news=rsp['news'];
	var flag=rsp['flag'];
	var message = '';
	var wiki = get_wiki_link(country, quote_country);
	var nav_buttons = get_nav_buttons();
	if (flag) {
		message += '<div class="ctryinfo">';
		message += '<table width="100%"><tr><td width="50px" valign="bottom">';
		message += sprintf('<img src="%s" alt="%s flag" height="35px"></td>',flag, country);
		message += sprintf('<td align="left">%s',country);
                message += sprintf('<span class="sublabel"><br>%s</span></td>',wiki);
		message += sprintf('<td align="right" nowrap="nowrap">%s</td></tr></table></div>', nav_buttons);
	} else {
		message += '<div class="ctryinfo">';
		message += '<table width="100%"><tr>';
		message += sprintf('<td align="left">%s',country);
                message += sprintf('<span class="sublabel"><br>%s</span></td>',wiki);
		message += sprintf('<td align="right" nowrap="nowrap">%s</td></tr></table></div>', nav_buttons);
		t=country;
		//message=sprintf('<div class="ctryhdr">%s',country);
		//message+= nav_buttons;
		//message+=sprintf('<br><span class="sublabel">Wikipedia link: <a href="http://en.wikipedia.org/wiki/%s">%s</a></span><br></div>',quote_country, country);
	}
	message+=get_news_items_html(news);
	$('message').innerHTML=message;
	
}

function country_callback(XmlHttp) {
	var rsp=eval('('+XmlHttp.responseText+')');
	var code=rsp[0];
	if (code=='1') {
		rsp = rsp[1];
		if (reload==0) {
			if (current==histsize-1) hist.shift();
			else {
				current++;
				slot=current;
			}
			hist[slot]=rsp;
		} else {
			reload=0;
			hist[current]=rsp;
		}
		generate_content();
	} else {
		$('message').innerHTML=rsp[1];
	}
}

function switch_region(region) {
	switch(region) {
		case 'Africa': 	 map.setCenter(new GLatLng(2.0, 17.0), 3);
		break;
		case 'Australasia': 	map.setCenter(new GLatLng(-9.0,146.16), 3); 
		break;
		case 'East_Asia': 	map.setCenter(new GLatLng(34.0, 115.224), 3); 
		break;
		case 'Europe': map.setCenter(new GLatLng(56.365, 10.459), 3);
		break;
        case 'Middle_East': map.setCenter(new GLatLng(34.0, 39.0), 4);
		break;
		case 'North_America': map.setCenter(new GLatLng(44.21, -99.756), 3);
		break;
		case 'South_America': map.setCenter(new GLatLng(-24.367, -66.357), 3);
		break;
		case 'West_Asia': map.setCenter(new GLatLng(38.548, 69.521), 3);
		break;
	}
}

function set_region(region) {
	var regions=['Africa', 'Australasia', 'East_Asia', 'Europe', 'Middle_East','North_America', 'South_America', 'West_Asia'];
	for (var i=0; i<regions.length; i++) {
		$(regions[i]).style['background'] = '#ffea8d';
		$(regions[i]).style['color'] = '#1E1D57';
	}
	$(region).style['background'] = '#c0540b';
	$(region).style['color'] = '#FFFFFF';
	$('message').innerHTML='<div style="text-align: center"><br><br><\
br><br>Click on a region to start.</div>';
	var func=sprintf('switch_region("%s")',region);
    ajax('/ajax_log','msg='+func,null);
	setTimeout(func,10);	
}

function sprintf(){
	var parts=arguments[0].split('%s');
	var l=parts.length;
	var k=arguments.length;
	var retval=parts[0];
	for (i=1;i<l; i++) {
		if (i<k) retval+=arguments[i];
		retval+=parts[i];
	}
	return retval;
}








