
document.write("<script type='text/javascript' src='/scripts/jquery/jquery/jquery.js'></script>");
var comtype = "community";
function post_comment(pid)
{
  if(document.comment.name.value == '')
  {
  alert('Please enter your name');
  document.comment.name.focus();
  return false;
  }
  if(document.comment.name.value.substring(0,1) == " ")
  {
  alert("The First character should not be a space in your name");
  document.comment.name.focus();
  return false;
  }
  if(document.comment.email.value == '') 
  {
  alert('Please enter your email');
  document.comment.email.focus();
  return false;
  }
  if(document.comment.email.value.substring(0,1) == " ")
  {
  alert("The First character should not be a space in email");
  document.comment.email.focus();
  return false;
  }
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.comment.email.value)) { 
  }
  else
  {
  alert("Invalid E-mail Address! Please re-enter.");
  return false;
  }
  if(document.comment.comment_text.value == '')
  {
  alert('Please enter your comment');
  document.comment.comment_text.focus();
  return false;
  }
  if(document.comment.comment_text.value.substring(0,1) == " ")
  {
  alert("The First character should not be a space in comments");
  document.comment.comment_text.focus();
  return false;
  }
  if(document.comment.security_code.value == '')
  {
  alert('Please enter security code as shown');
  document.comment.security_code.focus();
  return false;
  }
  if(document.comment.security_code.value.substring(0,1) == " ")
  {
  alert("The First character should not be a space in security code");
  document.comment.security_code.focus();
  return false;
  }	
  var comm = document.comment.comment_text.value;
  var myname = document.comment.name.value;
  var mail = document.comment.email.value;
  var pqid = pid;
  var secode = document.comment.security_code.value;
       
 $.get("/modules/comments/add_comments.php",{comment:comm,name:myname,email:mail,pid:pqid,security_code:secode,type:comtype},
 function (resp)
 {
  //alert(resp);
  if(resp == 404)
  {
  alert('Invalid Security Code. Please try again!');
  document.getElementById('errmsg').innerHTML='<font color=red>Invalid Security Code. Please try again!</font>';
  }
  else if(resp == 1)   
       {
          $.get("/modules/comments/view_comments.php",{pqid:pid,type:comtype},
          function (resp)
          {
		   document.getElementById('dispcomm').innerHTML = resp;
           $('#showform').hide();//hides body content
           $('#dispcomm').show();//shows spinner
		   document.comment.comment_text.value='';
		   //document.comment.name.value='';
		   //document.comment.email.value='';
		   document.comment.security_code.value='';
		   document.getElementById('errmsg').style.display = "none";
	       document.getElementById('entercomm').style.display='none';
		  });
       }
  else
   { }
         
 }
 );
}


function disp(pid) {
   $.get("/modules/comments/view_comments.php",{pqid:pid,type:comtype},
   function(resp)
   {
	document.getElementById('dispcomm').innerHTML = resp;
	document.getElementById('errmsg').style.display='none';
	document.getElementById('entercomm').style.display='none';
   }
  )
      document.getElementById('dispcomm').style.display = '';
      document.getElementById('entercomm').style.display = 'none';
  }

function disp1(){
  
  document.getElementById('dispcomm').style.display = 'none';
  document.getElementById('entercomm').style.display = '';
  document.getElementById('captcha').src = '/modules/captcha/securimage_show.php?' + Math.random();
        }


function load_page(pno,pid)///////////for ajax pagination
{
 $.get("/modules/comments/view_comments.php",{pqid : pid,page : pno,type:comtype},
  function(resp)
  {
   document.getElementById('dispcomm').innerHTML = resp;
   document.getElementById('entercomm').style.display = 'none';
  }
 )
}


