function SetEdit(Editor, Command, UserInterface, Option){
    //document.execCommand('formatblock',null,'<h1>');
    // first we assign the content of the textarea to the variable mainField
  var mainField;
        mainField = document.getElementById(Editor);
        //mainField.innerHTML = 'Johoohohoho, tak jsem tu ...';
  // then we will use execCommand to execute the option on the textarea making sure the textarea stays in focus
  try{
    mainField.focus();
    document.execCommand(Command, UserInterface, Option);
    //mainField.focus();
    //alert('Enter key pressed');
  } catch (e) { }
}

function AddLink(){
  SetEdit('EditPad', 'Subscript', false, Option);
  var i = 1000000;
  while(i){
    i--;
  }
  var PadContent = document.getElementById("EditPad").innerHTML;
  //re1=/(\d+)\s(\w+)/g;
  var Rel = /<sub>(.*)<\/sub>/gi;
  var RelIE = /<SUB>(.*)<\/SUB>/gi;
  var LinkText;
  if(!Rel.test(PadContent)){
    LinkText = PadContent.match(RelIE);
    if(!RelIE.test(PadContent)){
      //SetEdit('EditPad', 'Undo', false, Option);
      alert("Nejprve vyberte text, ktery ma slouzit jako odkaz ...");
      document.getElementById("EditPad").focus();
    }else{
      var result2=str.replace(re2,"$2=$1");
      alert(LinkText[0]);
      alert(LinkText[1]);
    }
  }else{
    var HardLinkText = PadContent.match(Rel);
    var StringLenght = HardLinkText[0].length;
    var LinkText = HardLinkText[0].substring(5,StringLenght-6);
    alert(LinkText);
    var Address = prompt("Zadejte adresu:","http://");
    if((Address == "") || (Address == "http://") || (Address == null) || (Address == false)){
      var result2=PadContent.replace(Rel,LinkText);
      document.getElementById("EditPad").innerHTML = result2;
      alert("Musite zadat nejkaou adresu ...");
    }else{
      var result2=PadContent.replace(Rel,"<a href='" + Address + "'>" + LinkText + "</a> ");
      document.getElementById("EditPad").innerHTML = result2;
    }
  }
}

function RTE_Save(){
  var PadContent = document.getElementById("EditPad").innerHTML;
  document.getElementById("RTEContentHiddenInput").value = PadContent;
  //alert(document.getElementById("RTEContentHiddenInput").value);
  return true;
}

function RTE_AddAction(){
  var PadContent = document.getElementById("EditPad").innerHTML;
  var ActionDay = document.DataForm.ActionDay.selectedIndex;
  var ActionMonth = document.DataForm.ActionMonth.selectedIndex;
  var ActionYear = document.DataForm.ActionYear.selectedIndex;
  var ActionAvatar = document.DataForm.ActionAvatar.selectedIndex;
  var ActionTitle = document.DataForm.ActionTitle.value;

  document.getElementById("RTEContentHiddenInput1").value = PadContent;
  document.getElementById("ActionDay").value = document.DataForm.ActionDay.options[ActionDay].value;
  document.getElementById("ActionMonth").value = document.DataForm.ActionMonth.options[ActionMonth].value;
  document.getElementById("ActionYear").value = document.DataForm.ActionYear.options[ActionYear].value;
  document.getElementById("ActionAvatar").value = document.DataForm.ActionAvatar.options[ActionAvatar].text;
  document.getElementById("ActionTitle").value = ActionTitle;

  return true;
}

function RTE_Confirm(Message){
  var ConfirmValue = confirm(Message);
  if (ConfirmValue) {
    return true;
  }else{
    return false;
  }
}

function RTE_DeleteAction(Message){
  var ConfirmValue = confirm(Message);
  if (ConfirmValue) {
    var Reason = prompt("Napiste duvod, proc je akce zrusena:");
    document.getElementById("CanceledReason").value = Reason;
    return true;
  }else{
    return false;
  }
}

// Changes the cursor to an hourglass
function RTE_SetHandCursor() {
document.body.style.cursor = 'pointer';
}

// Returns the cursor to the default pointer
function RTE_SetDefaultCursor() {
document.body.style.cursor = 'default';
}
