
function getTargetControl(p_ctrl) {
	var ctrl;
	var ctrlObj;

	ctrl = p_ctrl;
	
	if (ctrl.constructor && ctrl.constructor == String)
	{
		ctrlObj  = eval(ctrl);
	} else {
		ctrlObj  = ctrl;
	}
	
	return ctrlObj
}

function shortCuts(p_ctrl) {
	if (event.ctrlKey != true) return;
	strSelection = document.selection.createRange().text;
	if (event.keyCode == 1) ahrefThis(p_ctrl, 2);
	if (event.keyCode == 2) boldThis(p_ctrl, 2);
	if (event.keyCode == 9) italicThis(p_ctrl, 2);
}

function ahrefThis(p_ctrl, from) {

	var ctrlObj;
	
	ctrlObj = getTargetControl(p_ctrl);
	
	strSelection = document.selection.createRange().text;
	
	if (strSelection == "") {
		ctrlObj.focus();
	}
	
	strHref = prompt("Enter the URL you want to link to:","http://");
	
	if (strHref == null) {
		return;
	}
	
	document.selection.createRange().text = "<a href=\"" + strHref + "\">" + strSelection + "</a>";
	
	return;
}

function boldThis(p_ctrl, from) {

	var ctrlObj;
	
	ctrlObj = getTargetControl(p_ctrl);

	strSelection = document.selection.createRange().text;
	
	if (strSelection == "") {
		ctrlObj.focus();

		if (from == 2) {
			ctrlObj.select();
		}
		
		strSelection = document.selection.createRange().text;
		document.selection.createRange().text = strSelection + "<strong></strong>";
	
	} else {
	
		document.selection.createRange().text = "<strong>" + strSelection + "</strong>";
		
	}
	return;
}

function italicThis(p_ctrl, from) {
	var ctrlObj;
	
	ctrlObj = getTargetControl(p_ctrl);

	strSelection = document.selection.createRange().text;
	
	if (strSelection == "") {

		ctrlObj.focus();

		if (from == 2) {
			ctrlObj.select();
		}

		strSelection = document.selection.createRange().text;
		document.selection.createRange().text = strSelection + "<em></em>";

	} else {
		document.selection.createRange().text = "<em>" + strSelection + "</em>";
	}
	
	return;
}
