getBrowser();
	
function getBrowser()
{
	return (window.Browser != null)?
	window.Browser: window.Browser =
	{
		isMozilla : (document.implementation && document.implementation.createDocument),
		isOpera : ((navigator.userAgent.indexOf("Opera")!=-1)?true:false),
		isOpera5 : ((navigator.appVersion.indexOf("MSIE 5")!=-1 && navigator.userAgent.indexOf("Opera 5")!=-1)?true:false),
		isOpera6 : ((navigator.appVersion.indexOf("MSIE 5")!=-1 && navigator.userAgent.indexOf("Opera 6")!=-1)?true:false),
		isN6 : ((navigator.userAgent.indexOf("Gecko")!=-1)),
		isN4 : ((document.layers)?true:false),
		isMac : ((navigator.userAgent.indexOf("Mac")!=-1)),
		isIE : ((document.all && !this.isOpera && (!this.isMac || navigator.appVersion.indexOf("MSIE 4")==-1))?true:false)
	};
}

function openDialogEx(src, width, height, left, top)
{
	var fnClose = null;
	if (window.childWindow != null && (fnClose = window.childWindow.close) != null)
	{
	    fnClose();
	    window.childWindow = null;
	}
	if (getBrowser().isIE)
	{
		showPreloader();
	}
	window.childWindow = openDialog(src, width, height, left, top);
}

var srcName=0;

function openDialog(src, width, height, left, top, historyID)
{
	srcName+=1;
    if (left == null)
    {
        left = (screen.width / 2) - (width / 2);
    }
    if (top == null)
    {
        top = (screen.height / 2) - (height / 2);
    }
    var newWindow = null;
    if (!getBrowser().isIE)
    {
        newWindow = window.open(src + '?' + srcName, "winDialog", "dialog=yes,resizable=no,dependent=yes" 
                                + (left != null? ",left=" + left.toString():"")
                                + (top != null? ",top=" + top.toString():"")
                                + (height != null? ",height=" + height.toString():"")
                                + (width != null? ",width=" + width.toString():"")
                                + ",scrollbars=1");
    }
    else
    {
        newWindow = window.showModelessDialog(src + '?' + srcName, window, "resizable=no;scroll=1;help:0"
                                + (left != null? ";dialogLeft=" + left.toString() + "px":"")
                                + (top != null? ";dialogTop=" + top.toString() + "px":"")
                                + (height != null? ";dialogHeight=" + height.toString() + "px":"")
                                + (width != null? ";dialogWidth=" + width.toString() + "px":"")
                                + ";status:1");
    }
    checkIEHistory(newWindow, historyID);
    return newWindow;
}

function showPreloader(func)
{
	var leftPop = (screen.width / 2) - 125;
	var topPop = (screen.height / 2) - 125;
	var oPop = window.createPopup();
	var oPopBody = oPop.document.body;
	window.preloaderWindow = oPop;
}

function checkIEHistory(dialog, historyID)
{
	if (!getBrowser().isIE)
	{
		return false;
	}
	if (dialog == null)
	{
		dialog = window;
	}
	if (!dialog.ieHistory || !dialog.history.isDialogHistory)
	{
	    var _history = dialog.ieHistory;
	    try
	    {
    		dialog.ieHistory = new DialogHistory((window != dialog)? window: dialog.dialogArguments, dialog, historyID);
	    	dialog.ieHistory.isDialogHistory = true;
	    }
	    catch (ex)
	    {
	    	dialog.ieHistory = _history;
	    }
	}
	if (dialog.ieHistory == null)
	{
		return false;
	}
	dialog.history.back = dialog.ieHistory.back;
	dialog.history.go = dialog.ieHistory.go;
	dialog.ieHistory.refresh();
	return true;
}

function DialogHistory(parentWindow, dialog, ID)
{
	var historyArray = null;
	var go = null;
	var back = null;
	var refresh = null;
	createDialogHistory();
	this.back = back;
	this.go = go;
	this.refresh = refresh;
	function createDialogHistory()
	{
		if (parentWindow == null)
		{
			return null;
		}
		var history = getHistory();
		if (!history || !history.go || !history.back || !history.onPageLoad)
		{
			return null;
		}
		go = history.go;
		back = history.back;
		refresh = history.onPageLoad;
	}
	function getHistory()
	{
		var histories = parentWindow.dialogHistories;
		
		if (histories == null)
		{
			histories = new Array();
			parentWindow.dialogHistories = histories;
		}
		var _ID = ((ID == null)? "null": ID.toString());
	    var history = histories[_ID];
		if (history != null)
		{
			if (window != dialog)
			{
				history.release();

				history = new HistoryArray(dialog, ID);
				histories[_ID] = history;
				history.open();
			}
			else
			{
				;
			}
		}
		else
		{
			history = new HistoryArray(dialog, ID);
			histories[_ID] = history;
			history.open();
		}
		return history;
	}
	function HistoryArray(dialog, ID)
	{
		var objHistory = null;
		var selectedIndex = -1;
		var historyLength = 0;
		this.release = release;
		this.open = open;
		this.back = null;
		this.go = null;
		this.onPageLoad = (dialog != null)? onPageLoad: null;
		createHistoryArray();
		function createHistoryArray(){}
		function release()
		{
			this.back = null;
			this.go = null;
			selectedIndex = -1;
			historyLength = 0;
			objHistory = null;
		}
		function open()
		{
			clear();
			this.back = back;
			this.go = go;
		}
		function clear()
		{
			selectedIndex = -1;
			historyLength = 0;
			objHistory = new Array();
		}
		function back(){return go(-1);}
		function go(pos)
		{
			if (!dialog){return;}	
			var location = dialog.location;
			if (location)
			{
				var url = getUrl(pos);
				if (url){return url;}
			}
		}
		function getUrl(pos)
		{
		    if (objHistory != null)
		    {
		    	if (selectedIndex < 0)
		    	{
					var location = dialog.location;
					if (location){return location.toString();}
					return null;
		    	}
			    pos = (pos == null)? selectedIndex: selectedIndex + pos;
		   	 	if (pos >= 0 && pos < historyLength){return objHistory[pos];}
		    	else if (pos < 0){pos = 0;}
		    	if (pos < historyLength){return objHistory[pos];}
		    	if (historyLength > 0){return objHistory[historyLength - 1];}
		   	}	
			return null;
		}
		function onPageLoad()
		{
			if (dialog == null || objHistory == null){return;}
			var location = dialog.location;
			if (location)
			{
				var url = getUrl();
				if (url != null && historyLength == 0)
				{
					objHistory[selectedIndex = 0] = location.href.toString();
					historyLength = selectedIndex + 1;
				}
				else
				{
  					var href = (location.href? location.href.toString(): null);
					if (href && !(url == href))
					{
						var ind = selectedIndex;
						while (ind >= 0 && objHistory[ind] != href){ind--;}
						if (ind >= 0)
						{
							selectedIndex = ind;
							historyLength = ind + 1;
						}
						else
						{
							objHistory[++selectedIndex] = location.toString();
							historyLength = selectedIndex + 1;
						}
					}
					else{;}
			    }
			}
		}
	}
}

function openDialogImage(src, Img)
{
	var pic = new Image();
	pic.onload= function()
	{
		var width = this.width;
		var height = this.height;
		if (!getBrowser().isOpera && getBrowser().isIE)
		{
			width+=9;
			height+=63;
		}
		var left = (screen.width / 2) - (width / 2);
		var top = (screen.height / 2) - (height / 2);
		openDialogEx(src, width, height, left, top);
	}
	pic.src = Img;
}

function openDialogTrade(obj, url, width, height)
{
	var src;
	if (url == "norm") {src = obj;}
	if (url == "error") {src = "/delivery/404_trade.htm";}
	var left = (screen.width / 2) - (width / 2);
	var top = (screen.height / 2) - (height / 2);
    if (window.newWindow != null)
    {
        window.newWindow.close();
        window.newWindow = null;
    }
    if (window.showModelessDialog == null)
    {
        newWindow = window.open(src, "popup_window", "dialog=yes,resizable=yes,dependent=yes"
                                + (left != null? ",left=" + left.toString():"")
                                + (top != null? ",top=" + top.toString():"")
                                + (height != null? ",height=" + height.toString():"")
                                + (width != null? ",width=" + width.toString():"")
                                + ",scrollbars");
    }
    else
    {
        newWindow = window.showModelessDialog(src, window, "resizable;scroll=1;help:0"
                                + (left != null? ";dialogLeft=" + left.toString() + "px":"")
                                + (top != null? ";dialogTop=" + top.toString() + "px":"")
                                + (height != null? ";dialogHeight=" + height.toString() + "px":"")
                                + (width != null? ";dialogWidth=" + width.toString() + "px":"")
                                + ";status:1");
    }
    return newWindow;
}