var BLOG_NAME

function submitComment(name, comment, blog){ 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
 		alert ("Browser does not support HTTP Request")
 		return
	}
	
	comment = escape(comment)
	for(i=0; i<comment.length; i++){
		if(comment.indexOf("%0D%0A") > -1){
			comment=comment.replace("%0D%0A", "<br />")
		}
		else if(comment.indexOf("%0A") > -1){
			comment=comment.replace("%0A", "<br />")
		}
		else if(comment.indexOf("%0D") > -1){
			comment=comment.replace("%0D", "<br />")
		}
	}
	comment=unescape(comment)

	BLOG_NAME = blog
	var url="/blog_comment.php"
	url=url+"?name="+name
	url=url+"&comment="+comment
	url=url+"&blog="+blog
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChangedComment
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function stateChangedComment(){ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		if(xmlHttp.responseText == 'ERROR'){
			document.getElementById('blog_comment_error_'+BLOG_NAME).innerHTML = "<p>Oops!  Please enter a comment ...</p><br>"
		}
		else{
			document.getElementById('blog_footer_'+BLOG_NAME).innerHTML = xmlHttp.responseText
		}
	} 
}

function submitRating(blog, comment, type, rating){ 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
 		alert ("Browser does not support HTTP Request")
 		return
	}
	BLOG_NAME = blog
	var url="/blog_rating.php"
	url=url+"?blog="+blog
	url=url+"&comment="+comment
	url=url+"&type="+type
	url=url+"&rating="+rating
	url=url+"&sid="+Math.random()
	if (type=="blog"){
		xmlHttp.onreadystatechange=stateChangedRating
	}
	else if (type=="blog" && rating=="positive"){
		xmlHttp.onreadystatechange=stateChangedRatingPositive
	}
	else if (type=="blog" && rating=="negative"){
		xmlHttp.onreadystatechange=stateChangedRatingNegative
	}
	else if (type=="comment"){
		BLOG_NAME = blog+comment
		xmlHttp.onreadystatechange=stateChangedCommentRating
	}
	else if (type=="comment" && rating=="positive"){
		BLOG_NAME = blog+comment
		xmlHttp.onreadystatechange=stateChangedCommentRatingPositive
	}
	else if (type=="comment" && rating=="negative"){
		BLOG_NAME = blog+comment
		xmlHttp.onreadystatechange=stateChangedCommentRatingNegative
	}
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function stateChangedRating(){ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		document.getElementById('blog_rating_'+BLOG_NAME).innerHTML=xmlHttp.responseText
		Effect.Appear('blog_rating_'+BLOG_NAME)
	} 
}

function stateChangedRatingPositive(){ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		document.getElementById('blog_rating_positive_'+BLOG_NAME).innerHTML=xmlHttp.responseText
	} 
}

function stateChangedRatingNegative(){ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		document.getElementById('blog_rating_negative_'+BLOG_NAME).innerHTML=xmlHttp.responseText
	} 
}

function stateChangedCommentRating(){ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		document.getElementById('blog_comment_rating_'+BLOG_NAME).innerHTML=xmlHttp.responseText
		Effect.Appear('blog_comment_rating_'+BLOG_NAME)
	} 
}

function stateChangedCommentRatingPositive(){ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		document.getElementById('blog_comment_rating_positive_'+BLOG_NAME).innerHTML=xmlHttp.responseText
	} 
}

function stateChangedCommentRatingNegative(){ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		document.getElementById('blog_comment_rating_negative_'+BLOG_NAME).innerHTML=xmlHttp.responseText
	} 
}