/************************************************************************
 * 		Schnipsel für die Anzeige einzelner grafischer Elemente			*
 * 		C 2008 by René Lange & Thomas Müller & Steve Rohrlack @ mindbox	*
 ************************************************************************/
 
// Clearer für Floats
var Clearer = new Class({
 	initialize : function() {
 		return new Element('div',{'class':'clear'});
 	}
});

// Löschen-Button
var RemoveButton = new Class({
 	initialize : function(id,text,sId){
		return new Element('div',{'class':'removeButton'})
				.adopt(new Element('a',{'class':'tpRemoveItem','name':id,'id':'tpRemoveItem_' + (sId ? sId : id),'href':'#',title:'Remove Entry'}).set('text',text)
		);
	}
});

// Details-Button
var DetailButton = new Class({
 	initialize : function(entry,text, sId){
		var	href = window.location.host;
		if (entry.sg_entry_type == 'offer') {
			href = href + 'Offer-and-Packages/Offer-and-Packages-Details.html?id=';
		} else {
			href = href + 'Service-Provider/Service-Provider-Details.html?id='
		}
		href = href + entry.id_sg_entry;
		
		return new Element('div',{'class':'detailButton'})
				.adopt(new Element('a',{'class':'tpShowDetails','id':'tpShowDetails_' + (sId ? sId : entry.id_entry) ,'name':entry.id_entry,'href':href,'target':'_blank',title:'Show Details of Entry'}).set('text',text)
		);
	}
});

// Bearbeiten-Button
var EditButton = new Class({
 	initialize : function(sgId){
		return new Element('div',{'class':'editButton'})
				.adopt(new Element('a',{'class':'tpEditTour','name':sgId,'href':'#'})
				.adopt(new Element('span').setText('Edit Tour'))
		);
	}
});

// Löschen-Button
var DeleteButton = new Class({
 	initialize : function(sgId){
		return new Element('div',{'class':'deleteButton'})
				.adopt(new Element('a',{'class':'tpDeleteTour','name':sgId,'href':'#'})
				.adopt(new Element('span').setText('Delete Tour'))
		);
	}
});

// Tour wechseln Button
var TourChangeButton = new Class({
 	initialize : function(sgId){
		return new Element('div',{'class':'tpTourChangeDiv'})
				.adopt(new Element('input',{'class':'tpTourChangeButton','name':'tpTourChangeButton','id':'tpTourChangeButton','href':'#'})
		);
	}
});

// Tourwahl im eingeloggten Modus
var ChangeToursSelection = new Class({
 	initialize : function(tours, entry){
		// Select-Box für die Auswahl einer Tour zu einem Entry
		var tourSelector = new Element('select',{'id':'tpChangeTour','class':'tpChangeTour','name':'tpChangeTour'});
		
		var i = 0;
		var id = TourPlanner.instance.currentTour.id_tour; 
		
		// Neue Tour
		var tourSelOpt = new Element('option',{'value':('new')}).setText('New Tour');
		if (id == 'new') {
			tourSelOpt.setProperty('selected','selected');		
		}
		tourSelector.adopt(tourSelOpt);
		i = i+1;
		
		// Touren einlesen
		tours.each(function(tour){
			var tourSelOpt = new Element('option',{'value':(tour.id_tour)}).set('text', tour.title);
			if (id == tour.id_tour) {
				tourSelOpt.setProperty('selected','selected');		
			}
			tourSelector.adopt(tourSelOpt);
			i = i + 1;
		}.bind(this));
		
		tmpEl2 = new Element('div',{'id':'status'});
		var subTmpEl2 = new Element('input',{'id':'deleteTour','type':'submit','value':'Delete current tour','class':'sub'});
		tmpEl2.adopt(subTmpEl2);

		tmpEl = new Element('div',{'id':'status'});
		var subTmpEl = new Element('input',{'id':'tourDateSub','type':'submit','value':'Save current tour','class':'sub'});
		tmpEl.adopt(subTmpEl);

		// erstellen des formulars
		return new Element('div',{'class':'options'})
				// the selector for the tour
				.adopt(tourSelector)
				.adopt(new TourChangeButton())
				.adopt(new Element('div',{'class':'separator'}))
				.adopt(tmpEl)
				.adopt(new Element('div',{'class':'separator floatr'}))
				.adopt(tmpEl2)
		;
	}	
 });

// Sortierpfeile im Planner
var SortingOptions = new Class({
 	initialize : function(id){
		var dirs = ['moveUp','moveDown'];
		var texts = ['UP', 'DOWN'];
		var opts = new Element('div',{'class':'sortingOptions'}).set('text','Arrange');
		dirs.each(function(dir,i){
				opts.adopt(new Element('a',{'class':'tp'+dir.substr(0,1).toUpperCase()+dir.substr(1),'name':id,'href':'#'}).set('text',texts[i]));
				if(i < dirs.length-1){
					opts.adopt(new Element('div',{'class':'sepHor'}));
				}
		});
		return opts;
	}
 });

// Optionen für die Entries im Planner
var OptionsForm = new Class({
 	initialize : function(day, entry, noDays, selDay, sId){
		
		// Select-Box für die Auswahl des Tages zu einem Entry
		var daySelector = new Element('select',{'id':'tpDayOfEntry_' + (sId ? sId : entry.id_entry) ,'class':'tpDayOfEntry','name':entry.id_entry});		
		// Tour Start
		var daySelOpt = new Element('option',{'value':(-1)}).setHTML('Start');
			daySelector.adopt(daySelOpt);
		
		for (i = 1; i <= noDays; i++) {
			var daySelOpt = new Element('option',{'value':(i-1)}).setText('day ' + i);
			if(i-1 == selDay){
				daySelOpt.setProperty('selected','selected');
			}
			daySelector.adopt(daySelOpt);
		}
		
		// Aufenthaltsdauer formatieren - h:mm 
		var stayTime = new Object();
		var value = parseInt(entry.stayTime);

		var staySelector = new Element('select',{'id':'tpStayTimeOfEntry_' + (sId ? sId : entry.id_entry),'class':'tpStayTimeOfEntry','name':entry.id_entry,'value':stayTime});
		for(i=0; i <= 7; i +=0.5){
			staySelector.adopt(new Element('option',{ 'value':i*60}).set('text', i.toString().replace(/\./,',') +' h'));
		}
		staySelector.set('value',value);
		
		// Erstellen des Formulars
		return new Element('div',{'class':'options'})
				// the selector for the day
				.adopt(new Element('label',{'for':'tpDayOfEntry_'+entry.id_entry}).setText('Move to'))
				.adopt(daySelector)
				.adopt(new Clearer())
				// the input field for the duration of stay at a location
				.adopt(new Element('label',{'for':'tpStayTimeOfEntry_'+entry.id_entry}).setText('Stay'))
				.adopt(staySelector)
		;
	}
});
