// This error prompt is similar to the error prompt provided by jquery.validationEngine.js
// It has fewer options. However, it can be invoked for any field even if it is not validated using the validationEngine
// It is useful for input fields where we filter the input.

function buildPrompt ( caller, promptText ) {
  var deleteItself = "." + $(caller).attr("id") + "formError";
  
  if($(deleteItself)[0]){
    $(deleteItself).stop();
    $(deleteItself).remove();
  }
  var divFormError = document.createElement('div');
  var formErrorContent = document.createElement('div');
  $(divFormError).addClass("formError");
  $(divFormError).addClass(linkToField(caller));
  $(formErrorContent).addClass("formErrorContent");
  
  $("body").append(divFormError);
  $(divFormError).append(formErrorContent);

  var arrow = document.createElement('div');
  $(arrow).addClass("formErrorArrow");
  $(divFormError).append(arrow);
  $(divFormError).append(arrow);
  $(arrow).html('<div class="line10"><!-- --></div><div class="line9"><!-- --></div><div class="line8"><!-- --></div><div class="line7"><!-- --></div><div class="line6"><!-- --></div><div class="line5"><!-- --></div><div class="line4"><!-- --></div><div class="line3"><!-- --></div><div class="line2"><!-- --></div><div class="line1"><!-- --></div>');
  
  $(formErrorContent).html(promptText);

  var callerTopPosition = $(caller).offset().top;
  var callerleftPosition = $(caller).offset().left;
  var callerWidth =  $(caller).width();
  var inputHeight = $(divFormError).height();

  callerTopPosition += -inputHeight -10;
  
  $(divFormError).css({
    top:callerTopPosition,
    left:callerleftPosition,
    opacity:0.87
  });
  
}

function deletePrompt(caller) {
  var deleteItself = "." + $(caller).attr("id") + "formError";
  
  if($(deleteItself)[0]){
    $(deleteItself).stop();
    $(deleteItself).remove();
  }
}

function linkToField(caller) {
  var linkTofield = $(caller).attr("id") + "formError";
  linkTofield = linkTofield.replace(/\[/g,""); 
  linkTofield = linkTofield.replace(/\]/g,"");
  return linkTofield;
}
