function md5(strValue) {

    function Utf8Encode(strValue) {
        strValue = strValue.replace(/\r\n/g,"\n");
        var utftext = "";

        for(var n = 0; n < strValue.length; n++) {
            var c = strValue.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            } else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }
        }

        return utftext;
    };

    function RotateLeft(lValue, iShiftBits) {
        return (lValue << iShiftBits) | (lValue >>> (32-iShiftBits));
    }
	
	function AddUnsigned(lX,lY) {
	    var lX8 = (lX & 0x80000000);
	    var lY8 = (lY & 0x80000000);
	    var lX4 = (lX & 0x40000000);
	    var lY4 = (lY & 0x40000000);
	    var lResult = (lX & 0x3FFFFFFF)+(lY & 0x3FFFFFFF);
	    if (lX4 & lY4) {
	        return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
	    }
	    if (lX4 | lY4) {
	        if (lResult & 0x40000000) {
	            return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
	        } else {
	            return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
	        }
	    } else {
	        return (lResult ^ lX8 ^ lY8);
	    }
	 }

	function F(x, y, z) { return (x & y) | ((~x) & z); }
	function G(x, y, z) { return (x & z) | (y & (~z)); }
	function H(x, y, z) { return (x ^ y ^ z); }
	function I(x, y, z) { return (y ^ (x | (~z))); }
	
    function Md5FF(a,b,c,d,x,s,ac) {
        a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac));
        return AddUnsigned(RotateLeft(a, s), b);
    };

    function Md5GG(a,b,c,d,x,s,ac) {
        a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac));
        return AddUnsigned(RotateLeft(a, s), b);
    };

    function Md5HH(a,b,c,d,x,s,ac) {
        a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac));
        return AddUnsigned(RotateLeft(a, s), b);
    };

    function Md5II(a,b,c,d,x,s,ac) {
        a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac));
        return AddUnsigned(RotateLeft(a, s), b);
    };

    function ConvertToWordArray(strValue) {
        var lWordCount;
        var lMessageLength = strValue.length;
        var lNumberOfWords_temp1 = lMessageLength + 8;
        var lNumberOfWords_temp2 = (lNumberOfWords_temp1 - (lNumberOfWords_temp1 % 64))/64;
        var lNumberOfWords = (lNumberOfWords_temp2 + 1) * 16;
        var lWordArray = new Array(lNumberOfWords - 1);
        var lBytePosition = 0;
        var lByteCount = 0;
        while(lByteCount < lMessageLength) {
            lWordCount = (lByteCount - (lByteCount % 4)) / 4;
            lBytePosition = (lByteCount % 4) * 8;
            lWordArray[lWordCount] = (lWordArray[lWordCount] | (strValue.charCodeAt(lByteCount) << lBytePosition));
            ++lByteCount;
        }
        lWordCount = (lByteCount - (lByteCount % 4)) / 4;
        lBytePosition = (lByteCount % 4) * 8;
        lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80 << lBytePosition);
        lWordArray[lNumberOfWords - 2] = lMessageLength << 3;
        lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29;
        return lWordArray;
    };

    function WordToHex(lValue) {
        var hexValue = "";
        for (var n = 0; n <= 3; ++n) {
            var lByte = (lValue >>> (n * 8)) & 255;
            var temp = "0" + lByte.toString(16);
            hexValue = hexValue + temp.substr(temp.length - 2, 2);
        }
        return hexValue;
    };

    strValue = Utf8Encode(strValue);

    var array = ConvertToWordArray(strValue);

	// Init chaining variables...
	var a = 0x67452301;
	var b = 0xefcdab89;
	var c = 0x98badcfe;
	var d = 0x10325476;

    for (var n = 0; n < array.length; n += 16) {
        var AA = a; 
        var BB = b; 
        var CC = c; 
        var DD = d;
       	
       	//	Round 1...
        a = Md5FF(a, b, c, d, array[n + 0], 	7,	0xd76aa478);
        d = Md5FF(d, a, b, c, array[n + 1], 	12,	0xe8c7b756);
        c = Md5FF(c, d, a, b, array[n + 2], 	17,	0x242070db);
        b = Md5FF(b, c, d, a, array[n + 3], 	22,	0xc1bdceee);
        a = Md5FF(a, b, c, d, array[n + 4], 	7,	0xf57c0faf);
        d = Md5FF(d, a, b, c, array[n + 5], 	12,	0x4787c62a);
        c = Md5FF(c, d, a, b, array[n + 6], 	17,	0xa8304613);
        b = Md5FF(b, c, d, a, array[n + 7], 	22,	0xfd469501);
        a = Md5FF(a, b, c, d, array[n + 8], 	7,	0x698098d8);
        d = Md5FF(d, a, b, c, array[n + 9], 	12,	0x8b44f7af);
        c = Md5FF(c, d, a, b, array[n + 10],	17,	0xffff5bb1);
        b = Md5FF(b, c, d, a, array[n + 11],	22,	0x895cd7be);
        a = Md5FF(a, b, c, d, array[n + 12],	7,	0x6b901122);
        d = Md5FF(d, a, b, c, array[n + 13],	12,	0xfd987193);
        c = Md5FF(c, d, a, b, array[n + 14],	17,	0xa679438e);
        b = Md5FF(b, c, d, a, array[n + 15],	22,	0x49b40821);

		//	Round 2...
        a = Md5GG(a, b, c, d, array[n + 1], 	5,	0xf61e2562);
        d = Md5GG(d, a, b, c, array[n + 6], 	9,	0xc040b340);
        c = Md5GG(c, d, a, b, array[n + 11],	14,	0x265e5a51);
        b = Md5GG(b, c, d, a, array[n + 0], 	20,	0xe9b6c7aa);
        a = Md5GG(a, b, c, d, array[n + 5], 	5,	0xd62f105d);
        d = Md5GG(d, a, b, c, array[n + 10],	9,	0x2441453);
        c = Md5GG(c, d, a, b, array[n + 15],	14,	0xd8a1e681);
        b = Md5GG(b, c, d, a, array[n + 4], 	20,	0xe7d3fbc8);
        a = Md5GG(a, b, c, d, array[n + 9], 	5,	0x21e1cde6);
        d = Md5GG(d, a, b, c, array[n + 14],	9,	0xc33707d6);
        c = Md5GG(c, d, a, b, array[n + 3], 	14,	0xf4d50d87);
        b = Md5GG(b, c, d, a, array[n + 8], 	20,	0x455a14ed);
        a = Md5GG(a, b, c, d, array[n + 13],	5,	0xa9e3e905);
        d = Md5GG(d, a, b, c, array[n + 2], 	9,	0xfcefa3f8);
        c = Md5GG(c, d, a, b, array[n + 7], 	14,	0x676f02d9);
        b = Md5GG(b, c, d, a, array[n + 12],	20,	0x8d2a4c8a);
 
	  	//	Round 3...
        a = Md5HH(a, b, c, d, array[n + 5], 	4,	0xfffa3942);
        d = Md5HH(d, a, b, c, array[n + 8], 	11,	0x8771f681);
        c = Md5HH(c, d, a, b, array[n + 11],	16,	0x6d9d6122);
        b = Md5HH(b, c, d, a, array[n + 14],	23,	0xfde5380c);
        a = Md5HH(a, b, c, d, array[n + 1], 	4,	0xa4beea44);
        d = Md5HH(d, a, b, c, array[n + 4], 	11,	0x4bdecfa9);
        c = Md5HH(c, d, a, b, array[n + 7], 	16,	0xf6bb4b60);
        b = Md5HH(b, c, d, a, array[n + 10],	23,	0xbebfbc70);
        a = Md5HH(a, b, c, d, array[n + 13],	4,	0x289b7ec6);
        d = Md5HH(d, a, b, c, array[n + 0], 	11,	0xeaa127fa);
        c = Md5HH(c, d, a, b, array[n + 3], 	16,	0xd4ef3085);
        b = Md5HH(b, c, d, a, array[n + 6], 	23,	0x4881d05);
        a = Md5HH(a, b, c, d, array[n + 9], 	4,	0xd9d4d039);
        d = Md5HH(d, a, b, c, array[n + 12],	11,	0xe6db99e5);
        c = Md5HH(c, d, a, b, array[n + 15],	16,	0x1fa27cf8);
        b = Md5HH(b, c, d, a, array[n + 2], 	23,	0xc4ac5665);
        
	  	//	Round 4...
        a = Md5II(a, b, c, d, array[n + 0], 	6,	0xf4292244);
        d = Md5II(d, a, b, c, array[n + 7], 	10,	0x432aff97);
        c = Md5II(c, d, a, b, array[n + 14],	15,	0xab9423a7);
        b = Md5II(b, c, d, a, array[n + 5], 	21,	0xfc93a039);
        a = Md5II(a, b, c, d, array[n + 12],	6,	0x655b59c3);
        d = Md5II(d, a, b, c, array[n + 3], 	10,	0x8f0ccc92);
        c = Md5II(c, d, a, b, array[n + 10],	15,	0xffeff47d);
        b = Md5II(b, c, d, a, array[n + 1], 	21,	0x85845dd1);
        a = Md5II(a, b, c, d, array[n + 8], 	6,	0x6fa87e4f);
        d = Md5II(d, a, b, c, array[n + 15],	10,	0xfe2ce6e0);
        c = Md5II(c, d, a, b, array[n + 6], 	15,	0xa3014314);
        b = Md5II(b, c, d, a, array[n + 13],	21,	0x4e0811a1);
        a = Md5II(a, b, c, d, array[n + 4], 	6,	0xf7537e82);
        d = Md5II(d, a, b, c, array[n + 11],	10,	0xbd3af235);
        c = Md5II(c, d, a, b, array[n + 2], 	15,	0x2ad7d2bb);
        b = Md5II(b, c, d, a, array[n + 9], 	21,	0xeb86d391);
        
        a = AddUnsigned(a, AA);
        b = AddUnsigned(b, BB);
        c = AddUnsigned(c, CC);
        d = AddUnsigned(d, DD);
    }

    var ret = WordToHex(a) + WordToHex(b) + WordToHex(c) + WordToHex(d);

    return ret.toLowerCase();
}

function SDApplication(strPackageId, strPackageName, nVersion, bInstalled, bHasLicense, bActive, strDateExpires, bTrial, bAutoVoucher, strLabel, strIconSrc, strTitle, strDescription, strLinkBo, strLinkBase, nSortOrder, bNewVersionExists)
{
	if(!(objESCF instanceof ESCF)) objESCF = new ESCF();

	this.m_strPackageId			= strPackageId;
	this.m_strPackageName		= strPackageName;
	this.m_nVersion				= nVersion;
	this.m_bInstalled			= bInstalled;

	this.m_bHasLicense			= bHasLicense;
	this.m_bActive				= bActive;
	this.m_dateExpires			= objESCF.CreateDateFromInternalFormatString(strDateExpires);
	this.m_bTrial				= bTrial;
	this.m_bAutoVoucher			= bAutoVoucher;
	this.m_strLabel				= strLabel;

	this.m_strIconSrc			= strIconSrc;
	this.m_strTitle				= strTitle;
	this.m_strDescription		= strDescription;

	this.m_strLinkBo			= strLinkBo;
	this.m_strLinkBase			= strLinkBase;

	this.m_nSortOrder			= nSortOrder;
	this.m_bNewVersionExists	= typeof(bNewVersionExists) == "boolean" ? bNewVersionExists : false;

	// strType: i, u, a, r, b (install, uninstall, activate, read more, buy)
	this.GetUrl = function(strType)
	{
		if(!(objLibrary instanceof SDLibrary) || this.m_strLinkBase == "" || this.m_strPackageId == "" || this.m_strPackageName == "") return "";
		return this.m_strLinkBase + "?cmd=sd_asevent&t=" + encodeURIComponent(strType) + "&pi=" + encodeURIComponent(this.m_strPackageId) + "&p=" + encodeURIComponent(this.m_strPackageName) + "&su=" + encodeURIComponent(objLibrary.m_strSiteUrl) + ""
	}
	
	this.GetUrlSolved = function(strType)
	{
		switch(strType) {
			case "i":
				{
					if(!(objLibrary instanceof SDLibrary) || !objLibrary.CheckOkToInstall(this.m_strPackageId)) return "";
					if(this.m_bHasLicense) {
						if(!this.m_bActive || this.GetNumDaysLeft() == 0) return "";
						return this.GetUrl("i");
					}
					if(this.m_bAutoVoucher) return this.GetUrl("i");
				}
				break;
			case "u": if(this.m_bInstalled) return this.GetUrl("u");																			break;
			case "a": if(this.m_bTrial) return this.GetUrl("a");																				break;
			case "r": return this.GetUrl("r");
			case "b": if(this.m_bHasLicense ? this.m_bTrial : this.m_bTrial || !this.m_bAutoVoucher) return this.GetUrl("b");					break;
		}
		return "";
	}
	
	this.GetNumDaysLeft = function(dateNow)
	{
		if(!(dateNow instanceof Date)) dateNow = objLibrary.dateNow;
		if(!(this.m_dateExpires instanceof Date) || !(dateNow instanceof Date)) return -1;
		
		var nMsInDay = 1000 * 60 * 60 * 24;

		var date1 = new Date(this.m_dateExpires);
		var date2 = new Date(dateNow);
		date1.setHours(0, 0, 0, 0);
		date2.setHours(0, 0, 0, 0);

		var nMs1 = date1.getTime();
		var nMs2 = date2.getTime();
		
		var nMsDiff = Math.abs(nMs1 - nMs2);
		var nDaysLeft = Math.round(nMsDiff / nMsInDay)
		
		if(nDaysLeft < 0) nDaysLeft = 0;
		
		return nDaysLeft;
	}
}

function SDAppConstraints()
{
	this.m_arrNot	= [];
	this.m_arrOr	= [];
	this.m_arrAnd	= [];
	this.AddNot		= function(strPackageId) { this.m_arrNot.push(strPackageId); }
	this.AddOr		= function(strPackageId) { this.m_arrOr.push(strPackageId); }
	this.AddAnd		= function(strPackageId) { this.m_arrAnd.push(strPackageId); }
}

function SDLibrary(strServiceUrl, strSiteUrl, strDateNow)
{
	if(!(objESCF instanceof ESCF)) objESCF = new ESCF();

	this.m_strServiceUrl		= strServiceUrl;
	this.m_strSiteUrl			= strSiteUrl;
	this.dateNow				= objESCF.CreateDateFromInternalFormatString(strDateNow)
	this.m_strUiInstall			= "";
	this.m_strUiUninstall		= "";
	this.m_strUiActivate		= "";
	this.m_strUiReadMore		= "";
	this.m_strUiBuy				= "";
	this.m_strUiNoConnection	= "";
	this.m_arrApps				= new Array();
	this.m_nCount				= 1;
	this.m_objConstraints		= {};	// this.m_objConstraints[****-****] = SDAppConstraints

	this.GetUiString = function(strType)
	{
		switch(strType) {
			case "i": return this.m_strUiInstall;
			case "u": return this.m_strUiUninstall;
			case "a": return this.m_strUiActivate;
			case "r": return this.m_strUiReadMore;
			case "b": return this.m_strUiBuy;
		}
		return "";
	}

	this.Add = function(strPackageId, strPackageName, nVersion, bActive, strDateExpires, bTrial, bAutoVoucher, strIconSrc, strTitle, strDescription, strLinkBo, strLinkBase)
	{
		this.m_arrApps.push(new SDApplication(strPackageId, strPackageName, nVersion, true, true, bActive, strDateExpires, bTrial, bAutoVoucher, "", strIconSrc, strTitle, strDescription, strLinkBo, strLinkBase, ++this.m_nCount, false));
	}

	this.Append = function(strPackageId, strPackageName, nVersion, bHasLicense, bActive, strDateExpires, bTrial, bAutoVoucher, strLabel, strIconSrc, strTitle, strDescription, strLinkBo, strLinkBase, nSortOrder)
	{
		if(typeof(this.m_strServiceUrl) == "string" && this.m_strServiceUrl.length > 0 && objESCF.IsAjaxEnabled()) {
			var strQuery = "?type=admin&cmd=updatepackage";
			strQuery += "&packageid="	+ encodeURIComponent(strPackageId);
			strQuery += "&active="		+ (bActive ? "true" : "false");
			strQuery += "&dateexpires=" + encodeURIComponent(strDateExpires);
			strQuery += "&trial="		+ (bTrial ? "true" : "false");
			strQuery += "&linkbase="	+ encodeURIComponent(strLinkBase);
			strQuery += "&sortorder="	+ nSortOrder;
			objESCF.DoRequest("GET", this.m_strServiceUrl + strQuery, "");
		}
	
		var objApp = null;
		for(var i = 0; i < this.m_arrApps.length; ++i) {
			if(strPackageId == this.m_arrApps[i].m_strPackageId) {
				objApp = this.m_arrApps[i];
				break;
			}
		}
		if(objApp != null) {
			// Update from lv
			objApp.m_bActive		= bActive;
			objApp.m_dateExpires	= objESCF.CreateDateFromInternalFormatString(strDateExpires);
			objApp.m_bTrial			= bTrial;
			objApp.m_nSortOrder		= nSortOrder;
			objApp.m_strLinkBase	= strLinkBase;

			if(!objApp.m_bActive && typeof(objApp.m_strLinkBo) == "string" && objApp.m_strLinkBo.length > 0) {
				objApp.m_strLinkBo = objApp.GetUrl("r");
			}
			if(objApp.m_nVersion < nVersion) {
				objApp.m_bNewVersionExists = true;
			}

		} else {
			this.m_arrApps.push(new SDApplication(strPackageId, strPackageName, nVersion, false, bHasLicense, bActive, strDateExpires, bTrial, bAutoVoucher, strLabel, strIconSrc, strTitle, strDescription, strLinkBo, strLinkBase, nSortOrder, false));
		}
	}

	this.GetApplication = function(strPackageId)
	{
		for(var i = 0; i < this.m_arrApps.length; ++i) {
			if(strPackageId == this.m_arrApps[i].m_strPackageId) {
				return this.m_arrApps[i];
			}
		}
		return null;
	}
	
	this.GetApplications = function(bInstalled)
	{
		var arr = new Array();
		for(var i = 0; i < this.m_arrApps.length; ++i) {
			if(bInstalled == this.m_arrApps[i].m_bInstalled) {
				arr.push(this.m_arrApps[i]);
			}
		}
		arr.sort(function(o1, o2) { return o1.m_nSortOrder < o2.m_nSortOrder ? -1 : (o1.m_nSortOrder == o2.m_nSortOrder ? (o1.m_strTitle < o2.m_strTitle ? -1 : (o1.m_strTitle == o2.m_strTitle ? 0 : 1)) : 1) });
		return arr;
	}

	this.CheckOkToInstall = function(strPackageId)
	{
		var objConstraints = this.m_objConstraints[strPackageId];
		if(!(objConstraints instanceof SDAppConstraints)) return true;

		for(var i = 0; i < objConstraints.m_arrNot.length; ++i) {
			if(this.GetApplication(objConstraints.m_arrNot[i]).m_bInstalled) return false;
		}

		for(var i = 0; i < objConstraints.m_arrAnd.length; ++i) {
			if(!this.GetApplication(objConstraints.m_arrAnd[i]).m_bInstalled) return false;
		}
		if(objConstraints.m_arrOr.length == 0) return true;

		for(var i = 0; i < objConstraints.m_arrOr.length; ++i) {
			if(this.GetApplication(objConstraints.m_arrOr[i]).m_bInstalled) return true;
		}
		return false;
	}
}

var NODE_ELEMENT				= 1;
var NODE_ATTRIBUTE				= 2;
var NODE_TEXT					= 3;
var NODE_CDATA_SECTION			= 4;
var NODE_ENTITY_REFERENCE		= 5;
var NODE_ENTITY					= 6;
var NODE_PROCESSING_INSTRUCTION	= 7;
var NODE_COMMENT				= 8;
var NODE_DOCUMENT				= 9;
var NODE_DOCUMENT_TYPE			= 10;
var NODE_DOCUMENT_FRAGMENT		= 11;
var NODE_NOTATION				= 12;

function ESCFNode(objXMLNode)
{
	this.CheckXMLNode = function(objNode)
	{
		var bOK = false;
		try {
			if(objNode != null && typeof(objNode) != "undefined" && objNode.nodeType != null && typeof(objNode.nodeType) != "undefined" && !(isNaN(objNode.nodeType))) bOK = true;
		} catch(e) { bOK = false; }
		return bOK;	
	}

	this.GetName = function()
	{
		if(!this.CheckXMLNode(objXMLNode)) return "";
		return objXMLNode.nodeName;
	}

	this.GetValue = function()
	{
		if(!this.CheckXMLNode(objXMLNode) || objXMLNode.nodeType != NODE_TEXT) return "";
		return objXMLNode.nodeValue;
	}

	this.GetType = function()
	{
		if(!this.CheckXMLNode(objXMLNode)) return -1;
		return objXMLNode.nodeType;
	}

	this.GetAttribute = function(strName)
	{
		if(!this.CheckXMLNode(objXMLNode) || objXMLNode.nodeType != NODE_ELEMENT) return "";
		return objXMLNode.getAttribute(strName);
	}

	this.ChildGetNum = function()
	{
		if(!this.CheckXMLNode(objXMLNode)) return 0;
		return objXMLNode.childNodes.length;
	}

	this.ChildGetIndex = function(nIndex)
	{
		if(!this.CheckXMLNode(objXMLNode)) return null;
		return new ESCFNode(objXMLNode.childNodes.item(nIndex));
	}

	this.ChildGetByName = function(strName)
	{
		if(!this.CheckXMLNode(objXMLNode)) return null;
		for(var i = 0; i < objXMLNode.childNodes.length; ++i) {
			var s = objXMLNode.childNodes.item(i).nodeName;
			if(s.toUpperCase() == strName.toUpperCase()) return new ESCFNode(objXMLNode.childNodes.item(i));
		}
		return null;
	}

	this.GetFirstText = function()
	{
		if(!this.CheckXMLNode(objXMLNode)) return "";
		if(this.GetType() == NODE_TEXT) return this.GetValue();
		for(var i = 0; i < this.ChildGetNum(); ++i) {
			var s = this.ChildGetIndex(i).GetFirstText();
			if(s != "") return s;
		}
		return "";
	}
}

function ESCFListener(strChannelId, objFunction)
{
	this.strChannelId	= strChannelId;
	this.objFunction	= objFunction;
}

var g_ESCFMessageListeners = new Array();

function ESCF()
{
	this.XMLDoc		= null;

	this.GetRef = function(strId)
	{
		return (document.all) ? document.all[strId] : document.getElementById(strId);
	}

	this.QuoteHtmlAttribute = function(str)
	{
		str += "";
		str = str.replace(/\&/g, "&amp;");
		str = str.replace(/\</g, "&lt;");
		str = str.replace(/\>/g, "&gt;");
		str = str.replace(/\"/g, "&quot;");
		str = str.replace(/\'/g, "&apos;");
		return str;
	}

	this.LayerWrite = function(strId, strHtml)
	{
		var obj = this.GetRef(strId);
		if(obj == null || typeof(obj) == "undefined") return;
		obj.innerHTML = strHtml;
	}

	this.SwitchImage = function(strId, strFileName)
	{
		var objImage = this.GetRef(strId);
		if(objImage == null || typeof(objImage) == "undefined") return;
		objImage.src = strFileName;
	}

	this.CreateDateFromInternalFormatString = function(str)
	{
		try {
			var arr = str.split(",");
			if(arr.length != 6) return null;
			return new Date(arr[0], parseInt(arr[1]) - 1, arr[2], arr[3], arr[4], arr[5]); 
		} catch(e) {}
		return null;
	}

	this.CreateInternalFormatStringFromDate = function(objDate)
	{
		try {
			return (objDate instanceof Date) ? objDate.getFullYear() + "," + (objDate.getMonth() + 1) + "," + objDate.getDate() + "," + objDate.getHours() + "," + objDate.getMinutes() + "," + objDate.getSeconds() : "";
		} catch(e) {}
		return "";
	}

	this.Fix2Digits = function(str)
	{
		str += "";
		return (str.length < 2 ? "0" + str : str);
	}

	this.IsAdminLoggedOn = function()
	{
		try {
			if(!this.IsAjaxEnabled()) return false;

			var strGet = "http://www.webrevisor.dk/admin/sd_admin_services.php?type=admin&cmd=getloginpackages";
			if(strGet.search(/\[/) != -1 || strGet.search(/\]/) != -1) return false;
			if(this.DoRequest("GET", strGet, "")) {
				var objEntryNode = this.NodeGetRoot().ChildGetByName("sd_admin_admin_getloginpackages");
				return objEntryNode != null && objEntryNode.GetAttribute("status") == "ok";
			}
		} catch(e) {}

		return false;
	}

	this.MessageSend = function(strChannelId, strFromId, strCmd, nParam, strParam, objParam)
	{
		if(window.opener && typeof(window.opener.g_ESCFMessageListeners) != "undefined")
			g_ESCFMessageListeners = window.opener.g_ESCFMessageListeners;
		for(var i = 0; i < g_ESCFMessageListeners.length; ++i) {
			if(strChannelId == g_ESCFMessageListeners[i].strChannelId)
				g_ESCFMessageListeners[i].objFunction(strChannelId, strFromId, strCmd, nParam, strParam, objParam);
		}
	}

	this.MessageListenerAdd = function(strChannelId, objFunction)
	{
		g_ESCFMessageListeners[g_ESCFMessageListeners.length] = new ESCFListener(strChannelId, objFunction);
	}		
		
	this.IsAjaxEnabled = function()
	{
		var bOK = false;
		try {
			var objHttpXmlRequest = null;
			if(window.XMLHttpRequest) {		// Use native object
				objHttpXmlRequest = new XMLHttpRequest();
			} else {
				if(window.ActiveXObject) {	// ...otherwise, use the ActiveX control for IE5.x and IE6
					objHttpXmlRequest = new ActiveXObject("Microsoft.XMLHTTP");
				}
			}
			bOK = objHttpXmlRequest != null;
			objHttpXmlRequest = null;
		} catch(e) { bOK = false; }
		return bOK;
	}

	this.NodeGetRoot = function()
	{
		return new ESCFNode(this.XMLDoc);
	}

	this.NodesGetByTagName = function(strTagName)
	{
		var arr = new Array();
		if(this.XMLDoc == null) return arr;
		var objItems = this.XMLDoc.getElementsByTagName(strTagName);
		for(var i = 0; i < objItems.length; ++i) {
			arr[i] = new ESCFNode(objItems.item(i));
		}
		return arr;
	}

	this.FormGetQuerystring = function(strFormId)
	{
		var objForm = this.GetRef(strFormId);
		if(objForm == null || typeof(objForm) + "" == "undefined") return "";

		var strRet = "";
		// Extract the name and value for each form element
		for(var i = 0; i < objForm.elements.length; ++i) {
			var objElement = objForm.elements[i];
			switch(objElement.type + "") {
				case "text":
				case "hidden":
				case "password":
				case "textarea":
					strRet += "&" + objElement.name + "=" + encodeURIComponent(objElement.value);
					break;

				case "select-one":
				case "select-multiple":
					for(var j = 0; j < objElement.options.length; ++j) {
						strRet += objElement.options[j].selected ? "&" + objElement.name + "=" + encodeURIComponent(objElement.options[j].value) : "";
					}
					break;

				case "checkbox":
				case "radio":
					strRet += objElement.checked ? "&" + objElement.name + "=" + encodeURIComponent(objElement.value) : "";
					break;
			}
		}
		if(strRet.substr(0, 1) == "&") strRet = strRet.substr(1);
		return strRet;
	}

	this.DoRequest = function(strMethod, strUrl, strData)
	{
		this.XMLDoc = null;
		var objHttpXmlRequest = null;
		if(window.XMLHttpRequest) {		// Use native object
			objHttpXmlRequest = new XMLHttpRequest();
		} else {
			if(window.ActiveXObject) {	// ...otherwise, use the ActiveX control for IE5.x and IE6
				objHttpXmlRequest = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}

		objHttpXmlRequest.open(strMethod.toUpperCase(), strUrl, false);
		if(strMethod.search(/POST/i) == 0) {
			objHttpXmlRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		}
		objHttpXmlRequest.send(strData);

		if(objHttpXmlRequest.status == 200) {
			this.XMLDoc = objHttpXmlRequest.responseXML;
		}
		return this.XMLDoc != null;
	}

	this.DoRequestPostForm = function(strFormId, strUrl)
	{
		return this.DoRequest("POST", strUrl, this.FormGetQuerystring(strFormId));
	}
}

//--------------------------------------------------------------------------------
//	Resource Picker... (requires jQuery)
//--------------------------------------------------------------------------------

// Custom Variables...
var g_strResPickerPackage		= "sd_admin";
var g_strResPickerClose			= "Close";
var g_strResPickerSelectFile	= "Select file";
var g_strResPickerHit			= "hit";
var g_strResPickerHits			= "hits";
var g_strResPickerDBFailed		= "File upload succeeded, but the file could not be added to the database.";
var g_strResPickerUploadFailed	= "File upload failed, please try again.";
var g_nResPickerIconCols		= 4;

// Internal variables...
var g_strResPickerCurId			= "";
var g_strResPickerSearchFor		= "";
var g_nResPickerTimeout			= 0;

//$(document).ready(function() {
//	$("div.res_picker").each(function(nIndex, obj) {
//		RefreshResourceList($(this).attr("id"));
//	});
//});

function FillResourcePicker(strId, nImageMargin, nIconWidth) 
{
	if(typeof(g_strResPickerSearchFor) == "string" && g_strResPickerSearchFor != "") $("#search_displaypicker").attr("value", g_strResPickerSearchFor).removeClass("blursearch");
	$.get("sd_admin_services.php?type=resources&cmd=getimages&searchfor=" + encodeURIComponent(g_strResPickerSearchFor) + "", function(data, strStatus, objHttpXmlRequest) {
		var objESCF = new ESCF();
		objESCF.XMLDoc = objHttpXmlRequest.responseXML;
		var arr = objESCF.NodesGetByTagName("image");

		$("#" + strId).empty();
		$("#search_displaypicker_label").empty();
		$("#search_displaypicker_label").append("<span>" + (g_strResPickerSearchFor.length == 0 ? "" : arr.length + " " + (arr.length == 1 ? g_strResPickerHit : g_strResPickerHits)) + "</span>");
		for(var i = 0; i < arr.length; ++i) {
			var nImgWidth	= parseInt(arr[i].GetAttribute("width"));
			var nImgHeight	= parseInt(arr[i].GetAttribute("height"));
			var nIconHeight = nIconWidth;
			var bLandscape = nImgWidth > nImgHeight;
			var nW = nImgWidth > nIconWidth ? nIconWidth : nImgWidth;
			var nH = nImgHeight > nIconHeight ? nIconHeight : nImgHeight;
			if(bLandscape) {
				if(nImgHeight > nIconHeight) {
					nH = Math.round(nImgHeight / nImgWidth * nIconHeight);
				}
			} else {
				if(nImgWidth > nIconWidth) {
					nW = Math.round(nImgWidth / nImgHeight * nIconWidth);
				}
			}
			var nMarginTop		= (nIconHeight - nH);
			var nMarginBottom	= 0;
			var nMarginLeft		= Math.round((nIconWidth - nW) / 2);
			var nMarginRight	= nIconWidth - nW - nMarginLeft;
			var bPicked			= $("#" + g_strResPickerCurId + "_resourceid").attr("value") == arr[i].GetAttribute("src");
			var strResources = "";
			strResources += "<div style=\"float:left;text-align:center;padding-bottom:10px;margin-right:" + nImageMargin + "px;margin-bottom:" + (nImageMargin * 2) + "px;\">";
			strResources += "<div style=\"width:" + nIconWidth + "px;height:" + nIconHeight + "px;\">";
			strResources += "<a class=\"pick\" href=\"#\">";
			strResources += "<img src=\"" + arr[i].GetAttribute("src").replace("\/" + g_strResPickerPackage + "\/", "/" + g_strResPickerPackage + "/tn120_") + "\" class=\"" + (bLandscape ? "landscape" : "portrait") + "\" name=\"" + arr[i].GetAttribute("src") + "\" style=\"width:" + nW + "px;height:" + nH + "px;margin:" + nMarginTop + "px " + nMarginRight + "px " + nMarginBottom + "px " + nMarginLeft + "px;\" title=\"" + arr[i].GetAttribute("title") + "\" alt=\"" + arr[i].GetAttribute("alt") + "\" />";
			strResources += "</a>";
			strResources += "</div>";
			strResources += "<div style=\"padding:2px;margin-top:2px;" + (bPicked ? "background-color:#eee;color:#000;" : "") + "\">" + (typeof(SDStringLimit) == "function" ? SDStringLimit(arr[i].GetAttribute("title"), 20, "...") : arr[i].GetAttribute("title").substr(0, 20)) + "</div>";
			strResources += "</div>";
			$("#" + strId).append(strResources);
		}
		$("#" + strId).show();
	}, "text/xml");
}

function DisplayPicker(e)
{
		var strId = $(this).attr("id");
		if(g_strResPickerCurId == strId) return;
		g_strResPickerCurId = strId;

		$("#div_displaypicker").hide();
		
		var nWindowWidth = $(window).width();
		var nWindowHeight = $(window).height();
		
		var nCols			= 4
		var nPopupHeight	= 400;
		var nIconWidth		= 120;
		var nImageMargin	= 20;
		var nScroller		= 25;
		var nPopupWidth		= nIconWidth * nCols + nImageMargin * (nCols - 1 + 2) + nScroller;
		
		if(nWindowWidth < nPopupWidth - 80 && nWindowWidth > 200) {
			nPopupWidth = nWindowWidth - 80;
			nIconWidth = Math.round((nPopupWidth - nScroller - nImageMargin * (nCols - 1 + 2)) / nCols);
		}
		if(nWindowHeight < nPopupHeight - 80 && nWindowHeight > 100) {
			nPopupHeight = nWindowHeight - 80;
		}

		var nX = (nWindowWidth - nPopupWidth) / 2;
		var nY = (nWindowHeight - nPopupHeight) / 2;
		if(nX < 0) nX = 0;
		if(nY < 0) nY = 0;
		nX += $(document).scrollLeft();
		nY += $(document).scrollTop();
		
		var strDiv = "";
		strDiv += "<div id=\"div_displaypicker\" style=\"z-index:1;display:none;position:absolute;width:" + nPopupWidth + "px;left:" + nX + "px;top:" + nY + "px;padding:0;border:solid 1px #808080;\">";
		strDiv += "<div>";
		strDiv += "<table class=\"topbar\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"height:28px;\"><tr><td style=\"vertical-align:middle;width:30px;\"><a href=\"#\" class=\"add\"><img src=\"img/sd_eshop_plus.png\" alt=\"\" style=\"vertical-align:middle;margin:0 7px\" /></a><span style=\"position:relative;\" id=\"file_container\"></span></td><td style=\"vertical-align:middle;margin:0;\"><input type=\"text\" class=\"blursearch\" value=\"\" id=\"search_displaypicker\" style=\"height:14px;\" /><span id=\"search_displaypicker_label\" style=\"margin-left:5px;\"></span></td><td class=\"logo\" style=\"vertical-align:middle;text-align:right;\"><a href=\"#\" class=\"close\" title=\"" + g_strResPickerClose + "\"><img src=\"img/sd_eshop_delete.png\" alt=\"\" title=\"" + g_strResPickerClose + "\" style=\"float:right;margin:0 7px\" /></a></td></tr></table>";
		strDiv += "</div>";
		strDiv += "<div style=\"height:" + nPopupHeight + "px;overflow:auto;padding:" + nImageMargin + "px 0 " + nImageMargin + "px " + nImageMargin + "px;border-top:solid 1px #808080;background-color:#ffffff;\" id=\"div_displaypicker_images\"></div>";
		strDiv += "</div>";
		if($("#div_displaypicker").length == 0) {
			$("body").prepend(strDiv);
		} else {
			$("#div_displaypicker").replaceWith(strDiv);
		}
		AttachSearchFormFocusEvents();

		$("#div_displaypicker").show();
		FillResourcePicker("div_displaypicker_images", nImageMargin, nIconWidth);

		$("#div_displaypicker a.close").click(function(e) {
			$("#div_displaypicker").hide();
			g_strResPickerCurId = "";
			e.preventDefault();
		});

		var bIframeAdded	= false;
		var bFormSubmitted	= false;
		$("#div_displaypicker a.add").click(function(e) {
			$.get("sd_admin_services.php?type=admin&cmd=createtoken&cat=" + encodeURIComponent(g_strResPickerPackage) + "", function(data, strStatus, objHttpXmlRequest) {
				var objESCF = new ESCF();
				objESCF.XMLDoc = objHttpXmlRequest.responseXML;
				var arr = objESCF.NodesGetByTagName("sd_admin_admin_createtoken");
				if(arr.length == 1) {
					var strToken = arr[0].GetAttribute("token");

					$("#file_container").append("<div style=\"display:none;\"><iframe id=\"file_iframe\" name=\"file_iframe\" style=\"display:none;\" /></div>");
					$("#file_container").append("<form method=\"post\" action=\"sd_admin_fu" + (".php" == ".asp" ? ".aspx" : ".php") + "?cat=" + encodeURIComponent(g_strResPickerPackage) + "&t=" + encodeURIComponent(strToken) + "\" enctype=\"multipart/form-data\" id=\"file_form\" target=\"file_iframe\" style=\"position:absolute;top:0px;left:5px;background-color:#e8e8e8;border:solid 1px #808080;padding:10px;white-space:nowrap;\">" + g_strResPickerSelectFile + ":<br /><input type=\"file\" id=\"add_file\" name=\"add_file\" /></form>");
					bIframeAdded	= true;
					bFormSubmitted	= false;

					$("#file_form").mousedown(function(e) {
						e.stopPropagation();
					});
					
					$(document).mousedown(function(e) {
						if(!bIframeAdded) return;
						$("#file_iframe").remove();
						$("#file_form").remove();
						bIframeAdded = false;
					});

					var interval = null;
					$("#add_file").click(function(e) {
						interval = setInterval(function() {
							if(!bIframeAdded) return;
							var strValue = $("#add_file").attr("value");
							if(strValue != "" && !bFormSubmitted) {
								$("#file_form")[0].submit();
								$("#file_form").css("display", "none");
								bFormSubmitted = true;
								clearInterval(interval);
								return;
							}
						}, 200);
					});

					$("#file_iframe").load(function(e) {
						var iframe = $("#file_iframe").first()[0];
						var doc = iframe.contentDocument ? iframe.contentDocument : frames[iframe.id].document;

						var objESCF = new ESCF();
						objESCF.XMLDoc = (typeof(doc.XMLDocument) == "undefined" ? doc : doc.XMLDocument);
						var arrStatus = objESCF.NodesGetByTagName("swfileupload");
						if(typeof(doc.body) == "undefined" || (typeof(doc.body) != "undefined" && doc.body.innerHTML.length > 0)) {
							var bUploadError = true;
							if(arrStatus.length > 0) {
								if(arrStatus[0].GetAttribute("status") == "ok") {
									if(bIframeAdded) {
										$("#file_iframe").remove();
										$("#file_form").remove();
										bIframeAdded = false;
									}
									var arr = objESCF.NodesGetByTagName("file");
									if(arr.length > 0) {
										bUploadError = false;
										for(var i = 0; i < arr.length; ++i) {
											var strUrl = "";
											strUrl += "sd_admin_services.php?type=resources&cmd=addresource";
											strUrl += "&resourceid=" + encodeURIComponent(arr[i].GetAttribute("relpath"));
											strUrl += "&mimetype=" + encodeURIComponent(arr[i].GetAttribute("mimetype"));
											strUrl += "&url=" + encodeURIComponent(arr[i].GetAttribute("relpath"));
											strUrl += "&width=" + encodeURIComponent(arr[i].GetAttribute("width"));
											strUrl += "&height=" + encodeURIComponent(arr[i].GetAttribute("height"));
											strUrl += "&filesize=" + encodeURIComponent(arr[i].GetAttribute("filesize"));
											$.get(strUrl, function(data, strStatus, objHttpXmlRequest) {
												var objESCF = new ESCF();
												objESCF.XMLDoc = objHttpXmlRequest.responseXML;
												var arr = objESCF.NodesGetByTagName("sd_admin_resources_addresource");
												if(arr.length != 1 || arr[0].GetAttribute("status") != "ok") {
													// db update failed...
													alert(g_strResPickerDBFailed);
													if(bIframeAdded) {
														$("#file_iframe").remove();
														$("#file_form").remove();
														bIframeAdded = false;
													}
												} else {
													g_strResPickerSearchFor = "";
													$("#search_displaypicker").attr("value", "").blur();
												}
											});
										}
									}
								}
							}
							if(bUploadError) {
								// file upload failed...
								alert(g_strResPickerUploadFailed);
								if(bIframeAdded) {
									$("#file_iframe").remove();
									$("#file_form").remove();
									bIframeAdded = false;
								}
							}
						}
					});
				}
			});

			e.preventDefault();
			return false;
		});

		$(document).ajaxComplete(function(e, objXmlHttpRequest, ajaxOptions) {
			if(ajaxOptions.url.search(/addresource/i) != -1) {
				FillResourcePicker("div_displaypicker_images", nImageMargin, nIconWidth);
			}
			$("#div_displaypicker_images a.pick").click(function(e) {
				$("#div_displaypicker").hide();

				if(g_strResPickerCurId != "") {
					var strTypeId = g_strResPickerCurId;
					var n = strTypeId.search(/__/);
					if(n != -1) {
						strTypeId = strTypeId.substr(0, n);
						var strResourceId	= $(this).children("img").first().attr("name");
						var strTnSrc		= $(this).children("img").first().attr("src");
						$("#" + g_strResPickerCurId).children("img").attr("src", strTnSrc);
						var strPickClass = $(this).children("img").first().attr("class");

						var strFields = "";
						var strName = $("#" + strTypeId + "_fields").attr("name")
						var arr = strName.split("|||");
						var strResourceTypeId	= arr[0];
						var strMaxCount			= arr[1];
						strFields += "<div id=\"" + strTypeId + "_fields\" name=\"" + strName + "\">\r\n";
						var nCount = 0;
						$(".displaypicker[id^=" + strTypeId + "]").each(function(e) {
							var strId		= $(this).attr("id");
							var strName		= $(this).attr("name");
							var strResId	= g_strResPickerCurId == strId ? strResourceId : strName;
							var strClass	= g_strResPickerCurId == strId ? strPickClass : $(this).parent().attr("class");
							if(strResId != "") {
								strFields += "<input type=\"hidden\" id=\"" + strTypeId + "__" + nCount + "_resourceid\" name=\"" + strTypeId + "__" + nCount + "_resourceid\" value=\"" + strResId + "\" class=\"" + strClass + "\" />\r\n";
								strFields += "<input type=\"hidden\" id=\"" + strTypeId + "__" + nCount + "_resourcetypeid\" name=\"" + strTypeId + "__" + nCount + "_resourcetypeid\" value=\"" + strResourceTypeId + "\" />\r\n";
								strFields += "<input type=\"hidden\" id=\"" + strTypeId + "__" + nCount + "_sortorder\" name=\"" + strTypeId + "__" + nCount + "_sortorder\" value=\"" + nCount + "\" />\r\n";
								++nCount;
							}
						});
						strFields += "<input type=\"hidden\" id=\"" + strTypeId + "_num\" name=\"" + strTypeId + "_num\" value=\"" + nCount + "\" />";
						strFields += "</div>\r\n";
						$("#" + strTypeId + "_fields").replaceWith(strFields);

						RefreshResourceList(strTypeId);
					}
				}
				g_strResPickerCurId = "";
				e.preventDefault();
			});
		});

		$("#search_displaypicker").keyup(function(e) {
			g_strResPickerSearchFor = $(this).attr("value");
			FillResourcePicker("div_displaypicker_images", nImageMargin, nIconWidth);
		});

		$(document).keyup(function(e) {
			if(e.keyCode == 27) {	// escape key
				if(bIframeAdded) {
					$("#file_iframe").remove();
					$("#file_form").remove();
					bIframeAdded = false;
				}
				$("#div_displaypicker").hide();
				g_strResPickerCurId = ""

				e.stopPropagation();
				e.preventDefault();
			}
		});

		e.preventDefault();
}

function RefreshResourceList(strId)
{
	var strPicker = "<div id=\"" + strId + "\">";
	strPicker += "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tbody>";
	strPicker += "<tr>";
	for(var i = 0; i < g_nResPickerIconCols; ++i) strPicker += "<td style=\"padding:0;\"><div style=\"width:130px;height:1px;\"></div></td>\r\n";
	strPicker += "</tr><tr>";
	var nCount = 0;
	$("#" + strId + "_fields input[id$=\"_resourceid\"]").each(function(nIndex, obj) {
		if(nCount > 0 && nCount % g_nResPickerIconCols == 0) strPicker += "</tr><tr>";

		var strClass = $(this).attr("class");

		var strPickerId = strId + "__" + nCount;
		strPicker += "<td style=\"vertical-align:bottom;text-align:center;\"><div style=\"position:relative;height:120px;\" class=\"" + strClass + "\"><a href=\"#\" class=\"displaypicker res_core\" id=\"" + strPickerId + "\" name=\"" + $(this).attr("value") + "\"><img class=\"picker " + strClass + "\" src=\"" + $(this).attr("value") + "\" /></a></div></td>";
		++nCount;
	});
	if(nCount < parseInt($("#" + strId + "_fields").attr("name").split("|||")[1])) {
		if(nCount > 0 && nCount % g_nResPickerIconCols == 0) strPicker += "</tr><tr>";
		strPickerId = strId + "__" + nCount;
		strPicker += "<td style=\"position:relative;width:120px;\"><a href=\"#\" class=\"displaypicker\" id=\"" + strPickerId + "\" name=\"\"><img class=\"picker\" src=\"files/sd_no_image_en.png\" /></a></td>";
		++nCount;
	}
	var nFillColspan = g_nResPickerIconCols - nCount % g_nResPickerIconCols;
	if(nFillColspan > 0 && nFillColspan < g_nResPickerIconCols) strPicker += "<td " + (nFillColspan > 1 ? "colspan=\"" + nFillColspan + "\"" : "") + ">&nbsp;</td>";
	strPicker += "</tr>";
	strPicker += "</tbody></table>";
	strPicker += "</div>";

	$("#" + strId).replaceWith(strPicker)
	$("a.displaypicker").click(DisplayPicker);
	$("a.res_core").mouseover(function(e) {
		clearTimeout(g_nResPickerTimeout);
		$("#res_delete_container").remove();
		$(this).parent().prepend("<div id=\"res_delete_container\"><a href=\"#\" class=\"res_delete\" name=\"" + $(this).attr("value") + "\" title=\"Remove\"><img src=\"files/sd_res_delete.png\" alt=\"\" /></a></div>");

		$("a.res_delete").click(function(e) {
			var strCoreId = $(this).parent().parent().children().filter("a.res_core").attr("id");
			$("input[id^=" + strCoreId + "_]").remove();
			clearTimeout(g_nResPickerTimeout);
			$("#res_delete_container").remove();

			{
				var $objCount = $("#" + strId + "_num");
				var strCount = $objCount.attr("value");
				var nCount = parseInt(strCount);
				nCount = isNaN(nCount) ? 0 : (nCount - 1);
				$objCount.attr("value", nCount);
			}

			var nPos = strCoreId.search(/__/);
			var nIndexSource = parseInt(strCoreId.substr(nPos + 2));
			var strTypeId = strCoreId.substr(0, nPos);
			$("input[id^=" + strTypeId + "]").each(function(nIndex, obj) {
				var strId = $(this).attr("id");
				var nPos = strId.search(/__/);
				var nCurIndex = parseInt(strId.substr(nPos + 2));
				if(nCurIndex > nIndexSource) {
					$(this).attr("id", strId.replace("__" + nCurIndex + "_", "__" + (nCurIndex - 1) + "_"));
					$(this).attr("name", strId.replace("__" + nCurIndex + "_", "__" + (nCurIndex - 1) + "_"));
				}
			});

			RefreshResourceList(strTypeId);
			return false;
		});
	});
	$("a.res_core").mouseout(function(e) {
		if($(e.relatedTarget).parent().parent().attr("id") == "res_delete_container") return;
		clearTimeout(g_nResPickerTimeout);
		g_nResPickerTimeout = setTimeout("$(\"#res_delete_container\").remove()", 1000);
	});
}

