var contentWin;
var currPrototypeEditorSource;
var currPrototypeEditorTextArea;
var currPrototypeEditorDisplayArea;
var cssFile = 'testgate.css';
var cssPath = 'prototype/themes/';
var debugInfo = new Array();

function openPrototypeDiv(divId, windowTitle, divWidth, divHeight) {
	//debug('Prototype Div Opened: divId = ' + divId + '; windowTitle = ' + windowTitle + ';');
	
	if (!windowTitle) windowTitle = '';
	if (!divWidth) divWidth = '300';
	if (!divHeight) divHeight = '150';
	contentWin = new Window('divWindow', {title: windowTitle, className: "testgate", resizable: true, draggable: true, width: divWidth, height: divHeight, minWidth: 300, minHeight: 100, minimizable: false, maximizable: false, showEffect:Element.show, hideEffect:Element.hide, zIndex:990});
	contentWin.setContent(divId, false, true);
	contentWin.setDestroyOnClose();
	contentWin.setConstraint(true, {left:0, right:0, top:0, bottom:0});
	contentWin.showCenter(true);
	
	  // Set up a windows observer, check out debug window to get messages
	myObserver = {
		onDestroy: function(eventName, win) {
			//debugger;
		    if (win == contentWin) {
				$('Container' + divId).appendChild($(divId));
				contentWin = null;
				Windows.removeObserver(this);
			}
			//debug(eventName + " on " + win.getId())
		}
	}
	  Windows.addObserver(myObserver);
}

function openPrototypeConfirm(text, okAction, cancelAction, okLabel, cancelLabel, windowTitle, divWidth, divHeight) {
	//debug('Prototype Confirm Opened: text = ' + text + '; okAction = ' + okAction + '; cancelAction = ' + cancelAction + '; windowTitle = ' + windowTitle + ';');
	if (!okLabel) okLabel = 'Ok';
	if (!cancelLabel) cancelLabel = 'Cancel';	
	if (!windowTitle) windowTitle = '';
	if (!divWidth) divWidth = '300';
	if (!divHeight) divHeight = '150';
	
	Dialog.confirm("<center>" + text + "</center>", {windowParameters: {title: windowTitle, className: "testgate", width: divWidth, height: divHeight, showEffect:Element.show, hideEffect:Element.hide, zIndex:990}, okLabel: okLabel, cancelLabel: cancelLabel, id: "confirmDialog",	
		cancel:function(win) {if($('dialogOK')) $('dialogOK').disabled='true'; if($('dialogCancel')) $('dialogCancel').disabled='true'; eval(cancelAction);  return false;},
		ok:function(win) {if($('dialogOK')) $('dialogOK').disabled='true';if($('dialogCancel'))  $('dialogCancel').disabled='true'; eval(okAction);  return false;}
		});
}
var contentWin;
function openPrototypeUrl(url, windowTitle, divWidth, divHeight) {
	//debug('Prototype Url Opened: url = ' + url + '; windowTitle = ' + windowTitle + ';');
	if (!windowTitle) windowTitle = '';
	if (!divWidth) divWidth = '750';
	if (!divHeight) divHeight = '500';
	contentWin = new Window('urlWindow', {title: windowTitle, className: "testgate", resizable: true, draggable: true, width: divWidth, height: divHeight, minWidth: 300, minHeight: 100, minimizable: false, maximizable: true, showEffect:Element.show, hideEffect:Element.hide, url: url, zIndex:1100});
	contentWin.setDestroyOnClose();
	contentWin.setConstraint(true, {left:0, right:0, top:0, bottom:0});
	if (windowTitle != "Question Search") {
		contentWin.showCenter(true);
	} else {
		contentWin.show(true);
	}	
	//contentWin.doMaximize = true;
	contentWin.maximize();
	  // Set up a windows observer, check out debug window to get messages
	myObserver = {
		onDestroy: function(eventName, win) {
			//debugger;
		    if (win == contentWin) {
				//destroy the cookie that maintains scroll position
				document.cookie = contentWin.getId() + "=''; expires='Thu, 01-Jan-70 00:00:01 GMT'";
				contentWin = null;
				Windows.removeObserver(this);
			}
			//debug(eventName + " on " + win.getId())
		}
	}
	  Windows.addObserver(myObserver);
	//if (top.contentWin.getId() && top.contentWin.getId() != '') { document.cookie = contentWin.getId() + "=''; expires='Thu, 01-Jan-70 00:00:01 GMT'"; }
}

function openPrototypeEditor(source, textArea, displayArea, windowTitle){
	//debug('Prototype Editor Opened: source = ' + source + '; textArea = ' + textArea + ', displayArea = ' + displayArea + '; windowTitle = ' + windowTitle + ';');
	
	if (!windowTitle) windowTitle = 'Edit';
	
	currPrototypeEditorSource = null;
	currPrototypeEditorTextArea = null;
	currPrototypeEditorDisplayArea = null;
	
	if (source && $(source)) {
		currPrototypeEditorSource = $(source);
		if (textArea && $(textArea)) {
			currPrototypeEditorTextArea = $(textArea);
			if (displayArea && $(displayArea)){
				currPrototypeEditorDisplayArea = $(displayArea);
			}
		}
		//DO NOT use the fade Effect with the editor
		contentWin = new Window('prototypeEditor', {title: windowTitle, className: "testgate", resizable: false, draggable: true, width: 650, height: 425, minimizable: false, maximizable: false, showEffect:Element.show, hideEffect:Element.hide, url: "edithtmlv2.asp", zIndex:990});
		contentWin.setDestroyOnClose();
		contentWin.setConstraint(true, {left:0, right:0, top:0, bottom:0});
		contentWin.showCenter(true);  
	}
}

function updatePrototypeEditor(newVal) {
	currPrototypeEditorSource.innerHTML = newVal; 
	if (currPrototypeEditorDisplayArea && currPrototypeEditorTextArea) {
		currPrototypeEditorTextArea.value = currPrototypeEditorDisplayArea.innerHTML;
		FlagChangeV2(currPrototypeEditorTextArea);
	} else if (!currPrototypeEditorDisplayArea && currPrototypeEditorTextArea) {
		currPrototypeEditorTextArea.value = newVal;
		FlagChangeV2(currPrototypeEditorTextArea);
	}
}

/*
function addDebugInfo(val, key) {
	if (!key) key = debugInfo.length;
	debugInfo.Push(key + '=' + val);
}

function printDebugInfo() {
	var keyValPairs = new Array();
	for(var i=0;i<debugInfo.length;i++) {
		keyValPairs = debugInfo[i].split('=');
		if (keyValPairs[0] != i) debug(keyValPairs[0] + ': ' + keyValPairs[1]);
		else debug(keyValPairs[1]);
	}
}
*/

//The following line and the debug includes in main3.xsl need to be uncommented to use the prototype debug 
//onload_actions.push("attachKeyPress('showExtendedDebug();', 68, true, true, false)");

/*
// This is replaced by the above code

document.onkeydown = switchOnDebug;

function switchOnDebug(e) {
	var code;
	if (!e) var e = window.event;
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;	
	if (code == 68 && e.ctrlKey && e.altKey) showExtendedDebug();
	return true;
}
*/