﻿var cleared = false;
var posted = false;

function ClearPlaybookComment(){

    if (cleared == false)
    {
        document.getElementById('taPlaybook').value = '';
        cleared = true;
    }
}

function ValidateMaxLength(objToCheck,MaxLength){

    var strCheckMe = new String();
    
    strCheckMe = objToCheck.value;
    if (strCheckMe.length > MaxLength) {
        objToCheck.value = strCheckMe.substring(0,MaxLength);
        var varMessage = "This field is limited to " + MaxLength + " characters.";
        alert(varMessage);
    }
}

function AddComment(playbookid,userid,username,spacesname,ownerspace){

    var comment = document.getElementById('taPlaybook').value;
    
    if(comment.length > 0 && cleared == true){
      
      if (posted == false){
            posted = true;
            ajaxUpdates.AddPlaybookComment(playbookid,userid,username,spacesname,comment)
            location.reload();
      }	
      
    }else{
        alert('Please enter a value for the "Message" field.');
        document.getElementById('taPlaybook').focus();
    }
  
}

function DeleteComment(commentid,playbookid,spacesname){
    ajaxUpdates.DeletePlaybookComment(commentid,playbookid)      
    
    document.getElementById('comment' + commentid).visible=false;
    location.reload();
}

function validatePost(el){
    el.href = "javascript:void(0);"
    if (document.getElementById('taPlaybook').value.length == 0 || cleared == false){
        alert('Please enter a value for the "Message" field.');
        document.getElementById('taPlaybook').focus();
    }else{
    
       if (posted == false){
           posted = true;
           __doPostBack('aBtn','');
           location.reload();
       }
    }
}