/*
 * RADactive I-Load 2009.R1
 * Copyright © 2005-2010 RADactive srl - All Rights Reserved.
 * <www.RADactive.com>
 * Author: Sergio Turolla
 */
 
function StringReplace(sStr, search, replace)
{
	if (!sStr)
	{
		return sStr;
	}
	var result = sStr;
	while (result.indexOf(search) >= 0)
	{
		var newResult = result.replace(search, replace);
		if (newResult != result)
		{
			result = newResult;
		}
		else
		{
			break
		}
	}
	return result;
}

function GetFileNameWithExtension(file)
{
	if (file == null)
	{
		file = "";
	}
	file = file.replace("/","\\");
	var vett = file.split("\\");
	if (vett.length > 0)
	{
		return vett[vett.length - 1];
	}
	else
	{
		return "";
	}	
}

function GetFileNameWithoutExtension(file)
{
	var fileName = GetFileNameWithExtension(file);
	var p1 = fileName.lastIndexOf(".");
	if (p1 > 0)
	{
		return fileName.substr(0, p1);
	}
	else
	{
		return fileName;
	}
}

function URLEncode(sStr) 
{
	if (typeof encodeURIComponent != "undefined")
	{
		return encodeURIComponent(sStr);
	}
	else
	{
		var result = escape(sStr);
		result = StringReplace(result, "+", "%2b");
		result = StringReplace(result, "\"", "%22");
		result = StringReplace(result, "'", "%27");
		result = StringReplace(result, "/", "%2f");
		return result;
	}
}

function URLDecode(sStr) 
{
	if (typeof decodeURIComponent != "undefined")
	{
		return decodeURIComponent(sStr);
	}
	else
	{
		var result = unescape(sStr);
		return result;
	}

}

function listenEvent(targetElement, eventName, functionReference) 
{
	if (targetElement.addEventListener)
	{
		targetElement.addEventListener(eventName, functionReference, false);
	}
	else
	{
		if (targetElement.attachEvent) 
		{
			var result = targetElement.attachEvent("on" + eventName, functionReference);
			return result;
		}
	}
}

function Size(width, height)
{
	this.Width = width;
	this.Height = height;
}
Size.prototype.Width = 0;
Size.prototype.Height = 0;

function Rectangle(x,y,width,height)
{
	this.X = x;
	this.Y = y;
	this.Width = width;
	this.Height = height;
}
Rectangle.prototype.X = 0;
Rectangle.prototype.Y = 0;
Rectangle.prototype.Width = 0;
Rectangle.prototype.Height = 0;


function ImageCropFilters()
{
	this.SourceImageSize = new Size(0,0);
	this.SourceRectangle = new Rectangle(0,0,0,0);
}
ImageCropFilters.prototype.SourceImageSize = null;
ImageCropFilters.prototype.ZoomFactor = 100;
ImageCropFilters.prototype.SourceRectangle = null
ImageCropFilters.prototype.RotationAngle = 0;
ImageCropFilters.prototype.FlipHorizontal = false;
ImageCropFilters.prototype.FlipVertical = false;

//-------------------------------------------------------

if (!window.DOMParserUseXMLRepeater)
{
	window.DOMParserUseXMLRepeater = false;
}
if (typeof window.DOMParser == "undefined") 
{
	function DOMParser() {}
}
if (typeof window.DOMParser != "undefined") 
{
	if (typeof window.DOMParser.parseFromString == "undefined") 
	{
		window.DOMParserUseXMLRepeater = true;
		
		var fLoad = function (str, contentType) 
		{
			//var ieVersion = Radactive.WebControls.GetIEVersion();
			//if ((ieVersion < 7) && (window.ActiveXObject)) 
			if (window.ActiveXObject)
			{
				var d = new ActiveXObject("MSXML.DomDocument");
				d.loadXML(str);
				return d;
			} 
			else if (window.XMLHttpRequest) 
			{
				var req = new XMLHttpRequest;

				req.open("POST", "WebCoreModule.ashx?__ac=1&__ac_wcmid=RAWCIL&__ac_lib=Radactive.WebControls.ILoad&__ac_key=RAWVCO_501&__ac_sid=s4rfctrneoukwdrduxhxqdaw&__ac_cn=&__ac_ssid=&fr=" + escape(Date()), false);
				req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
								
				req.send("xml=" + URLEncode(str));
				var res = req.responseXML;
				return res;
			}
		}
		
		if (DOMParser.prototype)
		{
			DOMParser.prototype.parseFromString = fLoad;
		}
		else
		{
			DOMParser.parseFromString = fLoad;
		}
	}
}

if (document.implementation && document.implementation.createDocument)
{
	var doc = document.implementation.createDocument("", "doc", null);
	if (!doc.loadXML)
	{
		if (typeof(Document) != "undefined")
		{
			if (Document.prototype)
			{
				Document.prototype.loadXML = function (s) 
				{  
					var doc2 = (new DOMParser()).parseFromString(s, "text/xml");
					      
					while (this.hasChildNodes())
					{
						this.removeChild(this.lastChild);
					}

					for (var i = 0; i < doc2.childNodes.length; i++) 
					{
						this.appendChild(this.importNode(doc2.childNodes[i], true));
					}
				}
			}
		}
	}
}

function createXMLDOM(rootTagName)
{
	return createXMLDOMFromString("<" + rootTagName + " />");
}

function createXMLDOMFromString(str)
{
	var doc;
	
	//var ieVersion = Radactive.WebControls.GetIEVersion();
	//if ((ieVersion < 7) && (window.ActiveXObject))
	if (window.ActiveXObject)
	{
		doc = new ActiveXObject("Microsoft.XMLDOM")
		doc.loadXML(str);
	}
	else
	{
		if (window.DOMParserUseXMLRepeater)
		{
			doc = (new DOMParser()).parseFromString(str, "text/xml");
		}
		else
		{
			doc = document.implementation.createDocument("", "doc", null);
			doc.loadXML(str);
		}
	}

	return doc;
}

function createXMLDOMFromRequest(url, async)
{
	var doc;

	//var ieVersion = Radactive.WebControls.GetIEVersion();
	//if ((ieVersion < 7) && (window.ActiveXObject)) 
	if (window.ActiveXObject)
	{
		doc = new ActiveXObject("Microsoft.XMLDOM")
		doc.async = async;
		doc.load(url);
	}
	else
	{
		if (window.DOMParserUseXMLRepeater)
		{
			if (window.XMLHttpRequest) 
			{
				var req = new XMLHttpRequest;

				req.open("GET", url, false);						
				req.send(null);
				doc = req.responseXML;
			}
		}
		else
		{
			doc = document.implementation.createDocument("", "doc", null);
			doc.async = async;
			doc.load(url);
		}
	}

	return doc;
}

// \u00a0
function htmlAppendText(o, text)
{	
	o.appendChild(document.createTextNode(text));
}

function htmlSetText(o, text)
{
	if(o.firstChild)
	{
		o.firstChild.nodeValue = text;
	}
	else
	{
		htmlAppendText(o, text);
	}
}

function htmlAppendBr(o)
{
	var o2 = document.createElement("br");
	o.appendChild(o2);
}

function clearElement(o)
{	
	while(o.childNodes.length > 0)
	{
		o.removeChild(o.childNodes[o.childNodes.length-1]);
	}
}

function addObject(o, w, h, str)
{
	if (o)
	{
		var newO = document.createElement('div');
		newO.style.width = w;
		newO.style.height = h;
		o.appendChild(newO);
		newO.innerHTML = str;
	}
}

//-------------------------------------------------------

function _Radactive()
{
}

function Radactive_WebControls()
{
}

// MSIE
Radactive_WebControls.prototype.Dialog_hborder = 6;
Radactive_WebControls.prototype.Dialog_vborder = 50;

Radactive_WebControls.prototype.ShowDialog_window = null;
Radactive_WebControls.prototype.ShowDialog_window_isModal = false;

Radactive_WebControls.prototype.GetScaleFactor = function ()
{
	var ieVersion = this.GetIEVersion();
	if (ieVersion >= 6)
	{
		if (screen)
		{
			if ((screen.deviceXDPI) && (screen.logicalXDPI))
			{
				return screen.deviceXDPI / screen.logicalXDPI;
			}
		}
	}
	return 1;
}

Radactive_WebControls.prototype.GetScaledSize = function (size)
{
	return Math.round(size * this.GetScaleFactor())
}

Radactive_WebControls.prototype.GetFormElement = function (elementId)
{
	var result = document.getElementById(elementId);
	if (result)
	{
		return result;
	}
	for(var i=0;i<document.forms.length;i++)
	{
		var result = document.forms[i].elements[elementId];
		if (result)
		{
			return result;
		}
	}
	return result;
}

Radactive_WebControls.prototype.ShowDialog = function (url, width, height, modal, center, resize, title)
{
	this.ShowDialog_window_isModal = false;
	var resizeTxt = "no";
	if (resize)
	{
		resizeTxt = "yes";
	}
	var ieVersion = this.GetIEVersion();
	var isAOL = false;
	if (navigator.userAgent.indexOf("AOL") != -1)
	{
		isAOL = true;
	}
	var isOpera = false;
	if (navigator.userAgent.indexOf("Opera ") != -1)
	{
		isOpera = true;
	}

	if ((ieVersion >= 4) && (!isAOL) && (!isOpera))
	{
		// MSIE
		var hborder = 0;
		var vborder = 0;
		
		if (ieVersion < 7) 
		{
			hborder += this.Dialog_hborder;
			vborder += this.Dialog_vborder;
		}
		
		if (resize)
		{
			hborder += 2;
			vborder += 2;
		}
		
		var scaleFactor = this.GetScaleFactor();
		
		var centerTxt = "no";
		if (center)
		{
			centerTxt = "yes";
		}
		else
		{
			if (window.top.dialogLeft)
			{
				var left = parseInt(window.top.dialogLeft) + 20;
				var top = parseInt(window.top.dialogTop) + 20;
				
				var scaledLeft = Math.round(scaleFactor * left);
				var scaledTop = Math.round(scaleFactor * top);
				
				centerTxt += "; dialogLeft=" + scaledLeft + "px; dialogTop=" + scaledTop + "px";
			}
		}
		
		var scaledWidth = Math.round(scaleFactor * (width + hborder));
		var scaledHeight = Math.round(scaleFactor * (height + vborder));		
		
		if (modal)
		{
			this.ShowDialog_window_isModal = true;
			return window.showModalDialog(url,window,"dialogHeight:" + scaledHeight + "px; dialogWidth:" + scaledWidth +"px; resizable:" + resizeTxt +"; help:no; scroll:no; status:yes; center:" + centerTxt);	
		}
		else
		{
			this.ShowDialog_window = window.showModelessDialog(url,window,"dialogHeight:" + scaledHeight + "px; dialogWidth:" + scaledWidth +"px; resizable:" + resizeTxt + "; help:no; scroll:no; status:yes; center:" + centerTxt);	
			return this.ShowDialog_window;
		}	
	}
	else
	{
		// Other browsers...
		this.HideDialog(this.ShowDialog_window);
		var optionsString = "width=" + width + ",height=" + height + ",status=yes,dependent=yes,dialog=yes,close=no,alwaysRaised=yes,modal=yes,resizable=" + resizeTxt;
		this.ShowDialog_window = window.open(url, "ppw", optionsString);
		if (!this.ShowDialog_window)
		{
			alert("A popup blocker was detected, please allow popup.");
		}
		return this.ShowDialog_window;
	}
}

Radactive_WebControls.prototype.ShowDialog2 = function(url, title, width, height, modal, center, resize)
{
	return this.ShowDialog("WebCoreModule.ashx?__ac=1&__ac_wcmid=RAWCIL&__ac_lib=Radactive.WebControls.ILoad&__ac_key=RAWVCO_101&__ac_sid=s4rfctrneoukwdrduxhxqdaw&__ac_cn=&__ac_ssid=&fr=" + URLEncode(Date()) + "&url=" + URLEncode(url) + "&title=" + URLEncode(title), width, height, modal, center, resize, title);
}

Radactive_WebControls.prototype.HideDialog = function (w)
{
	if (w)
	{
		if (!w.closed)
		{
			if (w.close)
			{
				var ex;
				try
				{
					w.close();
				}
				catch(ex)
				{
				}
			}
		}
	}
}

Radactive_WebControls.prototype.GetIEVersion = function()
{
	return 0;
}

function LRMEntry()
{
}

LRMEntry.prototype.Context = "";
LRMEntry.prototype.Culture = "";
LRMEntry.prototype.Key = "";
LRMEntry.prototype.Value = "";

function Radactive_LRM()
{
	this.Entries = new Array();
}

Radactive_LRM.prototype.Entries = null;

Radactive_LRM.prototype.GetString = function(context, culture, key, defaultValue)
{
	var entryIndex = this.GetIndex(context, culture, key);
	if (entryIndex >= 0)
	{
		var entry = this.Entries[entryIndex];
		return entry.Value;
	}
	else
	{
		return defaultValue;
	}
}

Radactive_LRM.prototype.SetString = function(context, culture, key, value)
{
	var entry;
	var entryIndex = this.GetIndex(context, culture, key);
	if (entryIndex >= 0)
	{
		entry = this.Entries[entryIndex];
	}
	else
	{
		entry = new LRMEntry();
		entry.Context = context;
		entry.Culture = culture;
		entry.Key = key;
		this.Entries[this.Entries.length] = entry;
	}
	entry.Value = value;

	return value;
}

Radactive_LRM.prototype.GetIndex = function(context, culture, key)
{
	for(var i=0;i<this.Entries.length;i++)
	{
		var entry = this.Entries[i];
		if (entry.Context == context)
		{
			if (entry.Culture == culture)
			{
				if (entry.Key == key)
				{
					return i;
				}
			}			
		}
	}
	return -1;
}

_Radactive.prototype.WebControls = new Radactive_WebControls();
_Radactive.prototype.LRM = new Radactive_LRM();

var Radactive = new _Radactive();

function Radactive_WebControls_ILoad()
{
}

Radactive_WebControls_ILoad.prototype.PageBaseUrl = "/";

Radactive_WebControls_ILoad.prototype.GetControl = function(controlId)
{
	if (!controlId)
	{
		return null;
	}
		
	for(var i=0;i<ILoadControls.length;i++)
	{
		var control = ILoadControls[i];
		if (control)
		{
			if (control.ControlId == controlId)
			{
				return control;
			}
		}
	}
	
	return null;
}

Radactive_WebControls_ILoad.prototype.GetControl2 = function(controlId)
{
	return document.getElementById(controlId);
}

Radactive_WebControls_ILoad.prototype.CreateControl = function(controlId, uniqueId)
{
	var control = new ILoadControl(controlId, uniqueId);

	var oldIndex = -1;
	for(var i=0;i<ILoadControls.length;i++)
	{
		var oldControl = ILoadControls[i];
		if (oldControl.ControlId == controlId)
		{
			oldIndex = i;
			break;
		}
	}

	if (oldIndex >= 0)
	{
		ILoadControls[oldIndex] = control;
	}
	else
	{
		if (ILoadControls.push)
		{
			ILoadControls.push(control);
		}
		else
		{
			ILoadControls[ILoadControls.length] = control;
		}
	}
	
	// Setup the hidden values
	var valueSpaceId = controlId + "__Value";
	var valueSpaceName = uniqueId + "__Value";

	var formSpace = null;

	var hiddenValueContainerSpaceId = controlId + "_hvc";
	var hiddenValueContainerSpace = document.getElementById(hiddenValueContainerSpaceId);

	if (!hiddenValueContainerSpace)
	{
		if (document.forms.length > 0)
		{
			formSpace = document.forms[0];
		}
	}
	
	var valueSpace = document.getElementById(valueSpaceId);
	if (!valueSpace)
	{
		valueSpace = document.createElement("input");
		valueSpace.setAttribute("type", "hidden");
		valueSpace.setAttribute("id", valueSpaceId);
		valueSpace.setAttribute("name", valueSpaceName);
		valueSpace.setAttribute("value", "");
		if (hiddenValueContainerSpace)
		{
			hiddenValueContainerSpace.appendChild(valueSpace);
		}
		else
		{
			if (formSpace)
			{
				formSpace.appendChild(valueSpace);
			}
		}
	}
	
	var oldValueSpaceId = controlId + "__OldValue";
	var oldValueSpaceName = uniqueId + "__OldValue";

	var oldValueSpace = document.getElementById(oldValueSpaceId);
	if (!oldValueSpace)
	{
		oldValueSpace = document.createElement("input");
		oldValueSpace.setAttribute("type", "hidden");
		oldValueSpace.setAttribute("id", oldValueSpaceId);
		oldValueSpace.setAttribute("name", oldValueSpaceName);
		oldValueSpace.setAttribute("value", "");
		if (hiddenValueContainerSpace)
		{
			hiddenValueContainerSpace.appendChild(oldValueSpace);
		}
		else
		{
			if (formSpace)
			{
				formSpace.appendChild(oldValueSpace);
			}
		}
	}

	return control;
}

Radactive_WebControls_ILoad.prototype.InitializeControl = function(controlId, 
	contrlKey,
	controlTitle,
	imageUploadWizardWindowTitle,
	previewWindowTitle,
	addImageButtonText,
	editImageButtonText,
	appearance,
	definitionTitles,
	resizeDefinitionTitles,
	valueChangedEventHandler,
	windowMode,
	customWindowProvider_Open,
	customWindowProvider_Close,
	customWindowProvider_UseGetOpener,
	culture,
	lrmKeys,
	lrmValues,
	allowEditImage,
	allowPreviewWindow,
	iconCustomResize,
	value,
	postBackEventHandler,
	autoPostBack,
	automaticallyClearTemporaryFiles,
	automaticallyDeleteRemovedFiles,
	controlInitializedEventHandler,
	lightbox_CssClass
	)
{
	this.SetControlKey(controlId, contrlKey);
	this.SetControlTitle(controlId, controlTitle);
	this.SetImageUploadWizardWindowTitle(controlId, imageUploadWizardWindowTitle);
	this.SetPreviewWindowTitle(controlId, previewWindowTitle);
	this.SetAddImageButtonText(controlId, addImageButtonText);
	this.SetEditImageButtonText(controlId, editImageButtonText);
	this.SetAppearance(controlId, appearance);
	this.SetDefinitionTitles(controlId, definitionTitles);
	this.SetResizeDefinitionTitles(controlId, resizeDefinitionTitles);
	this.SetValueChangedEventHandler(controlId, valueChangedEventHandler);
	this.SetWindowMode(controlId, windowMode);
	this.SetCustomWindowProvider_Open(controlId, customWindowProvider_Open);
	this.SetCustomWindowProvider_Close(controlId, customWindowProvider_Close);
	this.SetCustomWindowProvider_UseGetOpener(controlId, customWindowProvider_UseGetOpener);
	this.SetCulture(controlId, culture);

	for(var i=0;i<lrmKeys.length;i++)
	{
		this.SetLRMText(controlId, lrmKeys[i], lrmValues[i]);
	}
	
	this.SetAllowEditImage(controlId, allowEditImage);
	this.SetAllowPreviewWindow(controlId, allowPreviewWindow);
	this.SetIconCustomResize(controlId, iconCustomResize);
	this.SetValue(controlId, value, false, false, true);
	this.SetPostBackEventHandler(controlId, postBackEventHandler);
	this.SetAutoPostBack(controlId, autoPostBack);
	this.SetAutomaticallyClearTemporaryFiles(controlId, automaticallyClearTemporaryFiles);
	this.SetAutomaticallyDeleteRemovedFiles(controlId, automaticallyDeleteRemovedFiles);
	this.SetLightbox_CssClass(controlId, lightbox_CssClass);
	
	this.OnControlInitialized(controlId, controlInitializedEventHandler);
}

Radactive_WebControls_ILoad.prototype.GetAddImagePopupUrl = function(controlId, edit)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return;
	}
	var editParam = "0";
	if (edit)
	{
		editParam = "1";
	}

	var controlKey = control.ControlKey;
	var url = this.PageBaseUrl + "WebCoreModule.ashx?__ac=1&__ac_wcmid=RAWCIL&__ac_lib=Radactive.WebControls.ILoad&__ac_key=RAWCCIL_201&__ac_sid=s4rfctrneoukwdrduxhxqdaw&__ac_ssid=&__ac_ssid2=1&__controlKey=" + URLEncode(controlKey) + "&___controlId=" + URLEncode(controlId) + "&___edit=" + URLEncode(editParam) + "&fr=" + URLEncode(Date()) + "&pageUrl=" + URLEncode(document.location.href)
	url += "&__ac_cn=" + URLEncode(control.Culture);

	return url;
}

Radactive_WebControls_ILoad.prototype.Last_AddImage_Id = null;
Radactive_WebControls_ILoad.prototype.Last_AddImage_Edit = false;
Radactive_WebControls_ILoad.prototype.Last_AddImage_Config = null;
Radactive_WebControls_ILoad.prototype.AddImage = function(controlId, edit)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		alert("I-Load Error:\r\nUnable to find RADactive I-Load control ClientID: '" + controlId + "'. Please ensure the control is placed inside a form element <form runat=\"server\">...</form>.");
		return;
	}
	var windowLabel = "RAWCIL_WL_IMAGEUPLOAD";
	if (edit)
	{
		var webImage = this.GetValue(controlId);
		windowLabel = "RAWCIL_WL_IMAGEEDIT";
		if (!webImage)
		{
			alert(this.GetLRMText(controlId, "ILoad_Error_NoImageToEdit", "Error: No image to edit."));
			return;
		}
		if (!webImage.SourceImage())
		{
			alert(this.GetLRMText(controlId, "ILoad_Error_SourceImageNotFound", "I-Load configuration error:\r\nSource image not found. Please enable [KeepSourceImage]."));
			return;
		}
	}	
	
	this.Last_AddImage_Id = controlId;
	this.Last_AddImage_Edit = edit;

	var url = this.GetAddImagePopupUrl(controlId, edit);

	var result = this.WindowOpen(controlId, windowLabel, url, 600, 430, true, true, false, this.GetImageUploadWizardWindowTitle(controlId), false);
	if (result)
	{
		if (typeof result.result == "object")
		{
			if (result.result.myType == "ILoadResult")
			{
				result.result.controlId = controlId;
				this.AddImage_Return(result.result);
			}
		}
		return result.result;
	}
	else
	{
		return null;
	}
}

Radactive_WebControls_ILoad.prototype.AddImageAutoEdit = function(controlId)
{
	var webImage = this.GetValue(controlId);
	if (webImage)
	{
		var allowEdit = this.GetAllowEditImage(controlId);
		this.AddImage(controlId, allowEdit);
	}
	else
	{
		this.AddImage(controlId, false);
	}
}

Radactive_WebControls_ILoad.prototype.AddImage_Return = function(iload_result)
{
	if (!iload_result)
	{
		return;
	}
	if (this.GetAutomaticallyClearTemporaryFiles(iload_result.controlId))
	{
		this.ClearTemporaryFiles(iload_result.subSessionId, !iload_result.completed);
	}
	if (iload_result.completed)
	{
		if (this.Last_AddImage_Edit)
		{
			var oldValue = this.GetValue(iload_result.controlId);
			if (oldValue)
			{
				if (oldValue.IsTemporary())
				{
					if (this.GetAutomaticallyClearTemporaryFiles(iload_result.controlId))
					{
						this.ClearTemporaryFiles(oldValue.Id, true);
					}
				}
				else
				{
					if (this.GetAutomaticallyDeleteRemovedFiles(iload_result.controlId))
					{
						this.DeleteWebImageFiles(oldValue.Storage, oldValue.ConfigurationInternalCode, oldValue.Id, oldValue.K2, oldValue.PE);
					}
				}
			}
		}
		
		this.SetValue(iload_result.controlId, iload_result.index, true, true, false);
	}
}

Radactive_WebControls_ILoad.prototype.ClearTemporaryFiles = function(ssid, clearAll)
{
	var url = "WebCoreModule.ashx?__ac=1&__ac_wcmid=RAWCIL&__ac_lib=Radactive.WebControls.ILoad&__ac_key=RAWCCIL_2011&__ac_sid=s4rfctrneoukwdrduxhxqdaw&__ac_cn=&__ac_ssid=&fr=" + URLEncode(Date());
	url += "&ssidToClear=" + URLEncode(ssid);
	if (clearAll)
	{
		url += "&removeTemporaryFiles=1";
	}
	createXMLDOMFromRequest(url, false);
}

Radactive_WebControls_ILoad.prototype.DeleteWebImageFiles = function(storage, configurationInternalCode, id, k2, pe)
{
	var url = "WebCoreModule.ashx?__ac=1&__ac_wcmid=RAWCIL&__ac_lib=Radactive.WebControls.ILoad&__ac_key=RAWCCIL_2012&__ac_sid=s4rfctrneoukwdrduxhxqdaw&__ac_cn=&__ac_ssid=&fr=" + URLEncode(Date());
	url += "&storage=" + URLEncode(storage);
	url += "&configIC=" + URLEncode(configurationInternalCode);
	url += "&id=" + URLEncode(id);
	url += "&k2=" + URLEncode(k2);
	url += "&pe=" + URLEncode(pe);
	
	createXMLDOMFromRequest(url, false);
}

Radactive_WebControls_ILoad.prototype.RemoveImage = function(controlId)
{
	if (window.confirm(this.GetLRMText(controlId, "ILoad_Alert_ConfirmRemoveImage", "Are you sure you want to remove this image ?")))
	{
		this.SetValue(controlId, null, true, true, false);
	}
}	

Radactive_WebControls_ILoad.prototype.GetValue = function(controlId)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return null;
	}
	return control.WebImage;
}



Radactive_WebControls_ILoad.prototype.SetValue = function(controlId, newWebImage, raiseValueChangedEventHandler, raiseValidation, setOldValue)
{
	var webImage = null;
	var useIndex = false;
	
	if (typeof raiseValidation == "undefined")
	{
		raiseValidation = true;
	}
	
	if (newWebImage)
	{
		if (typeof newWebImage == "string")
		{
			if (newWebImage != "")
			{
				webImage = new WebImage(newWebImage);
				if (webImage.ImageDefinitionInternalCode == "")
				{
					// Safari bug
					for(var i=0;i<10;i++)
					{
						webImage = new WebImage(newWebImage);
						if (webImage.ImageDefinitionInternalCode != "")
						{
							break;
						}
					}
				}
			}
			else
			{
				webImage = null;
			}
			useIndex = true;
		}
		else
		{
			webImage = newWebImage;
		}
	}
	
	var control = this.GetControl(controlId);
	if (!control)
	{
		return;
	}
	var valueSpace = Radactive.WebControls.GetFormElement(controlId + "__Value");
	if (!valueSpace)
	{
		return;
	}
	
	var oldValueSpace = Radactive.WebControls.GetFormElement(controlId + "__OldValue");	
	
	var oldValue = control.WebImage;
	if (oldValue)
	{
		if (!oldValue.IsSameImage(webImage))
		{
			if (oldValue.IsTemporary())
			{
				if (this.GetAutomaticallyClearTemporaryFiles(controlId))
				{
					this.ClearTemporaryFiles(oldValue.Id, true);
				}
			}
			else
			{
				if (this.GetAutomaticallyDeleteRemovedFiles(controlId))
				{
					this.DeleteWebImageFiles(oldValue.Storage, oldValue.ConfigurationInternalCode, oldValue.Id, oldValue.K2, oldValue.PE);
				}
			}
		}
	}
	control.WebImage = webImage;
	
	if (webImage)
	{
		if (useIndex)
		{
			valueSpace.value = URLEncode(newWebImage);
		}
		else
		{
			valueSpace.value = URLEncode(webImage.GetIndex());
		}
	}
	else
	{
		valueSpace.value = "";
	}
	
	if (setOldValue)
	{
		if (oldValueSpace)
		{
			oldValueSpace.value = valueSpace.value;
		}
	}
	
	if (raiseValueChangedEventHandler)
	{
		if (control.ValueChangedEventHandler)
		{
			if (control.ValueChangedEventHandler.prototype)
			{
				control.ValueChangedEventHandler(controlId, webImage);
			}
			else
			{
				var ex;
				try
				{
					var f = eval(control.ValueChangedEventHandler);
					if (f)
					{
						if (f.prototype)
						{
							f(controlId, webImage);
						}
						else
						{
							alert("I-Load error: 1 - Invalid ValueChangedEventHandler function '" + control.ValueChangedEventHandler + "'.");
						}
					}
					else
					{
						alert("I-Load error: 2 - Invalid ValueChangedEventHandler function '" + control.ValueChangedEventHandler + "'.");
					}
				}
				catch(ex)
				{
					var desc = ex.description;
					if (ex.message)
					{
						desc = ex.message;
					}
					alert("I-Load error: 3 - Invalid ValueChangedEventHandler function '" + control.ValueChangedEventHandler + "'.\r\n" + desc);
				}
			}
		}
	}
	
	var control2 = this.GetControl2(controlId);
	if (control2)
	{
		if (control2.onValueChange)
		{
			if (control2.onValueChange.prototype)
			{
				control2.onValueChange();
			}
			else
			{
				eval(control2.onValueChange);
			}
		}
	}
	
	if (this.GetAutoPostBack(controlId))
	{
		window.setTimeout("Radactive.WebControls.ILoad.RaiseBackEventHandler('" + controlId + "');",500);
		return;
	}
	
	var appearance = this.GetAppearance(controlId);
	switch(appearance)
	{
		case 1:
			// Default:
			var iconPreviewSpace = document.getElementById(controlId + "__IconPreview");
			var imageDetailSpace = document.getElementById(controlId + "__ImageDetails");
			var imageDetailEmptySpace = document.getElementById(controlId + "__ImageDetailsEmpty");
			var removeImageSpace = document.getElementById(controlId + "__RemoveImage");
			var editImageSpace = document.getElementById(controlId + "__EditImage")
			var addImageSpace = document.getElementById(controlId + "__AddImage");
			
			if (webImage)
			{
				var iconResize = null;
				var iconCustomResize = this.GetIconCustomResize(controlId);
				if (iconCustomResize != "")
				{
					iconResize = webImage.GetResizeByName(iconCustomResize);
				}
				if (!iconResize)
				{
					iconResize = webImage.IconImage();
				}
				if (iconResize)
				{
					if (iconPreviewSpace)
					{
						clearElement(iconPreviewSpace);
					
						var parentEl;
						if (this.GetAllowPreviewWindow(controlId))
						{
							var oA1 = document.createElement("a");
							oA1.setAttribute("href", "javascript:void(0);");
							oA1.onclick = function()
							{
								Radactive.WebControls.ILoad.ShowImagePreview(controlId);
								return false;
							};
							iconPreviewSpace.appendChild(oA1);
							parentEl = oA1;
						}
						else
						{
							parentEl = iconPreviewSpace;
						}
						
						var oImg1 = document.createElement("img");
						oImg1.setAttribute("src", iconResize.FileUrl_NoCache());
						oImg1.setAttribute("alt", "");
						if (this.GetAllowPreviewWindow(controlId))
						{
							oImg1.setAttribute("title", this.GetLRMText(controlId, "ILoad_Text_ShowImagePreview", "Show image preview"));
						}
						var w = parseInt(iconResize.Size.Width);
						var h = parseInt(iconResize.Size.Height);
						oImg1.style.width = "" + w + "px";
						oImg1.style.height = "" + h + "px";
						oImg1.style.borderStyle = "solid";
						oImg1.style.borderWidth = "1px";
						oImg1.style.borderColor = "#CCCCCC";
						oImg1.style.padding = "0px";
						oImg1.style.margin = "0px";
						oImg1.style.verticalAlign = "middle";
						parentEl.appendChild(oImg1);
					}
				}
				if (imageDetailSpace)
				{
					clearElement(imageDetailSpace);

					var definitionTitle = this.GetDefinitionTitle(controlId, webImage.ImageDefinitionInternalCode);
					if (definitionTitle == "")
					{
						definitionTitle = "Unknown";
					}

					var str = this.GetLRMText(controlId, "ILoad_Text_Definition", "Definition: ") + definitionTitle;
					htmlAppendText(imageDetailSpace, str);
					htmlAppendBr(imageDetailSpace);

					var selectedResize = webImage.SelectedImage();
					if (selectedResize)
					{
						str = this.GetLRMText(controlId, "ILoad_Text_Size", "Size (px): ") + selectedResize.ImageSizeText  + "\u00a0\u00a0(" + selectedResize.Extension + " - " + selectedResize.FileSizeText + ")\r\n";
						htmlAppendText(imageDetailSpace, str);
						htmlAppendBr(imageDetailSpace);
					}
					imageDetailSpace.style.display = "block";
				}
				if (imageDetailEmptySpace)
				{
					imageDetailEmptySpace.style.display = "none";
				}
				if (editImageSpace)
				{
					editImageSpace.style.display = "block";
					if (addImageSpace)
					{
						addImageSpace.style.display = "none";
					}
				}
				else
				{
					if (addImageSpace)
					{
						addImageSpace.style.display = "block";
					}
				}
				if (removeImageSpace)
				{
					removeImageSpace.style.display = "block";
				}
			}
			else
			{
				if (iconPreviewSpace)
				{
					clearElement(iconPreviewSpace);
				}
				if (imageDetailSpace)
				{
					imageDetailSpace.style.display = "none";
				}
				if (imageDetailEmptySpace)
				{
					imageDetailEmptySpace.style.display = "block";
				}
				if (addImageSpace)
				{
					addImageSpace.style.display = "block";
				}
				if (editImageSpace)
				{
					editImageSpace.style.display = "none";
				}
				if (removeImageSpace)
				{
					removeImageSpace.style.display = "none";
				}
			}
			break;
		case 2:
			// Button
			var buttonSpace = document.getElementById(controlId);
			
			var buttonText = this.GetAddImageButtonText(controlId);
			if (webImage)
			{
				var allowEditImage = this.GetAllowEditImage(controlId);
				if (allowEditImage)
				{
					buttonText = this.GetEditImageButtonText(controlId);
				}
			}
			
			if (buttonSpace)
			{
				buttonSpace.value = buttonText;
			}

			break;
		case 3:
			// Hidden
			break;
	}
			
	if (raiseValidation)
	{		
		this.UpdateValidators(controlId);
	}	
}

Radactive_WebControls_ILoad.prototype.SetAutoPostBack = function(controlId, value)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return;
	}
	if (value)
	{
		control.AutoPostBack = true;
	}
	else
	{
		control.AutoPostBack = false;
	}
}

Radactive_WebControls_ILoad.prototype.GetAutoPostBack = function(controlId)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return false;
	}
	if (control.AutoPostBack == true)
	{
		return true;
	}
	if (control.AutoPostBack == false)
	{
		return false;
	}
	return false;
}

Radactive_WebControls_ILoad.prototype.SetAutomaticallyClearTemporaryFiles = function(controlId, value)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return;
	}
	if (value)
	{
		control.AutomaticallyClearTemporaryFiles = true;
	}
	else
	{
		control.AutomaticallyClearTemporaryFiles = false;
	}
}

Radactive_WebControls_ILoad.prototype.GetAutomaticallyClearTemporaryFiles = function(controlId)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return false;
	}
	if (control.AutomaticallyClearTemporaryFiles == true)
	{
		return true;
	}
	if (control.AutomaticallyClearTemporaryFiles == false)
	{
		return false;
	}
	return false;
}

Radactive_WebControls_ILoad.prototype.SetAutomaticallyDeleteRemovedFiles = function(controlId, value)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return;
	}
	if (value)
	{
		control.AutomaticallyDeleteRemovedFiles = true;
	}
	else
	{
		control.AutomaticallyDeleteRemovedFiles = false;
	}
}

Radactive_WebControls_ILoad.prototype.GetAutomaticallyDeleteRemovedFiles = function(controlId)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return false;
	}
	if (control.AutomaticallyDeleteRemovedFiles == true)
	{
		return true;
	}
	if (control.AutomaticallyDeleteRemovedFiles == false)
	{
		return false;
	}
	return false;
}

Radactive_WebControls_ILoad.prototype.SetAllowEditImage = function(controlId, value)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return;
	}
	if (value)
	{
		control.AllowEditImage = true;
	}
	else
	{
		control.AllowEditImage = false;
	}
}

Radactive_WebControls_ILoad.prototype.GetAllowEditImage = function(controlId)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return false;
	}
	if (control.AllowEditImage == true)
	{
		return true;
	}
	if (control.AllowEditImage == false)
	{
		return false;
	}
	return false;
}

Radactive_WebControls_ILoad.prototype.SetAllowPreviewWindow = function(controlId, value)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return;
	}
	if (value)
	{
		control.AllowPreviewWindow = true;
	}
	else
	{
		control.AllowPreviewWindow = false;
	}
}

Radactive_WebControls_ILoad.prototype.GetAllowPreviewWindow = function(controlId)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return false;
	}
	if (control.AllowPreviewWindow == true)
	{
		return true;
	}
	if (control.AllowPreviewWindow == false)
	{
		return false;
	}
	return false;
}

Radactive_WebControls_ILoad.prototype.SetIconCustomResize = function(controlId, value)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return;
	}
	control.IconCustomResize = value;
}

Radactive_WebControls_ILoad.prototype.GetIconCustomResize = function(controlId)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return "";
	}
	if (control.IconCustomResize)
	{
		return control.IconCustomResize;
	}
	else
	{
		return "";
	}
}

Radactive_WebControls_ILoad.prototype.SetPostBackEventHandler = function(controlId, value)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return;
	}
	control.AutoPostBackEventHandler = value;
}

Radactive_WebControls_ILoad.prototype.SetLightbox_CssClass = function(controlId, value)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return;
	}
	control.Lightbox_CssClass = value;
}

Radactive_WebControls_ILoad.prototype.GetLightbox_CssClass = function(controlId)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return "";
	}
	return control.Lightbox_CssClass;
}

Radactive_WebControls_ILoad.prototype.RaiseBackEventHandler = function(controlId)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return;
	}
	if (control.AutoPostBackEventHandler)
	{
		if (typeof(window.__doPostBack) == "undefined")
		{
			if (document.forms.length <= 0)
			{
				alert("I-Load postback error. Unable to find the <form> element. Please ensure that the aspx markup contains the tag: <form runat=\"server\">...</form>.");
				return;
			}

			window.__doPostBack = function(eventTarget, eventArgument) 
			{				
				var theForm = document.forms[0];

				if (!theForm.onsubmit || (theForm.onsubmit() != false)) 
				{
					theForm.__EVENTTARGET.value = eventTarget;
					theForm.__EVENTARGUMENT.value = eventArgument;
					theForm.submit();
				}
		    }
		}
		
		if (control.AutoPostBackEventHandler.prototype)
		{
			control.AutoPostBackEventHandler();
		}
		else
		{
			eval(control.AutoPostBackEventHandler);
		}
	}
}

Radactive_WebControls_ILoad.prototype.SetValueChangedEventHandler = function(controlId, valueChangedEventHandler)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return;
	}
	control.ValueChangedEventHandler = valueChangedEventHandler;
}

Radactive_WebControls_ILoad.prototype.OnControlInitialized = function(controlId, controlInitializedEventHandler)
{
	var webImage = this.GetValue(controlId);

	if (controlInitializedEventHandler)
	{
		if (controlInitializedEventHandler.prototype)
		{
			controlInitializedEventHandler(controlId, webImage);
		}
		else
		{
			var ex;
			try
			{
				var f = eval(controlInitializedEventHandler);
				if (f)
				{
					if (f.prototype)
					{
						f(controlId, webImage);
					}
					else
					{
						alert("I-Load error: 1 - Invalid ControlInitializedEventHandler function '" + controlInitializedEventHandler + "'.");
					}
				}
				else
				{
					alert("I-Load error: 2 - Invalid ControlInitializedEventHandler function '" + controlInitializedEventHandler + "'.");
				}
			}
			catch(ex)
			{
				var desc = ex.description;
				if (ex.message)
				{
					desc = ex.message;
				}
				alert("I-Load error: 3 - Invalid ControlInitializedEventHandler function '" + controlInitializedEventHandler + "'.\r\n" + desc);
			}
		}
	}
}

Radactive_WebControls_ILoad.prototype.SetWindowMode = function(controlId, value)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return;
	}
	control.WindowMode = value;
}

Radactive_WebControls_ILoad.prototype.GetWindowMode = function(controlId)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return 1;
	}
	return control.WindowMode;
}

Radactive_WebControls_ILoad.prototype.GetCustomWindowProvider_Open = function(controlId)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return "I-Load";
	}
	return control.CustomWindowProvider_Open;
}

Radactive_WebControls_ILoad.prototype.SetCustomWindowProvider_Open = function(controlId, customWindowProvider_Open)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return;
	}
	control.CustomWindowProvider_Open = customWindowProvider_Open;
}

Radactive_WebControls_ILoad.prototype.GetCustomWindowProvider_Close = function(controlId)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return "I-Load";
	}
	return control.CustomWindowProvider_Close;
}

Radactive_WebControls_ILoad.prototype.SetCustomWindowProvider_Close = function(controlId, customWindowProvider_Close)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return;
	}
	control.CustomWindowProvider_Close = customWindowProvider_Close;
}

Radactive_WebControls_ILoad.prototype.GetCustomWindowProvider_UseGetOpener = function(controlId)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return false;
	}
	return control.CustomWindowProvider_UseGetOpener;
}

Radactive_WebControls_ILoad.prototype.SetCustomWindowProvider_UseGetOpener = function(controlId, customWindowProvider_UseGetOpener)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return;
	}
	control.CustomWindowProvider_UseGetOpener = customWindowProvider_UseGetOpener;
}

Radactive_WebControls_ILoad.prototype.SetCulture = function(controlId, culture)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return;
	}
	control.Culture = culture;
}

Radactive_WebControls_ILoad.prototype.GetCulture = function(controlId, culture)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return "";
	}
	return control.Culture;
}

Radactive_WebControls_ILoad.prototype.GetLRMContext = function(controlId)
{
	return "ILoad1|" + controlId;
}

Radactive_WebControls_ILoad.prototype.SetLRMText = function(controlId, key, value)
{
	var context = this.GetLRMContext(controlId);
	var culture = this.GetCulture(controlId);
	Radactive.LRM.SetString(context, culture, key, value);
	return value;
}

Radactive_WebControls_ILoad.prototype.GetLRMText = function(controlId, key, defaultValue)
{
	var context = this.GetLRMContext(controlId);
	var culture = this.GetCulture(controlId);
	return Radactive.LRM.GetString(context, culture, key, defaultValue);
}

Radactive_WebControls_ILoad.prototype.SetControlTitle = function(controlId, controlTitle)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return;
	}
	control.ControlTitle = controlTitle;
}

Radactive_WebControls_ILoad.prototype.GetControlTitle = function(controlId)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return "I-Load";
	}
	return control.ControlTitle;
}

Radactive_WebControls_ILoad.prototype.SetPreviewWindowTitle = function(controlId, previewWindowTitle)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return;
	}
	control.PreviewWindowTitle = previewWindowTitle;
}

Radactive_WebControls_ILoad.prototype.GetPreviewWindowTitle = function(controlId)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return "RADactive I-Load - Preview";
	}
	return control.PreviewWindowTitle;
}

Radactive_WebControls_ILoad.prototype.SetImageUploadWizardWindowTitle = function(controlId, imageUploadWizardWindowTitle)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return;
	}
	control.ImageUploadWizardWindowTitle = imageUploadWizardWindowTitle;
}

Radactive_WebControls_ILoad.prototype.GetImageUploadWizardWindowTitle = function(controlId)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return "RADactive I-Load";
	}
	return control.ImageUploadWizardWindowTitle;
}

Radactive_WebControls_ILoad.prototype.SetAddImageButtonText = function(controlId, buttonText)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return;
	}
	control.AddImageButtonText = buttonText;
}

Radactive_WebControls_ILoad.prototype.GetAddImageButtonText = function(controlId)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return "Browse...";
	}
	return control.AddImageButtonText;
}

Radactive_WebControls_ILoad.prototype.SetEditImageButtonText = function(controlId, buttonText)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return;
	}
	control.EditImageButtonText = buttonText;
}

Radactive_WebControls_ILoad.prototype.GetEditImageButtonText = function(controlId)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return "Edit...";
	}
	return control.EditImageButtonText;
}

Radactive_WebControls_ILoad.prototype.SetAppearance = function(controlId, value)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return;
	}
	control.Appearance = value;
}

Radactive_WebControls_ILoad.prototype.GetAppearance = function(controlId)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return 1;
	}
	return control.Appearance;
}

Radactive_WebControls_ILoad.prototype.SetWindowMode = function(controlId, value)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return;
	}
	control.WindowMode = value;
}

Radactive_WebControls_ILoad.prototype.GetWindowMode = function(controlId)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return 1;
	}
	return control.WindowMode;
}

Radactive_WebControls_ILoad.prototype.SetDefinitionTitles = function(controlId, definitions)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return;
	}
	var vett = definitions.split("\r");
	control.Definition_InternalCodes = vett[0].split("\n");
	control.Definition_Titles = vett[1].split("\n");
}

Radactive_WebControls_ILoad.prototype.GetDefinitionTitle = function(controlId, internalCode)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return "";
	}
	for(var i=0;i<control.Definition_InternalCodes.length;i++)
	{
		if (control.Definition_InternalCodes[i] == internalCode)
		{
			return control.Definition_Titles[i];
		}
	}
	return "";
}

Radactive_WebControls_ILoad.prototype.SetResizeDefinitionTitles = function(controlId, resizes)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return;
	}
	var vett = resizes.split("\r");
	control.ResizeDefinition_InternalCodes = vett[0].split("\n");
	control.ResizeDefinition_Titles = vett[1].split("\n");
}

Radactive_WebControls_ILoad.prototype.GetResizeDefinitionTitles = function(controlId, internalCode)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return "";
	}
	var webImage = this.GetValue(controlId);
	if (webImage)
	{
		internalCode = webImage.ImageDefinitionInternalCode + "|" + internalCode;
	}
	for(var i=0;i<control.ResizeDefinition_InternalCodes.length;i++)
	{
		if (control.ResizeDefinition_InternalCodes[i] == internalCode)
		{
			return control.ResizeDefinition_Titles[i];
		}
	}
	return "";
}

Radactive_WebControls_ILoad.prototype.GetControlKey = function(controlId)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return "";
	}
	return control.ControlKey;
}

Radactive_WebControls_ILoad.prototype.SetControlKey = function(controlId, controlKey)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return "";
	}
	control.ControlKey = controlKey;
}

Radactive_WebControls_ILoad.prototype.GetShowImagePreviewPopupUrl = function(controlId)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return "";
	}
	
	var controlKey = control.ControlKey;	
	var url = this.PageBaseUrl + "WebCoreModule.ashx?__ac=1&__ac_wcmid=RAWCIL&__ac_lib=Radactive.WebControls.ILoad&__ac_key=RAWCCIL_301&__ac_sid=s4rfctrneoukwdrduxhxqdaw&__controlKey=" + URLEncode(controlKey) +  "&fr=" + URLEncode(Date()) + "&___controlId=" + URLEncode(controlId);
	url += "&__ac_cn=" + URLEncode(control.Culture);

	return url;
}

Radactive_WebControls_ILoad.prototype.Last_ShowImagePreview_ControlId = ""; 
Radactive_WebControls_ILoad.prototype.ShowImagePreview = function(controlId)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return "";
	}
	this.Last_ShowImagePreview_ControlId = controlId;
	
	var url = this.GetShowImagePreviewPopupUrl(controlId);

	var result = this.WindowOpen(controlId, "RAWCIL_WL_IMAGEPREVIEW", url, 450, 470, true, true, true, this.GetPreviewWindowTitle(controlId), true);
}

Radactive_WebControls_ILoad.prototype.Validate = function(validatorControl)
{
	var controlId = validatorControl.controltovalidate;
	var control = Radactive.WebControls.ILoad.GetControl(controlId);
	var webImage = Radactive.WebControls.ILoad.GetValue(controlId);
	if (webImage)
	{
		return true;
	}
	else
	{
		return false;
	}
}

Radactive_WebControls_ILoad.prototype.RegisterValidator = function(controlId, controlToValidateId)
{
	var validator = document.all ? document.all[controlId] : document.getElementById(controlId);
	if (validator)
	{
		if (!window.Page_Validators) 
		{
			window.Page_Validators = new Array();
		}
		if (window.Page_Validators)
		{
			if (!this.GetValidator(controlId)) 
			{
				window.Page_Validators[window.Page_Validators.length] = validator;
			}
		}

		validator.controltovalidate = controlToValidateId;
		validator.evaluationfunction = "Radactive.WebControls.ILoad.Validate";
		validator.dispose = function() {Radactive.WebControls.ILoad.UnregisterValidator(controlId);};
	}
}

Radactive_WebControls_ILoad.prototype.UnregisterValidator = function(controlId)
{
	if (window.Page_Validators)
	{
		var validator = this.GetValidator(controlId);
		if (validator) 
		{
			if (Array.remove)
			{
				Array.remove(window.Page_Validators, validator);
			}
		}
	}
}

Radactive_WebControls_ILoad.prototype.GetValidatorForControl = function(controlId)
{
	if (!controlId)
	{
		return null;
	}
	
	if (window.Page_Validators)
	{
		for(var i=0;i<window.Page_Validators.length;i++)
		{
			var validator = window.Page_Validators[i];
			if (validator)
			{
				if (validator.controltovalidate == controlId)
				{
					return validator;
				}
			}
		}
	}
	
	return null;
}

Radactive_WebControls_ILoad.prototype.GetValidator = function(controlId)
{
	if (!controlId)
	{
		return null;
	}
	
	if (window.Page_Validators)
	{
		for(var i=0;i<window.Page_Validators.length;i++)
		{
			var validator = window.Page_Validators[i];
			if (validator)
			{
				if (validator.id == controlId)
				{
					return validator;
				}
			}
		}
	}
	
	return null;
}

Radactive_WebControls_ILoad.prototype.ValidatorUpdateDisplay = function(val) 
{
	if (!val)
	{
		return;
	}
    if (typeof(val.display) == "string") {
        if (val.display == "None") {
            return;
        }
        if (val.display == "Dynamic") {
            val.style.display = val.isvalid ? "none" : "inline";
            return;
        }
    }
    if ((navigator.userAgent.indexOf("Mac") > -1) &&
        (navigator.userAgent.indexOf("MSIE") > -1)) {
        val.style.display = "inline";
    }
    val.style.visibility = val.isvalid ? "hidden" : "visible";
}

Radactive_WebControls_ILoad.prototype.UpdateValidators = function(controlId)
{
	if (window.Page_Validators)
	{
		for(var i=0;i<window.Page_Validators.length;i++)
		{
			var validator = window.Page_Validators[i];
			if (validator)
			{
				if ((validator.evaluationfunction == Radactive.WebControls.ILoad.Validate) || (validator.evaluationfunction == "Radactive.WebControls.ILoad.Validate"))
				{
					if (validator.controltovalidate == controlId)
					{
						if (window.ValidatorValidate)
						{
							window.ValidatorValidate(validator);
						}
						else
						{
							validator.isvalid = Radactive.WebControls.ILoad.Validate(validator);
							if (window.ValidatorUpdateDisplay)
							{
								window.ValidatorUpdateDisplay(validator);
							}
							else
							{
								this.ValidatorUpdateDisplay(validator);
							}
						}
					}
				}
			}
		}
	}
}

Radactive_WebControls_ILoad.prototype.GetUseCustomWindowMode = function(controlId)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return null;
	}
	if (control.WindowMode == 11)
	{
		return true;
	}
	if (control.WindowMode == 1)
	{
		if (control.CustomWindowProvider_Open)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	return false;
}

Radactive_WebControls_ILoad.prototype.WindowOpen = function(controlId, windowLabel, url, width, height, modal, center, resizable, title, useShowDialg2)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return null;
	}

	var d = new Date();
	var r = 10000 + (Math.floor(Math.random()*9999));
	var windowId = "WID_RAWCIL_" + d.getTime() + "_" + r;
	
	var url2 = url;
	url2 += "&___cwp=1";
	url2 += "&___cwpwid=" + URLEncode(windowId);	
	if (control.CustomWindowProvider_UseGetOpener)
	{
		url2 += "&___cwpugo=1";
	}
	if (useShowDialg2)
	{
		url2 = "WebCoreModule.ashx?__ac=1&__ac_wcmid=RAWCIL&__ac_lib=Radactive.WebControls.ILoad&__ac_key=RAWVCO_101&__ac_sid=s4rfctrneoukwdrduxhxqdaw&__ac_cn=&__ac_ssid=&fr=" + URLEncode(Date()) + "&url=" + URLEncode(url2) + "&title=" + URLEncode(title);
	}
	
	var height2 = height;
	if ((windowLabel == "RAWCIL_WL_IMAGEUPLOAD") || (windowLabel == "RAWCIL_WL_IMAGEEDIT"))
	{
		if (false)
		{
			height2 += 18;
		}
	}
		
	var result = new ILoadWindowOpenResult();
	var done = false;
	
	var useCustomWindowMode = this.GetUseCustomWindowMode(controlId);
	if (useCustomWindowMode)
	{
		if (control.CustomWindowProvider_Open.prototype)
		{
			result.useCustomProvider = true;
			result.result = control.CustomWindowProvider_Open(controlId, windowLabel, windowId, url2, width, height2, modal, center, resizable, title);
			done = true;
		}
		else
		{
			var ex;
			try
			{
				var f = eval(control.CustomWindowProvider_Open);
				if (f)
				{
					if (f.prototype)
					{
						result.useCustomProvider = true;
						result.result = f(controlId, windowLabel, windowId, url2, width, height2, modal, center, resizable, title);
						done = true;
					}
					else
					{
						alert("I-Load error: 1 - Invalid CustomWindowProvider_Open function '" + control.CustomWindowProvider_Open + "'.");
						return null;
					}
				}
				else
				{
					alert("I-Load error: 2 - Invalid CustomWindowProvider_Open function '" + control.CustomWindowProvider_Open + "'.");
					return null;
				}
			}
			catch(ex)
			{
				var desc = ex.description;
				if (ex.message)
				{
					desc = ex.message;
				}
				alert("I-Load error: 3 - Invalid CustomWindowProvider_Open function '" + control.CustomWindowProvider_Open + "'.\r\n" + desc);
				return null;
			}			
		}
	}
	
	if (!done)
	{
		if (control.WindowMode == 31)
		{
			// LightBox
			done = true;
			Radactive.WebControls.ILoad.ShowLightBox(controlId, windowLabel, windowId, url2, width, height2, modal, center, resizable, title);
		}
	}

	if (!done)
	{
		// DefaultPopup
		done = true;

		if (useShowDialg2)
		{
			result.result = Radactive.WebControls.ShowDialog2(url, title, width, height2, modal, center, resizable);
		}
		else
		{
			result.result = Radactive.WebControls.ShowDialog(url, width, height2, modal, center, resizable, title);
		}
	}
	
	return result;
}

Radactive_WebControls_ILoad.prototype.WindowClose = function(controlId, windowLabel, windowId, w)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return;
	}
	
	var useCustomWindowMode = this.GetUseCustomWindowMode(controlId);
	if (useCustomWindowMode)
	{
		if (control.CustomWindowProvider_Close)
		{
			if (control.CustomWindowProvider_Close.prototype)
			{
				control.CustomWindowProvider_Close(controlId, windowLabel, windowId, w);
				return;
			}
			else
			{
				var ex;
				try
				{
					var f = eval(control.CustomWindowProvider_Close);
					if (f)
					{
						if (f.prototype)
						{
							f(controlId, windowLabel, windowId, w);
							return;
						}
						else
						{
							alert("I-Load error: 1 - Invalid CustomWindowProvider_Close function '" + control.CustomWindowProvider_Close + "'.");
							return;
						}
					}
					else
					{
						alert("I-Load error: 2 - Invalid CustomWindowProvider_Close function '" + control.CustomWindowProvider_Close + "'.");
						return;
					}
				}
				catch(ex)
				{
					var desc = ex.description;
					if (ex.message)
					{
						desc = ex.message;
					}
					alert("I-Load error: 3 - Invalid CustomWindowProvider_Close function '" + control.CustomWindowProvider_Close + "'.\r\n" + desc);
					return;
				}	
			}
		}
	}

	if (control.WindowMode == 31)
	{
		Radactive.WebControls.ILoad.HideLightBox(controlId, windowLabel, windowId, w);
		return;
	}

	Radactive.WebControls.HideDialog(w);	
}

Radactive_WebControls_ILoad.prototype.LoadWebImageFromUrl = function(providerUrl)
{
	var doc = createXMLDOMFromRequest(providerUrl, false);
	
	var root = doc.documentElement;
	
	if ((root.nodeName == "Null") || (root.nodeName == "null"))
	{
		return null;
	}
	
	if ((root.nodeName == "Error") || (root.nodeName == "error"))
	{
		var message = "";
		var attribute = root.attributes.getNamedItem("Message");
		if (attribute != null)
		{
			message = attribute.value;
		}
		else
		{
			attribute = root.attributes.getNamedItem("message");
			if (attribute != null)
			{
				message = attribute.value;
			}
		}
		if (message != "")
		{
			alert("I-Load WebImage Load Error:\r\n" + message);
		}
		
		return null;
	}
	
	return new WebImage(doc);
}

Radactive_WebControls_ILoad.prototype.LoadWebImageFromReference = function(value)
{
	var url = "WebCoreModule.ashx?__ac=1&__ac_wcmid=RAWCIL&__ac_lib=Radactive.WebControls.ILoad&__ac_key=RAWCCIL_2031&__ac_sid=s4rfctrneoukwdrduxhxqdaw&__ac_cn=&__ac_ssid=&fr=" + URLEncode(Date());
	url += "&wir=" + URLEncode(value)
	
	return this.LoadWebImageFromUrl(url);
}

Radactive_WebControls_ILoad.prototype.IsWebImageReference = function(value)
{
	if ((value == null) || (value == ""))
	{
		return false;
	}
	var referencePrefix = "WEBIMAGE:"; 
	if (value.length > referencePrefix.length)
	{
		if (value.substring(0, referencePrefix.length) == referencePrefix)
		{
			return true;
		}
	}
	return false;
}

Radactive_WebControls_ILoad.prototype.HideLightBox = function(controlId, windowLabel, windowId, w)
{
	var control = Radactive.WebControls.ILoad.GetControl(controlId);

	var onWindowResize = control["__LightBox_Handlers_resize"];
	var onWindowScroll = control["__LightBox_Handlers_scroll"];

	if (onWindowResize)
	{
		if (window.removeEventListener)
		{
			window.removeEventListener("resize", onWindowResize, false);
			window.removeEventListener("scroll", onWindowScroll, false);
		} 
		else if (window.detachEvent)
		{
			window.detachEvent("onresize", onWindowResize);
			window.detachEvent("onscroll", onWindowScroll);
		}	   
    }

	control["__LightBox_Handlers_resize"] = null;
	control["__LightBox_Handlers_scroll"] = null;

	var containerId = controlId + "_LightBox_Container";
	var oContainer = document.getElementById(containerId);
	if (oContainer)
	{
		oContainer.parentNode.removeChild(oContainer);
	}
}
			
Radactive_WebControls_ILoad.prototype.ShowLightBox = function(controlId, windowLabel, windowId, url, w, h, modal, center, resizable, title)
{
	var control = Radactive.WebControls.ILoad.GetControl(controlId);
	var useLightbox_CssClass = false;
	var lightbox_CssClass = Radactive.WebControls.ILoad.GetLightbox_CssClass(controlId);
	if ((lightbox_CssClass != null) && (lightbox_CssClass != ""))
	{
		useLightbox_CssClass = true;
	}

	var ieVersion = Radactive.WebControls.GetIEVersion();

	var body = window.document.getElementsByTagName("body");
	if (body)
	{
		if (body.length > 0)
		{
			body = body[0];
		}
		else
		{
			body = null;
		}
	}
	if (!body)
	{
		body = window.document.body;
	}

	var containerId = controlId + "_LightBox_Container";
	var oContainer = document.getElementById(containerId);
	if (oContainer)
	{
		oContainer.parentNode.removeChild(oContainer);
	}

	oContainer = window.document.createElement("div");
	oContainer.setAttribute("id", containerId);
	if (useLightbox_CssClass)
	{
		oContainer.className = lightbox_CssClass;
	}
	else
	{
		oContainer.style.position = "absolute";
		oContainer.style.overflow = "hidden";
		oContainer.style.left = "0px";
		oContainer.style.top = "0px";
		oContainer.style.zIndex = 10101;
	}
	
	body.insertBefore(oContainer, body.firstChild);	

	if (ieVersion <= 0)
	{
		oContainer.style.width = "100%";
		oContainer.style.height = "100%";
	}

	var backgroundId = controlId + "_LightBox_Background";
	var oBackground = window.document.createElement("div");
	oBackground.setAttribute("id", backgroundId);
	if (useLightbox_CssClass)
	{
		oBackground.className = "background";
	}
	else
	{
		oBackground.style.display = "block";
		oBackground.style.position = "relative";
		oBackground.style.overflow = "hidden";
		oBackground.style.left = "0px";
		oBackground.style.top = "0px";
		oBackground.style.width = "100%";
		oBackground.style.height = "100%";	
		oBackground.style.backgroundColor = "#ffffff";		
		oBackground.style.opacity = 0.75;
		oBackground.style.filter = "alpha(opacity=75)";
	}

	oContainer.appendChild(oBackground);
	
	var windowId = controlId + "_LightBox_Window";
	var oWindow = window.document.createElement("div");
	oWindow.setAttribute("id", windowId);
	if (useLightbox_CssClass)
	{
		oWindow.className = "window";
		oWindow.style.width = w + "px";
		oWindow.style.height = h + "px";
	}
	else
	{
		oWindow.style.display = "block";
		oWindow.style.position = "relative";
		oWindow.style.overflow = "hidden";
		oWindow.style.width = w + "px";
		oWindow.style.height = h + "px";
		oWindow.style.borderColor = "#bbbbbb";
		oWindow.style.borderWidth = "10px";
		oWindow.style.borderStyle = "solid";
		oWindow.style.backgroundColor = "#ffffff";
	}
	
	oContainer.appendChild(oWindow);

	var fr1Id = controlId + "_LightBox_Fr1";
	var oFr1 = window.document.createElement("ifr" + "ame");
	oFr1.setAttribute("id", fr1Id);
	oFr1.setAttribute("name", fr1Id);
	oFr1.setAttribute("fr" + "ameBorder", "0");
	if (ieVersion > 0)
	{
		oFr1.allowTransparency = true;
	}
	oFr1.style.borderStyle = "none";
	oFr1.style.width = w + "px";
	oFr1.style.height = h + "px";
	
	oWindow.appendChild(oFr1);
	oFr1.setAttribute("src", url);
	oContainer.style.display = "block";

	var updateLayout = function()
	{	
        var left = 0;
        var top = 0;
        if ((document.documentElement) && ((document.documentElement.scrollLeft) || (document.documentElement.scrollTop)))
        {
			left = document.documentElement.scrollLeft;
			top = document.documentElement.scrollTop;
		}
		else if (document.body)
		{
			left = document.body.scrollLeft;
			top = document.body.scrollTop;
		}

		oContainer.style.left = left + "px";
		oContainer.style.top = top + "px";	
		
        var width = 0;
        var height = 0;
        if (window.innerWidth) 
        {
            width = window.innerWidth;
            height = window.innerHeight;
        } 
        else if ((window.document.documentElement) && (window.document.documentElement.clientWidth)) 
        {
            width = window.document.documentElement.clientWidth;
            height = window.document.documentElement.clientHeight;
        } 
        else if (window.document.body) 
        {
            width = window.document.body.clientWidth;
            height = window.document.body.clientHeight;
        }

		if (ieVersion > 0)
		{
			oContainer.style.width = width + "px";
			oContainer.style.height = height + "px";
		}

		if (oWindow.clientWidth != w)
		{
			oWindow.style.width = (w + (w - oWindow.clientWidth)) + "px";				
		}
		var windowLeft = Math.round((width - oWindow.offsetWidth) / 2);
		if (windowLeft < 0)
		{
			windowLeft = 0;
		}
		if (oWindow.clientHeight != h)
		{
			oWindow.style.height = (h + (h - oWindow.clientHeight)) + "px";				
		}
		oWindow.style.left = windowLeft + "px";
		var windowTop = (0 - height + Math.round((height - oWindow.offsetHeight) / 2));
		if (windowTop < (0 - height))
		{
			windowTop = (0 - height);
		}
		oWindow.style.top = windowTop + "px";
	}
	
	updateLayout();

	var onWindowResize = function(e)
	{
		if (!e)
		{
			e = window.event;
		}
		
		updateLayout();
	}

	var onWindowScroll = function(e)
	{
		if (!e)
		{
			e = window.event;
		}
		
		updateLayout();
	}

    if (window.addEventListener)
    {
        window.addEventListener("resize", onWindowResize, false);
        window.addEventListener("scroll", onWindowScroll, false);
    } 
    else if (window.attachEvent)
    {
        window.attachEvent("onresize", onWindowResize);
        window.attachEvent("onscroll", onWindowScroll);
    }
    
	control["__LightBox_Handlers_resize"] = onWindowResize;
	control["__LightBox_Handlers_scroll"] = onWindowScroll;
}


Radactive_WebControls.prototype.ILoad = new Radactive_WebControls_ILoad();

function ILoadWindowOpenResult()
{
}

ILoadWindowOpenResult.prototype.useCustomProvider = false;
ILoadWindowOpenResult.prototype.result = false;

function ILoadResult()
{
}

ILoadResult.prototype.myType = "ILoadResult";
ILoadResult.prototype.controlId = "";
ILoadResult.prototype.subSessionId = "";
ILoadResult.prototype.completed = false;
ILoadResult.prototype.index = null;

function WebImage(index)
{
	this.Resizes = new Array();

	var doc;
	if (typeof index == "string")
	{	
		doc = createXMLDOMFromString(index);
	}
	else
	{
		doc = index;
	}
	var root = doc.documentElement;
		
	var attribute = root.attributes.getNamedItem("FolderUrl");
	if (attribute != null)
	{
		this.FolderUrl = attribute.value;
	}
	else
	{
		attribute = root.attributes.getNamedItem("folderurl");
		if (attribute != null)
		{
			this.FolderUrl = attribute.value;
		}
	}
	
	attribute = root.attributes.getNamedItem("Id");
	if (attribute != null)
	{
		this.Id = attribute.value;
	}
	else
	{
		attribute = root.attributes.getNamedItem("id");
		if (attribute != null)
		{
			this.Id = attribute.value;
		}
	}
		
	attribute = root.attributes.getNamedItem("K2");
	if (attribute != null)
	{
		this.K2 = attribute.value;
	}
	else
	{
		attribute = root.attributes.getNamedItem("k2");
		if (attribute != null)
		{
			this.K2 = attribute.value;
		}
	}
	
	attribute = root.attributes.getNamedItem("PE");
	if (attribute != null)
	{
		this.PE = attribute.value;
	}
	else
	{
		attribute = root.attributes.getNamedItem("pe");
		if (attribute != null)
		{
			this.PE = attribute.value;
		}
	}
	
	attribute = root.attributes.getNamedItem("ConfigurationInternalCode");
	if (attribute != null)
	{
		this.ConfigurationInternalCode = attribute.value;
	}
	else
	{
		attribute = root.attributes.getNamedItem("configurationinternalcode");
		if (attribute != null)
		{
			this.ConfigurationInternalCode = attribute.value;
		}
	}
	
	attribute = root.attributes.getNamedItem("ImageDefinitionInternalCode");
	if (attribute != null)
	{
		this.ImageDefinitionInternalCode = attribute.value;
	}
	else
	{
		attribute = root.attributes.getNamedItem("imagedefinitioninternalcode");
		if (attribute != null)
		{
			this.ImageDefinitionInternalCode = attribute.value;
		}
	}
	
	attribute = root.attributes.getNamedItem("Storage");
	if (attribute != null)
	{
		this.Storage = attribute.value;
	}
	else
	{
		attribute = root.attributes.getNamedItem("storage");
		if (attribute != null)
		{
			this.Storage = attribute.value;
		}
	}
	
	attribute = root.attributes.getNamedItem("SourceImageClientFileName");
	if (attribute != null)
	{
		this.SourceImageClientFileName = attribute.value;
	}
	else
	{
		attribute = root.attributes.getNamedItem("sourceimageclientfilename");
		if (attribute != null)
		{
			this.SourceImageClientFileName = attribute.value;
		}
		else
		{
			this.SourceImageClientFileName = "";
		}
	}
	
	attribute = root.attributes.getNamedItem("Tag");
	if (attribute != null)
	{
		this.Tag = attribute.value;
	}
	else
	{
		attribute = root.attributes.getNamedItem("tag");
		if (attribute != null)
		{
			this.Tag = attribute.value;
		}
		else
		{
			this.Tag = "";
		}
	}
	
	var nodes = root.getElementsByTagName("SourceFilters");
	if (nodes.length > 0)
	{
		var sourceFiltersElement = nodes[0];
		this.SourceFilters = new ImageCropFilters();
		
		
		nodes = sourceFiltersElement.getElementsByTagName("SourceImageSize");
		if (nodes.length == 0)
		{
			nodes = sourceFiltersElement.getElementsByTagName("sourceimagesize");
		}
		if (nodes.length > 0)
		{
			var sourceImageSizeElement = nodes[0];

			var width = 0;
			attribute = sourceImageSizeElement.attributes.getNamedItem("Width");
			if (attribute != null)
			{
				width = attribute.value;
			}
			else
			{
				attribute = sourceImageSizeElement.attributes.getNamedItem("width");
				if (attribute != null)
				{
					width = attribute.value;
				}
			}

			var height = 0;
			attribute = sourceImageSizeElement.attributes.getNamedItem("Height");
			if (attribute != null)
			{
				height = attribute.value;
			}
			else
			{
				attribute = sourceImageSizeElement.attributes.getNamedItem("height");
				if (attribute != null)
				{
					height = attribute.value;
				}
			}

			this.SourceFilters.SourceImageSize = new Size(width,height);
		}


		attribute = sourceFiltersElement.attributes.getNamedItem("ZoomFactor");
		if (attribute != null)
		{
			this.SourceFilters.ZoomFactor = attribute.value;
		}
		else
		{
			attribute = sourceFiltersElement.attributes.getNamedItem("zoomfactor");
			if (attribute != null)
			{
				this.SourceFilters.ZoomFactor = attribute.value;
			}
		}
		

		nodes = sourceFiltersElement.getElementsByTagName("SourceRectangle");
		if (nodes.length == 0)
		{
			nodes = sourceFiltersElement.getElementsByTagName("sourcerectangle");
		}
		if (nodes.length > 0)
		{
			var sourceRectangleElement = nodes[0];

			var x = 0;
			attribute = sourceRectangleElement.attributes.getNamedItem("X");
			if (attribute != null)
			{
				x = attribute.value;
			}
			else
			{
				attribute = sourceRectangleElement.attributes.getNamedItem("x");
				if (attribute != null)
				{
					x = attribute.value;
				}
			}

			var y = 0;
			attribute = sourceRectangleElement.attributes.getNamedItem("Y");
			if (attribute != null)
			{
				y = attribute.value;
			}
			else
			{
				attribute = sourceRectangleElement.attributes.getNamedItem("y");
				if (attribute != null)
				{
					y = attribute.value;
				}
			}

			var width = 0;
			attribute = sourceRectangleElement.attributes.getNamedItem("Width");
			if (attribute != null)
			{
				width = attribute.value;
			}
			else
			{
				attribute = sourceRectangleElement.attributes.getNamedItem("width");
				if (attribute != null)
				{
					width = attribute.value;
				}
			}

			var height = 0;
			attribute = sourceRectangleElement.attributes.getNamedItem("Height");
			if (attribute != null)
			{
				height = attribute.value;
			}
			else
			{
				attribute = sourceRectangleElement.attributes.getNamedItem("height");
				if (attribute != null)
				{
					height = attribute.value;
				}
			}

			this.SourceFilters.SourceRectangle = new Rectangle(x,y,width,height);
		}
		
		
		attribute = sourceFiltersElement.attributes.getNamedItem("RotationAngle");
		if (attribute != null)
		{
			this.SourceFilters.RotationAngle = attribute.value;
		}
		else
		{
			attribute = sourceFiltersElement.attributes.getNamedItem("rotationangle");
			if (attribute != null)
			{
				this.SourceFilters.RotationAngle = attribute.value;
			}
		}
		
		attribute = sourceFiltersElement.attributes.getNamedItem("FlipHorizontal");
		if (attribute == null)
		{
			attribute = sourceFiltersElement.attributes.getNamedItem("fliphorizontal");
		}
		if (attribute != null)
		{
			if (attribute.value == "1")
			{
				this.SourceFilters.FlipHorizontal = true;
			}
		}
		
		attribute = sourceFiltersElement.attributes.getNamedItem("FlipVertical");
		if (attribute == null)
		{
			attribute = sourceFiltersElement.attributes.getNamedItem("flipvertical");
		}
		if (attribute != null)
		{
			if (attribute.value == "1")
			{
				this.SourceFilters.FlipVertical = true;
			}
		}
	}

	nodes = root.getElementsByTagName("Resizes");
	if (nodes.length > 0)
	{
		var resizesElement = nodes[0];
		if (resizesElement != null)
		{
			for(var i=0;i<resizesElement.childNodes.length; i++)
			{
				var node = resizesElement.childNodes[i];
				var resizeElement = node;

				var internalCode = "";
				attribute = resizeElement.attributes.getNamedItem("InternalCode");
				if (attribute != null)
				{
					internalCode = attribute.value;
				}
				else
				{
					attribute = resizeElement.attributes.getNamedItem("internalcode");
					if (attribute != null)
					{
						internalCode = attribute.value;
					}
				}
				
				var imageSize = new Size(0,0);

				nodes = resizeElement.getElementsByTagName("ImageSize");
				if (nodes.length > 0)
				{
					var imageSizeElement = nodes[0];
					var width = 0;
					attribute = imageSizeElement.attributes.getNamedItem("Width");
					if (attribute != null)
					{
						width = attribute.value;
					}
					else
					{
						attribute = imageSizeElement.attributes.getNamedItem("width");
						if (attribute != null)
						{
							width = attribute.value;
						}
					}

					var height = 0;
					attribute = imageSizeElement.attributes.getNamedItem("Height");
					if (attribute != null)
					{
						height = attribute.value;
					}
					else
					{
						attribute = imageSizeElement.attributes.getNamedItem("height");
						if (attribute != null)
						{
							height = attribute.value;
						}
					}

					imageSize = new Size(width,height);
				}

				var fileSize = 0;
				attribute = resizeElement.attributes.getNamedItem("FileSize");
				if (attribute != null)
				{
					fileSize = attribute.value;
				}
				else
				{
					attribute = resizeElement.attributes.getNamedItem("filesize");
					if (attribute != null)
					{
						fileSize = attribute.value;
					}
				}
				
				var extension = "";
				attribute = resizeElement.attributes.getNamedItem("Extension");
				if (attribute != null)
				{
					extension = attribute.value;
				}
				else
				{
					attribute = resizeElement.attributes.getNamedItem("extension");
					if (attribute != null)
					{
						extension = attribute.value;
					}
				}
				
				var imageFormatText = "";
				attribute = resizeElement.attributes.getNamedItem("ImageFormatText");
				if (attribute != null)
				{
					imageFormatText = attribute.value;
				}
				else
				{
					attribute = resizeElement.attributes.getNamedItem("imageformattext");
					if (attribute != null)
					{
						imageFormatText = attribute.value;
					}
				}
				
				var imageSizeText = "";
				attribute = resizeElement.attributes.getNamedItem("ImageSizeText");
				if (attribute != null)
				{
					imageSizeText = attribute.value;
				}
				else
				{
					attribute = resizeElement.attributes.getNamedItem("imagesizetext");
					if (attribute != null)
					{
						imageSizeText = attribute.value;
					}
				}
				
				var fileSizeText = "";
				attribute = resizeElement.attributes.getNamedItem("FileSizeText");
				if (attribute != null)
				{
					fileSizeText = attribute.value;
				}
				else
				{
					attribute = resizeElement.attributes.getNamedItem("filesizetext");
					if (attribute != null)
					{
						fileSizeText = attribute.value;
					}
				}
				
				var resize = new WebImageResize(this, internalCode, imageSize, fileSize, extension, imageFormatText, imageSizeText, fileSizeText);

			}
		}
	}
		
	doc = null;
}

WebImage.prototype.Resizes = null;
WebImage.prototype.GetResizeByName = function(internalCode)
{
	for(var i=0;i<this.Resizes.length;i++)
	{
		if (this.Resizes[i].InternalCode == internalCode)
		{
			return this.Resizes[i];
		}
	}
	return null;
}

WebImage.prototype.SourceImage = function()
{
	return this.GetResizeByName("__Source");
}

WebImage.prototype.SelectedImage = function()
{
	return this.GetResizeByName("__Selected");
}

WebImage.prototype.IconImage = function()
{
	return this.GetResizeByName("__Icon");
}

WebImage.prototype.FolderUrl = "";
WebImage.prototype.Id = "";
WebImage.prototype.K2 = "";
WebImage.prototype.PE = "";
WebImage.prototype.ConfigurationInternalCode = "";
WebImage.prototype.ImageDefinitionInternalCode = "";
WebImage.prototype.SourceFilters = null;
WebImage.prototype.SourceImageClientFileName = "";
WebImage.prototype.Storage = "";
WebImage.prototype.Tag = "";

WebImage.prototype.IsTemporary = function()
{
	if (this.Storage == "TemporaryFolder")
	{
		return true;
	}
	else
	{
		return false;
	}
}

WebImage.prototype.UseCustomStorage = function()
{
	if (this.Storage == "Custom")
	{
		return true;
	}
	else
	{
		return false;
	}
}

WebImage.prototype.UseFileSystemStorage = function()
{
	return !this.UseCustomStorage();
}

WebImage.prototype.GetFileName = function(internalCode, extension)
{
	if (this.UseFileSystemStorage())
	{
		if (extension[0] == ".")
		{
			var s = "";
			extension = extension.substring(1, extension.length-1);
		}
		return this.Id + "_" + internalCode + "." + extension;
	}
	else
	{
		return this.GetFileUrlName(internalCode, extension);
	}
}

WebImage.prototype.GetFileUrlName = function(internalCode, extension)
{
	if (this.UseFileSystemStorage())
	{
		if (this.Storage == "WebPublishedFileSystem")
		{
			return this.GetFileName(internalCode, extension);
		}
		else
		{
			var res = "";
			res += "__GIId=" + URLEncode(this.Id);
			res += "&__GIResize=" + URLEncode(internalCode);
			res += "&__GIExt=" + URLEncode(extension);
			res += "&__GIK2=" + URLEncode(this.K2);
			res += "&__GIPE=" + URLEncode(this.PE);
			return res;
		}
	}
	else
	{
		var res = "";
		res += "&ConfigIC=" + URLEncode(this.ConfigurationInternalCode);
		res += "&Id=" + URLEncode(this.Id);
		res += "&Resize=" + URLEncode(internalCode);
		res += "&FileExtension=" + URLEncode(extension.toLowerCase());
		return res;
	}
}

WebImage.prototype.GetFileUrl = function(fileName)
{
	if (this.UseFileSystemStorage())
	{
		if (this.Storage == "WebPublishedFileSystem")
		{
			if (this.FolderUrl)
			{
				var lastChar = this.FolderUrl.substr(this.FolderUrl.length-1,1);
				if (lastChar == "/")
				{
					return this.FolderUrl + fileName;
				}
				else
				{
					return this.FolderUrl + "/" + fileName;
				}
			}
			return fileName;
		}
	}
	if (this.FolderUrl.indexOf("?") >= 0)
	{
		return this.FolderUrl + "&" + fileName;
	}
	else
	{
		return this.FolderUrl + "?" + fileName;
	}
}

WebImage.prototype.GetIndex = function()
{
	var doc = createXMLDOM("WebImage");
	var root = doc.firstChild;
	
	root.setAttribute("Version", "4.0");
	
	root.setAttribute("ConfigurationInternalCode", "" + this.ConfigurationInternalCode);	
	root.setAttribute("ImageDefinitionInternalCode", "" + this.ImageDefinitionInternalCode);
	root.setAttribute("PE", "" + this.PE);
	root.setAttribute("FolderUrl", "" + this.FolderUrl);
	root.setAttribute("Id", "" + this.Id);
	root.setAttribute("K2", "" + this.K2);
	root.setAttribute("Storage", "" + this.Storage);
	root.setAttribute("SourceImageClientFileName", "" + this.SourceImageClientFileName);
	root.setAttribute("Tag", "" + this.Tag);
	
	if (this.SourceFilters != null)
	{
		var sourceFiltersElement = doc.createElement("SourceFilters");
		root.appendChild(sourceFiltersElement);
		
		sourceFiltersElement.setAttribute("ZoomFactor", "" + this.SourceFilters.ZoomFactor);

		var sourceImageSizeElement = doc.createElement("SourceImageSize");
		sourceFiltersElement.appendChild(sourceImageSizeElement);
		
		sourceImageSizeElement.setAttribute("Width", "" + this.SourceFilters.SourceImageSize.Width);
		sourceImageSizeElement.setAttribute("Height", "" + this.SourceFilters.SourceImageSize.Height);

		var sourceRectangleElement = doc.createElement("SourceRectangle");
		sourceFiltersElement.appendChild(sourceRectangleElement);
		
		sourceRectangleElement.setAttribute("X", "" + this.SourceFilters.SourceRectangle.X);
		sourceRectangleElement.setAttribute("Y", "" + this.SourceFilters.SourceRectangle.Y);
		sourceRectangleElement.setAttribute("Width", "" + this.SourceFilters.SourceRectangle.Width);
		sourceRectangleElement.setAttribute("Height", "" + this.SourceFilters.SourceRectangle.Height);

		sourceFiltersElement.setAttribute("RotationAngle", "" + this.SourceFilters.RotationAngle);
		if (this.SourceFilters.FlipHorizontal)
		{
			sourceFiltersElement.setAttribute("FlipHorizontal", "1");
		}
		else
		{
			sourceFiltersElement.setAttribute("FlipHorizontal", "0");
		}
		if (this.SourceFilters.FlipVertical)
		{
			sourceFiltersElement.setAttribute("FlipVertical", "1");
		}
		else
		{
			sourceFiltersElement.setAttribute("FlipVertical", "0");
		}

	}

	var resizesElement = doc.createElement("Resizes");
	root.appendChild(resizesElement);

	for(var i=0;i<this.Resizes.length;i++)
	{
		var resize = this.Resizes[i];

		var resizeElement = doc.createElement("Resize");
		resizesElement.appendChild(resizeElement);
		
		resizeElement.setAttribute("InternalCode", resize.InternalCode);

		var imageSizeElement = doc.createElement("ImageSize");
		resizeElement.appendChild(imageSizeElement);
		
		imageSizeElement.setAttribute("Width", "" + resize.Size.Width);
		imageSizeElement.setAttribute("Height", "" + resize.Size.Height);
		
		resizeElement.setAttribute("Extension", "" + resize.Extension);
		resizeElement.setAttribute("FileSize", "" + resize.FileSize);
		resizeElement.setAttribute("ImageFormatText", "" + resize.ImageFormatText);
		resizeElement.setAttribute("ImageSizeText", "" + resize.ImageSizeText);
		resizeElement.setAttribute("FileSizeText", "" + resize.FileSizeText);
	}
	
	var res = "";
	if (window.ActiveXObject)
	{
		res += doc.xml;
	}
	else
	{		
		var xmlSerializer = new XMLSerializer();
		res += xmlSerializer.serializeToString(doc);
		xmlSerializer = null;
		
		if ((!res) || (res == ""))
		{
			//res = getInnerXMLGeneric(doc);
		}
	}
		
	res = StringReplace(res, "&amp;", "_^?@EC1?^_");
	res = StringReplace(res, "&", "_^?@EC2?^_");
	res = StringReplace(res, "_^?@EC1?^_", "&amp;");
	res = StringReplace(res, "_^?@EC2?^_", "&amp;");
			
	doc = null;
	return res;
}

WebImage.prototype.IsSameImage = function(value)
{
	if (value != null)
	{
		if (value.K2 == this.K2)
		{
			if (value.ImageDefinitionInternalCode == this.ImageDefinitionInternalCode)
			{
				if (value.SourceImageClientFileName == this.SourceImageClientFileName)
				{
					if (value.SourceImage != null)
					{
						if (value.SourceImage.ImageFormatText == this.SourceImage.ImageFormatText)
						{
							if (value.SourceImage.ImageSizeText == this.SourceImage.ImageSizeText)
							{
								return true;
							}
						}
					}
				}
			}
		}
	}
	return false;
}

WebImage.prototype.GetReference = function()
{
	var result = "WEBIMAGE:";
	
	// Reference Version 1
	result += "1";
	result += "&" + URLEncode(this.ConfigurationInternalCode);
	result += "&" + URLEncode(this.Id);
	result += "&" + URLEncode(this.K2);
	result += "&" + URLEncode(this.Storage);
	if (this.Storage == "TemporaryFolder")
	{
		result += "&" + URLEncode(this.PE);
		result += "&"
	}
	if (this.Storage == "FileSystem")
	{
		result += "&" + URLEncode(this.PE);
		result += "&"
	}	
	if (this.Storage == "WebPublishedFileSystem")
	{
		result += "&" + URLEncode(this.PE);
		result += "&" + URLEncode(this.FolderUrl);
	}
	if (this.Storage == "Custom")
	{
		result += "&"
		result += "&" + URLEncode(this.FolderUrl);
	}
	
	return result
}

function WebImageResize(webImage, internalCode, size, fileSize, extension, imageFormatText, imageSizeText, fileSizeText)
{
	this.WebImage = webImage;
	this.InternalCode = internalCode;
	this.Size = size;
	this.FileSize = fileSize;
	this.Extension = extension;
	if (this.WebImage.Resizes.push)
	{
		this.WebImage.Resizes.push(this);
	}
	else
	{
		this.WebImage.Resizes[this.WebImage.Resizes.length] = this
	}
	
	this.ImageFormatText = imageFormatText;
	this.ImageSizeText = imageSizeText;
	this.FileSizeText = fileSizeText;
}

WebImageResize.prototype.WebImage = null;
WebImageResize.prototype.InternalCode = "";
WebImageResize.prototype.Extension = "";
WebImageResize.prototype.Size = null;
WebImageResize.prototype.FileSize = "";

WebImageResize.prototype.ImageSizeText = "";
WebImageResize.prototype.FileSizeText = "";
WebImageResize.prototype.ImageFormatText = "";

WebImageResize.prototype.FileName = function()
{
	return this.WebImage.GetFileName(this.InternalCode, this.Extension);
}

WebImageResize.prototype.FileUrlName = function()
{
	return this.WebImage.GetFileUrlName(this.InternalCode, this.Extension);
}

WebImageResize.prototype.FileUrl = function()
{
	return this.WebImage.GetFileUrl(this.FileUrlName());
}

WebImageResize.prototype.FileUrl_NoCache = function()
{
	var url = this.FileUrl();
	if (url.indexOf("?") < 0)
	{
		return url + "?fr=" + escape(Date());
	}
	else
	{
		return url + "&fr=" + escape(Date());
	}
}

function ILoadControl(controlId, uniqueId)
{
	this.ControlId = controlId;
	this.UniqueId = uniqueId;
}
ILoadControl.prototype.ControlId = "";
ILoadControl.prototype.UniqueId = "";
ILoadControl.prototype.ControlKey = "";
ILoadControl.prototype.WebImage = null;
ILoadControl.prototype.AutoPostBack = false;
ILoadControl.prototype.AutomaticallyClearTemporaryFiles = true;
ILoadControl.prototype.AutomaticallyDeleteRemovedFiles = false;
ILoadControl.prototype.AllowEditImage = false;
ILoadControl.prototype.AllowPreviewWindow = true;
ILoadControl.prototype.IconCustomResize = "";
ILoadControl.prototype.AutoPostBackEventHandler = false;
ILoadControl.prototype.ControlTitle = "";
ILoadControl.prototype.ImageUploadWizardWindowTitle = "";
ILoadControl.prototype.PreviewWindowTitle = "";
ILoadControl.prototype.AddImageButtonText = "Browse...";
ILoadControl.prototype.EditImageButtonText = "Edit...";
ILoadControl.prototype.Appearance = 1;
ILoadControl.prototype.Definition_InternalCodes = null;
ILoadControl.prototype.Definition_Titles = null;
ILoadControl.prototype.ResizeDefinition_InternalCodes = null;
ILoadControl.prototype.ResizeDefinition_Titles = null;
ILoadControl.prototype.ValueChangedEventHandler = false;
ILoadControl.prototype.WindowMode = 1;
ILoadControl.prototype.CustomWindowProvider_Open = false;
ILoadControl.prototype.CustomWindowProvider_Close = false;
ILoadControl.prototype.CustomWindowProvider_UseGetOpener = false;
ILoadControl.prototype.Culture = "";
ILoadControl.prototype.Lightbox_CssClass = "";

var ILoadControls = new Array();
