﻿/*  
   Author:Gyanesh Buda  
          Dot Net Programmer  
          [WebSearch Professional]
          gyanesh_buda@hotmail.com  
          
*/ 

var defaultAuthor='Ditt namn (Obligatorisk)';
var defaultAuthorEmail ='Din E-post adress (Frivilligt)';
var defaultAuthorDesc = 'Skriv din kommentar här (Obligatorisk)';

function showFullData(objData)
{
//  var ary=new Array();
//  ary=objData.innerHTML.split("_");
//  var myCommentId=document.getElementById("RadDock3_C_Comment1_rptComment_"+ ary[4]+"_divIDContent").innerHTML;
// if(document.getElementById("RadDock3_C_Comment1_rptComment_"+ ary[4]+"_pnlCommentContent")!=null)
// document.getElementById("RadDock3_C_Comment1_rptComment_"+ary[4]+"_pnlCommentContent").innerHTML=WidgetHandler.getCommentFromID(myCommentId).value;
}
function ReportThisComment(obj)
{
  var choice = confirm('Är du säker på att du vill anmäla denna bild till webmaster?');         
    if(choice == true)
        {
             var userMessage = prompt('Please type your message.(optional)','');            
             var userEmail = prompt('Please type your email address(optional)','');
              if(userMessage == null)
                  userMessage = '';
                if(userEmail == null)
                    userEmail = '';

         
                var commentedBy = obj.parentElement.children[1].innerHTML;
                var commentedOn = obj.parentElement.children[2].innerHTML;
                var commentContent=obj.parentElement.children[3].innerHTML;
                var result = ClickHandler.SendBackstageMail(userMessage,userEmail,commentedBy,commentedOn,commentContent).value;
                alert(result);
            }
}
function deleteMyComment(kommentId)
{
   //ClickHandler.DeleteBackStageComment(kommentId);
   EventDataHandler_Comment.DeleteComment(kommentId);
   window.location.reload();
}
function deleteMyCommentReply(ReplyId)
{
    EventDataHandler_Comment.DeleteReply(ReplyId);
    window.location.reload();
}
function ShowMyCommentReply(CommentId)
{
    document.getElementById('txtRplyAuthorName'+CommentId).value= defaultAuthor;
    document.getElementById('txtRplyEmail'+CommentId).value= defaultAuthorEmail;
    document.getElementById('txtRplyCommentText'+CommentId).value= defaultAuthorDesc;
    var divs = document.getElementsByTagName('div');
    
    for(var i = 0; i < divs.length; i++)
    {
        if(divs[i].id.indexOf("rep8605") >= 0 && divs[i].id != "rep"+CommentId)
        {
            divs[i].style.display = 'none';
        }
    }
    
    if(document.getElementById("rep8605"+CommentId).style.display=="none")
    {
        document.getElementById("rep8605"+CommentId).style.display="block";
    }
    else
    {
        document.getElementById("rep8605"+CommentId).style.display="none";
    }
    //
    
  
}
function btnReplyComment(commentId)
{
   var CommentAuthor = document.getElementById("txtRplyAuthorName"+commentId);
   var commentEmail = document.getElementById("txtRplyEmail"+commentId);
   var commentDescription = document.getElementById('txtRplyCommentText'+commentId);
   
   if(CommentAuthor.value== defaultAuthor)
        CommentAuthor.value='';
   if(commentEmail.value==defaultAuthorEmail)
        commentEmail.value='';
   if(commentDescription.value==defaultAuthorDesc)
        commentDescription.value='';
   
   var todayDate = new Date(now.getFullYear(),now.getMonth(),now.getDate());      
        
   if(CommentAuthor!=null &&  CommentAuthor.value!="" && commentDescription!= null && commentDescription.value!="" && commentEmail!= null )
   {
        try
        {
         var insertReply = EventDataHandler_Comment.InsertCommentReply(commentId,CommentAuthor.value,commentEmail.value,commentDescription.value,now.getMonth()+'/'+now.getDate()+'/'+now.getFullYear());
        }
        catch(Error)
        {
        }
        
        if(insertReply)
        {
         alert('Reply has been saved successfully.');
        }
        else{
         alert('Reply could not be saved.');
        }
       
   }
    document.getElementById("rep8605"+commentId).style.display="none";
    window.location.reload();
//alert(CommentAuthor.value+' *** '+commentEmail.value +' *** '+ commentDescription.value );
}
function deleteDefaultTitle(CommentId)
{
    if(document.getElementById('txtRplyAuthorName'+CommentId).value==defaultAuthor)
    {
        document.getElementById('txtRplyAuthorName'+CommentId).value='';
    }   
    if(document.getElementById('txtRplyEmail'+CommentId).value=="")
    {
        document.getElementById('txtRplyEmail'+CommentId).value=defaultAuthorEmail;
    }
    if(document.getElementById('txtRplyCommentText'+CommentId).value=='')
    {
        document.getElementById('txtRplyCommentText'+CommentId).value=defaultAuthorDesc;
    }
}
function deleteDefaultEmail(CommentId)
{
    if(document.getElementById('txtRplyEmail'+CommentId).value==defaultAuthorEmail)
    {
        document.getElementById('txtRplyEmail'+CommentId).value='';
    }
    if(document.getElementById('txtRplyCommentText'+CommentId).value=='')
    {
        document.getElementById('txtRplyCommentText'+CommentId).value=defaultAuthorDesc;
    }
    if(document.getElementById('txtRplyAuthorName'+CommentId).value=='')
    {
        document.getElementById('txtRplyAuthorName'+CommentId).value=defaultAuthor;
    }
}
function deleteDefaultDesc(CommentId)
{
    if(document.getElementById('txtRplyCommentText'+CommentId).value==defaultAuthorDesc)
    {
        document.getElementById('txtRplyCommentText'+CommentId).value='';
    }
    if(document.getElementById('txtRplyAuthorName'+CommentId).value=='')
    {
        document.getElementById('txtRplyAuthorName'+CommentId).value=defaultAuthor;
    }
    if(document.getElementById('txtRplyEmail'+CommentId).value=="")
    {
        document.getElementById('txtRplyEmail'+CommentId).value=defaultAuthorEmail;
    }
}
function IsPressedEnterKey(commentId,obj)
{
  if(window.event) // IE
  {
    keynum = obj.keyCode;
  }
  else if(obj.which) // Netscape/Firefox/Opera
  {
    keynum = obj.which;
  }
  //keychar = String.fromCharCode(keynum);
  //numcheck = /\d/;
  //alert(commentId+'*************'+keynum);
  if(keynum==13)
  {
    btnReplyComment(commentId);
  }
}


 
 function CheckPublishComment(chk,divName)
{
    document.getElementById(divName).style.display = chk.checked? "inline":"none";

}
function Update_CommentMain()
{

  if(document.getElementById(CommentControlId + '_chkShowCommentBox') !=null && document.getElementById(CommentControlId + '_chkAllowPublishing'))
  {
   
    var AllowComment = document.getElementById(CommentControlId + '_chkShowCommentBox').checked;
    var PublishImmediately = document.getElementById(CommentControlId + '_chkAllowPublishing').checked;

    var result = EventDataHandler_Comment.InsertCommentMain(TemplateId,CommentTargetControlId,AllowComment,PublishImmediately);
   
  }

}

//function Update_CommentMain()
//{

//  if(document.getElementById(CommentControlId + '_LoginView1_chkShowCommentBox') !=null && document.getElementById(CommentControlId + '_LoginView2_chkAllowPublishing'))
//  {
//   
//    var AllowComment = document.getElementById(CommentControlId + '_LoginView1_chkShowCommentBox').checked;
//    var PublishImmediately = document.getElementById(CommentControlId + '_LoginView2_chkAllowPublishing').checked;

//    var result = EventDataHandler_Comment.InsertCommentMain(TemplateId,CommentTargetControlId,AllowComment,PublishImmediately);
//   
//  }

//}

function chkPublishComment_Checked(object)
{
   var CommentId = object.value;
   EventDataHandler_Comment.UpdateComment(parseInt(CommentId),object.checked);
}

function chkPublishReply_Checked(object)
{
  var ReplyId = object.value;
  EventDataHandler_Comment.UpdateCommentReply(parseInt(ReplyId),object.checked);
}


  function LoadName(object) {
    
        var infoName = document.getElementById(object.id).value;
        if (infoName == '')
            document.getElementById(object.id).value = 'Ditt namn (Obligatorisk)';
            
            }
  function LoadEmail(object) {
    
        var infoEmail = document.getElementById(object.id).value;
        if (infoEmail == '')
            document.getElementById(object.id).value = 'Din E-post adress (Frivilligt)';
            
            }
   function LoadComment(object) {
    
        var infoComment = document.getElementById(object.id).value;
        if (infoComment == '')
            document.getElementById(object.id).value = 'Skriv din kommentar här (Obligatorisk)';
            
            }