//**************************************************************************************************************/
//	SuperDialog v1.00
//
//	 Author: Markus F. Hay, inspired by the work of Lokesh Dhakar on Lightbox JS (http://www.huddletogether.com)
//	   Date: August 14, 2006
//	License: Creative Commons Attribution 2.5 License (http://creativecommons.org/licenses/by/2.5/)
//**************************************************************************************************************/
//	SuperDialog Class Definition
//	- SuperDialog()			: constructor - initializes member variables, preloads images, sets up initial body/overlay/dialog references
//	- start()				: starts the dialog
//	- keypress()			: handles <ENTER> and <ESC> key presses
//	- closeDialog()			: closes the dialog
//	- checkClick()			: checks which button was clicked (set to check every half second by default)
//	- checkFrame()			: sets member variable (boolean) which determines if we're in a iFrame or not
//	- action()				: meant to be overwritten by user so they can respond to button clicks appropriately
//	- clearAction()			: clears the action to be taken when a button is clicked
//	- toggleElements()		: toggles visibility for certain elements on the page, such as selects for IE6 and below...
//	- setDialog()			: calls setType(), setTitle(), setDetails()
//	- setType()				: sets the member variable type
//	- getType()				: returns the dialog type
//	- setTitle()			: sets the member variable title
//	- getTitle()			: returns the dialog title
//	- setDetails()			: sets the member variable details
//	- getDetails()			: returns the dialog details
//	- setPromptInput()		: set the user input from the prompt
//	- getPromptInput()		: returns the user input from the prompt
//	- setButtonClicked()	: sets the button that was clicked on the dialog (string)
//	- getButtonClicked()	: gets the button that was clicked on the dialog (string)
//	- getButtons()			: returns the buttons (images) to be displayed on the dialog
//	- getInputStyle()		: returns the style used by the input element on the "PROMPT" dialog
//	- doAJAX()				: handles/sends an AJAX request to the specified URL
//	- setError()			: sets an error that is displayed on the "LOGIN" dialog if authentication fails
//	- getPageSize()			: returns array of page/window dimensions
//	- getPageScroll()		: returns the y page scroll value
//	- fadeIn()				: fade in effect for an element
//	- fadeOut()				: fade out effect for an element
//	- changeOpac()			: changes the opacity of an element (called by fadeIn/Out()
//
//	- initSuperDialog()		: creates a new instance of SuperDialog()
//**************************************************************************************************************/


//*************************/
// SuperDialog constructor
//*************************/
function SuperDialog(type, title, details) {
	// set values for the dialog, then check if we are in an iframe or not
	this.setDialog(type, title, details);
	this.checkFrame();
	
	// speed and opacity of the overlay for fade in/out effect
	this.speed = Math.round(500 / 100);
	this.maxOpacity = 80;
	
	this.backgroundTitle = '#63686e';
	this.colorTitle = '#e5f1ff';
	
	this.backgroundDetails = '#e5f1ff';
	this.colorDetail = '#000';

	// initialize member variables used for AJAX requests
	this.status = this.urlAJAX = this.handler = this.objReq = this.responseType = null;
	
	// initialize the interval member variable
	this.interval = null;
}

//********************************************************/
//	start() - Build the dialog box CSS/HTML, then show it.
//********************************************************/
SuperDialog.prototype.start = function() {
	
// we need to know the browser version (or if it's IE) and compatibility mode since IE is "special" and required spoon feeding
	/*@cc_on
		/*@if (@_jscript)
			this.ie = (document.all) ? true : false;
		/*@else @*/
			this.ie = false;
		/*@end
	@*/
	this.ie4 = (this.ie && !document.getElementById);
	this.ie5 = (this.ie && !document.createAttribute);
	this.ie6 = (this.ie && document.createAttribute && !window.XMLHttpRequest);
	this.ie7 = (this.ie && window.XMLHttpRequest);
	if (this.isFrame) {
		this.compat = (document.compatMode) ? parent.document.compatMode : '';
	} else {
		this.compat = (document.compatMode) ? document.compatMode : '';
	}
	
	// opera only
	this.opera = window.opera ? true : false;
	
	// setup the styles to be used -- these are inline because we don't know if we are in an iframe or not
	properWidth = (((this.ie6 || this.ie7) && this.compat != 'BackCompat') || !this.ie || this.opera) ? 346 : 350; /* needed thanks to the IE5 and below proprietary box model */
	this.sDialogTitle 		= 'height: 26px; width: 350px; overflow: hidden; margin: 0 auto; padding: 0; border: 0; background: '+ this.backgroundTitle +';';
	this.sDialogTitleType 	= 'height: 26px; width: 13px; float: left; margin: 0 auto; padding: 0; border: 0;';
	this.sDialogTitleText 	= 'height: 26px; width: 284px; float: left; color: '+ this.colorTitle +'; font: bold 12px Arial, Helvetica, sans-serif; text-align: left; padding: 0.7em 0 0 0; margin: 0 auto; border: 0;';
	this.sDialogTitleButton = 'height: 26px; width: 25px; float: left; margin: 0 auto; padding: 0; border: 0;';
	this.sDialogTitleEnd 	= 'height: 26px; width: 14px; float: left; margin: 0 auto; padding: 0; border: 0;';	
	this.sDialogDetails 	= 'min-height: 78px; width: ' + properWidth + 'px; text-align: left; border-left: 2px solid '+ this.backgroundTitle +'; border-right: 2px solid '+ this.backgroundTitle +'; border-top: 0; border-bottom: 0; margin: 0 auto; padding: 0;background: '+ this.backgroundDetails +';';
	this.sDialogDetailsText = 'display: block; margin: 0 auto; padding: 10px; font: 12px Arial, Helvetica, sans-serif; color: '+ this.colorDetail +'; border: 0;';
	this.sDialogInput		= 'font: 12px Arial, Helvetica, sans-serif; color: black; border: 2px solid '+ this.backgroundTitle +'; background-color: '+ this.backgroundTitle +'; margin: 0 auto; padding: 2px;';
	this.sDialogButtons 	= 'height: 35px; width: ' + (properWidth-10) + 'px; background: '+ this.backgroundDetails +'; border-top: 0; border-bottom: 0; border-left: 2px solid '+ this.backgroundTitle +'; border-right: 2px solid '+ this.backgroundTitle +'; overflow: hidden; margin: 0 auto; text-align: center; padding: 0; padding-right: 10px;';
	this.sDialogFooter 		= 'height: 10px; width: 346px; margin: 0 auto; padding: 0; border: 0; background: '+ this.backgroundDetails +'; border: 2px solid '+ this.backgroundTitle +'; border-top: none;';
    this.sButton = 'background: url(\'/css/img/obj_butt.png\') repeat-x scroll left top transparent; width: 80px; height: 28px; border: 1px solid #353535; color: #FFFFFF; cursor: pointer; font-weight: bold; padding: 0 14px;'



	// Get a handle on the body tag in the proper window (parent if currently in an iframe)
	var objBody = this.isFrame ? parent.document.getElementsByTagName("body").item(0) : document.getElementsByTagName("body").item(0);
	
	// This is necessary because IE sucks and won't update the contents of SuperDialog...
	if (document.getElementById("superDialog")) {
		objBody.removeChild(document.getElementById("superDialog"));
	} else if (parent.document.getElementById("superDialog")) {
		objBody.removeChild(parent.document.getElementById("superDialog"));
	}
		
	/* START BUILDING SUPERDIALOG HTML */
	
		var objOverlay = this.isFrame ? parent.document.createElement("div") : document.createElement("div");
			objOverlay.setAttribute('id','superOverlay');
			objOverlay.style.display = 'none'; objOverlay.style.width = '100%'; objOverlay.style.height = '100%'; objOverlay.style.position = 'fixed';
			objOverlay.style.top = '0'; objOverlay.style.left = '0'; objOverlay.style.zIndex = '90'; objOverlay.style.backgroundColor = '#ffffff';
			objOverlay.style.filter = 'alpha(opacity=0)'; objOverlay.style.MozOpacity = '0'; objOverlay.style.opacity = '0';
			objBody.appendChild(objOverlay);
		var objDialog = this.isFrame ? parent.document.createElement("div") : document.createElement("div");
			objDialog.setAttribute('id','superDialog');
			objDialog.style.display = 'none'; objDialog.style.position = 'absolute'; objDialog.style.top = '40px'; objDialog.style.left = '0';
			objDialog.style.width = '100%'; objDialog.style.zIndex = '100'; objDialog.style.textAlign = 'center';
		
		// this will only be populated (and shown) if we are using a "prompt" dialog
		var frmPrompt = '';
		if (this.getType() == "PROMPT") {
			frmPrompt = '<br /><br /><form name="superDialogForm"><input style="' + this.sDialogInput + '" type="text" name="userInput" size="60"></form>';
		}
		
		// this will only be populated (and shown) if we are using a "login" dialog
		var frmLogin = '';
		if (this.getType() == "LOGIN") {
			frmLogin = '<br /><div align="center"><span id="superErrorMessage" style="color:red;"></span></div>';
		}
		
		// now we start using innerHTML, yo.
		objDialog.innerHTML =		'<div style="' + this.sDialogTitle + '">' +
										'<div style="' + this.sDialogTitleType + '">' +
										'</div>' +
										'<div style="' + this.sDialogTitleText + '">' + this.getTitle() + '</div>' +
										'<div style="' + this.sDialogTitleButton + '">' +
										'</div>' +
										'<div style="' + this.sDialogTitleEnd + '">' +
										'</div>' +
									'</div>' +
									'<div style="' + this.sDialogDetails + ' ' + ';">' +
										'<span style="' + this.sDialogDetailsText + '"><a id="_focus"></a>' + this.getDetails() + frmPrompt + frmLogin + '</span>' +
									'</div>' +
									'<div style="' + this.sDialogButtons + '">' + this.getButtons() + '</div>' +
									'<div style="' + this.sDialogFooter + '"></div>';
									
	objBody.appendChild(objDialog);
	/* END THE SUPERDIALOG HTML */
	
	var pageSize = this.getPageSize();
	
	if ((this.ie6 || this.ie7) && this.compat != 'BackCompat') {
		objBody.style.height = '100%';
		objOverlay.style.height = '100%';
	} else {
		objOverlay.style.height = pageSize[0] + "px";
	}
		
	// hide select boxes and scrollbars before overlaying the page (exclude Opera since there is an issue with hiding/showing scrollbars)
	if (!this.opera) { this.toggleElements('hide'); }
	
	// fade in the overlay
	this.fadeIn('superOverlay', this.speed, this.maxOpacity);
	
	// calculate top offset for the SuperDialog and display
	objDialog.style.top = (this.getPageScroll() + (pageSize[1] / 8)) + "px";
	objDialog.style.display = '';
	
	// set an interval to query (every 3/10 second) for the button being clicked
	objDialog.interval = setInterval("myDialog.checkClick()", 300);
	
	// handle keypress events (<ENTER> and <ESC>)
	if (this.isFrame) {
		if (document.addEventListener) {	// W3C
			parent.document.addEventListener("keydown", this.keyPress, false);
		} else if (document.attachEvent) {	// Exploder
			parent.document.attachEvent("onkeydown", this.keyPress);
		} else {							// Old Skool
			parent.document.onkeydown = this.keyPress;
		}
		parent.document.getElementById("_focus").focus();
	} else {
		if (document.addEventListener) {	// W3C
			document.addEventListener("keydown", this.keyPress, false);
		} else if (document.attachEvent) {	// Exploder
			document.attachEvent("onkeydown", this.keyPress);
		} else {							// Old Skool
			document.onkeydown = this.keyPress;
		}
		document.getElementById("_focus").focus();
	}
};

//****************************************************************************************/
// keyPress() - Handle <ENTER> and <ESC>
//				Keycodes: <ENTER> = 13, <ESC> = 27, y = 89, n = 78, o = 79, c = 67
//****************************************************************************************/
SuperDialog.prototype.keyPress = function(e) {
	if (!e) var e = window.event;
	
	var keycode = (e.keyCode) ? e.keyCode : e.which;
	var type = (this.isFrame) ? window.parent[window.name].myDialog.getType() : myDialog.getType();
	var dialog = (this.isFrame) ? "window.parent[window.name].myDialog" : "myDialog";
	
	switch(type) {
		case "POTVRZENI":
			if (keycode == 13) {		// <ENTER>
				setTimeout(dialog + ".setButtonClicked('okay')", 1);
				setTimeout(dialog + ".closeDialog()", 100);
			}
			break;
		case "INFO":
		case "ERROR":
			if (keycode == 13 || keycode == 27) {		// <ENTER>, <ESC>
				setTimeout(dialog + ".setButtonClicked('okay')", 1);
				setTimeout(dialog + ".closeDialog()", 100);
			}
			break;
		case "WARNING":
		case "PROMPT":
			if (keycode == 13) {						// <ENTER>
				setTimeout(dialog + ".setButtonClicked('okay')", 1);
				setTimeout(dialog + ".closeDialog()", 10);
			} else if (keycode == 27) {					// <ESC>
				setTimeout(dialog + ".setButtonClicked('cancel')", 1);
				setTimeout(dialog + ".closeDialog()", 10);
			}
			break;
		case "CONFIRM":
			if (keycode == 13) {						// <ENTER>
				setTimeout(dialog + ".setButtonClicked('yes')", 1);
				setTimeout(dialog + ".closeDialog()", 10);
			} else if (keycode == 27) {					// <ESC>
				setTimeout(dialog + ".setButtonClicked('no')", 1);
				setTimeout(dialog + ".closeDialog()", 10);
			}
			break;
		case "LOGIN":
			if (keycode == 13) {						// <ENTER>
				setTimeout(dialog + ".setButtonClicked('login')", 1);
				this.action(); this.setButtonClicked("");
			} else if (keycode == 27) {					// <ESC>
				setTimeout(dialog + ".setButtonClicked('cancel')", 1);
				this.action(); this.setButtonClicked("");
			}
	}
	
	return false;
};

//***********************************/
// closeDialog() - closes the dialog
//***********************************/
SuperDialog.prototype.closeDialog = function() {	
	// remove the "keydown" event listeners that were added in start()
	if (this.isFrame) {
		if (document.removeEventListener) {	// W3C
			parent.document.removeEventListener("keydown", this.keyPress, false);
		} else if (document.detachEvent) {	// Exploder
			parent.document.detachEvent("onkeydown", this.keyPress);
		} else {							// Old Skool
			parent.document.onkeydown = '';
		}
	} else {
		if (document.removeEventListener) {	// W3C
			document.removeEventListener("keydown", this.keyPress, false);
		} else if (document.detachEvent) {	// Exploder
			document.detachEvent("onkeydown", this.keyPress);
		} else {							// Old Skool
			document.onkeydown = '';
		}
	}
	
	// if we are using a "prompt" dialog, store the input in a member variable before closing the dialog
	if (this.getType() == "PROMPT" && this.getButtonClicked() == "okay") {
		this.setPromptInput(this.isFrame ? parent.document.forms["superDialogForm"].userInput.value : document.forms["superDialogForm"].userInput.value);
	}
	
	// hide the dialog
	if (!this.isFrame) {
		document.getElementById("superDialog").style.display = 'none';
	} else {
		parent.document.getElementById("superDialog").style.display = 'none';
	}
		
	// fade out the overlay
	this.fadeOut('superOverlay', this.speed, this.maxOpacity);
	
	// show select boxes and scrollbars before overlaying the page (exclude Opera since there is an issue with hiding/showing scrollbars)
	if (!this.opera) { this.toggleElements('show'); }
	
	// wait 2 seconds, then call clearAction() to set this.action back to its default
	var blah = setTimeout("myDialog.clearAction()", 1000);
};

//****************************************************************************************************************************/
// checkClick() - Determines if a button on the dialog has been clicked. If so, clear the interval and button clicked value.
//				  A special condition was added for "login" dialogs to ensure that this.status != null or "cancel" was pressed.
//****************************************************************************************************************************/
SuperDialog.prototype.checkClick = function() {
	if (this.getButtonClicked() == "") {
		return;
	} else if (this.getType() == "LOGIN") {
		if (this.getButtonClicked() == "login" || this.getButtonClicked() == "cancel") {
			this.action();
			this.setButtonClicked("");
		}
	} else {
		clearInterval(myDialog.interval);
		this.action();				// if the user doesn't override this, nothing happens
		this.setButtonClicked("");	// we need to clear this so that the next time the dialog is "invoked" getButtonClicked() doesn't return the prior value
	}
};

//***********************************************************************************/
// checkFrame() - Determines if we are in an iFrame or not so we can display properly
//***********************************************************************************/
SuperDialog.prototype.checkFrame = function() {
	// If we are an iFrame ONLY (framesets are excluded because we can't overlay a frameset).
	// Note that there are situations where "this" will not refer to SuperDialog, such as when buttons are clicked,
	// therefor we have to set this.dialog appropriately.
	if (window.parent.frames[window.name] && (parent.document.getElementsByTagName('frameset').length <= 0)) {
		this.isFrame = true;
		this.dialog = "window.parent." + window.name + ".myDialog";
	} else {
		this.isFrame = false;
		this.dialog = "myDialog";
	}
};

//***************************************************************************************************************************/
// action() - This is meant to be overwritten by the end-user to process an action when a click action occurs (yes, no, etc.)
// clearAction() - Resets the action to do nothing after the dialog closes.
//***************************************************************************************************************************/
SuperDialog.prototype.action = function() {};
SuperDialog.prototype.clearAction = function() { this.action = function() {}; };

//*****************************************************************************************/
// toggleElements() - show/hide select boxes (ie 6 and below only) and show/hide scrollbars
//*****************************************************************************************/
SuperDialog.prototype.toggleElements = function(state) {
	var i, selects;
	
	// show/hide select boxes
	if (this.ie && !this.ie7) {
		
		// IE6 and below need to have selects hidden
		if (this.isFrame) {
			// hide in the parent frame, then in child frames
			var selects = parent.document.getElementsByTagName("select");
			for (i = 0; i < selects.length; i++ ) {
				selects[i].style.visibility = (state == "hide") ? 'hidden' : 'visible';
			}
			
			for (i = 0; i < parent.frames.length; i++) {
				selects = parent.frames[i].window.document.getElementsByTagName("select");
				for (var j = 0; j < selects.length; j++) {
					selects[j].style.visibility = (state == "hide") ? 'hidden' : 'visible';
				}
			}
		} else {
			// hide in the current page only
			var selects = document.getElementsByTagName("select");
			for (i = 0; i != selects.length; i++) {
				selects[i].style.visibility = (state == "hide") ? 'hidden' : 'visible';
			}
		}
	}
	
	// enable page scrolling
	if (this.isFrame) {
		if (this.ie5) {	// hide/show any iframe(s) in the parent window
			for (i = 0; i < parent.frames.length; i++) {
				parent.document.all[parent.frames[i].window.name].style.visibility = (state == "hide") ? 'hidden' : 'visible';
			}
		}
		
		if ((this.ie6 || this.ie7) && this.compat != 'BackCompat') { // IE6 and above in standards mode
			parent.document.getElementsByTagName('html')[0].style.overflow = (state == "hide") ? "hidden" : '';
		} else {
			parent.document.body.style.overflow = (state == "hide") ? "hidden" : '';
		}		
	} /*else {
		if ((this.ie6 || this.ie7) && this.compat != 'BackCompat') { // IE6 and above in standards mode
			document.getElementsByTagName('html')[0].style.overflow = (state == "hide") ? "hidden" : '';
		} else {
			document.body.style.overflow = (state == "hide") ? "hidden" : "visible";
		}		
	}*/
};

//**************************************************************************************************************************/
// setDialog() - Calls the individual setter methods to set type, title, display, and an empty string for the button clicked
//**************************************************************************************************************************/
SuperDialog.prototype.setDialog = function(type, title, details) {
	this.setType(type);
	this.setTitle(title);
	this.setDetails(details);
	this.setButtonClicked("");
};

//********************************************************************************************************************/
// setType() - Set the type of dialog. Type must not be null and must be a valid type (see cases). Defaults to "INFO".
//		info		: display the "info" icon with an "Okay" button
//		confirm		: display the "question" icon with "Yes" and "No" buttons
//		warning		: display the "warning" icon with "Okay" and "Cancel" buttons
//		error		: display the "error" icon with an "Okay" button
//		prompt		: display the "input" icon with "Okay" and "Cancel" buttons
//		login		: display the "login" icon with "Login" and "Cancel" buttons
// getType() - returns the type of dialog (info, confirm, warning, error, or prompt)
//********************************************************************************************************************/
SuperDialog.prototype.setType = function(type) {
	this.type = type.toUpperCase();
		
	switch(this.type) {
		case "POTVRZENI":
		case "INFO":
		case "CONFIRM":
		case "WARNING":
		case "ERROR":
		case "PROMPT":
		case "LOGIN":
			break;
		default:
			this.type = "INFO";
	}
};
SuperDialog.prototype.getType = function() { return this.type; };

//*********************************************************************************************************/
// setTitle() - Set the title of dialog. If no title is passed, we set a generic one depending on the type.
// getTitle() - return the title of the dialog
//*********************************************************************************************************/
SuperDialog.prototype.setTitle = function(title) {
	if (title && title.length > 50) {	// truncate so that we don't break the look & feel...
		this.title = title.substring(0,29) + "...";
	} else if (!title) {				// no title was passed, set it blank so "undefined" does not get output
		this.title = '';
	} else {
		this.title = title;
	}
};
SuperDialog.prototype.getTitle = function() { return this.title; };

//*************************************************/
// setDetails() - Set the details text of dialog
// getDetails() - returns the details of the dialog
//*************************************************/
SuperDialog.prototype.setDetails = function(details) { this.details = details ? details : ""; };
SuperDialog.prototype.getDetails = function() { return this.details; };

//************************************************/
// setPromptInput() - Set the user input value
// getPromptInput() - returns the user input value
//************************************************/
SuperDialog.prototype.setPromptInput = function(input) { this.input = input ? input : ""; };
SuperDialog.prototype.getPromptInput = function() { return this.input; };

//*****************************************************************************/
// setButtonClicked() - sets the property to determine which button was clicked
// getButtonClicked() - gets the property which returns the button clicked
//*****************************************************************************/
SuperDialog.prototype.setButtonClicked = function(button) { this.button = button; };
SuperDialog.prototype.getButtonClicked = function() { return this.button; };
	
//**********************************************************************/
// getButtons() - Returns the buttons that we want to use on the dialog.
//**********************************************************************/
SuperDialog.prototype.getButtons = function() {
	switch(this.getType()) {
		case "POTVRZENI":
			return '<input type="button" value="Pokračovat" onclick="' + this.dialog + '.setButtonClicked(\'okay\');' + this.dialog + '.closeDialog();" class="submit" style="'+ this.sButton +'"/>';
			break;
		case "INFO":
		case "ERROR":
			return '<input type="button" value="OK" onclick="' + this.dialog + '.setButtonClicked(\'okay\');' + this.dialog + '.closeDialog();" class="submit" style="'+ this.sButton +'"/>';
			break;
		case "CONFIRM":
			return '<input type="button" value="NE" onclick="' + this.dialog + '.setButtonClicked(\'cancel\');' + this.dialog + '.closeDialog();"  class="submit" style="'+ this.sButton +' margin-right: 100px;" /><input type="button" value="ANO" onclick="' + this.dialog + '.setButtonClicked(\'yes\');' + this.dialog + '.closeDialog();" class="submit" style="'+ this.sButton +' margin-right: 50px;" />';
			break;
		case "PROMPT":
			return '<input type="button" value="OK" onclick="' + this.dialog + '.setButtonClicked(\'okay\');' + this.dialog + '.closeDialog();" class="submit" style="'+ this.sButton +'"/>&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="Zrušit" onclick="' + this.dialog + '.setButtonClicked(\'cancel\');' + this.dialog + '.closeDialog();" class="submit" style="'+ this.sButton +'"/>';
			break;
		case "WARNING":
			return '<input type="button" value="OK" onclick="' + this.dialog + '.setButtonClicked(\'okay\');' + this.dialog + '.closeDialog();" class="submit" style="'+ this.sButton +'"/>&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="Zrušit" onclick="' + this.dialog + '.setButtonClicked(\'cancel\');' + this.dialog + '.closeDialog();" class="submit" style="'+ this.sButton +'"/>';
			break;
		case "LOGIN":
			return '<img id="superLoginButton" src="' + this.url + 'images/login.png" onclick="' + this.dialog + '.setButtonClicked(\'login\');" style="cursor:pointer;" onmouseover="this.src=\'' + this.url + 'images/login_on.png\';" onmouseout="this.src=\'' + this.url + 'images/login.png\';" />&nbsp;&nbsp;&nbsp;&nbsp;<img id="superCancelButton" src="' + this.url + 'images/cancel.png" onclick="' + this.dialog + '.setButtonClicked(\'cancel\');' + this.dialog + '.closeDialog();" style="cursor:pointer;" onmouseover="this.src=\'' + this.url + 'images/cancel_on.png\';" onmouseout="this.src=\'' + this.url + 'images/cancel.png\';" />';
			break;
	}
};

//*********************************************************************/
// getInputStyle() - Returns the default style used for form elements.
//*********************************************************************/
SuperDialog.prototype.getInputStyle = function() { return this.sDialogInput };

//*****************************************************************************/
// doAJAX() - Does the AJAX request.
//
// Paramters:
//	- url: the full url where the request should be sent... querystring parameters included
//  - handler: the response handler function
//  - type: the type of response (text or xml)
//
// Note: this.status has a value set so that "checkClick()" knows whether or
//		 not to allow an action to take place.
//*****************************************************************************/
SuperDialog.prototype.doAJAX = function(url, handler, type) {
	// Some initial validation to ensure we have values...
	if (!url || !handler) {
		alert("Oooops... the developer didn't read the documentation!");
		return;
	}
	
	// Encode the URL and set a value in this.status.
	this.urlAJAX = encodeURI(url);
	this.handler = handler;
	this.responseType = (type == "text" || type == "xml") ? type : "text";
	this.status = ".";
	
	// First make sure that "status" is not null (WE NEED TO DO MORE VALIDATION...)
	if (!this.status) { return; }
	
	// Start the "progress" indicator.
	this.setError('<img src="' + this.url + 'images/progress.gif" />');
	
	// Disable the login/cancel/close buttons by saving the old onclick/onmouseover/onmouseout/src properties in an array.
	// These values will be restored later once the processing is complete...
	this.closeButton = document.getElementById("superCloseButton");
	this.loginButton = document.getElementById("superLoginButton");
	this.cancelButton = document.getElementById("superCancelButton");
	
	this.closeProperties = new Array(this.closeButton.onclick, this.closeButton.onmouseover, this.closeButton.onmouseout);
	this.loginProperties = new Array(this.loginButton.onclick, this.loginButton.onmouseover, this.loginButton.onmouseout, this.loginButton.src.replace("_on", ""));
	this.cancelProperties = new Array(this.cancelButton.onclick, this.cancelButton.onmouseover, this.cancelButton.onmouseout, this.cancelButton.src);
	
	this.closeButton.onclick = "";	this.closeButton.onmouseover = "";	this.closeButton.onmouseout = "";	this.closeButton.style.cursor = "";
	this.loginButton.onclick = "";	this.loginButton.onmouseover = "";	this.loginButton.onmouseout = "";	this.loginButton.src = this.url + 'images/login_off.png';		this.loginButton.style.cursor = "";
	this.cancelButton.onclick = "";	this.cancelButton.onmouseover = "";	this.cancelButton.onmouseout = "";	this.cancelButton.src = this.url + 'images/cancel_off.png';	this.cancelButton.style.cursor = "";
	
	// Make an AJAX request...	(myDialog is used in place of "this" because we are out of our objects' scope)
	this.objReq = (window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"));
	if (this.objReq) {
		this.objReq.onreadystatechange = function() {
			var d = myDialog;
			if (d.objReq.readyState == 4) { // 4 = COMPLETE
				if (d.objReq.status == 200) {
					// we need to clear this hear so error messages won't be overwritten or blanked...
					d.setButtonClicked("");
					
					if (d.handler(d.responseType == "text" ? d.objReq.responseText : d.objReq.responseXML)) {
						// Everything is good...
						clearInterval(d.interval);
						d.status = d.responseType = d.urlAJAX = d.handler = null;
						d.closeDialog();
					}
					
					// Restore the original attribute values of the buttons...
					d.closeButton.onclick = d.closeProperties[0];		d.closeButton.onmouseover = d.closeProperties[1];
					d.closeButton.onmouseout = d.closeProperties[2];	d.closeButton.style.cursor = "pointer";
					d.loginButton.onclick = d.loginProperties[0];		d.loginButton.onmouseover = d.loginProperties[1];
					d.loginButton.onmouseout = d.loginProperties[2];	d.loginButton.src = d.loginProperties[3];
					d.loginButton.style.cursor = "pointer";
					d.cancelButton.onclick = d.cancelProperties[0];		d.cancelButton.onmouseover = d.cancelProperties[1];
					d.cancelButton.onmouseout = d.cancelProperties[2];	d.cancelButton.src = d.cancelProperties[3];
					d.cancelButton.style.cursor = "pointer";
				} else {
					d.handler(d.objReq.statusText);
				}
				d.objReq = null;
			}
		}
		this.objReq.open("GET", this.urlAJAX, true);
		this.objReq.setRequestHeader('content-type', 'text/xml');
		this.objReq.send(null);
	} else {
		this.handler("Could not create the request object.");
	}
};

//*********************************************************************/
// setError() - Sets an error message on the login form
//*********************************************************************/
SuperDialog.prototype.setError = function(msg) { document.getElementById("superErrorMessage").innerHTML = msg; };

//*******************************************************************************/
// getPageSize() - Returns array with page width, height and window width, height
// Core code from - quirksmode.org, Edit for Firefox by pHaez
//*******************************************************************************/
SuperDialog.prototype.getPageSize = function() {
	var yScroll, pageHeight;
	
	if (window.innerHeight && window.scrollMaxY) {
		yScroll = this.isFrame ? (parent.window.innerHeight + parent.window.scrollMaxY) : (window.innerHeight + window.scrollMaxY);
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yScroll = this.isFrame ? parent.document.body.scrollHeight : document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		yScroll = this.isFrame ? parent.document.body.offsetHeight : document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowHeight = this.isFrame ? parent.innerHeight : self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowHeight = this.isFrame ? parent.document.documentElement.clientHeight : document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowHeight = this.isFrame ? parent.document.body.clientHeight : document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	pageHeight = (yScroll < windowHeight) ? windowHeight : yScroll;

	var arrayPageSize = new Array(pageHeight, windowHeight);
	return arrayPageSize;
};

//**************************************************/
// getPageScroll() - returns the y page scroll value
//**************************************************/
SuperDialog.prototype.getPageScroll = function() {
	if (self.pageYOffset) {
		return this.isFrame ? parent.pageYOffset : self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		return this.isFrame ? parent.document.documentElement.scrollTop : document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		return this.isFrame ? parent.document.body.scrollTop : document.body.scrollTop;
	}
};

//*****************************/
// fadeIn() - fade in an element
//*****************************/
SuperDialog.prototype.fadeIn = function (id, speed, maxOpacity) {	
	if (!this.isFrame) {
		document.getElementById(id).style.display = '';
	} else {
		parent.document.getElementById(id).style.display = '';
	}

	var timer = 0;
	
	for (var i = 1; i <= maxOpacity; i++) {
		setTimeout("myDialog.changeOpac(" + i + ",'" + id + "')", (timer * speed));
		timer++;
	}
};

//*******************************/
// fadeOut() - fade out an element
//*******************************/
SuperDialog.prototype.fadeOut = function (id, speed, maxOpacity) {
	var timer = 0;
	
	for (var i = maxOpacity; i >= 0; i--) {
		setTimeout("myDialog.changeOpac(" + i + ",'" + id + "')", (timer * speed));
		timer++;
	}
};

//**************************************************/
// changeOpac() - changes the opacity of an element
//**************************************************/
SuperDialog.prototype.changeOpac = function (opacity, id) {
    var object = this.isFrame ? parent.document.getElementById(id).style : document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
	
	if (opacity == 0) {
		if (!this.isFrame) {
	 		document.getElementById(id).style.display = 'none';
		} else {
			parent.document.getElementById(id).style.display = 'none';
		}
	}
};

//***************/
// add listeners
//***************/
if (window.addEventListener) {		// W3C
	window.addEventListener("load",initSuperDialog,false);
} else if (window.attachEvent) {	// Exploder
	window.attachEvent("onload",initSuperDialog);
} else {							// Old skool
	window.onload = function() {initSuperDialog();}
}

//*****************************************************/
// initSuperDialog - creates an instance of SuperDialog
//*****************************************************/
function initSuperDialog() { myDialog = new SuperDialog('info'); }


//*****************************************************/
// vlastni pridane funkce
//*****************************************************/

//nastaveni akce odeslani formulare pro myDialog, pokud je kliknuto na okay
function nastavitAkciOdeslaniForm(pForm) {
	myDialog.action = function() { if (myDialog.getButtonClicked() == "okay") pForm.submit(); }
}

//nastaveni akce odeslani formulare pro myDialog, pokud je kliknuto na ano
function nastavitAkciOdeslaniFormAno(pForm) {
	myDialog.action = function() { if (myDialog.getButtonClicked() == "yes") pForm.submit(); }
}

//upozorneni pro semafor a namitkove rizeni
function zobrazitUpozorneniCopyright() {
	var myDialog = new SuperDialog('info', 'UPOZORNĚNÍ:', 'Poskytnutá zadání úloh jsou předmětem duševního vlastnictví www.scio.cz, s.r.o., resp.společnosti svědčí veškerá autorská práva k těmto testům. Tato práva jsou chráněna dle zákona č. 121/2000 Sb., o právu autorském a dalšími souvisejícími zákony. Zveřejněním testů společnost neuděluje uživatelům těchto webových stránek, jakož i dalším osobám, právo tyto testy stahovat, kopírovat, šířit či předávat jakýmkoliv způsobem dalším subjektům. S takovým jednáním jsou spojeny veškeré negativní právní důsledky plynoucí z ochrany autorských práv, včetně možné trestněprávní odpovědnosti.'); 

	myDialog.backgroundTitle = '#fa0000';
	myDialog.colorTitle = '#fffafa';

	myDialog.backgroundDetails = '#fffafa';
	myDialog.colorDetail = '#fa0000';

	myDialog.start();
}

//upozorneni pro oponenturu
function zobrazitUpozorneniOponentura() {
	var myDialog = new SuperDialog('info', 'UPOZORNĚNÍ:', 'K příspěvku se budou po dobu min. 24 hodin vyjadřovat ostatní účastníci testu. Po této době na základě komentářů je autor povinen svůj příspěvek potvrdit. Pokud tak neučiní, nebude se nezávislá námitková komise jeho příspěvkem zabývat.'); 

	myDialog.backgroundTitle = '#fa0000';
	myDialog.colorTitle = '#fffafa';

	myDialog.backgroundDetails = '#fffafa';
	myDialog.colorDetail = '#fa0000';

	myDialog.start();
}
