﻿// JScript File


       var w3c=document.getElementById && !window.opera;;
       var ie45=document.all && !window.opera;
       
       function postComment()
       {
           document.getElementById("CommentTable").style.display = "block";
       }
       function postCommentHide()
       {
           document.getElementById("CommentTable").style.display = "none";
       }
       function postReply(replyNo,buttonObj)
       {
            var x = getElementLeft(buttonObj);
            var y = getElementTop(buttonObj);

            document.getElementById("PostReplyTable").style.zIndex = 3;
            document.getElementById("PostReplyTable").style.top = y + 30 + "px";  
            document.getElementById("PostReplyTable").style.left = x + 5 + "px";
           // document.getElementById("PostReplyTable").style.position = (navigator.userAgent.indexOf('MSIE 6') > -1) ? 'absolute' : 'fixed'; 
            document.getElementById("PostReplyTable").style.display = "block";
            document.getElementById("HiddenCount").value = replyNo;
       }
       
       function postReplyHide()
       {
          document.getElementById("PostReplyTable").style.display = "none";
       }
       
       function getElementLeft(p_elm) {
        var x = 0;
        var elm;
        if(typeof(p_elm) == "object"){
          elm = p_elm;
        } else {
          elm = (w3c)?document.getElementById(p_elm):document.all[p_elm];
        }
        while (elm != null) {
          x+= elm.offsetLeft;
          elm = elm.offsetParent;
        }
        return parseInt(x);
      } 
       
      function getElementTop(p_elm) {
        var y = 0;
        var elm;
        if(typeof(p_elm) == "object"){
          elm = p_elm;
        } else {
          elm = (w3c)?document.getElementById(p_elm):document.all[p_elm];
        }
        while (elm != null) {
          y+= elm.offsetTop;
          elm = elm.offsetParent;
        }
        return parseInt(y);
      }
      
      
      function commentValidation()
      {
          var name = document.getElementById("NameTb").value;
          var comment = document.getElementById("CommentsTb").value;
          
          
          if(name.trim() == "")
          {
              document.getElementById("errlbl").innerHTML = "Please Enter Name";
              return false;
          }
          if(!validateAlphabets(name.trim()))
          {
              document.getElementById("errlbl").innerHTML = "Name should contain Characters only";
              return false;
          }
          if(!validateName(name.trim(),3,50))
          { 
              document.getElementById("errlbl").innerHTML = "Name should contain atleast 3 letters";
              return false;
          }
          
          if(comment.trim() == "")
          {
              document.getElementById("errlbl").innerHTML = "Please Enter Comment";
              return false;
          }
          if(!validateName(comment.trim(),3,5000))
          { 
              document.getElementById("errlbl").innerHTML = "Comment should contain atleast 3 letters";
              return false;
          }
          
          return true;
      }
      
      function replyValidation()
      {
          var name = document.getElementById("replyNameTb").value;
          var comment = document.getElementById("replyMessageTb").value;
          
          
          if(name.trim() == "")
          {
              document.getElementById("replylbl").innerHTML = "Please Enter Name";
              return false;
          }
          if(!validateAlphabets(name.trim()))
          {
              document.getElementById("replylbl").innerHTML = "Name should contain Characters only";
              return false;
          }
          if(!validateName(name.trim(),3,50))
          { 
              document.getElementById("replylbl").innerHTML = "Name should contain atleast 3 letters";
              return false;
          }
          
          if(comment.trim() == "")
          {
              document.getElementById("replylbl").innerHTML = "Please Enter Message";
              return false;
          }
          if(!validateName(comment.trim(),3,5000))
          { 
              document.getElementById("replylbl").innerHTML = "Message should contain atleast 3 letters";
              return false;
          }
          
          return true;
      }
      
      // functions for validations
      
      String.prototype.trim = function ()
        {
            return this.replace(/^\s*/, "").replace(/\s*$/, "");
        }
      
      function validateAlphabets(name)
        {
             var r  =/^[A-Za-z]+$/;
             if(!r.test(name))
                return false
             else return true;
        }
        
        function validateName(name,min,max)
        {
            if(name.length < min || name.length > max) return false;
            else return true;
           
        }