/*################################################################################
	D E B U G
################################################################################*/

var debugModus = 0	; // Debugmodus EIN = 1 || AUS = 0

function debug(txt)
{
	if(!debugModus || typeof(console) != "object") { return; }
	else { console.log(txt); }
}
debug("debugModus = true");


/*################################################################################
	$$$
################################################################################*/

// get Elements by Name

function $$$(obj)
{
	var obj = document.getElementsByName(obj);
	obj = (obj.length==1)?obj[0]:obj;
	return obj;
}


/*################################################################################
	F U N C T I O N S
################################################################################*/



/*################################################################################
	init_ddBox()
################################################################################*/

function init_ddBox()
{
	var boxes = $$('.ddBox');
	boxes.each(function(el)
	{
		var childs = el.getChildren();
		var title = childs[0];
		var content = childs[1];
		
		title.content = content;
			
		title.onclick = function()
		{
			if(this.content.style.display == "block")
			{
				this.content.style.display = "none";
				this.style.backgroundImage = "url(/pix/main/open.gif)";
			} else {
				this.content.style.display = "block";
				this.style.backgroundImage = "url(/pix/main/close.gif)";
			}
		}
		title.onmouseover	= function() { this.style.backgroundColor = ""; }
		title.onmouseout	= function() { this.style.backgroundColor = ""; }
	});
}
window.addEvent("load",function(){ init_ddBox(); });


/*################################################################################
	showNavi()
################################################################################*/




/*################################################################################
	ShowDiv()
################################################################################*/

function ShowDiv() {
    document.getElementById("Res").style.display='block';
}

function HideDiv() {
    document.getElementById("Res").style.display='none';
}

/*================================================================================
	onSubmitError()
================================================================================*/
validator.onSubmitError = function(els){
	var str = '<b>'+submiterror__message+'</b><br />';
	$each(els, function(el){
		str += '- '+el.title || el.label.innerHTML.stripTags();
		str += '<br />';
	})
	str += '<a style="display:block; text-align:right" href="javascript:overlay.hide();">'+submiterror__close+'</a>';
	Alert({title:submiterror__title,content:str});
	overlay.opt.onclose = function(){
		els[0].focus()
	}
}

/*================================================================================
Booking Engine
================================================================================*/
function closeBE(){
	$('close').setStyle('display','none');		
}

function stopClosing(e) {
	e.stopPropagation();
}

function setBeIframe(orderId,price) {
	var container = $('beIframeContainer');
	var source		  = 'https://tracking.quisma.com/s.cfs?';
	
	container.empty();
	
	var request_params = $H({
		'qupid': 32202,
		'CID': 1,
		'OrderID': orderId,
		'TotalPrice': price,
		'CurrencySymbol': 'CHF'
	});
	
	request_params.each(function(value,key,hash){
		source += '&'+key+'='+value;
	});
	
	var frame = new Element('iframe',{
		src: source,
		width: 1,
		height: 1,
		frameborder: 0
	});
	
	frame.inject(container);
}

function removeBeIframe() {
	$('beIframeContainer').empty();
}

function showBookingEngine(path,parameters){
	var window_dimensions = window.getScrollSize();
	var be_background     = $('close');
	var be_content        = $('bookingEngineCont');
  var be_container	  = $('beContainer');
	var be_content_dim    = [965,720];
	
	be_background.style.height 	= window_dimensions.y+'px';
	be_content.style.width     	= be_content_dim[0]+'px';
	be_content.style.height    	= be_content_dim[1]+'px';
	be_content.style.left = ((window_dimensions.x-be_content_dim[0])/2)+'px'; 
	
	be_container.style.width     	= be_content_dim[0]+'px';
	be_container.style.height    	= be_content_dim[1]+'px';
	be_container.style.left = ((window_dimensions.x-be_content_dim[0])/2)+'px'; 
	
	window.scrollTo(0,0);
	
	var swfObj = new Swiff ('/reservation/Bookingengine.swf', {
	    id: 'bookingengine',
	    //width: '100%' , 
	    //height: '100%',
	    width: be_content.style.width,
	    height: be_content.style.height,
	    container: 'bookingEngineCont',
	   
	    vars: {
		 	url: path,
	        language: parameters.language,
		 	hotelId: parameters.hotel_id,
	        productId: parameters.product_id,
	        roomId: parameters.room_id,
	        packageCategoryId: parameters.package_category_id,
	        packageId: parameters.package_id,
	        individualOfferCategoryId: parameters.ioffer_category_id,
	        individualOfferId: parameters.ioffer_id
	    }
	});

	if($('bookingEngineCont').addEventListener){
		$('bookingEngineCont').addEventListener('click', stopClosing, false );	
	} else {
		$('bookingEngineCont').attachEvent('onclick', stopClosing);	
	}
	
	$('close').setStyle('display','block');
}

