function changeCaptcha(){
  var rnd = new Date().getTime();
  document.getElementById("cimage").src = "./captcha.php?rnd="+ rnd + "&png";
  return false;
}

function validateComment(){
  var RE_txt = /\S+/;
  var RE_captcha = /^[A-Za-z]{5}$/;
  var RE_email = /^[0-9A-Za-z._-]{1,}@[0-9A-Za-z_-]{1,}\.[0-9A-Za-z_.-]{2,}$/;  
  
  if (!RE_txt.test(document.getElementById("comm_name").value)){
  	alert("Please enter your name");
	document.getElementById("comm_name").focus();
	return false;
  }
  if (!RE_email.test(document.getElementById("comm_email").value)){
  	alert("Please enter your email address");
	document.getElementById("comm_email").focus();
	return false;
  }
  if (!RE_txt.test(document.getElementById("comm_msg").value)){
  	alert("Please enter your comment");
	document.getElementById("comm_msg").focus();
	return false;
  }
  if (!RE_captcha.test(document.getElementById("blog_captchauser").value)){
  	alert("Please enter the code you see in the image");
	document.getElementById("blog_captchauser").focus();
	return false;
  }
  return true;
}

function showCommentPopup(){
	//position popup centered in screen		
	var margin = -35;
	if (typeof window.pageYOffset != 'undefined'){
		margin += window.pageYOffset;
	}else if (document.documentElement.scrollTop != 'undefined' && document.documentElement.scrollTop != 0){
	    margin += document.documentElement.scrollTop;   
	}else if (typeof document.body.scrollTop != 'undefined'){
	   margin += document.body.scrollTop;
	}
		
  	document.getElementById("blog_pop").style.marginTop = margin + 'px';
  	document.getElementById("blog_pop").style.display = 'block';
  	
}

var http = getHTTPObject();

var cmode = '';
function flagComment(pid,cid,mode){
  	if (confirm("Do you confirm that the comment is Inappropriate?")){
		var rand = new Date().getTime();
		var url  = 'blog-flagc.php';
		var params = 'rnd='+rand+'&bpid='+pid+'&bpcid='+cid+'&mode='+mode;
		cmode = mode;
		http.open("POST", url, true);
  		http.onreadystatechange = handleHttpResponseFlag;
		http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');				  	
  		http.send(params);
  	}
	return false;  
}

function handleHttpResponseFlag(){
  	if (http.readyState == 4){
	    if (http.responseText.length > 2){
	      	var parts = http.responseText.split('|||');
			alert(parts[0]);
			if (cmode == 'A')
				document.getElementById("blog_archive_comm_list").innerHTML = parts[1];			
			else
				document.getElementById("blog_comm_list").innerHTML = parts[1];
			//window.location.reload();  
		}
	}
}