/*
 * Copyright © 2008-2009 RADactive srl - All Rights Reserved.
 * <www.RADactive.com>
 *  
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 
 * ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
 * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 
 * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 
 * SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR 
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 
 * OR OTHER DEALINGS IN THE SOFTWARE.
 */

function ILoad_CustomAppearance_Browse_click(controlId)
{
    // Launch the image upload window
	Radactive.WebControls.ILoad.AddImage(controlId, false);
}
	
function ILoad_CustomAppearance_Edit_click(controlId)
{
    // Launch the image edit window
	Radactive.WebControls.ILoad.AddImage(controlId, true);
}

function ILoad_CustomAppearance_Remove_click(controlId)
{
	if (!window.confirm("Are you sure?"))
	{
		return;
	}
	// Remove the image from the I-Load control and raise the client ValueChanged event handler
	Radactive.WebControls.ILoad.SetValue(controlId, null, true);
}
	
function ILoad_CustomAppearance_ILoad1_ValueChanged(controlId, webImage, ILoad_CustomAppearanceClientId, noImageUrl)
{
	if (webImage)
	{
	    // An image has been selected...
	    
	    // Get the resize "MyThumbnail"
		var resize = webImage.GetResizeByName("MyThumbnail");
		var str;
		if (resize != null)
		{
		    str = "<a href=\"javascript:void(0);\" onclick=\"Radactive.WebControls.ILoad.ShowImagePreview('" + controlId + "'); return false;\">";
		    str += "<img src=\"" + resize.FileUrl_NoCache() + "\" alt=\"\" style=\"border:none;\" />";
		    str += "</a>";
		}		
		else
		{
		    str = "";
		    alert("ILoad_CustomAppearance ASCX Control Error: Unable to find the WebImageResizeDefinition 'MyThumbnail'.\r\n");
		}			
	    document.getElementById(ILoad_CustomAppearanceClientId + "_Icon").innerHTML = str;		
		document.getElementById(ILoad_CustomAppearanceClientId + "_Edit").style.display = "inline";
		document.getElementById(ILoad_CustomAppearanceClientId + "_Remove").style.display = "inline";
	}
	else
	{
	    // No image selected...
	    
	    // Reset the layout
		var str = "<a href=\"javascript:void(0);\" onclick=\"ILoad_CustomAppearance_Browse_click('" + controlId + "'); return false;\">";
		str += "<img src=\"" + noImageUrl + "\" alt=\"\" style=\"border:none;\" />";
		str += "</a>";
		document.getElementById(ILoad_CustomAppearanceClientId + "_Icon").innerHTML = str;					
		document.getElementById(ILoad_CustomAppearanceClientId + "_Edit").style.display = "none";
		document.getElementById(ILoad_CustomAppearanceClientId + "_Remove").style.display = "none";
	}
}

