//AHAJAX Functions - Copyright 2008 TNAFlix.com All rights reserved
//Proceses GET Request with server
var xmlhttp
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	  try {
	  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
	 } catch (e) {
	  try {
	    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
	  } catch (E) {
	   xmlhttp=false
	  }
	 }
	@else
	 xmlhttp=false
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	 try {
	  xmlhttp = new XMLHttpRequest();
	 } catch (e) {
	  xmlhttp=false
	 }
	}
	function myXMLHttpRequest() {
	  var xmlhttplocal;
	  try {
	    xmlhttplocal= new ActiveXObject("Msxml2.XMLHTTP")
	 } catch (e) {
	  try {
	    xmlhttplocal= new ActiveXObject("Microsoft.XMLHTTP")
	  } catch (E) {
	    xmlhttplocal=false;
	  }
	 }

	if (!xmlhttplocal && typeof XMLHttpRequest!='undefined') {
	 try {
	  var xmlhttplocal = new XMLHttpRequest();
	 } catch (e) {
	  var xmlhttplocal=false;
	  alert('couldn\'t create xmlhttp object');
	 }
	}
	return(xmlhttplocal);
}

function addslashes(str) {
    return str.replace('/(["\'\])/g', "\\$1").replace('/\0/g', "\\0");
}

function getComments(id, page) {
        document.getElementById('commentOutput').className = '';
	document.getElementById('commentOutput').innerHTML = '<br class="clear" /><div class="clear center"><img src="images/spinna.gif" alt="Loading..." /></div>';
        document.getElementById('commentOutput').style.height = '600px';
	var url = "ajax/get_blog_comments.php?bid=" + id + "&page="+ page;

	xmlhttp.open("get", url);
	xmlhttp.onreadystatechange = showOnlyComments;
	xmlhttp.send(null);
}

var formName = '';

function showOnlyComments() {
    if(xmlhttp.readyState == 4) {
        if(xmlhttp.responseText != ''){
            document.getElementById('commentOutput').style.height = '';
            document.getElementById('commentOutput').className = 'blogComments floatLeft';
            document.getElementById('commentOutput').innerHTML = xmlhttp.responseText;
        }

    }
}

function showComments() {
    if(xmlhttp.readyState == 4) {
        document.getElementById('commentMsg').innerHTML = '';
        document.getElementById('submit').className = 'floatLeft submit';

        eval(xmlhttp.responseText);
    }
}

function sndComment(comment,bid,cCode) {
    if(comment != "" || bid != ""){
        document.getElementById('commentMsg').innerHTML = '<br /><br /><div style="text-align: center;"><img src="images/spinna.gif" alt="Loading..." /></div>';
        document.getElementById('submit').className = 'hidden';

        xmlhttp.open('post', '/ajax/blog_add_comment.php?bid='+bid+'&cCode='+cCode);
        xmlhttp.onreadystatechange = showComments;
        xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        xmlhttp.send('c='+comment);

        if(document.getElementById('comment')){
            document.getElementById('comment').value = '';
        }
        if(document.getElementById('captcha')){
            document.getElementById('captcha').value = '';
        }
    }else{
        alert('You cant post an empty comment!');
    }
}