/**
 * maputil.js 1.0 (24-Dec-2007)
 * (c) by Christian Effenberger 
 * All Rights Reserved
 * Source: mapper.netzgesta.de
 * Distributed under NSL
 * License permits free of charge
 * use on non-commercial and 
 * private web sites only 
**/

function makeSVGfromMap(obj,q,w,h,ifc,isc,hfc,hsc) {
	function getCl(cla,str,rep){var j,ar,pd,tt=rep; pd=(cla.indexOf(';')!=-1?cla.split(';'):pd=cla); for(j=0;j<pd.length;j++) {if(pd[j].indexOf(':')!=-1) {ar=pd[j].split(':'); if(ar[0].indexOf(str)!=-1) {tt=ar[1]; break;}}} return tt; }
	if(obj.tagName.toLowerCase()=="map") {
		var a,d,e,i,j,k,l,n,p,r,s,t,x,y,z,tmp,win,ele=obj.getElementsByTagName("area"); x=q?"<":"&lt;"; y=q?">":"&gt;"; z=q?"\n":"<br>";
		tmp =x+'?xml version="1.0" encoding="utf-8" standalone="no"?'+y+z;
		tmp+=x+'!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"'+y+z;
		tmp+=x+'svg width="'+(w||100)+'px" height="'+(h||100)+'px" viewBox="0 0 '+(w||100)+' '+(h||100)+'" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"'+y+z;
		tmp+=x+'title'+y+(obj.id||obj.name||"Unnamed")+x+'/title'+y+x+'desc'+y+'Generated with maputil.js (mapper.netzgesta.de)'+x+'/desc'+y+z;
		tmp+=x+'defs'+y+z+x+'script type="text/ecmascript"'+y+z+x+'![CDATA['+z+'var fdat="",sdat="";'+z;
		tmp+='function onAreaOver(evt){var ele=evt.target; fdat=ele.getAttribute("fill"); sdat=ele.getAttribute("stroke"); ele.setAttribute("fill","'+(hfc||"limegreen")+'"); ele.setAttribute("stroke","'+(hsc||"green")+'");}'+z;
		tmp+='function onAreaOut(evt){var ele=evt.target; ele.setAttribute("fill",fdat); ele.setAttribute("stroke",sdat);}'+z;
		tmp+=']]'+y+z+x+'/script'+y+z+x+'/defs'+y+z;
		for(i=0;i<ele.length;i++) {
			d=ele[i].coords.split(","); s=ele[i].shape; l=ele[i].title||ele[i].alt; p=''; a=ele[i].getAttribute('href'); t=l!=''?l:"area_"+i; e=""; n=ele[i].id||ele[i].name||t; e=ele[i].getAttribute('style');
			if(e!=null){k=getCl(e,'fill','silver')||ifc||"silver"; r=getCl(e,'stroke','gray')||isc||"gray";}else {k=ifc||"silver"; r=isc||"gray";}
			if(s.toLowerCase()=='rect') {
				tmp+=x+'a xlink:title="'+l+'" xlink:href="'+(a!=''?a:"#")+'"'+y+x+'rect id="'+n+'" fill="'+k+'" stroke="'+r+'" onmouseover="onAreaOver(evt);" onmouseout="onAreaOut(evt);" x="'+parseInt(d[0])+'" y="'+parseInt(d[1])+'" width="'+parseInt(d[2]-d[0])+'" height="'+parseInt(d[3]-d[1])+'" /'+y+x+'/a'+y+z;
			}else if(s.toLowerCase()=='circle') {
				tmp+=x+'a xlink:title="'+l+'" xlink:href="'+(a!=''?a:"#")+'"'+y+x+'circle id="'+n+'" fill="'+k+'" stroke="'+r+'" onmouseover="onAreaOver(evt);" onmouseout="onAreaOut(evt);" cx="'+parseInt(d[0])+'" cy="'+parseInt(d[1])+'" r="'+parseInt(d[2])+'" /'+y+x+'/a'+y+z;
			}else if(s.toLowerCase()=='poly') {
				for(j=0;j<d.length;j+=2) {p+=parseInt(d[j])+','+parseInt(d[j+1]); if((j+2)<d.length) {p+=',';}} 
				tmp+=x+'a xlink:title="'+l+'" xlink:href="'+(a!=''?a:"#")+'"'+y+x+'polygon id="'+n+'" fill="'+k+'" stroke="'+r+'" onmouseover="onAreaOver(evt);" onmouseout="onAreaOut(evt);" points="'+p+'" /'+y+x+'/a'+y+z;
			}
		}
		tmp+=x+'/svg'+y+z; if(q) {return tmp; }else {win=top.window.open('',"SVG"); win.document.open("text/html"); win.document.write("<pre>"+tmp+"</pre>"); win.document.close();}
	}
}