function ajaxFunction(queryString, file, div){
	var ajaxRequest;

	try {
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	}
	catch (e) {
		// Internet Explorer Browsers
		try {
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				// Request Failed
				alert("An error occured while processing your request.");
				return false;
			}
		}
	}

	ajaxRequest.onreadystatechange = function() {
		if(ajaxRequest.readyState == 4) {
			var ajaxDisplay = document.getElementById('ajax_' + div);
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
		}
	}

	ajaxRequest.open("GET", file + "?" + queryString, true);
	ajaxRequest.send(null); 
}

var selection_news = new Array();
var selection_rumors = new Array();
var selection_v_news = new Array();
var selection_reviews = new Array();
var selection_previews = new Array();
var selection_soon_on = new Array();
var selection_media = new Array();
var selection_demos = new Array();
var selection_upcoming = new Array();
var selection_past = new Array();
var forums_edit = false;
var posttext = "";
var newpost = false;

function gameAJAX(target, section) {
	var queryString;
	var data = target.innerHTML;

	if((window["selection_" + section].join("")).indexOf("|"+data+"|") >= 0) {
		var g = 0;
		while (g < window["selection_" + section].length) {
			if (window["selection_" + section][g] == "|"+data+"|") {
				window["selection_" + section].splice(g, 1);
			}
			else {
				g++;
			}
		}
	}
	else {
		window["selection_" + section] = window["selection_" + section].concat("|"+data+"|");
	}
	
	for(var i in window["selection_" + section]) {
		if(queryString == null) {
			queryString = "&game" + i + "=" + window["selection_" + section][i].substring(1, (window["selection_" + section][i].length-1));
		}
		else {
			queryString = queryString + "&game" + i + "=" + window["selection_" + section][i].substring(1, (window["selection_" + section][i].length-1));
		}
	}
	
	if(target.style.fontWeight == 'normal' || !target.style.fontWeight) {
		target.style.fontWeight = 'bold';
		target.style.color = '#ff6600';
	}
	else {
		target.style.fontWeight = 'normal';
		target.style.color = '';
	}
	
	if(!queryString) {
		queryString = '';
	}
	
	queryString = "category="+section+""+queryString;
	
	if(section == "media" || section == "demos") {
		var file = 'media.php';
	}
	else if(section == "upcoming" || section == "past") {
		var file = 'matches.php';
	}
	else {
		var file = 'left.php';
	}

	ajaxFunction(queryString, "/ajax/"+file, section);
}

function gameAjax2(target, section) {
	var queryString;
	target2 = document.getElementById(target);
	var data = document.getElementById(target).innerHTML;
	if((window["selection_" + section].join("")).indexOf("|"+data+"|") >= 0) {
		var g = 0;
		while (g < window["selection_" + section].length) {
			if (window["selection_" + section][g] == "|"+data+"|") {
				window["selection_" + section].splice(g, 1);
			}
			else {
				g++;
			}
		}
	}
	else {
		window["selection_" + section] = window["selection_" + section].concat("|"+data+"|");
	}
	
	for(var i in window["selection_" + section]) {
		if(queryString == null) {
			queryString = "&game" + i + "=" + window["selection_" + section][i].substring(1, (window["selection_" + section][i].length-1));
		}
		else {
			queryString = queryString + "&game" + i + "=" + window["selection_" + section][i].substring(1, (window["selection_" + section][i].length-1));
		}
	}
	if(target2.style.fontWeight == 'normal' || !target2.style.fontWeight) {
		target2.style.fontWeight = 'bold';
		target2.style.color = '#ff6600';
	}
	else {
		target2.style.fontWeight = 'normal';
		target2.style.color = '';
	}
	
	if(!queryString) {
		queryString = '';
	}
	
	queryString = "category="+section+""+queryString;
	
	if(section == "media" || section == "demos") {
		var file = 'media.php';
	}
	else if(section == "upcoming" || section == "past") {
		var file = 'matches.php';
	}
	else {
		var file = 'left.php';
	}

	ajaxFunction(queryString, "/ajax/"+file, section);
}

function changeText(post, id, get2, get3, type) {
	if(forums_edit == false) {
		if(type == "admin") {
			document.getElementById("span_" + post).innerHTML = "<a href=\"javascript: closeEdit(" + post + "," + id + "," + get2 + "," + get3 + ",'" + type +"');\">Cancel Edit</a> - <a href=\"javascript: nukePost(" + post + "," + id + ");\">Nuke Post</a> - <a href=\"javascript: delPost(" + post + "," + id + "," + get2 + "," + get3 + ");\">Delete</a> - <a href=\"\">Reply</a>";
		} else {
			document.getElementById("span_" + post).innerHTML = "<a href=\"javascript: closeEdit(" + post + "," + id + "," + get2 + "," + get3 + ",'" + type +"');\">Cancel Edit</a> -  <a href=\"javascript: delPost(" + post + "," + id + "," + get2 + "," + get3 + ");\">Delete</a> - <a href=\"\">Reply</a>";
		}
		posttext = document.getElementById("text_"+ post).innerHTML;
		getPost(id, post, 1, get2, get3, type);
		forums_edit = true;
	}
}

function delTopic(id, cat) {
	var check = confirm("Are you sure you want to delete this topic?");
	if(check) {
		delTopic_Go(id, cat);
	}
}

function delTopic_Go(id, cat) {
		var file = "forums2.php";
		var queryString = "a=deltopic&topic="+id+"&cat="+cat;
		var ajaxRequest8;

		try {
			// Opera 8.0+, Firefox, Safari
			ajaxRequest8 = new XMLHttpRequest();
		}
		catch (e) {
			// Internet Explorer Browsers
			try {
				ajaxRequest8 = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
				try {
					ajaxRequest8 = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e) {
					// Request Failed
					alert("An error occured while processing your request.");
					return false;
				}
			}
		}
	
		ajaxRequest8.onreadystatechange = function() {
			if(ajaxRequest8.readyState == 4) {
				document.getElementById("forum_topic").innerHTML = ajaxRequest8.responseText;
				document.getElementById("addComment").innerHTML = "You can no longer post on this topic.";
			}
		}

		ajaxRequest8.open("GET", "/ajax/"+file + "?" + queryString, true);
		ajaxRequest8.send(null);
}
	
function lock(type, id, cat) {
		var file = "forums2.php";
		var queryString = "a=lock&topic="+id+"&type=" + type;
		var ajaxRequest8;

		try {
			// Opera 8.0+, Firefox, Safari
			ajaxRequest8 = new XMLHttpRequest();
		}
		catch (e) {
			// Internet Explorer Browsers
			try {
				ajaxRequest8 = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
				try {
					ajaxRequest8 = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e) {
					// Request Failed
					alert("An error occured while processing your request.");
					return false;
				}
			}
		}
	
		ajaxRequest8.onreadystatechange = function() {
			if(ajaxRequest8.readyState == 4) {
				alert(ajaxRequest8.responseText);
				window.location("/forums/" + cat + "/" + id);
			}
		}

		ajaxRequest8.open("GET", "/ajax/"+file + "?" + queryString, true);
		ajaxRequest8.send(null);
}

function getPost(id, post, type, get2, get3, type2) {
		var file = "forums2.php";
		var queryString = "a=get&post="+id;
		var ajaxRequest4;

		try {
			// Opera 8.0+, Firefox, Safari
			ajaxRequest4 = new XMLHttpRequest();
		}
		catch (e) {
			// Internet Explorer Browsers
			try {
				ajaxRequest4 = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
				try {
					ajaxRequest4 = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e) {
					// Request Failed
					alert("An error occured while processing your request.");
					return false;
				}
			}
		}
	
		ajaxRequest4.onreadystatechange = function() {
			if(ajaxRequest4.readyState == 4) {
				if(type == 1) {
					document.getElementById("text_" + post).innerHTML = "<form method=\"GET\" action=\"javascript: forum_updatePost(" + post + "," + id + "," + get2 + "," + get3 + ",'" + type2 + "');\"><textarea id=\"edit_field_" + post + "\" cols=\"25\" rows=\"7\">" + ajaxRequest4.responseText + "</textarea><input type=\"submit\" style=\"margin-left: 4px\" value=\"Submit\" /></form>";
				} else if(type == 2) {
					genPosts(id, get2, get3);
				}
			}
		}

		ajaxRequest4.open("GET", "/ajax/"+file + "?" + queryString, true);
		ajaxRequest4.send(null);
}

function closeEdit(post, id, get2, get3, type) {
	document.getElementById("span_" + post).innerHTML = "<a href=\"javascript: changeText(" + post + "," + id + "," + get2 + "," + get3 + ",'" + type + "');\">Edit</a> - <a href=\"javascript: nukePost("+ post + "," + id + ");\">Nuke Post</a> - <a href=\"javascript: delPost("+ post + "," + id + ", " + get2 + ", " + get3 + ");\">Delete</a> - <a href=\"\">Reply</a>";
	getPost(id, post, 2, get2, get3, type );
	forums_edit = false;
}

function nukePost(post, id) {
	forum_updatePost(post, id, "nuked");
}

function delPost(post, id, get2, get3) {
	forum_updatePost(post, id, "delete");
	genPosts(id, get2, get3);
}

function addQuote(post, id2) {
	var quote = document.getElementById("text_" + post).innerHTML;
	document.getElementById("comment_text").innerHTML = document.getElementById("comment_text").innerHTML + "[quote=\"" + id2 + "\"]" + quote + "[/quote]";
}

function forum_updatePost(post, id, type, get2, get3, type2) {
	var file = "forums2.php";
	if(type == "nuked") {
		var content = "Nuked_by_admin";
	} else if(type == "delete") {
		var content = "Delete_by_admin";
	} else {
		var content = strip_tags(document.getElementById("edit_field_" + post).value);
		content = nl2br(content);
	}
	if(content.length <= 8) {
		alert("Sorry, you need more than 8 characters in your content to post.");
		
	} else {
		var queryString = "a=edit&post="+id+"&content="+content;
		document.getElementById("text_"+post).innerHTML = "<span style=\"font-style: italic\">Updating Entry...</span>";
		var ajaxRequest5;

		try {
			// Opera 8.0+, Firefox, Safari
			ajaxRequest5 = new XMLHttpRequest();
		}
		catch (e) {
			// Internet Explorer Browsers
			try {
				ajaxRequest5 = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
				try {
					ajaxRequest5 = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e) {
					// Request Failed
					alert("An error occured while processing your request.");
					return false;
				}
			}
		}
	
		ajaxRequest5.onreadystatechange = function() {
			if(ajaxRequest5.readyState == 4) {
				if(type == "delete") {
					getPost(id, post, 3, get2, get3, type2);
				} else {
					getPost(id, post, 2, get2, get3, type2);
				}
				alert(ajaxRequest5.responseText);
				if(type != "nuked" || type != "delete") {
					closeEdit(post, id, get2, get3, type2);
				}
			}
		}

		ajaxRequest5.open("GET", "/ajax/"+file + "?" + queryString, true);
		ajaxRequest5.send(null);
	}
}

function genPosts(id, get2, get3) {
		var file = "forums2.php";
		var queryString = "a=genPosts&post="+id+"&get2="+get2;
		document.getElementById("forum_topic").innerHTML = "<div class=\"comment\"><center><i>Generating Posts...</i></center></div>";
		var ajaxRequest6;

		try {
			// Opera 8.0+, Firefox, Safari
			ajaxRequest6 = new XMLHttpRequest();
		}
		catch (e) {
			// Internet Explorer Browsers
			try {
				ajaxRequest6 = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
				try {
					ajaxRequest6 = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e) {
					// Request Failed
					alert("An error occured while processing your request.");
					return false;
				}
			}
		}
	
		ajaxRequest6.onreadystatechange = function() {
			if(ajaxRequest6.readyState == 4) {
				document.getElementById("forum_topic").innerHTML = ajaxRequest6.responseText;
			}
		}

		ajaxRequest6.open("GET", "/ajax/"+file + "?" + queryString, true);
		ajaxRequest6.send(null);
	}
	
function genTopics(get2, type) {
	var file = "forums2.php";
	var queryString = "a=genTopics&type="+type+"&cat="+get2;
	document.getElementById("forum_category").innerHTML = "<div class=\"comment\"><center><i>Generating Topics...</i></center></div>";
	var ajaxRequest6;

	try {
		// Opera 8.0+, Firefox, Safari
		ajaxRequest6 = new XMLHttpRequest();
	}
	catch (e) {
		// Internet Explorer Browsers
		try {
			ajaxRequest6 = new ActiveXObject("Msxml2.XMLHTTP");
	
		} catch (e) {
			try {
				ajaxRequest6 = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				// Request Failed
				alert("An error occured while processing your request.");
				return false;
			}
		}
	}
	
	ajaxRequest6.onreadystatechange = function() {
		if(ajaxRequest6.readyState == 4) {
			document.getElementById("forum_category").innerHTML = ajaxRequest6.responseText;
		}
	}

	ajaxRequest6.open("GET", "/ajax/"+file + "?" + queryString, true);
	ajaxRequest6.send(null);
}

function forums(type, post, poster, cat, postnum) {
	if(newpost == false) {
		var file = "forums2.php";
		var content = strip_tags(document.getElementById("comment_text").value);
		content = nl2br(content);
		if(content.length <= 2) {
			alert("Sorry, you need more than 8 characters in your content to post.");
		
		} else {
			newpost = true;
			var queryString = "a=post&post="+post+"&poster="+poster+"&cat="+cat+"&postnum="+postnum+"&content="+content;
			var ajaxRequest2;

			try {
				// Opera 8.0+, Firefox, Safari
				ajaxRequest2 = new XMLHttpRequest();
			}
			catch (e) {
				// Internet Explorer Browsers
				try {
					ajaxRequest2 = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch (e) {
					try {
						ajaxRequest2 = new ActiveXObject("Microsoft.XMLHTTP");
					}
					catch (e) {
						// Request Failed
						alert("An error occured while processing your request.");
						return false;
					}
				}
			}
	
			ajaxRequest2.onreadystatechange = function() {
				if(ajaxRequest2.readyState == 4) {
					var ajaxDisplay = document.getElementById("addComment");
					ajaxDisplay.innerHTML = ajaxRequest2.responseText;
				}
			}

			ajaxRequest2.open("GET", "/ajax/"+file + "?" + queryString, true);
			ajaxRequest2.send(null);
		}
	}
}

function forums_addTopic(cat, uid) {
	var file = "forums2.php";
	var topic = document.getElementById("name").value;
	var content = strip_tags(document.getElementById("comment_text").value);
	content = nl2br(content);
	if(content.length <= 2 || topic.length <= 2) {
		alert("Sorry, you need more than 8 characters in your content or topic to post.");
	} else if(topic.length > 40) {
		alert("Sorry, your topic title is too long.  Please shorten it.");
		
	} else {
		var queryString = "poster="+uid+"&cat="+cat+"&topic="+topic+"&content="+content;
		var ajaxRequest3;

		try {
			// Opera 8.0+, Firefox, Safari
			ajaxRequest3 = new XMLHttpRequest();
		}
		catch (e) {
			// Internet Explorer Browsers
			try {
				ajaxRequest3 = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
				try {
					ajaxRequest3 = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e) {
					// Request Failed
					alert("An error occured while processing your request.");
					return false;
				}
			}
		}
	
		ajaxRequest3.onreadystatechange = function() {
			if(ajaxRequest3.readyState == 4) {
				var ajaxDisplay = document.getElementById("addTopic");
				ajaxDisplay.innerHTML = ajaxRequest3.responseText;
			}
		}

		ajaxRequest3.open("GET", "/ajax/"+file + "?" + queryString, true);
		ajaxRequest3.send(null);
	}
}

function pollAjax() {
	var checked;
	
	for(var v in document.getElementById("poll_form").poll_vote) {
		if(eval(document.getElementById("poll_form").poll_vote[v].checked) == true) {
			checked = eval(document.getElementById("poll_form").poll_vote[v].value);
		}
	}
	
	//alert(checked);

	if(checked == "undefined") {
		alert("Please select an option to vote for.");
		return false;
	}
	else {
		ajaxFunction('option='+checked, '/ajax/poll.php', 'poll');
	}
}

var selection_headlines = new Array("General News");

function newsAJAX(target, div, offset, test, number) {
	var queryString;
	target2 = target;
	/*if(test == true) {
		target2 = document.getElementById(target);
	} else {
		target2 = target;
	}*/
	
	if((window["selection_headlines"].join("")).indexOf(target2.innerHTML) >= 0) {
		var g = 0;
		while (g < window["selection_headlines"].length) {
			if (window["selection_headlines"][g] == target2.innerHTML) {
				window["selection_headlines"].splice(g, 1);
				target2.style.backgroundPosition = offset + 'px 0px';
				target2.onmouseover = function() {
					target2.style.backgroundPosition = offset + 'px -47px';
				}
				target2.onmouseout = function() {
					target2.style.backgroundPosition = offset + 'px 0px';
				}
			}
			else {
				g++;
			}
		}
	}
	else {
		window["selection_headlines"] = window["selection_headlines"].concat(target2.innerHTML);
		target2.style.backgroundPosition = offset + 'px -47px';
		target2.onmouseover = function() {
			target2.style.backgroundPosition = offset + 'px 0px';
		}
		target2.onmouseout = function() {
			target2.style.backgroundPosition = offset + 'px -47px';
		}
	}
	
	for(var i in window["selection_headlines"]) {
		if(queryString == null) {
			queryString = "category" + i + "=" + window["selection_headlines"][i];
		}
		else {
			queryString = queryString + "&category" + i + "=" + window["selection_headlines"][i];
		}
	}
	
	if(!queryString) {
		queryString = '';
	}
	/*if(!test) {
		var file = "checkLeft.php";
		var ajaxRequest29;
		var queryString = "a=headlines&headline_num=" + number;

		try {
			// Opera 8.0+, Firefox, Safari
			ajaxRequest29 = new XMLHttpRequest();
		}
		catch (e) {
			// Internet Explorer Browsers
			try {
				ajaxRequest29 = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
				try {
					ajaxRequest29 = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e) {
					// Request Failed
					alert("An error occured while processing your request.");
					return false;
				}
			}
		}
		ajaxRequest29.onreadystatechange = function() {
			if(ajaxRequest29.readyState == 4) {
				// alert(ajaxRequest29.responseText);
			}
		}
	
		ajaxRequest29.open("GET", "/ajax/"+file + "?" + queryString, true);
		ajaxRequest29.send(null);
	}*/
	ajaxFunction(queryString, "/ajax/entries.php", "headlines");
}

function friend(user_id, user_page) {
	if(typeof(eval(user_id)) == "number") {
		ajaxFunction('friend='+user_id+'&user_page='+user_page, "/ajax/friend.php", "profile_friends");
	}
	else {
		alert("No friend selected.");
	}
}

function fav(table, id) {
	if(typeof(eval(id)) == "number") {
		ajaxFunction('table='+table+'&id='+id, "/ajax/favorite.php", "fav");
	}
	else {
		alert("No ID provided.");
	}
}

function gallerySave(id) {
	var queryString = "id="+id+"&gid="+document.getElementById("gid").value;
	ajaxFunction(queryString, "/ajax/gallery.php", "gallery_"+id);
}

function addSub(type, id) {
	var typecheck;
	if(type == "ForumTopic") {
		typecheck = "topic on the forum";
	} else if(type == "Article") {
		typecheck = "article";
	} else if(type == "Demo" || type == "Video") {
		typecheck = "media file";
	}
	var check = confirm("Are you sure you want to subscribe to this " + typecheck + "?");
	if(check) {
		var file = "addSub.php";
		var queryString = "a=addSub&type="+type+"&id="+id;
		var ajaxRequest22;

		try {
			// Opera 8.0+, Firefox, Safari
			ajaxRequest22 = new XMLHttpRequest();
		}
		catch (e) {
			// Internet Explorer Browsers
			try {
				ajaxRequest22 = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
				try {
					ajaxRequest22 = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e) {
					// Request Failed
					alert("An error occured while processing your request.");
					return false;
				}
			}
		}
	
		ajaxRequest22.onreadystatechange = function() {
			if(ajaxRequest22.readyState == 4) {
				alert(ajaxRequest22.responseText + " Look at your subscriptions management, or at content listings to view this subscription.");		
			}
		}
	
		ajaxRequest22.open("GET", "/ajax/"+file + "?" + queryString, true);
		ajaxRequest22.send(null);
	}
}

function delSub(id) {
	var check = confirm("Are you sure you want to delete this subscription?");
	if(check) {
		var file = "addSub.php";
		var queryString = "a=delSub&id="+id;
		var ajaxRequest23;

		try {
			// Opera 8.0+, Firefox, Safari
			ajaxRequest23 = new XMLHttpRequest();
		}
		catch (e) {
			// Internet Explorer Browsers
			try {
				ajaxRequest23 = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
				try {
					ajaxRequest23 = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e) {
					// Request Failed
					alert("An error occured while processing your request.");
					return false;
				}
			}
		}
	
		ajaxRequest23.onreadystatechange = function() {
			if(ajaxRequest23.readyState == 4) {
				refreshSubs();
				alert(ajaxRequest23.responseText);
			}
		}
	
		ajaxRequest23.open("GET", "/ajax/"+file + "?" + queryString, true);
		ajaxRequest23.send(null);
	}
}

function refreshSubs() {
	var file = "addSub.php";
	var queryString = "a=getSubs";
	var ajaxRequest23;
	document.getElementById("subslist").innerHTML = "<tr>\n<td colspan=\"3\"><em>Refreshing Subscriptions...</em></td>\n</tr>\n";

	try {
		// Opera 8.0+, Firefox, Safari
		ajaxRequest23 = new XMLHttpRequest();
	}
	catch (e) {
		// Internet Explorer Browsers
		try {
			ajaxRequest23 = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				ajaxRequest23 = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				// Request Failed
				alert("An error occured while processing your request.");
				return false;
			}
		}
	}
	
	ajaxRequest23.onreadystatechange = function() {
		if(ajaxRequest23.readyState == 4) {
			document.getElementById("subslist").innerHTML = ajaxRequest23.responseText;		
		}
	}
	
	ajaxRequest23.open("GET", "/ajax/"+file + "?" + queryString, true);
	ajaxRequest23.send(null);
}

function nl2br (str, is_xhtml) {
 
    breakTag = '<br />';
    if (typeof is_xhtml != 'undefined' && !is_xhtml) {
        breakTag = '<br />';
    }
 
    return (str + '').replace(/([^>]?)\n/g, '$1'+ breakTag +'\n');
}

function strip_tags(str, allowed_tags) { 
    var key = '', tag = '', allowed = false;
    var matches = allowed_array = [];
 
    var replacer = function(search, replace, str) {
        return str.split(search).join(replace);
    };
 
    // Build allowes tags associative array
    if (allowed_tags) {
        allowed_array = allowed_tags.match(/([a-zA-Z]+)/gi);
    }
  
    str += '';
 
    // Match tags
    matches = str.match(/(<\/?[^>]+>)/gi);
 
    // Go through all HTML tags
    for (key in matches) {
        if (isNaN(key)) {
            // IE7 Hack
            continue;
        }
 
        // Save HTML tag
        html = matches[key].toString();
 
        // Is tag not in allowed list? Remove from str!
        allowed = false;
 
        // Go through all allowed tags
        for (k in allowed_array) {
            // Init
            allowed_tag = allowed_array[k];
            i = -1;
 
            if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+'>');}
            if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+' ');}
            if (i != 0) { i = html.toLowerCase().indexOf('</'+allowed_tag)   ;}
 
            // Determine
            if (i == 0) {
                allowed = true;
                break;
            }
        }
 
        if (!allowed) {
            str = replacer(html, "", str); // Custom replace. No regexing
        }
    }
 
    return str;
}

function insertSelText(type) {
	start = document.getElementById("comment_text").selectionStart;
	end = document.getElementById("comment_text").selectionEnd;
	index = (document.getElementById("comment_text").value).substring(start, end);
	if(index.length == 0) {
		index = "";
	}
	if(type == "bold") {
		one = "[b]";
		two = "[/b]";
	} else if(type == "italic") {
		one = "[i]";
		two = "[/i]";
	} else if(type == "underline") {
		one = "[u]";
		two = "[/u]";
	} else if(type == "link" ){
		one = '[a=""]';
		two = '[/a]';
	}
	text = document.getElementById("comment_text").value;
	text = text.substring(0,start) + one + text.substring(start, end) + two + text.substring(end, text.length);
	document.getElementById("comment_text").value = text;
}

function checkLeft() {
	var file = "checkLeft.php";
	var ajaxRequest55;
	var queryString = "";

	try {
		// Opera 8.0+, Firefox, Safari
		ajaxRequest55 = new XMLHttpRequest();
	}
	catch (e) {
		// Internet Explorer Browsers
		try {
			ajaxRequest5 = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				ajaxRequest55 = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				// Request Failed
				alert("An error occured while processing your request.");
				return false;
			}
		}
	}
	
	ajaxRequest55.onreadystatechange = function() {
		if(ajaxRequest55.readyState == 4) {
			var myArray = ajaxRequest55.responseText.split(";");
			for(i = 0; i<=myArray.length; i++) {
				if(myArray[i]) {
					eval(myArray[i]);
				}
			}	
			
		}
	}
	
	ajaxRequest55.open("GET", "/ajax/"+file + "?" + queryString, true);
	ajaxRequest55.send(null);
}
		
