/*
 * To get position fixed work in IE you have to use:
 *	<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 *	<html xmlns="http://www.w3.org/1999/xhtml">
 */

var DoReserve_Widget = {
	server: '',
	domain: 'doreserve.com',
	preinit: false,
	position: 'right',
	color: '#ffc000',
	top: '30%',
	
	addButton: function(btnId) {
		var fileref=document.createElement("link")
		fileref.setAttribute("rel", "stylesheet")
		fileref.setAttribute("type", "text/css")
		fileref.setAttribute("href", 'http://' + this.server + '/common/css/widget_client.css');
		document.getElementsByTagName("head")[0].appendChild(fileref);

		if(!btnId) {
			this.buttonNode = document.createElement('div');
			this.buttonNode.id = '_doreserveWidgetButton';
			this.styleButton();
			document.body.appendChild(this.buttonNode);
		}
		else {
			this.buttonNode = document.getElementById(btnId);
		}
		
		var instance = this;
		this.buttonNode.onclick = function() {instance.showFrame();};
		
		if(this.preinit) {
			this.showFrame();
		}
	},

	styleButton: function() {
		var imagePath = 'http://' + this.server + '/common/images/widget/';
		imagePath += this.domain;
		imagePath += '-' + this.position + '.png';
		
		this.buttonNode.style.backgroundImage = 'url(' + imagePath + ')';
		
		this.buttonNode.style.left = 'auto';
		this.buttonNode.style.right = 'auto';
		
		this.buttonNode.style.backgroundColor = this.color;
		this.buttonNode.style.top = this.top;
		this.buttonNode.style[this.position] = '0px';
	},
	
	showFrame: function() {
		if(!this.iframeNode) {			
			this.iframeNode = document.createElement('div');
			this.iframeNode.id = 'doreserve_widget_container';
			this.iframeNode.className = '_doreserveWidgetContainer';
			
			this.frame = document.createElement('iframe');
			this.frame.src= 'http://' + this.server + '/sheduler/manage?type=widget&layout=widget';
			this.frame.scroll = 'no';
			this.frame.frameBorder = 'no';
			this.frame.width = '754';
			this.frame.height = '630';
			
			this.iframeNode.appendChild(this.frame);
			
			var closeButton = document.createElement('img');
			closeButton.src = 'http://' + this.server + '/common/images/close.png';
			closeButton.className = '_doreserveCloseButton';
						
			var instance = this;
			closeButton.onclick = function() {instance.hideFrame();};
			this.iframeNode.appendChild(closeButton);
			
			if(this.preinit) {
				this.iframeNode.style.display = 'none';
				//this.hideFrame();
			}
			
			document.body.appendChild(this.iframeNode);
		}
		else {
			this.iframeNode.style.display = 'block';
		}
	},
	
	hideFrame: function() {
		if(this.iframeNode) {
			this.iframeNode.style.display = 'none';
		}
	}
};

var DoReserve_Widget_Custom = {
	server: '',
	domain: 'doreserve.com',
	preinit: false,
	className: '',
	text: 'Doreserve',
	
	addButton: function() {
		var fileref=document.createElement("link")
		fileref.setAttribute("rel", "stylesheet")
		fileref.setAttribute("type", "text/css")
		fileref.setAttribute("href", 'http://' + this.server + '/common/css/widget_client.css');
		document.getElementsByTagName("head")[0].appendChild(fileref);
	
		var id = '_doreserveWidgetCustomButton' + Math.random() * 1000;
		document.write('<div id="' + id + '"></div>');
	
		this.buttonNode = document.getElementById(id);
		
		this.styleButton();
		
		var instance = this;
		this.buttonNode.onclick = function() {instance.showFrame();};
		
		if(this.preinit) {
			this.showFrame();
		}
		DoReserve_Widget.server = this.server;
		DoReserve_Widget.domain = this.domain;
		DoReserve_Widget.preinit = this.preinit;
	},
	
	styleButton: function() {
		this.buttonNode.className = this.className;
		this.buttonNode.innerHTML = this.text;
	},
	
	showFrame: function() {
		DoReserve_Widget.showFrame();
	},
	
	hideFrame: function() {
		Reserve_Widget.hideFrame();
	}
};
