﻿
//common piece
function FindFirstChildByTagName(element, tagName) {
	for (var j = 0; j < element.childNodes.length; j++) {
		var child = element.childNodes[j];

		if (child.nodeType == 1 /* element */ && child.tagName == tagName) {
			return child;
		}
		else {
			var subSearchResult = FindFirstChildByTagName(child, tagName);
			if (subSearchResult) {
				return subSearchResult;
			}
		}
	}
	return null;
}

//used for tooltip (resize)
function OnClientBeforeShow(sender, eventArgs) {
	try {
		if (sender.get_text().length > 100) {
			var tooltipTable = sender._tableElement;
			if (tooltipTable) {
				//alert(tooltipTable.rows[1].cells[1]);

				//var ContentDiv = FindFirstChildByTagName(tooltipTable.rows[1].cells[1], "DIV") ;
				//alert(ContentDiv.style.width);
				tooltipTable.rows[1].cells[1].style.width = "300px";
				tooltipTable.rows[1].cells[1].style.height = ((sender.get_text().length / 50) + 1) * 13 + "px";
				//alert(tooltipTable.rows[1].cells[1].style.height);
				//ContentDiv.style.height = "100px";
				//alert(ContentDiv.style.width);
				//tooltipTable.style.width = "300px";
				//tooltipTable.style.height = ((sender.get_text().length / 50 ) + 1) * 20 + "px";
			}
			else {
				tooltip.set_width("");
				tooltip.set_height("");
			}

			sender.set_contentScrolling(0);
		}
	}
	catch (err) {

	}
}


//this opens a radwindow
function ShowRadWindow(windowClientID, url, title, width, height, enableClosePostback, OnClientCloseMethod, windowsBehaviors) {
	//alert(0);
	var oWnd = $find(windowClientID);
	//alert(oWnd);
	if (oWnd != null) {
		if (url != undefined) {
			oWnd.SetUrl(url);
		}
		if (title != undefined) {
			oWnd.SetTitle(title);
		}
		if (width != undefined) {
			oWnd.SetWidth(width);
		}
		if (height != undefined) {
			oWnd.SetHeight(height);
		}
		if (enableClosePostback) {
			oWnd.add_close(OnClientCloseMethod);
		}
		oWnd.set_behaviors(windowsBehaviors);

		oWnd.Argument = 1;
		oWnd.show();
	}
}


//this closes a radwindow with a given clientID
function CloseRadWindow(windowClientID) {
	var oWnd = $find(windowClientID);
	oWnd.close();
}

//this gets the current rad window showing
function GetRadWindow() {
	var oWindow = null;
	if (window.radWindow)
		oWindow = window.radWindow;
	else if
		(window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
	return oWindow;
}

//this closes a radwindow without a clientID
function CloseRadWindowFromPopup() {
	var oWindow = GetRadWindow();
	oWindow.Close();
}

//this closes a radwindow with an argument
function CloseRadWindowFromPopupWithArgument(argument) {
	var oWindow = GetRadWindow();
	var arg = new Object();
	arg.value = argument;
	oWindow.Close(arg);
}


//this reloads the page after a window closes
function OnClientClose(oWnd, eventArgs) {
}

function resizeWindow(validationGroup) {
	var valid;

	//alert(4);

	window.Page_ClientValidate(validationGroup);
	//alert(window.Page_IsValid);
	if (window.Page_IsValid == undefined) {
		valid = true;
	}
	else {
		valid = window.Page_IsValid;
	}
	if (valid == false) {
		var oWnd;
		oWnd = GetRadWindow();
		if (oWnd != null) {
			oWnd.autoSize();
		}
	}
}
