if (window.ActiveXObject) window.ie = window[window.XMLHttpRequest ? 'ie7' : 'ie6'] = true;
var agent = navigator.userAgent.toLowerCase();
window.ie_old = false;
var pos_ie = agent.indexOf("msie");
if (pos_ie != -1) {
	var ver_ie = agent.charAt(pos_ie + 1 + 4);
	if (ver_ie < 7){
		window.ie_old = true;
	}
}

var MessageBox = {};
MessageBox = Class.create();
MessageBox.prototype = {
	initialize: function() {
	    var id;
	    var optionIndex = 0;	    
	    id = "window_" + new Date().getTime();
	      
	    if ($(id)){
			alert("Window " + id + " is already registered in the DOM! Make sure you use setDestroyOnClose() or destroyOnClose: true in the constructor");
			return;
		}

	    this.options = Object.extend({
			modal:				false,
			className:			"alphacube",
			parent:				document.body,
			typeWin:			"content",
			scrolling:			false,
			closeByOverlay:		false,
			autopos:			true,
			pageSize:			null,
			url:				null,
			title:				null,
			closable:			null,
			width:				200,
			height:				300,
			top:				0,
			left:				0,
			bottom:				0,
			right:				0,
			opacity:			1,
			onCloseFunc:		null,
			external_var:		null,
			nameWin:				null,
			destroyOnClose:		true
	    }, arguments[optionIndex] || {});

		this.id = id;
		this.init = true;	
		this.width = this.options.width;
		this.height = this.options.height;
		this.top = this.options.top;
		this.left = this.options.left;
		this.bottom = this.options.bottom;
		this.right = this.options.right;
		this.title = this.options.title;
		this.typeWin = this.options.typeWin;
		this.pageSize = this.options.pageSize;
		this.scrolling = this.options.scrolling;
		this.closable = this.options.closable;
		this.nameWin = this.options.nameWin;
		
		if (this.options.modal) {
			this.createOverlay(this.id, this.options.className);
			if (this.options.closeByOverlay){
				this.clickclose = this.close.bindAsEventListener(this);
				Event.observe(this.overlay, "click", this.clickclose);
			}
		}
		
		this.element = this.createWindow(id);	
		this.eventResize = this._scroll_resize.bindAsEventListener(this);
		this.content = $(this.element.id + "_content");
		this.content_div = $(this.element.id + "_content_div");
		this.setClosable(this.closable);
		Event.observe(window, "resize", this.eventResize);
		Event.observe(window, "scroll", this.eventResize);
			
		if (this.width && this.height)
			this.setSize(this.options.width, this.options.height);
			
		WindowsBox.register(this, 'msg');
	},

	destroy: function() {					
		if (this.options.closeByOverlay && this.options.modal)
			Event.stopObserving(this.overlay, "click", this.clickclose);
		
		Event.stopObserving(window, "resize", this.eventResize);
		Event.stopObserving(window, "scroll", this.eventResize);
		if (this.options.modal) {
			Element.remove(this.overlay);
		}
			
		if (this.options.onCloseFunc != null){
			if (this.options.external_var != null){
				var the_var = this.options.external_var;	
				this.options.onCloseFunc(the_var);
			}else{
				this.options.onCloseFunc();
			}
		}
		WindowsBox.unregister(this, 'msg');  
		Element.remove(this.element);
	},
	
	createOverlay: function(id, className) {
		var objOverlay = document.createElement("div");
		objOverlay.setAttribute('id', id+"_overlay");
		objOverlay.className = "overlay_" + className;
		objOverlay.style.display = 'none';
		objOverlay.style.position = 'absolute';
		objOverlay.style.top = '0';
		objOverlay.style.left = '0';
		objOverlay.style.zIndex = WindowsBox.maxZIndex + 1;
		WindowsBox.maxZIndex += 1;
		objOverlay.style.width = '100%';
		this.overlay = objOverlay;
		document.body.appendChild(objOverlay);
	},
	
	createWindow: function(id) {
		var class_name = this.options.className;
	    var win = document.createElement("div");
	    win.setAttribute('id', id);
	    win.className = class_name;

	    var content;
		var titleDiv = ''; 
		var closeDiv = '';
		if (this.options.url != null)
	      content = "<iframe frameborder=\"0\" name=\"" + id + "_content\"  id=\"" + id + "_content\" width=\"" + (this.width - 10) + "\" height=\"" + (this.height - 10) + "\" src=\""+ this.options.url +"\"> </iframe>";
	    else
	      content = "<div id=\"" + id + "_content\" class=\"" +class_name + "_content t"+this.typeWin+"\"><div class=\""+class_name+"_progress\"></div></div>";

		closeDiv = "<div class='"+ class_name +"_close' id='"+ id +"_close'> </div>";
		this.close_area = id +"_close";
		
		if (this.title != null){
			titleDiv = "<div class=\""+class_name+"_title\">"+this.title+"</div>";
		}
		var headerDiv = "<div class=\""+class_name+"_header t"+this.typeWin+"_header\" id=\"header_"+id+"\">"+titleDiv+closeDiv+"</div>";
	    var blank = "../themes/default/blank.gif";
	    
		win.innerHTML = headerDiv + "<div id=\""+ id +"_content_div\" class=\""+ class_name +"_content_div\">" + content + "</div>";
		
		Element.hide(win);
			
	    this.options.parent.appendChild(win);
	    return win;
	},
	
	setSize: function(width, height, useEffect, fromCenter) {    
		var old_width, old_height, wDiff, hDiff;
		
		if (fromCenter == null){
			fromCenter = false;
		}
		
		old_width = this.width;
		old_height = this.height;
		width = parseFloat(width);
	    height = parseFloat(height);	
		wDiff = old_width - width;
        hDiff = old_height - height;
		this.width = width;
		this.height = height;
		
		if (this.init){
			this.element.setStyle({width: width + "px"});
			this.element.setStyle({height: height + 37 + 10 + "px"});
			if (this.options.url == null){ 
				this.content.setStyle({height: height + 'px'});
				this.content.setStyle({width: width + 'px'});
			}
		}else{
			if (useEffect != null){			
				if (hDiff != 0 || wDiff != 0)
					this.content.setStyle({visibility:'hidden'});
					
				var xScale = (width  / old_width)  * 100;
				var yScale = ((height + 37 + 10) / (old_height + 37 + 10)) * 100;
				var yScale_cont = (height / old_height) * 100;

				if (wDiff != 0){
					new Effect.Parallel(
						[ 
							new Effect.Scale(this.element, xScale, {sync: true, scaleContent:false, scaleFromCenter: fromCenter, scaleY: false, duration: 0.5}), 
							new Effect.Scale(this.content, xScale, {sync: true, scaleContent:false, scaleFromCenter: fromCenter, scaleY: false, duration: 0.5})
						], 
						{ 
							duration: 0.5, 
							queue: {scope: 'resize', limit: 4}
						} 
					);
				}
				if (hDiff != 0)	{
					new Effect.Parallel(
						[ 
							new Effect.Scale(this.element, yScale, {sync: true, scaleContent:false, scaleFromCenter: fromCenter, scaleX: false, duration: 0.5}), 
							new Effect.Scale(this.content, yScale_cont, {sync: true, scaleContent:false, scaleFromCenter: fromCenter, scaleX: false, duration: 0.5})
						], 
						{ 
							duration: 0.5, 
							queue: {scope: 'resize', position: 'end', limit: 4}
						} 
					);}					

				if (this.options.url != null){ 
					this.content.setStyle({width: (width - 10) + 'px'});
					this.content.setStyle({width: (height - 10) + 'px'});
				}
					
				if (hDiff != 0 || wDiff != 0){
					(function(){
						this.content.setStyle({visibility:'visible'});
						var pos_data = this._posContent();	
					}).bind(this).delay(1);
				}
				
			}else{
				if (wDiff != 0) this.element.setStyle({width: width + "px"});
				if (hDiff != 0) this.element.setStyle({height: height + 37 + 10 + "px"});
				if (this.options.url == null){ 
					if (hDiff != 0) this.content.setStyle({height: height + 'px'});
					if (wDiff != 0) this.content.setStyle({width: width + 'px'});
				}
				var pos_data = this._posContent();	
			}
		}			
	},
	
	setCloseByOverlay: function(closable) {
		if (!this.options.modal){
			return;
		}
		if (this.options.closeByOverlay && closable){
			return;
		}
		if (!this.options.closeByOverlay && !closable){
			return;
		}
		this.options.closeByOverlay = closable;
		if (closable){
			this.clickclose = this.close.bindAsEventListener(this);
			Event.observe(this.overlay, "click", this.clickclose);
		}else{
			Event.stopObserving(this.overlay, "click", this.clickclose);
		}
	},
	
	setClosable: function(status) {
		this.options.closable = status;
		this.closable = status;
		if (status){
			if ($(this.close_area))
				$(this.close_area).onclick = this.close.bind(this);
		}else{
			if ($(this.close_area))
				$(this.close_area).onclick = null;
		}
	},
	
	setCloseFunc: function(callback) {
		this.options.onCloseFunc = callback;
	},
	
	setExternalVar: function(external_var) {
		this.options.external_var = external_var;
	},
	
	getContent: function () {
		return this.content;
	},
	
	getId: function() {
		return this.element.id;
	},
	
	setURL: function(url) {
    // Not an url content, change div to iframe
	    if (this.options.url) 
			this.content.src = null;
	    this.options.url = url;
	    var content= "<iframe frameborder='0' name='" + this.id + "_content' id='" + this.id + "_content' src='" + url + "' width='" + (this.width - 10) + "' height='" + (this.height - 10) + "'> </iframe>";
	    $(this.id +"_content_div").update(content);
	    this.content = $(this.element.id + "_content");
	},
	
	show: function(pos) {
		this.posType = pos;		
		
		var pos_data = this._posContent();	
		
		if (this.options.modal){
			this._displayOverlay(this.overlay);
			this.setZIndex(WindowsBox.maxZIndex + 1);
		}else{
			this.setZIndex(WindowsBox.maxZIndex++ + 1);
		}
		
		WindowsBox._hideSpecialElts();
		WindowsBox._showSpecialElts(this.id);
	
		if (this.typeWin == 'info'){
			new Effect.Appear(this.element, {duration: 0.3});
		}else{
			Element.show(this.element);
			new Effect.Move(this.element, {x: pos_data.left, y: pos_data.top, mode: 'absolute'});
		}
		this.init = false;
    },
	
	setZIndex: function(zindex) {
	    this.element.setStyle({zIndex: zindex});
	    WindowsBox.updateZindex(zindex, this);
	},
	
	close: function() {
		if (this.options.destroyOnClose) { 
			var destroyFunc = this.destroy.bind(this);
		}
		if (this.options.modal) {
			var closeOverlay = this.close_overlay.bind(this);
			new Effect.Fade(this.element, {duration: 0.3, afterFinish: function(effect) { closeOverlay(); }});	
		}else{
			new Effect.Fade(this.element, {duration: 0.3, afterFinish: function(effect) { destroyFunc(); }});
		}
	},
	
	close_overlay: function() {
		if (this.options.destroyOnClose) { 
			var destroyFunc = this.destroy.bind(this);
		}
		var Objoverlay = $(this.id+'_overlay');
		new Effect.Fade(Objoverlay, {duration: 0.2, afterFinish: function(effect) { destroyFunc(); }});
	},
	
	_displayOverlay: function(overlayId) {
		// prep objects
		var objOverlay = $(overlayId);
		// set height of Overlay to take up whole page and show
		objOverlay.style.height = (this.pageSize.pageHeight + 'px');
		objOverlay.style.display = 'none'; 
		objOverlay.show();
	},
	
	_posContent: function (){
		var pageSize;
		if (this.pageSize == null){
			pageSize = WindowsBox._getPageSize();
			this.pageSize = pageSize;
		}else{
			pageSize = this.pageSize;
		}
		var windowScroll = WindowsBox._getWindowScroll();
		var left_center = (pageSize.windowWidth - this.width) / 2;
		var top_center = (pageSize.windowHeight  - this.height) / 2;
		var top, left;
		
		// pos finale
		if (this.posType == 'center'){
			top = top_center + windowScroll.top;
			left = left_center + windowScroll.left;
		}else if (this.posType == 'top'){
			left = left_center + windowScroll.left;
			top = this.top + windowScroll.top;
		}else if (this.posType == 'left'){
			left = this.left + windowScroll.left;
			top = top_center + windowScroll.top;
		}else if (this.posType == 'right'){
			left = pageSize.windowWidth - this.right - this.width + windowScroll.left;
			top = top_center + windowScroll.top;
		}else if (this.posType == 'bottom'){
			left = left_center + windowScroll.left;
			top = pageSize.windowHeight - this.bottom - this.height + windowScroll.top;
		}else if(this.posType == 'bottom_right'){
			top = pageSize.windowHeight - this.bottom - this.height + windowScroll.top;
			left = pageSize.windowWidth - this.right - this.width + windowScroll.left;
		}else if(this.posType == 'bottom_left'){
			top = pageSize.windowHeight - this.bottom - this.height + windowScroll.top;
			left = this.left + windowScroll.left;
		}else if(this.posType == 'top_left'){
			top = this.top + windowScroll.top;
			left = this.left + windowScroll.left;
		}else if(this.posType == 'top_right'){
			top = this.top + windowScroll.top;
			left = pageSize.windowWidth - this.right - this.width + windowScroll.left;
		}
		
		if (this.init){
			if (this.typeWin == 'info'){
				this.element.setStyle({top: top + 'px'});
				this.element.setStyle({left: left + 'px'});
				return '';
			}else if (this.typeWin == 'content'){
				var top_ini, left_ini;
				if (this.posType == 'center'){
					top_ini = 0 - this.height - 5 + windowScroll.top;
					left_ini = left_center;
				}else if (this.posType == 'top'){
					left_ini = left_center;
					top_ini = 0 - this.height - 5 +windowScroll.top;
				}else if (this.posType == 'left'){
					left_ini = 0 - this.width - 5;
					top_ini = top_center + windowScroll.top;
				}else if (this.posType == 'right'){
					left_ini = pageSize.windowWidth + windowScroll.left + 5;
					top_ini = top_center + windowScroll.top;
				}else if (this.posType == 'bottom'){
					left_ini = left_center + windowScroll.left;
					top_ini = pageSize.windowHeight + windowScroll.top + 5;
				}else if(this.posType == 'bottom_right'){
					top_ini = pageSize.windowHeight + windowScroll.top + 5;
					left_ini = pageSize.windowWidth + windowScroll.left + 5;
				}else if(this.posType == 'bottom_left'){
					top_ini = pageSize.windowHeight + windowScroll.top + 5;
					left_ini = 0 - this.width - 5;
				}else if(this.posType == 'top_left'){
					top_ini = 0 - this.height - 5 + windowScroll.top;
					left_ini = 0 - this.width - 5;
				}else if(this.posType == 'top_right'){
					top_ini = 0 - this.height - 5 + windowScroll.top;
					left_ini = pageSize.windowWidth + windowScroll.left + 5;
				}
				
				this.element.setStyle({top: top_ini + 'px'});
				this.element.setStyle({left: left_ini + 'px'});
				return {top: top, left: left};
			}
		}else{
			new Effect.Move(this.element, {delay:0.5, duration:0.5, x: left, y: top, mode: 'absolute'});
			return '';
		}
	},
	
	_scroll_resize: function(event) {
		if (!this.scrolling){
			this.pageSize = WindowsBox._getPageSize();
			// set height of Overlay to take up whole page and show
			if ($(this.overlay)) 
				$(this.overlay).setStyle({height: (this.pageSize.pageHeight + 'px')});

			if (this.options.autopos)
				var pos = this._posContent();   
	    }
	}
};

var AlertBox = {};
AlertBox = Class.create();
AlertBox.prototype = {
	initialize: function() {   
		var id;
	    var optionIndex = 0;	    

	    this.options = Object.extend({
			className:			"alphacube",
			parent:				document.body,
			type:				'invit',
			width:				310,
			height:				160,
			destroyOnClose:		true
	    }, arguments[optionIndex] || {});

		id = "window_alert_" + this.options.type + "_" + new Date().getTime();
	      
	    if ($(id)){
			return;
		}
		
		this.id = id;	
		this.width = this.options.width;
		this.height = this.options.height;		
		this.type = this.options.type;		
		this.element = this.createWindow(id);	
		this.content = $(this.element.id + "_alert_content");
		this.timer = null;
		this.stopclose = null;	
		this.eventResize = this._resize.bindAsEventListener(this);
		this.eventScroll = this._scroll.bindAsEventListener(this);
		Event.observe(window, "resize", this.eventResize);
		if (window.ie_old) {
			Event.observe(window, "scroll", this.eventScroll);
		}
	},

	destroy: function() {	
		this.element.setStyle({display: 'none'});		
		Event.stopObserving(this.element, "click", this.stopclose);
		Event.stopObserving(window, "resize", this.eventResize);
		if (window.window.ie_old) {
			Event.stopObserving(window, "scroll", this.eventResize);
		}
		WindowsBox.unregister(this, 'alert');  
			
		Element.remove(this.element);
	},
		
	createWindow: function(id) {
		var class_name = this.options.className;
	    var win = document.createElement("div");
	    win.setAttribute('id', id);
	    win.className = class_name + "_alert";

	    var content = "<div id=\"" + id + "_alert_content\" class=\"" +class_name + "_alert_content\"></div>";
		var closeDiv = "<div class='"+ class_name +"_alert_close' id='"+ id +"_alert_close'> </div>";
		this.close_area = id +"_alert_close";
		var headerDiv = "<div class=\""+class_name+"_alert_header id=\"header_alert_"+id+"\">"+closeDiv+"</div>";	    
		win.innerHTML = headerDiv + content;
		
	    Element.hide(win);
	    this.options.parent.appendChild(win);
	    return win;
	},
	
	getContent: function () {
		return this.content;
	},
	
	show: function() {
		this.setZIndex(WindowsBox.maxZIndex++ + 1);
		$(this.close_area).onclick = this.close.bind(this);
		var page = WindowsBox._getPageSize();
		var top = page.windowHeight + 5;
		var left = page.windowWidth - this.width - 15;
		if (window.window.ie_old) {
			this.element.setStyle({position: 'absolute'});
		}else{
			this.element.setStyle({position: 'fixed'});
		}
		this.element.setStyle({top: top+'px', left: left+'px', display: 'block'});
		var yMove = 0 - this.height;
		new Effect.Move(this.element, {duration:0.5, mode:'relative', y:yMove, delay: 0.3});
		
		var id = this.getId();
		this.timer = setTimeout(function(){ WindowsBox.close(id, 'alert'); }, 10000);
		this.stopclose = this.stopTimer.bindAsEventListener(this)
		Event.observe(this.element, "click", this.stopclose);	
			
		if (((page.windowWidth - 850) / 2) - 70 < this.width){	
			WindowsBox._hideSpecialElts();
			WindowsBox._showSpecialElts(this.id);
		}
    },
	
	
	close: function() {
		if (this.options.destroyOnClose) { 
			var destroyFunc = this.destroy.bind(this);
		}
		var yMove = this.height + 5;
		new Effect.Move(this.element, {mode: 'relative', y:yMove, duration: 0.3, afterFinish: function(effect) { destroyFunc(); }});
	},
	
	setZIndex: function(zindex) {
	    this.element.setStyle({zIndex: zindex});
	    WindowsBox.updateZindex(zindex, this);
	},
	
	register: function() {
		WindowsBox.register(this, 'alert');  
	},
	
	_resize: function(event) {
		var pageSize = WindowsBox._getPageSize();
		var top = pageSize.windowHeight - this.height + 5;
		var left = pageSize.windowWidth - this.width - 15;
		this.element.setStyle({top: top+'px'});
		this.element.setStyle({left: left+'px'});
		if (((pageSize.windowWidth - 850) / 2) - 70 < this.width){	
			WindowsBox._hideSpecialElts();
			WindowsBox._showSpecialElts(this.id);
		}else{
			WindowsBox._showSpecialElts();
		}
	},
	
	_scroll: function(event) {
		var pageSize = WindowsBox._getPageSize();
		var pageScroll = WindowsBox._getWindowScroll();
		var top = pageSize.windowHeight - this.height + 5 + pageScroll.top;
		var left = pageSize.windowWidth - this.width - 15 + pageScroll.left;
		this.element.setStyle({top: top+'px'});
		this.element.setStyle({left: left+'px'});
		if (((pageSize.windowWidth - 850) / 2) - 70 < this.width){	
			WindowsBox._hideSpecialElts();
			WindowsBox._showSpecialElts(this.id);
		}else{
			WindowsBox._showSpecialElts();
		}
	},
	
	stopTimer: function() {
		clearTimeout(this.timer);
	},
	
	getId: function() {
		return this.element.id;
	}
};

// Windows containers, register all page windows
var WindowsBox = {
	maxZIndex: 0,
	windows: [],
	alert_windows: [],
	active: false,
	onRegister: false,
	timer: null,
  
	// add window and show if no active alert window
	register: function(win, type) {
		if (type == 'alert'){
			if (this.onRegister){
				this.timer = setTimeout(function(){ WindowsBox.register(win, 'alert'); }, 200);
			}
			this.onRegister = true;
			if (!this.alert_windows.length){
				win.show();
				this.active = true;
			}
			this.alert_windows.push(win);
			this.onRegister = false;
		}else{
			this.windows.push(win);
		}
	},
        
	// delete window and call next alert  window if exists 
	unregister: function(win, type) {
		if (type == 'alert'){ 
			this.alert_windows = this.alert_windows.reject(function(d) { return d==win });
			if (!this.alert_windows.length){
				this.active = false;
				if (!this.windows.length){
					this._showSpecialElts();
				}else{
					this._hideSpecialElts();
					this._showSpecialElts(this.windows.last().getId());
				}
			}else{
				var next_win = this.alert_windows[0];
				next_win.show();
			}
		}else{
			this.windows = this.windows.reject(function(d) { return d==win });
			if (this.windows.length >= 1){
				this._hideSpecialElts();
				this._showSpecialElts(this.windows.last().getId());
			}else{
				if (!this.alert_windows.length)
					this._showSpecialElts();
				else{
					var page = WindowsBox._getPageSize();
					if (((page.windowWidth - 850) / 2) - 70 < $(this.alert_windows.last().getId()).getWidth()){	
						WindowsBox._hideSpecialElts();
						WindowsBox._showSpecialElts(this.alert_windows.last().getId());
					}else{
						WindowsBox._showSpecialElts();
					}
				}
			}
		}
	},
	
	isRegistered: function(name, type) {
		var boxArray;
		var is_registered = false;
		
		if (type == 'alert'){
			boxArray = this.alert_windows;
		}else{
			boxArray = this.windows;
		}
		$A(boxArray).each(function (elt){
			if (elt.nameWin != null && elt.nameWin == name){
				is_registered = true;
				throw $break;
			}
		});
		return is_registered;
	},
	
	updateZindex: function(zindex) {
		if (zindex > this.maxZIndex)
			this.maxZIndex = zindex;
	},
	
	// Gets window from its id
	getWindow: function(id, type) {
		if (type == 'alert')
			return this.alert_windows.detect(function(d) { return d.getId() == id });
		else
			return this.windows.detect(function(d) { return d.getId() == id });
	},
	
	_hideSpecialElts: function(id) {
		id = id ==  null ? "" : "#" + id + " ";
		if (window.ie) {
			$$(id + 'select').each(function(elt) {
				if (!WindowsBox.isDefined(elt.oldVisibility)) {
					elt.oldVisibility = elt.style.visibility ? elt.style.visibility : "visible";
					elt.style.visibility = "hidden";
				}
			});
		}
		$$(id + '.flash').each(function(elt){
			if (!WindowsBox.isDefined(elt.oldVisibility)) {
				elt.oldVisibility = elt.style.visibility ? elt.style.visibility : "visible";
				elt.style.visibility = "hidden";
			}
		});
	},

	_showSpecialElts: function(id) {
		id = id ==  null ? "" : "#" + id + " ";
		if (window.ie) {
			$$(id + 'select').each(function(elt) {
				if (WindowsBox.isDefined(elt.oldVisibility)) {
					// Why?? Ask IE
					try {
						elt.style.visibility = elt.oldVisibility;
					} catch(e) {
						elt.style.visibility = "visible";
					}
					elt.oldVisibility = null;
				}else{
					if (elt.style.visibility)
						elt.style.visibility = "visible";
				}
			});
		}
		$$(id + '.flash').each(function(elt){
			if (WindowsBox.isDefined(elt.oldVisibility)) {
				// Why?? Ask IE
				try {
					elt.style.visibility = elt.oldVisibility;
				} catch(e) {
					elt.style.visibility = "visible";
				}
				elt.oldVisibility = null;
			}else{
				if (elt.style.visibility)
					elt.style.visibility = "visible";
			}
		});
	},
	
	isDefined: function(object) {
		return typeof(object) != "undefined" && object != null;
	},
	
	close: function(id, type) {
		var win = this.getWindow(id, type);
		if (win) 
			win.close();
	},
	
	_getPageSize: function(){
	    var xScroll, yScroll;

		if (window.innerHeight && window.scrollMaxY) {  
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}

		var windowWidth, windowHeight;

		if (self.innerHeight) {  // all except Explorer
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}  
		var pageHeight, pageWidth;

		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}

		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){  
			pageWidth = windowWidth;
		} else {
			pageWidth = xScroll;
		}

		return {pageWidth: pageWidth ,pageHeight: pageHeight , windowWidth: windowWidth, windowHeight: windowHeight};
	},
	
	_getWindowScroll: function() {
		var w = window;
		var T, L, W, H;
		L = window.pageXOffset || document.documentElement.scrollLeft;
		T = window.pageYOffset || document.documentElement.scrollTop;

		if (window.ie) 
			W = Math.max(document.documentElement.offsetWidth, document.documentElement.scrollWidth);
  		else if (window.khtml) 
			W = document.body.scrollWidth;
  		else 
			W = document.documentElement.scrollWidth;
  		  
  		if (window.ie) 
			H = Math.max(document.documentElement.offsetHeight, document.documentElement.scrollHeight);
    	else if (window.khtml) 
			H = document.body.scrollHeight;
    	else
			H = document.documentElement.scrollHeight;
    	
		return { top: T, left: L, width: W, height: H };
	}
};