//<![CDATA[
/*
*Creates an Open atlas object with it's Map 
*/
function OpenAtlas()
	{
		this.groupT = new Array();//array of GROUP objects
		this.userT = new Array();//Array of USER objects
		//openCustomMap(id,lat,long,maxlat,maxlong,zoom,path,opal.map.getMapTypes()[2],listxy);
		this.mapT = new Array();//Array of custom maps obj = {id , Name , lat , lon , maxlat, maxlong , zoom , maxzoom,listxy,path} 
		this.searchcrum ="";
		this.debug = false;
		this.debughtml="";
		this.map = new GMap2(document.getElementById("map"),{
                 mapTypes : [G_SATELLITE_MAP,G_NORMAL_MAP]
              });
		
		//adding my own custom map
		//CopyRights
	    var copyright = new GCopyright(1,new GLatLngBounds(0, 0, 0, 0), 0, "opal test");
    	var copyrightCollection = new GCopyrightCollection('Custom Layer');
		copyrightCollection.addCopyright(copyright);
	 
	    // Set Path to Our Custom Map Image Tiles
		var tilelayers = [new GTileLayer(copyrightCollection , 0, 25)]; 
		tilelayers[0].getTileUrl = CustomGetTileUrl;
				
	    // Map Display name in the auto-generated maplink in the top right corner.
	    // Register the new mapType with the running google map.
		var custommap = new GMapType(tilelayers, G_SATELLITE_MAP.getProjection(), "CustomLayer", {errorMessage:"No chart data available"});
		this.map.addMapType(custommap);
		 
		this.map.addControl(new GSmallMapControl());
		this.map.addControl(new GMapTypeControl());
		this.map.addControl( new GScaleControl() ) ; 
		this.marker = new PdMarker(new GLatLng(0, 0));
	}

function CustomGetTileUrl(a,b) 
	{ 	
		var custom = false;
		 //based on an array : globlistxy [[Z,X,Y,MX,MY],...]
		for(var ix = 0 ; ix < globlistxyT.length && !custom ; ix++)
		{	
			if (b==globlistxyT[ix][0] && a.x>=globlistxyT[ix][1] && a.x<=globlistxyT[ix][3] && a.y>=globlistxyT[ix][2] && a.y<= globlistxyT[ix][4])
				custom = true; 
		}
		if(custom) 
			return cpath+tilepath+'/Tile_'+a.x+'_'+a.y+'_'+b+'.png';
         else 
          return G_SATELLITE_MAP.getTileLayers()[0].getTileUrl(a,b);
	}

OpenAtlas.prototype.empty = function()
	{
		//clean groupT
		var delx = "";
		var gpl = countT(this.groupT)[1];
		var ul = countT(this.userT)[1];
		if(gpl>2)
			for(delx in this.groupT)
				if(delx!="copy" && delx!="each")
				   	this.groupT[delx].remove();

	   	//clean userT
	   	if(ul>2)
		   	for(delx in this.userT)
		   		if(delx!="copy" && delx!="each")
					this.userT[delx].remove();

	}

OpenAtlas.prototype.toString = function(){
	return "groups list : "+countT(this.groupT)[0]+"\nnum groups :"+countT(this.groupT)[1]+", \n user list : "+countT(this.userT)[0]+"\ncount:"+countT(this.userT)[1];
}


OpenAtlas.prototype.addUser = function(active_marker)
	{
		//alert((new XMLSerializer()).serializeToString(active_marker.getElementsByTagName('user')[0]));
		var latlng = null;
		var fathertype = active_marker.getAttribute("fathertype");
		var username = active_marker.getAttribute("user");
	    if(!this.userT[username])
	    {
	    	if(active_marker.getElementsByTagName('user')[0] && active_marker.getElementsByTagName('user')[0].getAttribute("lat")!='0' && active_marker.getElementsByTagName('user')[0].getAttribute("lng")!='0')
				latlng = new GLatLng(active_marker.getElementsByTagName('user')[0].getAttribute("lat") , active_marker.getElementsByTagName('user')[0].getAttribute("lng"));
			else 
				latlng = new GLatLng(active_marker.getAttribute("lat"),active_marker.getAttribute("lng"));  
			
			//select icon if user islogged or not 
	    	var i = (in_T(connectedT,username)) ? iconT["logpone"] : iconT["pone"];
	    	
	    	//create user instance in userT
	        this.userT[username] = new User(username,latlng,i);
	        
	        if(active_marker.getElementsByTagName('user')[0])
		    {
		    	this.userT[username].name = active_marker.getElementsByTagName('user')[0].getAttribute("name");
		    	this.userT[username].lastname = active_marker.getElementsByTagName('user')[0].getAttribute("lastname");
		    	//alert("latlng in adduser :"+active_marker.getElementsByTagName('user')[0].getAttribute("lng")+","+active_marker.getElementsByTagName('user')[0].getAttribute("lat"));
		    }
	    }
		
		//check if type isn not allready in menuT
		if(!in_T(this.userT[username].menuT,fathertype))
		 	this.userT[username].menuT.push(fathertype);
	}

//closes all the open Groups 
OpenAtlas.prototype.closeGroups = function ()
	{
		for(var ix in this.groupT){
			if(ix!="copy" && ix!="each" && this.groupT[ix].marker && this.groupT[ix].marker.onMap == false){
				for(var tx = 0 ; tx < this.groupT[ix].markerT.length ; tx++){
					this.map.removeOverlay(this.groupT[ix].markerT[tx]);	
					this.groupT[ix].markerT[tx].onMap = false;
				}
				this.map.addOverlay(this.groupT[ix].marker);	
				this.groupT[ix].marker.onMap = true;
			}
		}	
	}


/****************************************
*  DRAWING LIBS
****************************************/	
//does all the marker creation , map overlaying, 
//Todo : visible or not and clustering rules
OpenAtlas.prototype.Draw = function()
	{
		//alert(this);
		if(this.debug)
			this.debughtml="<p>"+this+"<br/>********************************************<br/></p>";
		//draw markers for each theme
		if(data!="mono")
		{
			if(countT(this.groupT)[1]>2)
			{
				for(var pp in this.groupT)
				{
					//if these are group marker(grp structure), only draw containers
					if(pp != "copy" && pp != "each")
					{
						if(this.groupT[pp].gpid)
						{
							if(!this.groupT[pp].marker)
								this.groupT[pp].markerSetUp();
							opal.map.addOverlay(this.groupT[pp].marker);
							this.groupT[pp].marker.onMap = true; 
						} //else draw all contained latlngs
						else if(this.groupT[pp].markerT)
						{
							for(var ix = 0; ix < this.groupT[pp].markerT.length ;ix++)
							{
								
								//remove latlngs off non requested user
								if(user && this.groupT[pp].markerT[ix].onMap == true 
										&& this.groupT[pp].markerT[ix].getUserData() != user)
								{
									//alert("remove"+this.groupT[pp].markerT[ix].getUserData());
									opal.map.removeOverlay(this.groupT[pp].markerT[ix]);
									this.groupT[pp].markerT[ix].onMap = false; 
								}//draw latlngs for all or for requested user 
								else if(!this.groupT[pp].markerT[ix].onMap 
									&& (user == '' || this.groupT[pp].markerT[ix].getUserData()==user))
								{	
									opal.map.addOverlay(this.groupT[pp].markerT[ix]);
									this.groupT[pp].markerT[ix].onMap = true; 
								}
								
							}
						}
						if(this.debug && pp!="copy" && pp!="each")
							this.debughtml += "<p>"+this.groupT[pp]+"</p>";
					}
				}
			}
		}
		
		//???why is the copy and each as default elements of the userT tab
		if(countT(this.userT)[1]>2)
		{
			for(var u in this.userT){
				if(u!="copy" && u!="each" && this.userT[u].username && this.userT[u].marker.onMap==false)
					this.drawUser(u);
				if(this.debug && u!="copy" && u!="each")
					this.debughtml += "<p>"+this.userT[u]+"</p>";
			}
		}
		
		//this means there are more than one group
		if(countT(this.groupT)[1]>3)
		{
			var fgpname = getFirstName(this.groupT);
			//if this has a group structure draw according to design pattern gpstruct
			if(this.groupT[fgpname].gpid && this.groupT[fgpname].subGroupT.length > 0)
				this.groupT[fgpname].drawStruct("linkgroups");
		}
		
		//write in the title the requested context			
		if(this.searchcrum!=""&&gId('QUM1'))
			gId('QUM1').firstChild.innerHTML = this.searchcrum+this.debughtml
//				" <a class='menugreentxt' href='javascript:showHide(\"searchbuild\")'>Search</a></h3>";
	}

OpenAtlas.prototype.drawUser = function(u) 
	{	
		//will contain only main categories
		var drawMenuT = [];
		//menuT contains all fathertypes
		for(var mx=0; mx < this.userT[u].menuT.length ; mx++)
		{
			var fathertype = this.userT[u].menuT[mx];
			if(!in_T(drawMenuT,fathertype))
			{
				drawMenuT.push(fathertype);
				var actionlink = "data=\"multi\"; user=\""+this.userT[u].username+"\"; getMarkerby(\"\",\""+fathertype+"\",\"\",false);";
				this.userT[u].marker.addHtmlDetailWin("<div><a class='menugreentxt' href='javascript:"+actionlink+"'>"+fathertype+"<\/a><\/div>");
			}
		}
		if(mx > 1)
		{
			//link to show all users latlngs
			actionlink = "data=\"multi\"; user=\""+this.userT[u].username+"\"; getMarkerby(\"\",\"\",\"\",false);";
			this.userT[u].marker.addHtmlDetailWin("<div><a class='menugreentxt' href='javascript:"+actionlink+"'>All<\/a><\/div>");
		}
		
		var name = (this.userT[u].name) ? " : "+this.userT[u].name+" "+this.userT[u].lastname : "";
		var changeloc = (logged == u) ? "<br/><a href='javascript:PdMarkerClose("+this.userT[u].marker.internalId+"); addlatlng2Map(\"member\","+this.userT[u].marker.getPoint().x+","+this.userT[u].marker.getPoint().y+");'>Change location<\/a>" : "";
		var sendmsg = (logged != "false" && logged != u && this.userT[u].marker.icon == iconT["logpone"] )?"<br/><a href='javascript:var msg = prompt(\"This message will be send to "+u+" :\",\"your message\" ); if(msg)saveChat(\""+u+"\",msg);'>Send a message to "+u+"<\/a>" : "";
		this.userT[u].marker.addHtmlDetailWin("<div style='white-space:nowrap'><a href='?user="+u+"'>"+this.userT[u].username+name+"<\/a>"+changeloc+sendmsg+"<\/div>");

		opal.map.addOverlay(this.userT[u].marker);
		this.userT[u].marker.onMap = true;
		//alert("Draw "+this.userT[u]);
	}

//drawing section in gathered above structures
function drawByType(gpid, gpT, Tlatlngs, gtype, globtype, gpstruct,centerLatLng)
	{
	  if(!gpid && (gpstruct=="linear" || globtype=="sciencedata")){
	      for(var ct = 0 ; ct < gpT.length ; ct+=2){
	      	  drawPoly(gpT[ct+1],Tlatlngs[gpT[ct]]);
	      }
	  } 
	  //draws and links all the latlngs inside a group 
	  else if(gpid && Tlatlngs.length != 0 && gpstruct!="latlng")
	  	drawGroup(gpstruct,Tlatlngs,centerLatLng,gtype);
	  else if(gtype && gtype!="latlng")
	  	drawPoly(gtype,Tlatlngs);
	}

//draws a simple poluline or a polygone with an Array of latlngs
function drawPoly(gtype,geomT)
	{
		var hcolor = "#FF0000";//genHex();
		if(gtype == 'area'){
			//alert("draw poly "+gtype+geomT.length);
			opal.map.addOverlay(new GPolygon(geomT,hcolor,2,1,hcolor,0.5));
		} else {
	        opal.map.addOverlay(new GPolyline(geomT,hcolor,2,1));
	    } 
	}
	
//according to gtype lines or area from one latlng to all other latlngs of an Array of latlngs
function lineOne2All(geomT,latlng, style,gtype)
	{
		for(var ft=0 ; ft < geomT.length ; ft++)
			opal.map.addOverlay(new GPolyline([geomT[ft],latlng] , style.color , style.weight , style.opacity));
		if(gtype=="area"){
			geomT.push(latlng);
	        drawPoly(gtype,geomT);   
	    }
	}
	
/************* User Class*******************/
function User(username,latlng,icon)
	{
		this.username = username;
		this.menuT = new Array();//array of string of father thematics of this User 
		this.groupT = new Array();//array of [type]
		this.latlng = latlng;
		this.icon = icon;
		this.marker = new PdMarker(latlng , icon);
		this.marker.setTooltip(this.username);
		this.name = null;
		this.lastname = null;
		/*this.type = null;
		this.sex = null;
		this nationality = null;
		this.profession = null;
		this.sexo = null;
		this.photo = null;*/
		var Xuser = this;
		GEvent.addListener(this.marker, "click", function() {
			data = "multi";
			user = username;
			opal.map.removeOverlay(this.marker);
	  	});
	}

//User Class destructor
User.prototype.remove = function()
	{
		//alert("remove user"+this);
   		//clean inside menuT
   		for(var mx = 0; mx < this.menuT.length; mx++)
   			this.menuT[mx] = null;
   		this.menuT = null;
   		//clean inside groupT
   		for(mx = 0; mx < this.groupT.length; mx++)
   			this.groupT[mx] = null;
   		this.groupT = null;
   		if(this.marker)
	   		this.marker.remove();
   	}

User.prototype.toString = function()
	{
		return this.username+" : pos:"+this.latlng+" ,\ncontains grp :"+this.groupT.length+" : \nmenuT : "+this.menuT.length+"\n onMap : "+this.marker.onMap;
	}
	
User.prototype.addmenu = function(type)
	{
		this.menuT.push(type);
	}

/************ Group CLass *****************/
function Group(gpname,gpid,gpstruct,gtype,centerLatLng,icon,pos){
	this.gpname = gpname;
	this.gpid = gpid;
	this.gpstruct = gpstruct; //distrib,central,linear,latlng
	this.gtype = gtype; //latlng,lines, area
	this.centerLatLng = centerLatLng; //Glatlng
	this.markerT = new Array(); //is an array of PdMarkers
	this.subGroupT = new Array(); //is an array of GroupName:user+gpid stored as groups in opal.groupT
	this.marker = null;//is PdMarker
	this.icon = iconT["gpe"];
	this.pos = pos; //position in opal.groupT array
}

//Group Class destructor
Group.prototype.remove = function()
	{
   		for(var mx = 0; mx < this.markerT.length; mx++)
   			this.markerT[mx] = null;
   		this.markerT = null;
   		//clean inside subGroupT
   		for(mx = 0; mx < this.subGroupT.length; mx++)
   			this.subGroupT[mx] = null;
   		this.subGroupT = null;
   		if(this.marker)
	   		this.marker.remove();
	}

Group.prototype.toString = function(){
	return this.pos+" - "+this.gpid+" - "+this.gpname+"\n marker num :"+this.markerT.length+"\n SubGroup num :"+this.subGroupT.length+"\non Map:"+this.marker.onMap;
}

Group.prototype.markerSetUp = function()
	{
		var gp = this;
		gp.marker = new PdMarker(gp.centerLatLng ,gp.icon);
		gp.marker.setTooltip(gp.gpname+" contains "+gp.markerT.length+" latlngs<br/>Click to open.");
		GEvent.addListener(gp.marker, "mouseover", function() {
			this.setImage(cpath+"gfx/maps/icons/023+.gif"); // change graphic
			this.topMarkerZIndex(); // bring marker to top
		}); 
	
		GEvent.addListener(gp.marker, "mouseout", function() {
			this.restoreImage();
			this.restoreMarkerZIndex();
		});
	    
	    GEvent.addListener(gp.marker, "click", function() {
	    	opal.closeGroups();
			gp.open();
  		});  
	}

//first closes anu other opened group then displays all the markers in the group
Group.prototype.open = function()
	{
		//alert("open "+this);
		for(var x = 0 ; x < this.markerT.length ; x++)
		{
			opal.map.addOverlay(this.markerT[x]);	
			this.markerT[x].onMap = true;
		}
		this.drawStruct("linkmarkers");
		opal.map.removeOverlay(this.marker);
		this.marker.onMap=false;
	}
	
//build but does not show overlay the create marker
//instanciates PdMarker and fills this.markerT
Group.prototype.AddMarker = function(active_marker){
	var iuser = active_marker.getAttribute("user");
	if(active_marker.getAttribute("type")!="user")
	{
		var latlng = new GLatLng(active_marker.getAttribute("lat"),active_marker.getAttribute("lng"));         
		var marker_icon = null;
		if(iconT[themeT[active_marker.getAttribute("fathertype")+"_"+active_marker.getAttribute("type")]]==null)
			iconT[themeT[active_marker.getAttribute("fathertype")+"_"+active_marker.getAttribute("fathertype")]];
		else
	    	marker_icon = iconT[themeT[active_marker.getAttribute("fathertype")+"_"+active_marker.getAttribute("type")]];
	    	
	    var marker = new PdMarker(latlng , iconT[themeT[active_marker.getAttribute("fathertype")+"_"+active_marker.getAttribute("type")]]);
	
		var tip = active_marker.getAttribute("name");
	    if(active_marker.getAttribute("path"))
	        tip = tip + "<br/><img height='100' src='"+cpath+active_marker.getAttribute("path")+"'/>";
	    
	    marker.setTooltip(tip);
		marker.setUserData(iuser);
	
	    var html = active_marker.getElementsByTagName('code')[0].firstChild.nodeValue;
	    marker.setDetailWinHTML(html);
	
	   	this.markerT.push(marker);
	}
   	
   	//creates the user icon and fills the menu
   	opal.addUser(active_marker);

   	//when we fill a group for a user we fill his groupT
   	if(!opal.userT[iuser].groupT[active_marker.getAttribute("fathertype")])
   		opal.userT[iuser].groupT[active_marker.getAttribute("fathertype")] = opal.groupT.length;
}

//links groups and subgroups togeether according to specified structure 
Group.prototype.drawStruct = function(type)
	{
		var hcolor = "#FF0000";//genHex();
		var style = {color: hcolor, weight:2, opacity:1};
		var fillstyle = {color: hcolor, opacity:0.5};
		
		var geomT = [];
		if(type == "linkgroups")
		{
			for(var ix = 0; ix < this.subGroupT.length ; ix++){
				geomT.push(opal.groupT[this.subGroupT[ix]].centerLatLng);
				//recursif untill no more subgroups
				//if(opal.groupT[this.subGroupT[ix]].subGroupT.length > 0)
					//opal.groupT[this.subGroupT[ix]].drawStruct();
			}
		} //this will be a Tab of MArker from the group class
		else
			for(var ix = 0; ix < this.markerT.length ; ix++)
				geomT.push(this.markerT[ix].getPoint());
				
		//alert("this group contains subGp: "+this.gpstruct+"/"+geomT.length+"/"+this.centerlatlng+"/"+this.gtype);
		
		if(this.gpstruct == 'linear'){
			geomT.push(this.centerLatLng);
			drawPoly("linear",geomT);
		}
		else if(this.gpstruct == 'central')
			lineOne2All(geomT,this.centerLatLng,style,this.gtype);
		else if(this.gpstruct == 'distrib')
	        for(var xt=geomT.length-1 ; xt > -1 ; xt--)
	        	lineOne2All(geomT,geomT.pop(), style,this.gtype); 	
	}

/****************************************
*  XML Parsing
****************************************/
//Xml manipulation of data to draw it on the map
function getData(xmlDoc)
	{	
		//alert((new XMLSerializer()).serializeToString(xmlDoc));
		var groups = xmlDoc.getElementsByTagName("markers");
		//alert("new groups :"+groups.length);
		if(xmlDoc.getElementsByTagName("marker").length>0)
		{
		  for (var gi = 0; gi < groups.length; gi++) 
		  {
		  	  var active_group_tag = groups[gi];
		  	  //make sure the group is not empty
		  	  if(active_group_tag.hasChildNodes())
		  	  {
		  	  	var active_group = new Group();
				
				//group specifications
				active_group.gpid = active_group_tag.getAttribute("gpid");
				active_group.gtype = active_group_tag.getAttribute("gtype");
				active_group.gpstruct = active_group_tag.getAttribute("gpstruct");
				active_group.gpname = active_group_tag.getAttribute("gpname");
				
				//set up index latlnger on first marker
				var active_marker = active_group_tag.firstChild;
				var coor = (active_group.gpstruct=="central") ? active_group_tag.getAttribute("gpcenter").split(","):"";
				active_group.centerLatLng = (coor) ? new GLatLng(coor[1],coor[0]) : new GLatLng(active_marker.getAttribute("lat"),active_marker.getAttribute("lng"));
				
				//writes the title of the search
				if(opal.searchcrum)
			  	  opal.searchcrum += " ("+xmlDoc.getElementsByTagName("marker").length+" points)";
			  	  
				var gpcrit = "";
				//scan all markers of this group
				while(active_marker != null && active_marker.nodeName == "marker") 
				{
					//when data == mono only show users			    				
					if(data != "mono")
						active_group.AddMarker(active_marker);	
					else
						opal.addUser(active_marker);			
						
					//go on to next marker
				    if(active_marker.nextSibling)
					    active_marker = active_marker.nextSibling;
					else 
						active_marker = null;		
				} 
				//organize groups and subgroups 
				if(data !="mono")
				  {
				  	  active_group.pos = opal.groupT.length;
				  	  var gpName = (active_group.gpid) ? active_group_tag.getAttribute("user")+active_group.gpid+globtype+globtime : user+globtype+globtime;
					  opal.groupT[gpName] = active_group;
					  //if this markers contains other markers then it is a group structure with subgroups 
					  if(active_group_tag.getElementsByTagName("markers").length>0)
					  {
					  	var subGroups = active_group_tag.getElementsByTagName("markers");
					  	for(var xt = 0 ; xt < subGroups.length ; xt++)
					  		active_group.subGroupT.push(subGroups[xt].getAttribute("user")+subGroups[xt].getAttribute("gpid"));
					  }
				  }
			  }
			  //if custom is click or active, builds the List of Custom Maps to draw outline bounds
			  if(onCustomlayer==true && opal.mapT.length <= 0){
			  	getMaps(xmlDoc);
			  }
		}//end for groups
	  }
	  document.getElementById("loadmsgdiv").style.display = "none";
	  document.getElementById("loader").style.display = "none";
	}

//Builds the 
function getMaps(xmlDoc)
	{
		if(opal.mapT.length == 0)
		{
			var allMarkers = xmlDoc.getElementsByTagName("marker");
			if(allMarkers.length>0)
			{
				//scan all markers
				for (var ix = 0; ix < allMarkers.length; ix++) 
		  		{
		  			active_marker = allMarkers[ix];
					//when data == mono only show users			    				
					if( active_marker.getAttribute("fathertype") == "maps" )
					{
						var mlat = active_marker.getAttribute("lat");
						var mlng = active_marker.getAttribute("lng");
						var mmaxlat = active_marker.getAttribute("maxlat");
						var mmaxlng = active_marker.getAttribute("maxlng");
						
						var map = {id : active_marker.getAttribute("id") ,  
								user : active_marker.getAttribute("user") , 
								name : active_marker.getAttribute("name") , 
								lat : mlat,
								lon : mlng, 
								maxlat : mmaxlat, 
								maxlon : mmaxlng , 
								zoom : active_marker.getAttribute("zoom") , 
								maxzoom : active_marker.getAttribute("maxzoom"),
								listxy : active_marker.getAttribute("listxy"),
								tilepath : active_marker.getAttribute("tilepath"),
								overlay : new GPolyline([new GLatLng(mlat,mlng),							
														new GLatLng(mmaxlat,mlng),
														new GLatLng(mmaxlat,mmaxlng),
														new GLatLng(mlat,mmaxlng),
														new GLatLng(mlat,mlng)],"#FF0000",2,1)};
						//gather all custom maps in mapT
						opal.mapT.push(map);	
					}
				} 
				
			}
		}
	}

function DrawMapBounds(bool)
	{
		for (var ix = 0; ix < opal.mapT.length; ix++) 
		{
			var map = opal.mapT[ix];
			//draw the maps bounds according to current lat long and bounds
			if(bool)
				opal.map.addOverlay(map.overlay);
			else
				opal.map.removeOverlay(map.overlay);
		}
	}
//Xml manipulation of data to draw it on the map
function drawXMLData(xmlDoc){/* deprecated
	//scan on PlaceMark tags
	var clusterer = new Clusterer( opal.map );
	var placemark = xmlDoc.getElementsByTagName('Placemark');
	var wpt = xmlDoc.getElementsByTagName('wpt');
	var markers = "";
	var desc = "";
	var name = ""; 
	if(placemark.length > 0 ){
		markers = placemark;
		desc = "description";
		name ="name";
	}
	else if(wpt.length > 0){
		markers = wpt;
		desc = "desc";
		name="name";
	}else 
		alert("This Format cannot not be previewed, please contact us.")
	if(markers != "")
	{
	    for(i=0;i<markers.length;i++){
			var lat="";
	       	var lng="";
	    	//Coordinate information
	    	if(placemark.length>0)
	    	{
				var coord = markers[i].getElementsByTagName('coordinates')[0].firstChild.nodeValue;
		       	var multicoord = coord.split(" ");
		       	
		       	if( multicoord.length > 1) {
					//multiple coordinates
			      	//inputcoord.setAttribute("name" , "multicoord"+i);
			      	//inputcoord.setAttribute("value" , coord);
					lat = multicoord[0].split(",")[1];
					lng = multicoord[0].split(",")[0];
			    } else {
					var coordT = coord.split(",");
					lng = coordT[0];
					lat = coordT[1];
			    }
			 }else if(wpt.length > 0 )
			 {
			 	lng = markers[i].getAttribute("lon");
				lat = markers[i].getAttribute("lat");
			 }
		    
	    	if(lng.length > 10)
				lng = lng.substring(0,10);
		  	if(lat.length > 10)
		  		lat = lat.substring(0,10); 
		    	    
		    var marker = new PdMarker(new GLatLng(parseInt(lat),parseInt(lng)) , iconT["default"]);
		    var name = "";
			if(markers[i].getElementsByTagName(name)[0])
				name = markers[i].getElementsByTagName(name)[0].firstChild.nodeValue;
			else 
				name=""+i;
		    marker.setTooltip(name);
		    var html = "";
		    if(markers[i].getElementsByTagName(desc)[0])
				html = markers[i].getElementsByTagName(desc)[0].firstChild.nodeValue;
		    marker.setDetailWinHTML(html);
		    clusterer.AddMarker( marker, name ,"kml");
	    }
	}
	document.getElementById("loadmsgdiv").style.display = "none";
	document.getElementById("loader").style.display = "none";*/
}



//]]>
