var map=null,geocoder=null,address="";function GetLatLng(){if(GBrowserIsCompatible()){address=Trim(document.getElementById("txtAddress").value);geocoder&&geocoder.getLatLng(address,ShowCoords)}}var isInitialized=false;
function Initialize(){if(GBrowserIsCompatible()&!isInitialized){alert("Enter valid Address and click 'Get Coordinates' to display map with Coordinates\n\nIf Coordinates are valid, click 'Add These Coordinates' to add to current Placemark");map=new GMap2(document.getElementById("map_canvas"));map.setCenter(new GLatLng(37.4419,-122.1419),13);geocoder=new GClientGeocoder;document.getElementById("divMapCoords").style.display="block";document.getElementById("txtAddress").focus();isInitialized=true}}
function ShowCoords(a){if(a){map.setCenter(a,13);var b=new GMarker(a);map.addOverlay(b);a=a.lat()+","+a.lng();b.openInfoWindowHtml('<span style="font-size:18px;">'+a+"</span><br /><br />"+address);document.getElementById("txtLatLong").value=a;document.getElementById("txtLatLong").className="DemoBox"}else{alert(address+" not found");document.getElementById("txtLatLong").value="";document.getElementById("txtLatLong").className=""}}var placeCount=0;
function AddPlacemark(){if(document.getElementById("txtPlaceName"+placeCount).value.length<2){alert("Please enter Name for current Placemark before adding new");document.getElementById("txtPlaceName"+placeCount).focus()}else if(document.getElementById("txtCoords"+placeCount).value.match(/^[\d,-\.]+$/)){placeCount++;var a,b;a=document.getElementById("tblPlacemarks");a=a.insertRow(a.rows.length);a.setAttribute("id","placeRow"+placeCount);var d=document.createElement("input");d.setAttribute("id","txtPlaceName"+
placeCount);d.style.width="220px";d.setAttribute("type","text");b=a.insertCell(a.cells.length);b.setAttribute("valign","top");b.appendChild(d);var c=document.createElement("input");c.setAttribute("id","txtCoords"+placeCount);c.style.width="140px";c.setAttribute("type","text");b=a.insertCell(a.cells.length);b.setAttribute("valign","top");b.appendChild(c);c=document.createElement("textarea");c.setAttribute("id","taDescription"+placeCount);c.style.width="190px";c.style.height="40px";b=a.insertCell(a.cells.length);
b.appendChild(c);c=document.createElement("a");c.setAttribute("href","javascript:RemovePlace("+placeCount+");");b=document.createElement("img");b.setAttribute("src","images/Delete.gif");b.style.width="16px";b.style.height="16px";b.setAttribute("border","0");b.setAttribute("alt","Remove Placemark");c.appendChild(b);b=a.insertCell(a.cells.length);b.appendChild(c);d.focus()}else{alert("Please enter valid Coords for current Placemark before adding new");document.getElementById("txtCoords"+placeCount).focus()}}
function RemovePlace(a){a=document.getElementById("placeRow"+a);if(a!=null){a.parentNode.removeChild(a);placeCount--}}function AddCoords(){var a=Trim(document.getElementById("txtLatLong").value);if(a.match(/^[\d,-\.]+$/)){document.getElementById("txtCoords"+placeCount).value=a;document.getElementById("txtCoords"+placeCount).className="DemoBox"}else alert("Please enter valid Coordinates")}
function BuildContent(){var a=document.getElementById("tblPlacemarks").getElementsByTagName("tr"),b='<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">\n\t<Document>\n\t\t<name>',d=Trim(document.getElementById("txtName").value);if(d.length<2){alert("Please enter a Name");document.getElementById("txtName").focus()}else{b+=d;b+="</name>\n\t\t<atom:author>\n\t\t\t<atom:name>";d=Trim(document.getElementById("txtAuthor").value);if(d.length<2){alert("Please enter Author");
document.getElementById("txtAuthor").focus()}else{b+=d;b+='</atom:name>\n\t\t</atom:author>\n\t\t<atom:link href="';d=Trim(document.getElementById("txtLink").value);if(d.indexOf("http://")==-1){alert("Please enter a valid URL for Link");document.getElementById("txtLink").focus()}else{b+=d;b+='" />';for(d=0;d<placeCount+1;d++){b+="\n\t\t<Placemark>\n\t\t\t<name>";var c=Trim(a[d].cells[0].childNodes[0].value);if(c.length<2){alert("Please enter a Place Name");a[d].cells[0].childNodes[0].focus();return}b+=
c;b+="</name>";c=Trim(a[d].cells[2].childNodes[0].value);if(c.length>0)b+="\n\t\t\t<description><![CDATA["+c+"]]\></description>";b+="\n\t\t\t<Point>\n\t\t\t\t<coordinates>";c=Trim(a[d].cells[1].childNodes[0].value);c=c.split(",");c=c[1]+","+c[0];if(!c.match(/^[\d,-\.]+$/)){alert("Please enter a valid Coordinate value for "+c);a[d].cells[1].childNodes[0].focus();return}b+=c;b+="</coordinates>\n\t\t\t</Point>\n\t\t</Placemark>"}b+="\n\t</Document>\n</kml>";document.getElementById("taContent").value=
b;document.getElementById("taContent").style.height=(placeCount+1)*100+140+"px";document.getElementById("divContent").style.display="block";document.location.href="#Step2"}}}}
function BuildMap(){if(Trim(document.getElementById("txtKmlUrl").value).match(/^http:\/\/.+\.kml$/)){document.getElementById("txtKmlUrl").style.backgroundColor="";var a='<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:geo="http://www.google.com/geo/schemas/sitemap/1.0">\n\t<url>\n\t\t<loc>';a+=Trim(document.getElementById("txtKmlUrl").value);a+="</loc>\n\t\t<geo:geo>\n\t\t\t<geo:format>kml</geo:format>\n\t\t</geo:geo>\n\t</url>\n</urlset>";
document.getElementById("taMap").value=a;document.getElementById("divMap").style.display="block";document.location.href="#Step4"}else{document.getElementById("txtKmlUrl").className="DemoBox";alert("Please enter a valid url for your Geomap Content\n\nEg: http://www.mysite.com/example.kml\n\nThis is the URL you uploaded (or will upload) your Content file to");document.getElementById("txtKmlUrl").focus()}}function Trim(a){return a.replace(/^\s\s*/,"").replace(/\s\s*$/,"")}
function Demo(){if(document.getElementById("txtName").value.length>0)if(!confirm("This will clear all current entries\n\nContinue ?"))return;if(placeCount>0)for(var a=placeCount;a>0;a--)RemovePlace(a);a=document.getElementById("txtName");var b=document.getElementById("txtAuthor"),d=document.getElementById("txtLink"),c=document.getElementById("txtPlaceName0"),e=document.getElementById("txtCoords0"),f=document.getElementById("taDescription0"),g=document.getElementById("txtKmlUrl");a.value="One Reader's View of Harry Potter";
a.className="DemoBox";b.value="J. K. Rowling";b.className="DemoBox";d.value="http://www.harrypotter.com";d.className="DemoBox";if(confirm("Enter a Name, Author and Link\n\nContinue ?")){a.className="";b.className="";d.className="";c.value="Hogwarts";c.className="DemoBox";e.value="-3.576327,50.620920";e.className="DemoBox";f.value="Harry Potter is a series of seven fantasy novels written by British author J. K. Rowling. The books chronicle the adventures of the adolescent wizard Harry Potter";f.className=
"DemoBox";if(confirm("Add a Placemark Name, its Coordinates and Description\n\nContinue ?")){c.className="";e.className="";f.className="";document.getElementById("btnShowMap").className="DemoBox";if(confirm("To find Coordinates from a known address click 'Enter Address to Get Map Coordinates'\n\nIf the address is valid, a Google map will be displayed with Coordinates and a button to add them\n\nDisplay Map and get Coordinates now ?")){document.getElementById("btnShowMap").className="";document.getElementById("btnAddPlacemark").className=
"";Initialize();document.getElementById("txtAddress").value="9 Macrossan Street, Port Douglas, QLD, Australia, 4877";document.getElementById("txtAddress").className="";GetLatLng();document.getElementById("btnAddCoordinates").className="DemoBox";alert("Click 'Add These Coordinates' to transfer map coordinates to current Placemark entry");document.getElementById("btnAddCoordinates").className=""}document.getElementById("btnShowMap").className="";document.getElementById("btnAddPlacemark").className=
"DemoBox";if(confirm("You can add Placemarks with 'Add Placemark' button and click cross to remove\n\nContinue ?")){document.getElementById("btnAddPlacemark").className="";if(confirm("Click 'Create Content' to display the contents\n\nClick, then right click, copy and paste into Notepad. \n\nSave as eg: exaple.kml and upload to your site\n\nContinue ?")){BuildContent();g.value="http://www.yoursite.com/example.kml";g.className="DemoBox";if(confirm("Now enter the address (Url) of the file you just created, saved and uploaded. eg: http://www.yoursite.com/example.kml\n\nClick 'Create Geo Sitemap' to display the Sitemap\n\nContinue ?")){g.className=
"";BuildMap();alert("Copy, paste into Notepad, save as eg: geo-sitemap.xml and upload to the root of your site\n\n add your Geo Sitemap using Google Webmaster Tools and your Google Account")}}}}}};