shortcut.add("Ctrl+Shift+H",function() {
	addH1();
});

shortcut.add("Ctrl+Shift+B",function() {
	addBold();
});

shortcut.add("Ctrl+Shift+J",function() {
	addH2();
});

shortcut.add("Ctrl+Shift+D",function() {
	addBlock();
});

shortcut.add("Ctrl+Shift+L",function() {
	addLink();
});

shortcut.add("Enter",function() {
	addBreak();
});




function addH1(){
	var $tb = document.getElementById("text");
	$tb.focus();
	
	if (document.selection){
	  var str=document.selection.createRange().text;
	  var sel=document.selection.createRange();
	  sel.text="<h1>"+str+"</h1>";
	  
	}else if (typeof $tb.selectionStart != 'undefined'){
	  var $before, $after, $selection;
	  $before= $tb.value.substring(0, $tb.selectionStart)
	  $selection = $tb.value.substring($tb.selectionStart, $tb.selectionEnd)
	  $after = $tb.value.substring($tb.selectionEnd, $tb.value.length)
	  $tb.value= String.concat($before, "<h1>", $selection, "</h1>", $after)
	}
	 $tb.focus();
}

function addBreak(){
	var $tb = document.getElementById("text");
	$tb.focus();
	if (document.selection){
	  var str=document.selection.createRange().text;
	  var sel=document.selection.createRange();
	  sel.text="<br />\n";
	}
	else if (typeof $tb.selectionStart != 'undefined'){
	  var $before, $after, $selection;
	  $before= $tb.value.substring(0, $tb.selectionStart)
	  $selection = $tb.value.substring($tb.selectionStart, $tb.selectionEnd)
	  $after = $tb.value.substring($tb.selectionEnd, $tb.value.length)
	  $tb.value= String.concat($before, "<br />\n", $after)
	}
	 $tb.focus();
}



function addBold(){
	var $tb = document.getElementById("text");
	$tb.focus();
	if (document.selection){
	  var str=document.selection.createRange().text;
	  var sel=document.selection.createRange();
	  sel.text="<strong>"+str+"</strong>";
	}else if (typeof $tb.selectionStart != 'undefined'){
	  var $before, $after, $selection;
	  $before= $tb.value.substring(0, $tb.selectionStart)
	  $selection = $tb.value.substring($tb.selectionStart, $tb.selectionEnd)
	  $after = $tb.value.substring($tb.selectionEnd, $tb.value.length)
	  $tb.value= String.concat($before, "<strong>", $selection, "</strong>", $after)
	}
	 $tb.focus();
}

function addH2(){
	var $tb = document.getElementById("text");
	$tb.focus();
	if (document.selection){
	  var str=document.selection.createRange().text;
	  var sel=document.selection.createRange();
	  sel.text="<h2>"+str+"</h2>";
	}else if (typeof $tb.selectionStart != 'undefined'){
	  var $before, $after, $selection;
	  $before= $tb.value.substring(0, $tb.selectionStart)
	  $selection = $tb.value.substring($tb.selectionStart, $tb.selectionEnd)
	  $after = $tb.value.substring($tb.selectionEnd, $tb.value.length)
	  $tb.value= String.concat($before, "<h2>", $selection, "</h2>", $after)
	}
	 $tb.focus();
}

function addBlock(){
	var $tb = document.getElementById("text");
	$tb.focus();
	if (document.selection){
	  var str=document.selection.createRange().text;
	  var sel=document.selection.createRange();
	  sel.text='<div class="blockText">'+str+'</div>';
	}else if (typeof $tb.selectionStart != 'undefined'){
	  var $before, $after, $selection;
	  $before= $tb.value.substring(0, $tb.selectionStart)
	  $selection = $tb.value.substring($tb.selectionStart, $tb.selectionEnd)
	  $after = $tb.value.substring($tb.selectionEnd, $tb.value.length)
	  $tb.value= String.concat($before, '<div class="blockText">', $selection, '</div>', $after)
	}
	 $tb.focus();
}


function addLink(){
	var $tb = document.getElementById("text");
	$tb.focus();
	if (document.selection){
		
		var link = prompt("URL of the location", "");
		if(link){
		  	var str=document.selection.createRange().text;
		 	var sel=document.selection.createRange();
		  	sel.text= '<a class="link" href="' + link + '">' + str + '</a>';
		}
	  	
	  	
	}else if (typeof $tb.selectionStart != 'undefined'){
		
					
		var name = prompt("Name of the link", "");
 		var link = prompt("URL of the location", "");
 		var newLink = '<a class="link" href="' + link + '">' + name + '</a>';
 		
 		if(link && name){
	 		var $before, $after, $selection;
		 	$before= $tb.value.substring(0, $tb.selectionStart)
		 	$selection = $tb.value.substring($tb.selectionStart, $tb.selectionEnd)
		 	$after = $tb.value.substring($tb.selectionEnd, $tb.value.length)
			$tb.value= String.concat($before, newLink, $after);
 		}
	}
	 $tb.focus();
}
