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;
	}
  }
  return (xmlhttplocal);
}

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }

var mnmxmlhttp = Array ();
var xvotesString = Array ();
var mnmPrevColor = Array ();
var responsestring = Array ();
var myxmlhttp = Array ();
var responseString = new String;


function voteup (id, md5, value)
{
  	if (xmlhttp) {
		url = "/voteup.php";
		var mycontent = "id=" + id + "&md5=" + md5 + "&value=" + value;
    		mnmxmlhttp[id] = new myXMLHttpRequest ();
    		if (mnmxmlhttp) {
    			mnmxmlhttp[id].open ("POST", url, true);
    			mnmxmlhttp[id].setRequestHeader ('Content-Type',
    					   'application/x-www-form-urlencoded');
    //alert(mnmxmlhttp[id]);
    			mnmxmlhttp[id].send (mycontent);
    			errormatch = new RegExp ("^ERROR:");    
    			//target1 = document.getElementById ('xvotes-' + id);    
    		//	mnmPrevColor[id] = target1.style.backgroundColor;
    			mnmxmlhttp[id].onreadystatechange = function () {
    				if (mnmxmlhttp[id].readyState == 4) {
    					xvotesString[id] = mnmxmlhttp[id].responseText;
    					//alert(mnmxmlhttp[id].responseText);
    					if (xvotesString[id].match (errormatch)) {
    						xvotesString[id] = xvotesString[id].substring (6, xvotesString[id].length);
							changemnmvalues (id, value, true);    					} else {
														if (xvotesString[id].substring (1, 6) == "ERROR") { 
                            
                } else {
                changemnmvalues ('up',id, value, false); 
                }     					}
    				}
    			}
    		}
    
	}
}

function flag (id, md5, value)
{
  	if (xmlhttp) {
		url = "/flag.php";
		var mycontent = "id=" + id + "&md5=" + md5 + "&value=" + value;
    		mnmxmlhttp[id] = new myXMLHttpRequest ();
    		if (mnmxmlhttp) {
    			mnmxmlhttp[id].open ("POST", url, true);
    			mnmxmlhttp[id].setRequestHeader ('Content-Type',
    					   'application/x-www-form-urlencoded');
    //alert(mnmxmlhttp[id]);
    			mnmxmlhttp[id].send (mycontent);
    			errormatch = new RegExp ("^ERROR:");    
    			//target1 = document.getElementById ('xvotes-' + id);    
    		//	mnmPrevColor[id] = target1.style.backgroundColor;
    			mnmxmlhttp[id].onreadystatechange = function () {
    				if (mnmxmlhttp[id].readyState == 4) {
    					xvotesString[id] = mnmxmlhttp[id].responseText;
    					//alert(mnmxmlhttp[id].responseText);
    					if (xvotesString[id].match (errormatch)) {
    						xvotesString[id] = xvotesString[id].substring (6, xvotesString[id].length);
							changemnmvalues (id, value, true);    					} else {
														if (xvotesString[id].substring (1, 6) == "ERROR") { 
                            
                } else {
                changemnmvalues ('flag',id, value, false); 
                }     					}
    				}
    			}
    		}
    
	}
}

function changemnmvalues (vote_type, id, value, error)
{
	split = new RegExp ("~--~");
	b = xvotesString[id].split (split);
	//alert(id);
	//alert("--" + b[0]+"--");
	if( b[0]!=''){
  	if(vote_type=='up'){
  	 target1 = document.getElementById ('xapplaud-' + id);
	if(b[0].trim()=="1"){
	target1.innerHTML = "" + b[0].trim() + " person prayed for this";	
	  	target2 = document.getElementById ('xvotes-' + id);
  	 target2.innerHTML = b[0].trim();
	} else if(b[0].trim()=="0"){
	target1.innerHTML = "Your submission has been recorded";
	} else {
	target1.innerHTML = "" + b[0].trim() + " people prayed for this";
	  	target2 = document.getElementById ('xvotes-' + id);
  	 target2.innerHTML = b[0].trim();
	}

  	 target3 = document.getElementById ('xvote-' + id);
  	 target3.innerHTML = "Thanks"; 
  	 target4 = document.getElementById ('xbox-' + id);
  	 newImage = "url(/images/vote-l.png)";
     target4.style.backgroundImage = newImage; 	 
    } else if (vote_type=='down'){
      target1 = document.getElementById ('xsmite-' + id);
      target1.innerHTML = "(-" + b[0].trim() + ")";
    }  else {
      target1 = document.getElementById ('xflag-' + id);
      target1.innerHTML = " (" + b[0].trim() + ")";
    } 
	}
	return false;
}
var oldComment='';
function comment (id, md5, author, guid, value)
{
if(value!=''){
if (xmlhttp) {
//var comment = value.replace("\n", "<br/>");
var comment = replaceAll(value, "\n", "<br/>");
nocomments = document.getElementById ('nocomments');
nocomments.innerHTML = "";
newcomments = document.getElementById ('newcomments');	newcomments.innerHTML += '<p class="bubble-blue">' +
'' + comment + '' +
'</p>' +
'<div class="applaud">' + author + ' | 1 second ago</div><br />';
url = "/addComment.php";
var mycontent = "id=" + id + "&md5=" + md5 + "&author=" + author + "&guid=" + guid + "&value=" + escape(value) ;
if(oldComment!=comment){
mnmxmlhttp[id] = new myXMLHttpRequest ();
if (mnmxmlhttp) {
mnmxmlhttp[id].open ("POST", url, true);
mnmxmlhttp[id].setRequestHeader ('Content-Type',
'application/x-www-form-urlencoded');
mnmxmlhttp[id].send (mycontent);
errormatch = new RegExp ("^ERROR:");
mnmxmlhttp[id].onreadystatechange = function () {
if (mnmxmlhttp[id].readyState == 4) {
xvotesString[id] = mnmxmlhttp[id].responseText;
if (xvotesString[id].match (errormatch)) {
xvotesString[id] = xvotesString[id].substring (6, xvotesString[id].length);
changemnmvalues (id, value, true);	} else {
if (xvotesString[id].substring (1, 6) == "ERROR") {
} else {
document.getElementById('commentfield').value="";
}	}
}
}
}
}
oldComment=comment;
}
}
}
function replaceAll(txt, replace, with_this) {
  return txt.replace(new RegExp(replace, 'g'),with_this);
}
