﻿Import('other/ImageLayer.js');
Import('myLib/native/String.js');
Import('myLib/layers/LayerManager.js');

PageService = {};

Import.clone(Service, PageService);

PageService.openJudaicaPage = function(index){
	var pages = {
		  'szczescie'	: ['http://art.wola.waw.pl', '_blank']
		, 'galeria'		: null
		, 'mapa'		: null
		, 'karcelak'	: null
		, 'judaica'		: null

	}
	if(typeof(pages[index]) != 'undefined' && pages[index] != null){
		PageService.openPage(pages[index][0], pages[index][1]);
	}
	//else{
	//	alert('Było klikać?');
	//}
};

//---

PageService.openPage = function(href, target){
	var href = href.replaceAll('@', '&');
	if(target == '_self')
		document.location.href = href;
	else
		window.open(href);
};

PageService.closeLayer = function(id) {
	LayerManager.close(id);
};

//---

PageService.changeSelects = function(isShow){
	//alert(Browser.browsers.IE+'-'+Browser.version);
	if(Browser.type == Browser.browsers.IE && Browser.version < 7){
		var items = [
			['form_cadences', 'kadencja_id'],
			['form_date', 'date'],
			['form_auction_categories', 'kategoria_id'],
			['form_auction_kinds', 'rodzaj_id'],
			['form_auction_statusses', 'status_id']
		];

		for(var i = 0; i < items.length; i++){
			var form = document.forms[items[i][0]];
			if(form != null){
				var field = form[items[i][1]];
				if(field != null){
					field.style.visibility = isShow ? 'visible' : 'hidden';
				}
			}
		}
	}
};

//---

PageService.openImageById = function(id, description){
	var path = Config.getPathToPage() + Config.file.VIEWER + '?id=' + id;
	ImageLayer.showOnce(path, description);
};

PageService.openImage = function(image, description){
	var path = Config.getPathToData() + image;
	ImageLayer.showOnce(path, description);
};

PageService.openAddedImageById = function(id){
	ImageLayer.showById(id);
};

PageService.setImage = function(id, image, description){
	var path = Config.getPathToData() + image;
	ImageLayer.setValues(id, path, description);
};

//---

PageService.openPrintVersion = function(url){
	var params = {
		left:		20,
		top:		20,
		width: 		640,
		height: 	550,
		scrollbars: 'yes',
		menubar: 'yes'
	};
	Service.openWindow(url, params);
};

PageService.openViewNewsletter = function(){
	var params = {
		left:		20,
		top:		20,
		width: 		580,
		height: 	550,
		scrollbars: 'yes',
		resizable:	'yes'
	};
	var path = Config.PATH + Config.dir.PAGE + Config.file.NEWSLETTER;
	Service.openWindow(path, params);
};

PageService.openFormNotifier = function(){
	var params = {
		left:		100,
		top:		100,
		width: 		520,
		height: 	300
	};
	var path = Config.PATH + Config.dir.PAGE +
	Config.file.NOTIFIER + document.location.search;
	Service.openWindow(path, params);
};
