// Browser detection

var agent = navigator.userAgent.toLowerCase(); 
var browserProps = new Object;
browserProps.isIE = (agent.indexOf("msie") >= 0);
browserProps.isWindows = (agent.indexOf("windows") >= 0);
browserProps.is98 = (agent.indexOf("98") > 0);

// Alerts for debugging

var g_bDebug = (location.href.toLowerCase().indexOf("debug") != -1);
var g_DebugWindow = null;
var gParentDied = false;

var gAlertTimer = null;
var gAlertString = '';

function myAlert(str, caller) {
	if (g_bDebug) {
		if (caller)
			str = "<U>(child)</U>"+str;
		var op = getOpener();
		var logged = true;
		if (op && (! gParentDied)) {
			try {
				op.myAlert(str, this);
			}
			catch (er) {
				logged = false;
				str = "(failed parent log: " + er + ") " + str;
			}
		}
		else if (g_DebugWindow){ // no opener, we're the parent window
			try {
				g_DebugWindow.log(str);
			}
			catch (er) {
				logged = false;
				str = "(failed log: " + er + ") " + str;
			}
		}
		else {
//			alert("myAlert - no gdebugwindow");
		}
		if (! logged) {
			var t = new Date();
			var prefix = String(t.getHours()) + ":" + String(t.getMinutes()) + ":" + String(t.getSeconds());
			gAlertString += (prefix + str + '\n');
//		alert(gAlertString);
			if (! gAlertTimer)
				gAlertTimer = setTimeout("timerAlert()", 6000);
		}
	}
}

function timerAlert() {
	gAlertTime = null;
	var alertStr = gAlertString;
	gAlertString = '';
	alert(alertStr);
}

if (g_bDebug) {
	if (! getOpener()) {
		var str = "top=30,left=0,width=300,scrollbars=yes,resizable=yes";
		g_DebugWindow = window.open("icqconsole.html", "cnsl", str);
//			alert("openend window" + g_DebugWindow);
		window.focus();
	}
	else {
//			myAlert("have opener, not opening console");
	}
}


/********** Window Management ****************/

var g_windowsCollection = new Object;
var gWindowManager = new Object;

gWindowManager.init = function() {
	this.locations = new Array(8);
	for (var i = 0; i < 8; i++) {
		this.locations[i] = new Object;
		this.locations[i].windows = new Array(0);
	}
}

gWindowManager.makeWindowLocation = function() {
	var ind =  -1;
	var maxWindows = 9999;
	for (var i = 0; i < 8; i++) {
		var len = this.locations[i].windows.length;
		if (len == 0) {
			ind = i;
			break;
		}
		if (len < maxWindows) {
			ind = i;
			maxWindows = len;
		}
	}
	if (ind == -1) {
		myAlert("I don't understand how you could not find a location");
	}
	var o = new Object;
	o.top = 100 + ind * 25;
	o.left = 100 + ind * 20;
	o.id = ind;
	return o;
}

gWindowManager.addWindow = function(oWindow, winName, winClass, nIndex) {
	var o = new Object;
	o.window = oWindow;
	o.name = winName;
	o.windowClass = winClass;
	o.id = '';
	this.locations[nIndex].windows.push(o);
}

gWindowManager.removeWindow = function(oWindow) {
	for (var i = 0; i < this.locations.length; i++) {
		var location = this.locations[i];
		for (var ind = 0; ind < location.windows.length; ind++) {
			var rec = location.windows[ind];
			if (rec.window == oWindow || rec.realWindow == oWindow) {
				location.windows.splice(ind, 1);
				return rec;
			}
		}
	}
}

gWindowManager.setWindowID = function(topWindow, oWindow, sID) {
	myAlert("setting window id to " + sID);
	for (var i = 0; i < this.locations.length; i++) {
		var location = this.locations[i];
		for (var ind = 0; ind < location.windows.length; ind++) {
			var rec = location.windows[ind];
			if (rec.window == topWindow) {
				rec.realWindow = oWindow;
				rec.id = sID;
				return rec;
			}
		}
	}
}


gWindowManager.findWindowByName = function(winName) {
	for (var i = 0; i < this.locations.length; i++) {
		var location = this.locations[i];
		for (var ind = 0; ind < location.windows.length; ind++) {
			var rec = location.windows[ind];
			if (rec) {
				if (rec.name == winName) {
					var ret = rec.window;
					if (! isWindowOpen(ret))
						ret = null;
					return ret;
				}
			}
		}
	}
	return null;
}

gWindowManager.getChildWindows = function(bRealWindow) {
	var ret = new Array;
	for (var i = 0; i < this.locations.length; i++) {
		var location = this.locations[i];
		for (var ind = 0; ind < location.windows.length; ind++) {
			var win;
			if (bRealWindow)
				win = location.windows[ind].realWindow;
			else
				win = location.windows[ind].window;
			if (isWindowOpen(win)) {
					ret.push(win);
			}
		}
	}
	return ret;
}

function isWindowOpen(win) {
	var ret = false;
	if (win) {
		ret = true;
		try {
			if (typeof(win.closed) == "boolean") {
				if (win.closed)
					ret = false;
			}
		}
		catch (er) {
		
		}
	}
	return ret;
}



gWindowManager.init();

/*
// addWindow
// opener side
*/
function addWindow(topWin, win, id) { 
	myAlert("adding window with id " + id);
	gWindowManager.setWindowID(topWin, win, id);
}

var gOpener = -1;

function getOpener() {
	if (gOpener != -1)
		return gOpener;
	try {
		if (gBIsMaster) {
//			alert("getOpener found that this is the master window");
			gOpener = null;
			return null;
		}
	}
	catch (er) {
//		alert("getOpener :" + er);
	// nothing, gBIsMaster is either undefined or false
	}
	var ret = null;
	var w = getWindow();
	if (w.opener && (w.opener != top) && (w.opener != self)) {
		ret = w.opener;
		if (! isWindowOpen(ret))
			ret = null;
	}
	gOpener = ret;
	return ret;
}

var gWindow = null;
function getWindow() {
	if (gWindow == null) {
		gWindow = window.self;
		while (gWindow.top && (gWindow != gWindow.top))
			gWindow = gWindow.top;
	}
	return gWindow;
}

/*
// registerWindow
// child window side
*/
function registerWindow(sID) {
//	myAlert("register window " + sID);
	var myOpener = getOpener();
	if (myOpener && myOpener.addWindow) {
		myOpener.addWindow(getWindow(), window.self, sID);
	}
	else {
		myAlert("cannot find opener " + myOpener);
	}
}

/*********** End window manager *************/

function	setObjectVisibility(theName, bVis) {

//	alert("settting visibility of " + theDiv + " to " + bVis);
	var theDiv = document.getElementById(theName);

	if (theDiv) {
		var styleObject;
		if (theDiv.style) {
			styleObject = theDiv.style;
		}
		else
			styleObject = theDiv;
		var str = bVis ? "visible" : "hidden";

//		alert("style object is " + styleObject + ", visibility is " + styleObject.visibility);		
		styleObject.visibility = str;
	}
}

/*********** Focus management *************/

var isFocused = true;

function maorFocus() {
	isFocused = true;
	doFocusMovie();
}


function maorBlur() {
	isFocused = false;
}

function isWindowFocused() {
	return isFocused;
}

function maorUnload() {
	var isScriptRunning = getFLA("ScriptRunning");
	if ((isScriptRunning != null) && (String(isScriptRunning) != "1")) {
		var str = "In case you do not want to leave the ICQ2Go window, please choose 'cancel'";
	/*	var e = event;
		if (e) {
			str = '' + event;
			for (var key in event) {
				str += ("" + key + ": " + event[key] + "\n");
			}
		} */
			return str; 
	}
}

window.onfocus = maorFocus;
window.onblur = maorBlur;
if (gBIsMaster) {
	window.onbeforeunload = maorUnload;
}

/*********** End Focus management *************/


/*********** FLA interface *************/

//****** Global Variables *******//

// globals for SetVariable
var gFLA = null;
//var g_bSetVariable = false;
//var swfVarPrefix = "_root.gbrowser."
var swfVarPrefix = "gbrowser."
//var inited = false;

function getFLA(variable)
{
//	alert("send fla " + str);
//	if (g_bSetVariable) {
	var ret = null;
	try {
		ret = gFLA.GetVariable(swfVarPrefix + variable);
		myAlert("retrieved " + swfVarPrefix + variable + ", value is " + ret);
	}
	catch (er) {
		ret = null;
		myAlert(String(er) + "(get " + variable + " failed)");
	//		myAlert('no fla: cannot send ' + swfVarPrefix + variable + ', '+ str);
	}
	return ret;
}

function sendFla(variable,str)
{
//	alert("send fla " + str);
//	if (g_bSetVariable) {
	try {
		gFLA.SetVariable(swfVarPrefix + variable,str);
		myAlert("sending " + swfVarPrefix + variable + ", " + str);
	}
	catch (er) {
		myAlert(String(er) + "(set " + variable + " to " + String(str) + ")");
	//		myAlert('no fla: cannot send ' + swfVarPrefix + variable + ', '+ str);
	}
}

// global search string to relay to the swf
var searchstr = top.location.search;
if (! (searchstr.length > 0)) {
		searchstr = top.location.hash;
	}
	if (! (searchstr.length > 0)) {
	searchstr = '';
}
	if (searchstr.length > 0)
		searchstr = searchstr.substring(1, searchstr.length);

/******************* Window zooming *************/

// compute zoom factor for windows
kZoomFactor = 1;

if (screen) {
	var w = screen.availWidth;
//	w = 640
	if (typeof(w) == "number") {
		kZoomFactor = 1 + (((w - 1024) / 10) * 0.005);
	}
}

// Methods

// client methods for talking back to the parent
function doUnload() {
//	alert('unloading');
	sendFla('unload', 1);
	var myOpener = getOpener();
	if (myOpener && myOpener.windowDied) {
		myOpener.windowDied(getWindow());
	}
	else {
		myAlert("no opener, not calling window died");
	}
	var childWindows = gWindowManager.getChildWindows(true);
	myAlert("have " + childWindows.length + " children");
	for (var ind = 0; ind < childWindows.length; ind++) {
		var win = childWindows[ind];
		if (win) {
			if (win.parentClosed) {
				myAlert("calling parentclosed");
				win.parentClosed();
			}
			else {
				myAlert("found child window but it contains now parentClosed");
			}
		}
		else {
			myAlert("null window found in childWindows"); 
		}
	}
}


/*
	sends the parent window a close event
*/

function parentClosed() {
	gParentDied = true;
	sendFla ("parentClosed", "1");
	myAlert("parentClosed called");
	window.focus();
}

function closeWindow() {
	myAlert("closeWindow called");
	var myOpener = getOpener();
	if(myOpener && myOpener.closeChildWindow) {
		myOpener.closeChildWindow(this);
	}
	else {
		myAlert("closeWindow could not find opener");
		window.close();
	}
}

function closeChildWindow(win) {
	myAlert("closeChildWindow called");
	windowDied(win);
	if (win.top && (win.top != win))
		win = win.top;
	win.close();
}

function windowDied(inwindow) {
	var rec = gWindowManager.removeWindow(inwindow);
	if (rec) {
//		myAlert('child window ' + id + ' died'); 
		sendFla("windowClosed", rec.id)
		return;
	}
	myAlert('sub window closed but not found'); 
}

// sends tha flash object params

// adds the new window  to the collection
function shakeWindow(nTimes) {
	var w = getWindow();
	if (w.moveBy) {
		for (i = nTimes; i > 0; i--) {
			for (j = 12; j > 0; j-=2) {
				w.moveBy(0,i);
				w.moveBy(i,0);
				w.moveBy(0,-i);
				w.moveBy(-i,0);
			}
		}
	}
}

function openDialog(url, winName, winClass, width, height) {

	var w = gWindowManager.findWindowByName(winName);
	if (w) {
		w.focus();
		return;
	}
	
/*	if (! isDefined(width)) {
		if (winClass.length > 0) {
			var dim = GetCookie(winClass);
			if (dim.length > 0) {
				var arr = dim.split(',');
				width = parseInt(arr[0]);
				height = parseInt(arr[1]);
			}
		}
	} */
	if (! isDefined(width)) {
		width = 300;
		height = 200;
	}

	var widthstr = ',width=' + width;
	var heightstr = ',height=' + height;

	var o = gWindowManager.makeWindowLocation();
	var str = "top=" + o.top + ",left=" + o.left + widthstr + heightstr + ",directories=0,location=0,menubar=0,scrollbars=0,status=0,titlebar=0,toolbar=0,resizable=0";
//	myAlert(str);
	w = window.open(url, winName, str);
	if (w) {
		w.focus();
	}
	else {
		alert("You seem to have popups blocked. For ICQ2Go to function properly, popup windows must be enabled, at least for the icq.com domain");
	}
	gWindowManager.addWindow(w, winName, winClass, o.id);
}

function focusWindow(inFocus) {
	if (inFocus)
		this.focus();
	else
		this.blur();
}


// window title routines


var gTitleRec = new Object;
gTitleRec.m_sSavedTitle = getWindow().document.title;

gTitleRec.start = function(interval) {
	this.m_nIterations = 0;
	this.m_nInterval = interval;
	this.timer = setInterval("_doAnimateTitle()", Number(interval));
}

gTitleRec.stop = function() {
	if (this.timer) {
		clearInterval(this.timer);
		this.timer = null;
	}
	if (this.sleepTimer) {
		clearTimeout(this.sleepTimer);
		this.sleepTimer = null;
	}
	document.title = this.m_sSavedTitle;
}

gTitleRec.sleep = function(nMSec) {
	this.stop();
	this.sleepTimer = setTimeout("gTitleRec.start(" + this.m_nInterval + ")", Number(nMSec));
}

//********

var gDelayedTitle = '';

function makeTitle(str) {
	var ret = str;
	if (browserProps.isIE) {
//		for (var i = 0; i < 10; i++) {
			ret += ' ';		
//		}
//		ret += '.';
	}
	return ret;
}

function setDelayedTitle() {
	var oldTitle = getWindow().document.title;
	getWindow().document.title = gDelayedTitle;
//	myAlert("***delayed setting window title: old title was " + oldTitle + ", new title is " + document.title + ", typeof is " + typeof(document.title.innerHTML));
	gTitleRec.m_sSavedTitle = gDelayedTitle;
}

function setWindowTitle(str) {
	if (str.length > 0) {
//		gDelayedTitle = '';
//		for (var i = 0; i < str.length; i++)
//			gDelayedTitle += str.charAt(i);
//		setTimeout("setDelayedTitle()", 500);
		str = makeTitle(str);
		getWindow().document.title = str;
		gTitleRec.m_sSavedTitle = str;
	}
}

function stopTitleAnimation() {
	gTitleRec.stop();
}


function getNextChar(inChar) {
	if (inChar == '.')
		inChar = ' ';
	else
		inChar = '.';
	return inChar;
}

function _doAnimateTitle() {
	var str = '';
	var i = 0;
	var nextChar = ' ';
	while (i  < gTitleRec.position) {
		nextChar = getNextChar(nextChar);
		str += nextChar;
		i++
	}
	var ind = 0;
	if (gTitleRec.position < 0)
		ind = -gTitleRec.position;

//	alert("after initial padding str is " + str + ", length is now " + str.length + , "statring to copy at " + ind);
	
	while (ind < gTitleRec.titleLen && i < gTitleRec.maxLen) {
		str += gTitleRec.title.charAt(ind++);
		i++;
	}
	
	// the next string starts titleLen spaces after the end of this string
	var limit = Math.min(gTitleRec.maxLen, i + gTitleRec.maxLen - 2);

	while (i < limit) {
		nextChar = getNextChar(nextChar);
		str += nextChar;
		i++;
	}
	
	var pos = 0;
	var newPosition = i;
	while (i < gTitleRec.maxLen) {
		str += gTitleRec.title.charAt(pos);
		pos++, i++;
	}

	getWindow().document.title = str;

	gTitleRec.position--;
	if (gTitleRec.position  < (1 - gTitleRec.titleLen)) {
		gTitleRec.position = newPosition;
		gTitleRec.m_nIterations++;
		if (gTitleRec.m_nIterations > 3)
			gTitleRec.sleep(1000);
	}
}

function animateWindowTitle(str) {
	return;
	stopTitleAnimation();
	if (isWindowFocused())
		return;

	gTitleRec.title = str;
	gTitleRec.titleLen = str.length;
	gTitleRec.maxLen = str.length * 2;
	gTitleRec.position = gTitleRec.maxLen - 2;
	gTitleRec.start(200);
}


function initFLiCQ() {
//	alert ("set g_bSetVariable to " + g_bSetVariable + ", fla is " + fla); // + ", typeof setvariable is " + typeof(fla.SetVariable));
//	inited = true;
/*	if (window.top != window.self) {
		myAlert("setting top focus function (really), top is " + window.top);
		window.top._MaorWindow = window.self;
		window.top.onfocus = function() {
//			alert("top focus");
			this._MaorWindow.maorFocus();
		}
	} */
	
	if (browserProps.is98) {
		window.blur();
		window.focus();
	}

	testFLAConnection();
	focusMovie();
}

/* private */
function findFLA() {
	if (document.getElementById) {
		if (browserProps.isIE) {
			gFLA = document.getElementById(gFlashObjectID);
			myAlert("ie found gFLA " + gFLA);
		}
		else
			gFLA = document.getElementById(gFlashEmbedID);
	}
	else {
		gFLA = document[gFlashID];
	}
}

/* private */
function doFocusMovie() {
	myAlert("dofocusmovie called");
	if (browserProps.isIE && browserProps.isWindows) {
		try {
			gFLA.focus();
			sendFla(	"movieFocused", "1");
		}
		catch (er) {
			myAlert("doFocusMovie: " + er);
		}
	}
	else {
/*		var theDiv = document.getElementById("maindiv");
		if (! theDiv)
			theDiv = document.maindiv;
		if (theDiv)
			theDiv.onclick();
		else
			alert("div not found"); */
	}
}

/* public */
function focusMovie() {
	if (gFLA) {
		setTimeout("doFocusMovie()", 2000);	
	}
}

function testFLAConnection() {
	findFLA();
	if (gFLA) {
		try {
//			gFLA.SetVariable("test", "1");
//			g_bSetVariable = true;
			sendFla("noKeepAlive", "1");
		}
		catch (er) {
//			g_bSetVariable = false;
			myAlert("caught error " + er);
		}

/*		var str = typeof(gFLA.setVariable);
		g_bSetVariable = (gFLA && (str != "undefined"));
		myAlert("testFLAConnecton found setVariable to be " + str);
//		var str = "\"setting g_bSetVariable to " + g_bSetVariable + " gfla is " + gFLA + "\"";
//		setTimeout('myAlert(' + str + ')', 3000);
	//	alert("setvariable is " +  g_bSetVariable);
	//	alert ("set g_bSetVariable to " + g_bSetVariable + ", fla is " + fla); // + ", typeof setvariable is " + typeof(fla.SetVariable));
	//	alert ("set g_bSetVariable to " + g_bSetVariable + ", fla is " + fla + ", typeof setvariable is " + typeof(fla.SetVariable));
	//	setTimeout("sendFla(\"noKeepAlive\", \"1\")", 4000);
		sendFla("noKeepAlive", "1"); */
	}
	else {
		myAlert("testFLAConnection: no fla found");
	}
}

//*********** resize support ******************//
kAlignLeft = -1, kAlignRight = 1, kDontAlign = 0;

function Min(x, y) {
	return (x < y) ? x : y;
}

function Max(x, y) {
	return (x > y) ? x : y;
}

function isUndefined(x) {
	return (typeof(x) == 'undefined');
}

function isDefined(x) {
	return (typeof(x) != 'undefined');
}

var _useInnerDim = 1,  _useDocumentDim = 2, _useBodyDim = 3, _useUnknownDim = 4;
var gUseDim = _useUnknownDim;

function getWindowSize(windowRef)
{
	var ret = new Object;
	if (! windowRef)
		windowRef = self;

	switch (gUseDim) {
		case _useInnerDim:
			ret.width = windowRef.innerWidth;
			ret.height = windowRef.innerHeight;
			break;
		case _useDocumentDim:
			ret.width = windowRef.document.clientWidth;
			ret.height = windowRef.document.clientHeight;
			break;
		case _useBodyDim:
			ret.width = windowRef.document.body.clientWidth;
			ret.height = windowRef.document.body.clientHeight;
			break;
		case _useUnknownDim:
			if (isDefined(windowRef.document.clientWidth) && windowRef.document.clientWidth)
				gUseDim = _useDocumentDim;
			else if (isDefined(windowRef.document.body.clientWidth) && windowRef.document.body.clientWidth)
				gUseDim = _useBodyDim;
			else
				gUseDim = _useInnerDim;
			ret = getWindowSize(windowRef);
			break;
		}
		return ret;
}


function relocate(width, height, left, top, align) {
//	myAlert("called relocate " + width + ", " + height + ", " + top + ", " + left + ", " + align);
//	var sWidth = screen.availWidth, sHeight = screen.availHeight;
	var dim = getWindowSize();
	var deltaX = Number(width) - dim.width;// + self._widthBias;
	var deltaY = Number(height) - dim.height;// + self._heightBias;
//		myAlert("cur width is "+dim.width+", curHeight is "+dim.height+
//		", deltaX is "+deltaX+", deltaY is "+deltaY + ", finalWidth is "+finalWidth + 
//		", finalHeight is "+ finalHeight);
	var w = getWindow();
	w.resizeBy(deltaX, deltaY);
//	window.resizeTo(Number(width), Number(height));
//	setObjectVisibility("maor", true);
	
	switch (align) {
		case kAlignLeft:
//			myAlert("left align");
			w.moveTo(0, 0);
			break;
		case kAlignRight:
//			myAlert("moving to " + (screen.availWidth - width) + ", " + top);
			w.moveTo(screen.availWidth - width, top);
			break;
		case kDontAlign:
		default:
//			myAlert("default align to " + left + "," + top);
			if (isDefined(top) && isDefined(left))
				w.moveTo(left, top);
			break;
	}
}



function relocate1(width, height, left, top, align) {
	myAlert("called relocate " + width + ", " + height + ", " + top + ", " + left + ", " + align);
//	var sWidth = screen.availWidth, sHeight = screen.availHeight;
	var dim = getWindowSize();
/*	
	if (isDefined(self._widthBias))
		delete(self._widthBias);// = undefined;
	if (isDefined(self._lastResizeWidth))
		delete(self._lastResizeWidth);// = undefined;
	if (isDefined(self._lastResizeHeight))
		delete(self._lastResizeHeight);// = undefined; */

	setObjectVisibility("maor", false);

	width = Math.round(width * kZoomFactor);
	height = Math.round(height * kZoomFactor);

	var dx = Math.floor(width - dim.width);
	var dy = Math.floor(height - dim.height) ;
	if (dx == 0 && dy == 0) {
		setObjectVisibility("maor", true);
		return;
	}
	var delta = Max(Math.abs(dx), Math.abs(dy));
	var nSteps;

	if (delta <= 50)
		nSteps = 1;
	else {
		var portion = 50;
		while (delta / portion < 50) {
			portion --;
		}
		nSteps = Math.round(delta / portion);
	}
	if (nSteps > 3)
		nSteps = 3;
	var deltaX = Math.round(dx / nSteps);
	var deltaY = Math.round(dy / nSteps);

//	myAlert("cur width is "+dim.width+", curHeight is "+dim.height+ " dx is " + dx + " dy is " + dy +
//		", deltaX is "+deltaX+", deltaY is "+deltaY + ", finalWidth is "+width + 
//		", finalHeight is "+ height + ", nSteps is "+nSteps);
	
	switch (align) {
		case kAlignLeft:
//			myAlert("left align");
			window.moveTo(0, 0);
			break;
		case kAlignRight:
//			myAlert("moving to " + (screen.availWidth - width) + ", " + top);
			window.moveTo(screen.availWidth - width, top);
			break;
		case kDontAlign:
		default:
//			myAlert("default align to " + left + "," + top);
			if (isDefined(top) && isDefined(left))
				window.moveTo(left, top);
			break;
	}
	
	relocateStep(deltaX, deltaY, width, height, nSteps);
}

function adjustDelta(curSize, targetSize, delta) {
	if (delta > 0) {
		if (curSize + delta > targetSize)
			delta = targetSize - curSize;
	}
	else if (delta < 0) {
		if (curSize + delta < targetSize)
			delta = targetSize - curSize;
	}
	return delta;
}

function relocateStep(deltaX, deltaY, finalWidth, finalHeight, nSteps) {
	nSteps--;
	if (nSteps >= 0) {
		var predim = getWindowSize();
		deltaX = adjustDelta(predim.width, finalWidth, deltaX);
		deltaY = adjustDelta(predim.height, finalHeight, deltaY);
//		myAlert(" before: window width is " + predim.width + ", height is " + predim.height);
		window.resizeBy(deltaX, deltaY);
/*		if (isUndefined(self._widthBias)) {
			if (isUndefined(self._lastResizeWidth)) {
				self._lastResizeWidth = predim.width + deltaX;
				self._lastResizeHeight = predim.height + deltaY;
			}
			else {
				self._widthBias = self._lastResizeWidth - predim.width;
				self._heightBias = self._lastResizeHeight - predim.height;
				myAlert("prev width was " + self._lastResizeWidth + ", current is " + predim.width + ", widthbias is " + self._widthBias + ", height bias is " + self._heightBias);
			}
		} */
		var str = "relocateStep("+deltaX+","+deltaY+","+finalWidth+","+finalHeight+","+nSteps+")";
//		myAlert("running \n"+str);
		setTimeout(str, 20);
	}
	else {
		var dim = getWindowSize();
		deltaX = finalWidth - dim.width;// + self._widthBias;
		deltaY = finalHeight - dim.height;// + self._heightBias;
//		myAlert("cur width is "+dim.width+", curHeight is "+dim.height+
//		", deltaX is "+deltaX+", deltaY is "+deltaY + ", finalWidth is "+finalWidth + 
//		", finalHeight is "+ finalHeight);
		window.resizeBy(deltaX, deltaY);
		setObjectVisibility("maor", true);
	}
}
	
function resizeMe(dx, dy) {
	var w = getWindow();
	try {
		w.resizeBy(parseInt(dx), parseInt(dy));
		}
		catch (er) {
			alert("error resizing " + er);
	}
}

function getParam(sKey) {
	var searchstr = window.location.search;
	if (! (searchstr.length > 0))
		searchstr = top.location.hash;
	if (! (searchstr.length > 0))
		return null;
	searchstr = searchstr.substring(1, searchstr.length);

	var ret = null;

	var arr = searchstr.split('&');
	for (var i = 0; i < arr.length; i++) {
		var keyval = arr[i].split('=');
		if (keyval.length > 0) {
			if (keyval[0].toLowerCase().indexOf(sKey) == 0) {
				ret = keyval[1];
				break;
			}
		}
	}
	return ret;
}

