/*
 This file is part of HiNii.

 Copyright (C) 2008 Carnino Claudio (jollyr0ger) <jollyr0g3r@gmail.com>
 */

/**
 * Dialogs
 * @author jollyr0ger
 *
 * Attention need:
 * -Prototype
 * -ModalBox
 * -GlassBox
 */
var Dialog = Class.create({ });
Object.extend(Dialog, {	


	
	/**
	 * Popup a lightbox, using GlassBox js library
	 * @param	string		divName		Id of the div to popup
	 * @param	string		width		Div width (20px, 50em, ...)
	 * @param	string		height		Div height (20px, 50em, ...)
	 * @param	string		closeLabel	Close label [Not obligatory]
	 */
	lightbox: function(divId, width, height, closeLabel){

		// Close element
		if(closeLabel != null){
			var closeElem = closeLabel;
		}else{
			var closeElem = '<img src="/js/HNjs/Dialog/closelabel.gif" alt="Close" style="padding: 20px;"/>';
		}
		
		// Set predifined height and width
		if(height == null){
			height = '350px';
		}
		if(width == null){
			width = '350px';
		}

		// Insert at the top of the Div a big button to close it
		var closeButton = '<p align="center"><a href="#" onclick="$(\''+ divId +'\').hide()">'+ closeElem +'</a></p>';
		$(divId).insert(closeButton, 'above');
		
		// create the lightbox and show it
		var myGlassBox = new GlassBox();
		myGlassBox.init(divId, width, height, 'auto');
		myGlassBox.lbo(false);
		$(divId).show();
		
	},

	
	
	/**
	 * Popup a lightbox with a warning message
	 * @param	string		text		Text to popup
	 * @param	string		width		Div width (20px, 50em, ...)
	 * @param	string		height		Div height (20px, 50em, ...)
	 */
	attention: function(text, width, height){
		
		if(height == null){
			height = '200px';
		}
		
		// Hide previous alert
		if( $('newlightbox') ){
			$('newlightbox').remove();
		}
		
		var divName = 'newlightbox';
		var newDiv = '<div id="'+ divName +'"><h2 style="text-align :center;">Attention</h2> <p style="text-align :center; font-size: large;">'+ text +'</p></div>';
		$('body').insert(newDiv, 'bottom');
		
		Dialog.lightbox(divName, width, height);
	},
	

	
	/**
	 * Popup a lightbox with a warning message and the list of the fields to fill
	 * @param	string		text		Text to popup
	 * @param	Element[]	fields		Elements to fill
	 * @param	string		width		Div width (20px, 50em, ...)
	 * @param	string		height		Div height (20px, 50em, ...)
	 */
	attentionFill: function(text, fieldText, width, height){
		
		if(height == null){
			height = '300px';
		}

		// Hide previous alert
		if( $('newlightbox') ){
			$('newlightbox').remove();
		}
		
		var divName = 'newlightbox';
		var newDiv = '<div id="'+ divName +'"><h2 style="text-align :center;">Attention</h2> <p style="text-align :center; font-size: large;">'+ text +'</p><p style="text-align :center; font-size: medium;">'+ fieldText +'</p></div>';
		$('body').insert(newDiv, 'bottom');
		
		Dialog.lightbox(divName, width, height);
	}
	
	
	
});

