function Radactive_WebControls_ILoad()
{
}

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;
			}
		}
	}
	
	var controlId2 = controlId.replace("$","_");
	for(var i=0;i<ILoadControls.length;i++)
	{
		var control = ILoadControls[i];
		if (control)
		{
			if (control.ControlId.replace("$","_") == controlId2)
			{
				return control;
			}
		}
	}
	return null;
}

Radactive_WebControls_ILoad.prototype.GetControl2 = function(controlId)
{
	return document.getElementById(controlId);
}

Radactive_WebControls_ILoad.prototype.CreateControl = function(controlId)
{
	var control = new ILoadControl(controlId);

	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[i] = control;
	}
	else
	{
		if (ILoadControls.push)
		{
			ILoadControls.push(control);
		}
		else
		{
			ILoadControls[ILoadControls.length] = control;
		}
	}
	return control;
}

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)
	{
		return;
	}
	var editParam = "0";
	if (edit)
	{
		editParam = "1";
		var webImage = this.GetValue(controlId);
		if (!webImage)
		{
			alert("Error: Image no image to edit.");
			return;
		}
		if (!webImage.SourceImage())
		{
			alert("I-Load configuration error:\nSource image not found. Please enable [KeepSourceImage].");
			return;
		}
		if (webImage.UseCustomStorage())
		{
			alert("I-Load configuration error:\nCustom storage option doesn't support edit function.\nPlease disable I-Load edit function by setting 'AllowEdit' to false.");
			return;
		}
	}	
	
	this.Last_AddImage_Id = controlId;
	this.Last_AddImage_Edit = edit;
	var controlKey = control.ControlKey;
	var iload_result = Radactive.WebControls.ShowDialog("http://www.pattersonandtedford.com/Default.aspx?__ac=1&__ac_wcmid=RAWCIL&__ac_lib=Radactive.WebControls.ILoad&__ac_key=RAWCCIL_201&__ac_sid=54umedjgegmh4neg1vo5fm45&__ac_ssid=&__ac_ssid2=1&__ControlKey=" + URLEncode(controlKey) + "&___controlId=" + URLEncode(controlId) + "&___edit=" + URLEncode(editParam) + "&fr=" + URLEncode(Date()), 600, 430, true, true, false);
	if (Radactive.WebControls.ShowDialog_window_isModal)
	{
		this.AddImage_Return(iload_result);
	}
	return iload_result;
}

Radactive_WebControls_ILoad.prototype.AddImage_Return = function(iload_result)
{
	this.ClearTemporaryFiles(iload_result.subSessionId, !iload_result.completed);
	if (iload_result.completed)
	{
		var webImage = new WebImage(iload_result.index);
		this.SetValue(iload_result.controlId, webImage);
	}
}

Radactive_WebControls_ILoad.prototype.ClearTemporaryFiles = function(ssid, clearAll)
{
	var url = "http://www.pattersonandtedford.com/Default.aspx?__ac=1&__ac_wcmid=RAWCIL&__ac_lib=Radactive.WebControls.ILoad&__ac_key=RAWCCIL_2011&__ac_sid=54umedjgegmh4neg1vo5fm45&__ac_ssid=&fr=" + URLEncode(Date());
	url += "&ssidToClear=" + URLEncode(ssid);
	if (clearAll)
	{
		url += "&removeTemporaryFiles=1";
	}
	createXMLDOMFromRequest(url, false);
}

Radactive_WebControls_ILoad.prototype.DeleteWebImageFiles = function(folderPathEnc, id, key, k2)
{
	var url = "http://www.pattersonandtedford.com/Default.aspx?__ac=1&__ac_wcmid=RAWCIL&__ac_lib=Radactive.WebControls.ILoad&__ac_key=RAWCCIL_2012&__ac_sid=54umedjgegmh4neg1vo5fm45&__ac_ssid=&fr=" + URLEncode(Date());
	url += "&folderPath=" + URLEncode(folderPathEnc);
	url += "&id=" + URLEncode(id);
	url += "&key=" + URLEncode(key);
	url += "&k2=" + URLEncode(k2);
	
	createXMLDOMFromRequest(url, false);
}

Radactive_WebControls_ILoad.prototype.RemoveImage = function(controlId)
{
	if (window.confirm("Are you sure you want to remove this image?"))
	{
		this.SetValue(controlId, null);
	}
}	

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, webImage)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return;
	}
	var valueSpace = document.getElementById(controlId + "__Value");	
	if (!valueSpace)
	{
		return;
	}
	
	var oldValue = control.WebImage;
	if (oldValue)
	{
		if (oldValue.IsTemporary())
		{
			this.ClearTemporaryFiles(oldValue.Id, true);
		}
		else
		{
			if (this.GetAutomaticallyDeleteRemovedFiles(controlId))
			{
				if (oldValue.UseFileSystemStorage())
				{
					this.DeleteWebImageFiles(oldValue.FolderPathEnc ,oldValue.Id, oldValue.Key, oldValue.K2);
				}
			}
		}
	}
	control.WebImage = webImage;
	
	if (webImage)
	{
		valueSpace.value = URLEncode(webImage.GetIndex());
	}
	else
	{
		valueSpace.value = "";
	}
	
	if (this.GetAutoPostBack(controlId))
	{
		window.setTimeout("Radactive.WebControls.ILoad.RaiseBackEventHandler('" + controlId + "');",500);
		return;
	}
	
	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 = webImage.IconImage();
		if (iconResize)
		{
			if (iconPreviewSpace)
			{
				iconPreviewSpace.innerHTML = "<a href=\"#\" onclick=\"Radactive.WebControls.ILoad.ShowImagePreview('" + controlId + "'); return false;\"><img src=\"" + iconResize.FileUrl_NoCache() + "\" border=\"0\" alt=\"Show image preview\" style=\"border:solid 1px #CCCCCC;\" HIDEFOCUS=\"true\"></A>";
			}
		}
		if (imageDetailSpace)
		{
			var str = "";
			var definitionTitle = this.GetDefinitionTitle(controlId, webImage.ImageDefinitionInternalCode);
			if (definitionTitle == "")
			{
				definitionTitle = "Unknown";
			}
			str += "Definition: " + definitionTitle + "<br>";
			var selectedResize = webImage.SelectedImage();
			if (selectedResize)
			{
				str += "Size (px): " + selectedResize.ImageSizeText  + "&nbsp;&nbsp;&nbsp;(" + selectedResize.Extension + " - " + selectedResize.FileSizeText + ")<br>";
			}
			imageDetailSpace.innerHTML = str;
			imageDetailSpace.style.display = "block";
		}
		if (imageDetailEmptySpace)
		{
			imageDetailEmptySpace.style.display = "none";
		}
		if ((editImageSpace) && (!webImage.UseCustomStorage()))
		{
			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)
		{
			iconPreviewSpace.innerHTML = "";
		}
		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";
		}
	}
	
	var control2 = this.GetControl2(controlId);
	if (control2)
	{
		if (control2.onValueChange)
		{
			if (control2.onValueChange.prototype)
			{
				control2.onValueChange();
			}
			else
			{
				eval(control2.onValueChange);
			}
		}
	}
	
	this.UpdateValidator(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.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.SetPostBackEventHandler = function(controlId, value)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return;
	}
	control.AutoPostBackEventHandler = value;
}

Radactive_WebControls_ILoad.prototype.RaiseBackEventHandler = function(controlId)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return;
	}
	if (control.AutoPostBackEventHandler)
	{
		if (control.AutoPostBackEventHandler.prototype)
		{
			control.AutoPostBackEventHandler();
		}
		else
		{
			eval(control.AutoPostBackEventHandler);
		}
	}
}

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.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.SetControlKey = function(controlId, controlKey)
{
	var control = this.GetControl(controlId);
	if (!control)
	{
		return "";
	}
	control.ControlKey = controlKey;
}

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 controlKey = control.ControlKey;
	var result = Radactive.WebControls.ShowDialog("http://www.pattersonandtedford.com/Default.aspx?__ac=1&__ac_wcmid=RAWCIL&__ac_lib=Radactive.WebControls.ILoad&__ac_key=RAWCCIL_301&__ac_sid=54umedjgegmh4neg1vo5fm45&__ControlKey=" + URLEncode(controlKey) +  "&fr=" + URLEncode(Date()), 450, 470, true, true, true);
}

Radactive_WebControls_ILoad.prototype.Validate = function(validatorControl)
{
	var controlId = validatorControl.controltovalidate;
	var webImage = Radactive.WebControls.ILoad.GetValue(controlId);
	if (webImage)
	{
		return true;
	}
	else
	{
		return false;
	}
}

Radactive_WebControls_ILoad.prototype.GetValidator = function(controlId)
{
	if (!controlId)
	{
		return null;
	}
	
	if (window.Page_Validators)
	{
		if (window.Page_Validators.length)
		{
			for(var i=0;i<window.Page_Validators.length;i++)
			{
				var validator = window.Page_Validators[i];
				if (validator)
				{
					if (validator.controltovalidate == controlId)
					{
						return validator;
					}
				}
			}
			for(var i=0;i<window.Page_Validators.length;i++)
			{
				var validator = window.Page_Validators[i];
				if (validator)
				{
					if (validator.controltovalidate == controlId.replace("$","_"))
					{
						return validator;
					}
				}
			}
		}
	}
	
	return null;
}

Radactive_WebControls_ILoad.prototype.UpdateValidator = function(controlId)
{
	var validator = this.GetValidator(controlId);
	if (validator)
	{
		if (window.ValidatorValidate)
		{
			window.ValidatorValidate(validator);
		}
	}
}

function ILoadResult()
{
}

ILoadResult.prototype.controlId = "";
ILoadResult.prototype.subSessionId = "";
ILoadResult.prototype.completed = false;
ILoadResult.prototype.index = null;

function WebImage(index)
{
	this.Resizes = new Array();
	
	var doc = createXMLDOMFromString(index);
	var root = doc.documentElement;
	
	var attribute = root.attributes.getNamedItem("FolderPath");
	if (attribute != null)
	{
		this.FolderPath = attribute.value;
	}
	
	attribute = root.attributes.getNamedItem("FolderPathEnc");
	if (attribute != null)
	{
		this.FolderPathEnc = attribute.value.replace(/\ /g, '+');
	}

	attribute = root.attributes.getNamedItem("FolderUrl");
	if (attribute != null)
	{
		this.FolderUrl = attribute.value;
	}
	
	attribute = root.attributes.getNamedItem("Id");
	if (attribute != null)
	{
		this.Id = attribute.value;
	}
	
	attribute = root.attributes.getNamedItem("Key");
	if (attribute != null)
	{
		this.Key = attribute.value;
	}
	
	attribute = root.attributes.getNamedItem("K2");
	if (attribute != null)
	{
		this.K2 = attribute.value;
	}
	
	attribute = root.attributes.getNamedItem("ConfigurationInternalCode");
	if (attribute != null)
	{
		this.ConfigurationInternalCode = attribute.value;
	}
	
	attribute = root.attributes.getNamedItem("ImageDefinitionInternalCode");
	if (attribute != null)
	{
		this.ImageDefinitionInternalCode = attribute.value;
	}
	
	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
	{
		this.SourceImageClientFileName = "";
	}
	
	var nodes = root.getElementsByTagName("SourceFilters");
	if (nodes.length > 0)
	{
		var sourceFiltersElement = nodes[0];
		this.SourceFilters = new ImageCrop();

		attribute = sourceFiltersElement.attributes.getNamedItem("ZoomFactor");
		if (attribute != null)
		{
			this.SourceFilters.ZoomFactor = attribute.value;;
		}

		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;
			}

			var y = 0;
			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;
			}

			var height = 0;
			attribute = sourceRectangleElement.attributes.getNamedItem("Height");
			if (attribute != null)
			{
				height = attribute.value;
			}

			this.SourceFilters.SourceRectangle = new Rectangle(x,y,width,height);
		}
	}

	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;
				}
				
				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;
					}

					var height = 0;
					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;
				}
				
				var extension = "";
				attribute = resizeElement.attributes.getNamedItem("Extension");
				if (attribute != null)
				{
					extension = attribute.value;
				}
				
				var imageFormatText = "";
				attribute = resizeElement.attributes.getNamedItem("ImageFormatText");
				if (attribute != null)
				{
					imageFormatText = attribute.value;
				}
				
				var imageSizeText = "";
				attribute = resizeElement.attributes.getNamedItem("ImageSizeText");
				if (attribute != null)
				{
					imageSizeText = attribute.value;
				}
				
				var fileSizeText = "";
				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.FolderPath = "";
WebImage.prototype.FolderPathEnc = "";
WebImage.prototype.FolderUrl = "";
WebImage.prototype.Id = "";
WebImage.prototype.Key = "";
WebImage.prototype.K2 = "";
WebImage.prototype.ConfigurationInternalCode = "";
WebImage.prototype.ImageDefinitionInternalCode = "";
WebImage.prototype.SourceFilters = null;
WebImage.prototype.SourceImageClientFileName = "";
WebImage.prototype.Storage = "";

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);
		}
		if (this.Key != "")
		{
			return this.Id + "_" + this.Key + "_"  + internalCode + "." + extension;
		}
		else
		{
			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 += "__GIPath=" + URLEncode(this.FolderPathEnc);
			res += "&__GIId=" + URLEncode(this.Id);
			res += "&__GIKey=" + URLEncode(this.Key);
			res += "&__GIResize=" + URLEncode(internalCode);
			res += "&__GIExt=" + URLEncode(extension);
			res += "&__GIK2=" + URLEncode(this.K2);
			return res;
		}
	}
	else
	{
		var mimeType = "image/jpeg";
		var s;
		switch(extension.toLowerCase())
		{
			case "jpeg":
				extension = "image/jpeg";
				break;
			case "gif":
				extension = "image/gif";
				break;
		}
		var res = "";
		res += "Config=" + URLEncode(this.ConfigurationInternalCode);
		res += "&Id=" + URLEncode(this.Id);
		res += "&Key=" + URLEncode(this.Key);
		res += "&Resize=" + URLEncode(internalCode);
		res += "&MimeType=" + URLEncode(mimeType);
		return res;
	}
}

WebImage.prototype.GetFilePath = function(fileName)
{
	if (!this.UseFileSystemStorage())
	{
		window.alert("Ivalid operation");
		return null;
	}
	if (this.FolderPath)
	{
		var lastChar = this.FolderPath.substr(this.FolderPath.length-1,1);
		if ((lastChar == "/") || (lastChar == "\\"))
		{
			return this.FolderPath + fileName;
		}
		else
		{
			return this.FolderPath + "/" + fileName;
		}
	}
	return fileName;
}

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("ConfigurationInternalCode", this.ConfigurationInternalCode);
	root.setAttribute("ImageDefinitionInternalCode", this.ImageDefinitionInternalCode);
	root.setAttribute("FolderPath", this.FolderPath);
	root.setAttribute("FolderPathEnc", this.FolderPathEnc);  //FolderEnc
	root.setAttribute("FolderUrl", this.FolderUrl);
	root.setAttribute("Id", this.Id);
	root.setAttribute("Key", this.Key);
	root.setAttribute("K2", this.K2);
	root.setAttribute("Storage", this.Storage);
	root.setAttribute("SourceImageClientFileName", this.SourceImageClientFileName);
	
	if (this.SourceFilters != null)
	{
		var sourceFiltersElement = doc.createElement("SourceFilters");
		root.appendChild(sourceFiltersElement);
		
		sourceFiltersElement.setAttribute("ZoomFactor", this.SourceFilters.ZoomFactor);

		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);
	}

	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 = res.replace(/&(?!amp;)/g,"&amp;");
		
	doc = null;
	return res;
}


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.FilePath = function()
{
	return this.WebImage.GetFilePath(this.FileName());
}

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)
{
	this.ControlId = controlId;
}
ILoadControl.prototype.ControlId = "";
ILoadControl.prototype.ControlKey = "";
ILoadControl.prototype.WebImage = null;
ILoadControl.prototype.AutoPostBack = false;
ILoadControl.prototype.AutomaticallyDeleteRemovedFiles = false;
ILoadControl.prototype.AutoPostBackEventHandler = false;
ILoadControl.prototype.ControlTitle = "";
ILoadControl.prototype.Definition_InternalCodes = null;
ILoadControl.prototype.Definition_Titles = null;
ILoadControl.prototype.ResizeDefinition_InternalCodes = null;
ILoadControl.prototype.ResizeDefinition_Titles = null;

var ILoadControls = new Array();