function CreateShortList() {

	var JSONRequest = new Request.JSON({url: '/config/shortlist_build.php', 
		onComplete: function(res){
			if (res.items.length>0) { 
				var resbox = $('shortlist_item_container');
				curr_count=res.items.length;
				if (curr_count==1) $('shortlist_headline').innerHTML='(1 offer)';
				else $('shortlist_headline').innerHTML='('+curr_count+' offers)';
	res.items.each (function(curr_item) {
		//we need to do this in order to prevent from adding empty boxes...
		if (curr_item.title!=null && curr_item.title!=undefined) {
			if (document.getElementById('sl'+curr_item.optid)==null) {
				var el = new Element('div', {'id': 'sl'+curr_item.optid,'class': 'shortlist_item'});
				var cl= new Element('div', { 'class': 'shortlist_close'});
				var close_button = new Element('span', {'html':'<a href="javascript:RemoveFromShortList(\''+curr_item.optid+'\');"><img src="/images/del_icon.gif" width="17" height="17" alt="remove this item from your wishlist" title="remove this item from your wishlist" border="0" /></a>'}).inject(cl);
				cl.inject(el);
				var title_box	= new Element('div', { 'class': 'shortlist_line2'});
				var title_label = new Element('span', {'html':curr_item.title}).inject(title_box);
				title_box.inject(el);

				var dets_box= new Element('div', { 'class': 'shortlist_line'});
				var ofdet='<b>'+curr_item.dep_date+'</b><br />departs <b>'+curr_item.airport+'</b>';
				
				if (curr_item.hotel!='') {
					ofdet+='<br />'+curr_item.hotel;
					if (curr_item.board_basis!=null) ofdet+=' (<b>'+curr_item.board_basis+'</b>)';
					ofdet+='<br />'+curr_item.roomtype+' (<b>'+curr_item.adults+'</b> adults, <b>'+curr_item.children+'</b> children)';
				}
				else	ofdet+='<br /><b>'+curr_item.adults+'</b> adults, <b>'+curr_item.children+'</b> children';

				var dets_label = new Element('span', {'html':ofdet}).inject(dets_box);
				dets_box.inject(el);

				var price_box= new Element('div', { 'class': 'shortlist_line3'});
				var price_label = new Element('span', {'html':'Price: &pound;'+curr_item.total_price}).inject(price_box);
				price_box.inject(el);

				el.inject(resbox);
				new Fx.Reveal($(el),{duration:'long'}).reveal();
				
			}
		}
	});
	}
	}}).get();

}

function AddToShortlist(optid) {
	if (optid!=null && optid!='undefined') {
		var JSONRequest = new Request.JSON({url: '/config/shortlist_add.php', 
		onComplete: function(res){
		if (res.item.length>0) { 
			var curr_item=res.item[0];
			var curr_count=curr_item.curr_count;

			$('line5').removeClass('non_act_txt');
			$('line5').addClass('act_txt');



		if (curr_count!=undefined && curr_count<=3) {

		if (curr_count==1) {
		// first element on the list, we need to reveal the box...
		var sl_move=new Fx.Morph('shortlist_container', {
			   duration: 600,
			    transition: Fx.Transitions.Sine.easeOut
			}).start({    'bottom': -2+'px'});
		var shortlist_status=1;
		$('shortlist_switch').toggleClass('shortlist_switch_close');

		// we need to show enquiry_button
		new Fx.Reveal($('shortlist_enquiry_button'),{duration:'short'}).reveal();
		}


			var resbox = $('shortlist_item_container');

		if (curr_count==1) $('shortlist_headline').innerHTML='(1 offer)';
		else $('shortlist_headline').innerHTML='('+curr_count+' offers)';

		//we need to do this in order to prevent from adding empty boxes...
		if (curr_item.title!=null && curr_item.title!=undefined) {
			if (document.getElementById('sl'+curr_item.optid)==null) {
				var el = new Element('div', {'id': 'sl'+curr_item.optid,'class': 'shortlist_item'});
				var cl= new Element('div', { 'class': 'shortlist_close'});
				var close_button = new Element('span', {'html':'<a href="javascript:RemoveFromShortList(\''+curr_item.optid+'\');"><img src="/images/del_icon.gif" width="17" height="17" alt="remove this item from your wishlist" title="remove this item from your wishlist" border="0" /></a>'}).inject(cl);
				cl.inject(el);
				var title_box	= new Element('div', { 'class': 'shortlist_line2'});
				var title_label = new Element('span', {'html':curr_item.title}).inject(title_box);
				title_box.inject(el);

				var dets_box= new Element('div', { 'class': 'shortlist_line'});
				var ofdet='<b>'+curr_item.dep_date+'</b><br />departs <b>'+curr_item.airport+'</b>';
				
				if (curr_item.hotel!='') {
					ofdet+='<br />'+curr_item.hotel;
					if (curr_item.board_basis!=null) ofdet+=' (<b>'+curr_item.board_basis+'</b>)';
					ofdet+='<br />'+curr_item.roomtype+' (<b>'+curr_item.adults+'</b> adults, <b>'+curr_item.children+'</b> children)';
				}
				else	ofdet+='<br /><b>'+curr_item.adults+'</b> adults, <b>'+curr_item.children+'</b> children';

				var dets_label = new Element('span', {'html':ofdet}).inject(dets_box);
				dets_box.inject(el);

				var price_box= new Element('div', { 'class': 'shortlist_line3'});
				var price_label = new Element('span', {'html':'Price: &pound;'+curr_item.total_price}).inject(price_box);
				price_box.inject(el);

				el.inject(resbox);
				new Fx.Reveal($(el),{duration:'long'}).reveal();

			}
		}
		}
		else {
			alert('You can have maximum of 3 offers on your shortlist!');
			return false;
		
		}
		}
	}}).get({'optid':optid});
   }
}


function RemoveFromShortList(optid) {
	if (optid!=null && optid!='undefined') {
		var JSONRequest = new Request.JSON({url: '/config/shortlist_remove.php', 
		onComplete: function(res){
		if (res.item.length>0) { 
			var remchain=new Chain();

			var curr_item=res.item[0];
			var curr_count=curr_item.curr_count;

	// there are 4 functions in this chain: removing element, changing headline contents, removing enquiry button (when necessary), hiding shortlist box (when necessary)

				var otd='sl'+optid;
				var remitem=function() {$(otd).nix({duration:'long'},true); };

				switch (curr_count) {
					case "0" : {
						var headline="&nbsp;";
						break;
					}
					case "1" : {
						var headline="(1 offer)";
						break;
					}
					default : {
						var headline="("+curr_count+" offers)";
						break;
					}
				}
				
				var changeheadline=function() {$('shortlist_headline').innerHTML=headline;}
		
			var eb_hide= function() {new Fx.Reveal('shortlist_enquiry_button', {
				    duration: 300,
				    transition: Fx.Transitions.Sine.easeOut
				}).dissolve(); };

			var sl_hide= function() {new Fx.Morph('shortlist_container', {
				    duration: 600,
				    transition: Fx.Transitions.Sine.easeOut
				}).start({    'bottom': -220+'px'}); };


			var switch_button=function() {$('shortlist_switch').toggleClass('shortlist_switch_close');};
			remchain.chain(remitem).chain(changeheadline).chain(eb_hide).chain(sl_hide).chain(switch_button);

			remchain.callChain.delay(100,remchain);
			remchain.callChain.delay(300,remchain);

		if (curr_count==1) $('shortlist_headline').innerHTML='(1 offer)';
		else $('shortlist_headline').innerHTML='('+curr_count+' offers)';

			if (curr_count==0) {
	
// remove enquiry button here
// hide shortlist box

				remchain.callChain.delay(200,remchain);
				remchain.callChain.delay(800,remchain);
				remchain.callChain.delay(100,remchain);

				var shortlist_status=1;
			}
		}
	}}).get({'optid':optid});
   }	
}


function RemoveFromShortListFinal(optid) {
	if (optid!=null && optid!='undefined') {
		var JSONRequest = new Request.JSON({url: '/config/shortlist_remove.php', 
		onComplete: function(res){
		if (res.item.length>0) { 
			var curr_item=res.item[0];
			var curr_count=curr_item.curr_count;

			var otd='slf_'+optid;
			$(otd).nix({duration:'long'},true); 
			if (curr_count==0) {
				window.location.href='/Contact/';
			}
		}
	}}).get({'optid':optid});
   }

}


function ShowDesc(did) {
	if (did) {
		elem="desc_"+did;
		var showdesc = new Fx.Scroll(window,{
			duration:'3000'
		});
		showdesc.toElement(elem).chain(function() {
			$(elem).tween('background-color','#eea9af','#6e000a');
		});
	}
}

function getNewXMLHttpRequest() {
  var obj;
    try {
      obj = new ActiveXObject('Microsoft.XMLHTTP');
    }
    catch(e) {
      try {
        obj = new XMLHttpRequest();
      }
      catch (e) {
        obj = false;
      }
    }
    return obj;
}


//------------------------------------------------------------------------------------------------------------------

function SubmitPartyBox(cma,children_allowed,subpage, title, duration, oid) {

	var adult_ages=new Array();
	var children_ages=new Array();
	var adults=document.getElementById('adults_selector').options[document.getElementById('adults_selector').selectedIndex].value;
	var children=(children_allowed==1) ? document.getElementById('children_selector').options[document.getElementById('children_selector').selectedIndex].value : 0;
	var err=0;
	for (i=0;i<adults;i++) {
		var aobj="adult_age"+i;
		ab="ab"+i;
		if (subpage==1)  $(ab).removeClass('active');
		else  $(ab).removeClass('active2');
			if ($(aobj).value=="") {
				err++; 
				if (subpage==1)  $(ab).toggleClass('active',true);
				else  $(ab).toggleClass('active2',true);
			 }
			else {
				if($(aobj).value<cma) {
					err++;
					if (subpage==1)  $(ab).toggleClass('active',true);
					else  $(ab).toggleClass('active2',true);
					alert('Adult must be at least '+cma+' years old!');
				}
				else {
					 adult_ages[adult_ages.length]=$(aobj).value;
				}
			}
	}

	for (i=0;i<children;i++) {
		var cobj="child_age"+i;
		cb='cb'+i;
		if (subpage==1)  $(cb).removeClass('active');
		else  $(cb).removeClass('active2');

		if ($(cobj).value=="" || $(cobj).value==0)  {
				err++; 
				if (subpage==1)  $(cb).toggleClass('active',true);
				else  $(cb).toggleClass('active2',true);
			 }

		else {
				 if ($(cobj).value>cma){
					if (subpage==1)  $(cb).toggleClass('active',true);
					else  $(cb).toggleClass('active2',true);
					err++;
					alert('Child must be maximum '+cma+' years old!');
				}
				else {
					children_ages[children_ages.length]=$(cobj).value;
				}
		}
	}

	if (err==0) {
		a_ages=adult_ages.join('|'); 
		c_ages=children_ages.join('|');
		var JSONRequest_up = new Request.JSON({url: '/config/update_partysize.php', 
			onComplete: function(res){ 
				link="/Offers/"+duration+"/"+title+"/"+oid+"/";
				window.location.href=link;

		}}).send({
			method: 'get',
			data: 'adults='+adults+'&children='+children+'&adult_ages='+a_ages+'&children_ages='+c_ages
		});

		


	}
	else return false;
}


function GetOfferDetails(offer_id,hotel_id,cna, airport_id,cma) {
	var urlink="/partysize.php?offer_id="+offer_id+"&hotel_id="+hotel_id+"&airport_id="+airport_id+"&cma="+cma+"&children_allowed="+cna;
	MOOdalBox.open( 
		urlink,
		"",
		"460 450"
	);
}

function GetHotelDetails(hotel_id) {
	var urlink="/hotel_details.php?hotel_id="+hotel_id;
	MOOdalBox.open( 
		urlink,
		"",
		"670 650"
	);
}

function ChangeResort() {
	var reslink=$('sel_resort').getSelected();
	document.getElementById("resorts").innerHTML='<span class="big">Please wait...</span>';
	if (reslink[0].value!='')	location.href=reslink[0].value;
}
function ChangeDuration() {
	var reslink=$('sel_duration').getSelected();
	document.getElementById("durations").innerHTML='<span class="big">Please wait...</span>';
	if (reslink[0].value!='')	location.href=reslink[0].value;
}

function ChangeOffer() {
	var reslink=$('sel_offer').getSelected();
	document.getElementById("offers_selector").innerHTML='<span class="big">Please wait...</span>';
	if (reslink[0].value!='')	location.href=reslink[0].value;
}

function showagelists_adults(subpage) {
		var seladults=document.getElementById('adults_selector').options[document.getElementById('adults_selector').selectedIndex].value;
		if (seladults>0) {
		$('adults_box').reveal();
			for (i=0;i<5;i++) {
				var caelem='ab'+i;
				if (subpage==1)  $(caelem).removeClass('active');
				else  $(caelem).removeClass('active2');
				(i<seladults) ? $(caelem).reveal() : $(caelem).dissolve();
	}
	}
	else {
			$('adults_box').dissolve();
	}
}

function showagelists_children(subpage) {
		var selchildren=document.getElementById('children_selector').options[document.getElementById('children_selector').selectedIndex].value;
		if (selchildren>0) {
		$('children_box').reveal();
			for (i=0;i<5;i++) {
				var caelem='cb'+i;
				if (subpage==1)  $(caelem).removeClass('active');
				else  $(caelem).removeClass('active2');
				(i<selchildren) ? $(caelem).reveal() : $(caelem).dissolve();
			}
		}
		else {
			$('children_box').dissolve();
		}
}



function disableIt(obj) { 	obj.disabled = !(obj.disabled); }



function SubscribeMe() {
	var subemail=$('sub_email').value;
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
  	 if(reg.test(subemail) == false) {
	      alert('Invalid Email Address!');
	   }
	else {
	var subrequest = getNewXMLHttpRequest();
	 geturl='/config/subscribe.php?subemail='+subemail;
		subrequest.open('GET', geturl);
		subrequest.onreadystatechange=function() {
		  if (subrequest.readyState==4) {
		           var response = subrequest.responseText;
				if (response=="0") { alert('An error occured. Please check your email address.');}
				else if (response=="1") { alert('Thank you for subscribing to our newsletter.'); $('sub_email').value='';}
				else if (response=="2") { alert(subemail+' already exists in our database!'); $('sub_email').value='';}
		 }
		}
    		subrequest.send(null);	

	}

}


function check_email() {
	emcheck=document.newsletter_form.sub_email.value;
	
	if (!(emcheck.indexOf(".") > 2) || !(emcheck.indexOf("@") > 0)) {
		alert ('Please type proper e-mail address!');
		return false;
	}
	else {
		document.newsletter_form.submit(); 
	}
	
}
function number_format( number, decimals, dec_point, thousands_sep ) {
    var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
    var d = dec_point == undefined ? "." : dec_point;
    var t = thousands_sep == undefined ? "," : thousands_sep, s = n < 0 ? "-" : "";
    var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
    
    return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
}


 function showpicture(url,width, height)
	{
        LeftPosition=(screen.width)?(screen.width-width)/2:100;
     TopPosition=(screen.height)?(screen.height-height)/2:100;
        var Win = window.open(url,'showpic','width=' + width + ',height=' + height + ',top='+TopPosition+',left='+LeftPosition+',resizable=0,scrollbars=no,menubar=no,toolbar=no,status=no')
	}


 function openpopup(url,width, height,scrollable)
	{
        LeftPosition=(screen.width)?(screen.width-width)/2:100;
     TopPosition=(screen.height)?(screen.height-height)/2:100;
if (scrollable==0 || scrollable=="")
        var Win = window.open(url,'showpic','width=' + width + ',height=' + height + ',top='+TopPosition+',left='+LeftPosition+',resizable=0,scrollbars=no,menubar=no,toolbar=no,status=no')
else 
        var Win = window.open(url,'showpic','width=' + width + ',height=' + height + ',top='+TopPosition+',left='+LeftPosition+',resizable=0,scrollbars=yes,menubar=no,toolbar=no,status=no')

	}

