var list = [];

var xhr = new XMLHttpRequest();
xhr.onload = function(r,a){
   list = list.concat(JSON.parse(this.responseText).options);	
	// TODO   : remove
	list.forEach(function(el){
		if (el.key=="printService") {
			el.value = "http://gis.esimo.ru:8080/print/pdf/";
		} else if (el.key=="basemapUrl") {
			el.value = "http://10.20.135.50:8081/cache/service/wms";
		} 
	});
   list.get = function(id){var l = list.filter(function(el){return el.key==id})[0]; return l ? l.value : undefined;} 
}

xhr.open("GET", OVROOT + "services?service=config&action=getList",false);
xhr.send();

window.CONFIG = {

		  blankImageUrl: OVROOT + "theme/app/img/blank.gif",
		  GPOpenLayersImgPath: OVROOT + "externals/GPOpenLayers/img/",
		  translateUrl: OVROOT + 'translate',
		  metadataUrl: OVROOT + 'metadata',
		  imageReloadAttempts: 2,

		  composer: {
			portalConfig: typeof(OVPORTLETDIV) === 'undefined'?undefined:{
				renderTo: OVPORTLETDIV,
				height: window.WINDOW_STATE=="maximized" ? $ (screen).availHeight*0.85 : 600
			},
			jossoReload: true,
			authWay: false,
			aliaseUrl : OVROOT + '/translate',
			
			metadataUrl: list.get("metadataUrl"),
			
			prickerAliaseUrl:  OVROOT + 'translate',
			prickerGetInfoUrl: 'http://oceanviewer.ru/resources/wms',
			prickerSaveChartUrl: '/save',
			
			restUrl : '/restserver/services/requests',//list.get("restUrl"),//"http://portal.esimo.ru/restserver/services/requests",
	
			username: window.JOSSO_USER,
			//password: 'pedit',
			authUrl: list.get("authUrl"),//"http://oceanviewer.ru/josso/signon/",			
			//proxy: OVROOT.length==0?"proxy/?url=":OVROOT + "cgi-bin/nph-proxy.cgi/00/?url=",			
			proxy: (window.PROXY_URL+"&urltoproxify=" || "") .replace("&amp;","&"),			
			printService: list.get('printService'),//(//"http://oceanviewer.ru/print/pdf/"),//,
			about: {
			  title: "Карта OceanViewer",
			  "abstract": "Сохраненная карта OceanViewer",
			  contact: "Разработчик приложения <a href='http://www.gispro.ru'>ЗАО 'ГИСпроект'</a>"
			},
			defaultSourceType: "gxp_wmscsource",
			downloadFilePageUrl: OVROOT + 'cgi-bin/get_features_24.py',

			jossoLoginUrl: list.get("authUrl")+"/login.do",//'http://oceanviewer.ru/josso/signon/login.do',
			jossoOutUrl: list.get("authUrl")+"/logout.do",//'http://oceanviewer.ru/josso/signon/logout.do',

			uploadUrl: list.get("geoserver")+"/rest",//'http://oceanviewer.ru/resources/rest',
			
			//ovLayer
			ovLayer: ['http://gis.esimo.ru:8080/cache/service/wms/'/*list.get("basemapUrl")*//*"http://oceanviewer.ru/cache/service/wms"*/, "eko_merge_v"],
			//ovLayer: ["http://gis.esimo.ru:8080/cache/service/wms"/*"http://oceanviewer.ru/cache/service/wms"*/, "eko_merge_v"],
			
			graticuleUrl: list.get("graticuleUrl") || "http://gis.esimo.ru:8080/resources/grid/wms",
			graticuleLayer: list.get("graticuleLayer") || "GEOGRID1_Merge",

			sources: {
			  arcgis93: { ptype: "gxp_arcgis93source" },
			  rss: { ptype: "gxp_rsssource" },
			  //google: { ptype: "gxp_googlesource" },
			  //bing: { ptype: "gxp_bingsource" },
			  osm: { ptype: "gxp_osmsource" },
			  baselayer: { ptype: "gxp_olsource" },
			  animation: { ptype: "gxp_animationsource" },
			  gispro: {
				//url: list.get("basemapUrl"),//"http://oceanviewer.ru/cache/service/wms",
				url: "http://gis.esimo.ru:8080/cache/service/wms",
				//url: "http://10.20.135.51:8081/eko",
				title: "Слои картоосновы"
			  }			  
			},

			map: {
			  projection: "EPSG:3857",
			  layers: [
				{
				  source: "baselayer",
				  group: "background",
				  fixed: true,
				  type: "GPOpenLayers.Layer",
				  name: "empty",
				  args: [
					locale.labels.basemaps.blank, {visibility: false}
				  ]
				},
				/*{
				  source: "bing",
				  title: locale.labels.basemaps.bingRoad,
				  name: "Road",
				  group: "background"
				},
				{
				  source: "bing",
				  title: locale.labels.basemaps.bingAerial,
				  name: "Aerial",
				  group: "background"
				},
				{
				  source: "bing",
				  title: "Bing гибрид",
				  title: locale.labels.basemaps.bingAerialWithLabels,
				  group: "background"
				},*/
				{
				  source: "osm",
				  title: locale.labels.basemaps.osm,
				  name: "mapnik",
				  group: "background"
				},
				{
				  source: "gispro",
				  title: locale.labels.basemaps.ekoBlank,
				  name: "eko_blank",
				  group: "background",
				  //args: [null, {alwaysInRange: true}],
				  queryable: false
				},
				{
				  source: "gispro",
				  title: locale.labels.basemaps.eko,
				  name: "eko_merge",
				  group: "background",
				  //args: [null, {alwaysInRange: true}],
				  queryable: false
				}				
			  ],
			  center: [0, 0],
			  zoom: 2
			}
		  }
		};
		
/*if (window.JOSSO_USER!="null") {
	window.CONFIG.composer.sources.editable = {
		url: list.get("geoserverRemoteURL")+"/userlayers/wms",//"http://oceanviewer.ru/resources/userlayers/wms",
		restUrl: list.get("geoserverRemoteURL")+"/rest",//"http://oceanviewer.ru/resources/rest",
		title: "Маркеры3"
	}
	window.CONFIG.composer.map.layers.push({
	  name:"userlayers:pointlayer",
	  source:"editable",
	  group:'editable',
	  cached: false,
	  visibility: false
	});
	window.CONFIG.composer.map.layers.push({
	  name:"userlayers:linelayer",
	  source:"editable",
	  group:'editable',
	  cached: false,
	  visibility: false
	});
	window.CONFIG.composer.map.layers.push({
	  name:"userlayers:polylayer",
	  source:"editable",
	  group:'editable',
	  cached: false,
	  visibility: false
	});
}*/
