﻿// --------------------------------------------------------------
// source :		radeditor.js
// created :	28-02-2008
// updated :	03-03-2009
// version :	16
// --------------------------------------------------------------

// fires when RadEditor is loaded
function RadOnClientLoad(editor) {

//	if (typeof ($telerik) != "undefined") {
//		if ($telerik.radControls && Telerik.Web.UI.RadEditor) {
//			for (var i = 0; i < $telerik.radControls.length; i++) {
//				var control = $telerik.radControls[i];
//				if (Telerik.Web.UI.RadEditor.isInstanceOfType(control)) {
//					//control is a radeditor object  
//				}
//			}
//		}
//	}  

}

function OnClientCommandExecuting(editor, args) {

	if (typeof ($telerik) != "undefined") {
		if ($telerik.radControls && Telerik.Web.UI.RadEditor) {
			for (var i = 0; i < $telerik.radControls.length; i++) {
				var control = $telerik.radControls[i];
				if (Telerik.Web.UI.RadEditor.isInstanceOfType(control)) {
					
					// get the correct rad editor - if more than 1 on page
					if (editor.get_id() == control.get_id()) {

						// our editor is found

						// smileysDropdown
						if (args.get_name() == "SmileysDropdown") {

							control.pasteHtml('<img src="' + args.get_value() + '">');
							args.set_cancel(true); 
						}







					}
				}
			}
		}
	}


//	Telerik.Web.UI.Editor.CommandList["SmileysDropdown"] = function(commandName, editor, oTool) {

//		var oArray = $telerik.radControls;

//		// loop thru editors collection to see if there is a match between the client and a Rad Editor component
//		for (var i = 0; i < oArray.length; i++) {
//			// is it a Rad Editor ?
//			if (oArray[i].Id.substring(oArray[i].Id.length - client.length) == client) {
//				oArray[i].PasteHtml('<img src="' + smileysrc + '" border="0">');
//			}
//		}
//	}

}


function setFocusOnError() {
	setTimeout("setFocusOnErrorDelayed()", 100);
}

function setFocusOnErrorDelayed() {

	if (typeof (Page_Validators) != "undefined") {
		for (var i = 0; i < Page_Validators.length; i++) {
			if (!Page_Validators[i].isvalid) {
				var controlToValidate = Page_Validators[i].controltovalidate;

				if (typeof ($telerik) != "undefined") {
					if ($telerik.radControls && Telerik.Web.UI.RadEditor) {
						for (var i = 0; i < $telerik.radControls.length; i++) {
							var control = $telerik.radControls[i];
							if (Telerik.Web.UI.RadEditor.isInstanceOfType(control)) {

								// get the correct rad editor - if more than 1 on page
								if (control.get_id() == controlToValidate) {

									// our editor is found

									// yes - set focus and exit loop
									control.setFocus();
									return true;
								}
							}
						}
					}
				}
			}
		}
	}
	//document.getElementById(controlId).focus();
	return false;
}



function SetBFFocus(controlId) {
	setTimeout("MakeBFFocus('" + controlId + "');", 350);
}

function MakeBFFocus(controlId)
{
	if (typeof ($telerik) != "undefined") {
		if ($telerik.radControls) {
			for (var i = 0; i < $telerik.radControls.length; i++) {
				var control = $telerik.radControls[i];

				// get the correct control
				if (control.get_id() == controlId) {

					// our control is found

					// yes - set focus and exit loop
					control.setFocus();
					return true;
				}
			}
		}
	}
	document.getElementById(controlId).focus();
	return false;
}

