function p_up(URL,w,h) 
{
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open('" + URL + "', '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=" + w + ",height=" + h + "');");
}

function doSubmitForum(rep) {
	var reply = document.getElementById('replybox').value;
	if (!reply) return;
			
	// check rep
	if (rep <= -15)
		alert('Your reputation is extremely low. Please try to make quality posts from now on!');

	var form = document.forms['doReply'];
	var action = form.action;

	var boolQuickPost = document.getElementById('enableQuickReply');
	if (!boolQuickPost || boolQuickPost.checked == false) {
		form.submit();
		return;
	}
	
	var queryOffset = action.indexOf('?');
	var urlQuery = action.substr(queryOffset);
	
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) { // no ajax support, submit old fashioned
		form.submit();
		return;
	}
	
	ajaxStatus('Writing your reply...');
	
	var postQuery = 'vibe=rocks';
	var formTags = new Array('input', 'textarea');
	
	for (i = 0; i < formTags.length; i++) {
		var elements = form.getElementsByTagName(formTags[i]);
		for (k = 0; k < elements.length; k++)
			postQuery += '&' + elements[k].name + '=' + encodeURIComponent(elements[k].value);
	}

	var table = document.getElementById('forumPostTable');
	if (!table) return false;

	var url = 'http://www.vibe.to/ajax/forumQuickPost' + urlQuery;
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			ajaxStatus();

			var pageURL = document.URL;
			var poundPos = pageURL.indexOf('#');
			if (poundPos != -1)
				pageURL = pageURL.substr(0, poundPos);

			if (xmlHttp.responseText == 'failed') {
				document.location.href = pageURL + '#replybox';
				document.location.reload();
				return;
			}

			var newRow = table.insertRow(table.rows.length);
			var newCell = newRow.insertCell(0);
			newCell.colSpan = '3';
			newCell.innerHTML = xmlHttp.responseText;

			var replybox = document.getElementById('replybox');
			if (!replybox) return;

			var postID;
			var regmatch = xmlHttp.responseText.match(/\<\!\-\-post\[([0-9]+),[0-9]+\]\-\-\>/);
			if (regmatch)
				postID = regmatch[1];

			replybox.value = '';
			
			document.location.href = pageURL + '#' + postID;
		}
	}
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-Length", postQuery.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(postQuery);	
}
	
function doSubmitRep(userid, action, username)
{
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{
		alert ("Your browser doesn't support this feature, please upgrade :)")
		return
	} 
	var url = 'http://www.vibe.to/ajax/doReputation?userid=' + userid + '&affect=' + action + '&username=' + username + '&rand=' + Math.random();
	xmlHttp.onreadystatechange = sendRep; 
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
	function sendRep()
	{
		if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
		{
			alert(xmlHttp.responseText);
		}
	}
}

function togglePost(id)
{
	var row = document.getElementById('postSibling' + id);
	if (!row) return;
	
	var display = (navigator.userAgent.indexOf('MSIE') != -1) ? 'block' : 'table-row';
	
	if (row.style.display == '' || row.style.display == display)
	{
		row.style.display = 'none';
	}
	else
	{
		row.style.display = display;
	}
}	
	
function saveQuickReplyValue(t)
{
	var cookieName = 'vibe[forumQuickReply]';
	createCookie(cookieName, t.checked, 365);
}

function setQuickReply()
{
	var checkbox = document.getElementById('enableQuickReply');
	if (!checkbox) return;
	
	var cookieName = 'vibe[forumQuickReply]';
			
	if (readCookie(cookieName) == 'true')
		checkbox.checked = true;
	else
		checkbox.checked = false;	
}

function resizeForumImages()
{
	var images = document.getElementsByTagName('img');
	for (i = 0; i < images.length; i++) {
		if (images[i].className == 'forumIMG' && (images[i].width > 700 || images[i].height > 700)) {
			var scale = 700 / Math.max(images[i].width, images[i].height);
			images[i].width = Math.floor(images[i].width * scale);
		}
		else if (images[i].className == 'forumSigIMG' && (images[i].width > 760 || images[i].height > 80)) {
			if (760 / images[i].width < 80 / images[i].height)
				images[i].width = 760;
			else
				images[i].height = 80;
		}
	}
}