
Utils = {
	strToBool:function(value){
		if (value!=null){
			value = value.toLowerCase();
			if ((value=='true')||(value=='t')||(value=='y')||(value=='1')) return true;
			if ((value=='false')||(value=='f')||(value=='n')||(value=='0')) return false;
		}
		return false;
	},
	round:function(value,prec){
		var mno = 1.0;
		for (var i=0;i<prec;i++) mno*=10.0;
		var w = Math.round(value*mno)/mno;
		var wt = w.toString();
		if (wt.indexOf('.')==-1) {
			wt+='.';
			for (var j=0;j<prec;j++) wt+='0';
		}
		return wt;
	},
	textToXml:function(text){
		try {
			xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc.async="false";
			xmlDoc.loadXML(text);
			return xmlDoc;
		}
		catch(e){
			var parser=new DOMParser();
			var xmlDoc=parser.parseFromString(text,"text/xml");
			return xmlDoc;
		}
	},
	HexToRGB:function(h){
		h = h.replace('#','');
			
		
		if (h.length==3){
			h = h[0]+''+h[0]+''+h[1]+''+h[1]+''+h[2]+''+h[2]+'';
		}	
		
		return [parseInt(h.substring(0,2),16),parseInt(h.substring(2,4),16),parseInt(h.substring(4,6),16)];
	},
	replaceNl:function(war){
		while (war.indexOf('\n')!=-1){
			war = war.replace('\n','<br/>')
		}
		return war;
	},
	replaceNlBack:function(war){
		while (war.indexOf('<br/>')!=-1){
			war = war.replace('<br/>','\n')
		}
		return war;
	},		
	isIE:function() {
		return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
	},
	isEmpty:function(s){
		return ((s == null) || (s.length == 0))
	},
	isFloat:function(val){
		if (val.indexOf("-")==0) val = val.substr(1);
		var reFloat = /^((\d+(\.\d*)?)|((\d*\.)?\d+))$/
		return reFloat.test(val)	
	},
	isInteger:function(s){
		return Math.floor(s) == s ? true : false;
	},
	isDate:function(data){
		if (data.length!=10) return false;
		var Y = data.substring(0,4);
		if (Utils.isInteger(Y)==false){
			return false;
		}
		var t = data.substring(4,5);
		if (t!='-'){
			return false;
		}	
		var m = data.substring(5,7);
		if (Utils.isInteger(m)==false){		
			return false;
		}
		var mf = parseFloat(m);
		if ((mf<=0)||(mf>12))	return false;
		
		t = data.substring(7,8);
		if (t!='-'){
			return false;
		}		
		
		var d = data.substring(8,10);
		if (Utils.isInteger(d)==false){		
			return false;
		}
		var df = parseFloat(d);
		if ((df<=0)||(df>31))	return false;
		
		return true;
	},
	isTimestamp:function(data){
		var Y = data.substring(0,4);
		if (Utils.isInteger(Y)==false){
			return false;
		}
		var t = data.substring(4,5);
		if (t!='-'){
			return false;
		}	
		var m = data.substring(5,7);
		if (Utils.isInteger(m)==false){		
			return false;
		}
		var mf = parseFloat(m);
		if ((mf<=0)||(mf>12))	return false;
		
		t = data.substring(7,8);
		if (t!='-'){
			return false;
		}		
		
		var d = data.substring(8,10);
		if (Utils.isInteger(d)==false){		
			return false;
		}
		var df = parseFloat(d);
		if ((df<=0)||(df>31))	return false;

		var d = data.substring(12,14);
		if (Utils.isInteger(d)==false){		
			return false;
		}
		var df = parseFloat(d);
		if ((df<=0)||(df>31))	return false;
		
		return true;
	}
}
Ajax = {
	post:function(url,param,onload){
		advAJAX.post({
			url : url,
			parameters : param, 
			onSuccess : function(obj) {
				onload(obj);
			},
			onError : function(obj) { alert("blad: " + obj.status); },
			onTimeout : function() { alert("Connection timed out."); },
			onRetry : function() { alert("Retry connection..."); },
			onRetryDelay : function() { alert("Awaiting retry..."); },
			onError : function(obj) { alert("Error: " + obj.status); }
		});					
	},
	get:function(url,param,onload){
		advAJAX.get({
			url : url,
			parameters : param, 
			onSuccess : function(obj) {
				onload(obj);
			},
			timeout : 10000,
			onTimeout : function() { alert("Connection timed out."); },
			onRetry : function() { alert("Retry connection..."); },
			onRetryDelay : function() { alert("Awaiting retry..."); },
			onError : function(obj) { alert("Error: " + obj.status); }
		});					
	}
}

/*
 * Raphael 1.0 RC1.3 - JavaScript Vector Library
 *
 * Copyright (c) 2008 - 2009 Dmitry Baranovskiy (http://raphaeljs.com)
 * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
 */
window.Raphael=(function(){var y=/[, ]+/,F=document,m=window,q={was:"Raphael" in window,is:window.Raphael},E=function(){return J.apply(E,arguments);},B={},O={"clip-rect":"0 0 10e9 10e9",cx:0,cy:0,fill:"#fff","fill-opacity":1,font:'10px "Arial"',"font-family":'"Arial"',"font-size":"10","font-style":"normal","font-weight":400,gradient:0,height:0,href:"http://raphaeljs.com/",opacity:1,path:"M0,0",r:0,rotation:0,rx:0,ry:0,scale:"1 1",src:"",stroke:"#000","stroke-dasharray":"","stroke-linecap":"butt","stroke-linejoin":"butt","stroke-miterlimit":0,"stroke-opacity":1,"stroke-width":1,target:"_blank","text-anchor":"middle",title:"Raphael",translation:"0 0",width:0,x:0,y:0},T={"clip-rect":"csv",cx:"number",cy:"number",fill:"colour","fill-opacity":"number","font-size":"number",height:"number",opacity:"number",path:"path",r:"number",rotation:"csv",rx:"number",ry:"number",scale:"csv",stroke:"colour","stroke-opacity":"number","stroke-width":"number",translation:"csv",width:"number",x:"number",y:"number"},U=["click","dblclick","mousedown","mousemove","mouseout","mouseover","mouseup"];E.version="1.0 RC1.3";E.type=(window.SVGAngle||document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure","1.1")?"SVG":"VML");E.svg=!(E.vml=E.type=="VML");E.idGenerator=0;E.fn={};E.isArray=function(R){return Object.prototype.toString.call(R)=="[object Array]";};E.setWindow=function(R){m=R;F=m.document;};E.hsb2rgb=x(function(AF,AD,AJ){if(typeof AF=="object"&&"h" in AF&&"s" in AF&&"b" in AF){AJ=AF.b;AD=AF.s;AF=AF.h;}var AA,AB,AK;if(AJ==0){return{r:0,g:0,b:0,hex:"#000"};}if(AF>1||AD>1||AJ>1){AF/=255;AD/=255;AJ/=255;}var AC=Math.floor(AF*6),AG=(AF*6)-AC,z=AJ*(1-AD),e=AJ*(1-(AD*AG)),AL=AJ*(1-(AD*(1-AG)));AA=[AJ,e,z,z,AL,AJ,AJ][AC];AB=[AL,AJ,AJ,e,z,z,AL][AC];AK=[z,z,AL,AJ,AJ,e,z][AC];AA*=255;AB*=255;AK*=255;var AH={r:AA,g:AB,b:AK},R=Math.round(AA).toString(16),AE=Math.round(AB).toString(16),AI=Math.round(AK).toString(16);if(R.length==1){R="0"+R;}if(AE.length==1){AE="0"+AE;}if(AI.length==1){AI="0"+AI;}AH.hex="#"+R+AE+AI;return AH;},E);E.rgb2hsb=x(function(R,e,AD){if(typeof R=="object"&&"r" in R&&"g" in R&&"b" in R){AD=R.b;e=R.g;R=R.r;}if(typeof R=="string"){var AF=E.getRGB(R);R=AF.r;e=AF.g;AD=AF.b;}if(R>1||e>1||AD>1){R/=255;e/=255;AD/=255;}var AC=Math.max(R,e,AD),i=Math.min(R,e,AD),AA,z,AB=AC;if(i==AC){return{h:0,s:0,b:AC};}else{var AE=(AC-i);z=AE/AC;if(R==AC){AA=(e-AD)/AE;}else{if(e==AC){AA=2+((AD-R)/AE);}else{AA=4+((R-e)/AE);}}AA/=6;if(AA<0){AA+=1;}if(AA>1){AA-=1;}}return{h:AA,s:z,b:AB};},E);E._path2string=function(){var z="",AC;for(var e=0,AA=this.length;e<AA;e++){for(var R=0,AB=this[e].length;R<AB;R++){z+=this[e][R];R&&R!=AB-1&&(z+=",");}e!=AA-1&&(z+="\n");}return z.replace(/,(?=-)/g,"");};function x(z,e,R){function i(){var AA=Array.prototype.splice.call(arguments,0,arguments.length),AB=AA.join("\u25ba");i.cache=i.cache||{};i.count=i.count||[];if(AB in i.cache){return R?R(i.cache[AB]):i.cache[AB];}if(i.count.length>1000){delete i.cache[i.count.unshift()];}i.count.push(AB);i.cache[AB]=z.apply(e,AA);return R?R(i.cache[AB]):i.cache[AB];}return i;}E.getRGB=x(function(R){var AF={aliceblue:"#f0f8ff",amethyst:"#96c",antiquewhite:"#faebd7",aqua:"#0ff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000",blanchedalmond:"#ffebcd",blue:"#00f",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#0ff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#f0f",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#789",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#0f0",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#f0f",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370db",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#db7093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",red:"#f00",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#fff",whitesmoke:"#f5f5f5",yellow:"#ff0",yellowgreen:"#9acd32"},AB;if((R+"").toLowerCase() in AF){R=AF[R.toString().toLowerCase()];}if(!R){return{r:0,g:0,b:0,hex:"#000"};}if(R=="none"){return{r:-1,g:-1,b:-1,hex:"none"};}var i,z,AE,AC=(R+"").match(/^\s*((#[a-f\d]{6})|(#[a-f\d]{3})|rgb\(\s*([\d\.]+\s*,\s*[\d\.]+\s*,\s*[\d\.]+)\s*\)|rgb\(\s*([\d\.]+%\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%)\s*\)|hs[bl]\(\s*([\d\.]+\s*,\s*[\d\.]+\s*,\s*[\d\.]+)\s*\)|hs[bl]\(\s*([\d\.]+%\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%)\s*\))\s*$/i);if(AC){if(AC[2]){AE=parseInt(AC[2].substring(5),16);z=parseInt(AC[2].substring(3,5),16);i=parseInt(AC[2].substring(1,3),16);}if(AC[3]){AE=parseInt(AC[3].substring(3)+AC[3].substring(3),16);z=parseInt(AC[3].substring(2,3)+AC[3].substring(2,3),16);i=parseInt(AC[3].substring(1,2)+AC[3].substring(1,2),16);}if(AC[4]){AC=AC[4].split(/\s*,\s*/);i=parseFloat(AC[0]);z=parseFloat(AC[1]);AE=parseFloat(AC[2]);}if(AC[5]){AC=AC[5].split(/\s*,\s*/);i=parseFloat(AC[0])*2.55;z=parseFloat(AC[1])*2.55;AE=parseFloat(AC[2])*2.55;}if(AC[6]){AC=AC[6].split(/\s*,\s*/);i=parseFloat(AC[0]);z=parseFloat(AC[1]);AE=parseFloat(AC[2]);return E.hsb2rgb(i,z,AE);}if(AC[7]){AC=AC[7].split(/\s*,\s*/);i=parseFloat(AC[0])*2.55;z=parseFloat(AC[1])*2.55;AE=parseFloat(AC[2])*2.55;return E.hsb2rgb(i,z,AE);}var AC={r:i,g:z,b:AE},e=Math.round(i).toString(16),AA=Math.round(z).toString(16),AD=Math.round(AE).toString(16);(e.length==1)&&(e="0"+e);(AA.length==1)&&(AA="0"+AA);(AD.length==1)&&(AD="0"+AD);AC.hex="#"+e+AA+AD;AB=AC;}else{AB={r:-1,g:-1,b:-1,hex:"none"};}return AB;},E);E.getColor=function(e){var i=this.getColor.start=this.getColor.start||{h:0,s:1,b:e||0.75},R=this.hsb2rgb(i.h,i.s,i.b);i.h+=0.075;if(i.h>1){i.h=0;i.s-=0.2;if(i.s<=0){this.getColor.start={h:0,s:1,b:i.b};}}return R.hex;};E.getColor.reset=function(){delete this.start;};E.parsePathString=x(function(R){if(!R){return null;}var i={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},e=[];if(E.isArray(R)&&E.isArray(R[0])){e=S(R);}if(!e.length){(R+"").replace(/([achlmqstvz])[\s,]*((-?\d*\.?\d*(?:e[-+]?\d+)?\s*,?\s*)+)/ig,function(AA,z,AD){var AC=[],AB=z.toLowerCase();AD.replace(/(-?\d*\.?\d*(?:e[-+]?\d+)?)\s*,?\s*/ig,function(AF,AE){AE&&AC.push(+AE);});while(AC.length>=i[AB]){e.push([z].concat(AC.splice(0,i[AB])));if(!i[AB]){break;}}});}e.toString=E._path2string;return e;});var b=x(function(AG){if(!AG){return{x:0,y:0,width:0,height:0};}AG=p(AG);var AD=0,AC=0,z=[],e=[];for(var AA=0,AF=AG.length;AA<AF;AA++){if(AG[AA][0]=="M"){AD=AG[AA][1];AC=AG[AA][2];z.push(AD);e.push(AC);}else{var AB=k(AD,AC,AG[AA][1],AG[AA][2],AG[AA][3],AG[AA][4],AG[AA][5],AG[AA][6]);z=z.concat(AB.min.x,AB.max.x);e=e.concat(AB.min.y,AB.max.y);}}var R=Math.min.apply(0,z),AE=Math.min.apply(0,e);return{x:R,y:AE,width:Math.max.apply(0,z)-R,height:Math.max.apply(0,e)-AE};}),S=function(AC){var z=[];if(!E.isArray(AC)||!E.isArray(AC&&AC[0])){AC=E.parsePathString(AC);}for(var e=0,AA=AC.length;e<AA;e++){z[e]=[];for(var R=0,AB=AC[e].length;R<AB;R++){z[e][R]=AC[e][R];}}z.toString=E._path2string;return z;},C=x(function(AA){if(!E.isArray(AA)||!E.isArray(AA&&AA[0])){AA=E.parsePathString(AA);}var AG=[],AI=0,AH=0,AL=0,AK=0,z=0;if(AA[0][0]=="M"){AI=AA[0][1];AH=AA[0][2];AL=AI;AK=AH;z++;AG.push(["M",AI,AH]);}for(var AD=z,AM=AA.length;AD<AM;AD++){var R=AG[AD]=[],AJ=AA[AD];if(AJ[0]!=AJ[0].toLowerCase()){R[0]=AJ[0].toLowerCase();switch(R[0]){case"a":R[1]=AJ[1];R[2]=AJ[2];R[3]=AJ[3];R[4]=AJ[4];R[5]=AJ[5];R[6]=+(AJ[6]-AI).toFixed(3);R[7]=+(AJ[7]-AH).toFixed(3);break;case"v":R[1]=+(AJ[1]-AH).toFixed(3);break;case"m":AL=AJ[1];AK=AJ[2];default:for(var AC=1,AE=AJ.length;AC<AE;AC++){R[AC]=+(AJ[AC]-((AC%2)?AI:AH)).toFixed(3);}}}else{R=AG[AD]=[];if(AJ[0]=="m"){AL=AJ[1]+AI;AK=AJ[2]+AH;}for(var AB=0,e=AJ.length;AB<e;AB++){AG[AD][AB]=AJ[AB];}}var AF=AG[AD].length;switch(AG[AD][0]){case"z":AI=AL;AH=AK;break;case"h":AI+=+AG[AD][AF-1];break;case"v":AH+=+AG[AD][AF-1];break;default:AI+=+AG[AD][AF-2];AH+=+AG[AD][AF-1];}}AG.toString=E._path2string;return AG;},0,S),V=x(function(AA){if(!E.isArray(AA)||!E.isArray(AA&&AA[0])){AA=E.parsePathString(AA);}var AF=[],AH=0,AG=0,AK=0,AJ=0,z=0;if(AA[0][0]=="M"){AH=+AA[0][1];AG=+AA[0][2];AK=AH;AJ=AG;z++;AF[0]=["M",AH,AG];}for(var AD=z,AL=AA.length;AD<AL;AD++){var R=AF[AD]=[],AI=AA[AD];if(AI[0]!=(AI[0]+"").toUpperCase()){R[0]=(AI[0]+"").toUpperCase();switch(R[0]){case"A":R[1]=AI[1];R[2]=AI[2];R[3]=AI[3];R[4]=AI[4];R[5]=AI[5];R[6]=+(AI[6]+AH);R[7]=+(AI[7]+AG);break;case"V":R[1]=+AI[1]+AG;break;case"H":R[1]=+AI[1]+AH;break;case"M":AK=+AI[1]+AH;AJ=+AI[2]+AG;default:for(var AC=1,AE=AI.length;AC<AE;AC++){R[AC]=+AI[AC]+((AC%2)?AH:AG);}}}else{for(var AB=0,e=AI.length;AB<e;AB++){AF[AD][AB]=AI[AB];}}switch(R[0]){case"Z":AH=AK;AG=AJ;break;case"H":AH=R[1];break;case"V":AG=R[1];break;default:AH=AF[AD][AF[AD].length-2];AG=AF[AD][AF[AD].length-1];}}AF.toString=E._path2string;return AF;},null,S),D=function(e,z,R,i){return[e,z,R,i,R,i];},W=function(e,z,AB,AA,R,i){return[2/3*e+1/3*AB,2/3*z+1/3*AA,2/3*e+1/3*R,2/3*z+1/3*i,R,i];},P=function(AK,Ao,AT,AR,AL,AF,AA,AJ,An,AM){var AQ=Math.PI*120/180,R=Math.PI/180*(+AL||0),AX=[],AU,Ak=x(function(Ap,As,i){var Ar=Ap*Math.cos(i)-As*Math.sin(i),Aq=Ap*Math.sin(i)+As*Math.cos(i);return{x:Ar,y:Aq};});if(!AM){AU=Ak(AK,Ao,-R);AK=AU.x;Ao=AU.y;AU=Ak(AJ,An,-R);AJ=AU.x;An=AU.y;var e=Math.cos(Math.PI/180*AL),AH=Math.sin(Math.PI/180*AL),AZ=(AK-AJ)/2,AY=(Ao-An)/2;AT=Math.max(AT,Math.abs(AZ));AR=Math.max(AR,Math.abs(AY));var z=AT*AT,Ac=AR*AR,Ae=(AF==AA?-1:1)*Math.sqrt(Math.abs((z*Ac-z*AY*AY-Ac*AZ*AZ)/(z*AY*AY+Ac*AZ*AZ))),AO=Ae*AT*AY/AR+(AK+AJ)/2,AN=Ae*-AR*AZ/AT+(Ao+An)/2,AE=Math.asin((Ao-AN)/AR),AD=Math.asin((An-AN)/AR);AE=AK<AO?Math.PI-AE:AE;AD=AJ<AO?Math.PI-AD:AD;AE<0&&(AE=Math.PI*2+AE);AD<0&&(AD=Math.PI*2+AD);if(AA&&AE>AD){AE=AE-Math.PI*2;}if(!AA&&AD>AE){AD=AD-Math.PI*2;}}else{AE=AM[0];AD=AM[1];AO=AM[2];AN=AM[3];}var AI=AD-AE;if(Math.abs(AI)>AQ){var AP=AD,AS=AJ,AG=An;AD=AE+AQ*(AA&&AD>AE?1:-1);AJ=AO+AT*Math.cos(AD);An=AN+AR*Math.sin(AD);AX=P(AJ,An,AT,AR,AL,0,AA,AS,AG,[AD,AP,AO,AN]);}var AC=Math.cos(AE),Am=Math.sin(AE),AB=Math.cos(AD),Al=Math.sin(AD),AI=AD-AE,Aa=Math.tan(AI/4),Ad=4/3*AT*Aa,Ab=4/3*AR*Aa,Aj=[AK,Ao],Ai=[AK+Ad*Am,Ao-Ab*AC],Ah=[AJ+Ad*Al,An-Ab*AB],Af=[AJ,An];Ai[0]=2*Aj[0]-Ai[0];Ai[1]=2*Aj[1]-Ai[1];if(AM){return[Ai,Ah,Af].concat(AX);}else{AX=[Ai,Ah,Af].concat(AX).join(",").split(",");var AV=[];for(var Ag=0,AW=AX.length;Ag<AW;Ag++){AV[Ag]=Ag%2?Ak(AX[Ag-1],AX[Ag],R).y:Ak(AX[Ag],AX[Ag+1],R).x;}return AV;}},Z=x(function(e,R,AO,AM,AB,AA,AD,AC,AI){var AG=Math.pow(1-AI,3)*e+Math.pow(1-AI,2)*3*AI*AO+(1-AI)*3*AI*AI*AB+Math.pow(AI,3)*AD,AE=Math.pow(1-AI,3)*R+Math.pow(1-AI,2)*3*AI*AM+(1-AI)*3*AI*AI*AA+Math.pow(AI,3)*AC,AK=e+2*AI*(AO-e)+AI*AI*(AB-2*AO+e),AJ=R+2*AI*(AM-R)+AI*AI*(AA-2*AM+R),AN=AO+2*AI*(AB-AO)+AI*AI*(AD-2*AB+AO),AL=AM+2*AI*(AA-AM)+AI*AI*(AC-2*AA+AM),AH=(1-AI)*e+AI*AO,AF=(1-AI)*R+AI*AM,z=(1-AI)*AB+AI*AD,i=(1-AI)*AA+AI*AC;return{x:AG,y:AE,m:{x:AK,y:AJ},n:{x:AN,y:AL},start:{x:AH,y:AF},end:{x:z,y:i}};}),k=x(function(e,R,z,i,AM,AL,AI,AF){var AK=(AM-2*z+e)-(AI-2*AM+z),AH=2*(z-e)-2*(AM-z),AE=e-z,AC=(-AH+Math.sqrt(AH*AH-4*AK*AE))/2/AK,AA=(-AH-Math.sqrt(AH*AH-4*AK*AE))/2/AK,AG=[R,AF],AJ=[e,AI],AD=Z(e,R,z,i,AM,AL,AI,AF,AC>0&&AC<1?AC:0),AB=Z(e,R,z,i,AM,AL,AI,AF,AA>0&&AA<1?AA:0);AJ=AJ.concat(AD.x,AB.x);AG=AG.concat(AD.y,AB.y);AK=(AL-2*i+R)-(AF-2*AL+i);AH=2*(i-R)-2*(AL-i);AE=R-i;AC=(-AH+Math.sqrt(AH*AH-4*AK*AE))/2/AK;AA=(-AH-Math.sqrt(AH*AH-4*AK*AE))/2/AK;AD=Z(e,R,z,i,AM,AL,AI,AF,AC>0&&AC<1?AC:0);AB=Z(e,R,z,i,AM,AL,AI,AF,AA>0&&AA<1?AA:0);AJ=AJ.concat(AD.x,AB.x);AG=AG.concat(AD.y,AB.y);return{min:{x:Math.min.apply(Math,AJ),y:Math.min.apply(Math,AG)},max:{x:Math.max.apply(Math,AJ),y:Math.max.apply(Math,AG)}};}),p=x(function(AL,AG){var AA=V(AL),AH=AG&&V(AG),AI={x:0,y:0,bx:0,by:0,X:0,Y:0},R={x:0,y:0,bx:0,by:0,X:0,Y:0},AC=function(AM,AN){if(!AM){return["C",AN.x,AN.y,AN.x,AN.y,AN.x,AN.y];}switch(AM[0]){case"M":AN.X=AM[1];AN.Y=AM[2];break;case"A":AM=["C"].concat(P(AN.x,AN.y,AM[1],AM[2],AM[3],AM[4],AM[5],AM[6],AM[7]));break;case"S":var i=AN.x+(AN.x-(AN.bx||AN.x)),AO=AN.y+(AN.y-(AN.by||AN.y));AM=["C",i,AO,AM[1],AM[2],AM[3],AM[4]];break;case"T":var i=AN.x+(AN.x-(AN.bx||AN.x)),AO=AN.y+(AN.y-(AN.by||AN.y));AM=["C"].concat(W(AN.x,AN.y,i,AO,AM[1],AM[2]));break;case"Q":AM=["C"].concat(W(AN.x,AN.y,AM[1],AM[2],AM[3],AM[4]));break;case"L":AM=["C"].concat(D(AN.x,AN.y,AM[1],AM[2]));break;case"H":AM=["C"].concat(D(AN.x,AN.y,AM[1],AN.y));break;case"V":AM=["C"].concat(D(AN.x,AN.y,AN.x,AM[1]));break;case"Z":AM=["C"].concat(D(AN.x,AN.y,AN.X,AN.Y));break;}return AM;},e=function(AM,AN){if(AM[AN].length>7){AM[AN].shift();var AO=AM[AN];while(AO.length){AM.splice(AN++,0,["C"].concat(AO.splice(0,6)));}AM.splice(AN,1);AJ=Math.max(AA.length,AH&&AH.length||0);}},z=function(AQ,AP,AN,AM,AO){if(AQ&&AP&&AQ[AO][0]=="M"&&AP[AO][0]!="M"){AP.splice(AO,0,["M",AM.x,AM.y]);AN.bx=0;AN.by=0;AN.x=AQ[AO][1];AN.y=AQ[AO][2];AJ=Math.max(AA.length,AH&&AH.length||0);}};for(var AE=0,AJ=Math.max(AA.length,AH&&AH.length||0);AE<AJ;AE++){AA[AE]=AC(AA[AE],AI);e(AA,AE);AH&&(AH[AE]=AC(AH[AE],R));AH&&e(AH,AE);z(AA,AH,AI,R,AE);z(AH,AA,R,AI,AE);var AD=AA[AE],AK=AH&&AH[AE],AB=AD.length,AF=AH&&AK.length;AI.bx=AD[AB-4]||0;AI.by=AD[AB-3]||0;AI.x=AD[AB-2];AI.y=AD[AB-1];R.bx=AH&&(AK[AF-4]||0);R.by=AH&&(AK[AF-3]||0);R.x=AH&&AK[AF-2];R.y=AH&&AK[AF-1];}return AH?[AA,AH]:AA;},null,S),L=x(function(AH){if(typeof AH=="string"){AH=AH.split(/\s*\-\s*/);var z=AH.shift();if(z.toLowerCase()=="v"){z=90;}else{if(z.toLowerCase()=="h"){z=0;}else{z=parseFloat(z);}}z=-z;var AF={angle:z,type:"linear",dots:[],vector:[0,0,Math.cos(z*Math.PI/180).toFixed(3),Math.sin(z*Math.PI/180).toFixed(3)]},AG=1/(Math.max(Math.abs(AF.vector[2]),Math.abs(AF.vector[3]))||1);AF.vector[2]*=AG;AF.vector[3]*=AG;if(AF.vector[2]<0){AF.vector[0]=-AF.vector[2];AF.vector[2]=0;}if(AF.vector[3]<0){AF.vector[1]=-AF.vector[3];AF.vector[3]=0;}AF.vector[0]=AF.vector[0];AF.vector[1]=AF.vector[1];AF.vector[2]=AF.vector[2];AF.vector[3]=AF.vector[3];for(var AC=0,AI=AH.length;AC<AI;AC++){var R={},AE=AH[AC].match(/^([^:]*):?([\d\.]*)/);R.color=E.getRGB(AE[1]).hex;AE[2]&&(R.offset=AE[2]+"%");AF.dots.push(R);}for(var AC=1,AI=AF.dots.length-1;AC<AI;AC++){if(!AF.dots[AC].offset){var e=parseFloat(AF.dots[AC-1].offset||0),AA=false;for(var AB=AC+1;AB<AI;AB++){if(AF.dots[AB].offset){AA=AF.dots[AB].offset;break;}}if(!AA){AA=100;AB=AI;}AA=parseFloat(AA);var AD=(AA-e)/(AB-AC+1);for(;AC<AB;AC++){e+=AD;AF.dots[AC].offset=e+"%";}}}return AF;}else{return AH;}}),g=function(){var i,e,AA,z,R;if(typeof arguments[0]=="string"||typeof arguments[0]=="object"){if(typeof arguments[0]=="string"){i=F.getElementById(arguments[0]);}else{i=arguments[0];}if(i.tagName){if(arguments[1]==null){return{container:i,width:i.style.pixelWidth||i.offsetWidth,height:i.style.pixelHeight||i.offsetHeight};}else{return{container:i,width:arguments[1],height:arguments[2]};}}}else{if(typeof arguments[0]=="number"&&arguments.length>3){return{container:1,x:arguments[0],y:arguments[1],width:arguments[2],height:arguments[3]};}}},A=function(R,i){var e=this;for(var z in i){if(i.hasOwnProperty(z)&&!(z in R)){switch(typeof i[z]){case"function":(function(AA){R[z]=R===e?AA:function(){return AA.apply(e,arguments);};})(i[z]);break;case"object":R[z]=R[z]||{};A.call(this,R[z],i[z]);break;default:R[z]=i[z];break;}}}};if(E.svg){var o=function(R){return +R+(Math.floor(R)==R)*0.5;};var Y=function(AB){for(var e=0,z=AB.length;e<z;e++){if(AB[e][0].toLowerCase()!="a"){for(var R=1,AA=AB[e].length;R<AA;R++){AB[e][R]=o(AB[e][R]);}}else{AB[e][6]=o(AB[e][6]);AB[e][7]=o(AB[e][7]);}}return AB;};var a=function(i,R){for(var e in R){if(R.hasOwnProperty(e)){i.setAttribute(e,R[e]);}}};E.toString=function(){return"Your browser supports SVG.\nYou are running Rapha\u00ebl "+this.version;};var w=function(R,z){var e=F.createElementNS(z.svgns,"path");z.canvas&&z.canvas.appendChild(e);var i=new K(e,z);i.type="path";f(i,{fill:"none",stroke:"#000",path:R});return i;};var n=function(AD,AB,AE){AB=L(AB);var AA=F.createElementNS(AE.svgns,(AB.type||"linear")+"Gradient");AA.id="r"+(E.idGenerator++).toString(36);if(AB.vector&&AB.vector.length){a(AA,{x1:AB.vector[0],y1:AB.vector[1],x2:AB.vector[2],y2:AB.vector[3]});}AE.defs.appendChild(AA);var AC=true;for(var e=0,z=AB.dots.length;e<z;e++){var R=F.createElementNS(AE.svgns,"stop");if(AB.dots[e].offset){AC=false;}a(R,{offset:AB.dots[e].offset?AB.dots[e].offset:(e==0)?"0%":"100%","stop-color":E.getRGB(AB.dots[e].color).hex||"#fff"});AA.appendChild(R);}if(AC&&AB.dots[z-1].opacity!=null){a(R,{"stop-opacity":AB.dots[z-1].opacity});}a(AD,{fill:"url(#"+AA.id+")",opacity:1,"fill-opacity":1});AD.style.fill="";AD.style.opacity=1;AD.style.fillOpacity=1;};var Q=function(e){var R=e.getBBox();a(e.pattern,{patternTransform:E.format("translate({0},{1})",R.x,R.y)});};var f=function(AH,AQ){var AK={"":[0],none:[0],"-":[3,1],".":[1,1],"-.":[3,1,1,1],"-..":[3,1,1,1,1,1],". ":[1,3],"- ":[4,3],"--":[8,3],"- .":[4,3,1,3],"--.":[8,3,1,3],"--..":[8,3,1,3,1,3]},AM=AH.node,AI=AH.attrs,AE=AH.attr("rotation"),AB=function(AX,AW){AW=AK[(AW+"").toLowerCase()];if(AW){var AU=AX.attrs["stroke-width"]||"1",AS={round:AU,square:AU,butt:0}[AX.attrs["stroke-linecap"]||AQ["stroke-linecap"]]||0,AV=[];var AT=AW.length;while(AT--){AV[AT]=AW[AT]*AU+((AT%2)?1:-1)*AS;}a(AM,{"stroke-dasharray":AV.join(",")});}};parseFloat(AE)&&AH.rotate(0,true);for(var AL in AQ){if(!(AL in O)){continue;}var AJ=AQ[AL];AI[AL]=AJ;switch(AL){case"href":case"title":case"target":var AO=AM.parentNode;if(AO.tagName.toLowerCase()!="a"){var z=F.createElementNS(AH.paper.svgns,"a");AO.insertBefore(z,AM);z.appendChild(AM);AO=z;}AO.setAttributeNS(AH.paper.xlink,AL,AJ);break;case"clip-rect":var e=(AJ+"").split(y);if(e.length==4){AH.clip&&AH.clip.parentNode.parentNode.removeChild(AH.clip.parentNode);var i=F.createElementNS(AH.paper.svgns,"clipPath"),AN=F.createElementNS(AH.paper.svgns,"rect");i.id="r"+(E.idGenerator++).toString(36);a(AN,{x:e[0],y:e[1],width:e[2],height:e[3]});i.appendChild(AN);AH.paper.defs.appendChild(i);a(AM,{"clip-path":"url(#"+i.id+")"});AH.clip=AN;}if(!AJ){var AP=F.getElementById(AM.getAttribute("clip-path").replace(/(^url\(#|\)$)/g,""));AP&&AP.parentNode.removeChild(AP);a(AM,{"clip-path":""});delete AH.clip;}break;case"path":if(AJ&&AH.type=="path"){AI.path=Y(V(AJ));a(AM,{d:AI.path});}case"width":AM.setAttribute(AL,AJ);if(AI.fx){AL="x";AJ=AI.x;}else{break;}case"x":if(AI.fx){AJ=-AI.x-(AI.width||0);}case"rx":case"cx":AM.setAttribute(AL,AJ);AH.pattern&&Q(AH);break;case"height":AM.setAttribute(AL,AJ);if(AI.fy){AL="y";AJ=AI.y;}else{break;}case"y":if(AI.fy){AJ=-AI.y-(AI.height||0);}case"ry":case"cy":AM.setAttribute(AL,AJ);AH.pattern&&Q(AH);break;case"r":if(AH.type=="rect"){a(AM,{rx:AJ,ry:AJ});}else{AM.setAttribute(AL,AJ);}break;case"src":if(AH.type=="image"){AM.setAttributeNS(AH.paper.xlink,"href",AJ);}break;case"stroke-width":AM.style.strokeWidth=AJ;AM.setAttribute(AL,AJ);if(AI["stroke-dasharray"]){AB(AH,AI["stroke-dasharray"]);}break;case"stroke-dasharray":AB(AH,AJ);break;case"rotation":AE=AJ;AH.rotate(AJ,true);break;case"translation":var AC=(AJ+"").split(y);AH.translate((+AC[0]+1||2)-1,(+AC[1]+1||2)-1);break;case"scale":var AC=(AJ+"").split(y);AH.scale(+AC[0]||1,+AC[1]||+AC[0]||1,+AC[2]||null,+AC[3]||null);break;case"fill":var AA=(AJ+"").match(/^url\(['"]?([^\)]+)['"]?\)$/i);if(AA){var i=F.createElementNS(AH.paper.svgns,"pattern"),AG=F.createElementNS(AH.paper.svgns,"image");i.id="r"+(E.idGenerator++).toString(36);a(i,{x:0,y:0,patternUnits:"userSpaceOnUse"});a(AG,{x:0,y:0});AG.setAttributeNS(AH.paper.xlink,"href",AA[1]);i.appendChild(AG);var AR=F.createElement("img");AR.style.position="absolute";AR.style.top="-9999em";AR.style.left="-9999em";AR.onload=function(){a(i,{width:this.offsetWidth,height:this.offsetHeight});a(AG,{width:this.offsetWidth,height:this.offsetHeight});F.body.removeChild(this);B.safari();};F.body.appendChild(AR);AR.src=AA[1];AH.paper.defs.appendChild(i);AM.style.fill="url(#"+i.id+")";a(AM,{fill:"url(#"+i.id+")"});AH.pattern=i;AH.pattern&&Q(AH);break;}delete AQ.gradient;delete AI.gradient;if(typeof AI.opacity!="undefined"&&typeof AQ.opacity=="undefined"){AM.style.opacity=AI.opacity;a(AM,{opacity:AI.opacity});}if(typeof AI["fill-opacity"]!="undefined"&&typeof AQ["fill-opacity"]=="undefined"){AM.style.fillOpacity=AI["fill-opacity"];a(AM,{"fill-opacity":AI["fill-opacity"]});}case"stroke":AM.style[AL]=E.getRGB(AJ).hex;AM.setAttribute(AL,E.getRGB(AJ).hex);break;case"gradient":n(AM,AJ,AH.paper);break;case"opacity":case"fill-opacity":if(AI.gradient){var R=F.getElementById(AM.getAttribute("fill").replace(/^url\(#|\)$/g,""));if(R){var AD=R.getElementsByTagName("stop");AD[AD.length-1].setAttribute("stop-opacity",AJ);}break;}default:AL=="font-size"&&(AJ=parseInt(AJ,10)+"px");var AF=AL.replace(/(\-.)/g,function(AS){return AS.substring(1).toUpperCase();});AM.style[AF]=AJ;AM.setAttribute(AL,AJ);break;}}t(AH,AQ);parseInt(AE,10)&&AH.rotate(AE,true);};var l=1.2;var t=function(R,AA){if(R.type!="text"||!("text" in AA||"font" in AA||"font-size" in AA||"x" in AA||"y" in AA)){return ;}var AF=R.attrs,e=R.node,AH=e.firstChild?parseInt(F.defaultView.getComputedStyle(e.firstChild,"").getPropertyValue("font-size"),10):10;if("text" in AA){while(e.firstChild){e.removeChild(e.firstChild);}var z=(AA.text+"").split("\n");for(var AB=0,AG=z.length;AB<AG;AB++){var AD=F.createElementNS(R.paper.svgns,"tspan");AB&&a(AD,{dy:AH*l,x:AF.x});AD.appendChild(F.createTextNode(z[AB]));e.appendChild(AD);}}else{var z=e.getElementsByTagName("tspan");for(var AB=0,AG=z.length;AB<AG;AB++){AB&&a(z[AB],{dy:AH*l,x:AF.x});}}a(e,{y:AF.y});var AC=R.getBBox(),AE=AF.y-(AC.y+AC.height/2);AE&&a(e,{y:AF.y+AE});};var K=function(e,R){var z=0,i=0;this[0]=e;this.node=e;this.paper=R;this.attrs=this.attrs||{};this.transformations=[];this._={tx:0,ty:0,rt:{deg:0,cx:0,cy:0},sx:1,sy:1};};K.prototype.rotate=function(e,R,z){if(e==null){if(this._.rt.cx){return[this._.rt.deg,this._.rt.cx,this._.rt.cy].join(" ");}return this._.rt.deg;}var i=this.getBBox();e=(e+"").split(y);if(e.length-1){R=parseFloat(e[1]);z=parseFloat(e[2]);}e=parseFloat(e[0]);if(R!=null){this._.rt.deg=e;}else{this._.rt.deg+=e;}(z==null)&&(R=null);this._.rt.cx=R;this._.rt.cy=z;R=R==null?i.x+i.width/2:R;z=z==null?i.y+i.height/2:z;if(this._.rt.deg){this.transformations[0]=E.format("rotate({0} {1} {2})",this._.rt.deg,R,z);this.clip&&a(this.clip,{transform:E.format("rotate({0} {1} {2})",-this._.rt.deg,R,z)});}else{this.transformations[0]="";this.clip&&a(this.clip,{transform:""});}a(this.node,{transform:this.transformations.join(" ")});return this;};K.prototype.hide=function(){this.node.style.display="none";return this;};K.prototype.show=function(){this.node.style.display="block";return this;};K.prototype.remove=function(){this.node.parentNode.removeChild(this.node);};K.prototype.getBBox=function(){if(this.type=="path"){return b(this.attrs.path);}if(this.node.style.display=="none"){this.show();var z=true;}var AD={};try{AD=this.node.getBBox();}catch(AB){}finally{AD=AD||{};}if(this.type=="text"){AD={x:AD.x,y:Infinity,width:AD.width,height:0};for(var R=0,AA=this.node.getNumberOfChars();R<AA;R++){var AC=this.node.getExtentOfChar(R);(AC.y<AD.y)&&(AD.y=AC.y);(AC.y+AC.height-AD.y>AD.height)&&(AD.height=AC.y+AC.height-AD.y);}}z&&this.hide();return AD;};K.prototype.attr=function(){if(arguments.length==1&&typeof arguments[0]=="string"){if(arguments[0]=="translation"){return this.translate();}if(arguments[0]=="rotation"){return this.rotate();}if(arguments[0]=="scale"){return this.scale();}return this.attrs[arguments[0]];}if(arguments.length==1&&E.isArray(arguments[0])){var R={};for(var e in arguments[0]){R[arguments[0][e]]=this.attrs[arguments[0][e]];}return R;}if(arguments.length==2){var i={};i[arguments[0]]=arguments[1];f(this,i);}else{if(arguments.length==1&&typeof arguments[0]=="object"){f(this,arguments[0]);}}return this;};K.prototype.toFront=function(){this.node.parentNode.appendChild(this.node);return this;};K.prototype.toBack=function(){if(this.node.parentNode.firstChild!=this.node){this.node.parentNode.insertBefore(this.node,this.node.parentNode.firstChild);}return this;};K.prototype.insertAfter=function(R){if(R.node.nextSibling){R.node.parentNode.insertBefore(this.node,R.node.nextSibling);}else{R.node.parentNode.appendChild(this.node);}return this;};K.prototype.insertBefore=function(R){var e=R.node;e.parentNode.insertBefore(this.node,e);return this;};var c=function(e,R,AB,AA){R=o(R);AB=o(AB);var z=F.createElementNS(e.svgns,"circle");e.canvas&&e.canvas.appendChild(z);var i=new K(z,e);i.attrs={cx:R,cy:AB,r:AA,fill:"none",stroke:"#000"};i.type="circle";a(z,i.attrs);return i;};var j=function(i,R,AD,e,AB,AC){R=o(R);AD=o(AD);var AA=F.createElementNS(i.svgns,"rect");i.canvas&&i.canvas.appendChild(AA);var z=new K(AA,i);z.attrs={x:R,y:AD,width:e,height:AB,r:AC||0,rx:AC||0,ry:AC||0,fill:"none",stroke:"#000"};z.type="rect";a(AA,z.attrs);return z;};var G=function(e,R,AC,AB,AA){R=o(R);AC=o(AC);var z=F.createElementNS(e.svgns,"ellipse");e.canvas&&e.canvas.appendChild(z);var i=new K(z,e);i.attrs={cx:R,cy:AC,rx:AB,ry:AA,fill:"none",stroke:"#000"};i.type="ellipse";a(z,i.attrs);return i;};var N=function(i,AC,R,AD,e,AB){var AA=F.createElementNS(i.svgns,"image");a(AA,{x:R,y:AD,width:e,height:AB,preserveAspectRatio:"none"});AA.setAttributeNS(i.xlink,"href",AC);i.canvas&&i.canvas.appendChild(AA);var z=new K(AA,i);z.attrs={x:R,y:AD,width:e,height:AB,src:AC};z.type="image";return z;};var h=function(e,R,AB,AA){var z=F.createElementNS(e.svgns,"text");a(z,{x:R,y:AB,"text-anchor":"middle"});e.canvas&&e.canvas.appendChild(z);var i=new K(z,e);i.attrs={x:R,y:AB,"text-anchor":"middle",text:AA,font:O.font,stroke:"none",fill:"#000"};i.type="text";f(i,i.attrs);return i;};var d=function(e,R){this.width=e||this.width;this.height=R||this.height;this.canvas.setAttribute("width",this.width);this.canvas.setAttribute("height",this.height);return this;};var J=function(){var AA=g.apply(null,arguments),i=AA.container,AC=AA.x,AB=AA.y,z=AA.width,AD=AA.height;if(!i){throw new Error("SVG container not found.");}B.canvas=F.createElementNS(B.svgns,"svg");var R=B.canvas,AE=R.style;R.setAttribute("width",z||512);B.width=z||512;R.setAttribute("height",AD||342);B.height=AD||342;if(i==1){F.body.appendChild(R);AE.position="absolute";AE.left=AC+"px";AE.top=AB+"px";}else{if(i.firstChild){i.insertBefore(R,i.firstChild);}else{i.appendChild(R);}}i={canvas:R,clear:function(){while(this.canvas.firstChild){this.canvas.removeChild(this.canvas.firstChild);}this.desc=F.createElementNS(B.svgns,"desc");this.defs=F.createElementNS(B.svgns,"defs");this.desc.appendChild(F.createTextNode("Created with Rapha\u00ebl"));this.canvas.appendChild(this.desc);this.canvas.appendChild(this.defs);}};for(var e in B){if(e!="create"){i[e]=B[e];}}A.call(i,i,E.fn);i.clear();i.raphael=E;return i;};B.remove=function(){this.canvas.parentNode&&this.canvas.parentNode.removeChild(this.canvas);};B.svgns="http://www.w3.org/2000/svg";B.xlink="http://www.w3.org/1999/xlink";B.safari=function(){if({"Apple Computer, Inc.":1,"Google Inc.":1}[navigator.vendor]){var R=this.rect(-99,-99,this.width+99,this.height+99);setTimeout(function(){R.remove();});}};}if(E.vml){var X=function(AC){var AA=p(AC);for(var e=0,z=AA.length;e<z;e++){AA[e][0]=(AA[e][0]+"").toLowerCase();AA[e][0]=="z"&&(AA[e][0]="x");for(var R=1,AB=AA[e].length;R<AB;R++){AA[e][R]=Math.round(AA[e][R]);}}return(AA+"");};E.toString=function(){return"Your browser doesn\u2019t support SVG. Assuming it is Internet Explorer and falling down to VML.\nYou are running Rapha\u00ebl "+this.version;};var w=function(R,AB){var z=v("group"),AC=z.style;AC.position="absolute";AC.left=0;AC.top=0;AC.width=AB.width+"px";AC.height=AB.height+"px";z.coordsize=AB.coordsize;z.coordorigin=AB.coordorigin;var i=v("shape"),e=i.style;e.width=AB.width+"px";e.height=AB.height+"px";i.path="";i.coordsize=this.coordsize;i.coordorigin=this.coordorigin;z.appendChild(i);var AA=new K(i,z,AB);AA.isAbsolute=true;AA.type="path";AA.path=[];AA.Path="";if(R){AA.attrs.path=E.parsePathString(R);AA.node.path=X(AA.attrs.path);}f(AA,{fill:"none",stroke:"#000"});AA.setBox();AB.canvas.appendChild(z);return AA;};var f=function(AF,AJ){AF.attrs=AF.attrs||{};var AH=AF.node,AK=AF.attrs,AC=AH.style,z,AO=AF;for(var AD in AJ){AK[AD]=AJ[AD];}AJ.href&&(AH.href=AJ.href);AJ.title&&(AH.title=AJ.title);AJ.target&&(AH.target=AJ.target);if(AJ.path&&AF.type=="path"){AK.path=E.parsePathString(AJ.path);AH.path=X(AK.path);}if(AJ.rotation!=null){AF.rotate(AJ.rotation,true);}if(AJ.translation){z=(AJ.translation+"").split(y);AF.translate(z[0],z[1]);}if(AJ.scale){z=(AJ.scale+"").split(y);AF.scale(+z[0]||1,+z[1]||+z[0]||1,+z[2]||null,+z[3]||null);}if("clip-rect" in AJ){var R=(AJ["clip-rect"]+"").split(y);if(R.length==4){R[2]=+R[2]+(+R[0]);R[3]=+R[3]+(+R[1]);var AE=AH.clipRect||F.createElement("div"),AN=AE.style,AB=AH.parentNode;AN.clip=E.format("rect({0}px {2}px {3}px {1}px)",R);if(!AH.clipRect){AN.position="absolute";AN.top=0;AN.left=0;AN.width=AF.paper.width+"px";AN.height=AF.paper.height+"px";AB.parentNode.insertBefore(AE,AB);AE.appendChild(AB);AH.clipRect=AE;}}if(!AJ["clip-rect"]){AH.clipRect&&(AH.clipRect.style.clip="");}}if(AF.type=="image"&&AJ.src){AH.src=AJ.src;}if(AF.type=="image"&&AJ.opacity){AH.filterOpacity=" progid:DXImageTransform.Microsoft.Alpha(opacity="+(AJ.opacity*100)+")";AC.filter=(AH.filterMatrix||"")+(AH.filterOpacity||"");}AJ.font&&(AC.font=AJ.font);AJ["font-family"]&&(AC.fontFamily='"'+AJ["font-family"].split(",")[0].replace(/^['"]+|['"]+$/g,"")+'"');AJ["font-size"]&&(AC.fontSize=AJ["font-size"]);AJ["font-weight"]&&(AC.fontWeight=AJ["font-weight"]);AJ["font-style"]&&(AC.fontStyle=AJ["font-style"]);if(AJ.opacity!=null||AJ["stroke-width"]!=null||AJ.fill!=null||AJ.stroke!=null||AJ["stroke-width"]!=null||AJ["stroke-opacity"]!=null||AJ["fill-opacity"]!=null||AJ["stroke-dasharray"]!=null||AJ["stroke-miterlimit"]!=null||AJ["stroke-linejoin"]!=null||AJ["stroke-linecap"]!=null){AH=AF.shape||AH;var AI=(AH.getElementsByTagName("fill")&&AH.getElementsByTagName("fill")[0]),AL=false;!AI&&(AL=AI=v("fill"));if("fill-opacity" in AJ||"opacity" in AJ){var e=((+AK["fill-opacity"]+1||2)-1)*((+AK.opacity+1||2)-1);e<0&&(e=0);e>1&&(e=1);AI.opacity=e;}AJ.fill&&(AI.on=true);if(AI.on==null||AJ.fill=="none"){AI.on=false;}if(AI.on&&AJ.fill){var i=AJ.fill.match(/^url\(([^\)]+)\)$/i);if(i){AI.src=i[1];AI.type="tile";}else{AI.color=E.getRGB(AJ.fill).hex;AI.src="";AI.type="solid";}}AL&&AH.appendChild(AI);var AA=(AH.getElementsByTagName("stroke")&&AH.getElementsByTagName("stroke")[0]),AM=false;!AA&&(AM=AA=v("stroke"));if((AJ.stroke&&AJ.stroke!="none")||AJ["stroke-width"]||AJ["stroke-opacity"]!=null||AJ["stroke-dasharray"]||AJ["stroke-miterlimit"]||AJ["stroke-linejoin"]||AJ["stroke-linecap"]){AA.on=true;}(AJ.stroke=="none"||AA.on==null||AJ.stroke==0||AJ["stroke-width"]==0)&&(AA.on=false);AA.on&&AJ.stroke&&(AA.color=E.getRGB(AJ.stroke).hex);var e=((+AK["stroke-opacity"]+1||2)-1)*((+AK.opacity+1||2)-1);e<0&&(e=0);e>1&&(e=1);AA.opacity=e;AJ["stroke-linejoin"]&&(AA.joinstyle=AJ["stroke-linejoin"]||"miter");AA.miterlimit=AJ["stroke-miterlimit"]||8;AJ["stroke-linecap"]&&(AA.endcap={butt:"flat",square:"square",round:"round"}[AJ["stroke-linecap"]]||"miter");AJ["stroke-width"]&&(AA.weight=(parseFloat(AJ["stroke-width"])||1)*12/16);if(AJ["stroke-dasharray"]){var AG={"-":"shortdash",".":"shortdot","-.":"shortdashdot","-..":"shortdashdotdot",". ":"dot","- ":"dash","--":"longdash","- .":"dashdot","--.":"longdashdot","--..":"longdashdotdot"};AA.dashstyle=AG[AJ["stroke-dasharray"]]||"";}AM&&AH.appendChild(AA);}if(AO.type=="text"){var AC=B.span.style;AK.font&&(AC.font=AK.font);AK["font-family"]&&(AC.fontFamily=AK["font-family"]);AK["font-size"]&&(AC.fontSize=AK["font-size"]);AK["font-weight"]&&(AC.fontWeight=AK["font-weight"]);AK["font-style"]&&(AC.fontStyle=AK["font-style"]);B.span.innerHTML=AO.node.string.replace(/</g,"&#60;").replace(/&/g,"&#38;").replace(/\n/g,"<br>");AO.W=AK.w=B.span.offsetWidth;AO.H=AK.h=B.span.offsetHeight;AO.X=AK.x;AO.Y=AK.y+Math.round(AO.H/2);switch(AK["text-anchor"]){case"start":AO.node.style["v-text-align"]="left";AO.bbx=Math.round(AO.W/2);break;case"end":AO.node.style["v-text-align"]="right";AO.bbx=-Math.round(AO.W/2);break;default:AO.node.style["v-text-align"]="center";break;}}};var M=function(e,R,AA,z){var i=Math.round(Math.atan((parseFloat(AA)-parseFloat(e))/(parseFloat(z)-parseFloat(R)))*57.29)||0;if(!i&&parseFloat(e)<parseFloat(R)){i=180;}i-=180;if(i<0){i+=360;}return i;};var n=function(AD,AC){AC=L(AC);AD.attrs=AD.attrs||{};var e=AD.attrs,AB=AD.node.getElementsByTagName("fill");AD.attrs.gradient=AC;AD=AD.shape||AD.node;if(AB.length){AB=AB[0];}else{AB=v("fill");}if(AC.dots.length){AB.on=true;AB.method="none";AB.type=((AC.type+"").toLowerCase()=="radial")?"gradientTitle":"gradient";if(typeof AC.dots[0].color!="undefined"){AB.color=E.getRGB(AC.dots[0].color).hex;}if(typeof AC.dots[AC.dots.length-1].color!="undefined"){AB.color2=E.getRGB(AC.dots[AC.dots.length-1].color).hex;}var AE=[];for(var z=0,AA=AC.dots.length;z<AA;z++){if(AC.dots[z].offset){AE.push(AC.dots[z].offset+" "+E.getRGB(AC.dots[z].color).hex);}}var R=typeof AC.dots[AC.dots.length-1].opacity=="undefined"?(typeof e.opacity=="undefined"?1:e.opacity):AC.dots[AC.dots.length-1].opacity;if(AE.length){AB.colors.value=AE.join(",");R=typeof e.opacity=="undefined"?1:e.opacity;}else{AB.colors&&(AB.colors.value="0% "+AB.color);}AB.opacity=R;if(typeof AC.angle!="undefined"){AB.angle=(-AC.angle+270)%360;}else{if(AC.vector){AB.angle=M.apply(null,AC.vector);}}if((AC.type+"").toLowerCase()=="radial"){AB.focus="100%";AB.focusposition="0.5 0.5";}}};var K=function(AA,AC,R){var AB=0,i=0,e=0,z=1;this[0]=AA;this.node=AA;this.X=0;this.Y=0;this.attrs={};this.Group=AC;this.paper=R;this._={tx:0,ty:0,rt:{deg:0},sx:1,sy:1};};K.prototype.rotate=function(e,R,i){if(e==null){if(this._.rt.cx){return[this._.rt.deg,this._.rt.cx,this._.rt.cy].join(" ");}return this._.rt.deg;}e=(e+"").split(y);if(e.length-1){R=parseFloat(e[1]);i=parseFloat(e[2]);}e=parseFloat(e[0]);if(R!=null){this._.rt.deg=e;}else{this._.rt.deg+=e;}(i==null)&&(R=null);this._.rt.cx=R;this._.rt.cy=i;this.setBox(this.attrs,R,i);this.Group.style.rotation=this._.rt.deg;return this;};K.prototype.setBox=function(AB,AC,AA){var e=this.Group.style,AD=(this.shape&&this.shape.style)||this.node.style;AB=AB||{};for(var AE in AB){this.attrs[AE]=AB[AE];}AC=AC||this._.rt.cx;AA=AA||this._.rt.cy;var AH=this.attrs,AK,AJ,AL,AG;switch(this.type){case"circle":AK=AH.cx-AH.r;AJ=AH.cy-AH.r;AL=AG=AH.r*2;break;case"ellipse":AK=AH.cx-AH.rx;AJ=AH.cy-AH.ry;AL=AH.rx*2;AG=AH.ry*2;break;case"rect":case"image":AK=AH.x;AJ=AH.y;AL=AH.width||0;AG=AH.height||0;break;case"text":this.textpath.v=["m",Math.round(AH.x),", ",Math.round(AH.y-2),"l",Math.round(AH.x)+1,", ",Math.round(AH.y-2)].join("");AK=AH.x-Math.round(this.W/2);AJ=AH.y-this.H/2;AL=this.W;AG=this.H;break;case"path":if(!this.attrs.path){AK=0;AJ=0;AL=this.paper.width;AG=this.paper.height;}else{var AF=b(this.attrs.path);AK=AF.x;AJ=AF.y;AL=AF.width;AG=AF.height;}break;default:AK=0;AJ=0;AL=this.paper.width;AG=this.paper.height;break;}AC=(AC==null)?AK+AL/2:AC;AA=(AA==null)?AJ+AG/2:AA;var z=AC-this.paper.width/2,AI=AA-this.paper.height/2;if(this.type=="path"||this.type=="text"){(e.left!=z+"px")&&(e.left=z+"px");(e.top!=AI+"px")&&(e.top=AI+"px");this.X=this.type=="text"?AK:-z;this.Y=this.type=="text"?AJ:-AI;this.W=AL;this.H=AG;(AD.left!=-z+"px")&&(AD.left=-z+"px");(AD.top!=-AI+"px")&&(AD.top=-AI+"px");}else{(e.left!=z+"px")&&(e.left=z+"px");(e.top!=AI+"px")&&(e.top=AI+"px");this.X=AK;this.Y=AJ;this.W=AL;this.H=AG;(e.width!=this.paper.width+"px")&&(e.width=this.paper.width+"px");(e.height!=this.paper.height+"px")&&(e.height=this.paper.height+"px");(AD.left!=AK-z+"px")&&(AD.left=AK-z+"px");(AD.top!=AJ-AI+"px")&&(AD.top=AJ-AI+"px");(AD.width!=AL+"px")&&(AD.width=AL+"px");(AD.height!=AG+"px")&&(AD.height=AG+"px");var AM=(+AB.r||0)/(Math.min(AL,AG));if(this.type=="rect"&&this.arcsize!=AM&&(AM||this.arcsize)){var R=v(AM?"roundrect":"rect");R.arcsize=AM;this.Group.appendChild(R);this.node.parentNode.removeChild(this.node);this.node=R;this.arcsize=AM;f(this,this.attrs);this.setBox(this.attrs);}}};K.prototype.hide=function(){this.Group.style.display="none";return this;};K.prototype.show=function(){this.Group.style.display="block";return this;};K.prototype.getBBox=function(){if(this.type=="path"){return b(this.attrs.path);}return{x:this.X+(this.bbx||0),y:this.Y,width:this.W,height:this.H};};K.prototype.remove=function(){this[0].parentNode.removeChild(this[0]);this.Group.parentNode.removeChild(this.Group);this.shape&&this.shape.parentNode.removeChild(this.shape);};K.prototype.attr=function(){if(arguments.length==1&&typeof arguments[0]=="string"){if(arguments[0]=="translation"){return this.translate();}if(arguments[0]=="rotation"){return this.rotate();}if(arguments[0]=="scale"){return this.scale();}return this.attrs[arguments[0]];}if(this.attrs&&arguments.length==1&&E.isArray(arguments[0])){var R={};for(var e=0,z=arguments[0].length;e<z;e++){R[arguments[0][e]]=this.attrs[arguments[0][e]];}return R;}var AA;if(arguments.length==2){AA={};AA[arguments[0]]=arguments[1];}if(arguments.length==1&&typeof arguments[0]=="object"){AA=arguments[0];}if(AA){if(AA.gradient){n(this,AA.gradient);}if(AA.text&&this.type=="text"){this.node.string=AA.text;}f(this,AA);this.setBox(this.attrs);}return this;};K.prototype.toFront=function(){this.Group.parentNode.appendChild(this.Group);return this;};K.prototype.toBack=function(){if(this.Group.parentNode.firstChild!=this.Group){this.Group.parentNode.insertBefore(this.Group,this.Group.parentNode.firstChild);}return this;};K.prototype.insertAfter=function(R){if(R.Group.nextSibling){R.Group.parentNode.insertBefore(this.Group,R.Group.nextSibling);}else{R.Group.parentNode.appendChild(this.Group);}return this;};K.prototype.insertBefore=function(R){R.Group.parentNode.insertBefore(this.Group,R.Group);return this;};var c=function(e,AE,AD,R){var AA=v("group"),z=AA.style,i=v("oval"),AC=i.style;z.position="absolute";z.left=0;z.top=0;z.width=e.width+"px";z.height=e.height+"px";AA.coordsize=e.coordsize;AA.coordorigin=e.coordorigin;AA.appendChild(i);var AB=new K(i,AA,e);AB.type="circle";f(AB,{stroke:"#000",fill:"none"});AB.attrs.cx=AE;AB.attrs.cy=AD;AB.attrs.r=R;AB.setBox({x:AE-R,y:AD-R,width:R*2,height:R*2});e.canvas.appendChild(AA);return AB;};var j=function(e,AE,AD,AF,AA,R){var AB=v("group"),z=AB.style,i=v(R?"roundrect":"rect"),AG=(+R||0)/(Math.min(AF,AA));i.arcsize=AG;z.position="absolute";z.left=0;z.top=0;z.width=e.width+"px";z.height=e.height+"px";AB.coordsize=e.coordsize;AB.coordorigin=e.coordorigin;AB.appendChild(i);var AC=new K(i,AB,e);AC.type="rect";f(AC,{stroke:"#000"});AC.arcsize=AG;AC.setBox({x:AE,y:AD,width:AF,height:AA,r:+R});e.canvas.appendChild(AB);return AC;};var G=function(R,AF,AE,i,e){var AB=v("group"),AA=AB.style,z=v("oval"),AD=z.style;AA.position="absolute";AA.left=0;AA.top=0;AA.width=R.width+"px";AA.height=R.height+"px";AB.coordsize=R.coordsize;AB.coordorigin=R.coordorigin;AB.appendChild(z);var AC=new K(z,AB,R);AC.type="ellipse";f(AC,{stroke:"#000"});AC.attrs.cx=AF;AC.attrs.cy=AE;AC.attrs.rx=i;AC.attrs.ry=e;AC.setBox({x:AF-i,y:AE-e,width:i*2,height:e*2});R.canvas.appendChild(AB);return AC;};var N=function(e,R,AF,AE,AG,AA){var AB=v("group"),z=AB.style,i=v("image"),AD=i.style;z.position="absolute";z.left=0;z.top=0;z.width=e.width+"px";z.height=e.height+"px";AB.coordsize=e.coordsize;AB.coordorigin=e.coordorigin;i.src=R;AB.appendChild(i);var AC=new K(i,AB,e);AC.type="image";AC.attrs.src=R;AC.attrs.x=AF;AC.attrs.y=AE;AC.attrs.w=AG;AC.attrs.h=AA;AC.setBox({x:AF,y:AE,width:AG,height:AA});e.canvas.appendChild(AB);return AC;};var h=function(e,AF,AE,AG){var AB=v("group"),AA=AB.style,z=v("shape"),AD=z.style,AH=v("path"),R=AH.style,i=v("textpath");AA.position="absolute";AA.left=0;AA.top=0;AA.width=e.width+"px";AA.height=e.height+"px";AB.coordsize=e.coordsize;AB.coordorigin=e.coordorigin;AH.v=["m",Math.round(AF),", ",Math.round(AE),"l",Math.round(AF)+1,", ",Math.round(AE)].join("");AH.textpathok=true;AD.width=e.width;AD.height=e.height;AA.position="absolute";AA.left=0;AA.top=0;AA.width=e.width;AA.height=e.height;i.string=AG;i.on=true;z.appendChild(i);z.appendChild(AH);AB.appendChild(z);var AC=new K(i,AB,e);AC.shape=z;AC.textpath=AH;AC.type="text";AC.attrs.text=AG;AC.attrs.x=AF;AC.attrs.y=AE;AC.attrs.w=1;AC.attrs.h=1;f(AC,{font:O.font,stroke:"none",fill:"#000"});AC.setBox();e.canvas.appendChild(AB);return AC;};var d=function(i,R){var e=this.canvas.style;this.width=i||this.width;this.height=R||this.height;e.width=this.width+"px";e.height=this.height+"px";e.clip="rect(0 "+this.width+"px "+this.height+"px 0)";this.canvas.coordsize=this.width+" "+this.height;return this;};F.createStyleSheet().addRule(".rvml","behavior:url(#default#VML)");try{!F.namespaces.rvml&&F.namespaces.add("rvml","urn:schemas-microsoft-com:vml");var v=function(R){return F.createElement("<rvml:"+R+' class="rvml">');};}catch(u){var v=function(R){return F.createElement("<"+R+' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');};}var J=function(){var z=g.apply(null,arguments),e=z.container,AE=z.height,AF,i=z.width,AD=z.x,AC=z.y;if(!e){throw new Error("VML container not found.");}var AB=B.canvas=F.createElement("div"),AA=AB.style;i=parseFloat(i)||"512px";AE=parseFloat(AE)||"342px";B.width=i;B.height=AE;B.coordsize=i+" "+AE;B.coordorigin="0 0";B.span=F.createElement("span");AF=B.span.style;AB.appendChild(B.span);AF.position="absolute";AF.left="-99999px";AF.top="-99999px";AF.padding=0;AF.margin=0;AF.lineHeight=1;AF.display="inline";AA.width=i+"px";AA.height=AE+"px";AA.position="absolute";AA.clip="rect(0 "+i+"px "+AE+"px 0)";if(e==1){F.body.appendChild(AB);AA.left=AD+"px";AA.top=AC+"px";e={style:{width:i,height:AE}};}else{e.style.width=i;e.style.height=AE;if(e.firstChild){e.insertBefore(AB,e.firstChild);}else{e.appendChild(AB);}}for(var R in B){e[R]=B[R];}A.call(e,e,E.fn);e.clear=function(){while(AB.firstChild){AB.removeChild(AB.firstChild);}};e.raphael=E;return e;};B.remove=function(){this.canvas.parentNode.removeChild(this.canvas);};B.safari=function(){};}var H=(function(){if(F.addEventListener){return function(AA,i,e,R){var z=function(AB){return e.call(R,AB);};AA.addEventListener(i,z,false);return function(){AA.removeEventListener(i,z,false);return true;};};}else{if(F.attachEvent){return function(AB,z,i,e){var AA=function(AC){return i.call(e,AC||m.event);};AB.attachEvent("on"+z,AA);var R=function(){AB.detachEvent("on"+z,AA);return true;};if(z=="mouseover"){AB.attachEvent("onmouseenter",AA);return function(){AB.detachEvent("onmouseenter",AA);return R();};}else{if(z=="mouseout"){AB.attachEvent("onmouseleave",AA);return function(){AB.detachEvent("onmouseleave",AA);return R();};}}return R;};}}})();for(var r=U.length;r--;){(function(R){K.prototype[R]=function(e){if(typeof e=="function"){this.events=this.events||{};this.events[R]=this.events[R]||{};this.events[R][e]=this.events[R][e]||[];this.events[R][e].push(H(this.shape||this.node,R,e,this));}return this;};K.prototype["un"+R]=function(e){this.events&&this.events[R]&&this.events[R][e]&&this.events[R][e].length&&this.events[R][e].shift()()&&!this.events[R][e].length&&delete this.events[R][e];};})(U[r]);}B.circle=function(R,i,e){return c(this,R,i,e);};B.rect=function(R,AA,e,i,z){return j(this,R,AA,e,i,z);};B.ellipse=function(R,z,i,e){return G(this,R,z,i,e);};B.path=function(R){if(R&&typeof R!="string"&&!E.isArray(R[0])){throw new Error("First argument for path method should be a string.");}return w(E.format.apply(E,arguments),this);};B.image=function(z,R,AA,e,i){return N(this,z,R,AA,e,i);};B.text=function(R,i,e){return h(this,R,i,e);};B.set=function(R){arguments.length>1&&(R=Array.prototype.splice.call(arguments,0,arguments.length));return new I(R);};B.setSize=d;K.prototype.stop=function(){clearTimeout(this.animation_in_progress);return this;};K.prototype.scale=function(AJ,AI,z,e){if(AJ==null&&AI==null){return{x:this._.sx,y:this._.sy,toString:function(){return this.x+" "+this.y;}};}AI=AI||AJ;!+AI&&(AI=AJ);var AN,AL,AM,AK,AZ=this.attrs;if(AJ!=0){var AH=this.getBBox(),AE=AH.x+AH.width/2,AB=AH.y+AH.height/2,AY=AJ/this._.sx,AX=AI/this._.sy;z=(+z||z==0)?z:AE;e=(+e||e==0)?e:AB;var AG=Math.round(AJ/Math.abs(AJ)),AD=Math.round(AI/Math.abs(AI)),AQ=this.node.style,Ab=z+(AE-z)*AG*AY,Aa=e+(AB-e)*AD*AX;switch(this.type){case"rect":case"image":var AF=AZ.width*AG*AY,AP=AZ.height*AD*AX,AC=Ab-AF/2,AA=Aa-AP/2;this.attr({width:AF,height:AP,x:AC,y:AA});break;case"circle":case"ellipse":this.attr({rx:AZ.rx*AY,ry:AZ.ry*AX,r:AZ.r*AY,cx:Ab,cy:Aa});break;case"path":var AS=C(AZ.path),AT=true;for(var AV=0,AO=AS.length;AV<AO;AV++){var AR=AS[AV];if(AR[0].toUpperCase()=="M"&&AT){continue;}else{AT=false;}if(E.svg&&AR[0].toUpperCase()=="A"){AR[AS[AV].length-2]*=AY;AR[AS[AV].length-1]*=AX;AR[1]*=AY;AR[2]*=AX;AR[5]=+(AG+AD?!!+AR[5]:!+AR[5]);}else{for(var AU=1,AW=AR.length;AU<AW;AU++){AR[AU]*=(AU%2)?AY:AX;}}}var R=b(AS),AN=Ab-R.x-R.width/2,AL=Aa-R.y-R.height/2;AS=C(AS);AS[0][1]+=AN;AS[0][2]+=AL;this.attr({path:AS.join(" ")});break;}if(this.type in {text:1,image:1}&&(AG!=1||AD!=1)){if(this.transformations){this.transformations[2]="scale(".concat(AG,",",AD,")");this.node.setAttribute("transform",this.transformations.join(" "));AN=(AG==-1)?-AZ.x-(AF||0):AZ.x;AL=(AD==-1)?-AZ.y-(AP||0):AZ.y;this.attr({x:AN,y:AL});AZ.fx=AG-1;AZ.fy=AD-1;}else{this.node.filterMatrix=" progid:DXImageTransform.Microsoft.Matrix(M11=".concat(AG,", M12=0, M21=0, M22=",AD,", Dx=0, Dy=0, sizingmethod='auto expand', filtertype='bilinear')");AQ.filter=(this.node.filterMatrix||"")+(this.node.filterOpacity||"");}}else{if(this.transformations){this.transformations[2]="";this.node.setAttribute("transform",this.transformations.join(" "));AZ.fx=0;AZ.fy=0;}else{this.node.filterMatrix="";AQ.filter=(this.node.filterMatrix||"")+(this.node.filterOpacity||"");}}AZ.scale=[AJ,AI,z,e].join(" ");this._.sx=AJ;this._.sy=AI;}return this;};E.easing_formulas={linear:function(R){return R;},"<":function(R){return Math.pow(R,3);},">":function(R){return Math.pow(R-1,3)+1;},"<>":function(R){R=R*2;if(R<1){return Math.pow(R,3)/2;}R-=2;return(Math.pow(R,3)+2)/2;},backIn:function(e){var R=1.70158;return e*e*((R+1)*e-R);},backOut:function(e){e=e-1;var R=1.70158;return e*e*((R+1)*e+R)+1;},elastic:function(i){if(i==0||i==1){return i;}var e=0.3,R=e/4;return Math.pow(2,-10*i)*Math.sin((i-R)*(2*Math.PI)/e)+1;},bounce:function(z){var e=7.5625,i=2.75,R;if(z<(1/i)){R=e*z*z;}else{if(z<(2/i)){z-=(1.5/i);R=e*z*z+0.75;}else{if(z<(2.5/i)){z-=(2.25/i);R=e*z*z+0.9375;}else{z-=(2.625/i);R=e*z*z+0.984375;}}}return R;}};K.prototype.animate=function(AS,AJ,AI,AA){clearTimeout(this.animation_in_progress);if(typeof AI=="function"||!AI){AA=AI||null;}var AM={},e={},AG={},AF={x:0,y:0};for(var AK in AS){if(AK in T){AM[AK]=this.attr(AK);(AM[AK]==null)&&(AM[AK]=O[AK]);e[AK]=AS[AK];switch(T[AK]){case"number":AG[AK]=(e[AK]-AM[AK])/AJ;break;case"colour":AM[AK]=E.getRGB(AM[AK]);var AL=E.getRGB(e[AK]);AG[AK]={r:(AL.r-AM[AK].r)/AJ,g:(AL.g-AM[AK].g)/AJ,b:(AL.b-AM[AK].b)/AJ};break;case"path":var AB=p(AM[AK],e[AK]);AM[AK]=AB[0];e[AK]=AB[1];AG[AK]=[];for(var AO=0,AE=AM[AK].length;AO<AE;AO++){AG[AK][AO]=[0];for(var AN=1,AQ=AM[AK][AO].length;AN<AQ;AN++){AG[AK][AO][AN]=(e[AK][AO][AN]-AM[AK][AO][AN])/AJ;}}break;case"csv":var R=(AS[AK]+"").split(y),AD=(AM[AK]+"").split(y);switch(AK){case"translation":AM[AK]=[0,0];AG[AK]=[R[0]/AJ,R[1]/AJ];break;case"rotation":AM[AK]=(AD[1]==R[1]&&AD[2]==R[2])?AD:[0,R[1],R[2]];AG[AK]=[(R[0]-AM[AK][0])/AJ,0,0];break;case"scale":AS[AK]=R;AM[AK]=(AM[AK]+"").split(y);AG[AK]=[(R[0]-AM[AK][0])/AJ,(R[1]-AM[AK][1])/AJ,0,0];break;case"clip-rect":AM[AK]=(AM[AK]+"").split(y);AG[AK]=[];var AO=4;while(AO--){AG[AK][AO]=(R[AO]-AM[AK][AO])/AJ;}break;}e[AK]=R;}}}var z=+new Date,AH=0,AR=function(i){return +i>255?255:+i;},AC=this;(function AP(){var AU=new Date-z,Ac={},AT;if(AU<AJ){var Aa=E.easing_formulas[AI]?E.easing_formulas[AI](AU/AJ):AU/AJ;for(var AY in AM){switch(T[AY]){case"number":AT=+AM[AY]+Aa*AJ*AG[AY];break;case"colour":AT="rgb("+[AR(Math.round(AM[AY].r+Aa*AJ*AG[AY].r)),AR(Math.round(AM[AY].g+Aa*AJ*AG[AY].g)),AR(Math.round(AM[AY].b+Aa*AJ*AG[AY].b))].join(",")+")";break;case"path":AT=[];for(var AW=0,Ad=AM[AY].length;AW<Ad;AW++){AT[AW]=[AM[AY][AW][0]];for(var AV=1,AX=AM[AY][AW].length;AV<AX;AV++){AT[AW][AV]=+AM[AY][AW][AV]+Aa*AJ*AG[AY][AW][AV];}AT[AW]=AT[AW].join(" ");}AT=AT.join(" ");break;case"csv":switch(AY){case"translation":var Ab=AG[AY][0]*(AU-AH),AZ=AG[AY][1]*(AU-AH);AF.x+=Ab;AF.y+=AZ;AT=[Ab,AZ].join(" ");break;case"rotation":AT=+AM[AY][0]+Aa*AJ*AG[AY][0];AM[AY][1]&&(AT+=","+AM[AY][1]+","+AM[AY][2]);break;case"scale":AT=[+AM[AY][0]+Aa*AJ*AG[AY][0],+AM[AY][1]+Aa*AJ*AG[AY][1],(2 in AS[AY]?AS[AY][2]:""),(3 in AS[AY]?AS[AY][3]:"")].join(" ");break;case"clip-rect":AT=[];var AW=4;while(AW--){AT[AW]=+AM[AY][AW]+Aa*AJ*AG[AY][AW];}break;}break;}Ac[AY]=AT;}AC.attr(Ac);AC.animation_in_progress=setTimeout(AP);E.svg&&B.safari();}else{(AF.x||AF.y)&&AC.translate(-AF.x,-AF.y);AC.attr(AS);clearTimeout(AC.animation_in_progress);E.svg&&B.safari();(typeof AA=="function")&&AA.call(AC);}AH=AU;})();return this;};K.prototype.translate=function(R,i){if(R==null){return{x:this._.tx,y:this._.ty};}this._.tx+=+R;this._.ty+=+i;switch(this.type){case"circle":case"ellipse":this.attr({cx:+R+this.attrs.cx,cy:+i+this.attrs.cy});break;case"rect":case"image":case"text":this.attr({x:+R+this.attrs.x,y:+i+this.attrs.y});break;case"path":var e=C(this.attrs.path);e[0][1]+=+R;e[0][2]+=+i;this.attr({path:e});break;}return this;};var I=function(R){this.items=[];this.length=0;if(R){for(var e=0,z=R.length;e<z;e++){if(R[e]&&(R[e].constructor==K||R[e].constructor==I)){this[this.items.length]=this.items[this.items.length]=R[e];this.length++;}}}};I.prototype.push=function(){var AA,R;for(var e=0,z=arguments.length;e<z;e++){AA=arguments[e];if(AA&&(AA.constructor==K||AA.constructor==I)){R=this.items.length;this[R]=this.items[R]=AA;this.length++;}}return this;};I.prototype.pop=function(){delete this[this.length--];return this.items.pop();};for(var s in K.prototype){I.prototype[s]=(function(R){return function(){for(var e=0,z=this.items.length;e<z;e++){this.items[e][R].apply(this.items[e],arguments);}return this;};})(s);}I.prototype.attr=function(e,AC){if(e&&E.isArray(e)&&typeof e[0]=="object"){for(var R=0,AB=e.length;R<AB;R++){this.items[R].attr(e[R]);}}else{for(var z=0,AA=this.items.length;z<AA;z++){this.items[z].attr.apply(this.items[z],arguments);}}return this;};I.prototype.getBBox=function(){var R=[],AC=[],e=[],AA=[];for(var z=this.items.length;z--;){var AB=this.items[z].getBBox();R.push(AB.x);AC.push(AB.y);e.push(AB.x+AB.width);AA.push(AB.y+AB.height);}R=Math.min.apply(Math,R);AC=Math.min.apply(Math,AC);return{x:R,y:AC,width:Math.max.apply(Math,e)-R,height:Math.max.apply(Math,AA)-AC};};E.registerFont=function(e){if(!e.face){return e;}this.fonts=this.fonts||{};var z={w:e.w,face:{},glyphs:{}},i=e.face["font-family"];for(var AC in e.face){z.face[AC]=e.face[AC];}if(this.fonts[i]){this.fonts[i].push(z);}else{this.fonts[i]=[z];}if(!e.svg){z.face["units-per-em"]=parseInt(e.face["units-per-em"],10);for(var AA in e.glyphs){var AB=e.glyphs[AA];z.glyphs[AA]={w:AB.w,k:{},d:AB.d&&"M"+AB.d.replace(/[mlcxtrv]/g,function(AD){return{l:"L",c:"C",x:"z",t:"m",r:"l",v:"c"}[AD]||"M";})+"z"};if(AB.k){for(var R in AB.k){z.glyphs[AA].k[R]=AB.k[R];}}}}return e;};B.getFont=function(AE,AF,e,AA){AA=AA||"normal";e=e||"normal";AF=+AF||{normal:400,bold:700,lighter:300,bolder:800}[AF]||400;var AB=E.fonts[AE];if(!AB){var z=new RegExp("(^|\\s)"+AE.replace(/[^\w\d\s+!~.:_-]/g,"")+"(\\s|$)","i");for(var R in E.fonts){if(z.test(R)){AB=E.fonts[R];break;}}}var AC;if(AB){for(var AD=0,AG=AB.length;AD<AG;AD++){AC=AB[AD];if(AC.face["font-weight"]==AF&&(AC.face["font-style"]==e||!AC.face["font-style"])&&AC.face["font-stretch"]==AA){break;}}}return AC;};B.print=function(AG,AF,AD,e,AK){var AB=this.set(),AE=(AD+"").split(""),R=0,AJ="",AA;typeof e=="string"&&(e=this.getFont(e));if(e){AA=(AK||16)/e.face["units-per-em"];for(var AC=0,AH=AE.length;AC<AH;AC++){var z=AC&&e.glyphs[AE[AC-1]]||{},AI=e.glyphs[AE[AC]];R+=AC?(z.w||e.w)+(z.k&&z.k[AE[AC]]||0):0;AI&&AI.d&&AB.push(this.path(AI.d).attr({fill:"#000",stroke:"none",translation:[R,0]}));}AB.scale(AA,AA,0,AF).translate(AG,(AK||16)/2);}return AB;};E.format=function(e){var R=E.isArray(arguments[1])?[0].concat(arguments[1]):arguments;e&&typeof e=="string"&&R.length-1&&(e=e.replace(/\{(\d+)\}/g,function(AA,z){return R[++z]==null?"":R[z];}));return e;};E.ninja=function(){var R=window.Raphael;if(q.was){window.Raphael=q.is;}else{try{delete window.Raphael;}catch(i){window.Raphael=void (0);}}return R;};E.el=K.prototype;return E;})();

System = {
	started:false,
	frameSize:5,
	toolFrameSize:4,
	captionBarSize:22,
	toolCaptionBarSize:18,
	borderColor: '#6c7579',
	windowColor: '#a3a4a4',
	captionBarFontSize: 12,
	captionBarFontColor: '#fff',
	toolCaptionBarFontSize: 11,
	lightBorder:'#fff',
	darkBorder:'#999',
	backColor:'#eee',
	lightBackColor:'#fdfdfd',
	buttonFontSize: 11,	
	contextMenuColor:'#fff',
	contextMenuBorderColor:'#aaa',
	path:'',
	round:function(value,prec){
		var mno = 1.0;
		for (var i=0;i<prec;i++) mno*=10.0;
		var w = Math.round(value*mno)/mno;
		var wt = w.toString();
		if (wt.indexOf('.')==-1) {
			wt+='.';
			for (var j=0;j<prec;j++) wt+='0';
		}
		return wt;
	},
	writeSpec:function(text){
		while(text.indexOf('&')!=-1){
			text = text.replace('&','(and)');
		}
		return text;
	},	
	readSpec:function(text){
		return text.replace('(and)','&');
	},		
	getElementsWithParent : function(element,tagName){
		var nodes = element.getElementsByTagName(tagName);
		var tab = new Array();
		for (var i=0;i<nodes.length;i++){
			if (nodes[i].parentNode == element) {
				tab.push(nodes[i]);
			}	
		}
		return tab;
	},
	includeModule:function(moduleName,oninclude){
		System.Utils.loadScript(System.path+'modules/'+moduleName+'.js',function(){
			if (oninclude) oninclude();
		});		
	},
	boolToInt:function(value){
		if (value==true) return 1;
		if (value==false) return 0;
		return 0;
	},
	intToBool:function(value){
		if (value==1) return true;
		if (value==0) return false;
		return false;
	},
	textToXml:function(text){
		try {
			xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc.async="false";
			xmlDoc.loadXML(text);
			return xmlDoc;
		}
		catch(e){
			var parser=new DOMParser();
			var xmlDoc=parser.parseFromString(text,"text/xml");
			return xmlDoc;
		}
	},	
	strToBool:function(value){
		if (value!=null){
			value = value.toLowerCase();
			if ((value=='true')||(value=='t')||(value=='y')||(value=='1')) return true;
			if ((value=='false')||(value=='f')||(value=='n')||(value=='0')) return false;
		}
		return false;
	},
	start:function(div,offset){
		Array.prototype.remove = function(from, to) {
			var rest = this.slice((to || from) + 1 || this.length);
			this.length = from < 0 ? this.length + from : from;
			return this.push.apply(this, rest);
		};
		Array.prototype.removeItem = function(item) {
			for (var i=0;i<this.length;i++){
				if (this[i]==item) {
					this.remove(i);
					break;	
				}	
			}
		};	
		Array.prototype.isItem = function(item) {
			for (var i=0;i<this.length;i++){
				if (this[i]==item) {
					return true;	
				}	
			}
			return false;
		};
		String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }
		this.keys = new Array()
		document.onkeyup=function(e){
			var key = null;
			if(window.event){
				key = window.event.keyCode;
			} else
			key = e.which;
			System.keys[key] = false;
			System.Utils.Keys.handleKeyUp(key);
		} 
		document.onkeydown=function(e){ 
			var key = null;
			if(window.event){
				key = window.event.keyCode;
			} else
			key = e.which;
			System.keys[key] = true;
			System.Utils.Keys.handleKeyDown(key);
		} 
		
		
		this.folderPath = this.path+'system/';
		this.windows = new Array();
		this.checkButtons = new Array();
		//tworzenie głwnego div-a
		
		if (offset==null) offset = 0;
		this.systemDiv = this.createDiv(0,offset,0,0,null,null);
		this.systemDiv.style.backgroundColor = '#eee';
		this.systemDiv.style.overflow = 'hidden';
		this.systemDiv.style.textAlign = 'left';
		this.systemDiv.style.fontFamily = 'tahoma';
		this.systemDiv.style.fontSize = '12px'
		
		if (div==null)
		document.body.appendChild(this.systemDiv);
		else
		div.appendChild(this.systemDiv);
		
		document.body.style.height = '100%';
		this.started = true;
		this.zIndex = 1000; 
		
		this.loadingDiv = this.createDiv(0,0,0,0,null,null);
		this.systemDiv.appendChild(this.loadingDiv);
		this.loadingDiv.style.backgroundImage = 'url('+System.folderPath+'blank.png)';		
		var load = this.createDiv(0,0,0,0,null,null);
		load.style.backgroundImage = 'url('+System.folderPath+'loading.gif)';
		load.style.backgroundPosition='center center';
		load.style.backgroundRepeat = 'no-repeat';
		this.loadingDiv.appendChild(load);
		this.loadingDiv.style.display = 'none';
		this.closeLoadingDiv = this.createDiv(null,null,0,0,40,20);
		this.closeLoadingDiv.innerHTML = 'close';
		this.closeLoadingDiv.style.fontSize='11px';
		this.closeLoadingDiv.style.color = '#aaa';
		this.closeLoadingDiv.style.cursor = 'pointer';
		this.closeLoadingDiv.onclick = function(){
			System.endLoading();
		}
		this.loadingDiv.appendChild(this.closeLoadingDiv);
		
		this.winConsole = new System.Window({x:50,y:50,width:600,height:300,text:'Console'});
		this.winConsole.workspaceDiv.style.overflow = 'auto';
		this.winConsole.hide();
		this.showConsole = function(){
			this.winConsole.show();
		}
		this.hideConsole = function(){
			this.winConsole.hide();
		}		
		this.write = function(text){
			this.winConsole.workspaceDiv.innerHTML+=text+'<br/>';
		}
	
		if (window.addEventListener)
		window.addEventListener('DOMMouseScroll', System.Utils.Mouse.wheelEvent, false);
		window.onmousewheel = document.onmousewheel = System.Utils.Mouse.wheelEvent;
	},
	startLoading:function(){
		this.loadingDiv.style.display = 'block';
		this.loadingDiv.style.zIndex = this.zIndex;
		this.zIndex+=1000;
	},
	endLoading:function(){
		this.loadingDiv.style.display = 'none';
	},
	createDiv:function(left,top,right,bottom,width,height){
		var div = document.createElement('div');
		div.style.position = 'absolute';
		if (left!=null)
		div.style.left = left+'px';
		if (top!=null)
		div.style.top = top+'px';
		if (right!=null)
		div.style.right = right+'px';
		if (bottom!=null)
		div.style.bottom = bottom+'px';
		if (width!=null)
		div.style.width = width+'px';
		if (height!=null)
		div.style.height = height+'px';
		return div;
	},
	setDiv:function(div,left,top,right,bottom,width,height){
		if (left!=null)
		div.style.left = left+'px';
		if (top!=null)
		div.style.top = top+'px';
		if (right!=null)
		div.style.right = right+'px';
		if (bottom!=null)
		div.style.bottom = bottom+'px';
		if (width!=null)
		div.style.width = width+'px';
		if (height!=null)
		div.style.height = height+'px';
	},
	createColoredFrame:function(size,color,borderColor){
		var div = this.createDiv(0,0,0,0,null,null);
		var top = this.createDiv(size,0,size,null,null,size-1);
		top.style.backgroundColor = color;
		top.style.borderTop = '1px solid '+borderColor;
		div.appendChild(top);
		var left = this.createDiv(0,size,null,size,size-1,null);
		left.style.backgroundColor = color;
		left.style.borderLeft = '1px solid '+borderColor;
		div.appendChild(left);
		var lefttop = this.createDiv(0,0,null,null,size-1,size-1);
		lefttop.style.backgroundColor = color;
		lefttop.style.borderLeft = '1px solid '+borderColor;
		lefttop.style.borderTop = '1px solid '+borderColor;
		div.appendChild(lefttop);		
		var righttop = this.createDiv(null,0,0,null,size-1,size-1);
		righttop.style.backgroundColor = color;
		righttop.style.borderRight = '1px solid '+borderColor;
		righttop.style.borderTop = '1px solid '+borderColor;
		div.appendChild(righttop);	
		var right = this.createDiv(null,size,0,size,size-1,null);
		right.style.backgroundColor = color;
		right.style.borderRight= '1px solid '+borderColor;
		div.appendChild(right);		
		var rightbottom = this.createDiv(null,null,0,0,size-1,size-1);
		rightbottom.style.backgroundColor = color;
		rightbottom.style.borderRight= '1px solid '+borderColor;
		rightbottom.style.borderBottom= '1px solid '+borderColor;
		div.appendChild(rightbottom);
		var leftbottom = this.createDiv(0,null,null,0,size-1,size-1);
		leftbottom.style.backgroundColor = color;
		leftbottom.style.borderLeft= '1px solid '+borderColor;
		leftbottom.style.borderBottom= '1px solid '+borderColor;
		div.appendChild(leftbottom);
		var bottom = this.createDiv(size,null,size,0,null,size-1);
		bottom.style.backgroundColor = color;
		bottom.style.borderBottom = '1px solid '+borderColor;
		div.appendChild(bottom);		
		return [div,top,righttop,right,rightbottom,bottom,leftbottom,left,lefttop];
	},
	addWindow:function(window){
		if (this.started == true){
			if ((parent!=null)&&(window.formType == 'WINDOW')){
				this.windows.push(window);
				this.systemDiv.appendChild(window.mainDiv);
				window.mainDiv.style.zIndex =  this.zIndex;
				this.zIndex+=1000;
			} else {
				alert('Nie można uruchomić okna');
			}
		} else {
			alert('System jeszce nie wystartował'); 
		}		
	},
	getWidth:function(){
		return this.systemDiv.clientWidth;
	},
	getHeight:function(){
		return this.systemDiv.clientHeight;
	},
	disableSelection:function(div){
		if (div){
		if (typeof div.onselectstart!="undefined") //IE route
			div.onselectstart=function(){return false}
		else 
			div.onmousedown=function(){return false}
		div.style.cursor = "default"	
		}
	},
	disableContextMenu:function(div){
		div.oncontextmenu = function(e){
			return false; 
		}	
	},
	cancelMouseUp:function(div){
		div.onmouseup = function(e){
			if (!e) var e = window.event
			e.cancelBubble = true;
			if (e.stopPropagation) e.stopPropagation();		
		}	
	},
	cancelMouseDown:function(div){
		if (div)
		div.onmousedown = function(e){
			if (!e) var e = window.event
			e.cancelBubble = true;
			if (e.stopPropagation) e.stopPropagation();		
		}	
	},
	cancelClick:function(div){
		div.onclick = function(e){
			if (!e) var e = window.event
			e.cancelBubble = true;
			if (e.stopPropagation) e.stopPropagation();		
		}	
	},
	cancelMouseOver:function(div){
		div.onmouseover = function(e){
			if (!e) var e = window.event
			e.cancelBubble = true;
			if (e.stopPropagation) e.stopPropagation();		
		}	
	},
	mouseDown:function(e){
		e = e || window.event;
		if (e.preventDefault){
			e.preventDefault();
		}
	},
	addEvent:function(element,event,fun){
		if (element.addEventListener){
			element.addEventListener(event,fun,false);
		} else {
			element.attachEvent('on'+event,fun);
		}
	},	
	addGlobalEvent:function(event,fun){
		this.addEvent(this.systemDiv,event,fun);
	},
	divPosition:function(div) {
		var left = 0;
		var top = 0;
		if (div.offsetParent) {
		do {
			left += div.offsetLeft;
			top += div.offsetTop;
			div = div.offsetParent;
		} while (div!=this.systemDiv);
		}
		return [left,top];
	},
	globalDivPosition:function(div) {
		var left = 0;
		var top = 0;
		if (div.offsetParent) {
		do {
			left += div.offsetLeft;
			top += div.offsetTop;
		} while (div = div.offsetParent)
		}
		return [left,top];
	},	
	mouseCoordinates:function (e){
		function isIE() {
			return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
		}
	
		var posx = 0;
		var posy = 0;
	
		if (!e) var e = window.event;
		if (e.pageX || e.pageY) 	{
			posx = e.pageX;
			posy = e.pageY;
		}
		else if (e.clientX || e.clientY) 	{
			posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
			posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
		}
		if (isIE()==true) {
			posx-=2;
			posy-=2;
			if (this.iedx){
				posx+=this.iedx;
				posy+=this.iedy;				
			}
		}	
		var pos = this.globalDivPosition(this.systemDiv);
		posx-=pos[0];
		posy-=pos[1];
		return [posx,posy];
	},
	setIEOffset : function(dx,dy){
		this.iedx = dx;
		this.iedy = dy;	
	},
	isRightButtonPressed:function (e) {
		var rightclick;
		if (!e) var e = window.event;
		if (e.which) rightclick = (e.which == 3);
		else if (e.button) rightclick = (e.button == 2);
		return rightclick;
	},
	Utils : {
		Ajax:{
			post:function(url,param,onload){
				advAJAX.post({
					url : url,
					parameters : param, 
					onSuccess : function(obj) {
						onload(obj);
					},
					onError : function(obj) { alert("blad: " + obj.status); },
					onTimeout : function() { alert("Connection timed out."); },
					onRetry : function() { alert("Retry connection..."); },
					onRetryDelay : function() { alert("Awaiting retry..."); },
					onError : function(obj) { alert("Error: " + obj.status); }
				});					
			},
			get:function(url,param,onload){
				advAJAX.get({
					url : url,
					parameters : param, 
					onSuccess : function(obj) {
						onload(obj);
					},
					timeout : 10000,
					onTimeout : function() { alert("Connection timed out."); },
					onRetry : function() { alert("Retry connection..."); },
					onRetryDelay : function() { alert("Awaiting retry..."); },
					onError : function(obj) { alert("Error: " + obj.status); }
				});					
			},
			getUrl:function(param,onload){
				this.post(System.folderPath+'geturl.php',param,function(obj){
					if (onload) onload(obj);
				});
			}
		},
		Language:function(fileUrl,onload){
			var object = this;
			this.languages = new Array();
			this.frazes = new Array();
			this.actualLang = null;
			this.setLanguage = function(id){
				this.actualLang = id;
			}
			this.getById = function(id){
				for (var i=0;i<this.frazes.length;i++){
					var f = this.frazes[i];
					if ((f.lang == this.actualLang)&&(f.id == id)) return f.text;
				}
				return '###';
			}
			this.getByName = function(name){
				for (var i=0;i<this.frazes.length;i++){
					var f = this.frazes[i];
					if ((f.lang == this.actualLang)&&(f.name == name)) return f.text;
				}
				return '###';
			}			
			System.Utils.Ajax.get(fileUrl,{},function(obj){
				var xml = obj.responseXML;
				var root = xml.getElementsByTagName('root')[0];		
				var langs = root.getElementsByTagName('available_languages')[0].getElementsByTagName('language');
				for (var i=0;i<langs.length;i++){
					var language = {name:langs[i].getElementsByTagName('name')[0].childNodes[0].data,
									id:parseInt(langs[i].getElementsByTagName('id')[0].childNodes[0].data)};
					object.languages.push(language);
					object.setLanguage(language.id);
				}
				
				var frazes = root.getElementsByTagName('frazes')[0].getElementsByTagName('fraze');
				for (var i=0;i<frazes.length;i++){
					var fraze = {id:parseInt(frazes[i].getAttribute("id")),lang:parseInt(frazes[i].getAttribute("lang")),name:frazes[i].getAttribute("name"),text:frazes[i].childNodes[0].data};
					object.frazes.push(fraze);
				}				
				if (onload) onload();
			});	
		},
		loadScript:function(url,onload) {
			var headID = document.getElementsByTagName("head")[0];         
			var newScript = document.createElement('script');
			newScript.type = 'text/javascript';
			
			newScript.onreadystatechange= function () {
				if (this.readyState == 'loaded') {onload(); }
			}

			newScript.onload=onload;
			newScript.src = url+'?'+(Math.round(Math.random()*Math.random()*1000000));
			headID.appendChild(newScript);
		},
		DataTime:{
			createDate:function(value){
				var y = parseInt(value.substring(0,4));
				var m = parseInt(value.substring(5,7));
				var d = parseInt(value.substring(8,10));
				var h = parseInt(value.substring(11,13));
				var n = parseInt(value.substring(14,16));
				var s = parseInt(value.substring(17,19));
				return new Date(y,m,d,h,n,s);	
			}
		},
		Mouse:{
			handleWheel:function(delta){
			},
			wheelEvent:function(event){
				var delta = 0;
				if (!event) /* For IE. */
					event = window.event;
				if (event.wheelDelta) { /* IE/Opera. */
					delta = event.wheelDelta/120;
					/** In Opera 9, delta differs in sign as compared to IE.  */
					if (window.opera)
                        delta = -delta;
				} else 
				if (event.detail) { /** Mozilla case. */
					/** In Mozilla, sign of delta is different than in IE.
					* Also, delta is multiple of 3.*/
					delta = -event.detail/3;
				}
				/** If delta is nonzero, handle it.
				* Basically, delta is now positive if wheel was scrolled up,
				* and negative, if wheel was scrolled down.
				*/
				var dalej = true;
				if (delta){
					dalej = System.Utils.Mouse.handleWheel(delta);
				}
				if (dalej==false){
					if (event.preventDefault)
					event.preventDefault();
					event.returnValue = false;
				}
			}
		},
		Keys:{
			handleKeyDown:function(code){
			
			},
			handleKeyUp:function(code){
			
			}			
		}
	},	
	// lightBorder,darkBorder - kolor 
	// x,y - pozycja okna 
	// width,height - wymiary okna
	// anchorTop,anchorLeft,anchorRight,anchorBottom - kotwice (true,false);
	// backColor
	// lightBackColor
	// image - adres obrazka
	// funkcje: onclick()	
	Button:function (param,parent){
		var obj = this;
		this.hide = function(){
			this.mainDiv.style.display = 'none';
		}
		this.show = function(){
			this.mainDiv.style.display = 'block';
		}		
		this.setText =  function(text){
			var div = document.getElementById(this.idText);
			div.innerHTML = text;
		}
		this.setEnabled = function(enabled){
			this.enabled = enabled;
			var div = document.getElementById(this.idText);
			if (enabled==true) 
				div.style.color = '#000';
			else
				div.style.color = '#666';
			
		}
		this.setWidth = function(width){
			this.mainDiv.style.width = width+'px';
		}
		this.setImage = function(url){
			var td = document.getElementById(obj.imageDivId);		
			if (td!=null) td.style.backgroundImage = 'url('+url+')';
		}
		this.calculatePositionParameters = function(){
			var parentWidth = 0;
			var parentHeight = 0;
			
			parentWidth = this.parentDiv.clientWidth;
			parentHeight = this.parentDiv.clientHeight;
				
			if ((this.anchorLeft == true)&&(this.anchorRight == false)){
				this.styleRight = null;
				this.styleLeft = this.x;
				this.styleWidth = this.width;
			}
			if ((this.anchorLeft == false)&&(this.anchorRight == true)){
				this.styleRight = parentWidth-this.x-this.width;
				this.styleWidth = this.width;
				this.styleLeft = null;
			}
			if ((this.anchorLeft == true)&&(this.anchorRight == true)){
				this.styleLeft = this.x;
				this.styleRight = parentWidth-this.x-this.width;			
				this.styleWidth = null;
			}
			
			if ((this.anchorTop == true)&&(this.anchorBottom == false)){
				this.styleTop = this.y;
				this.styleHeight = this.height;
				this.styleBottom = null;
			}		
			if ((this.anchorTop == false)&&(this.anchorBottom == true)){
				this.styleBottom = parentHeight-this.y-this.height;
				this.styleHeight = this.height;
				this.styleTop = null;
			}			
			if ((this.anchorTop == true)&&(this.anchorBottom == true)){
				this.styleTop = this.y;
				this.styleBottom = parentHeight-this.y-this.height;
				this.styleHeight = null;
			}		
		}
		this.setPositionFromActualParameters = function(){
			obj.calculatePositionParameters(); 
			if (obj.styleWidth!=null) obj.styleWidth-=2;
			if (obj.styleHeight!=null) obj.styleHeight-=2;
		
			System.setDiv(obj.mainDiv,obj.styleLeft,obj.styleTop,obj.styleRight,obj.styleBottom,obj.styleWidth,obj.styleHeight);
		}
		this.setPosition = function(x,y){
			obj.x = x;
			obj.y = y;
			obj.setPositionFromActualParameters();
		}
		if ((param!=null)&&(parent!=null)){
			this.formType = 'BUTTON';
			this.enabled = true;
			this.parentDiv = null;
			if (parent.nodeName=='DIV')
			this.parentDiv = parent;
			else {
				if (parent.formType!=undefined){
					if (parent.formType == 'WINDOW') this.parentDiv = parent.getWorkspaceDiv();
					if (parent.formType == 'PANEL') this.parentDiv = parent.mainDiv;
				}
			}
			
			if (this.parentDiv!=null){	
				this.onclick = null;
				if (param.x!=null)
					this.x = param.x;
				else
					this.x = 0;
			
				if (param.y!=null)
					this.y = param.y;
				else
					this.y = 0;
			
				if (param.width!=null)
					this.width = param.width;
				else
					this.width = 24;		
    
				if (param.height!=null)
					this.height = param.height;
				else
					this.height = 24;
			
				if (param.anchorLeft!=null)
					this.anchorLeft = param.anchorLeft;
				else
					this.anchorLeft = true;
			
				if (param.anchorTop!=null)
					this.anchorTop = param.anchorTop;
				else
					this.anchorTop = true;
				
				if (param.anchorRight!=null)
					this.anchorRight = param.anchorRight;
				else
					this.anchorRight = false;	
    
				if (param.anchorBottom!=null)
					this.anchorBottom = param.anchorBottom;
				else
					this.anchorBottom = false;	
				
				if ((this.anchorBottom == false)&&(this.anchorTop == false)) this.anchorTop = true;	
				if ((this.anchorLeft == false)&&(this.anchorRight == false)) this.anchorLeft = true;	
			
				if (param.lightBorder!=null)
					this.lightBorder = param.lightBorder;
				else
					this.lightBorder = System.lightBorder;
					
				if (param.darkBorder!=null)
					this.darkBorder = param.darkBorder;
				else
					this.darkBorder = System.darkBorder;	
					
				if (param.backColor!=null)
					this.backColor = param.backColor;
				else
					this.backColor = '';	
					
				this.image = param.image; 	
				if (param.lightBackColor!=null)
					this.lightBackColor = param.lightBackColor;
				else
					this.lightBackColor = System.lightBackColor;
				
				this.text = param.text;
			
				this.calculatePositionParameters();
				if (this.styleWidth!=null) this.styleWidth-=2;
				if (this.styleHeight!=null) this.styleHeight-=2;
				this.mainDiv = System.createDiv(this.styleLeft,this.styleTop,this.styleRight,this.styleBottom,this.styleWidth,this.styleHeight);
				this.mainDiv.style.borderTop = '1px solid '+this.lightBorder;
				this.mainDiv.style.borderLeft = '1px solid '+this.lightBorder;
				this.mainDiv.style.borderRight = '1px solid '+this.darkBorder;
				this.mainDiv.style.borderBottom = '1px solid '+this.darkBorder;
				this.mainDiv.style.fontSize = System.buttonFontSize+'px';
				this.mainDiv.style.fontFamily = 'tahoma';
				System.disableSelection(this.mainDiv);
				if(this.mainDiv.addEventListener){
				this.mainDiv.addEventListener('mousedown', System.mouseDown, true);
				}
				
				this.idText = 'buttonText'+Math.round(Math.random()*10000);
				
				if ((this.image!=null)&&(this.text==null)){					
					var img = new Image();
					obj.imageDivId = 'img'+Math.round(Math.random()*100000);
					img.onload = function(){
						obj.mainDiv.innerHTML='<table cellspacing=0 cellpadding=0 style="height:100%;margin: 0 auto"><tr><td id="'+obj.imageDivId+'" style="width:'+img.width+'px;background-image:url('+img.src+');background-position:center center;background-repeat:no-repeat"></td></tr></table>';
					}
					img.src = this.image;
				}
				
				if ((this.image==null)&&(this.text!=null))	
				this.mainDiv.innerHTML='<table cellspacing=0 cellpadding=0 style="width:100%;height:100%"><tr><td id="'+this.idText+'" align="center" valign="middle">'+this.text+'</td></tr></table>';			
				
				if ((this.image!=null)&&(this.text!=null)){	
					var img = new Image();
					obj.imageDivId = 'img'+Math.round(Math.random()*100000);
					img.onload = function(){
						obj.mainDiv.innerHTML='<table cellspacing=0 cellpadding=0 style="height:100%;margin: 0 auto"><tr><td id="'+obj.imageDivId+'" style="width:'+img.width+'px;background-image:url('+img.src+');background-position:center center;background-repeat:no-repeat"></td><td id="'+this.idText+'" align="center" valign="middle">'+obj.text+'</td></tr></table>';
					}
					img.src = this.image;
				}
				
				if (this.backColor!=null)
				this.mainDiv.style.backgroundColor = this.backColor;
				
				this.mainDiv.onmouseover = function(e){
					if (obj.enabled==true) obj.mainDiv.style.backgroundColor = obj.lightBackColor;
				}
				this.mainDiv.onmouseout= function(e){
					obj.mainDiv.style.backgroundColor = obj.backColor;
					obj.mainDiv.style.marginTop = '0px';
				}	
				this.down = false;
				var idText = this.idText;
				this.mainDiv.onmousedown= function(e){
					if ((obj.enabled==true)&&(obj.down==false)&&(System.isRightButtonPressed(e)==false)){	
						obj.mainDiv.style.marginTop = '1px';	
						//document.getElementById(idText).style.marginTop = '1px';	
						if (!e) var e = window.event 
						e.cancelBubble = true;
						if (e.stopPropagation) e.stopPropagation();
						obj.down = true;
					}
				}
				this.mainDiv.onmouseup= function(e){
					if ((obj.down==true)&&(System.isRightButtonPressed(e)==false)){	
						obj.mainDiv.style.marginTop = '0px';
						//document.getElementById(idText).style.marginTop = '0px';
						obj.down = false;
						if (obj.onclick!=null) obj.onclick(e);		
					}
				}			
				this.parentDiv.appendChild(this.mainDiv);
			}
		}	
	}, 
	IconButton:function (param,parent){
		var obj = this;
		this.hide = function(){
			this.mainDiv.style.display = 'none';
		}
		this.show = function(){
			this.mainDiv.style.display = 'block';
		}		
		this.setEnabled = function(enabled){
			this.enabled = enabled;
			var div = document.getElementById(this.idText);
			if (enabled==true) 
				div.style.color = '#000';
			else
				div.style.color = '#666';
			
		}
		this.setImage = function(url){
			var td = document.getElementById(obj.imageDivId);		
			if (td!=null) td.style.backgroundImage = 'url('+url+')';
		}
		this.calculatePositionParameters = function(){
			var parentWidth = 0;
			var parentHeight = 0;
			
			parentWidth = this.parentDiv.clientWidth;
			parentHeight = this.parentDiv.clientHeight;
				
			if ((this.anchorLeft == true)&&(this.anchorRight == false)){
				this.styleRight = null;
				this.styleLeft = this.x;
				this.styleWidth = this.width;
			}
			if ((this.anchorLeft == false)&&(this.anchorRight == true)){
				this.styleRight = parentWidth-this.x-this.width;
				this.styleWidth = this.width;
				this.styleLeft = null;
			}
			if ((this.anchorLeft == true)&&(this.anchorRight == true)){
				this.styleLeft = this.x;
				this.styleRight = parentWidth-this.x-this.width;			
				this.styleWidth = null;
			}
			
			if ((this.anchorTop == true)&&(this.anchorBottom == false)){
				this.styleTop = this.y;
				this.styleHeight = this.height;
				this.styleBottom = null;
			}		
			if ((this.anchorTop == false)&&(this.anchorBottom == true)){
				this.styleBottom = parentHeight-this.y-this.height;
				this.styleHeight = this.height;
				this.styleTop = null;
			}			
			if ((this.anchorTop == true)&&(this.anchorBottom == true)){
				this.styleTop = this.y;
				this.styleBottom = parentHeight-this.y-this.height;
				this.styleHeight = null;
			}		
		}
		this.setPositionFromActualParameters = function(){
			obj.calculatePositionParameters(); 
			if (obj.styleWidth!=null) obj.styleWidth-=2;
			if (obj.styleHeight!=null) obj.styleHeight-=2;
		
			System.setDiv(obj.mainDiv,obj.styleLeft,obj.styleTop,obj.styleRight,obj.styleBottom,obj.styleWidth,obj.styleHeight);
		}
		this.setPosition = function(x,y){
			obj.x = x;
			obj.y = y;
			obj.setPositionFromActualParameters();
		}
		if ((param!=null)&&(parent!=null)){
			this.formType = 'ICON_BUTTON';
			this.enabled = true;
			this.parentDiv = null;
			if (parent.nodeName=='DIV')
			this.parentDiv = parent;
			else {
				if (parent.formType!=undefined){
					if (parent.formType == 'WINDOW') this.parentDiv = parent.getWorkspaceDiv();
					if (parent.formType == 'PANEL') this.parentDiv = parent.mainDiv;
				}
			}
			
			if (this.parentDiv!=null){	
				this.onclick = null;
				if (param.x!=null)
					this.x = param.x;
				else
					this.x = 0;
			
				if (param.y!=null)
					this.y = param.y;
				else
					this.y = 0;
			
				if (param.width!=null)
					this.width = param.width;
				else
					this.width = 32;		
    
				if (param.height!=null)
					this.height = param.height;
				else
					this.height = 32;
			
				if (param.anchorLeft!=null)
					this.anchorLeft = param.anchorLeft;
				else
					this.anchorLeft = true;
			
				if (param.anchorTop!=null)
					this.anchorTop = param.anchorTop;
				else
					this.anchorTop = true;
				
				if (param.anchorRight!=null)
					this.anchorRight = param.anchorRight;
				else
					this.anchorRight = false;	
    
				if (param.anchorBottom!=null)
					this.anchorBottom = param.anchorBottom;
				else
					this.anchorBottom = false;	
				
				if ((this.anchorBottom == false)&&(this.anchorTop == false)) this.anchorTop = true;	
				if ((this.anchorLeft == false)&&(this.anchorRight == false)) this.anchorLeft = true;	
			
					
				if (param.backColor!=null)
					this.backColor = param.backColor;
				else
					this.backColor = null;	
					
					
				if (param.lightBackColor!=null)
					this.lightBackColor = param.lightBackColor;
				else
					this.lightBackColor = System.lightBackColor;
				
				this.image = param.image; 
				this.text = param.text;
			
				this.calculatePositionParameters();
				if (this.styleWidth!=null) this.styleWidth-=2;
				if (this.styleHeight!=null) this.styleHeight-=2;
				this.mainDiv = System.createDiv(this.styleLeft,this.styleTop,this.styleRight,this.styleBottom,this.styleWidth,this.styleHeight);

				this.mainDiv.style.fontSize = System.buttonFontSize+'px';
				this.mainDiv.style.fontFamily = 'tahoma';
				System.disableSelection(this.mainDiv);
				if(this.mainDiv.addEventListener){
				this.mainDiv.addEventListener('mousedown', System.mouseDown, true);
				}
				
				this.idText = 'buttonText'+Math.round(Math.random()*10000);
				
			
				if ((this.image!=null)&&(this.text!=null)){	
					var img = new Image();
					obj.imageDivId = 'img'+Math.round(Math.random()*100000);
					img.onload = function(){
						obj.mainDiv.innerHTML='<table cellspacing=0 cellpadding=0 style="height:100%;margin: 0 auto"><tr><td id="'+obj.imageDivId+'" style="width:'+img.width+'px;height:'+img.height+'px;background-image:url('+img.src+');background-position:center center;background-repeat:no-repeat"></td></tr><tr><td id="'+this.idText+'" align="center" valign="middle">'+obj.text+'</td></tr></table>';
					}
					img.src = this.image;
				}
				
				if (this.backColor!=null)
				this.mainDiv.style.backgroundColor = this.backColor;
				
				this.mainDiv.onmouseover = function(e){
					if (obj.enabled==true) obj.mainDiv.style.backgroundColor = obj.lightBackColor;
				}
				this.mainDiv.onmouseout= function(e){
					obj.mainDiv.style.backgroundColor = obj.backColor;
					obj.mainDiv.style.marginTop = '0px';
				}	
				this.down = false;
				var idText = this.idText;
				this.mainDiv.onmousedown= function(e){
					if ((obj.enabled==true)&&(obj.down==false)&&(System.isRightButtonPressed(e)==false)){	
						obj.mainDiv.style.marginTop = '1px';	
						//document.getElementById(idText).style.marginTop = '1px';	
						if (!e) var e = window.event 
						e.cancelBubble = true;
						if (e.stopPropagation) e.stopPropagation();
						obj.down = true;
					}
				}
				this.mainDiv.onmouseup= function(e){
					if ((obj.down==true)&&(System.isRightButtonPressed(e)==false)){	
						obj.mainDiv.style.marginTop = '0px';
						//document.getElementById(idText).style.marginTop = '0px';
						obj.down = false;
						if (obj.onclick!=null) obj.onclick(e);		
					}
				}			
				this.mainDiv.ondblclick= function(e){
					if (obj.ondblclick) obj.ondblclick();
				}					
				this.parentDiv.appendChild(this.mainDiv);
			}
		}	
	}, 
	ImageButton:function (param,parent){
		var obj = this;
		this.setCheck = function(value){
			this.checked = value;
			if (this.checked==false) this.mainDiv.style.backgroundImage = 'url('+obj.image+')';
			if (this.checked==true) this.mainDiv.style.backgroundImage = 'url('+obj.selectedImage+')';
		}		
		this.hide = function(){
			this.mainDiv.style.display = 'none';
		}
		this.show = function(){
			this.mainDiv.style.display = 'block';
		}		
		this.setEnabled = function(enabled){
			this.enabled = enabled;
			var div = document.getElementById(this.idText);
			if (enabled==true) 
				div.style.color = '#000';
			else
				div.style.color = '#666';
			
		}
		this.setImage = function(url){
			var td = document.getElementById(obj.imageDivId);		
			if (td!=null) td.style.backgroundImage = 'url('+url+')';
		}
		this.calculatePositionParameters = function(){
			var parentWidth = 0;
			var parentHeight = 0;
			
			parentWidth = this.parentDiv.clientWidth;
			parentHeight = this.parentDiv.clientHeight;
				
			if ((this.anchorLeft == true)&&(this.anchorRight == false)){
				this.styleRight = null;
				this.styleLeft = this.x;
				this.styleWidth = this.width;
			}
			if ((this.anchorLeft == false)&&(this.anchorRight == true)){
				this.styleRight = parentWidth-this.x-this.width;
				this.styleWidth = this.width;
				this.styleLeft = null;
			}
			if ((this.anchorLeft == true)&&(this.anchorRight == true)){
				this.styleLeft = this.x;
				this.styleRight = parentWidth-this.x-this.width;			
				this.styleWidth = null;
			}
			
			if ((this.anchorTop == true)&&(this.anchorBottom == false)){
				this.styleTop = this.y;
				this.styleHeight = this.height;
				this.styleBottom = null;
			}		
			if ((this.anchorTop == false)&&(this.anchorBottom == true)){
				this.styleBottom = parentHeight-this.y-this.height;
				this.styleHeight = this.height;
				this.styleTop = null;
			}			
			if ((this.anchorTop == true)&&(this.anchorBottom == true)){
				this.styleTop = this.y;
				this.styleBottom = parentHeight-this.y-this.height;
				this.styleHeight = null;
			}		
		}
		this.setPositionFromActualParameters = function(){
			obj.calculatePositionParameters(); 
		
			System.setDiv(obj.mainDiv,obj.styleLeft,obj.styleTop,obj.styleRight,obj.styleBottom,obj.styleWidth,obj.styleHeight);
		}
		this.setPosition = function(x,y){
			obj.x = x;
			obj.y = y;
			obj.setPositionFromActualParameters();
		}
		if ((param!=null)&&(parent!=null)){
			System.checkButtons.push(this);
			this.formType = 'ICON_BUTTON';
			this.enabled = true;
			this.checked = false;
			this.parentDiv = null;
			if (parent.nodeName=='DIV')
			this.parentDiv = parent;
			else {
				if (parent.formType!=undefined){
					if (parent.formType == 'WINDOW') this.parentDiv = parent.getWorkspaceDiv();
					if (parent.formType == 'PANEL') this.parentDiv = parent.mainDiv;
				}
			}
			
			if (this.parentDiv!=null){	
				this.onclick = null;
				
				if (param.check!=null)
				this.check = param.check;
				else
				this.check = false;	
				
				if (param.x!=null)
					this.x = param.x;
				else
					this.x = 0;
			
				if (param.y!=null)
					this.y = param.y;
				else
					this.y = 0;
			
				if (param.width!=null)
					this.width = param.width;
				else
					this.width = 32;		
    
				if (param.height!=null)
					this.height = param.height;
				else
					this.height = 32;
			
				if (param.anchorLeft!=null)
					this.anchorLeft = param.anchorLeft;
				else
					this.anchorLeft = true;
			
				if (param.anchorTop!=null)
					this.anchorTop = param.anchorTop;
				else
					this.anchorTop = true;
				
				if (param.anchorRight!=null)
					this.anchorRight = param.anchorRight;
				else
					this.anchorRight = false;	
    
				if (param.anchorBottom!=null)
					this.anchorBottom = param.anchorBottom;
				else
					this.anchorBottom = false;	
					
				this.group = param.group;	
				
				if ((this.anchorBottom == false)&&(this.anchorTop == false)) this.anchorTop = true;	
				if ((this.anchorLeft == false)&&(this.anchorRight == false)) this.anchorLeft = true;	
			
									
				this.image = param.image; 
				this.selectedImage = param.selectedImage; 
				this.hoverImage = param.hoverImage; 
				
				
				if (this.hoverImage==null) this.hoverImage = this.image;
				if (this.selectedImage==null) this.selectedImage = this.hoverImage;
			
				this.calculatePositionParameters();
				this.mainDiv = System.createDiv(this.styleLeft,this.styleTop,this.styleRight,this.styleBottom,this.styleWidth,this.styleHeight);

				this.mainDiv.style.fontSize = System.buttonFontSize+'px';
				this.mainDiv.style.fontFamily = 'tahoma';
				System.disableSelection(this.mainDiv);
				if(this.mainDiv.addEventListener){
				this.mainDiv.addEventListener('mousedown', System.mouseDown, true);
				}
				
				
				
			
				if ((this.image!=null)){	
					obj.mainDiv.style.backgroundImage='url('+obj.image+')';
				}
								
				var imgTmp = new Image();
				imgTmp.src = this.hoverImage;
				var imgTmp2 = new Image();
				imgTmp2.src = this.selectedImage;
				
				this.mainDiv.onmouseover = function(e){
					this.style.backgroundImage = 'url('+obj.hoverImage+')';
				}
				this.mainDiv.onmouseout= function(e){
				if (obj.check==true){
					if (obj.checked==false)
					this.style.backgroundImage = 'url('+obj.image+')';
					else
					this.style.backgroundImage = 'url('+obj.selectedImage+')';
				} else {
					this.style.backgroundImage = 'url('+obj.image+')';
				}
				
				obj.mainDiv.style.marginTop = '0px';
				}		
				
				
				this.down = false;
				var idText = this.idText;
				this.mainDiv.onmousedown= function(e){
					if ((obj.enabled==true)&&(obj.down==false)&&(System.isRightButtonPressed(e)==false)){	
						obj.mainDiv.style.marginTop = '1px';	
						//document.getElementById(idText).style.marginTop = '1px';	
						if (!e) var e = window.event 
						e.cancelBubble = true;
						if (e.stopPropagation) e.stopPropagation();
						obj.down = true;
					}
				}
				this.mainDiv.onmouseup= function(e){
					if ((obj.down==true)&&(System.isRightButtonPressed(e)==false)){	
					obj.mainDiv.style.marginTop = '0px';
					obj.down = false;
					if (obj.check==true){
						if (obj.group!=null)
						for (var i=0;i<System.checkButtons.length;i++) if ((System.checkButtons[i].group==obj.group)) System.checkButtons[i].setCheck(false);
						if (obj.checked==false) obj.setCheck(true);
					}
					if (obj.onclick!=null) obj.onclick(e);		
					}
				}			
				this.mainDiv.ondblclick= function(e){
					if (obj.ondblclick) obj.ondblclick();
				}					
				this.parentDiv.appendChild(this.mainDiv);
			}
		}	
	}, 	
	ToolbarButton:function (param,parent){
		var obj = this;
		this.setImage = function(url){		
			var td = document.getElementById(obj.imageDivId);		
			if (td!=null) td.style.backgroundImage = 'url('+url+')';
		}
		this.calculatePositionParameters = function(){
			var parentWidth = 0;
			var parentHeight = 0;
		
			parentWidth = this.parentDiv.clientWidth;
			parentHeight = this.parentDiv.clientHeight;
			
			if ((this.anchorLeft == true)&&(this.anchorRight == false)){
				this.styleRight = null;
				this.styleLeft = this.x;
				this.styleWidth = this.width;
			}
			if ((this.anchorLeft == false)&&(this.anchorRight == true)){
				this.styleRight = parentWidth-this.x-this.width;
				this.styleWidth = this.width;
				this.styleLeft = null;
			}
			if ((this.anchorLeft == true)&&(this.anchorRight == true)){
				this.styleLeft = this.x;
				this.styleRight = parentWidth-this.x-this.width;			
				this.styleWidth = null;
			}
		
			if ((this.anchorTop == true)&&(this.anchorBottom == false)){
				this.styleTop = this.y;
				this.styleHeight = this.height;
				this.styleBottom = null;
			}		
			if ((this.anchorTop == false)&&(this.anchorBottom == true)){
				this.styleBottom = parentHeight-this.y-this.height;
				this.styleHeight = this.height;
				this.styleTop = null;
			}			
			if ((this.anchorTop == true)&&(this.anchorBottom == true)){
				this.styleTop = this.y;
				this.styleBottom = parentHeight-this.y-this.height;
				this.styleHeight = null;
			}		
		}
		this.setPositionFromActualParameters = function(){
			obj.calculatePositionParameters(); 
			if (obj.styleWidth!=null) obj.styleWidth-=2;
			if (obj.styleHeight!=null) obj.styleHeight-=2;
		
			System.setDiv(obj.mainDiv,obj.styleLeft,obj.styleTop,obj.styleRight,obj.styleBottom,obj.styleWidth,obj.styleHeight);
		}
		this.setPosition = function(x,y){
			obj.x = x;
			obj.y = y;
			obj.setPositionFromActualParameters();
		}
		if ((param!=null)&&(parent!=null)&&(parent.formType == 'TOOLBAR')){
			this.formType = 'TOOLBAR_BUTTON';
			this.parentDiv = null;
		
			if (parent.formType!=undefined){
				if (parent.formType == 'TOOLBAR') this.parentDiv = parent.mainDiv;
			}
		
		
		//,lightBorder:'#dfe5e6',darkBorder:'#b1b9bb',lightBackColor:'#e6eced'
		
			if (this.parentDiv!=null){	
			this.onclick = null;


		

				
		


			if (param.height!=null)
				this.height = param.height;
			else
				this.height = parent.size -4;
				
			if (param.width!=null)
				this.width = param.width;
			else
				this.width = this.height;	
				
			this.x = parent.offset;
			parent.offset += this.width+3;
			this.y = Math.round((parent.size - this.height)*0.4);

			this.anchorLeft = true;		
			this.anchorTop = true;
			this.anchorRight = false;	
			this.anchorBottom = false;	
			
		
			if (param.lightBorder!=null)
				this.lightBorder = param.lightBorder;
			else
				this.lightBorder = '#dfe5e6';
				
			if (param.darkBorder!=null)
				this.darkBorder = param.darkBorder;
			else
				this.darkBorder = '#b1b9bb';	
				
			if (param.backColor!=null)
				this.backColor = param.backColor;
			else
				this.backColor = '';	
				
			this.image = param.image; 	
			if (param.lightBackColor!=null)
				this.lightBackColor = param.lightBackColor;
			else
				this.lightBackColor = '#e6eced';
			
			this.text = param.text;
		
			this.calculatePositionParameters();
			if (this.styleWidth!=null) this.styleWidth-=2;
			if (this.styleHeight!=null) this.styleHeight-=2;
			this.mainDiv = System.createDiv(this.styleLeft,this.styleTop,this.styleRight,this.styleBottom,this.styleWidth,this.styleHeight);
			this.mainDiv.style.borderTop = '1px solid '+this.lightBorder;
			this.mainDiv.style.borderLeft = '1px solid '+this.lightBorder;
			this.mainDiv.style.borderRight = '1px solid '+this.darkBorder;
			this.mainDiv.style.borderBottom = '1px solid '+this.darkBorder;
			this.mainDiv.style.fontSize = System.buttonFontSize+'px';
			this.mainDiv.style.fontFamily = 'tahoma';
			System.disableSelection(this.mainDiv);
			if(this.mainDiv.addEventListener){
			this.mainDiv.addEventListener('mousedown', System.mouseDown, true);
			}
			
			if ((this.image!=null)&&(this.text==null)){					
				var img = new Image();
				obj.imageDivId = 'img'+Math.round(Math.random()*100000);
				img.onload = function(){
					obj.mainDiv.innerHTML='<table cellspacing=0 cellpadding=0 style="height:100%;margin: 0 auto"><tr><td id="'+obj.imageDivId+'" style="width:'+img.width+'px;background-image:url('+img.src+');background-position:center center;background-repeat:no-repeat"></td></tr></table>';
				}
				img.src = this.image;
			}
			
			if ((this.image==null)&&(this.text!=null))	
			this.mainDiv.innerHTML='<table cellspacing=0 cellpadding=0 style="width:100%;height:100%"><tr><td align="center" valign="middle">'+this.text+'</td></tr></table>';			
			
			if ((this.image!=null)&&(this.text!=null)){	
				var img = new Image();
				obj.imageDivId = 'img'+Math.round(Math.random()*100000);
				img.onload = function(){
					obj.mainDiv.innerHTML='<table cellspacing=0 cellpadding=0 style="height:100%;margin: 0 auto"><tr><td id="'+obj.imageDivId+'" style="width:'+img.width+'px;background-image:url('+img.src+');background-position:center center;background-repeat:no-repeat"></td><td align="center" valign="middle">'+obj.text+'</td></tr></table>';
				}
				img.src = this.image;
			}
			
			if (this.backColor!=null)
			this.mainDiv.style.backgroundColor = this.backColor;
			
			this.mainDiv.onmouseover = function(e){
				obj.mainDiv.style.backgroundColor = obj.lightBackColor;
			}
			this.mainDiv.onmouseout= function(e){
				obj.mainDiv.style.backgroundColor = obj.backColor;
				obj.mainDiv.style.marginTop = '0px';
			}	
			
			this.down = false;
			this.mainDiv.onmousedown= function(e){
				if ((obj.down==false)&&(System.isRightButtonPressed(e)==false)){	
					obj.mainDiv.style.marginTop = '1px';		
					if (!e) var e = window.event 
					e.cancelBubble = true;
					if (e.stopPropagation) e.stopPropagation();
					obj.down = true;
				}
			}
			this.mainDiv.onmouseup= function(e){
				if ((obj.down==true)&&(System.isRightButtonPressed(e)==false)){	
					obj.mainDiv.style.marginTop = '0px';
					obj.down = false;
					if (obj.onclick!=null) obj.onclick(e);		
				}
			}			
			this.parentDiv.appendChild(this.mainDiv);
		}
	}	
	},
	ToolbarButtonImage:function (param,parent){
		var obj = this;
		this.setCheck = function(value){
			this.checked = value;
			if (this.checked==false) this.mainDiv.style.backgroundImage = 'url('+System.folderPath+'but_1.png)';
			if (this.checked==true) this.mainDiv.style.backgroundImage = 'url('+System.folderPath+'but_1_selected.png)';
		}
		this.setImage = function(url){		
			var td = document.getElementById(obj.imageDivId);		
			if (td!=null) td.style.backgroundImage = 'url('+url+')';
		}
		this.calculatePositionParameters = function(){
			var parentWidth = 0;
			var parentHeight = 0;
		
			parentWidth = this.parentDiv.clientWidth;
			parentHeight = this.parentDiv.clientHeight;
			
			if ((this.anchorLeft == true)&&(this.anchorRight == false)){
				this.styleRight = null;
				this.styleLeft = this.x;
				this.styleWidth = this.width;
			}
			if ((this.anchorLeft == false)&&(this.anchorRight == true)){
				this.styleRight = parentWidth-this.x-this.width;
				this.styleWidth = this.width;
				this.styleLeft = null;
			}
			if ((this.anchorLeft == true)&&(this.anchorRight == true)){
				this.styleLeft = this.x;
				this.styleRight = parentWidth-this.x-this.width;			
				this.styleWidth = null;
			}
		
			if ((this.anchorTop == true)&&(this.anchorBottom == false)){
				this.styleTop = this.y;
				this.styleHeight = this.height;
				this.styleBottom = null;
			}		
			if ((this.anchorTop == false)&&(this.anchorBottom == true)){
				this.styleBottom = parentHeight-this.y-this.height;
				this.styleHeight = this.height;
				this.styleTop = null;
			}			
			if ((this.anchorTop == true)&&(this.anchorBottom == true)){
				this.styleTop = this.y;
				this.styleBottom = parentHeight-this.y-this.height;
				this.styleHeight = null;
			}		
		}
		this.setPositionFromActualParameters = function(){
			obj.calculatePositionParameters(); 
			if (obj.styleWidth!=null) obj.styleWidth-=0;
			if (obj.styleHeight!=null) obj.styleHeight-=0;
		
			System.setDiv(obj.mainDiv,obj.styleLeft,obj.styleTop,obj.styleRight,obj.styleBottom,obj.styleWidth,obj.styleHeight);
		}
		this.setPosition = function(x,y){
			obj.x = x;
			obj.y = y;
			obj.setPositionFromActualParameters();
		}
		if ((param!=null)&&(parent!=null)&&(parent.formType == 'TOOLBAR')){
			System.checkButtons.push(this);
			this.formType = 'TOOLBAR_BUTTON';
			this.parentDiv = null;
			this.checked = false;
		
			if (parent.formType!=undefined){
				if (parent.formType == 'TOOLBAR') this.parentDiv = parent.mainDiv;
			}
		
		
		//,lightBorder:'#dfe5e6',darkBorder:'#b1b9bb',lightBackColor:'#e6eced'
		
			if (this.parentDiv!=null){	
			this.onclick = null;
				
			this.group = param.group;


			if (param.height!=null)
				this.height = param.height;
			else
				this.height = parent.size -4;
	
			if (param.check!=null)
				this.check = param.check;
			else
				this.check = false;	
	
			if (param.width!=null)
				this.width = param.width;
			else
				this.width = this.height;	
				
			this.x = parent.offset;
			parent.offset += this.width+3;
			this.y = Math.round((parent.size - this.height)*0.4);

			this.anchorLeft = true;		
			this.anchorTop = true;
			this.anchorRight = false;	
			this.anchorBottom = false;	
			
		

				
			if (param.backColor!=null)
				this.backColor = param.backColor;
			else
				this.backColor = '';	
				
			this.image = param.image; 	
			if (param.lightBackColor!=null)
				this.lightBackColor = param.lightBackColor;
			else
				this.lightBackColor = '#e6eced';
			
			this.text = param.text;
		
			this.calculatePositionParameters();
			this.mainDiv = System.createDiv(this.styleLeft,this.styleTop,this.styleRight,this.styleBottom,this.styleWidth,this.styleHeight);
			this.mainDiv.style.backgroundImage = 'url('+System.folderPath+'but_1.png)';

			this.mainDiv.style.fontSize = System.buttonFontSize+'px';
			this.mainDiv.style.fontFamily = 'tahoma';
			System.disableSelection(this.mainDiv);
			if(this.mainDiv.addEventListener){
			this.mainDiv.addEventListener('mousedown', System.mouseDown, true);
			}
			
			if ((this.image!=null)&&(this.text==null)){					
				var img = new Image();
				obj.imageDivId = 'img'+Math.round(Math.random()*100000);
				img.onload = function(){
					obj.mainDiv.innerHTML='<table cellspacing=0 cellpadding=0 style="height:100%;margin: 0 auto"><tr><td id="'+obj.imageDivId+'" style="width:'+img.width+'px;background-image:url('+img.src+');background-position:center center;background-repeat:no-repeat"></td></tr></table>';
				}
				img.src = this.image;
			}
			
			if ((this.image==null)&&(this.text!=null))	
			this.mainDiv.innerHTML='<table cellspacing=0 cellpadding=0 style="width:100%;height:100%"><tr><td align="center" valign="middle">'+this.text+'</td></tr></table>';			
			
			if ((this.image!=null)&&(this.text!=null)){	
				var img = new Image();
				obj.imageDivId = 'img'+Math.round(Math.random()*100000);
				img.onload = function(){
					obj.mainDiv.innerHTML='<table cellspacing=0 cellpadding=0 style="height:100%;margin: 0 auto"><tr><td id="'+obj.imageDivId+'" style="width:'+img.width+'px;background-image:url('+img.src+');background-position:center center;background-repeat:no-repeat"></td><td align="center" valign="middle">'+obj.text+'</td></tr></table>';
				}
				img.src = this.image;
			}
			
			var imgTmp = new Image();
			imgTmp.src = System.folderPath+'but_1_hover.png';
			
			this.mainDiv.onmouseover = function(e){
				this.style.backgroundImage = 'url('+System.folderPath+'but_1_hover.png)';
			}
			this.mainDiv.onmouseout= function(e){
				if (obj.check==true){
					if (obj.checked==false)
					this.style.backgroundImage = 'url('+System.folderPath+'but_1.png)';
					else
					this.style.backgroundImage = 'url('+System.folderPath+'but_1_selected.png)';
				} else {
					this.style.backgroundImage = 'url('+System.folderPath+'but_1.png)';
				}
				
				obj.mainDiv.style.marginTop = '0px';
			}	
			
			this.down = false;
			this.mainDiv.onmousedown= function(e){
				if ((obj.down==false)&&(System.isRightButtonPressed(e)==false)){	
					obj.mainDiv.style.marginTop = '1px';		
					if (!e) var e = window.event 
					e.cancelBubble = true;
					if (e.stopPropagation) e.stopPropagation();
					obj.down = true;
				}
			}
			this.mainDiv.onmouseup= function(e){
				if ((obj.down==true)&&(System.isRightButtonPressed(e)==false)){	
					obj.mainDiv.style.marginTop = '0px';
					obj.down = false;
					if (obj.check==true){
						if (obj.group!=null)
						for (var i=0;i<System.checkButtons.length;i++) if ((System.checkButtons[i].group==obj.group)) System.checkButtons[i].setCheck(false);
						if (obj.checked==false) obj.setCheck(true);
					}
					if (obj.onclick!=null) obj.onclick(e);		
				}
			}			
			this.parentDiv.appendChild(this.mainDiv);
		}
	}	
	},	
	
	//size
	Toolbar:function(param,parent){
		var obj = this;
		if ((param!=null)&&(parent!=null)&&(parent.formType == 'WINDOW')){
			this.formType = 'TOOLBAR';
			this.parentDiv = null;
			if (parent.nodeName=='DIV')
			this.parentDiv = parent;
			else {
				if (parent.formType!=undefined){
					if (parent.formType == 'WINDOW') this.parentDiv = parent.getWorkspaceDiv();
				}
			}
			if (this.parentDiv!=null){	
				this.offset = 5;
				if (param.size!=null)
					this.size = param.size;
				else
					this.size = 26;
			
				var top = 0;
				if (parent.formType == 'WINDOW'){
					top = parent.offsetTop;
					parent.offsetTop+=this.size;
				}
			
				this.mainDiv = System.createDiv(0,top,0,null,null,this.size-1);
				this.mainDiv.style.borderBottom = '1px solid #aaa';
				//System.cancelMouseUp(this.mainDiv);
				this.parentDiv.appendChild(this.mainDiv);
			
				this.backImage = new Image();
				this.backImage.onload = function(){
					obj.backImage.style.width = '100%';
					obj.backImage.style.height = '100%';
					//obj.mainDiv.appendChild(obj.backImage);
			
				}
				this.mainDiv.style.backgroundImage = 'url('+System.folderPath+'tlo_toolbar.png)';	
			}		
		}	
	},
	//size
	//fields tablica szerokosci
	StatusBar:function(param,parent){
		var obj = this;
		this.setText = function(index,text){
			if (this.fieldsDivs)
			this.fieldsDivs[index].innerHTML = text;
		}
		if ((param!=null)&&(parent!=null)&&(parent.formType == 'WINDOW')){
			this.formType = 'STATUS_BAR';
			this.parentDiv = null;
			if (parent.nodeName=='DIV')
			this.parentDiv = parent;
			else {
				if (parent.formType!=undefined){
					if (parent.formType == 'WINDOW') this.parentDiv = parent.getWorkspaceDiv();
				}
			}
			if (this.parentDiv!=null){	
				this.offset = 5;
				if (param.size!=null)
					this.size = param.size;
				else
					this.size = 24;
			
				var bottom = 0;
				if (parent.formType == 'WINDOW'){
					bottom = parent.offsetBottom;
					parent.offsetBottom+=this.size;
				}
				
				if (param.fields!=null) 
					this.fields = param.fields;
				else
					this.fields = null;
			
				this.mainDiv = System.createDiv(0,null,0,bottom,null,this.size-1);
				this.mainDiv.style.borderTop = '1px solid #aaa';
				this.mainDiv.style.backgroundColor = System.backColor;
				System.cancelMouseUp(this.mainDiv);
				this.parentDiv.appendChild(this.mainDiv);	
				
				var pasek = System.createDiv(-1,0,-1,-1,null,null);
				pasek.style.border = '1px solid #ffffff';
				this.mainDiv.appendChild(pasek);
				this.fieldsDivs = null;
				if (this.fields!=null){
					this.offset = 3;
					this.fieldsDivs = new Array();
					for (var i=0;i<this.fields.length;i++){
						var div = System.createDiv(this.offset,3,null,2,this.fields[i]-8,null);
						div.style.borderTop = '1px solid '+System.darkBorder;
						div.style.borderLeft = '1px solid '+System.darkBorder;
						div.style.borderRight = '1px solid '+System.lightBorder;
						div.style.borderBottom = '1px solid '+System.lightBorder;
						div.style.fontSize ='11px';
						div.style.padding = '2px 4px 2px 4px';
						this.mainDiv.appendChild(div);						
						this.offset+=this.fields[i]+5;
						this.fieldsDivs.push(div);
					}
				}
			}		
		}	
	},	
	//text - pozycja menu
	//enable - czy pozycja aktywna
	//onclick - funkcja na klikniecie, przyjmuje obiekt rodzica
	MenuItem:function(text,enable,onclick,submenu){
		var obj = this;
		this.addSubMenu = function(submenu){
			this.submenu = submenu;
			var div = System.createDiv(null,4,3,0,6,9);
			div.style.backgroundImage = 'url(forms/strzalka.png)';
			this.mainDiv.appendChild(div);
			submenu.setParent(this.parent);
			System.addEvent(this.mainDiv,'mouseover',function(e){		
				var x,y;
				x = obj.mainDiv.clientWidth;
				y = 0;
				submenu.show(obj.mainDiv,x,y);
			});
		}
		this.getSubMenu = function(){
			return this.submenu;
		}
		this.setEnable = function(enable){
			this.enable = enable;
			if (this.enable==false) 
				this.mainDiv.style.color = '#bbb'; 
			else
				this.mainDiv.style.color = '#000'; 
		}
		this.getParentMenu = function(){
			return this.parentMenu;
		}
		this.setParent = function(parent){
			this.parent = parent;
			if (this.menu!=null) this.menu.setParent(parent);	
		}
		if (text!=null){
			this.text = text;
			if (enable!=null)  
				this.enable = enable;
			else
				this.enable = true;
			
			this.onclick = onclick;
			
			if (this.text!="-"){
				this.mainDiv = System.createDiv(0,0,null,null,100,17);
				this.mainDiv.style.margin = '1px';
				this.mainDiv.style.paddingTop = '1px';
				this.mainDiv.style.paddingLeft = '8px';
				this.height = 20;	
							
				if (this.enable==false) this.mainDiv.style.color = '#bbb'; 			
				this.mainDiv.innerHTML = this.text;
				
			
							
				System.addEvent(this.mainDiv,'mouseover',function(e){
					obj.getParentMenu().hideSubMenus(obj.getSubMenu());
					obj.mainDiv.style.backgroundColor = '#b0d0e5';
				});
				System.addEvent(this.mainDiv,'mouseout',function(e){
					obj.mainDiv.style.backgroundColor = '#fff';
				});		
			
				if (this.onclick!=null){
					System.addEvent(this.mainDiv,'mousedown',function(e){
						if (obj.enable == true){
							obj.onclick(obj.parent);
							obj.parentMenu.hide();
						}
					});	
				}	
				
			
				if (submenu!=null){
					this.addSubMenu(submenu);
				}	
				
			} else {
				this.mainDiv = System.createDiv(0,0,0,null,null,5);	
				this.height=5;			
			
				var div2 = System.createDiv(4,2,4,null,null,1);
				div2.style.backgroundColor = '#aaa';
				this.mainDiv.appendChild(div2);
			}
		}

	},
	//width
	//items - tablica MenuItem
	//onclick
	Menu:function(param,items){
		var obj = this;
		this.addItem = function(item){
			this.items.push(item);
			item.mainDiv.style.top = this.height+'px';
			this.mainDiv.appendChild(item.mainDiv);
			item.mainDiv.style.width = (this.width-10)+'px';
			item.parent = this.parent;
			this.height+=item.height;
			this.mainDiv.style.height = this.height+'px';
			item.parentMenu = this;
		}
		this.hideSubMenus = function(actmenu){
			var i;
			for (i=0;i<this.items.length;i++)
			if ((this.items[i].submenu!=null)&&(this.items[i].submenu.opened==true)&&(this.items[i].submenu!=actmenu)) this.items[i].submenu.hide();
		}
		this.show = function(parentDiv,x,y){
			if (this.items.length>0){
				this.opened = true;
				if (parentDiv == System.systemDiv)
					parentDiv.appendChild(this.mainDiv);
				else {
					System.systemDiv.appendChild(this.mainDiv);
					var pos = System.divPosition(parentDiv);
					x+=pos[0];
					y+=pos[1];
				}
				this.mainDiv.style.display = 'block';
				this.mainDiv.style.zIndex = 999999999;
				System.zIndex+=1000;
				this.mainDiv.style.left = x+'px';
				this.mainDiv.style.top = y+'px';
			}	
		}
		this.setAutoHidding = function(){
			System.addGlobalEvent('mousedown',function(e){				
				if(obj.opened == true){			
					
					obj.hide();
				}
			});
		}		
		this.hide = function(){
			this.opened = false;
			this.mainDiv.style.display = 'none';
			var i;
			for (i=0;i<this.items.length;i++)
			if ((this.items[i].submenu!=null)) this.items[i].submenu.hide();
		}	
		this.setParent = function(parent){
			this.parent = parent;
			var i;
			for (i=0;i<this.items.length;i++){
				this.items[i].setParent(parent); 	
			}
		}		
		if (param!=null){
			this.formType = 'MENU';
			if (param.width!=null)
				this.width = param.width;
			else
				this.width = 150;

			this.height = 0;	
			this.opened = false;
			
			this.mainDiv = System.createDiv(0,0,null,null,this.width,this.height);
			this.mainDiv.style.backgroundColor = System.contextMenuColor;
			this.mainDiv.style.border = '1px solid '+System.contextMenuBorderColor;
			this.mainDiv.style.display = 'none';
			this.mainDiv.style.fontFamily = 'tahoma';
			this.mainDiv.style.fontSize = '11px';
			System.disableSelection(this.mainDiv);
			System.disableContextMenu(this.mainDiv);
			System.cancelMouseOver(this.mainDiv);
			
			System.addEvent(this.mainDiv,'mousedown',function(){
				if (obj.onclick) obj.onclick();
			})
			
			var i;
			this.items = new Array();	
			for (i=0;i<items.length;i++){
				this.addItem(items[i]); 	
			}
		}	
	},
	StripMenuItem:function(text,enable,submenu,onclick){
		var obj = this;
		if (text!=null){
			this.text = text;
			this.submenu = submenu;		
			
			this.mainDiv = document.createElement('div');
			this.mainDiv.style.position = 'relative';
			this.mainDiv.style.padding = '3px 7px 3px 7px';
			this.mainDiv.style.display = 'inline';
			this.mainDiv.innerHTML = this.text;
			System.disableSelection(this.mainDiv);
			
			System.addEvent(this.mainDiv,'mouseover',function(e){
					obj.mainDiv.style.backgroundColor = '#fff';
			});
			System.addEvent(this.mainDiv,'mouseout',function(e){
					if (obj.submenu !=null){
						if (obj.submenu.opened == false)
						obj.mainDiv.style.backgroundColor = '';
					} else {
						obj.mainDiv.style.backgroundColor = '';
					}
			});	
			System.disableContextMenu(this.mainDiv);
			//System.cancelMouseDown(this.mainDiv);
			
			if (this.submenu !=null){
				System.addEvent(this.mainDiv,'mouseup',function(e){
					obj.submenu.show(obj.mainDiv,0,20);	
					
				});	
				
				System.addGlobalEvent('mousedown',function(e){
					if(obj.submenu.opened == true){		
						obj.mainDiv.style.backgroundColor = '';	
						obj.submenu.hide();
					}
				});
				this.submenu.onclick = function(){	
					obj.mainDiv.style.backgroundColor = '';					
				}
			}
		}
	},
	StripMenu:function (items,parent){
		var obj = this;
		this.addItem = function(item){		
			item.stripMenu = this;
			this.items.push(item);
			this.containerDiv.appendChild(item.mainDiv);
		}	
		if ((parent!=null)&&(parent.formType == 'WINDOW')){
			this.formType = 'STRIPMENU';
			this.size = 24;
			this.parentDiv = parent.getWorkspaceDiv();
			
			var top = parent.offsetTop;
			parent.offsetTop+=this.size+1;
			
			this.mainDiv = System.createDiv(0,top,0,null,null,this.size-1);
			this.mainDiv.style.borderBottom = '1px solid #aaa';
			this.mainDiv.style.backgroundColor = System.backColor;
			System.disableSelection(this.mainDiv);
			System.cancelMouseUp(this.mainDiv);
			this.parentDiv.appendChild(this.mainDiv);
			
			this.containerDiv = System.createDiv(4,4,0,3,null,null);
			this.containerDiv.style.fontFamily = 'tahoma';
			this.containerDiv.style.fontSize = '12px';
			this.mainDiv.appendChild(this.containerDiv);
			
			var i;
			this.items = new Array();
			for(i=0;i<items.length;i++){
				this.addItem(items[i]);
			}
		}
		
	},
	//param object
	// text - tekst w pasku okienka
	// x,y - pozycja okna 
	// width,height - wymiary okna
	// minWidth,minHeight -minimalne  wymiary okna
	// anchorTop,anchorLeft,anchorRight,anchorBottom - kotwice (true,false);
	// startPosition - MANUAL,CENTER
	// clipChildren - przycina okienka nalezace do (true, false);
	// backColor - kolor obszaru roboczego
	// borderStyle - NONE,SIZABLE,FIXED,TOOL,TOOL_FIXED
	// isCloseButton (true/false);
	//sendOnTop (true/false)
	//dialog (true/false)
	// funkcje: onclose() onresize() onmousemove(x,y)
	Window:function(param,parent){
		var obj = this;
		this.parent = parent;
		this.parentSize = function(){
			var parentWidth = 0;
			var parentHeight = 0;
			
			if (this.parent==null){
				parentWidth = System.getWidth();
				parentHeight = System.getHeight();			
			} else {
				parentWidth = this.parent.getWidth();
				parentHeight = this.parent.getHeight();					
			}
			return [parentWidth,parentHeight];
		}
		this.calculatePositionParameters = function(){
			var parentWidth = 0;
			var parentHeight = 0;
			
			if (this.parent==null){
				parentWidth = System.getWidth();
				parentHeight = System.getHeight();			
			} else {
				parentWidth = this.parent.getWidth();
				parentHeight = this.parent.getHeight();					
			}

			if ((this.anchorLeft == true)&&(this.anchorRight == false)){
				this.styleRight = null;
				this.styleLeft = this.x;
				this.styleWidth = this.width;
			}
			if ((this.anchorLeft == false)&&(this.anchorRight == true)){
				this.styleRight = parentWidth-this.x-this.width;
				this.styleWidth = this.width;
				this.styleLeft = null;
			}
			if ((this.anchorLeft == true)&&(this.anchorRight == true)){
				this.styleLeft = this.x;
				this.styleRight = parentWidth-this.x-this.width;
				this.styleWidth = null;
			}
			
			if ((this.anchorTop == true)&&(this.anchorBottom == false)){
				this.styleTop = this.y;
				this.styleHeight = this.height;
				this.styleBottom = null;
			}		
			if ((this.anchorTop == false)&&(this.anchorBottom == true)){
				this.styleBottom = parentHeight-this.y-this.height;
				this.styleHeight = this.height;
				this.styleTop = null;
			}			
			if ((this.anchorTop == true)&&(this.anchorBottom == true)){
				this.styleTop = this.y;
				this.styleBottom = parentHeight-this.y-this.height;
				this.styleHeight = null;
			}		
		}
		this.addWindow = function(window){
			this.mainDiv.appendChild(window.mainDiv);
			this.mainDiv.style.zIndex =  System.zIndex;
			System.zIndex+=1000;
			if (!this.windows){
				this.windows = new Array();
			}
			this.windows.push(window);
		}
		this.getWidth = function(){
			return this.mainDiv.clientWidth;
		},
		this.getHeight = function(){
			return this.mainDiv.clientHeight;
		}
		this.getWorkspaceWidth = function(){
			return this.workspaceDiv.clientWidth;
		},
		this.getWorkspaceHeight = function(){
			return this.workspaceDiv.clientHeight;
		}
		this.getWorkspaceDiv = function(){
			return this.workspaceDiv;
		}
		this.show = function(){
			this.mainDiv.style.display = 'block';
		}
		this.close = function(){
			this.hide();
			obj = null;
		}
		this.hide = function(){
			this.mainDiv.style.display = 'none';
		}	
		this.setPositionFromActualParameters = function(){
			this.calculatePositionParameters(); 
			System.setDiv(this.mainDiv,this.styleLeft,this.styleTop,this.styleRight,this.styleBottom,this.styleWidth,this.styleHeight);
		}
		this.innerOnResize = function(){
			var width = this.width;
			var height = this.height;
			this.width = this.mainDiv.clientWidth; 
			this.height = this.mainDiv.clientHeight; 		
			this.x = this.mainDiv.offsetLeft;
			this.y = this.mainDiv.offsetTop;
			this.calculatePositionParameters();
			
			if (((width != this.mainDiv.clientWidth)||(height != this.mainDiv.clientHeight))&&(this.onresize!=null)) this.onresize();	

			if (this.windows)
			for (i45645=0;i45645<this.windows.length;i45645++) 
			if (this.windows[i45645]!=null) this.windows[i45645].innerOnResize();	
		}
		this.maximize = function(){
			this.maximized = true;

			if (this.maximizeButton!=null)
			this.maximizeButton.setImage(System.folderPath+'max2.png');
			
			this.beforeMaxX = this.x;
			this.beforeMaxY = this.y;
			this.beforeMaxWidth = this.width;
			this.beforeMaxHeight = this.height;
			if (this.borderStyle != 'NONE'){
				this.mainDiv.style.left = (-System.frameSize)+'px';
				this.mainDiv.style.top = '0px';
				this.mainDiv.style.right = (-System.frameSize)+'px';
				this.mainDiv.style.bottom = (-System.frameSize)+'px';
			} else {
				this.mainDiv.style.left = '0px';
				this.mainDiv.style.top = '0px';
				this.mainDiv.style.right = '0px';
				this.mainDiv.style.bottom = '0px';
			}
			
			this.mainDiv.style.width = '';
			this.mainDiv.style.height = '';	
			if (this.onresize) this.onresize();	
			
		}
		this.restore = function(){
			this.maximized = false;
			
			if (this.maximizeButton!=null)
			this.maximizeButton.setImage(System.folderPath+'max.png');
			this.x = this.beforeMaxX;
			this.y = this.beforeMaxY;
			this.width = this.beforeMaxWidth;
			this.height = this.beforeMaxHeight;
			this.setPositionFromActualParameters();
		}
		this.setText = function(text){
			if (this.captionDiv!=null)
			this.captionDiv.innerHTML = '<table><tr><td>'+text+'</td></tr></table>';
		}
		this.fullScreen = function(){
			this.mainDiv.style.width = '';
			this.mainDiv.style.height = '';	
			
			this.mainDiv.style.left = (-this.workLeft-1)+'px';
			this.mainDiv.style.top = (-this.workTop-1)+'px';
			this.mainDiv.style.right = (-this.workRight-1)+'px';
			this.mainDiv.style.bottom = (-this.workBottom-1)+'px';			
			if (this.resize)
			this.onresize();
		}
		this.sendOnTop = function(){
			var obj = this;
			if ((obj.sendOnTop==true)&&(obj.mainDiv.style.zIndex<System.zIndex)){	
				obj.mainDiv.style.zIndex = System.zIndex;
				System.zIndex+=1000;
			}
		}
		if ((param!=null)&&((parent==null)||(parent.formType == 'WINDOW')||(parent.formType == 'PANEL'))){
			this.formType = 'WINDOW';
			this.onclose = null;
			this.onresize = null;
			this.onmousemove = null;
			
			this.offsetTop = 0;
			this.offsetBottom = 0;
			
			this.parent = parent;
			if (param.text!=null)
				this.text = param.text; 
			else
				this.text = '';		
			
			if (param.x!=null)
				this.x = param.x;
			else
				this.x = 0;
			
			if (param.y!=null)
				this.y = param.y;
			else
				this.y = 0;
			
			if (param.width!=null)
				this.width = param.width;
			else
				this.width = 200;		

			if (param.minWidth!=null)
				this.minWidth = param.minWidth;
			else
				this.minWidth = 150;					
											
			if (param.height!=null)
				this.height = param.height;
			else
				this.height = 200;
				
			if (param.minHeight!=null)
				this.minHeight = param.minHeight;
			else
				this.minHeight = 120;		
			
			if (param.anchorLeft!=null)
				this.anchorLeft = param.anchorLeft;
			else
				this.anchorLeft = true;
			
			if (param.anchorTop!=null)
				this.anchorTop = param.anchorTop;
			else
				this.anchorTop = true;
				
			if (param.anchorRight!=null)
				this.anchorRight = param.anchorRight;
			else
				this.anchorRight = false;	

			if (param.anchorBottom!=null)
				this.anchorBottom = param.anchorBottom;
			else
				this.anchorBottom = false;	
				
			if ((this.anchorBottom == false)&&(this.anchorTop == false)) this.anchorTop = true;	
			if ((this.anchorLeft == false)&&(this.anchorRight == false)) this.anchorLeft = true;	
			
			if (param.startPosition!=null)
				this.startPosition = param.startPosition;
			else
				this.startPosition = 'MANUAL';
				
			if (param.backColor!=null)
				this.backColor = param.backColor;
			else
				this.backColor = System.backColor;
				
			if (param.sendOnTop!=null)
				this.sendOnTop  = param.sendOnTop;
			else
				this.sendOnTop = true;
				
			if (param.dialog !=null)
				this.dialog = param.dialog;
			else
				this.dialog = false;
		
			var parentWidth = 0;
			var parentHeight = 0;
			
		
			if (parent==null){
				parentWidth = System.getWidth();
				parentHeight = System.getHeight();			
			} else {
				parentWidth = parent.getWidth();
				parentHeight = parent.getHeight();					
			}
			
			if (this.startPosition == 'CENTER'){
				this.x = Math.round((parentWidth-this.width)*0.5);
				this.y = Math.round((parentHeight-this.height)*0.5);
			}
			
			if (param.clipChildren!=null)
				this.clipChildren = param.clipChildren;
			else
				this.clipChildren = true;	
				
			if (param.borderStyle!=null)
				this.borderStyle = param.borderStyle;
			else
				this.borderStyle = 'SIZABLE';
		
			if (param.isCloseButton!=null)
				this.isCloseButton = param.isCloseButton;
			else
				this.isCloseButton = true;
			if (param.isMaximizeButton!=null)
				this.isMaximizeButton = param.isMaximizeButton;
			else
				this.isMaximizeButton = true;
		
			this.maximized = false;
		
			this.calculatePositionParameters();
		
	
		
			this.mainDiv = System.createDiv(this.styleLeft,this.styleTop,this.styleRight,this.styleBottom,this.styleWidth,this.styleHeight);
			this.conDiv = System.createDiv(0,0,0,0,null,null);
			this.mainDiv.appendChild(this.conDiv);
			if (parent==null){
				System.addWindow(this);
			} else {
				parent.addWindow(this);		
			}
			
			if ((this.sendOnTop==true)){	
				obj.mainDiv.style.zIndex = System.zIndex;
				System.zIndex+=1000;
			}
				
			if (this.dialog == true){
				this.dialogDiv = System.createDiv(-1000,-1000,null,null,3000,3000);
				this.dialogDiv.style.backgroundImage = 'url('+System.folderPath+'blank.png)';				
				this.mainDiv.appendChild(this.dialogDiv);
				this.dialogDiv.onclick = function(){
					
				}
			}
			
			//this.mainDiv.style.backgroundColor = '#ccc';
		
			var workLeft = 0;
			var workTop = 0;
			var workRight = 0;
			var workBottom = 0;
			
			if (this.borderStyle != 'NONE'){
			
				if ((this.borderStyle == 'SIZABLE')||(this.borderStyle == 'FIXED')){
					workLeft = System.frameSize;
					workTop = System.captionBarSize+1;
					workRight = System.frameSize;
					workBottom = System.frameSize;	
					this.workLeft = workLeft;
					this.workTop = workTop;
					this.workRight = workRight;
					this.workBottom = workBottom;
					
					var ramki = System.createColoredFrame(System.frameSize,System.windowColor,System.borderColor);	
					this.frameDiv = ramki[0];
					this.mainDiv.appendChild(this.frameDiv);
					this.captionDiv = System.createDiv(System.frameSize,1,System.frameSize,null,null,System.captionBarSize);
					this.captionDiv.style.backgroundColor = System.windowColor;
					this.captionDiv.innerHTML = '<table><tr><td>'+this.text+'</td></tr></table>';
					this.captionDiv.style.fontSize = System.captionBarFontSize+'px';
					this.captionDiv.style.fontFamily = 'tahoma';
					this.captionDiv.style.fontWeight = 'bold';
					this.captionDiv.style.overflow = 'hidden';
					System.disableSelection(this.captionDiv);
					this.captionDiv.style.color = System.captionBarFontColor;
					this.mainDiv.appendChild(this.captionDiv);
					if (this.isCloseButton==true){
						this.closeButton = new System.Button({x:(this.width-35),y:3,width:22,height:16,anchorRight:true,anchorLeft:false,lightBorder:'#eee',darkBorder:'#eee',backColor:'#e56748',image:System.folderPath+'close.png',lightBackColor:'#e3bfbf'},this.captionDiv);
						this.closeButton.onclick = function(e){
							if (obj.onclose !=null){
								if (obj.onclose()!=false){
									obj.mainDiv.style.display = 'none';
									obj = null;
								}
							} else {
								obj.mainDiv.style.display = 'none';
								obj = null;
							}
						}
					}
					if (this.isMaximizeButton==true){
						this.maximizeButton = new System.Button({x:(this.width-60),y:3,width:22,height:16,anchorRight:true,anchorLeft:false,lightBorder:'#eee',darkBorder:'#eee',backColor:'#61b8ef',image:System.folderPath+'max.png',lightBackColor:'#bedaec'},this.captionDiv);
						this.maximizeButton.onclick = function(e){
							if (obj.maximized==false) obj.maximize(); else obj.restore();
						}
					}
				}
				if ((this.borderStyle == 'TOOL')||(this.borderStyle == 'TOOL_FIXED')){
					workLeft = System.toolFrameSize;
					workTop = 1+System.toolCaptionBarSize;
					workRight = System.toolFrameSize;
					workBottom = System.toolFrameSize;
					this.workLeft = workLeft;
					this.workTop = workTop;
					this.workRight = workRight;
					this.workBottom = workBottom;					
					var ramki = System.createColoredFrame(System.frameSize,System.windowColor,System.borderColor);	
					this.frameDiv = ramki[0];
					this.mainDiv.appendChild(this.frameDiv);	
					this.captionDiv = System.createDiv(System.toolFrameSize,1,System.toolFrameSize,null,null,System.toolCaptionBarSize);
					this.captionDiv.style.backgroundColor = System.windowColor;
					this.captionDiv.innerHTML = '<table><tr><td>'+this.text+'</td></tr></table>';
					this.captionDiv.style.fontSize = System.toolCaptionBarFontSize+'px';
					this.captionDiv.style.fontFamily = 'tahoma';
					this.captionDiv.style.fontWeight = 'bold';	
					this.captionDiv.style.overflow = 'hidden';
					this.captionDiv.style.color = System.captionBarFontColor;
					System.disableSelection(this.captionDiv);			
					this.mainDiv.appendChild(this.captionDiv);		
					if (this.isCloseButton==true){
						this.closeButton = new System.Button({x:(this.width-23),y:2,width:14,height:14,anchorRight:true,anchorLeft:false,lightBorder:'#eee',darkBorder:'#eee',backColor:'#e56748',image:System.folderPath+'close.png',lightBackColor:'#e3bfbf'},this.captionDiv);
						this.closeButton.onclick = function(e){
							if (obj.onclose !=null){
								if (obj.onclose()!=false)
								obj.mainDiv.style.display = 'none';
							} else {
								obj.mainDiv.style.display = 'none';
							}
						}	
					}		
				}
				var obj = this;
				System.addEvent(window,'resize',function(e){  
					if (obj!=null) obj.innerOnResize();			 
				});	
				System.addEvent(this.captionDiv,'mousedown',function(e){  
					if ((obj.maximized==false)&&(System.isRightButtonPressed(e)==false)){
						var pos = System.mouseCoordinates(e);
						obj.moveState = 1;			 
						obj.tempX = pos[0];
						obj.tempY = pos[1];
					}
				});			
				System.addGlobalEvent('mousemove',function(e){
					if ((obj!=null)&&(obj.moveState == 1)){
						var pos = System.mouseCoordinates(e);
						var dx = pos[0] - obj.tempX;
						var dy = pos[1] - obj.tempY;
																		
						if (obj.anchorLeft==true){
							obj.mainDiv.style.left = (obj.styleLeft+dx)+'px';
						}
						
						if (obj.anchorTop==true) {
							obj.mainDiv.style.top = (obj.styleTop+dy)+'px';
						}
						
						if (obj.anchorRight==true){
							obj.mainDiv.style.right = (obj.styleRight-dx)+'px';
						}
						if (obj.anchorBottom==true){
							obj.mainDiv.style.bottom = (obj.styleBottom-dy)+'px';
						}					
					}
				});
				System.addGlobalEvent('mouseup',function(e){
					if ((obj!=null)&&(obj.moveState == 1)){
						obj.moveState = 0;
						var pos = System.mouseCoordinates(e);
						var dx = pos[0] - obj.tempX;
						var dy = pos[1] - obj.tempY;
						
						if (obj.anchorLeft==true){
						obj.mainDiv.style.left = (obj.styleLeft+dx)+'px';
						}
						if (obj.anchorTop==true) {
							obj.mainDiv.style.top = (obj.styleTop+dy)+'px';
						}
						
						if (obj.anchorRight==true){
							obj.mainDiv.style.right = (obj.styleRight-dx)+'px';
						}
						if (obj.anchorBottom==true){
							obj.mainDiv.style.bottom= (obj.styleBottom-dy)+'px';
						}	
						
						obj.innerOnResize();
					}
				});
			} else {
				this.workLeft = 0
				this.workTop = 0;
				this.workRight = 0;
				this.workBottom = 0;
			}
			
		
			
			this.workspaceDiv = System.createDiv(workLeft,workTop,workRight,workBottom,null,null);
			this.workspaceDiv.style.backgroundColor = this.backColor;
			
			if (this.borderStyle != 'NONE'){
				this.backDiv = System.createDiv(workLeft,workTop,workRight,workBottom,null,null);
				this.backDiv.style.backgroundColor = System.borderColor;

				this.workspaceDiv = System.createDiv(1,1,1,1,null,null);				
				this.workspaceDiv.style.backgroundColor = this.backColor;
				this.backDiv.appendChild(this.workspaceDiv);
			
			
				if (this.clipChildren==true) this.workspaceDiv.style.overflow = 'hidden';
				this.mainDiv.appendChild(this.backDiv);
			} else {
				this.workspaceDiv = System.createDiv(workLeft,workTop,workRight,workBottom,null,null);
				this.workspaceDiv.style.backgroundColor = this.backColor;
				if (this.clipChildren==true) this.workspaceDiv.style.overflow = 'hidden';
				this.mainDiv.appendChild(this.workspaceDiv);			
			}
			
		
			System.addEvent(this.workspaceDiv,'mousemove',function(e){
				if (obj.onmousemove!=null){
					var pos = System.mouseCoordinates(e);
					var dpos = System.divPosition(obj.workspaceDiv);
					obj.onmousemove(pos[0]-dpos[0],pos[1]-dpos[1]);			
				}
			});
				
				
				
			
			
			System.addEvent(this.mainDiv,'mousedown',function(e){
			
				if ((obj.sendOnTop==true)&&(obj.mainDiv.style.zIndex<System.zIndex)){	
					obj.mainDiv.style.zIndex = System.zIndex;
					System.zIndex+=1000;
				}
			});	
			
			if ((this.borderStyle == 'SIZABLE')||(this.borderStyle == 'TOOL')){
				ramki[4].style.cursor = 'se-resize';
				if(ramki[4].addEventListener){
				ramki[4].addEventListener('mousedown', System.mouseDown, true);
				}
				System.addEvent(ramki[4],'mousedown',function(e){  
					if ((obj.maximized==false)&&(System.isRightButtonPressed(e)==false)){
						var pos = System.mouseCoordinates(e);
						obj.resizeState = 1;	
						obj.resizeIndex = 4;					
						obj.tempX = pos[0];
						obj.tempY = pos[1];
						obj.tmpWidth = obj.width;
						obj.tmpHeight = obj.height;
						
					}
				});
				System.addGlobalEvent('mousemove',function(e){
					if ((obj!=null)&&(obj.resizeIndex == 4)&&(obj.resizeState == 1)){
						var pos = System.mouseCoordinates(e);
						var dx = pos[0] - obj.tempX;
						var dy = pos[1] - obj.tempY;
						
						if ((obj.anchorRight==false)&&(obj.anchorLeft==true)&&((obj.tmpWidth+dx)>obj.minWidth)){
							obj.width = obj.tmpWidth+dx;
							obj.mainDiv.style.width = obj.width+'px';
						}
						if ((obj.anchorRight==true)&&(obj.anchorLeft==false)&&((obj.tmpWidth+dx)>obj.minWidth)){
							obj.width = obj.tmpWidth+dx;
							var par = obj.parentSize();
							obj.mainDiv.style.width = obj.width+'px';
							obj.mainDiv.style.right = (par[0]-obj.width-obj.x)+'px';
						}				
						if ((obj.anchorRight==true)&&(obj.anchorLeft==true)&&((obj.tmpWidth+dx)>obj.minWidth)){
							obj.width = obj.tmpWidth+dx;
							var par = obj.parentSize();
							obj.mainDiv.style.right = (par[0]-obj.width-obj.x)+'px';
						}					
						if ((obj.anchorBottom==false)&&(obj.anchorTop==true)&&((obj.tmpHeight+dy)>obj.minHeight)){
							obj.height = obj.tmpHeight+dy;
							obj.mainDiv.style.height = obj.height+'px';
						}
						if ((obj.anchorBottom==true)&&(obj.anchorTop==false)&&((obj.tmpHeight+dy)>obj.minHeight)){
							obj.height = obj.tmpHeight+dy;
							var par = obj.parentSize();
							obj.mainDiv.style.height = obj.height+'px';
							obj.mainDiv.style.bottom = (par[1]-obj.height-obj.y)+'px';
						}
						if ((obj.anchorBottom==true)&&(obj.anchorTop==true)&&((obj.tmpHeight+dy)>obj.minHeight)){
							obj.height = obj.tmpHeight+dy;
							var par = obj.parentSize();
							obj.mainDiv.style.bottom = (par[1]-obj.height-obj.y)+'px';
						}					
						
							
					}
				});			
				System.addGlobalEvent('mouseup',function(e){
					if ((obj!=null)&&(obj.resizeState == 1)){
						obj.resizeState = 0;
						obj.innerOnResize();
						if (obj.onresize!=null) obj.onresize();	
					}
				});	
				ramki[3].style.cursor = 'e-resize';
				if(ramki[3].addEventListener){
				ramki[3].addEventListener('mousedown', System.mouseDown, true);
				}
				System.addEvent(ramki[3],'mousedown',function(e){  
					if ((obj.maximized==false)&&(System.isRightButtonPressed(e)==false)){
						var pos = System.mouseCoordinates(e);
						obj.resizeState = 1;	
						obj.resizeIndex = 3;	
						obj.tempX = pos[0];
						obj.tempY = pos[1];
						obj.tmpWidth = obj.width;
						obj.tmpHeight = obj.height;
					}
				});
				System.addGlobalEvent('mousemove',function(e){
					if ((obj!=null)&&(obj.resizeIndex == 3)&&(obj.resizeState == 1)){
						var pos = System.mouseCoordinates(e);
						var dx = pos[0] - obj.tempX;
						var dy = pos[1] - obj.tempY;
						
						if ((obj.anchorRight==false)&&(obj.anchorLeft==true)&&((obj.tmpWidth+dx)>obj.minWidth)){
							obj.width = obj.tmpWidth+dx;
							obj.mainDiv.style.width = obj.width+'px';
						}
						if ((obj.anchorRight==true)&&(obj.anchorLeft==false)&&((obj.tmpWidth+dx)>obj.minWidth)){
							obj.width = obj.tmpWidth+dx;
							var par = obj.parentSize();
							obj.mainDiv.style.width = obj.width+'px';
							obj.mainDiv.style.right = (par[0]-obj.width-obj.x)+'px';
						}				
						if ((obj.anchorRight==true)&&(obj.anchorLeft==true)&&((obj.tmpWidth+dx)>obj.minWidth)){
							obj.width = obj.tmpWidth+dx;
							var par = obj.parentSize();
							obj.mainDiv.style.right = (par[0]-obj.width-obj.x)+'px';
						}																							
					}
				});						
				ramki[5].style.cursor = 'n-resize';
				if(ramki[5].addEventListener){
				ramki[5].addEventListener('mousedown', System.mouseDown, true);
				}
				System.addEvent(ramki[5],'mousedown',function(e){  
					if ((obj.maximized==false)&&(System.isRightButtonPressed(e)==false)){
						var pos = System.mouseCoordinates(e);
						obj.resizeState = 1;	
						obj.resizeIndex = 5;					
						obj.tempX = pos[0];
						obj.tempY = pos[1];
						obj.tmpWidth = obj.width;
						obj.tmpHeight = obj.height;
					}
				});
				System.addGlobalEvent('mousemove',function(e){
					if ((obj!=null)&&(obj.resizeIndex == 5)&&(obj.resizeState == 1)){
						var pos = System.mouseCoordinates(e);
						var dx = pos[0] - obj.tempX;
						var dy = pos[1] - obj.tempY;
									
						if ((obj.anchorBottom==false)&&(obj.anchorTop==true)&&((obj.tmpHeight+dy)>obj.minHeight)){
							obj.height = obj.tmpHeight+dy;
							obj.mainDiv.style.height = obj.height+'px';
						}
						if ((obj.anchorBottom==true)&&(obj.anchorTop==false)&&((obj.tmpHeight+dy)>obj.minHeight)){
							obj.height = obj.tmpHeight+dy;
							var par = obj.parentSize();
							obj.mainDiv.style.height = obj.height+'px';
							obj.mainDiv.style.bottom = (par[1]-obj.height-obj.y)+'px';
						}
						if ((obj.anchorBottom==true)&&(obj.anchorTop==true)&&((obj.tmpHeight+dy)>obj.minHeight)){
							obj.height = obj.tmpHeight+dy;
							var par = obj.parentSize();
							obj.mainDiv.style.bottom = (par[1]-obj.height-obj.y)+'px';
						}							
					}
				});			

			}
		}
		this.addContextMenuToWorkspace = function(menu){
			System.disableContextMenu(this.workspaceDiv);
			System.cancelMouseUp(this.workspaceDiv);
			System.addEvent(this.workspaceDiv,'mouseup',function(e){
				if(System.isRightButtonPressed(e)==true){
					var pos = System.mouseCoordinates(e);
					menu.setParent(obj);	
					menu.show(System.systemDiv,pos[0],pos[1]);
				}
			});
			System.addGlobalEvent('mousedown',function(e){
				if(menu.opened == true){			
					menu.hide();
				}
			});

		}	
	},
	//x,y - pozycja
	//text
	//fontSize
	//fontFamily
	//fontColor
	Label:function(param,parent){
		var obj = this;
		this.parent = parent;
		if ((param!=null)&&((parent.formType == 'WINDOW')||(parent.formType == 'PANEL')||(parent.nodeName=='DIV'))){
			
			if (parent.nodeName=='DIV') this.parentDiv = parent;
			else
			if (parent.formType!=undefined){
				if (parent.formType == 'WINDOW') this.parentDiv = parent.getWorkspaceDiv();
				if (parent.formType == 'PANEL') this.parentDiv = parent.mainDiv;				
			}
			
			if (param.x!=null)
				this.x = param.x;
			else
				this.x = 0;
		
			if (param.y!=null)
				this.y = param.y;
			else
				this.y = 0;
			
			if (parent.formType == 'WINDOW') this.parentDiv = this.parent.workspaceDiv;

			if (param.fontSize!=null)
				this.fontSize = param.fontSize+'px';
			else	
				this.fontSize = '12px';
				
			if (param.fontSize!=null)
				this.fontSize = param.fontSize+'px';
			else	
				this.fontSize = '11px';

			if (param.fontFamily!=null)
				this.fontFamily = param.fontFamily;
			else	
				this.fontFamily = 'tahoma';
				
			if (param.textAlign!=null)
				this.textAlign = param.textAlign;
			else	
				this.textAlign = 'left';
				
			if (param.fontColor!=null)
				this.fontColor = param.fontColor;
			else	
				this.fontColor = '#000';	
			
			this.text = param.text;	

			if (param.width!=null)
				this.width = param.width;
			else	
				this.width = null;
				
			if (param.backColor!=null)
				this.backColor = param.backColor;
			else	
				this.backColor = null;				
			
			if (this.width==null)
			this.mainDiv = System.createDiv(this.x,this.y,0,null,null,10);
			else
			this.mainDiv = System.createDiv(this.x,this.y,null,null,this.width,10);
			
			this.mainDiv.innerHTML = this.text;	
			this.mainDiv.style.fontFamily = this.fontFamily;
			this.mainDiv.style.fontSize = this.fontSize;
			this.mainDiv.style.color = this.fontColor;	
			this.mainDiv.style.textAlign = this.textAlign;
			if (this.backColor!=null){
				this.mainDiv.style.backgroundColor = this.backColor;
			}
			this.parentDiv.appendChild(this.mainDiv);	
		}		
	},
	//x,y - pozycja
	//text
	//checked
	//oncheck
	CheckBox:function(param,parent){
		var obj = this;
		this.parent = parent;
		this.setEnable=function(enable){
			if (enable==true){
				this.tdText.style.color = '#000';
				this.checkBox.disabled = false;
			} else {
				this.tdText.style.color = '#999';
				this.checkBox.disabled = true;
			}
		}
		this.setCheck = function(checked){
			this.checkBox.checked = checked;
			this.checked = checked;
		}
		if ((param!=null)&&((parent.formType == 'WINDOW')||(parent.formType == 'PANEL')||(parent.nodeName=='DIV')||(parent!=null))){
			
			if (parent.nodeName=='DIV') this.parentDiv = parent;
			else
			if (parent.formType!=undefined){
				if (parent.formType == 'WINDOW') this.parentDiv = parent.getWorkspaceDiv();
				if (parent.formType == 'PANEL') this.parentDiv = parent.mainDiv;				
			} else this.parentDiv = parent;
			
			if (param.x!=null)
				this.x = param.x;
			else
				this.x = 0;
		
			if (param.y!=null)
				this.y = param.y;
			else
				this.y = 0;
				
			if (param.checked!=null)
				this.checked = param.checked;
			else
				this.checked = false;	
			
			if (parent.formType == 'WINDOW') this.parentDiv = this.parent.workspaceDiv;

			this.text = param.text;	
				
			this.mainDiv = System.createDiv(this.x,this.y,0,null,null,10);
			this.parentDiv.appendChild(this.mainDiv);
			var table = document.createElement('table');
			table.style.width = '100%';
			this.mainDiv.appendChild(table);
			tbody = document.createElement('tbody');
			table.appendChild(tbody);
			var tr = document.createElement('tr');
			tbody.appendChild(tr);
			
			tdCheck = document.createElement('td');
			tdCheck.style.width = '1px';
			tr.appendChild(tdCheck);
			this.checkBox = document.createElement('input');
			this.checkBox.type = 'checkbox';
			tdCheck.appendChild(this.checkBox);
			
			System.addEvent(this.checkBox,'click',function(){
				obj.checked = obj.checkBox.checked;
				if (obj.oncheck) obj.oncheck(obj.checked);
			});
			
			
			this.setCheck(this.checked);
			
			this.tdText = document.createElement('td');
			this.tdText.style.textAlign = 'left';
			this.tdText.style.fontSize = '11px';
			this.tdText.innerHTML = this.text;
			tr.appendChild(this.tdText);
			
		}		
	},
	//x,y - pozycja okna
	// width,height - wymiary okna	
	// anchorTop,anchorLeft,anchorRight,anchorBottom - kotwice (true,false);	
	//backColor
	//imagesSite 'LEFT' 'RIGHT'
	ListItem:function(text,image,color,onclick,ondbclick){
		this.text = text;
		this.image = image;
		if (color!=null)
		this.color = color;
		else
		this.color = '#000';
		this.onclick = onclick;
		this.ondbclick = ondbclick;
	},
	List:function(param,parent){
		var obj = this;
		this.parent = parent;
		this.selectItemByIndex = function(index){
			if (index<this.items.length){
				var item = this.items[index];
				this.selectedItem = item;
				if (this.selectedItem!=null)
				this.selectedItem.mainDiv.style.backgroundColor = this.backColor;
				this.selectedItem.mainDiv.style.backgroundColor = '#a5c4ed';	
				return item;	
			} else return null;
		}
		this.removeAll = function(){
			for (var i=0;i<this.items.length;i++){
				this.tbody.removeChild(this.items[i].mainDiv);
			}
			this.items.length = 0;
			this.selectedItem = null;
		}
		this.addItem = function(item){
			this.items.push(item);
			var tr = document.createElement('tr');
			item.mainDiv = tr;
			this.tbody.appendChild(tr);
			
			System.addEvent(tr,'mouseup',function(e){
				if (obj.selectedItem!=null)
				obj.selectedItem.mainDiv.style.backgroundColor = obj.backColor;
				
				if (obj.selectedItem != item){
					obj.selectedItem = item;
					obj.selectedItem.mainDiv.style.backgroundColor = '#a5c4ed';
				}
			});
			
			if (item.onclick!=null) {
				System.addEvent(tr,'mouseup',function(e){
					if (item.pushed==true){
						if (item.onclick) item.onclick();
						item.pushed = false;
					}
				});
				System.addEvent(tr,'mousedown',function(e){
					item.pushed = true;
				});
				System.addEvent(tr,'mouseout',function(e){
					item.pushed = false;
				});			
			}
			
			if (item.ondbclick!=null){
				System.addEvent(tr,'dblclick',function(e){
					item.ondbclick();
				});			
			}
			
			if(this.imagesSite=='LEFT')
			if ((!((item.image==null)||(item.image=='')))){
				var tdImg = document.createElement('td');
				tdImg.style.padding = '1px';
				tdImg.style.width = '1px';
				tr.appendChild(tdImg);
				tdImg.innerHTML = '<img src="'+item.image+'"/>';		
			} else {
				var tdImg = document.createElement('td');
				tdImg.style.width = '0px';
				tr.appendChild(tdImg);
			}
			
			var tdText = document.createElement('td');
			tdText.style.padding = '3px';
			tdText.style.color = item.color;
			tr.appendChild(tdText);
			tdText.innerHTML = item.text;
			
			if (this.imagesSite=='RIGHT')
			if ((!((item.image==null)||(item.image=='')))){
				var tdImg = document.createElement('td');
				tdImg.style.width = '1px';	
				tdImg.style.padding = '1px';				
				tr.appendChild(tdImg);
				tdImg.innerHTML = '<img src="'+item.image+'"/>';						
			} else {
				var tdImg = document.createElement('td');
				tdImg.style.width = '0px';
				tr.appendChild(tdImg);
			}	
			return item;
		}
		this.calculatePositionParameters = function(){
			var parentWidth = 0;
			var parentHeight = 0;
			
			parentWidth = this.parentDiv.clientWidth;
			parentHeight = this.parentDiv.clientHeight;
				
			if ((this.anchorLeft == true)&&(this.anchorRight == false)){
				this.styleRight = null;
				this.styleLeft = this.x;
				this.styleWidth = this.width;
			}
			if ((this.anchorLeft == false)&&(this.anchorRight == true)){
				this.styleRight = parentWidth-this.x-this.width;
				this.styleWidth = this.width;
				this.styleLeft = null;
			}
			if ((this.anchorLeft == true)&&(this.anchorRight == true)){
				this.styleLeft = this.x;
				this.styleRight = parentWidth-this.x-this.width;			
				this.styleWidth = null;
			}
			
			if ((this.anchorTop == true)&&(this.anchorBottom == false)){
				this.styleTop = this.y;
				this.styleHeight = this.height;
				this.styleBottom = null;
			}		
			if ((this.anchorTop == false)&&(this.anchorBottom == true)){
				this.styleBottom = parentHeight-this.y-this.height;
				this.styleHeight = this.height;
				this.styleTop = null;
			}			
			if ((this.anchorTop == true)&&(this.anchorBottom == true)){
				this.styleTop = this.y;
				this.styleBottom = parentHeight-this.y-this.height;
				this.styleHeight = null;
			}		
		}
		if ((param!=null)&&((parent.formType == 'WINDOW')||(parent.formType == 'PANEL')||(parent.nodeName=='DIV'))){
			this.selectedItem = null;
			this.items = new Array();
			
			if (parent.nodeName=='DIV') this.parentDiv = parent;
			else
			if (parent.formType!=undefined){
				if (parent.formType == 'WINDOW') this.parentDiv = parent.getWorkspaceDiv();
				if (parent.formType == 'PANEL') this.parentDiv = parent.mainDiv;				
			}
			
			if (param.x!=null)
				this.x = param.x;
			else
				this.x = 0;
		
			if (param.y!=null)
				this.y = param.y;
			else
				this.y = 0;
			
			if (param.imagesSite!=null)
				this.imagesSite = param.imagesSite;
			else
				this.imagesSite = 'LEFT';
		
			if (param.width!=null)
				this.width = param.width;
			else
				this.width = 100;		
    
			if (param.height!=null)
				this.height = param.height;
			else
				this.height = 100;
		
			if (param.anchorLeft!=null)
				this.anchorLeft = param.anchorLeft;
			else
				this.anchorLeft = true;
		
			if (param.anchorTop!=null)
				this.anchorTop = param.anchorTop;
			else
				this.anchorTop = true;
			
			if (param.anchorRight!=null)
				this.anchorRight = param.anchorRight;
			else
				this.anchorRight = false;	
    
			if (param.anchorBottom!=null)
				this.anchorBottom = param.anchorBottom;
			else
				this.anchorBottom = false;	
			
			if ((this.anchorBottom == false)&&(this.anchorTop == false)) this.anchorTop = true;	
			if ((this.anchorLeft == false)&&(this.anchorRight == false)) this.anchorLeft = true;	
			
			if (param.border!=null)
				this.border = param.border;
			else
					this.border = '#aaa';	
					
			if (param.backColor!=null)
				this.backColor = param.backColor;
			else
				this.backColor = '#fefefe';	
				
			this.calculatePositionParameters();
			if (this.styleWidth!=null) this.styleWidth-=2;
			if (this.styleHeight!=null) this.styleHeight-=2;
			this.mainDiv = System.createDiv(this.styleLeft,this.styleTop,this.styleRight,this.styleBottom,this.styleWidth,this.styleHeight);
			this.mainDiv.style.borderTop = '1px solid '+this.border;
			this.mainDiv.style.borderLeft = '1px solid '+this.border;
			this.mainDiv.style.borderRight = '1px solid '+this.border;
			this.mainDiv.style.borderBottom = '1px solid '+this.border;
			this.mainDiv.style.fontSize = '12px';
			this.mainDiv.style.fontFamily = 'tahoma';
			this.mainDiv.style.overflow = 'auto';
			this.mainDiv.style.backgroundColor = this.backColor;
			System.disableSelection(this.mainDiv);
			this.parentDiv.appendChild(this.mainDiv);
			//alert(this.styleLeft+' '+this.styleTop+' '+this.styleRight+' '+this.styleBottom+' '+this.styleWidth+' '+this.styleHeight);
			var table = document.createElement('table');
			table.style.width = '100%';
			table.style.padding = '0px';
			table.style.borderCollapse= 'collapse';
			this.mainDiv.appendChild(table);
			this.tbody = document.createElement('tbody');
			table.appendChild(this.tbody);	
			var mainDiv = this.mainDiv;
			
			System.addEvent(this.mainDiv,'mousedown',function(e){
				if (obj.selectedItem!=null)
				obj.selectedItem.mainDiv.style.backgroundColor = obj.backColor;
				obj.selectedItem = null;
			});
		
			System.addEvent(this.mainDiv,'mouseup',function(e){
				
				var but = 0;
				if (System.isRightButtonPressed(e)==true) but = 1;
				var pos = System.mouseCoordinates(e);
				var dpos = System.divPosition(mainDiv);	
				if (obj.onmouseup) obj.onmouseup(but,pos[0]-dpos[0],pos[1]-dpos[1]);	
			});
			System.disableContextMenu(this.mainDiv);		
		}
	},
	//cells - tablica z wartosciami komórek we wierszu
	//onselect
	//oncheck
	//ondblclick
	//checked
	GridListItem:function(param){
		this.cells = param.cells;
		this.onselect = param.onselect;
		this.oncheck = param.oncheck;
		if (param.checked!=null) this.checked = param.checked; else this.checked = false;
		this.ondblclick = param.ondblclick;
		this.tds = new Array();
		this.getElement = function(index){
			return this.tds[index];
		}
		this.setTextColor = function(color){
			return this.mainDiv.style.color = color;
		}
		this.setCheck = function(checked){
			if (this.checkBox) this.checkBox.checked = checked;
			this.checked = checked;
		}
	},
	//x,y - pozycja okna
	// width,height - wymiary okna	
	// anchorTop,anchorLeft,anchorRight,anchorBottom - kotwice (true,false);	
	//backColor
	//gridWidths
	//gridAligns
	//headers
	//check (true/false) czy sa checkboxy
	//onselect
 	GridList:function(param,parent){	
		var obj = this;
		this.parent = parent;
		this.getRowByElementValue = function(elementIndex,value){
			for (var i=0;i<this.items.length;i++){
				var it = this.items[i];
				var elm = it.getElement(elementIndex);
				if (elm!=null){
					if (elm.innerHTML == value) return it;
				}
			}
			return null;
		}
		this.removeAll = function(){
			for (var i=0;i<this.items.length;i++){
				this.tbody.removeChild(this.items[i].mainDiv);
			}
			this.items.length = 0;
			this.selectedItem = null;
		}
		this.addItem = function(item){
			this.items.push(item);
			var tr = document.createElement('tr');
			item.mainDiv = tr;
			
			System.addEvent(tr,'mousedown',function(e){
				if (obj.selectedItem!=null)
				obj.selectedItem.mainDiv.style.backgroundColor = obj.backColor;
				obj.selectedItem = item;
				obj.selectedItem.mainDiv.style.backgroundColor = '#a5c4ed';
				if (obj.onselect) obj.onselect(obj.selectedItem);
			});
			
			if (item.onselect!=null) {
				System.addEvent(tr,'mouseup',function(e){
					if (item.pushed==true){
						item.onselect();
						item.pushed = false;
					}
				});
				System.addEvent(tr,'mousedown',function(e){
					item.pushed = true;
				});
				System.addEvent(tr,'mouseout',function(e){
					item.pushed = false;
				});			
			}
			
			if (item.ondblclick!=null){
				System.addEvent(tr,'dblclick',function(e){
					item.ondblclick();
				});			
			}
			
			this.tbody.appendChild(tr);
			
			if (this.check==true){
				var td = document.createElement('td');
				td.style.padding = '1px 1px 1px 1px';
				td.style.textAlign = 'center';
				//td.style.backgroundColor='#f00';
				tr.appendChild(td);
				var ln = Math.round(Math.random()*1000000);
				
				var check = document.createElement('input');
				check.name = ln;
				check.id = 'id'+ln;
				check.type = 'checkbox';
				td.appendChild(check);
				check.checked = item.checked;
				//alert(check.checked);				
				
				item.checkBox = check;
				
				System.addEvent(check,'click',function(){
					item.checked = check.checked;
					if (item.oncheck) item.oncheck();
				});
				
			}
			
			for (var i=0;i<item.cells.length;i++){
				if (i<this.gridWidths.length){
					
					var td = document.createElement('td');
					item.tds[i] = td;
					td.style.width = this.gridWidths[i];
					td.style.padding = '2px 3px 2px 3px';
					if ((this.gridAligns!=null)&&(this.gridAligns[i]))
					td.style.textAlign = this.gridAligns[i];
					else
					td.style.textAlign = 'center';
					tr.appendChild(td);
					td.innerHTML = item.cells[i];
				}
			}
		}		
		this.getCheckedItems = function(){
			var tab = new Array();
			for (var i=0;i<this.items.length;i++){
				if (this.items[i].checked) tab.push(this.items[i]);
			}
			return tab;
		}
		this.checkAll = function(){
			this.checkedItem.length = 0;
			for(var i=0;i<this.items.length;i++){
				this.items[i].checkBox.checked = true;
				this.checkedItem.push(this.items[i]);		
			}
		},
		this.calculatePositionParameters = function(){
			var parentWidth = 0;
			var parentHeight = 0;
			
			parentWidth = this.parentDiv.clientWidth;
			parentHeight = this.parentDiv.clientHeight;
				
			if ((this.anchorLeft == true)&&(this.anchorRight == false)){
				this.styleRight = null;
				this.styleLeft = this.x;
				this.styleWidth = this.width;
			}
			if ((this.anchorLeft == false)&&(this.anchorRight == true)){
				this.styleRight = parentWidth-this.x-this.width;
				this.styleWidth = this.width;
				this.styleLeft = null;
			}
			if ((this.anchorLeft == true)&&(this.anchorRight == true)){
				this.styleLeft = this.x;
				this.styleRight = parentWidth-this.x-this.width;			
				this.styleWidth = null;
			}
			
			if ((this.anchorTop == true)&&(this.anchorBottom == false)){
				this.styleTop = this.y;
				this.styleHeight = this.height;
				this.styleBottom = null;
			}		
			if ((this.anchorTop == false)&&(this.anchorBottom == true)){
				this.styleBottom = parentHeight-this.y-this.height;
				this.styleHeight = this.height;
				this.styleTop = null;
			}			
			if ((this.anchorTop == true)&&(this.anchorBottom == true)){
				this.styleTop = this.y;
				this.styleBottom = parentHeight-this.y-this.height;
				this.styleHeight = null;
			}		
		}
		if ((param!=null)&&((parent.formType == 'WINDOW')||(parent.formType == 'PANEL')||(parent.nodeName=='DIV'))){
			this.selectedItem = null;
			this.items = new Array();
			
			if (parent.nodeName=='DIV') this.parentDiv = parent;
			else
			if (parent.formType!=undefined){
				if (parent.formType == 'WINDOW') this.parentDiv = parent.getWorkspaceDiv();
				if (parent.formType == 'PANEL') this.parentDiv = parent.mainDiv;				
			}
			
			if (param.x!=null)
				this.x = param.x;
			else
				this.x = 0;
		
			if (param.y!=null)
				this.y = param.y;
			else
				this.y = 0;
			
			if (param.imagesSite!=null)
				this.imagesSite = param.imagesSite;
			else
				this.imagesSite = 'LEFT';
		
			if (param.width!=null)
				this.width = param.width;
			else
				this.width = 100;		
    
			if (param.height!=null)
				this.height = param.height;
			else
				this.height = 100;
		
			if (param.anchorLeft!=null)
				this.anchorLeft = param.anchorLeft;
			else
				this.anchorLeft = true;
				
			if (param.check!=null)
				this.check = param.check;
			else
				this.check = false;	
		
			if (param.anchorTop!=null)
				this.anchorTop = param.anchorTop;
			else
				this.anchorTop = true;
			
			if (param.anchorRight!=null)
				this.anchorRight = param.anchorRight;
			else
				this.anchorRight = false;	
    
			if (param.anchorBottom!=null)
				this.anchorBottom = param.anchorBottom;
			else
				this.anchorBottom = false;	
				
			if (param.gridWidths!=null){			
				this.gridWidths = new Array();
				var list = param.gridWidths.split(",");
				for (var i=0;i<list.length;i++){
					var p = list[i];
					if (p.indexOf("%")!=-1){
						this.gridWidths.push(p);
					} else if (p.indexOf("px")!=-1){
						this.gridWidths.push(p);
					} else this.gridWidths.push(p+"px");
				}
			}else {
				this.gridWidths = new Array();
				this.gridWidths[0] = '100%';
			}
			if (param.gridAligns!=null){
				this.gridAligns = param.gridAligns;			
			} else this.gridAligns = false;
			
			if (param.headers!=null){
				this.headers = param.headers.split(",");;			
			} else this.headers = null;
			
			if ((this.anchorBottom == false)&&(this.anchorTop == false)) this.anchorTop = true;	
			if ((this.anchorLeft == false)&&(this.anchorRight == false)) this.anchorLeft = true;	
			
			if (param.border!=null)
				this.border = param.border;
			else
					this.border = '#aaa';	
					
			if (param.backColor!=null)
				this.backColor = param.backColor;
			else
				this.backColor = '#fefefe';	
				
			
			this.calculatePositionParameters();
			if (this.styleWidth!=null) this.styleWidth-=2;
			if (this.styleHeight!=null) this.styleHeight-=2;
			this.mainDiv = System.createDiv(this.styleLeft,this.styleTop,this.styleRight,this.styleBottom,this.styleWidth,this.styleHeight);
			this.mainDiv.style.borderTop = '1px solid '+this.border;
			this.mainDiv.style.borderLeft = '1px solid '+this.border;
			this.mainDiv.style.borderRight = '1px solid '+this.border;
			this.mainDiv.style.borderBottom = '1px solid '+this.border;
			this.mainDiv.style.fontSize = '11px';
			this.mainDiv.style.fontFamily = 'tahoma';
			this.mainDiv.style.backgroundColor = this.backColor;
			System.disableSelection(this.mainDiv);
			System.disableContextMenu(this.mainDiv);	
			this.parentDiv.appendChild(this.mainDiv);
			//alert(this.styleLeft+' '+this.styleTop+' '+this.styleRight+' '+this.styleBottom+' '+this.styleWidth+' '+this.styleHeight);
			
			var offset = 0;
			if (this.headers!=null) offset = 22;
	
			this.workspaceDiv = System.createDiv(0,offset,0,0,null,null);
			this.workspaceDiv.style.overflow = 'auto';
			this.mainDiv.appendChild(this.workspaceDiv);
			
			if (this.headers!=null) {
				var headersTable = document.createElement('table');
				headersTable.style.width = '100%';
				headersTable.style.padding = '0px';
				headersTable.style.fontSize = '11px';
				headersTable.style.height = offset+'px';				
				headersTable.style.borderBottom = '1px solid #aaa';
				headersTable.style.borderCollapse= 'collapse';
				this.mainDiv.appendChild(headersTable);
				var headersTbody = document.createElement('tbody');
				headersTable.appendChild(headersTbody);			
				
				var tr = document.createElement('tr');
				tr.style.backgroundImage = 'url('+System.folderPath+'listgrid.png)';
				headersTbody.appendChild(tr);
				
				if (this.check==true){
					var td = document.createElement('td');
					td.style.width = '16px';
					td.style.padding = '2px 3px 2px 3px';
					td.style.textAlign = 'center';
					tr.appendChild(td);
					td.innerHTML = '&nbsp;&nbsp;&nbsp;&nbsp;';
					td.style.borderRight = '1px solid #aaa';
				}
				
				for (var i=0;i<this.headers.length;i++){
					if (i<this.gridWidths.length){
						var td = document.createElement('td');
						td.style.width = this.gridWidths[i];
						td.style.padding = '2px 3px 2px 3px';
						td.style.textAlign = 'center';
						tr.appendChild(td);
						td.innerHTML = this.headers[i];
						if (i<this.headers.length-1) td.style.borderRight = '1px solid #aaa';
					}
				}				
			}			
			
			
			var table = document.createElement('table');
			table.style.width = '100%';
			table.style.padding = '0px';
			table.style.borderCollapse= 'collapse';
			this.workspaceDiv.appendChild(table);
			this.tbody = document.createElement('tbody');
			table.appendChild(this.tbody);		

			System.addEvent(this.workspaceDiv,'mouseup',function(e){
				var but = 0;
				if (System.isRightButtonPressed(e)==true) but = 1;
				var pos = System.mouseCoordinates(e);
				var dpos = System.divPosition(obj.workspaceDiv);	
				if (obj.onmouseup) obj.onmouseup(but,pos[0]-dpos[0],pos[1]-dpos[1]);	
			});
			System.disableContextMenu(this.workspaceDiv);	
		}	
	},
	//x,y - pozycja okna
	// width,height - wymiary okna	
	// anchorTop,anchorLeft,anchorRight,anchorBottom - kotwice (true,false);	
	//backColor	
	//border true/false
	//borderColor
	Panel:function(param,parent){
		var obj = this;
		this.parent = parent;
		this.addWindow = function(window){
			this.mainDiv.appendChild(window.mainDiv);
			this.mainDiv.style.zIndex =  System.zIndex;
			System.zIndex+=1000;
			if (!this.windows){
				this.windows = new Array();
			}
			this.windows.push(window);
		}
		this.setCursor = function(cursor){
			this.mainDiv.style.cursor = cursor;
		}
		this.getCursor = function(){
			return this.mainDiv.style.cursor;
		}
		this.addEvent = function(event,fun){
			if (event == 'mousedown'){
				System.addEvent(this.mainDiv,event,function(e){
					var but = 0;
					if (System.isRightButtonPressed(e)==true) but=1;
					var pos = System.mouseCoordinates(e);
					var dpos = System.divPosition(obj.mainDiv);
					var x = pos[0]-dpos[0];
					var y = pos[1]-dpos[1];
					if (fun) fun(x,y,but);	
				});			
			}
			if (event == 'mouseup'){
				System.addEvent(this.mainDiv,event,function(e){
					var but = 0;
					if (System.isRightButtonPressed(e)==true) but=1;				
					var pos = System.mouseCoordinates(e);
					var dpos = System.divPosition(obj.mainDiv);
					var x = pos[0]-dpos[0];
					var y = pos[1]-dpos[1];
					if (fun) fun(x,y,but);	
				});			
			}
			if (event == 'mousemove'){
				System.addEvent(this.mainDiv,event,function(e){
					var pos = System.mouseCoordinates(e);
					var dpos = System.divPosition(obj.mainDiv);
					var x = pos[0]-dpos[0];
					var y = pos[1]-dpos[1];
					if (fun) fun(x,y);	
				});			
			}	
			if (event == 'mouseover'){
				System.addEvent(this.mainDiv,event,function(e){
					var pos = System.mouseCoordinates(e);
					var dpos = System.divPosition(obj.mainDiv);
					var x = pos[0]-dpos[0];
					var y = pos[1]-dpos[1];
					if (fun) fun(x,y);	
				});			
			}
			if (event == 'mouseout'){
				System.addEvent(this.mainDiv,event,function(e){
					var pos = System.mouseCoordinates(e);
					var dpos = System.divPosition(obj.mainDiv);
					var x = pos[0]-dpos[0];
					var y = pos[1]-dpos[1];
					if (fun) fun(x,y);	
				});			
			}			
		}
		this.hide = function(){
			this.backDiv.style.display = 'none';
			this.visible = false;
		}
		this.show = function(){
			this.backDiv.style.display = 'block';
			this.visible = true;
		}		
		this.addImage = function(image,x,y,width,height){
			var div = System.createDiv(x,y,null,null,width,height);
			div.style.backgroundImage = 'url('+image+')';
			this.mainDiv.appendChild(div);
		}
		this.addImageWithAnchor = function(image,left,top,right,bottom,width,height){
			var div = System.createDiv(left,top,right,bottom,width,height);
			div.style.backgroundImage = 'url('+image+')';
			this.mainDiv.appendChild(div);
			return div;
		}		
		this.getWidth = function(){
			return this.backDiv.clientWidth;
		}
		this.getHeight = function(){
			return this.backDiv.clientHeight;
		}		
		this.getWorkspaceWidth = function(){
			return this.mainDiv.clientWidth;
		}
		this.getWorkspaceHeight = function(){
			return this.mainDiv.clientHeight;
		}		
		this.setPositionFromActualParameters = function(){
			this.calculatePositionParameters(); 
			System.setDiv(this.backDiv,this.styleLeft,this.styleTop,this.styleRight,this.styleBottom,this.styleWidth,this.styleHeight);
		}
		this.calculatePositionParameters = function(){
			var parentWidth = 0;
			var parentHeight = 0;
			parentWidth = this.parentDiv.clientWidth;
			parentHeight = this.parentDiv.clientHeight;
				
			if ((this.anchorLeft == true)&&(this.anchorRight == false)){
				this.styleRight = null;
				this.styleLeft = this.x;
				this.styleWidth = this.width;
			}
			if ((this.anchorLeft == false)&&(this.anchorRight == true)){
				this.styleRight = parentWidth-this.x-this.width;
				this.styleWidth = this.width;
				this.styleLeft = null;
			}
			if ((this.anchorLeft == true)&&(this.anchorRight == true)){
				this.styleLeft = this.x;
				this.styleRight = parentWidth-this.x-this.width;			
				this.styleWidth = null;
			}
			
			if ((this.anchorTop == true)&&(this.anchorBottom == false)){
				this.styleTop = this.y;
				this.styleHeight = this.height;
				this.styleBottom = null;
			}		
			if ((this.anchorTop == false)&&(this.anchorBottom == true)){
				this.styleBottom = parentHeight-this.y-this.height;
				this.styleHeight = this.height;
				this.styleTop = null;
			}			
			if ((this.anchorTop == true)&&(this.anchorBottom == true)){
				this.styleTop = this.y;
				this.styleBottom = parentHeight-this.y-this.height;
				this.styleHeight = null;
			}		
		}
		this.addContextMenu = function(menu){
			System.disableContextMenu(this.mainDiv);
			System.cancelMouseUp(this.mainDiv);
			System.addEvent(this.mainDiv,'mouseup',function(e){
				if(System.isRightButtonPressed(e)==true){
					var pos = System.mouseCoordinates(e);
					menu.setParent(obj);	
					menu.show(System.systemDiv,pos[0],pos[1]);
				}
			});
			System.addGlobalEvent('mousedown',function(e){
				if(menu.opened == true){			
					menu.hide();
				}
			});

		}	
		if ((param!=null)&&((parent.formType == 'WINDOW')||(parent.formType == 'PANEL')||(parent.nodeName=='DIV'))){
			this.formType = 'PANEL';
			
			if (parent.nodeName=='DIV'){
				this.parentDiv = parent;
			} else {
				if (parent.formType!=undefined){
					if (parent.formType == 'WINDOW') this.parentDiv = parent.getWorkspaceDiv();
					if (parent.formType == 'PANEL') this.parentDiv = parent.mainDiv;
				}
			}
			
			if (param.x!=null)
				this.x = param.x;
			else
				this.x = 0;
		
			if (param.y!=null)
				this.y = param.y;
			else
				this.y = 0;
		
			if (param.width!=null)
				this.width = param.width;
			else
				this.width = 100;		
    
			if (param.height!=null)
				this.height = param.height;
			else
				this.height = 100;
		
			if (param.anchorLeft!=null)
				this.anchorLeft = param.anchorLeft;
			else
				this.anchorLeft = true;
		
			if (param.anchorTop!=null)
				this.anchorTop = param.anchorTop;
			else
				this.anchorTop = true;
			
			if (param.anchorRight!=null)
				this.anchorRight = param.anchorRight;
			else
				this.anchorRight = false;	
    
			if (param.anchorBottom!=null)
				this.anchorBottom = param.anchorBottom;
			else
				this.anchorBottom = false;	
				
			if ((this.anchorBottom == false)&&(this.anchorTop == false)) this.anchorTop = true;	
			if ((this.anchorLeft == false)&&(this.anchorRight == false)) this.anchorLeft = true;	

			if (param.backColor!=null)
				this.backColor = param.backColor;
			else
				this.backColor = System.backColor;	
				

			if (param.border!=null)
				this.border = param.border;
			else
				this.border = false;
			
			if (param.borderColor!=null)
				this.borderColor = param.borderColor;
			else
				this.borderColor = '#aaa';
				
			if (param.borderTop!=null)
				this.borderTop = param.borderTop;
			else
				this.borderTop = 1;	
				
			this.calculatePositionParameters();
							
			this.backDiv = System.createDiv(this.styleLeft,this.styleTop,this.styleRight,this.styleBottom,this.styleWidth,this.styleHeight);
			if (this.border == true){	
				this.backDiv.style.backgroundColor = this.borderColor;
				this.mainDiv = System.createDiv(1,this.borderTop,1,1,null,null);
			} else {
				this.mainDiv = System.createDiv(0,0,0,0,null,null);
			}
			this.backDiv.appendChild(this.mainDiv);
			this.mainDiv.style.fontSize = '12px';
			this.mainDiv.style.fontFamily = 'tahoma';
			this.mainDiv.style.overflow = 'hidden';
			if (this.backColor!='transparent')
			this.mainDiv.style.backgroundColor = this.backColor;
			else
			this.mainDiv.style.backgroundImage ='url('+System.folderPath+'blank2.png)';
			
			this.parentDiv.appendChild(this.backDiv);		

			System.addEvent(obj.mainDiv,'mousemove',function(e){
				if (obj.onmousemove!=null){
					var pos = System.mouseCoordinates(e);
					var dpos = System.divPosition(obj.mainDiv);
					obj.onmousemove(pos[0]-dpos[0],pos[1]-dpos[1]);			
				}
			});	
			
			obj.onmouseout = null;
			obj.onmouseover = null;
			System.addEvent(obj.mainDiv,'mouseover',function(e){
				if (obj.onmouseover!=null){
					obj.onmouseover();			
				}
			});	
			System.addEvent(obj.mainDiv,'mouseout',function(e){
				if (obj.onmouseout!=null){
					obj.onmouseout();			
				}
			});	
			System.addEvent(obj.mainDiv,'mouseup',function(e){
				if (obj.onmouseup!=null){
					obj.onmouseup();			
				}
			});				
		}
	},
	//x,y - pozycja okna
	// width,height - wymiary okna	
	// anchorTop,anchorLeft,anchorRight,anchorBottom - kotwice (true,false);		
	//text;
	//password (true/false)
	TextBox:function(param,parent){
		var obj = this;
		this.parent = parent;
		this.setText = function(value){
			this.edit.value = value;
		}
		this.getText = function(){
			return this.edit.value;
		}
		this.hide = function(){
			this.mainDiv.style.display = 'none';
		}
		this.show = function(){
			this.mainDiv.style.display = 'block';
		}		
		this.getWidth = function(){
			return this.mainDiv.clientWidth;
		}
		this.getHeight = function(){
			return this.mainDiv.clientHeight;
		}		
		this.setPositionFromActualParameters = function(){
			this.calculatePositionParameters(); 
			System.setDiv(this.mainDiv,this.styleLeft,this.styleTop,this.styleRight,this.styleBottom,this.styleWidth,this.styleHeight);
		}
		this.calculatePositionParameters = function(){
			var parentWidth = 0;
			var parentHeight = 0;
			parentWidth = this.parentDiv.clientWidth;
			parentHeight = this.parentDiv.clientHeight;
				
			if ((this.anchorLeft == true)&&(this.anchorRight == false)){
				this.styleRight = null;
				this.styleLeft = this.x;
				this.styleWidth = this.width;
			}
			if ((this.anchorLeft == false)&&(this.anchorRight == true)){
				this.styleRight = parentWidth-this.x-this.width;
				this.styleWidth = this.width;
				this.styleLeft = null;
			}
			if ((this.anchorLeft == true)&&(this.anchorRight == true)){
				this.styleLeft = this.x;
				this.styleRight = parentWidth-this.x-this.width;			
				this.styleWidth = null;
			}
			
			if ((this.anchorTop == true)&&(this.anchorBottom == false)){
				this.styleTop = this.y;
				this.styleHeight = this.height;
				this.styleBottom = null;
			}		
			if ((this.anchorTop == false)&&(this.anchorBottom == true)){
				this.styleBottom = parentHeight-this.y-this.height;
				this.styleHeight = this.height;
				this.styleTop = null;
			}			
			if ((this.anchorTop == true)&&(this.anchorBottom == true)){
				this.styleTop = this.y;
				this.styleBottom = parentHeight-this.y-this.height;
				this.styleHeight = null;
			}		
		}
		if ((param!=null)&&((parent.formType == 'WINDOW')||(parent.formType == 'PANEL')||(parent.nodeName=='DIV'))){
			this.formType = 'PANEL';
			
			if (parent.nodeName=='DIV')
				this.parentDiv = parent;
			else {
				if (parent.formType!=undefined){
					if (parent.formType == 'WINDOW') this.parentDiv = parent.getWorkspaceDiv();
					if (parent.formType == 'PANEL') this.parentDiv = parent.mainDiv;
				}
			}
			
			if (param.x!=null)
				this.x = param.x;
			else
				this.x = 0;
		
			if (param.y!=null)
				this.y = param.y;
			else
				this.y = 0;
		
			if (param.width!=null)
				this.width = param.width;
			else
				this.width = 100;		
    
			if (param.height!=null)
				this.height = param.height;
			else
				this.height = 22;
		
			if (param.anchorLeft!=null)
				this.anchorLeft = param.anchorLeft;
			else
				this.anchorLeft = true;
		
			if (param.anchorTop!=null)
				this.anchorTop = param.anchorTop;
			else
				this.anchorTop = true;
			
			if (param.anchorRight!=null)
				this.anchorRight = param.anchorRight;
			else
				this.anchorRight = false;	
    
			if (param.anchorBottom!=null)
				this.anchorBottom = param.anchorBottom;
			else
				this.anchorBottom = false;	
				
			if (param.text!=null)
				this.text = param.text;
			else
				this.text = '';		
				
			if (param.password!=null)
				this.password = param.password;
			else
				this.password = false;						
				
			if ((this.anchorBottom == false)&&(this.anchorTop == false)) this.anchorTop = true;	
			if ((this.anchorLeft == false)&&(this.anchorRight == false)) this.anchorLeft = true;	

			this.calculatePositionParameters();
						
			if (this.border == true){			
				if (this.styleWidth!=null) this.styleWidth-=2;
				if (this.styleHeight!=null) this.styleHeight-=2;
			}
			
			this.mainDiv = System.createDiv(this.styleLeft,this.styleTop,this.styleRight,this.styleBottom,this.styleWidth,this.styleHeight);
			//this.mainDiv.style.backgroundColor = '#f00';
			this.mainDiv.style.fontSize = '12px';
			this.mainDiv.style.fontFamily = 'tahoma';

			this.parentDiv.appendChild(this.mainDiv);	

				
			this.edit = document.createElement('input');

			if (this.password == true) this.edit.type = "password";
			
			this.edit.style.width = '98%';
			this.edit.value = this.text;
			this.mainDiv.appendChild(this.edit);	
			
		}
	},	
	
	//x,y - pozycja okna
	// width,height - wymiary okna	
	// anchorTop,anchorLeft,anchorRight,anchorBottom - kotwice (true,false);	
	//backColor	
	//border true/false
	//lightBorder,darkBorder
	//position
	//minPosition
	SlidePanel:function(param,parent){
		var obj = this;
		this.parent = parent;
		this.hideLeftPanel = function(){
			this.oldPosition = this.position;
			this.setPosition(-3);
			this.leftPanel.hide();
		}
		this.showLeftPanel = function(){
			if (this.oldPosition==null) this.oldPosition = 200;
			this.leftPanel.show();
			this.setPosition(this.oldPosition);
		}
		this.setPosition = function(value){
			this.position = value;
			if ((this.position-3)>=0)
			this.leftPanel.width = this.position-3;
			else
			this.leftPanel.width = 0;
			obj.leftPanel.height = obj.mainDiv.clientHeight;			
			this.leftPanel.setPositionFromActualParameters();
			this.rightPanel.x = this.position+3;
			this.rightPanel.width = this.mainDiv.clientWidth-this.position-3;
			obj.rightPanel.height = obj.mainDiv.clientHeight;	
			this.rightPanel.setPositionFromActualParameters();
			this.slideDiv.style.left = (this.position-3)+'px'; 	
			if (this.onchange) this.onchange(this.position);	
		}		
		this.calculatePositionParameters = function(){
			var parentWidth = 0;
			var parentHeight = 0;
			parentWidth = this.parentDiv.clientWidth;
			parentHeight = this.parentDiv.clientHeight;

			if ((this.anchorLeft == true)&&(this.anchorRight == false)){
				this.styleRight = null;
				this.styleLeft = this.x;
				this.styleWidth = this.width;
			}
			if ((this.anchorLeft == false)&&(this.anchorRight == true)){
				this.styleRight = parentWidth-this.x-this.width;
				this.styleWidth = this.width;
				this.styleLeft = null;
			}
			if ((this.anchorLeft == true)&&(this.anchorRight == true)){
				this.styleLeft = this.x;
				this.styleRight = parentWidth-this.x-this.width;			
				this.styleWidth = null;
			}
			
			if ((this.anchorTop == true)&&(this.anchorBottom == false)){
				this.styleTop = this.y;
				this.styleHeight = this.height;
				this.styleBottom = null;
			}		
			if ((this.anchorTop == false)&&(this.anchorBottom == true)){
				this.styleBottom = parentHeight-this.y-this.height;
				this.styleHeight = this.height;
				this.styleTop = null;
			}			
			if ((this.anchorTop == true)&&(this.anchorBottom == true)){
				this.styleTop = this.y;
				this.styleBottom = parentHeight-this.y-this.height;
				this.styleHeight = null;
			}		
		}
		if ((param!=null)&&((parent.formType == 'WINDOW')||(parent.formType == 'PANEL')||(parent.nodeName=='DIV'))){
			this.formType = 'SLIDE_PANEL';
			
			if (parent.nodeName=='DIV')
				this.parentDiv = parent;
			else {
				if (parent.formType!=undefined){
					if (parent.formType == 'WINDOW') this.parentDiv = parent.getWorkspaceDiv();
					if (parent.formType == 'PANEL') this.parentDiv = parent.mainDiv;
				}
			}
			
			if (param.x!=null)
				this.x = param.x;
			else
				this.x = 0;
		
			if (param.y!=null)
				this.y = param.y;
			else
				this.y = 0;
		
			if (param.width!=null)
				this.width = param.width;
			else
				this.width = 100;		
    
			if (param.height!=null)
				this.height = param.height;
			else
				this.height = 100;
		
			if (param.anchorLeft!=null)
				this.anchorLeft = param.anchorLeft;
			else
				this.anchorLeft = true;
		
			if (param.anchorTop!=null)
				this.anchorTop = param.anchorTop;
			else
				this.anchorTop = true;
			
			if (param.anchorRight!=null)
				this.anchorRight = param.anchorRight;
			else
				this.anchorRight = false;	
    
			if (param.anchorBottom!=null)
				this.anchorBottom = param.anchorBottom;
			else
				this.anchorBottom = false;	
				
			if ((this.anchorBottom == false)&&(this.anchorTop == false)) this.anchorTop = true;	
			if ((this.anchorLeft == false)&&(this.anchorRight == false)) this.anchorLeft = true;	

			if (param.backColor!=null)
				this.backColor = param.backColor;
			else
				this.backColor = System.backColor;	
				
			if (param.lightBorder!=null)
				this.lightBorder = param.lightBorder;
			else
				this.lightBorder = System.lightBorder;
					
			if (param.darkBorder!=null)
				this.darkBorder = param.darkBorder;
			else
				this.darkBorder = System.darkBorder;	

			if (param.border!=null)
				this.border = param.border;
			else
				this.border = false;
			
			if (param.position!=null)
				this.position = param.position;
			else
				this.position = 200;
				
			this.oldPosition = this.position;
			
			if (param.minPosition!=null)
				this.minPosition = param.minPosition;
			else
				this.minPosition = 20;
				
			this.calculatePositionParameters();
						
			if (this.border == true){			
				if (this.styleWidth!=null) this.styleWidth-=2;
				if (this.styleHeight!=null) this.styleHeight-=2;
			}
			
			this.mainDiv = System.createDiv(this.styleLeft,this.styleTop,this.styleRight,this.styleBottom,this.styleWidth,this.styleHeight);
			if (this.border == true){	
				this.mainDiv.style.borderTop = '1px solid '+this.lightBorder;
				this.mainDiv.style.borderLeft = '1px solid '+this.lightBorder;
				this.mainDiv.style.borderRight = '1px solid '+this.darkBorder;
				this.mainDiv.style.borderBottom = '1px solid '+this.darkBorder;
			}
			this.mainDiv.style.fontSize = '12px';
			this.mainDiv.style.fontFamily = 'tahoma';
			if (this.backColor!=null)
			this.mainDiv.style.backgroundColor = this.backColor;
			this.parentDiv.appendChild(this.mainDiv);				
			
			this.leftPanel = new System.Panel({x:0,y:0,width:this.position-3,height:this.mainDiv.clientHeight,anchorBottom:true,backColor:this.backColor},this.mainDiv);
			this.rightPanel = new System.Panel({x:this.position+3,y:0,width:this.mainDiv.clientWidth-this.position-3,height:this.mainDiv.clientHeight,anchorBottom:true,anchorRight:true,backColor:this.backColor},this.mainDiv);
			//this.rightPanel.mainDiv.style.backgroundColor = '#f00';
			this.slideDiv = System.createDiv(this.position-3,0,null,0,5,null);
			this.slideDiv.style.backgroundImage='url('+System.folderPath+'slide.png)';
			//this.slideDiv.style.backgroundRepeat = 'no-repeat';
			//this.slideDiv.style.backgroundPosition = 'center center';
			
			this.mainDiv.appendChild(this.slideDiv);
			this.slideDiv.style.cursor='e-resize';
			System.disableSelection(this.mainDiv);
			
			var obj = this;
			System.addEvent(this.slideDiv,'mousedown',function(e){				
				obj.pushed = true;
				var pos = System.mouseCoordinates(e);
				obj.tmpX = pos[0];
				obj.tmpPosition = obj.position;
			});
			System.addGlobalEvent('mousemove',function(e){				
				if (obj.pushed == true){
					var pos = System.mouseCoordinates(e);
					obj.position = obj.tmpPosition-(obj.tmpX-pos[0]);
					if (obj.position < obj.minPosition) obj.position = obj.minPosition;
					//obj.leftPanel.mainDiv.innerHTML = obj.position;
					obj.leftPanel.width = obj.position-3;
					obj.leftPanel.height = obj.mainDiv.clientHeight;
					obj.leftPanel.setPositionFromActualParameters();
					obj.rightPanel.x = obj.position+3;
					obj.rightPanel.width = obj.mainDiv.clientWidth-obj.position-3;
					obj.rightPanel.height = obj.mainDiv.clientHeight;
					//alert(obj.rightPanel.x+' '+obj.rightPanel.width);
					obj.rightPanel.setPositionFromActualParameters();
					obj.slideDiv.style.left = (obj.position-3)+'px'; 					
				}
			});			
			System.addGlobalEvent('mouseup',function(e){				
				if (obj.pushed == true){
					obj.pushed = false;
					if (obj.onchange) obj.onchange(obj.position);	
				}
			});				
		}
	},
	//text
	//onselect;
	Tab:function(param){
		this.text = param.text;
		if (param.width!=null)
		this.width = param.width;
		else
		this.width = 12+(param.text.length*7);
		
		this.onselect = param.onselect;
		
		this.panel = null;
		this.tdButton = null;
	},
	//x,y - pozycja okna
	// width,height - wymiary okna	
	// anchorTop,anchorLeft,anchorRight,anchorBottom - kotwice (true,false);	
	//backColor	
	//borderColor
	Tabs:function(param,parent){
		var obj = this;
		this.parent = parent;
		this.show = function(){
			this.mainDiv.style.display = 'block';
			this.tabsDiv.style.display = 'block';
		}
		this.hide = function(){
			this.mainDiv.style.display = 'none';
			this.tabsDiv.style.display = 'none';
		}		
		this.removeTabs = function(){
			this.tabsDiv.innerHTML = '';
			this.tabs.length = 0;
			this.tabsOffset = 0;
		}
		this.addTab = function(tab){
			this.tabs.push(tab);
			tab.panel = new System.Panel({x:0,y:22,width:this.getWidth(),height:this.getHeight()-22,border:true,anchorRight:true,anchorBottom:true,backColor:this.backColor,borderTop:0},this.mainDiv);		
			tab.panel.mainDiv.style.borderTop = '';
			
			tab.buttonDiv = System.createDiv(this.tabsOffset,0,null,null,tab.width-2,21);
			this.tabsOffset += tab.width-1;
			tab.buttonDiv.style.backgroundColor = '#ff0';
			tab.buttonDiv.style.borderTop = '1px solid '+this.borderColor;
			tab.buttonDiv.style.borderLeft = '1px solid '+this.borderColor;
			tab.buttonDiv.style.borderRight = '1px solid '+this.borderColor;
			tab.buttonDiv.style.paddingTop = '3px';
			tab.buttonDiv.style.cursor = 'default';
			tab.buttonDiv.style.textAlign = 'center';
			tab.buttonDiv.innerHTML = tab.text;
			this.tabsDiv.appendChild(tab.buttonDiv);
			

			System.addEvent(tab.buttonDiv,'click',function(){
				obj.selectTab(tab);
				if (tab.onselect) tab.onselect();
			});
			
			this.selectTab(tab);
		}
		this.selectTab = function(tab){
			for (var i=0;i<this.tabs.length;i++){		
				if (this.tabs[i]!=tab){
					this.tabs[i].buttonDiv.style.backgroundColor = this.backButtonColor;
					this.tabs[i].buttonDiv.style.height = '17px';
					this.tabs[i].panel.hide();
				} else {
					this.tabs[i].buttonDiv.style.backgroundColor = this.backColor;	
					this.tabs[i].buttonDiv.style.height = '18px';
					this.tabs[i].panel.show();					
				}
			}	
		}
		this.getWidth = function(){
			return this.mainDiv.clientWidth;
		}
		this.getHeight = function(){
			return this.mainDiv.clientHeight;
		}		
		this.setPositionFromActualParameters = function(){
			this.calculatePositionParameters(); 
			System.setDiv(this.mainDiv,this.styleLeft,this.styleTop,this.styleRight,this.styleBottom,this.styleWidth,this.styleHeight);
		}
		this.calculatePositionParameters = function(){
			var parentWidth = 0;
			var parentHeight = 0;
			
			parentWidth = this.parentDiv.clientWidth;
			parentHeight = this.parentDiv.clientHeight;
				
			if ((this.anchorLeft == true)&&(this.anchorRight == false)){
				this.styleRight = null;
				this.styleLeft = this.x;
				this.styleWidth = this.width;
			}
			if ((this.anchorLeft == false)&&(this.anchorRight == true)){
				this.styleRight = parentWidth-this.x-this.width;
				this.styleWidth = this.width;
				this.styleLeft = null;
			}
			if ((this.anchorLeft == true)&&(this.anchorRight == true)){
				this.styleLeft = this.x;
				this.styleRight = parentWidth-this.x-this.width;			
				this.styleWidth = null;
			}
			
			if ((this.anchorTop == true)&&(this.anchorBottom == false)){
				this.styleTop = this.y;
				this.styleHeight = this.height;
				this.styleBottom = null;
			}		
			if ((this.anchorTop == false)&&(this.anchorBottom == true)){
				this.styleBottom = parentHeight-this.y-this.height;
				this.styleHeight = this.height;
				this.styleTop = null;
			}			
			if ((this.anchorTop == true)&&(this.anchorBottom == true)){
				this.styleTop = this.y;
				this.styleBottom = parentHeight-this.y-this.height;
				this.styleHeight = null;
			}		
		}
		this.addContextMenu = function(menu){
			System.disableContextMenu(this.mainDiv);
			System.cancelMouseUp(this.mainDiv);
			System.addEvent(this.mainDiv,'mouseup',function(e){
				if(System.isRightButtonPressed(e)==true){
					var pos = System.mouseCoordinates(e);
					menu.setParent(obj);	
					menu.show(System.systemDiv,pos[0],pos[1]);
				}
			});
			System.addGlobalEvent('mousedown',function(e){
				if(menu.opened == true){			
					menu.hide();
				}
			});

		}	
		if ((param!=null)&&((parent.formType == 'WINDOW')||(parent.formType == 'PANEL')||(parent.nodeName=='DIV'))){
			this.formType = 'TABS';	
			this.tabsOffset = 0;		
			this.tabs = new Array();
			if (parent.nodeName=='DIV')
				this.parentDiv = parent;
			else {
				if (parent.formType!=undefined){
					if (parent.formType == 'WINDOW') this.parentDiv = parent.getWorkspaceDiv();
					if (parent.formType == 'PANEL') this.parentDiv = parent.mainDiv;
				}
			}
			
			if (param.x!=null)
				this.x = param.x;
			else
				this.x = 0;
		
			if (param.y!=null)
				this.y = param.y;
			else
				this.y = 0;
		
			if (param.width!=null)
				this.width = param.width;
			else
				this.width = 100;		
    
			if (param.height!=null)
				this.height = param.height;
			else
				this.height = 100;
		
			if (param.anchorLeft!=null)
				this.anchorLeft = param.anchorLeft;
			else
				this.anchorLeft = true;
		
			if (param.anchorTop!=null)
				this.anchorTop = param.anchorTop;
			else
				this.anchorTop = true;
			
			if (param.anchorRight!=null)
				this.anchorRight = param.anchorRight;
			else
				this.anchorRight = false;	
    
			if (param.anchorBottom!=null)
				this.anchorBottom = param.anchorBottom;
			else
				this.anchorBottom = false;	
				
			if ((this.anchorBottom == false)&&(this.anchorTop == false)) this.anchorTop = true;	
			if ((this.anchorLeft == false)&&(this.anchorRight == false)) this.anchorLeft = true;	

			if (param.backColor!=null)
				this.backColor = param.backColor;
			else
				this.backColor = System.backColor;	

			this.backButtonColor = '#ddd';		
			
			if (param.borderColor!=null)
				this.borderColor = param.borderColor;
			else
				this.borderColor = '#aaa';
			
			
			this.calculatePositionParameters();
						
			if (this.border == true){			
				if (this.styleWidth!=null) this.styleWidth-=2;
				if (this.styleHeight!=null) this.styleHeight-=2;
			}
			
			this.mainDiv = System.createDiv(this.styleLeft,this.styleTop,this.styleRight,this.styleBottom,this.styleWidth,this.styleHeight);
			this.mainDiv.style.fontSize = '12px';
			this.mainDiv.style.fontFamily = 'tahoma';
			this.parentDiv.appendChild(this.mainDiv);		
		
			this.tabsDiv = System.createDiv(5,5,5,null,null,21);
			//this.tabsDiv.style.backgroundColor = '#f00';
			this.tabsDiv.style.fontSize = '11px';
			this.tabsDiv.style.fontFamily = 'tahoma';
			this.tabsDiv.style.borderBottom = '1px solid '+this.borderColor;
			//this.tabsDiv.style.overflow = 'hidden';
			this.parentDiv.appendChild(this.tabsDiv);	
			
		}	
	},
	//x,y - pozycja okna
	// width,height - wymiary okna	
	// anchorTop,anchorLeft,anchorRight,anchorBottom - kotwice (true,false);	
	//onchange
	ComboBox:function(param,parent){
		var obj = this;
		this.parent = parent;
		this.removeAll = function(){
			this.select.length = 0;
		}	
		this.addItem = function(name,value){
			this.select.options[this.select.options.length] = new Option(name,value);
			this.select.options[this.select.options.length-1].data = value;
		}
		this.getSelectedItem = function(){
			return this.selectedItem;
		}		
		this.selectItem = function(name){
			for (var i=0;i<this.select.length;i++){
				if (this.select.options[i].text == name) {
					this.select.options[i].selected = true;
					this.selectedItem =this.select.options[i];
					return;
				} 	
			}
		}
		this.selectItemByValue = function(value){
			for (var i=0;i<this.select.length;i++){
				if (this.select.options[i].data == value) {
					this.select.options[i].selected = true;
					this.selectedItem =this.select.options[i];
					return;
				} 	
			}
		}		
		this.selectItemByName = function(name){
			for (var i=0;i<this.select.length;i++){
				if (this.select.options[i].text== name) {
					this.select.options[i].selected = true;
					this.selectedItem =this.select.options[i];
					return;
				} 	
			}
		}			
		this.selectItemByIndex = function(index){
			this.select.selectedIndex = index;
			this.selectedItem =this.select.options[index];

		}	
		this.getItemByIndex = function(index){
			return this.select.options[index];
		}	
		this.hide = function(){
			this.mainDiv.style.display = 'none';
		}
		this.show = function(){
			this.mainDiv.style.display = 'block';
		}		
		this.getWidth = function(){
			return this.mainDiv.clientWidth;
		}
		this.getHeight = function(){
			return this.mainDiv.clientHeight;
		}		
		this.setPositionFromActualParameters = function(){
			this.calculatePositionParameters(); 
			System.setDiv(this.mainDiv,this.styleLeft,this.styleTop,this.styleRight,this.styleBottom,this.styleWidth,this.styleHeight);
		}
		this.calculatePositionParameters = function(){
			var parentWidth = 0;
			var parentHeight = 0;
			parentWidth = this.parentDiv.clientWidth;
			parentHeight = this.parentDiv.clientHeight;
				
			if ((this.anchorLeft == true)&&(this.anchorRight == false)){
				this.styleRight = null;
				this.styleLeft = this.x;
				this.styleWidth = this.width;
			}
			if ((this.anchorLeft == false)&&(this.anchorRight == true)){
				this.styleRight = parentWidth-this.x-this.width;
				this.styleWidth = this.width;
				this.styleLeft = null;
			}
			if ((this.anchorLeft == true)&&(this.anchorRight == true)){
				this.styleLeft = this.x;
				this.styleRight = parentWidth-this.x-this.width;			
				this.styleWidth = null;
			}
			
			if ((this.anchorTop == true)&&(this.anchorBottom == false)){
				this.styleTop = this.y;
				this.styleHeight = this.height;
				this.styleBottom = null;
			}		
			if ((this.anchorTop == false)&&(this.anchorBottom == true)){
				this.styleBottom = parentHeight-this.y-this.height;
				this.styleHeight = this.height;
				this.styleTop = null;
			}			
			if ((this.anchorTop == true)&&(this.anchorBottom == true)){
				this.styleTop = this.y;
				this.styleBottom = parentHeight-this.y-this.height;
				this.styleHeight = null;
			}		
		}
		if ((param!=null)&&((parent.formType == 'WINDOW')||(parent.formType == 'PANEL')||(parent.nodeName=='DIV'))){
			this.formType = 'PANEL';
			this.selectedItem = null;
			if (parent.nodeName=='DIV')
				this.parentDiv = parent;
			else {
				if (parent.formType!=undefined){
					if (parent.formType == 'WINDOW') this.parentDiv = parent.getWorkspaceDiv();
					if (parent.formType == 'PANEL') this.parentDiv = parent.mainDiv;
				}
			}
			
			if (param.x!=null)
				this.x = param.x;
			else
				this.x = 0;
		
			if (param.y!=null)
				this.y = param.y;
			else
				this.y = 0;
		
			if (param.width!=null)
				this.width = param.width;
			else
				this.width = 100;		
    
			if (param.height!=null)
				this.height = param.height;
			else
				this.height = 22;
		
			if (param.anchorLeft!=null)
				this.anchorLeft = param.anchorLeft;
			else
				this.anchorLeft = true;
		
			if (param.anchorTop!=null)
				this.anchorTop = param.anchorTop;
			else
				this.anchorTop = true;
			
			if (param.anchorRight!=null)
				this.anchorRight = param.anchorRight;
			else
				this.anchorRight = false;	
    
			if (param.anchorBottom!=null)
				this.anchorBottom = param.anchorBottom;
			else
				this.anchorBottom = false;	
				
			if ((this.anchorBottom == false)&&(this.anchorTop == false)) this.anchorTop = true;	
			if ((this.anchorLeft == false)&&(this.anchorRight == false)) this.anchorLeft = true;	

			this.calculatePositionParameters();
						
			if (this.border == true){			
				if (this.styleWidth!=null) this.styleWidth-=2;
				if (this.styleHeight!=null) this.styleHeight-=2;
			}
			
			this.mainDiv = System.createDiv(this.styleLeft,this.styleTop,this.styleRight,this.styleBottom,this.styleWidth,this.styleHeight);
			//this.mainDiv.style.backgroundColor = '#f00';
			this.mainDiv.style.fontSize = '12px';
			this.mainDiv.style.fontFamily = 'tahoma';

			this.parentDiv.appendChild(this.mainDiv);	

			this.select = document.createElement('select');
			this.select.style.fontSize = '12px';
			this.select.style.width = '98%';
			this.select.onchange = function(){ 
				obj.selectedItem = obj.select.options[obj.select.selectedIndex];
				if (obj.onchange) obj.onchange();
			}
			this.select.onclick = function(){ 
				if (obj.onclick) obj.onclick();
			}			
			this.mainDiv.appendChild(this.select);	
			
		}
	},
	//cells ['adas','asdad']
	//widths  '10px,23px' lub '10%,90%'
	//aligns 'left,right',..
	//check
	//oncheck
	//extended (true/false)
	//textIndex
	TreeViewItem:function(param){
		var obj = this;
		this.checked = param.checked;
		this.cells = param.cells;
		this.aligns = param.aligns;
		this.oncheck = param.oncheck;
		this.parent = null;
		this.tds = new Array();
		this.mainDiv = null;
		this.level = null;
		this.tree = null;
		this.items = new Array();
		this.hasChildren = false;
		this.widths = param.widths;
		this.aligns = param.aligns;
		this.data = null;
		
		if (param.check !=null)
			this.check = param.check;
		else	
			this.check = true;
			
		if (param.checked !=null)
			this.checkd = param.checked;
		else	
			this.checked = false;
			
		if (param.extended !=null)
			this.extended = param.extended;
		else	
			this.extended = true;
			
		if (param.showChildrenItem !=null)
			this.showChildrenItem = param.showChildrenItem;
		else	
			this.showChildrenItem = true;	
				
		if (param.textIndex != null)
			this.textIndex = param.textIndex;
		else
			this.textIndex = 0;
			
		this.unselectItems = function(){
			if (this.items.length>0){
				for (var i=0;i<this.items.length;i++){
					this.items[i].mainTextDiv.style.backgroundColor = '#fff';
					this.items[i].unselectItems();
				}
			}
		}	
		this.addItem = function(item,position){
			if (this.parent!=null){
				this.hasChildren = true;
				item.parent = this;
				item.tree = this.tree;
				item.level = this.level+1;
				this.items.push(item);
				
				item.mainDiv = document.createElement('div');
				//item.mainDiv.style.position = 'relative';
				item.mainDiv.style.paddingLeft = '16px';
			
				this.contentDiv.appendChild(item.mainDiv);
			
				var textDiv = document.createElement('div');
				//textDiv.style.position = 'relative';
				/*
				textDiv.onmouseover = function(){
					textDiv.style.backgroundColor = '#d3e8f4';				
				}
				textDiv.onmouseout = function(){
					textDiv.style.backgroundColor = '#fff';				
				}	
				*/
				item.mainDiv.appendChild(textDiv); 

				item.contentDiv = document.createElement('div');
				//item.contentDiv.style.position = 'relative';
				item.mainDiv.appendChild(item.contentDiv); 
			
				var table = document.createElement('table');	
				table.style.padding = '0px';
				table.style.fontSize = '11px';
				table.style.borderCollapse= 'collapse';
				textDiv.appendChild(table);
				item.table = table;
					
				var tBody = document.createElement('tbody');
				table.appendChild(tBody);
				//table.style.backgroundColor ='#f00';
				var tr = document.createElement('tr');
				tBody.appendChild(tr);
				
				
				var td = document.createElement('td');
				td.style.width = '0px';
				tr.appendChild(td);
				item.plusTd = td;
				
				td.onclick = function(){
					if (item.hasChildren == true){
						if (item.extended == true) item.collapse(); else item.extend();
						if (item.onextend) item.onextend(item.extended);			
					}
				}
				
				if (item.check == true){
					var td = document.createElement('td');
					td.style.width = '10px';
					tr.appendChild(td);	
					item.checkbox = document.createElement('input');
					item.checkbox.type = 'checkbox';						
					td.appendChild(item.checkbox);
					item.checkbox.checked = item.checked;
					item.checkbox.onclick = function(){
						item.checked = item.checkbox.checked;
						if (item.oncheck) item.oncheck(item.checked);
					}	
				}
				
				var w=null;
				if (item.widths!=null){
					w = item.widths.split(',');			
				}	
				var a=null;
				if (item.aligns!=null){
					a = item.aligns.split(',');			
				}	
			
				System.cancelMouseUp(item.mainDiv);
				function setSelection(div,item){
					div.onmousedown = function(){
						obj.tree.downSelectedItem = item;			
					}			
					div.onmouseup = function(e){
						if (obj.tree.downSelectedItem == item){
							obj.tree.unselectItems(); 
							div.style.backgroundColor = '#9eceff';	
							obj.tree.selectedItem = item;
						}	
						var but = 0;
						if (System.isRightButtonPressed(e)==true) but = 1;
						var pos = System.mouseCoordinates(e);
						var dpos = System.divPosition(obj.tree.workspaceDiv);	
						if (obj.tree.onmouseup) obj.tree.onmouseup(but,pos[0]-dpos[0],pos[1]-dpos[1]);		
					}				
				}
				
				for (var i = 0;	i<item.cells.length;i++){			
					var td = document.createElement('td');
					td.style.padding = '1px';
					if ((w!=null)&&(w[i])) td.style.width = w[i];
					if ((a!=null)&&(a[i])) td.style.textAlign = a[i]; else td.style.textAlign = 'left';
					tr.appendChild(td);
					if (i==item.textIndex){
						var div = document.createElement("div");
						div.style.display = 'inline';
						div.style.padding = '1px 2px 1px 2px';
						div.innerHTML = item.cells[i];
						td.appendChild(div);
						item.mainTextDiv = div;
						setSelection(div,item);
					} else td.innerHTML = item.cells[i];
					item.tds.push(td);
				}
				
				if ((item.extended == false)){
					item.contentDiv.style.display = 'none';					
				}	
				
				if (this.extended==true)
					this.setPlusState(2);
				else
					this.setPlusState(1);
				
				item.checkParentItems();
				this.checkParentItems();
				
				return item;				
			} else alert('Najpierw dodaj dany wezel.');
			return null;
		}
		this.getCheckedItems = function(){
			var tab = new Array();
			for (var i=0;i<this.items.length;i++){
				if (this.items[i].checked) tab.push(this.items[i]);
			}
			return tab;		
		}
		this.extend = function(){
			this.extended = true;
			this.contentDiv.style.display = 'block';		
			this.setPlusState(2);
		}
		this.collapse = function(){
			this.extended = false;
			this.contentDiv.style.display = 'none';		
			this.setPlusState(1);			
		}		
		this.setPlusState = function(state){
			if (state == 0){
				this.plusTd.innerHTML ='';			
			} else {
				if (state == 1){
					this.plusTd.innerHTML = '<img src="'+System.folderPath+'plusik1.png"/>';	
				} else {
					this.plusTd.innerHTML = '<img src="'+System.folderPath+'plusikr1.png"/>';		
				}				
				this.plusTd.backgroundRepeat = 'no-repeat';
				this.plusTd.backgroundPosition ='center center';	
			}	
		}
		this.getElement = function(index){
			if (this.tds[index])
			return this.tds[index];
			else
			return null;
		}
		this.setTextColor = function(color){
			this.table.style.color = color;
		}
		this.checkParentItems = function(){
			var list = this.parent.items;	
			//alert(this.cells[0]+' '+list.length);	
			var has = false;
			for (var i=0;i<list.length;i++)
				if (list[i].hasChildren == true) has = true;
			if (has==true){
				for (var i=0;i<list.length;i++)
					list[i].plusTd.style.width ='10px';	
			}else {
				for (var i=0;i<list.length;i++)
					list[i].plusTd.style.width ='1px';	
			}			
		}
		this.setCheck = function(state){
			this.checkbox.checked = state;
			this.checked = state;
		}
	},
	//x,y - pozycja okna
	// width,height - wymiary okna	
	// anchorTop,anchorLeft,anchorRight,anchorBottom - kotwice (true,false);	
	//backColor
	// border - kolor
	//canmove
	TreeView:function(param,parent){
		var obj = this;
		this.parent = parent;
		this.unselectItems = function(){
			this.selectedItem = null;
			for (var i=0;i<this.items.length;i++){
				this.items[i].mainTextDiv.style.backgroundColor = '#fff';
				this.items[i].unselectItems();
			}
		}
		this.addItem = function(item,position){
			this.hasChildren = true;
			item.parent = this;
			item.tree = this;
			item.level = 0;
			this.items.push(item);
			item.mainDiv = document.createElement('div');
			item.mainDiv.style.position = 'relative';			
			this.workspaceDiv.appendChild(item.mainDiv);
			
			var textDiv = document.createElement('div');
			//textDiv.style.position = 'relative';
			/*
			textDiv.onmouseover = function(){
				textDiv.style.backgroundColor = '#d3e8f4';				
			}
			textDiv.onmouseout = function(){
				textDiv.style.backgroundColor = 'transparent';				
			}			
			*/
			item.mainDiv.appendChild(textDiv); 

			item.contentDiv = document.createElement('div');
			item.contentDiv.style.position = 'relative';
			item.mainDiv.appendChild(item.contentDiv); 
			
			var table = document.createElement('table');
			table.style.padding = '1px';
			table.style.fontSize = '11px';
			table.style.borderCollapse= 'collapse';
			textDiv.appendChild(table);
			item.table = table;		
			
			var tBody = document.createElement('tbody');
			table.appendChild(tBody);
				
			var tr = document.createElement('tr');
			tBody.appendChild(tr);
				
	
			var td = document.createElement('td');
			td.style.width = '0px';
			item.plusTd = td;
			tr.appendChild(td);
			td.onclick = function(){
				if (item.hasChildren == true){
					if (item.extended == true) item.collapse(); else item.extend();
					if (item.onextend) item.onextend( item.extended);
				}
			}	
			if (item.check == true){
				var td = document.createElement('td');
				td.style.width = '10px';
				tr.appendChild(td);	
				item.checkbox = document.createElement('input');
				item.checkbox.type = 'checkbox';	
				td.appendChild(item.checkbox);
				item.checkbox.checked = item.checked;
				item.checkbox.onclick = function(){
					item.checked = item.checkbox.checked;
					if (item.oncheck) item.oncheck(item.checked);
				}	
			}
			
			var w=null;
			if (item.widths!=null){
				w = item.widths.split(',');			
			}	
			var a=null;
			if (item.aligns!=null){
				a = item.aligns.split(',');			
			}	
			
			System.cancelMouseUp(item.mainDiv);
			function setSelection(div,item){
				
				div.onmousedown = function(){
					obj.downSelectedItem = item;			
				}			
				div.onmouseout = function(){
					if (obj.downSelectedItem == item){
						//item.mainDiv.style.display = 'none';
						obj.unselectItems(); 
						div.style.backgroundColor = '#9eceff';	
						obj.selectedItem = item;
						if (obj.canmove==true){
							obj.dragged = item;
							if (obj.onstartchangeposition) {
								obj.onstartchangeposition();
							}
						}	
					}
					item.mainDiv.style.borderTop = 'none';
				}
				div.onmouseup = function(e){
					if (obj.downSelectedItem == item){
						obj.unselectItems(); 
						div.style.backgroundColor = '#9eceff';	
						obj.selectedItem = item;
						obj.dragged = null;
					} else
					if (obj.dragged!=null){
						if (obj.onendchangeposition) {
							var drg = obj.dragged;
							obj.dragged = null;		
							
							obj.onendchangeposition(function(ok){	
								if (ok==true){
									obj.workspaceDiv.insertBefore(drg.mainDiv,item.mainDiv);
									if (obj.onchangeposition) obj.onchangeposition(drg,item);					
								} 	
							});
						} else {
							var drg = obj.dragged;
							obj.dragged = null;								
							obj.workspaceDiv.insertBefore(drg.mainDiv,item.mainDiv);
							if (obj.onchangeposition) obj.onchangeposition(drg,item);
						}
					}
					obj.downSelectedItem = 	null;	
					var but = 0;
					if (System.isRightButtonPressed(e)==true) but = 1;
					var pos = System.mouseCoordinates(e);
					var dpos = System.divPosition(obj.workspaceDiv);	
					if (obj.onmouseup) obj.onmouseup(but,pos[0]-dpos[0],pos[1]-dpos[1]);	
				}		
				div.onmousemove = function(){
					if (obj.dragged!=null){
						item.mainDiv.style.borderTop = '2px solid #bcf';
					}		
				}					
			}
			
			for (var i = 0;	i<item.cells.length;i++){			
				var td = document.createElement('td');
				td.style.padding = '1px';
				if ((w!=null)&&(w[i])) td.style.width = w[i];
				if ((a!=null)&&(a[i])) td.style.textAlign = a[i]; else td.style.textAlign = 'left';
				tr.appendChild(td);
				if (i==item.textIndex){
					var div = document.createElement("div");
					div.style.display = 'inline';
					div.style.padding = '1px 2px 1px 2px';
					div.innerHTML = item.cells[i];
					td.appendChild(div);
					item.mainTextDiv = div;
					setSelection(div,item);
				} else td.innerHTML = item.cells[i];
				item.tds.push(td);
			}
			
			if ((item.extended == false)){
				item.contentDiv.style.display = 'none';					
			}	
			item.checkParentItems();
			return item;
		}
		this.removeAll = function(){
			this.items.length = 0;
			this.workspaceDiv.innerHTML = '';
			this.selectedItem = null;
		}
		this.getCheckedItems = function(){
			var tab = new Array();
			for (var i=0;i<this.items.length;i++){
				if (this.items[i].checked) tab.push(this.items[i]);
			}
			return tab;		
		}
		this.calculatePositionParameters = function(){
			var parentWidth = 0;
			var parentHeight = 0;
			
			parentWidth = this.parentDiv.clientWidth;
			parentHeight = this.parentDiv.clientHeight;
				
			if ((this.anchorLeft == true)&&(this.anchorRight == false)){
				this.styleRight = null;
				this.styleLeft = this.x;
				this.styleWidth = this.width;
			}
			if ((this.anchorLeft == false)&&(this.anchorRight == true)){
				this.styleRight = parentWidth-this.x-this.width;
				this.styleWidth = this.width;
				this.styleLeft = null;
			}
			if ((this.anchorLeft == true)&&(this.anchorRight == true)){
				this.styleLeft = this.x;
				this.styleRight = parentWidth-this.x-this.width;			
				this.styleWidth = null;
			}
			
			if ((this.anchorTop == true)&&(this.anchorBottom == false)){
				this.styleTop = this.y;
				this.styleHeight = this.height;
				this.styleBottom = null;
			}		
			if ((this.anchorTop == false)&&(this.anchorBottom == true)){
				this.styleBottom = parentHeight-this.y-this.height;
				this.styleHeight = this.height;
				this.styleTop = null;
			}			
			if ((this.anchorTop == true)&&(this.anchorBottom == true)){
				this.styleTop = this.y;
				this.styleBottom = parentHeight-this.y-this.height;
				this.styleHeight = null;
			}		
		}		
		if ((param!=null)&&((parent.formType == 'WINDOW')||(parent.formType == 'PANEL'))){
			this.items = new Array();
			this.dragged = null;
			this.selectdItem = null;
			if (parent.formType!=undefined){
				if (parent.formType == 'WINDOW') this.parentDiv = parent.getWorkspaceDiv();
				if (parent.formType == 'PANEL') this.parentDiv = parent.mainDiv;
			}
			
			if (param.x!=null)
				this.x = param.x;
			else
				this.x = 0;
		
			if (param.y!=null)
				this.y = param.y;
			else
				this.y = 0;
			
			if (param.width!=null)
				this.width = param.width;
			else
				this.width = 100;		
    
			if (param.height!=null)
				this.height = param.height;
			else
				this.height = 100;
		
			if (param.anchorLeft!=null)
				this.anchorLeft = param.anchorLeft;
			else
				this.anchorLeft = true;
					
			if (param.anchorTop!=null)
				this.anchorTop = param.anchorTop;
			else
				this.anchorTop = true;
			
			if (param.anchorRight!=null)
				this.anchorRight = param.anchorRight;
			else
				this.anchorRight = false;	
    
			if (param.anchorBottom!=null)
				this.anchorBottom = param.anchorBottom;
			else
				this.anchorBottom = false;	
			
			if ((this.anchorBottom == false)&&(this.anchorTop == false)) this.anchorTop = true;	
			if ((this.anchorLeft == false)&&(this.anchorRight == false)) this.anchorLeft = true;	
			
			if (param.border!=null)
				this.border = param.border;
			else
				this.border = '#aaa';	
					
			if (param.backColor!=null)
				this.backColor = param.backColor;
			else
				this.backColor = '#fefefe';	
				
			if (param.check!=null)
				this.check = param.check;
			else
				this.check = true;	

			if (param.canmove!=null)
				this.canmove = param.canmove;
			else
				this.canmove = false;	
				
			this.calculatePositionParameters();
			this.mainDiv = System.createDiv(this.styleLeft,this.styleTop,this.styleRight,this.styleBottom,this.styleWidth,this.styleHeight);
			this.mainDiv.style.backgroundColor = this.border; 
			this.mainDiv.style.fontSize = '11px';
			this.mainDiv.style.fontFamily = 'tahoma';
			System.disableSelection(this.mainDiv);
			this.parentDiv.appendChild(this.mainDiv);
			
			this.workspaceDiv = System.createDiv(1,1,1,1,null,null);
			this.workspaceDiv.style.backgroundColor = this.backColor;
			this.workspaceDiv.style.overflow = 'auto';
			this.mainDiv.appendChild(this.workspaceDiv);
			System.addEvent(this.workspaceDiv,'mouseup',function(e){
				obj.unselectItems();
				var but = 0;
				if (System.isRightButtonPressed(e)==true) but = 1;
				var pos = System.mouseCoordinates(e);
				var dpos = System.divPosition(obj.workspaceDiv);	
				if (obj.onmouseup) obj.onmouseup(but,pos[0]-dpos[0],pos[1]-dpos[1]);	
			});
			System.disableContextMenu(this.mainDiv);
			
			
						
		}	
	}	
}

WMS={
	createGetFeatureInfoRequest:function(url,version,layers,box,width,height,projection,x,y){
		var adress = url;
		var num = url.lastIndexOf("?");
        var num2 = url.lastIndexOf("&");
		var znak='';
		if (num==url.length){}
		else if (num2==url.length){}
		else{
         if ((num==-1) &&(num2==-1)) znak = '?';
         if (num!=-1) znak='&';
		}

		adress+=znak;
		adress+="VERSION=1.1.1&SERVICE=WMS&REQUEST=GetFeatureInfo&INFO_FORMAT=text/html";
		adress+="&LAYERS="+layers;
		adress+="&QUERY_LAYERS="+layers;
		adress+="&SRS="+projection+"&FORMAT=image/png";

		adress+="&BBOX="+box.xmin+","+box.ymin+","+box.xmax+","+box.ymax;

		adress+="&WIDTH="+width;
		adress+="&HEIGHT="+height;
		adress+="&X="+x+"&Y="+y;
		var przecinkiLayers='';
		for (var i=0;i<layers.split(",").length-1;i++) przecinkiLayers+=',';
		adress+="&styles="+przecinkiLayers;

		return adress;
	}
}


MyMath = {
	PointPolyRelation:{
		Vertex:1,
		Edge:2,
		Outside:3,
		Inside:4
	},
	length:function(x1,y1,x2,y2){
		var dx = x1 - x2;
		var dy = y1 - y2;
		return Math.sqrt(dx*dx+dy*dy);
	},
	distanceFromPointToLine:function(x1,y1,x2,y2,x,y){
        var A = x - x1;
        var B = y - y1;
        var C = x2 - x1;
        var D = y2 - y1;

        var dot = A * C + B * D;
        var len_sq = C * C + D * D;
        var param = dot / len_sq;

        var xx, yy;

        if (param < 0)
        {
            xx = x1;
            yy = y1;
        }
        else if (param > 1)
        {
            xx = x2;
            yy = y2;
        }
        else
        {
            xx = x1 + param * C;
            yy = y1 + param * D;
        }

        return this.length(x, y, xx, yy);	
	},
	isPointOnLine:function(a,b,x,y,buffor){
        var czy = false;
        var minX = a.x, minY = a.y, maxX = a.x, maxY = a.y;

        if (b.x < minX) minX = b.x;
        if (b.x > maxX) maxX = b.x;
        if (b.y < minY) minY = b.y;
        if (b.y > maxY) maxY = b.y;

        if ((x > minX - buffor) && (x < maxX + buffor) && (y > minY - buffor) && (y < maxY + buffor)) czy = true;
        if (czy == true)
        {
            if (this.distanceFromPointToLine(a.x, a.y, b.x, b.y, x, y) < buffor) czy = true; else czy = false;
        }
        return czy;	
	
	},
	isPointInPoly:function(poly,x,y,precision){
        var i, j, nCrossCnt, i1;
        var iXP, iYP, iX0, iX1, iY0, iY1, iXA, iYA = 0;
        var nNoVert = poly.length;
        nCrossCnt = 0;
        iXP = x;
        iYP = y;
        var iPrec = precision;

        for (i = 0; i < nNoVert; i++){
            /* indeksy kolejnych wierzchołków w tablicy */
            i1 = (i + 1) % nNoVert;
            iX0 = poly[i].x;
            iX1 = poly[i1].x;
            iY0 = poly[i].y;
            iY1 = poly[i1].y;
            Math.abs(iY0 - iYP);
            /* czy punkt pokrywa się z wierzchołkiem struktury */
            if (Math.abs(iX0 - iXP) < iPrec && Math.abs(iY0 - iYP) < iPrec)
                return MyMath.PointPolyRelation.Vertex;
            if (Math.abs(iX1 - iXP) < iPrec && Math.abs(iY1 - iYP) < iPrec)
                return MyMath.PointPolyRelation.Vertex;
            if (iY0 == iY1)
            {  /* czy punkt leży na boku */
                if ((Math.abs(iY0 - iYP) < iPrec) &&
                    ((iX0 < iXP && iXP < iX1) || (iX1 < iXP && iXP < iX0)))
                    return MyMath.PointPolyRelation.Edge;
            }
            else
            {
                if ((iY0 < iYP && iYP < iY1) || (iY1 < iYP && iYP < iY0))
                {
                    iXA = iX0 + ((iYP - iY0) * (iX1 - iX0) / (iY1 - iY0));
                    if (Math.abs(iXA - iXP) < iPrec)
                        return MyMath.PointPolyRelation.Edge;
                    if (iXA > iXP)
                        nCrossCnt++;
                }
                else
                    if (iY1 == iYP && iX1 > iXP)
                    {             /* koniec odcinka na półprostej,
                poczštek poza prostš */
                        for (j = 1; j < nNoVert; j++)
                        {
                            iYA = poly[(i1 + j) % nNoVert].y;
                            if (iYA != iYP)
                                break;
                        }
                        if (j == nNoVert)
                            return MyMath.PointPolyRelation.Outside;
                        if ((iYA < iYP && iYP < iY0) || (iYA > iYP && iYP > iY0))
                            nCrossCnt++;
                    }
            }
        }
        if ((nCrossCnt % 2) != 0)
            return MyMath.PointPolyRelation.Inside; /* nieparzysta liczba przecięć
           - punkt leży wewnštrz */
        else
            return MyMath.PointPolyRelation.Outside; /* parzysta - na zewnštrz */
    },
	azymuth:function(dx,dy){
		var kat = Math.atan2(dy,dx);
		if (kat<0) kat+=2*3.14159;
		return kat;
	}
}

var wielkiOdliczacz = 0;

iGML = {
	actualMap : null,	
	Point:function(x,y){
		this.x = x;
		this.y = y;
		this.createFromXml = function(xml){
			this.x = parseFloat(xml.getAttribute('x'));
			this.y = parseFloat(xml.getAttribute('y'));			
		}	
		this.isPointOver = function(x,y){
			var dx=Math.abs(x-this.x);
			var dy=Math.abs(y-this.y);
			if ((dx<5)&&(dy<5)) return true;
			return false;
		}	
		
	},
	Box:function(xmin,ymin,xmax,ymax){
		this.xmin = xmin;
		this.ymin = ymin;
		this.xmax = xmax;
		this.ymax = ymax;
		this.createFromXml = function(xml){
			this.xmin = parseFloat(xml.getAttribute('xmin'));
			this.ymin = parseFloat(xml.getAttribute('ymin'));
			this.xmax = parseFloat(xml.getAttribute('xmax'));
			this.ymax = parseFloat(xml.getAttribute('ymax'));		
		}
		this.toString = function(){
			return this.xmin+' '+this.ymin+' '+this.xmax+' '+this.ymax;
		}
		this.isPointIn = function(point){
			if ((point.x>=this.xmin)&&(point.x<=this.xmax)&&(point.y>=this.ymin)&&(point.y<=this.ymax)) return true;
			return false;
		}
		this.isInside = function(box){
			if ((this.xmin>box.xmax)||(this.xmax<box.xmin)||(this.ymin>box.ymax)||(this.ymax<box.ymin)) return false;
			return true;
		}
	},
	Utils:{
		PointsFromEWKT:function(text){
			var index = text.indexOf('POLYGON');
			var points = new Array();
			if (index!=-1){
				var w = text.substring(index+9,text.length-2).split(',');
				for (var i=0;i<w.length;i++){
					var c = w[i].split(' ');
					points[i]={x:parseFloat(c[0]),y:parseFloat(c[1])};
				}
			}
			return points;
		}	
	},
	Overlays:{
		PointStyle:function(param){
			if (param!=null){
				//image - adres obrazka
				//width - szeroksc obrazka
				//height - wysokosc obrazka
				//xCenter - wspólrzedna x srodka
				//yCenter - wspólrzedna y srodka
				this.image = param.image;
				this.width = param.width;
				this.height = param.height;
				this.xCenter = param.xCenter;
				this.yCenter = param.yCenter;
				
			}
		},
		Point:function(x,y,style){
			this.type = 0;
			this.coord = new iGML.Point(x,y);
			this.scCoord = new iGML.Point(0,0);
			this.canRotate = false;
			this.visible = true;
			this.userVisible = true;
			this.style = style;
			this.map = null;
			this.marked = false;
			this.rObject = null;
			this.onclick = null;
			this.angle = 0;
			//funkcje//
			this.onchangeposition = null;
			////////
			this.rotate = function(angle){
				this.angle = angle;
				if ((this.map!=null)&&(this.canRotate==true)){					
					this.map.rotateOverlay(this,angle);
				}
			}
			this.setSymbolAngle = function(angle){
				this.rObject.attr("rotation",angle*57.29578);
			}
			this.setCanRotate = function(value){
				this.canRotate = value;
			}
			this.setVisibility = function(visible){
				this.userVisible = visible;
			}
			this.show = function(){
				this.visible = true;
				this.rObject.show();
			}
			this.hide = function(){
				this.visible = false;
				this.rObject.hide();
			}			
			this.isPointOver = function(x,y){
				var dx=Math.abs(x-this.scCoord.x);
				var dy=Math.abs(y-this.scCoord.y);
				if ((dx<5)&&(dy<5)) return true;
				return false;
			}
			this.mark = function(){
				this.rObject.attr("scale",1.2);
				this.marked = true;
			}
			this.unmark = function(){
				this.rObject.attr("scale",1.0);
				this.marked = false;
			}			
			this.asText = function(){
				return this.coord.x+' '+this.coord.y;
			}
		},
		Line:function(points,style){
			this.type = 1;
			this.points = null;
			this.scPoints  = new Array();
			this.visible = true;
			this.userVisible = true;
			this.boundingBox = new iGML.Box(-999999999,-999999999,999999999,999999999);
			this.map = null;
			this.marked = false;
			this.rObject = null;
			this.onclick = null;	
			
			if (points!=null){
				this.points = points;
				if (style!=null)
					this.style = style;
				else
					this.style = {};
				
				if (!this.style.width) this.style.width = 1;
				if (!this.style.color) this.style.color = '#000';
				if (!this.style.opacity) this.style.opacity = 1;
			}
			this.insertPoint = function(x,y,index){
				var tab = new Array();
				for (var i=0;i<index;i++){
					tab[i] = this.points[i];
				}
				tab[index] = {x:x,y:y};
				for (var i=index;i<this.points.length;i++){
					tab[i+1] = this.points[i];
				}
				this.points = tab;
			}
			this.calculateBox = function(){
				var xmin = 0;
				var ymin = 0;
				var xmax = 0;
				var ymax = 0;				
				if (this.points.length>0){
					xmin = this.points[0].x;
					ymin = this.points[0].y;
					xmax = this.points[0].x;
					ymax = this.points[0].y;
				}
				
				for (var i=0;i<this.points.length;i++){
					var p = this.points[i];
					if (p.x<xmin) xmin = p.x;
					if (p.y<ymin) ymin = p.y;
					if (p.x>xmax) xmax = p.x;
					if (p.y>ymax) ymax = p.y;					
				}
				this.boundingBox.xmin = xmin;
				this.boundingBox.ymin = ymin;
				this.boundingBox.xmax = xmax;
				this.boundingBox.ymax = ymax;			
			}
			this.isPointOver = function(x,y){
				for (var j=0;j<this.scPoints.length-1;j++){
					if (MyMath.isPointOnLine(this.scPoints[j],this.scPoints[j+1],x,y,3)==true) return true;
				}
				return false;
			}
			this.isPointOverSegment = function(x,y){
				for (var j=0;j<this.scPoints.length-1;j++){
					if (MyMath.isPointOnLine(this.scPoints[j],this.scPoints[j+1],x,y,3)==true) return j;
				}
				return -1;
			}			
			this.isPointOverPoint = function(x,y){
				for (var i=0;i<this.scPoints.length;i++){
					var dx=Math.abs(x-this.scPoints[i].x);
					var dy=Math.abs(y-this.scPoints[i].y);
					if ((dx<5)&&(dy<5)) return i;
				}
				return -1;
			}
			this.mark = function(){
				this.rObject.attr("stroke-width",this.style.width*1.5);
				this.marked = true;
			}
			this.unmark = function(){
				this.rObject.attr("stroke-width",this.style.width);
				this.marked = false;
			}
			this.show = function(){
				this.visible = true;
				this.rObject.show();
			}
			this.hide = function(){
				this.visible = false;
				this.rObject.hide();
			}			
			this.asText = function(){
				var g = new Array();
				for (var i=0;i<this.points.length;i++)
				g.push(this.points[i].x+' '+this.points[i].y);
				
				return g.join(',');
			}
		},
		Polygon:function(points,style){
			this.type = 2;
			this.points = null;
			this.scPoints  = new Array();
			this.visible = true;
			this.userVisible = true;
			this.boundingBox = new iGML.Box(-999999999,-999999999,999999999,999999999);
			this.map = null;
			this.marked = false;
			this.rObject = null;
			this.onclick = null;	
			this.closed = false;
			this.calculateBox = function(){
				var xmin = 0;
				var ymin = 0;
				var xmax = 0;
				var ymax = 0;				
				if (this.points.length>0){
					xmin = this.points[0].x;
					ymin = this.points[0].y;
					xmax = this.points[0].x;
					ymax = this.points[0].y;
				}
				
				for (var i=0;i<this.points.length;i++){
					var p = this.points[i];
					if (p.x<xmin) xmin = p.x;
					if (p.y<ymin) ymin = p.y;
					if (p.x>xmax) xmax = p.x;
					if (p.y>ymax) ymax = p.y;					
				}
				this.boundingBox.xmin = xmin;
				this.boundingBox.ymin = ymin;
				this.boundingBox.xmax = xmax;
				this.boundingBox.ymax = ymax;
				
				this.closed = false;
				if (this.points.length>3)
				if ((this.points[0].x==this.points[this.points.length-1].x)&&(this.points[0].y==this.points[this.points.length-1].y))
				this.closed = true;
				
								
			}
			this.insertPoint = function(x,y,index){
				var tab = new Array();
				for (var i=0;i<index;i++){
					tab[i] = this.points[i];
				}
				tab[index] = {x:x,y:y};
				for (var i=index;i<this.points.length;i++){
					tab[i+1] = this.points[i];
				}
				this.points = tab;
			}			
			this.isPointOver = function(x,y){
				if (MyMath.isPointInPoly(this.scPoints,x,y,0.1)==4) return true;
				return false;
			}
			this.isPointOverSegment = function(x,y){
				for (var j=0;j<this.scPoints.length-1;j++){
					if (MyMath.isPointOnLine(this.scPoints[j],this.scPoints[j+1],x,y,3)==true) return j;
				}
				return -1;
			}			
			this.isPointOverPoint = function(x,y){
				for (var i=0;i<this.scPoints.length;i++){
					var dx=Math.abs(x-this.scPoints[i].x);
					var dy=Math.abs(y-this.scPoints[i].y);
					if ((dx<5)&&(dy<5)) return i;
				}
				return -1;
			}			
			this.mark = function(){
				this.rObject.attr("fill-opacity",this.style.fillOpacity*0.7);
				this.marked = true;
			}
			this.unmark = function(){
				this.rObject.attr("fill-opacity",this.style.fillOpacity);
				this.marked = false;
			}
			this.show = function(){
				this.visible = true;
				this.rObject.show();
			}
			this.hide = function(){
				this.visible = false;
				this.rObject.hide();
			}				
			this.asText = function(){
				var g = new Array();
				for (var i=0;i<this.points.length;i++)
				g.push(this.points[i].x+' '+this.points[i].y);
				
				return g.join(',');
			}
			if (points!=null){
				this.points = points;
				if (style!=null)
					this.style = style;
				else
					this.style = {};
				
				if (!this.style.lineWidth) this.style.lineWidth = 0;
				if (!this.style.lineColor) this.style.lineColor = '#000';
				
				if (!this.style.lineOpacity) {
					if (this.style.lineWidth==0)
					this.style.lineOpacity = 0;
					else
					this.style.lineOpacity = 1;
				}	
				if (!this.style.fillColor) this.style.fillColor = '#f00';
				if (!this.style.fillOpacity) this.style.fillOpacity = 0.5;	
				this.calculateBox();		
			}
		}		
		
	},
	WMSLayer : function(param){
		if (param!=null){
			param.name == null?this.name='':this.name = param.name;
			param.title == null?this.title='':this.title = param.title;
			param.queryable == null?this.queryable=false:this.queryable = param.queryable;
			param.checked == null?this.checked=true:this.checked = param.checked;
		}
		this.createFromXml = function(xml){
			if (xml.getAttribute('name')) this.name = xml.getAttribute('name');
			if (xml.getAttribute('title')) this.title = xml.getAttribute('title');
			if (xml.getAttribute('queryable')) this.queryable = System.strToBool(xml.getAttribute('queryable'));
			if (xml.getAttribute('checked')) this.checked = System.strToBool(xml.getAttribute('checked'));
		}
	},
	WMSService : function(param,layers){
		if (param!=null){
			param.id == null?this.id=null:this.id = param.id;
			param.name == null?this.name='':this.name = param.name;
			param.url == null?this.url='':this.url = param.url;
			param.version == null?this.version='1.1.1':this.version = param.version;	
			param.format == null?this.format='image/png':this.format = param.format;
			param.checked == null?this.checked=true:this.checked = param.checked;	
			param.expandable ==null?this.expandable=true:this.expandable = param.expandable;	
			param.expanded ==null?this.expanded=true:this.expanded = param.expanded;	
			param.boundingBox==null?this.boundingBox = new iGML.Box(0,0,0,0):this.boundingBox = param.boundingBox;
			param.visibleFrom == null?this.visibleFrom=0:this.visibleFrom = param.visibleFrom;
			param.visibleTo == null?this.visibleTo=9999999:this.visibleTo = param.visibleTo;
			layers==null?this.layers = new Array():this.layers = layers;
			param.secret ==null?this.secret=false:this.secret = param.secret;	
			this.serviceType = 'WMS';
		}
		this.createFromXml = function(xml){
		
			if (xml.getAttribute('name')) this.name = xml.getAttribute('name'); 
			if (xml.getAttribute('url')) this.url = xml.getAttribute('url').replace('[and]','&');
			if (xml.getAttribute('version')) this.version = xml.getAttribute('version');
			if (xml.getAttribute('format')) this.format = xml.getAttribute('format');
			if (xml.getAttribute('id')) this.id = xml.getAttribute('id');
			
			if (xml.getAttribute('expandable')) this.expandable = System.strToBool(xml.getAttribute('expandable'));
			if (xml.getAttribute('expanded')) this.expanded = System.strToBool(xml.getAttribute('expanded'));			
			if (xml.getAttribute('checked')) this.checked = System.strToBool(xml.getAttribute('checked'));
			if (xml.getAttribute('secret')) this.secret = System.strToBool(xml.getAttribute('secret'));			
			
			if (xml.getAttribute('visibleFrom')) this.visibleFrom = parseFloat(xml.getAttribute('visibleFrom'));
			if (xml.getAttribute('visibleTo')) this.visibleTo = parseFloat(xml.getAttribute('visibleTo'));	

			var boxes = xml.getElementsByTagName('BoundingBox');
			if (boxes.length>0) this.boundingBox.createFromXml(boxes[0]);
			
			this.layers = new Array();
			var layers = xml.getElementsByTagName('Layer');
			for (var i=0;i<layers.length;i++) {
				var layer = new iGML.WMSLayer({});
				layer.createFromXml(layers[i]);
				this.layers.push(layer);			
			}
		}	
		this.getCheckedLayersList = function(){
			var layers = new Array();
			for (var i=0;i<this.layers.length;i++){
				var l = this.layers[i];
				if (l.checked==true){
					layers.push(l.name);
				}
			}
			return layers.join(',');
		}
		this.isVisible = function(box,scale){
			var is = true;
			if (this.checked == false) is = false;
			if (is==true){
				if ((scale<this.visibleFrom) || (scale>this.visibleTo))	is = false;
				if (is==true){
					if (this.boundingBox.isInside(box)==false) is=false;
					if (is==true){
						var layers = this.getCheckedLayersList();
						if (layers=='') is = false;
					}
				}
			}
			return is;
		}
		this.getMapRequest = function(box,crs,width,height){
			var layers = this.getCheckedLayersList();	
			if (layers!=''){
				var adress = this.url;
				var num = this.url.lastIndexOf("?");
                var num2 = this.url.lastIndexOf("&");
				var znak='';
				if (num==this.url.length){}
				else if (num2==this.url.length){}
				else{
                 if ((num==-1) &&(num2==-1)) znak = '?';
                 if (num!=-1) znak='&';
				}
    
				adress+=znak;
				adress+="VERSION="+this.version+"&SERVICE=WMS&REQUEST=GetMap";
				adress+="&LAYERS="+layers;
    
				adress+="&SRS="+crs;
    
				adress+="&BBOX="+box.xmin+","+box.ymin+","+box.xmax+","+box.ymax;
    
				adress+="&WIDTH="+width;
				adress+="&HEIGHT="+height;
				if (this.format!='image/jpeg')
				adress+="&TRANSPARENT=TRUE";
				else
				adress+="&TRANSPARENT=FALSE";
				adress+="&FORMAT="+this.format;
				var przecinkiLayers='';
				for (var i=0;i<layers.split(",").length-1;i++) przecinkiLayers+=',';
				adress+="&styles="+przecinkiLayers+'&unique='+Math.round(Math.random()*10000);

				return adress;
			} else {
				return null;	
			}				
		}
		this.getFeatureInfoRequest = function(x,y,box,crs,width,height){
			var layers = '';
			for (var i=0;i<this.layers.length;i++){
				if ((this.layers[i].queryable==true)&&(this.layers[i].checked==true)) layers+=this.layers[i].name+',';
			}
			if (layers!='') layers = layers.substring(0,layers.length-1);
			return WMS.createGetFeatureInfoRequest(this.url,this.version,layers,box,width,height,crs,x,y);
		}	
		this.isQueryable = function(){
			for (var i=0;i<this.layers.length;i++){
				if ((this.layers[i].queryable==true)&&(this.layers[i].checked==true)) return true;
			}							
			return false;
		}
	},
	TileService : function(param){
		if (param!=null){
			param.id == null?this.id=null:this.id = param.id;
			param.name == null?this.name='':this.name = param.name;
			param.url == null?this.url='':this.url = param.url;			
			param.checked == null?this.checked=true:this.checked = param.checked;				
			param.boundingBox==null?this.boundingBox = new iGML.Box(0,0,0,0):this.boundingBox = param.boundingBox;
			param.visibleFrom == null?this.visibleFrom=0:this.visibleFrom = param.visibleFrom;
			param.visibleTo == null?this.visibleTo=9999999:this.visibleTo = param.visibleTo;			
			param.secret ==null?this.secret=false:this.secret = param.secret;	
			param.shema ==null?this.shema='gs':this.shema = param.shema;
			param.format == null?this.format='png':this.format = param.format;
			param.level == null?this.level=0:this.level = param.level;
			param.infoUrl == null?this.infoUrl=null:this.infoUrl = param.infoUrl; 
			param.infoLayers == null?this.infoLayers='':this.infoLayers = param.infoLayers;
			param.infoVersion == null?this.infoVersion='1.1.1':this.infoVersion = param.infoVersion;
			this.serviceType = 'Tile';
		}
		this.createFromXml = function(xml){
		
			if (xml.getAttribute('name')) this.name = xml.getAttribute('name'); 
			if (xml.getAttribute('url')) this.url = xml.getAttribute('url').replace('[and]','&');
			if (xml.getAttribute('id')) this.id = xml.getAttribute('id');
			
			if (xml.getAttribute('checked')) this.checked = System.strToBool(xml.getAttribute('checked'));
			if (xml.getAttribute('shema')) this.shema = xml.getAttribute('shema');
			if (xml.getAttribute('format')) this.format = xml.getAttribute('format');			
			if (xml.getAttribute('visibleFrom')) this.visibleFrom = parseFloat(xml.getAttribute('visibleFrom'));
			if (xml.getAttribute('visibleTo')) this.visibleTo = parseFloat(xml.getAttribute('visibleTo'));	

			if (xml.getAttribute('level')) this.level = parseInt(xml.getAttribute('level'));	
			
			if (xml.getAttribute('info_url')) this.infoUrl = xml.getAttribute('info_url');		
			if (xml.getAttribute('info_layers')) this.infoLayers = xml.getAttribute('info_layers');
			if (xml.getAttribute('info_version')) this.infoVersion = xml.getAttribute('info_version');			
			
			var boxes = xml.getElementsByTagName('BoundingBox');
			if (boxes.length>0) this.boundingBox.createFromXml(boxes[0]);			
		}	
		this.isVisible = function(box,scale){
			var is = true;
			if (this.checked == false) is = false;
			if (is==true){
				if ((scale<this.visibleFrom) || (scale>this.visibleTo))	is = false;
				if (is==true){
					if (this.boundingBox.isInside(box)==false) is=false;					
				}
			}
			return is;
		}		
		this.getTileRequest = function(l,x,y){

				var adress = this.url;
				var num = this.url.lastIndexOf("?");
                var num2 = this.url.lastIndexOf("&");
				var znak='';
				if (num==this.url.length){}
				else if (num2==this.url.length){}
				else{
                 if ((num==-1) &&(num2==-1)) znak = '?';
                 if (num!=-1) znak='&';
				}
    
				adress+=znak;
				if (this.shema == 'gs'){
					adress+="L="+l+"&X="+x+"&Y="+y;						
				}
				if (this.shema == 'gp'){	
					if ((l-this.level)<0) return null;
					adress+="fileIDX=L"+(l-this.level)+"X"+x+"Y"+y+"."+this.format;	
				}				
			return adress;	
		}	
		this.isQueryable = function(){
			if ((this.infoVersion!=null)&&(this.infoLayers!='')) return true;
			return false;
		}	
		this.getFeatureInfoRequest = function(x,y,box,crs,width,height){
			return WMS.createGetFeatureInfoRequest(this.infoUrl,this.infoVersion,this.infoLayers,box,width,height,crs,x,y);
		}		
	},
	Map : function(divId,path){
		var obj = this;
		this.folderPath = path;
		this.initOverlays = function(){
			this.paper = Raphael(this.overlayPanel.mainDiv, this.overlayPanel.getWorkspaceWidth(), this.overlayPanel.getWorkspaceHeight());
			this.overlayPanel.mainDiv.style.overflow = 'hidden';
			this.overlays = new Array();
		}
		this.refreshOverlay = function(overlay){
			if (overlay.userVisible==true){
				if (overlay.type==0){
					if (this.box.isPointIn(overlay.coord)==true){
						if (overlay.visible==false) {
							overlay.rObject.show();
							overlay.visible=true;
						}	
						overlay.scCoord.x = obj.pX(overlay.coord.x);
						overlay.scCoord.y = obj.pY(overlay.coord.y);
						overlay.rObject.attr("x",overlay.scCoord.x-overlay.style.xCenter);
						overlay.rObject.attr("y",overlay.scCoord.y-overlay.style.yCenter);
						overlay.rObject.show();
					} else {
						if (overlay.visible==true){
							overlay.rObject.hide();
							overlay.visible=false;
						}
				
					}
				}
				if ((overlay.type==1)||(overlay.type==2)){
					if (overlay.boundingBox.isInside(obj.box)==true){
						if (overlay.visible==false) {
							overlay.rObject.show();
							overlay.visible=true;
						}				
						var path = '';
						overlay.scPoints.length = 0;
						for (var i=0;i<overlay.points.length;i++){
							overlay.scPoints[i] = new iGML.Point(obj.pX(overlay.points[i].x),obj.pY(overlay.points[i].y));				
							if (i==0) path+='M'; else path+='L';
							path+=overlay.scPoints[i].x+' '+overlay.scPoints[i].y;
						}
						overlay.rObject.attr("path",path);
						
						if (overlay.type==2){
							if (overlay.closed==true){
								overlay.rObject.attr("fill-opacity",overlay.style.fillOpacity);
							} else {
								overlay.rObject.attr("fill-opacity",0);
							}
						}
						overlay.rObject.show();
						this.drawedPolygonsCount++;
					} else {
						if (overlay.visible==true){
							overlay.rObject.hide();
							overlay.visible=false;
						}										
					}
				}				
				
				
			} else {
				if (overlay.visible==true){
					overlay.hide();
				}
			}
			
		}
		this.refreshEditingLine = function(){
			this.editLineLine.hide();
			if ((this.editedOverlay!=null)&&((this.editedOverlay.type==1)||((this.editedOverlay.type==2)))){
				if (this.action != 'edit_line_move_point'){
					if ((this.editedOverlay.points.length>0)&&(this.editLineSnap!=0)){
						var lp = {x:0,y:0};
						if (this.editLineSnap==1){		
							//lp = this.editedOverlay.scPoints[this.editedOverlay.points.length-1];
							lp = new iGML.Point(obj.pX(this.editedOverlay.points[this.editedOverlay.points.length-1].x),obj.pY(this.editedOverlay.points[this.editedOverlay.points.length-1].y));	
						}
						if (this.editLineSnap==2){		
							//lp = this.editedOverlay.scPoints[0];				
							lp = new iGML.Point(obj.pX(this.editedOverlay.points[0].x),obj.pY(this.editedOverlay.points[0].y));	
						}
						var path = 'M'+lp.x+' '+lp.y+'L';
						path+='L'+this.mouseCoordinates.x+' '+this.mouseCoordinates.y;  
						this.editLineLine.attr("path",path);		
						this.editLineLine.toFront();
						
						var show = true;
						if ((this.editedOverlay.type==2)&&(this.editedOverlay.closed==true)) show = false;	 	

						if (show==true)		
						this.editLineLine.show();
					}	
				} else {
					if ((obj.editLineSelectedPoint-1)>=0)
					var lp = this.editedOverlay.scPoints[obj.editLineSelectedPoint-1];
					else{
						var lp = this.mouseCoordinates;
						if ((this.editedOverlay.type==2)&&(this.editedOverlay.closed==true)){
							lp = this.editedOverlay.scPoints[this.editedOverlay.points.length-2];
						}
					}
					
					if ((obj.editLineSelectedPoint+1)<this.editedOverlay.scPoints.length)
					var lk = this.editedOverlay.scPoints[obj.editLineSelectedPoint+1];
					else {
						var lk = this.mouseCoordinates;
						if ((this.editedOverlay.type==2)&&(this.editedOverlay.closed==true)){
							lk = this.editedOverlay.scPoints[1];
						}
					}
					
					var path = 'M'+lp.x+' '+lp.y+'L';
					path+='L'+this.mouseCoordinates.x+' '+this.mouseCoordinates.y;  
					path += 'L'+lk.x+' '+lk.y+'';
					this.editLineLine.attr("path",path);		
					this.editLineLine.toFront();
					
					
					this.editLineLine.show();				

				}
			}			 
		}
		this.refreshEditingControls = function(){
			this.editPointLine.hide();	
			this.editPointCenter.hide();
			this.editPointRotate.hide();
			
			for (var i=0;i<this.editLinePoints.length;i++){
				this.editLinePoints[i].r.remove();
			}
			this.editLinePoints.length = 0;
			
			if (this.editedOverlay!=null){
				if (this.editedOverlay.type == 0){

					if (this.editedOverlay.visible==true){								
						if (this.editedOverlay.canRotate == true){
							var r = 50;
							var path = 'M'+this.editedOverlay.scCoord.x+' '+this.editedOverlay.scCoord.y+'L';
							var rx = this.editedOverlay.scCoord.x+Math.round(r*Math.cos(this.editedOverlay.angle));
							var ry = this.editedOverlay.scCoord.y+Math.round(r*Math.sin(this.editedOverlay.angle));
							this.editPointRotateCoord = new iGML.Point(rx,ry);
							path+=rx+' '+ry;
							//alert(path);
							this.editPointLine.attr("path",path);		
							this.editPointLine.toFront();					
							this.editPointLine.show();		
							
							this.editPointRotate.attr("cx",rx);
							this.editPointRotate.attr("cy",ry);			
							this.editPointRotate.toFront();					
							this.editPointRotate.show();							
						}		
						this.editPointCenter.attr("cx",this.editedOverlay.scCoord.x);
						this.editPointCenter.attr("cy",this.editedOverlay.scCoord.y);			
						this.editPointCenter.toFront();					
						this.editPointCenter.show();						
					} 
				}				
			
				if (((this.editedOverlay.type == 1)||(this.editedOverlay.type == 2))&&(this.editedOverlay.visible==true)){

					
					for (var i=0;i<this.editedOverlay.points.length;i++){
						var p = this.editedOverlay.scPoints[i];
						var r = this.paper.circle(p.x,p.y,4);
						r.attr('stroke-opacity',0);
						r.attr('fill','#f00');					
						
						this.editLinePoints.push({r:r,big:false});
					
					}
				}
			}
		}
		this.refreshOverlays = function(){
			for (var i=0;i<this.overlays.length;i++){
				if (this.overlays[i].visible==true)
				this.overlays[i].rObject.hide();
			}
			this.drawedPolygonsCount = 0;
			for (var i=0;i<this.overlays.length;i++){
				this.refreshOverlay(this.overlays[i]);
			}
			this.refreshEditingControls();	
			this.refreshEditingLine();			
		}
		this.rotateOverlay = function(overlay,angle){
			overlay.angle = angle;
			overlay.rObject.attr("rotation",overlay.angle*(57.2958));
		}
		this.setMaxScale = function(scale){
			this.maxScale = scale;
		}
		this.addOverlay = function(overlay){
			this.overlays.push(overlay);
			if (overlay.type==0){
				overlay.rObject = this.paper.image(overlay.style.image,0,0,overlay.style.width,overlay.style.height);
				overlay.map = this;				
				this.refreshOverlay(overlay);
			}
			if (overlay.type==1){
				overlay.rObject = this.paper.path("M0 0L0 0");
				overlay.rObject.attr("stroke",overlay.style.color);
				overlay.rObject.attr("stroke-width",overlay.style.width);
				overlay.rObject.attr("stroke-opacity",overlay.style.opacity);
				overlay.calculateBox();
				overlay.map = this;
				this.refreshOverlay(overlay);
			}				
			if (overlay.type==2){
				overlay.rObject = this.paper.path("M0 0L0 0");

				overlay.rObject.attr("stroke",overlay.style.lineColor);
				overlay.rObject.attr("stroke-width",overlay.style.lineWidth);
				overlay.rObject.attr("stroke-opacity",overlay.style.lineOpacity);
				
				overlay.rObject.attr("fill",overlay.style.fillColor);
				overlay.rObject.attr("fill-opacity",overlay.style.fillOpacity);
				overlay.calculateBox();
				overlay.map = this;
				this.refreshOverlay(overlay);
			}			
			return overlay;
		}
		this.removeOverlay = function(overlay){
			overlay.rObject.remove();
			this.overlays.removeItem(overlay);
		}
		this.removeOverlays = function(){
			if (this.overlays){
				for (var i=this.overlays.length-1;i>=0;i--){
					this.removeOverlay(this.overlays[i]);
				}
			}
		}
		this.setCRS = function(crs){
			this.crs = crs;
		}
		this.calculateBox = function(x,y,scale){
			var width = this.controlPanel.getWidth();
			var height = this.controlPanel.getHeight();
			this.box.xmin = x-(width*0.5/scale);
			this.box.ymin = y-(height*0.5/scale);
			this.box.xmax = x+(width*0.5/scale);
			this.box.ymax = y+(height*0.5/scale);			
		}
		this.findNearScale = function(scale){
			min = 99999999999999999;
			var res = this.levelsScale[0];
			for (var i=0;i<this.levelsScale.length;i++){
				var dx = Math.abs(this.levelsScale[i]-scale);
				if (dx<min){
					min = dx;
					res = this.levelsScale[i];
				}
			}
			return res;
		}
		this.getLevel = function(){
			min = 99999999999999999;
			var res = 0;
			for (var i=0;i<this.levelsScale.length;i++){
				var dx = Math.abs(this.levelsScale[i]-this.scale);
				if (dx<min){
					min = dx;
					res = i;
				}
			}
			return res;		
		}
		this.setView = function(x,y,scale){
			this.viewPoint.x = x;
			this.viewPoint.y = y;
			
			
			this.scale = this.findNearScale(scale);
			
			this.clearLevels();
			this.refresh(true);
		}
		this.setViewFromBox= function(box){
			obj.setViewFromExtent(box);
			obj.clearLevels(); 
			obj.refresh(true);
		}
		this.drawLoadingLayerStatus = function(){
			if (this.loadingLayersCount>0){
				this.loadingPanelText.innerHTML = this.loadingLayersCount;
				this.loadingPanel.show();

			} else {
				this.loadingPanel.hide();
				this.loadedPanel.show();
				if (this.downloadError == false){
					this.loadedPanel.mainDiv.style.backgroundImage='url('+obj.folderPath+'images/mapa/loaded.png)';	
				} else {
					this.loadedPanel.mainDiv.style.backgroundImage='url('+obj.folderPath+'images/mapa/loadedwrong.png)';	
				}
			}
		}
		this.drawWmsLevel = function(level,request,code){
			var width = this.mapPanel.getWorkspaceWidth();
			var height = this.mapPanel.getWorkspaceHeight();	
			var img = new Image();
			var div = level.div;
			var src = request;
			img.onload = function(){
				if ((level.actCode == code)){
						
					level.left = 0;
					level.top = 0;
					level.width = width;
					level.height = height;
					div.style.left = '0px';
					div.style.top = '0px';
					div.style.width = width+'px';
					div.style.height =  height+'px';
						
					img.style.width = '100%';
					img.style.height = '100%';						
					div.innerHTML = '';
					div.appendChild(img);
					obj.loadingLayersCount--;
					obj.drawLoadingLayerStatus();
					if (level.tdLoading)
					level.tdLoading.innerHTML = '';
					
					
				}
			}	
			img.onerror = function(){
				if ((level.actCode == code)){
					obj.downloadError = true;
					obj.loadingLayersCount--;
					obj.drawLoadingLayerStatus();
					
					if (level.tdLoading){
						var img = new Image();
						img.style.cursor = 'pointer';
						img.src = ''+obj.folderPath+'images/mapa/error_icon.png';
						level.tdLoading.innerHTML = '<a target="blank" href="'+src+'"><img style="border:none" src="'+img.src+'"/></a>';
					}	
				}	
			}
			img.src = src;				
		}
		this.drawTileLevel = function(level,ser){
			var width = this.mapPanel.getWorkspaceWidth();
			var height = this.mapPanel.getWorkspaceHeight();	
			var div = level.div;
			level.left = 0;
			level.top = 0;
			level.width = width;
			level.height = height;
			div.style.left = '0px';
			div.style.top = '0px';
			div.style.width = width+'px';
			div.style.height =  height+'px';
			
			
			var level = this.getLevel();
			var prec = 256/this.scale;
			
			var xminR = Math.floor(this.box.xmin/prec);
			var yminR = Math.floor(this.box.ymin/prec);
			xmin = xminR*prec;
			ymin = yminR*prec;			
			var xmaxR = Math.floor(this.box.xmax/prec)+1;
			var ymaxR = Math.floor(this.box.ymax/prec)+1;
			xmax = xmaxR*prec;
			ymax = ymaxR*prec;	

			
			
			div.innerHTML = '';
			var tab = new Array();
			var str = '';
			for (var i=xminR;i<xmaxR;i++){
				for (var j=yminR;j<ymaxR;j++){
					var x = this.pX(xmin+(i-xminR)*prec);
					var y = this.pY(ymin+(j-yminR)*prec)-256;
					tab.push({i:i,j:j,x:x,y:y});
				}
			}
			
			var src = '';
			for (var i=0;i<tab.length;i++){
				var req = ser.getTileRequest(level,tab[i].i,tab[i].j);
				if (req!=null)
				src += '<img style="position:absolute;left:'+tab[i].x+'px;top:'+tab[i].y+'px" src="'+req+'"/>';
				/*
				img.style.position = 'absolute';
				img.style.left = tab[i].x+'px';
				img.style.top = tab[i].y+'px';
				
				img.onLoad = function(){
					div.appendChild(this);
				}
				*/
			}
			div.innerHTML = src;
			
			obj.loadingLayersCount--;
			obj.drawLoadingLayerStatus();
			if (level.tdLoading)
			level.tdLoading.innerHTML = '';
					
		}		
		this.refresh = function(odrazu){
			if (odrazu==null) odrazu = false;
			
			if (odrazu==false) wielkiOdliczacz=1000;
			
			if (odrazu==true){
				if (this.onbeforerefresh) this.onbeforerefresh();
				var width = this.mapPanel.getWorkspaceWidth();
				var height = this.mapPanel.getWorkspaceHeight();	
				
				this.refreshInfo = {images:new Array(),width:width,height:height};
				
				this.calculateBox(this.viewPoint.x,this.viewPoint.y,this.scale);
				this.loadingLayersCount = 0;	
				obj.downloadError = false;			
				for (var i=0;i<this.services.length;i++){
					var ser = this.services[i];
					var visible = false;
					var actCode = 'code'+Math.round(Math.random()*100000);
					if (ser.isVisible(this.box,this.scale)==true) visible = true; else visible = false;
					
					
					
					if (visible == true){
						this.levels[i].active = true;
						this.levels[i].actCode = actCode;
						this.levels[i].serviceType = ser.serviceType;
						if (ser.item){
							this.levels[i].tdLoading = ser.item.getElement(2);
							if (this.levels[i].tdLoading!=null)
							this.levels[i].tdLoading.innerHTML = '<img src="'+obj.folderPath+'images/mapa/loading3.gif"/>';
							ser.item.setTextColor('#000');
						}
						
						if (ser.serviceType == 'WMS'){
							var req = ser.getMapRequest(this.box,this.crs,width,height);
							this.refreshInfo.images.push(req);
							this.drawWmsLevel(this.levels[i],req,actCode);
							this.loadingLayersCount++;	
							this.loadedPanel.hide();		
						}
						if (ser.serviceType == 'Tile'){

							this.drawTileLevel(this.levels[i],ser);
							this.loadingLayersCount++;	
							this.loadedPanel.hide();							
						}					
					} else {
						this.levels[i].div.innerHTML='';
						this.levels[i].active = false;
						this.levels[i].actCode = actCode;
						if (ser.item){
							ser.item.setTextColor('#999');
							if (this.levels[i].tdLoading!=null)
							this.levels[i].tdLoading.innerHTML = '';
						}
					}
				}
    
				obj.drawLoadingLayerStatus();
				this.refreshOverlays();
			}
		}
		this.loadLayersFromXml = function(xmlText,checkSecret){
			if (!checkSecret) checkSecret=false;
			var xml = System.textToXml(xmlText);
			
			var list = xml.getElementsByTagName('WMSService');
			for (var i=0;i<list.length;i++){
				var xml = list[i];
				
				if ((xml.getAttribute('type'))&&(xml.getAttribute('type')=='tile')){
					var tile = new iGML.TileService({},null);
					tile.createFromXml(list[i]);
					this.services.push(tile); 
					
				} else {
			
					var wms = new iGML.WMSService({},null);
					wms.createFromXml(list[i]);
					
					//alert(wms.name+" "+wms.secret);
					if (checkSecret==true) {
						if (wms.secret==false){
							wms.createFromXml(list[i]);
							this.services.push(wms); 
						} 
					} else {
						
						this.services.push(wms); 
					}	
				}	
			}
			

			this.createLevels();
		}		
		this.addService = function(layer){
			this.services.push(layer);
		},
		this.getServiceById = function(id){
			for (var i=0;i<this.services.length;i++){
				if (this.services[i].id == id) return this.services[i];
			}	
			return null;
		},
		this.createLevels = function(){
			this.levels = new Array();
			this.mapPanel.mainDiv.innerHTML = '';
			for (var i=0;i<this.services.length;i++){
				var div = System.createDiv(0,0,0,0,null,null);
				div.style.zIndex = (this.services.length+1)-i;
				this.mapPanel.mainDiv.appendChild(div);
				this.levels.push({div:div,top:0,left:0,width:this.mapPanel.getWorkspaceWidth(),height:this.mapPanel.getWorkspaceHeight()});
			}	
		}
		this.clearLevels = function(){
			for (var i=0;i<this.levels.length;i++){
				this.levels[i].div.innerHTML = '';
			}
		}
		this.setDivExtentPosition = function(div,xp,yp,x,y){
			if ((Math.abs(y-yp)>2)&&(Math.abs(x-xp)>2)){
				if ((y-yp)>=0) {
					div.style.top = yp+'px';
					div.style.height = (y-yp-2)+'px';
				} else {
					div.style.top= y+'px';
					div.style.height = (-(y-yp+2))+'px';							
				}
				if ((x-xp)>=0){							
					div.style.left = xp+'px';
					div.style.width = (x-xp-2)+'px';
				} else {
					div.style.left = x+'px';
					div.style.width = (-x+xp+2)+'px';							
				}
				div.style.display = 'block';		
			}		
		}
		this.getCorrectBox = function(px,py,kx,ky){		
			var realKX = kx;
			var realKY = ky;
			var realPX = px;
			var realPY = py;	
	
			if (realKX>realPX){
				var minX = realPX;
				var maxX = realKX;
			} else {
				var minX = realKX;
				var maxX = realPX;
			}
			if (realKY>realPY){
				var minY = realPY;
				var maxY = realKY;
			} else {
				var minY = realKY;
				var maxY = realPY;
			}	
			return new iGML.Box(minX,minY,maxX,maxY);
		}
		
		this.setViewFromExtent=function(box){
			if (box!=null){		
				var width = obj.mapPanel.getWorkspaceWidth();
				var height = obj.mapPanel.getWorkspaceHeight();
				this.viewPoint.x = (box.xmin+box.xmax)*0.5;
				this.viewPoint.y = (box.ymin+box.ymax)*0.5;			
			
				var dx = box.xmax-box.xmin;
				var dy = box.ymax-box.ymin;
				//alert(dx+' '+dy);
				var wsx =width/dx;
				var wsy =height/dy;

				var scale = wsx;
				if (wsy<wsx) scale = wsy;
				this.scale = this.findNearScale(scale);
			}				
		}
		this.endZoomByExtent = function(){
			this.zoomByExtent = false;
			this.zoomDiv.style.display = 'none';
			this.zoomDiv.style.left = '2000px';
			this.zoomInButton.setCheck(false);
			this.action = '';			
			this.setCursor();
		}
		this.setCursor = function(){

			if ((obj.action == 'listen')||(obj.action == '')){
				obj.controlPanel.setCursor('default');
			}	
			if ((obj.action == 'move_map')||(obj.isOverOverlay == true)||(obj.editLineSelectedPoint!=-1)){
				if (obj.controlPanel.getCursor()!='move')
				obj.controlPanel.setCursor('move');
			}
			if ((obj.action=='edit_line_move_point')||(obj.editLineSnap!=0)||(obj.pointOnLineSegment!=-1)||(obj.action == 'zoom_by_extent')||(obj.zoomByExtent == true)||(((obj.editedOverlay!=null)&&(obj.editedOverlay.type==0)&&(obj.editedOverlay.coord.x==null)))){
				obj.controlPanel.setCursor('crosshair');
			}	
			
		}
		this.startEditing = function(overlay){
			this.editedOverlay = overlay;
			this.editedOverlay.unmark();
			
			if ((overlay.type==1)||(overlay.type==2)){
				if (overlay.points.length==0)
				this.editLineSnap = 1;
				else
				this.editLineSnap = 0;
				this.pointOnLineSegment = -1;
				this.editLineSelectedPoint= -1;
				this.editPolygonSnapPoint= -1;
				this.potSnap = -1;
			}

			this.refreshEditingControls();
			obj.refreshEditingLine();
		}		
		this.setTool = function(name,param1){
			// name - nazwa narzedzia, dostepne: pointer,get_info,edit,multiedit
			// param1 w zaleznosci od narzedzie  edit - overlay do edycji , multiedit  - obiekt{ overlays,editingOverlay
			
			this.action = '';
			this.endZoomByExtent();
			this.pointerButton.setCheck(false);			
			this.pointerButton.setCheck(false);	
			this.editedOverlay = null;
			this.refreshEditingControls();
			obj.refreshEditingLine();
			this.editPanel.hide();
			this.editLineSnap = 0;
			this.pointOnLineSegment = -1;
			this.editLineSelectedPoint= -1;
			this.editPolygonSnapPoint= -1;
			this.potSnap = -1;
			this.editDiv.style.display = 'none';
			this.hideInfoWindow();
			this.getInfoPanel.hide();	
			
			obj.tool = name;
			if (name=='pointer'){
				this.pointerButton.setCheck(true);			
			}
			if (name=='get_info'){
				this.startGetFeatureInfo();	
				this.pointerButton.setCheck(false);			
			}		
			if (name == 'edit'){
				this.editPanel.show();
				this.startEditing(param1);
			}			
		}
		this.createEditTool = function(){
			this.editPanel = new System.Panel({x:290,y:0,
											width:600,
											height:24,
											backColor:'transparent'
											},this.statusPanel);
			this.editPanel.hide();
			
			this.editDiv = System.createDiv(3,3,null,null,230,40);
			this.controlPanel.mainDiv.appendChild(this.editDiv);	
			this.editDiv.style.fontSize='10px';
			this.editDiv.style.color = '#fff';
			this.editDiv.style.backgroundImage = 'url('+obj.folderPath+'images/mapa/tlo_black.png)';
			this.editDiv.style.padding='4px';
			this.editDiv.style.lineHeight = '14px';
			this.editDiv.style.display = 'none';
			
			//point edition control
			this.editPointCenter =  this.paper.circle(50, 50, 4);
			this.editPointCenter.attr('fill','#f00');
			this.editPointCenter.attr('stroke-opacity',0);
			this.editPointCenter.hide();
			
			this.editPointLine =  this.paper.path("M10 10L90 90");
			this.editPointLine.attr('stroke','#f00');
			this.editPointLine.attr('stroke-width',2);
			this.editPointLine.attr('stroke-dasharray','. ');
			this.editPointLine.hide();			
			
			this.editPointRotate = this.paper.circle(50, 50, 3);
			this.editPointRotate.attr('fill','#f00');
			this.editPointRotate.attr('stroke-opacity',0);
			this.editPointRotate.hide();
			
			this.editLineLine =  this.paper.path("M10 10L90 90");
			this.editLineLine.attr('stroke','#f00');
			this.editLineLine.attr('stroke-width',2);
			this.editLineLine.attr('stroke-dasharray','. ');
			this.editLineLine.hide();	
			
			this.editLinePoints = new Array();
			
			this.editLineSnap = 0;
			this.pointOnLineSegment = -1;
			this.editLineSelectedPoint= -1;
			this.potSnap = -1;
		}
		this.createGetFeatureTool = function(){
			this.selectedGetFeatureLayer = null;
			this.getInfoPanel =  new System.Panel({x:290,y:0,
											width:600,
											height:24,
											backColor:'transparent'
											},this.statusPanel);
			this.getInfoPanel.addImage(''+obj.folderPath+'images/mapa/info.png',1,1,22,22);	
			this.getInfoCombo = new System.ComboBox({x:25,y:2,width:150,height:21},this.getInfoPanel);			
			this.getInfoCombo.onchange = function(){
				obj.selectedGetFeatureLayer	 = obj.getInfoCombo.getSelectedItem().data;	
				//alert(obj.selectedGetFeatureLayer.name)	
			}
			this.getInfoPanel.hide();							
		}
		this.startGetFeatureInfo = function(){
			this.getInfoCombo.removeAll();
			
			for (var i=0;i<this.services.length;i++){
				var ser = this.services[i];
				if ((ser.checked==true)&&(ser.isQueryable()==true)){					
					this.getInfoCombo.addItem(ser.name,ser);
					if ((this.selectedGetFeatureLayer!=null)&&(this.selectedGetFeatureLayer==ser)) this.getInfoCombo.selectItemByValue(ser);
				}
			}
			if ((this.selectedGetFeatureLayer == null)&&(this.getInfoCombo.select.length>0)){
				this.selectedGetFeatureLayer =  this.getInfoCombo.getItemByIndex(0).data;
			}
			
			this.getInfoPanel.show();
		}
		this.createToolbar = function(){
			this.toolbar = new System.Toolbar({size:31},this.mainWindow);
			this.pointerButton = new System.ToolbarButtonImage({width:26,height:26,image:''+obj.folderPath+'images/mapa/pointer.png',check:true,group:1},this.toolbar);

			this.zoomInButton = new System.ToolbarButtonImage({width:26,height:26,image:''+obj.folderPath+'images/mapa/zoomin.png',check:true},this.toolbar);
			this.zoomOutButton = new System.ToolbarButtonImage({width:26,height:26,image:''+obj.folderPath+'images/mapa/zoomout.png',lightBorder:'transparent',darkBorder:'transparent',lightBackColor:'#444'},this.toolbar);
			this.zoomExtend = new System.ToolbarButtonImage({width:26,height:26,image:''+obj.folderPath+'images/mapa/zoom_zakres.png',lightBorder:'transparent',darkBorder:'transparent',lightBackColor:'#444'},this.toolbar);

			this.getInfoButton = new System.ToolbarButtonImage({width:26,height:26,image:''+obj.folderPath+'images/mapa/info.png',check:true,group:1},this.toolbar);
			//this.printButton = new System.ToolbarButtonImage({width:26,height:26,image:''+obj.folderPath+'images/mapa/info.png'},this.toolbar);
		
		
			this.zoomInButton.onclick = function(){
				obj.zoomByExtent = true;
				obj.setCursor();
			}
			this.zoomOutButton.onclick = function(){
				obj.zoom(-1,false);
			}		
			this.pointerButton.onclick = function(){
				obj.setTool('pointer');
			}	
			this.getInfoButton.onclick = function(){
				obj.setTool('get_info');
			}				
			this.zoomExtend.onclick = function(){
				var box = new iGML.Box(9999999999,9999999999,-9999999999,-9999999999);
				for (var i=0;i<obj.services.length;i++){
					if (obj.services[i].boundingBox.xmin<box.xmin) box.xmin = obj.services[i].boundingBox.xmin;
					if (obj.services[i].boundingBox.ymin<box.ymin) box.ymin = obj.services[i].boundingBox.ymin;
					if (obj.services[i].boundingBox.xmax>box.xmax) box.xmax = obj.services[i].boundingBox.xmax;
					if (obj.services[i].boundingBox.ymax>box.ymax) box.ymax = obj.services[i].boundingBox.ymax;
				}
				obj.setViewFromExtent(box);		
				obj.clearLevels(); 
				obj.refresh();		
				if (obj.tool == 'get_info'){
					obj.refreshInfoWindowPosition();					
				}				
			}
			var map = this;
			/*
			this.printButton.onclick = function(){
					var b = map.box;
					var dx = b.xmax - b.xmin;
					var dy = b.ymax - b.ymin;
					
					dd = dx;
					if (dy>dx) dd = dy;
					dd = Math.round(dd*0.5);
					var wid = map.mapPanel.getWorkspaceWidth();
					var hei = map.mapPanel.getWorkspaceHeight();
					
					var w = Math.round((wid+hei)*0.5);
					var h = w;
					
					var box = new iGML.Box(map.viewPoint.x-dd,map.viewPoint.y-dd,map.viewPoint.x+dd,map.viewPoint.y+dd);
					var adr = new Array();
					for (var i=0;i<map.services.length;i++){
						var s = map.services[i];
						if (s.checked==true){
							var r = s.getMapRequest(box,'EPSG:2180',w,h);
							if (r.indexOf("http")==-1) r = window.location.toString()+r;
							adr.push(r);
						}
					}
					//BEngine.Interface.LoadingPanel.show();
					var serwis = window.location.toString();
					System.Utils.Ajax.post('images/mapa/wydruk.php',{width:w,height:h,servers:adr.join('@'),nazwa_serwisu:serwis},function(obj){
						var obiekt =eval( "("+obj.responseText+")");
	
							var html = "<html><head>";
					
							html += "</head><body>";
					
							html += '<a href="skrypty/bengine/'+obiekt.sciezka+'">Pobierz dokument pdf z mapą</a>';
					
							html += "<body></html>";
					
							//BEngine.Interface.LoadingPanel.hide();
							var okno = window.open("","wydruk","status=1,width=300,height=150");
							okno.document.write(html);				
						
					});
				
				

				}*/
			
			
			
		}
		this.createMenuPanel = function(){
			this.menuPanelWidth = 190;
			this.menuPanelTop = 70;
			this.menuPanelHeight = this.workPanel.getWorkspaceHeight()-this.menuPanelTop;
			
		
			this.menuPanel = new System.Panel({x:0,y:this.menuPanelTop,width:this.menuPanelWidth,height:this.menuPanelHeight,backColor:'transparent',borderStyle:'NONE' },this.workPanel);
			this.menuPanel.mainDiv.style.zIndex = 5000;
			

			this.menuPanel.addImageWithAnchor(''+obj.folderPath+'images/mapa/dymek/rt.png',null,0,0,null,16,16);
			this.menuPanel.addImageWithAnchor(''+obj.folderPath+'images/mapa/dymek/t.png',0,0,16,null,null,16);		
			this.menuPanel.addImageWithAnchor(''+obj.folderPath+'images/mapa/dymek/r.png',null,16,0,0,16,null);
			this.menuPanel.addImageWithAnchor(''+obj.folderPath+'images/mapa/dymek/c.png',0,16,16,0,null,null);
			
			/*
			//var closeButton = new System.Button({x:(this.menuPanel.getWorkspaceWidth()-26),y:11,width:14,height:14,anchorRight:true,anchorLeft:false,lightBorder:'#eee',darkBorder:'#eee',backColor:'#e56748',image:''+obj.folderPath+'images/mapa/close.png',lightBackColor:'#e3bfbf'},this.menuPanel);
			//closeButton.onclick = function(){
			//	obj.menuPanel.hide();
			//}
			
			
			//var layerTreeButton = new System.ImageButton({x:11,y:11,width:25,height:20,image:''+obj.folderPath+'images/mapa/lay_tree.png',hoverImage:''+obj.folderPath+'images/mapa/lay_tree_p.png',selectedImage:''+obj.folderPath+'images/mapa/lay_tree_s.png',check:true,group:2},this.menuPanel);
			//var layerListButton = new System.ImageButton({x:36,y:11,width:24,height:20,image:''+obj.folderPath+'images/mapa/lay_list.png',hoverImage:''+obj.folderPath+'images/mapa/lay_list_p.png',selectedImage:''+obj.folderPath+'images/mapa/lay_list_s.png',check:true,group:2},this.menuPanel);
			//var lab = new System.Label({text:'Warstwy',x:7,y:11},this.menuPanel);
		*/
			this.layerTree = new System.TreeView({x:5,y:14,width:this.menuPanelWidth-24,height:this.menuPanelHeight-19,canmove:false,anchorLeft:true,anchorTop:true,anchorRight:true,anchorBottom:true},this.menuPanel);
			this.menuPanel.hide();
			
			this.menuSliderRight = this.menuPanel.addImageWithAnchor(''+obj.folderPath+'images/mapa/slide.png',null,34,10,6,5,null);
			this.menuSliderRight.style.cursor = 'col-resize';
			this.menuSliderTop = this.menuPanel.addImageWithAnchor('',5,4,26,null,null,5);
			this.menuSliderTop.style.cursor = 'row-resize';	
			
			this.menuPanelFrame = System.createDiv(-3,76,null,null,this.menuPanelWidth-14,this.menuPanelHeight-7);
			this.menuPanelFrame.style.display = 'none';
			this.menuPanelFrame.style.border='3px dashed #95cb2d';
			this.workPanel.mainDiv.appendChild(this.menuPanelFrame);		
			
			System.addEvent(this.menuSliderRight,'mousedown',function(e){
				obj.menuPanel.hide();
				obj.menuPanelFrame.style.display = 'block';
				obj.resizingMenu = 1;
				obj.tmpPos = System.mouseCoordinates(e);
				obj.oldWidth = obj.menuPanelWidth;
			});
			System.addEvent(this.menuSliderTop,'mousedown',function(e){
				obj.menuPanel.hide();
				obj.menuPanelFrame.style.display = 'block';
				obj.resizingMenu = 2;
				obj.tmpPos = System.mouseCoordinates(e);
				obj.oldHeight = obj.menuPanelHeight;
				obj.oldTop = obj.menuPanelTop;
			});						
			System.addGlobalEvent('mousemove',function(e){
				if (obj.resizingMenu == 2){
					var pos = System.mouseCoordinates(e);
					obj.menuPanelHeight = obj.oldHeight-(pos[1]-obj.tmpPos[1]);
					obj.menuPanelTop = obj.oldTop+(pos[1]-obj.tmpPos[1]);
					
					obj.menuPanelFrame.style.height = (obj.menuPanelHeight-1)+'px';
					obj.menuPanelFrame.style.top = (obj.menuPanelTop)+'px';
				}
				if (obj.resizingMenu == 1){
					var pos = System.mouseCoordinates(e);
					obj.menuPanelWidth = obj.oldWidth+(pos[0]-obj.tmpPos[0]);
					obj.menuPanelFrame.style.width = (obj.menuPanelWidth-14)+'px';
				}				
			});	
			System.addGlobalEvent('mouseup',function(e){
				if ((obj.resizingMenu == 1)||(obj.resizingMenu == 2)){
					obj.menuPanelFrame.style.display = 'none';	
					if (obj.menuPanelTop<70) obj.menuPanelTop = 70;			
					obj.showMenuPanel(); 
					obj.resizingMenu = 0;	
					
				}			
			});				
			
		}		
		this.showMenuPanel = function(){
			if (this.menuPanelHeight > (this.workPanel.getWorkspaceHeight()-70)){
				this.menuPanelHeight = this.workPanel.getWorkspaceHeight()-70;			
				this.menuPanelTop = 70;
			}
			
			
			this.menuPanel.y = this.menuPanelTop;
			this.menuPanel.height = this.menuPanelHeight;
			this.menuPanel.width = this.menuPanelWidth;
			this.menuPanel.setPositionFromActualParameters();
			
			this.menuPanelFrame.style.width = (this.menuPanelWidth-14)+'px';
			this.menuPanelFrame.style.height = (this.menuPanelHeight-4)+'px';
			this.menuPanelFrame.style.top = (this.menuPanelTop+5)+'px';
		
			this.menuPanel.show();
			this.fillLayerTree();
		}
		this.setMenuPanelWidth = function(value){
			this.menuPanelWidth = value;
		}
		this.setMenuPanelHeight = function(value){
			this.menuPanelHeight = value;
			this.menuPanelTop = this.workPanel.getWorkspaceHeight()-this.menuPanelHeight;
		}		
		this.fillLayerTree = function(){
			this.layerTree.removeAll();
			for (var i = 0;i<this.services.length;i++){
				var s = this.services[i];
				
				var cells=['',s.name,''];
				var textIndex = 1;
				
				var item = new System.TreeViewItem({cells:cells,textIndex:textIndex,widths:'1px,700px,13px',checked:s.checked,extended:s.expanded,oncheck:function(checked){
					this.service.checked = checked;
					obj.refresh();
				}});
				item.onextend = function(){
					this.service.expanded = this.extended;
				}
				item.service = s;
				s.item = item;
				this.layerTree.addItem(item);
				if (s.expandable==true){	
					for (var j=0;j<s.layers.length;j++){
						var l = s.layers[j];
						var cells=['',l.title];
						var textIndex = 1;
						var subitem = new System.TreeViewItem({cells:cells,textIndex:textIndex,widths:'1px,700px',checked:l.checked,extended:false,oncheck:function(checked){
							this.layer.checked = checked;
							obj.refresh();
						}});				
						subitem.layer = l;
						item.addItem(subitem);
					}
				}
				
			}
		}
		this.initControls =function(){
			this.createToolbar(); 
			var workspace = this.controlPanel;
			this.mouseInWorkspace = false;
			this.zoomByExtent = false;
			this.action = '';
			this.tool = 'pointer';
			this.pPosMouse = new iGML.Point(0,0);
			this.pPosReal = new iGML.Point(0,0);
			this.state = 0;
			//div zoom
			this.zoomDiv = System.createDiv(0,0,null,null,3,3);
			this.zoomDiv.style.border = '2px solid #45a';
			this.zoomDiv.style.backgroundColor = '#60abff';
			this.zoomDiv.style.filter='alpha(opacity=40)';
			this.zoomDiv.style.opacity='0.4';
			
			this.zoomDiv.style.display = 'none';
			obj.controlPanel.mainDiv.appendChild(this.zoomDiv);
			////////////
			
			workspace.addEvent('mousemove',function(x,y){
				var d = new Date();
				var msec = d.getTime();
				obj.mouseInWorkspace = true;
				obj.mouseCoordinates.x = x;				
				obj.mouseCoordinates.y = y;		
				var wspX = obj.box.xmin+((obj.box.xmax-obj.box.xmin)*(x/workspace.getWorkspaceWidth()));
				var wspY = obj.box.ymin+((obj.box.ymax-obj.box.ymin)*((workspace.getWorkspaceHeight()-y)/workspace.getWorkspaceHeight()));
				obj.position.x = wspX;
				obj.position.y = wspY;									
				obj.coordinatesTextBox.setText('X : '+System.round(wspY,1)+'  Y : '+System.round(wspX,1));	
				
				if (obj.action=='edit_point_center_move'){
					obj.editedOverlay.coord.x = obj.position.x;
					obj.editedOverlay.coord.y = obj.position.y;
					obj.refreshOverlay(obj.editedOverlay);
					obj.refreshEditingControls();
				}
				if (obj.action=='edit_point_rotate_move'){

					var dx = x - obj.editedOverlay.scCoord.x;
					var dy = y - obj.editedOverlay.scCoord.y;
					obj.editedOverlay.angle = MyMath.azymuth(dx,dy);
					obj.editedOverlay.setSymbolAngle(obj.editedOverlay.angle);
					obj.refreshOverlay(obj.editedOverlay);
					obj.refreshEditingControls();
					if (obj.editedOverlay.onrotate) obj.editedOverlay.onrotate(obj.editedOverlay.angle);
				}				
				
				if (obj.action == 'zoom_by_extent'){
					obj.setDivExtentPosition(obj.zoomDiv,obj.pPosMouse.x,obj.pPosMouse.y,x,y);								
				}
				if (obj.action == 'listen'){
					if (obj.tool == 'get_info'){
			
						if (((msec-obj.msec)>500) ||(Math.abs(x-obj.pPosMouse.x)>2)||(Math.abs(y-obj.pPosMouse.y)>2)) {
							obj.action = 'move_map';	
		
						}
					}
					if (obj.tool == 'edit'){			
						if (((msec-obj.msec)>500) ||(Math.abs(x-obj.pPosMouse.x)>2)||(Math.abs(y-obj.pPosMouse.y)>2)) {
							obj.action = 'move_map';			
						}
												
					}					
					if (obj.tool == 'pointer'){
						obj.action = 'move_map';	
					}				
				}
				if (obj.action == 'move_map'){
					var dx = x - obj.pPosMouse.x;
					var dy = y - obj.pPosMouse.y;
					for (var i= 0;i<obj.levels.length;i++){
						var level = obj.levels[i];
						level.div.style.left = (level.left+dx)+'px';
						level.div.style.top = (level.top+dy)+'px';
						level.actCode = 'code'+Math.round(Math.random()*100000);
					}		
					obj.overlayPanel.mainDiv.style.left = (dx)+'px';
					obj.overlayPanel.mainDiv.style.top = (dy)+'px';						
					if (obj.tool == 'get_info'){
						obj.refreshInfoWindowPosition(dx,dy);					
					}

				}
				
				if (obj.tool == 'edit'){
					
					if (obj.editedOverlay!=null){
						if ((obj.editedOverlay.type==0)&&(obj.editedOverlay.coord.x!=null)){
							obj.isOverOverlay = false;
							obj.isOverType = 0;
							if (obj.editedOverlay.isPointOver(x,y)==true){
								obj.isOverOverlay = true;
								obj.isOverType = 1;
							} 
							if ((obj.editedOverlay.canRotate==true)&&(obj.editPointRotateCoord.isPointOver(x,y)==true)){
								obj.isOverOverlay = true;
								obj.isOverType = 2;
							} 
						}
						
					}	


					
					if ((obj.editedOverlay.type==1)||(obj.editedOverlay.type==2)){
						if (obj.action == 'edit_line_move_point'){
							obj.refreshEditingLine();						
						}
						if ((obj.editLineSnap==0)&&(obj.action != 'edit_line_move_point')){
							if ((obj.editedOverlay.type==2)&&(obj.editedOverlay.closed==true)){
								obj.blockSnap = true;							
							}
							for (var i=0;i<obj.editLinePoints.length;i++){
								if (obj.editLinePoints[i].big==true){
									obj.editLinePoints[i].big = false;
									obj.editLinePoints[i].r.animate({r: 4}, 100);
								}
							}
							obj.editLineSelectedPoint = -1;
							var ind = obj.editedOverlay.isPointOverPoint(x,y);
							
							if (obj.potSnap!=-1){
								var dx = Math.abs(x-obj.potSnapX);
								var dy = Math.abs(y-obj.potSnapY);
								if ((dx>10)||(dy>10)){
									obj.editLineSnap=obj.potSnap;	
									obj.potSnap	= -1;	
								}								
							}	
							
							if ((obj.potSnap==-1)&&(obj.blockSnap!=true)){
								if (ind == 0){
									obj.potSnap=2;
								}  
								if (ind == (obj.editedOverlay.points.length-1)){
									obj.potSnap=1;										
								} 								
								obj.potSnapX = x;
								obj.potSnapY = y;								
							}
							
							//document.getElementById('info').innerHTML = obj.potSnap;
							if (obj.blockSnap == true){
								var dx = Math.abs(x-obj.blockSnapX);
								var dy = Math.abs(y-obj.blockSnapY);								
								if ((dx>15)||(dy>15)){
									obj.blockSnap = false;
								}
							}
							
							if ((ind!=-1)&&(ind<obj.editedOverlay.points.length)){
								obj.editLinePoints[ind].r.animate({r: 6}, 100);
								obj.editLinePoints[ind].big = true;								
							}
							obj.editLineSelectedPoint = ind;
							
							var indSeg=-1;							
							if (ind==-1){
								indSeg = obj.editedOverlay.isPointOverSegment(x,y);
								if ((indSeg!=-1)&&(ind<obj.editedOverlay.points.length-1)){
									obj.editLinePoints[indSeg].r.animate({r: 6}, 100);
									obj.editLinePoints[indSeg+1].r.animate({r: 6}, 100);
									obj.editLinePoints[indSeg].big = true;
									obj.editLinePoints[indSeg+1].big = true;
								}
							}
							obj.pointOnLineSegment = indSeg; 
						}
						if ((obj.editLineSnap!=0)&&(obj.editedOverlay.type==2)&&(obj.editedOverlay.points.length>=3)){
							obj.editPolygonSnapPoint= -1;
							var ind = obj.editedOverlay.isPointOverPoint(x,y);
							for (var i=0;i<obj.editLinePoints.length;i++){
								if (obj.editLinePoints[i].big==true){
									obj.editLinePoints[i].big = false;
									obj.editLinePoints[i].r.animate({r: 4}, 100);
								}
							}
							if ((obj.editLineSnap==1)&&(ind==0)){
								obj.editLinePoints[ind].r.animate({r: 6}, 100);
								obj.editLinePoints[ind].big = true;		
								obj.editPolygonSnapPoint= ind;
							}
							if ((obj.editLineSnap==2)&&(ind==(obj.editedOverlay.points.length-1))){
								obj.editLinePoints[ind].r.animate({r: 6}, 100);
								obj.editLinePoints[ind].big = true;	
								obj.editPolygonSnapPoint= ind;								
							}
							
						}
						if (obj.action=='')
						obj.refreshEditingLine();
					}

					//komunikaty
					obj.editDiv.style.display = 'none';
					obj.editDiv.innerHTML = '';
					var ilew = 0;
					if (obj.editedOverlay.type==0){
						if (obj.editedOverlay.coord.x==null) {
							obj.editDiv.innerHTML += '<span style="color:#eff7ff;font-weight:bold">Lewy klik</span> - wstawienie punktu<br/>';
							ilew++;
						} else {
							obj.editDiv.innerHTML += '';
							if (obj.isOverType == 1){
								obj.editDiv.innerHTML += '<span style="color:#eff7ff;font-weight:bold">Lewy przeciągnięcie</span> - zmienia położenie punktu<br/>';
								ilew++;
							}
							if (obj.isOverType == 2){
								obj.editDiv.innerHTML += '<span style="color:#eff7ff;font-weight:bold">Lewy przeciągnięcie</span> - obraca punkt<br/>';
								ilew++;
							}
						}
					}
					if (obj.editedOverlay.type==1){
						if (obj.editLineSnap!=0){
							if (obj.editedOverlay.points.length<2) {
								obj.editDiv.innerHTML += '<span style="color:#eff7ff;font-weight:bold">Lewy klik</span> - dodanie punktu<br/>';
								ilew++;
							} else {
								obj.editDiv.innerHTML += '<span style="color:#eff7ff;font-weight:bold">Lewy klik</span> - dodanie punktu<br/><span style="color:#eff7ff;font-weight:bold">Spacja</span> - zakończenie wstawiania odcinka<br/>';
								ilew+=2;
							}
						} else {
							if (obj.editLineSelectedPoint!=-1){
								if ((obj.potSnap==1)||(obj.potSnap==2)){
									obj.editDiv.innerHTML += '<span style="color:#eff7ff;font-weight:bold">Przeciągnięcie</span> - kontynuowanie tworzenia<br/>';
									ilew++;
								}

								obj.editDiv.innerHTML += '<span style="color:#eff7ff;font-weight:bold">Lewy przeciągnięcie</span> - zmienia położenie punkt<br/>';
								ilew++;

								if (obj.editedOverlay.points.length>2){
									obj.editDiv.innerHTML +='<span style="color:#eff7ff;font-weight:bold">Delete</span> - usunięcie punktu<br/>';
									ilew++;
								}
							}
							if (obj.pointOnLineSegment!=-1){
								obj.editDiv.innerHTML += '<span style="color:#eff7ff;font-weight:bold">Lewy klik</span> - wstawienie punktu<br/>';
								ilew++;
							}
						}
						if (obj.editedOverlay.points.length>1){
							obj.editDiv.innerHTML += '<span style="color:#eff7ff;font-weight:bold">Y</span> - usunięcie osi ulicy<br/>';
							ilew++;
						}
					}
					if (obj.editedOverlay.type==2){
						if (obj.editLineSnap!=0){
							if (obj.editedOverlay.points.length<4) {
								obj.editDiv.innerHTML += '<span style="color:#eff7ff;font-weight:bold">Lewy klik</span> - dodanie punktu<br/>';
								ilew++;
							} else {
								if (obj.editPolygonSnapPoint!=-1){
									obj.editDiv.innerHTML += '<span style="color:#eff7ff;font-weight:bold">Lewy klik</span> - zamkniecie poligonu<br/>';
								} else {
									obj.editDiv.innerHTML += '<span style="color:#eff7ff;font-weight:bold">Lewy klik</span> - dodanie punktu<br/>';
								}
								obj.editDiv.innerHTML += '<span style="color:#eff7ff;font-weight:bold">Spacja</span> - zakończenie wstawiania<br/>';
								ilew+=2;
							}



						} else {
							if (obj.editLineSelectedPoint!=-1){
								if ((obj.potSnap==1)||(obj.potSnap==2)){
									obj.editDiv.innerHTML += '<span style="color:#eff7ff;font-weight:bold">Przeciągnięcie</span> - kontynuowanie tworzenia<br/>';
									ilew++;
								}

								obj.editDiv.innerHTML += '<span style="color:#eff7ff;font-weight:bold">Lewy przeciągnięcie</span> - zmienia położenie punkt<br/>';
								ilew++;

								if (obj.editedOverlay.points.length>4){
									obj.editDiv.innerHTML +='<span style="color:#eff7ff;font-weight:bold">Delete</span> - usunięcie punktu<br/>';
									ilew++;
								}
							}
							if (obj.pointOnLineSegment!=-1){
								obj.editDiv.innerHTML += '<span style="color:#eff7ff;font-weight:bold">Lewy klik</span> - wstawienie punktu<br/>';
								ilew++;
							}
						}
					}
					obj.editDiv.innerHTML += '';
					if (ilew>0){
						obj.editDiv.style.height = ((14*ilew))+'px';
						obj.editDiv.style.display = 'block';			
					}				
				}
				//ustawianie kursora
				obj.setCursor();
				if (System.keys[17]==true) obj.controlPanel.setCursor('crosshair');
				
				
				if (obj.tool == 'pointer'){
				for (var i=0;i<obj.overlays.length;i++){
					var ovr = obj.overlays[i];							
					if (ovr.visible == true){
						if (ovr.marked==true) ovr.unmark();																		
					}
				}				
				for (var i=(obj.overlays.length-1);i>=0;i--){
					var ovr = obj.overlays[i];							
					if (ovr.visible == true){
						if (ovr.isPointOver(x,y)==true) { ovr.mark(); break; }														
					}
				}
				}
			});				
			workspace.addEvent('mousedown',function(x,y,button){
				obj.pPosMouse.x = x;
				obj.pPosMouse.y = y;
				obj.pPosReal.x = obj.position.x;
				obj.pPosReal.y = obj.position.y;
				var d = new Date();
				obj.msec = d.getTime();
				
				var isZoomByExtent = false;
				if ((button==0)&&((System.keys[17]==true)||(obj.zoomByExtent==true))) { //CTRL
					isZoomByExtent = true;
				}				
				if (isZoomByExtent==true){
					obj.action = 'zoom_by_extent';	
				} else {
					if ((obj.tool == 'edit')&&(button==0)){
						if (obj.editedOverlay!=null){
							if ((obj.editedOverlay.type==0)&&(obj.editedOverlay.coord.x!=null)){														
								if (obj.editedOverlay.isPointOver(x,y)==true){
									obj.action='edit_point_center_move';
									obj.editedOverlay.unmark();
								} 
								if ((obj.editedOverlay.canRotate==true)&&(obj.editPointRotateCoord.isPointOver(x,y)==true)){
									obj.action='edit_point_rotate_move';								
								} 
							}
							
							if (((obj.editedOverlay.type==1)||(obj.editedOverlay.type==2))&&(obj.editLineSnap==0)&&(obj.editLineSelectedPoint!=-1)){
								obj.action = 'edit_line_move_point';
							}
						}		
					
					}
					if ((button==0)&&(obj.action=='')) obj.action = 'listen';
				}
				obj.setCursor();
			});
			workspace.addEvent('mouseup',function(x,y,button){
				var d = new Date();
				var msec = d.getTime();
				
				if (obj.action=='edit_point_center_move'){
					obj.editedOverlay.unmark();		
					obj.action = '';
					if (obj.editedOverlay.onchangeposition) obj.editedOverlay.onchangeposition(obj.editedOverlay.coord.x,obj.editedOverlay.coord.y);
				}
				if (obj.action=='edit_point_rotate_move'){
					obj.action = '';
				}				
				if (obj.action == 'zoom_by_extent'){
					if ((Math.abs(x-obj.pPosMouse.x)>2)||(Math.abs(y-obj.pPosMouse.y)>2)) {					
						var box = obj.getCorrectBox(obj.pPosReal.x,obj.pPosReal.y,obj.position.x,obj.position.y);
						obj.setViewFromExtent(box);
						obj.clearLevels(); 
						obj.refresh();
						obj.zoomDiv.style.display = 'none';
						obj.action = '';
					} else {
						obj.zoom(1,true);
						obj.action = '';
					}		
					obj.endZoomByExtent();	
					if (obj.tool == 'get_info'){
						obj.refreshInfoWindowPosition();					
					}					
				}
				if ((obj.action == 'move_map')&&(button==0)){
					var dx = x - obj.pPosMouse.x;
					var dy = y - obj.pPosMouse.y;
					for (var i= 0;i<obj.levels.length;i++){
						var level = obj.levels[i];
						level.left+=dx;
						level.top+=dy;
						level.div.style.left = (level.left)+'px';
						level.div.style.top = (level.top)+'px';
					}
					obj.viewPoint.x-=dx/obj.scale;
					obj.viewPoint.y+=dy/obj.scale;
					obj.overlayPanel.mainDiv.style.left = '0px';
					obj.overlayPanel.mainDiv.style.top = '0px';		
					
					obj.refresh();
					obj.action = '';	
					if (obj.tool == 'get_info'){
						obj.refreshInfoWindowPosition();					
					}
				}
				if (obj.action == 'edit_line_move_point'){
					obj.action = '';					
					obj.editLineSnap=0;
					obj.potSnap	= -1;								
					obj.editedOverlay.points[obj.editLineSelectedPoint].x = obj.position.x;
					obj.editedOverlay.points[obj.editLineSelectedPoint].y = obj.position.y;
					if ((obj.editedOverlay.type==2)&&(obj.editedOverlay.closed==true)){
						if (obj.editLineSelectedPoint == 0){
							obj.editedOverlay.points[obj.editedOverlay.points.length-1].x = obj.position.x;
							obj.editedOverlay.points[obj.editedOverlay.points.length-1].y = obj.position.y;						
						}
						if (obj.editLineSelectedPoint == (obj.editedOverlay.points.length-1)){
							obj.editedOverlay.points[0].x = obj.position.x;
							obj.editedOverlay.points[0].y = obj.position.y;						
						}						
					}
					obj.blockSnap = true;
					obj.blockSnapX = x;
					obj.blockSnapY = y;
					obj.editLineSelectedPoint=-1;
					obj.editedOverlay.calculateBox();
					obj.refreshOverlay(obj.editedOverlay);
					obj.refreshEditingControls();											
					obj.refreshEditingLine();		
				}
				if (obj.action=='listen') {
					if (obj.tool == 'get_info'){
						if ((msec-obj.msec)<500) {
							if (obj.selectedGetFeatureLayer!=null){
								var width = obj.mapPanel.getWorkspaceWidth();
								var height = obj.mapPanel.getWorkspaceHeight();
								var req = obj.selectedGetFeatureLayer.getFeatureInfoRequest(x,y,obj.box,obj.crs,width,height);
								obj.showInfoWindow(obj.position.x,obj.position.y,req);	
							} else {
								alert('Brak serwisu do zapytania');
							}
						}						
					}
					if ((obj.tool == 'edit')&&(button==0)){
						if (obj.editedOverlay!=null){
							if ((obj.editedOverlay.type==0)&&(obj.editedOverlay.coord.x==null)){														
								obj.editedOverlay.coord.x = obj.position.x;	
								obj.editedOverlay.coord.y = obj.position.y;	
								obj.refreshOverlay(obj.editedOverlay);
								obj.refreshEditingControls();	
								if (obj.editedOverlay.onchangeposition) obj.editedOverlay.onchangeposition(obj.position.x,obj.position.y);
							}
							if ((obj.editedOverlay.type==1)||(obj.editedOverlay.type==2)){ 
															
								var indexInsert = -1;
								
								if (obj.editLineSnap==1)
								indexInsert = obj.editedOverlay.points.length;
								if (obj.editLineSnap==2)
								indexInsert = 0;
								if (obj.editLineSnap==0){
									if (obj.pointOnLineSegment!=-1)
									indexInsert = obj.pointOnLineSegment+1;
								}
								
								if (indexInsert!=-1){
									var x = obj.position.x;
									var y = obj.position.y;
									if (obj.editPolygonSnapPoint!=-1){
										x = obj.editedOverlay.points[obj.editPolygonSnapPoint].x;
										y = obj.editedOverlay.points[obj.editPolygonSnapPoint].y;
										obj.editLineSnap = 0;
										obj.editPolygonSnapPoint=-1;
									}
									obj.editedOverlay.insertPoint(x,y,indexInsert);
									obj.editedOverlay.calculateBox();
									obj.refreshOverlay(obj.editedOverlay);
									obj.refreshEditingControls();	
									
								}
								obj.refreshEditingLine();
								
							}
						}		
					
					}					
					if (obj.tool == 'pointer'){
						for (var i=0;i<obj.overlays.length;i++){
							var ovr = obj.overlays[i];
							if (ovr.onclick!=null){
								if (ovr.visible == true){
									if (ovr.isPointOver(x,y)==true) { ovr.onclick(); break;}														
								}
							}
						}
						
						//obsluga zdarezn mapy - click
						for (var i=0;i<obj.events.length;i++){
							var evt = obj.events[i];
							if (evt.name == 'click') evt.func(obj.position.x,obj.position.y,button);
						
						}
						
						if (obj.onclick) obj.onclick(obj.position.x,obj.position.y);
					}
					
					
				}
	
				obj.action = '';
				obj.setCursor();
			});	
			workspace.addEvent('mouseout',function(x,y){
				if ((obj.action == 'move_map')){
					var dx = x - obj.pPosMouse.x;
					var dy = y - obj.pPosMouse.y;
					for (var i= 0;i<obj.levels.length;i++){
						var level = obj.levels[i];
						level.left+=dx;
						level.top+=dy;
						level.div.style.left = (level.left)+'px';
						level.div.style.top = (level.top)+'px';
					}
					obj.viewPoint.x-=dx/obj.scale;
					obj.viewPoint.y+=dy/obj.scale;
					obj.refresh();
					obj.action = '';	
				}
				
				obj.mouseInWorkspace = false;
				obj.setCursor();	
			});	
			System.Utils.Mouse.handleWheel = function(delta){
				if (obj.mouseInWorkspace==true){
					if ((obj.scale<obj.maxScale)||(delta<0)){
					obj.zoom(delta,true);
					if (obj.tool == 'get_info'){
						obj.refreshInfoWindowPosition();					
					}
					}
					return false;
				}
				return true;
			}	
			System.Utils.Keys.handleKeyUp = function(code){
				if (obj.mouseInWorkspace == true){

					obj.setCursor();
					if ((obj.action == 'zoom_by_extent')&&(code==32)){
						obj.endZoomByExtent();				
					}
					if ((obj.editLineSnap!=0)&&(code==32)&&(obj.editedOverlay.points.length>1)){
						obj.editLineSnap = 0;
						obj.potSnap	= -1;	
						obj.refreshEditingControls();
						obj.refreshEditingLine();					
					}
					if ((obj.editedOverlay!=null)&&(obj.editLineSnap==0)&&(obj.editedOverlay.type==1)&&(code==46)&&(obj.editedOverlay.points.length>2)&&(obj.editLineSelectedPoint!=-1)){
						obj.editedOverlay.points.remove(obj.editLineSelectedPoint,obj.editLineSelectedPoint);
						obj.editLineSelectedPoint=-1;
						obj.editLineSnap=0;
						obj.potSnap	= -1;	
						obj.refreshOverlay(obj.editedOverlay);
						obj.refreshEditingControls();
						obj.refreshEditingLine();					
					}	
					if ((obj.editedOverlay!=null)&&(obj.editLineSnap==0)&&(obj.editedOverlay.type==2)&&(code==46)&&(obj.editedOverlay.points.length>4)&&(obj.editLineSelectedPoint!=-1)){
						obj.editedOverlay.points.remove(obj.editLineSelectedPoint,obj.editLineSelectedPoint);
						obj.editLineSelectedPoint=-1;
						obj.editLineSnap=0;
						obj.potSnap	= -1;	
						obj.refreshOverlay(obj.editedOverlay);
						obj.refreshEditingControls();
						obj.refreshEditingLine();					
					}				
					if ((obj.editedOverlay!=null)&&(obj.editedOverlay.type==1)&&(code==89)&&(obj.editedOverlay.points.length>1)){
						if (confirm('Czy na pewno chcesz usunąć linie?')){
							obj.removeOverlay(obj.editedOverlay);
							obj.setTool('pointer');
						}	
					}						
				}
			}
			System.Utils.Keys.handleKeyDown = function(code){			
				if (code==17){
					obj.controlPanel.setCursor('crosshair');
				}
			}			
			this.createEditTool();
			this.createGetFeatureTool();
			this.createMenuPanel();
			this.setTool('pointer');
		}
		this.zoom = function(delta,wheel){
			var width = obj.controlPanel.getWorkspaceWidth();
			var height = obj.controlPanel.getWorkspaceHeight();
			
			var wsp = 1;
			if (delta>0) wsp=2;
			if (delta<0) wsp=0.5;
			obj.scale*=wsp;
			if (obj.scale>this.findNearScale(999)) {obj.scale = this.findNearScale(999); wsp=1; return 0;}
			

			obj.scale = this.findNearScale(obj.scale);
			
			
			var x = obj.mouseCoordinates.x;
			var y = obj.mouseCoordinates.y;
			if (wheel==false){
				x=(width*0.5);
				y=(height*0.5);			
			}					
					
			for (var i= 0;i<obj.levels.length;i++){					
				var level = obj.levels[i];
				if ( level.active==true){	
					if (level.serviceType == 'Tile') level.div.innerHTML = '';
					var dx = x-level.left;
					var dy = y-level.top;
					dx = dx/level.width;
					dy = dy/level.height;
					
					var dl = Math.round(((level.width*wsp)-level.width)*dx);
					var dt = Math.round(((level.height*wsp)-level.height)*dy);
					level.left-=dl;
					level.top-=dt;
					level.width = Math.round(level.width*wsp);
					level.height =Math.round(level.height *wsp);		

					level.div.style.width = (level.width)+'px';
					level.div.style.height = (level.height)+'px';
					level.div.style.top = (level.top)+'px';
					level.div.style.left = (level.left)+'px';		
				}						
			}	
			var dx = 0.5-(x/width);
			var dy = 0.5-(y/height);					
			var dl = Math.round(((width*wsp)-width)*dx);
			var dt = Math.round(((height*wsp)-height)*dy);					
			obj.viewPoint.x-=dl/obj.scale;
			obj.viewPoint.y+=dt/obj.scale;
			
			obj.refresh();					
		}
		this.pX = function(x){
			return Math.round(((x-this.box.xmin)/(this.box.xmax-this.box.xmin))*this.mapPanel.getWorkspaceWidth());
		}
		this.pY = function(y){
			return Math.round(this.mapPanel.getWorkspaceHeight()-(((y-this.box.ymin)/(this.box.ymax-this.box.ymin))*this.mapPanel.getWorkspaceHeight()));
		}		
		this.addEventListener = function(event,func){
			//click (x,y,button) - tylko gdy tool == pointer
			this.events.push({name:event,func:func});
		}
		this.createInfoWindow = function(){
			this.infoWindowWidth = 240;
			this.infoWindowHeight = 250;
			
			
			this.infoPanel = new System.Window({width:300,height:250,startPosition:'CENTER',borderStyle:'TOOL',text:'Informacja o obiekcie'},this.workPanel);

			
			/*
			this.infoPanel.addImageWithAnchor(''+obj.folderPath+'images/mapa/dymek/lt.png',0,0,null,null,16,16);
			this.infoPanel.addImageWithAnchor(''+obj.folderPath+'images/mapa/dymek/rt.png',null,0,0,null,16,16);
			this.infoPanel.addImageWithAnchor(''+obj.folderPath+'images/mapa/dymek/lb.png',0,null,null,0,16,16);
			this.infoPanel.addImageWithAnchor(''+obj.folderPath+'images/mapa/dymek/rb.png',null,null,0,0,16,16);	

			this.infoPanel.addImageWithAnchor(''+obj.folderPath+'images/mapa/dymek/t.png',16,0,16,null,null,16);
			//this.infoPanel.addImageWithAnchor(''+obj.folderPath+'images/mapa/dymek/b.png',16,null,16,0,null,16);
			this.infoPanelB1 = this.infoPanel.addImageWithAnchor(''+obj.folderPath+'images/mapa/dymek/b.png',16,null,null,0,30-16,16);
			this.infoPanelB2 = this.infoPanel.addImageWithAnchor(''+obj.folderPath+'images/mapa/dymek/b.png',30+21,null,16,0,null,16);
			this.infoPanel.addImageWithAnchor(''+obj.folderPath+'images/mapa/dymek/l.png',0,16,null,16,16,null);
			this.infoPanel.addImageWithAnchor(''+obj.folderPath+'images/mapa/dymek/r.png',null,16,0,16,16,null);
			this.infoPanelText = this.infoPanel.addImageWithAnchor(''+obj.folderPath+'images/mapa/dymek/c.png',16,16,16,16,null,null);			
			this.infoPanelText.style.padding = '12px 0px 3px 0px';
			this.infoPanelOgonek = this.infoPanel.addImageWithAnchor(''+obj.folderPath+'images/mapa/dymek/ogonek.png',30,null,null,-10,21,26);
				
			var s3 = this.infoPanel.addImageWithAnchor(''+obj.folderPath+'images/mapa/size3.png',16,14,null,null,8,8);	
			var s2 = this.infoPanel.addImageWithAnchor(''+obj.folderPath+'images/mapa/size2.png',25,14,null,null,8,8);	
			var s1 = this.infoPanel.addImageWithAnchor(''+obj.folderPath+'images/mapa/size1.png',36,14,null,null,8,8);	
				
			s3.style.cursor = 'pointer';
			s3.onclick = function(){
				obj.infoWindowWidth = 170;
				obj.infoWindowHeight = 180;
				obj.refreshInfoWindowPosition();
			}			
			s2.style.cursor = 'pointer';
			s2.onclick = function(){
				obj.infoWindowWidth = 240;
				obj.infoWindowHeight = 250;
				obj.refreshInfoWindowPosition();
			}	
			s1.style.cursor = 'pointer';
			s1.onclick = function(){
				obj.infoWindowWidth = 320;
				obj.infoWindowHeight = 330;
				obj.refreshInfoWindowPosition();
			}		
			
			this.infoPanel.hide();
			
			 var closeButton = new System.Button({x:(this.infoPanel.getWorkspaceWidth()-26),y:11,width:14,height:14,anchorRight:true,anchorLeft:false,lightBorder:'#eee',darkBorder:'#eee',backColor:'#e56748',image:''+obj.folderPath+'images/mapa/close.png',lightBackColor:'#e3bfbf'},this.infoPanel);
			closeButton.onclick = function(){
				obj.hideInfoWindow();
			}
			*/
		}
		this.showInfoWindow = function(x,y,req){

			this.infoPanelX = x;
			this.infoPanelY = y;
			//this.infoPanelText.innerHTML = content;

			
			//this.refreshInfoWindowPosition();
			this.infoPanel.show();		
			this.infoPanel.getWorkspaceDiv().style.backgroundColor = '#ffffff';			
			this.infoPanel.getWorkspaceDiv().innerHTML = '';
			var self = this;
			Ajax.post('ajax_pobierz_plik.php',{file:req},function(obj){
				self.infoPanel.getWorkspaceDiv().innerHTML = obj.responseText;
			});
		}
		this.refreshInfoWindowPosition = function(mdx,mdy){
		/*
			this.infoPanel.mainDiv.style.width = this.infoWindowWidth+'px';
			this.infoPanel.mainDiv.style.height = this.infoWindowHeight+'px';
			
			if (document.getElementById('infoFrame'))
			document.getElementById('infoFrame').style.height = (this.infoWindowHeight-47)+'px';
			
			var xe = this.pX(this.infoPanelX);
			var ye = this.pY(this.infoPanelY);
	
			var dx = Math.round((this.infoWindowWidth-21)*0.5);
							
			xe-=(8+32+dx);
			ye-=(14+32+this.infoWindowHeight);
			
			if (mdx!=null) xe+=mdx;
			if (mdy!=null) ye+=mdy;

			this.infoPanel.mainDiv.style.left = xe+'px';
			this.infoPanel.mainDiv.style.top = ye+'px';
			
			this.infoPanelOgonek.style.left = dx+'px';
			this.infoPanelB1.style.width = (dx-16)+'px';
			this.infoPanelB2.style.left = (dx+21)+'px';		
		*/	
		}
		
		this.hideInfoWindow = function(){
			this.infoPanel.hide();
		}
		if (divId!=null){
			iGML.actualMap = this;
			var parentDiv = document.getElementById(divId);
			System.path=obj.folderPath;
			System.start(parentDiv,0);
			System.folderPath = 'images/mapa/';
			System.cancelMouseDown(parentDiv);
			System.disableSelection(parentDiv);
			System.cancelClick(parentDiv);
			
			
			this.levelsScale = new Array();
			

			this.levelsScale[0] = 0.000625;
			this.levelsScale[1] = 0.00125;
			this.levelsScale[2] = 0.0025;
			this.levelsScale[3] = 0.005;
			this.levelsScale[4] = 0.01;
			this.levelsScale[5] = 0.02;
			this.levelsScale[6] = 0.04;
			this.levelsScale[7] = 0.08;
			this.levelsScale[8] = 0.16;
			this.levelsScale[9] = 0.32;
			this.levelsScale[10] = 0.64;
			this.levelsScale[11] = 1.28;
			this.levelsScale[12] = 2.56;
			this.levelsScale[13] = 5.12;
			
			this.events = new Array();
			//silnik
			this.services = new Array();
			this.viewPoint = new iGML.Point(0,0);
			this.scale = 1;
			this.position = new iGML.Point(0,0);
			this.box = new iGML.Box(0,0,0,0);
			this.crs = 'EPSG:2180';
			this.maxScale = 13;
			this.mouseCoordinates = new iGML.Point(0,0);
		
			//kontrolki
			this.mainWindow = new System.Window({backColor:'#888',borderStyle:'NONE' },null);
			this.mainWindow.maximize();
			
			
			
			this.workPanel= new System.Panel({x:1,y:31,
											width:this.mainWindow.getWorkspaceWidth()-2,
											height:this.mainWindow.getWorkspaceHeight()-32-25,
											backColor:'#fff',
											anchorLeft:true,
											anchorRight:true,
											anchorTop:true,
											anchorBottom:true
											},this.mainWindow);
			this.workPanel.mainDiv.style.backgroundImage='url('+obj.folderPath+'images/mapa/white.png)';	
			
			this.mapPanel = new System.Panel({x:0,y:0,
											width:this.workPanel.getWorkspaceWidth(),
											height:this.workPanel.getWorkspaceHeight(),
											backColor:'#fff',
											anchorLeft:true,
											anchorRight:true,
											anchorTop:true,
											anchorBottom:true
											},this.workPanel);
			this.overlayPanel = new System.Panel({x:-1,y:0,
											width:this.workPanel.getWorkspaceWidth(),
											height:this.workPanel.getWorkspaceHeight(),
											backColor:'transparent',
											anchorLeft:true,
											anchorRight:true,
											anchorTop:true,
											anchorBottom:true
											},this.workPanel);		
							
			this.initOverlays();

			this.controlPanel = new System.Panel({x:0,y:0,
											width:this.workPanel.getWorkspaceWidth(),
											height:this.workPanel.getWorkspaceHeight(),
											backColor:'transparent',
											anchorLeft:true,
											anchorRight:true,
											anchorTop:true,
											anchorBottom:true
											},this.workPanel);										
				
			this.statusPanel = new System.Panel({x:1,y:this.mainWindow.getWorkspaceHeight()-25,
											width:this.mainWindow.getWorkspaceWidth()-2,
											height:24,
											backColor:'#eee',
											anchorTop:false,
											anchorRight:true,
											anchorBottom:true
											},this.mainWindow);		
			this.statusPanel.mainDiv.style.backgroundImage='url('+obj.folderPath+'images/mapa/tlo_status.png)';	
			
			this.coordinatesTextBox = new System.TextBox({x:90,y:2,width:185,height:16},this.statusPanel);	
			this.coordinatesTextBox.mainDiv.style.backgroundImage='url('+obj.folderPath+'images/mapa/tlo_text.png)';	
			this.coordinatesTextBox.mainDiv.style.padding = "2px 5px 2px 5px";
			this.coordinatesTextBox.edit.style.fontFamily = 'tahoma,arial';	
			this.coordinatesTextBox.edit.style.fontSize = '11px';	
			this.coordinatesTextBox.edit.style.border='none';	
			this.coordinatesTextBox.edit.style.backgroundColor='transparent';		
			this.coordinatesTextBox.edit.onclick = function(){ alert(obj.scale); }
				
			this.loadedPanel = new System.Panel({x:2,y:0,
											width:22,
											height:22,
											backColor:'transparent'
											},this.statusPanel);	
			this.loadedPanel.mainDiv.style.backgroundImage='url('+obj.folderPath+'images/mapa/loaded.png)';		
			this.loadedPanel.mainDiv.style.backgroundRepeat = 'no-repeat';			
			
			this.loadingPanel = new System.Panel({x:2,y:0,
											width:22,
											height:22,
											backColor:'transparent'
											},this.statusPanel);	
			var imgTmp3 = new Image();
			imgTmp3.src = ''+obj.folderPath+'images/mapa/loading2.gif';
			var imgTmp4 = new Image();
			imgTmp4.src = ''+obj.folderPath+'images/mapa/loadedwrong.gif';
			
			this.loadingPanel.mainDiv.style.backgroundImage='url('+obj.folderPath+'images/mapa/loading2.gif)';	
			this.loadingPanelText = System.createDiv(5,5,null,null,12,12);
			this.loadingPanel.mainDiv.appendChild(this.loadingPanelText);
			this.loadingPanelText.style.fontSize = '10px';
			this.loadingPanelText.style.textAlign='center';
			this.loadingPanelText.style.color='#eef';
			this.loadingPanelText.innerHTML='23';
			this.loadingPanel.hide();
			this.loadingLayersCount = 0;	

			this.layerButtonPanel = new System.Panel({x:25,y:2,
											width:62,
											height:19,
											backColor:'transparent'
											},this.statusPanel);	
			this.layerButtonPanel.mainDiv.style.padding = '2px 4px 2px 4px';
			this.layerButtonPanel.mainDiv.style.cursor = 'pointer';
			this.layerButtonPanel.mainDiv.style.color = '#fff';
			this.layerButtonPanel.mainDiv.style.fontSize='11px';
			this.layerButtonPanel.mainDiv.style.textAlign='center';
			this.layerButtonPanel.mainDiv.innerHTML='<b>Warstwy</b>';	
			this.layerButtonPanel.onmouseover = function(){
				this.mainDiv.style.backgroundColor = '#333';
			}
			this.layerButtonPanel.onmouseout = function(){
				this.mainDiv.style.backgroundColor = 'transparent';
			}		
			this.layerButtonPanel.onmouseup = function(){
				if (obj.menuPanel.visible==false){
					obj.showMenuPanel();	
				} else
				obj.menuPanel.hide();	
			}	
				
			this.statusPanel.addImage(''+obj.folderPath+'images/mapa/status_sep.png',288,0,4,24);	
				
			this.mapPanel.mainDiv.style.zIndex = 0;
			this.overlayPanel.mainDiv.style.zIndex = 1000;
			this.controlPanel.mainDiv.style.zIndex = 2000;
			this.statusPanel.mainDiv.style.zIndex = 3000;
			
			
			System.disableContextMenu(this.controlPanel.mainDiv);	
			System.cancelMouseDown(this.controlPanel.mainDiv);	
			this.createInfoWindow();
			this.initControls();
	
		}
	}

}

window.setInterval(function () {
	if (wielkiOdliczacz != 0){
		wielkiOdliczacz-=100;
		if (wielkiOdliczacz==0) {
			iGML.actualMap.refresh(true);	
		}	
	}
},100);



