// JavaScript Document
var hasLoaded = false;
var xmlhttp;
function GetXmlHttpObject()
{
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject)
	{
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}
function stateChanged()
{
	if (xmlhttp.readyState==4)
	{
		if(xmlhttp.status==200)
		{
			eval(xmlhttp.responseText);
		}
		else
		{
			alert("Problem retrieving XML data:" + xmlhttp.statusText);
		}
	}
}
function loadXMLDoc(url,method,formdata)
{
	if(method == null)
	{
   		method = "GET";
	}
 	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	{
		alert ("Your browser does not support XMLHTTP!");
		return;
	}
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open(method,url,true);
	if(method == "POST")
	{
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	}
	xmlhttp.send(formdata);
}
function showCommentsTab(blog_id) {
	document.getElementById('blog_comments_'+blog_id).style.display = 'block';
	document.getElementById('blog_leave_comment_'+blog_id).style.display = 'none';
	document.getElementById('blog_email_'+blog_id).style.display = 'none';
	document.getElementById('comments_tab_'+blog_id).src = '/images/design/blog_comments_active.jpg';
	document.getElementById('email_tab_'+blog_id).src = '/images/design/blog_email.jpg';
	document.getElementById('security_image_comments_'+blog_id).src = '/security_image.php';
	reloadComments(blog_id);
}
function showLeaveCommentTab(blog_id) {
	document.getElementById('blog_comments_'+blog_id).style.display = 'block';
	document.getElementById('blog_leave_comment_'+blog_id).style.display = 'block';
	document.getElementById('blog_email_'+blog_id).style.display = 'none';
	document.getElementById('comments_tab_'+blog_id).src = '/images/design/blog_comments_active.jpg';
	document.getElementById('email_tab_'+blog_id).src = '/images/design/blog_email.jpg';
}
function showEmailTab(blog_id) {
	document.getElementById('blog_comments_'+blog_id).style.display = 'none';
	document.getElementById('blog_leave_comment_'+blog_id).style.display = 'none';
	document.getElementById('blog_email_'+blog_id).style.display = 'block';	
	document.getElementById('email_tab_'+blog_id).src = '/images/design/blog_email_active.jpg';
	document.getElementById('comments_tab_'+blog_id).src = '/images/design/blog_comments.jpg';
	document.getElementById('security_image_email_'+blog_id).src = '/security_image.php';
}
function showErrors() {
	document.getElementById('errors').style.display = 'inline';
}
function hideErrors() {
	document.getElementById('errors').style.display = 'none';
}
function sendEmail(id)
{
	var data="id="+id;
	data+="&email_from_name="+document.getElementById('email_from_name_'+id).value;
	data+="&email_from_email="+document.getElementById('email_from_email_'+id).value;
	data+="&email_to_name="+document.getElementById('email_to_name_'+id).value;
	data+="&email_to_email="+document.getElementById('email_to_email_'+id).value;
	data+="&security_code="+document.getElementById('security_code_email_'+id).value;
	data+="&sid="+document.getElementById('sid').value;
	
	var url="/requests/blog_sendEmail.php";
	loadXMLDoc(url,"POST",data);
}
function leaveComment(id)
{
	var data="id="+id;
	data+="&name="+document.getElementById('newComment_name_'+id).value;
	data+="&email="+document.getElementById('newComment_email_'+id).value;
	data+="&comment="+document.getElementById('newComment_comment_'+id).value;
	data+="&security_code="+document.getElementById('security_code_comments_'+id).value;
	data+="&sid="+document.getElementById('sid').value;
	
	var url="/requests/blog_leaveComment.php";
	loadXMLDoc(url,"POST",data);
}
function reloadComments(id)
{
	var url="/requests/blog_reloadComments.php?id="+id;
	loadXMLDoc(url);
}