	
	var TourManager = {
		
		url : '/wp-content/plugins/tour-manager/ajax.php',
		li : '<li class="my-tour-li-TOUR_ID"><a href="/?p=TOUR_ID" title="TOUR_TITLE" class="tour-list">TOUR_TITLE</a><a href="javascript:;" onclick="TourManager.Delete(\'TOUR_ID,TOUR_TITLE\');" title="Delete" class="tour-del">del</a></li>',
		li_order : '<li class="w300 my-tour-li-TOUR_ID"><input onclick="TourManager.Delete(\'TOUR_ID,TOUR_TITLE\');" type="checkbox" value="TOUR_ID,TOUR_TITLE" class="sel" name="selected_tours[]" checked="checked"/><label class="t-label">TOUR_TITLE</label> <input type="text" name="selected_dates[]" id="tour-date-TOUR_ID" value="" class="w60"/><img src="/wp-content/themes/mybp/images/calendar.png" alt=""/></li>',
		option : '<option value="" onclick="TourManager.Add(\'TOUR_ID,TOUR_TITLE\',this);">TOUR_TITLE</option>',
		
		Add : function(string,obj)
		{
			jQuery.post(TourManager.url, { action: 'add', id: string }, function(data){
				if(data == 'true'){
					string = string.split(',');
					jQuery('#my-tour-list').append( TourManager.li.replace(/TOUR_ID/gi,string[0]).replace(/TOUR_TITLE/gi,string[1]) );
					if(jQuery('#my-tour-box').css('display') == 'none'){
						jQuery('#my-tour-box').css('display','block');
					}
					/* Order page... */
					if( obj )
					{
						jQuery(obj).remove();
						jQuery('#number-of').before( TourManager.li_order.replace(/TOUR_ID/gi,string[0]).replace(/TOUR_TITLE/gi,string[1]) );
						$('#tour-date-'+string[0]).datepick();				
					}
				}
				else if( data == 'selected'){
					alert('Tour has been added at early.');
				}
				else {
					alert('Error! Please try again later.');
				}
			});				
		},
		
		Delete : function(string,obj)
		{			
			if (confirm('Are you sure delete "'+string.split(',')[1]+'" tour from the list?')) {
				jQuery.post(TourManager.url, {
					action: 'delete',
					id: string
				}, function(data){
					if (data == 'true') {
						string = string.split(',');
						jQuery('.my-tour-li-' + string[0]).remove();
						if (jQuery('#additional-programs')) {
							jQuery('#additional-programs').append(TourManager.option.replace(/TOUR_ID/gi, string[0]).replace(/TOUR_TITLE/gi, string[1]));
						}
					}
					else 
						if (data == 'true-empty') {
							string = string.split(',');
							jQuery('.my-tour-li-' + string[0]).remove();
							if (jQuery('#additional-programs')) {
								jQuery('#additional-programs').append(TourManager.option.replace(/TOUR_ID/gi, string[0]).replace(/TOUR_TITLE/gi, string[1]));
							}
							jQuery('#my-tour-box').css('display', 'none');
						}
						else {
							alert('Error! Please try again later.');
						}
				});
			}
		}
		
	}	
	
	
	
	/*
	 *    Űrlap ellenőrzés
	 * 	  written by Bodonyi László
	 */
	function validateTourForm()
	{
		var filled = true, validEmail = true, accepted = true, focusThis = false;
							
		$("#orderform .required-field").each(function(index,item)
		{					
			if (filled == true) {
											
				item = jQuery(item);		
				
				// Beviteli mezők ellenőrzése	
				if (!item.val()) {
					filled = false;
				}
				
				// Ha e-mail címet vár a beviteli mező, akkor a helyesség ellenőrzése
				if (item.attr('name').search('email') > -1) {
					if (validEmail) {
						validEmail = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/.test(item.val());
					}
				}
				
				// Ha checkbox-ot találtunk, pipálás ellenőrzése
				if (item.attr('type') == 'checkbox' && !item.attr('checked')) {
					accepted = false;
				}
				
				// Ha bármi hiba történt, beviteli mező megjelölése 'error' class-szal
				if ((!filled || !accepted || !validEmail) && !focusThis) {
					focusThis = item;
					if (item.attr('type') != 'checkbox') {
						item.parent().addClass('error');
					}
				}
				
			}
			
		});																				
		
		// Ha minden rendben van...
		if(filled && validEmail && accepted)
		{ 					
			return true;		
		}
		
		// Ha hiba történt
		else 
		{			
			if(!filled && validEmail){ alert('A *-gal jelölt mezők kitöltése kötelező!'); } 
			else if( !validEmail ){ alert('Please provide your (correct) email address! '); }
			else { alert('Please grant MyBudapest the right to contact according to the data protection terms!'); }			
			focusThis.focus();
			return false;
		}
	}
	
	
	
