function cComment(){
	this.server = new cServer();
	this.infoDiv = document.createElement('div');
//	this.infoDiv.style.position = 'relative';
//	this.infoDiv.style.top = '-120px';
	this.infoDiv.innerHTML = '<center>Sparar kommentaren...</center>';
}

cComment.prototype.showNewComment = function(obj){
	document.getElementById('newComment').style.display='block';
	obj.parentNode.style.display='none';
}

cComment.prototype.hideNewComment = function(obj){
	document.getElementById('showNewComment').style.display='block';
	document.getElementById('newComment').style.display='none';
}

cComment.prototype.onFocus = function(obj){
	if (obj.value == obj.title)
		obj.value = '';
}

cComment.prototype.onBlur = function(obj){
	if (obj.value == '')
		obj.value = obj.title;
}

cComment.prototype.saveNew = function(obj, BandId, Pic){
//	str = '';
//	for (i=0; i < obj.elements.length; i++)
//		str += obj.elements[i].value + '\n';
//	alert(str);

	if (obj.elements[0].value != obj.elements[0].title && obj.elements[1].value != obj.elements[1].title && obj.elements[0].value.trim() != '' && obj.elements[1].value.trim() != ''){
		name = obj.elements[0].value;
		text = obj.elements[1].value;
//		document.getElementById('newComment').style.visibility = 'hidden';
		document.getElementById('newComment').style.display = 'none';
		document.getElementById('newComment').parentNode.appendChild(this.infoDiv);

		//alert(name+'\n'+text+'\n'+BandId+'\n'+Pic+'\n');
		this.server.post('/comments.php?savecomment=Yes', new Array('Namn', 'Comment', 'BandId', 'Pic'), new Array(name, text, BandId, Pic), this.onSaved, this);
	}else{
		alert('Du måste fylla i alla fällt!');
	}
}


cComment.prototype.showReport = function(Id, obj){
	this.currId = Id;
	this.currReportLink = obj;
	document.getElementById('reportComment').style.display = 'block';
}
cComment.prototype.hideReport = function(){
	document.getElementById('reportComment').style.display = 'none';
}

cComment.prototype.report = function(){
//	this.server.get('comment.asp?reportComment='+Id, this.onReported, this);
//	obj = document.getElementById('reportComment').childNodes[0];
	obj = document.getElementById('reasonReportComment');
	if (obj.value != obj.title && obj.value.trim() != '')
	{	
		reason = obj.value;
		this.server.post('/comments.php?reportcomment='+this.currId, new Array('reason'), new Array(reason), this.onReported, this);
	}
	else
		alert('Du måste ange en orsak för anmälan!');
	
}










cComment.prototype.onSaved = function(error, text, obj){

	if (error)
	{
		obj.infoDiv.innerHTML = '<center>Kunde inte spara inlägget!<br></center>';
	}
	else
	{
		//alert(text);
		arr = text.split('|');
		obj.addNew(arr[0], arr[2], arr[1]);
		document.getElementById('newComment').style.display='none';
		obj.infoDiv.style.display = 'none';
	}

}

cComment.prototype.onReported = function(error, text, obj){
	if (error)
	{
		alert('Kunde inte anmäla inlägget!\n('+text+')');
//		obj.infoDiv.innerHTML = '<center>Kunde inte spara inlägget!<br>('+text+')</center>';
	}
	else
	{
		alert('Inlägget är anmält!');
		obj.hideReport();
		obj.currReportLink.parentNode.innerHTML = 'Inlägget är anmält';
	}

}

cComment.prototype.addNew = function(name, text, date){
	table = document.createElement('table');
	table.cellSpacing = 0;
	table.cellPadding = 3;
	table.border = 0;
	table.width = '100%';

	row = table.insertRow(table.rows.length);
	row.className = 'small';
		cell = row.insertCell(row.cells.length);
		cell.innerHTML = name;

		cell = row.insertCell(row.cells.length);
		cell.width = '13%';
		cell.className = 'right';
		cell.innerHTML = '&nbsp;';

		cell = row.insertCell(row.cells.length);
		cell.width = '13%';
		cell.className = 'right';
		cell.innerHTML = date;

	row = table.insertRow(table.rows.length);
		cell = row.insertCell(row.cells.length);
		cell.colSpan=3;
		cell.innerHTML = text;


	tableArr = document.getElementById('comments').getElementsByTagName('table');
	//alert(tableArr[1]);
	if (tableArr.length > 2)
		document.getElementById('comments').insertBefore(table, tableArr[2]);
	else
		document.getElementById('comments').appendChild(table);

	document.getElementById('newComment').style.display='none';
		//alert('Hit3');
}
/*


<table cellspacing=0 cellpadding=3 border=0 width='100%'>
<tr class='small'>
	<td>Namn</td>
	<td width='13%' class='right'><a href='?reportComment=5'>Anmäl inlägget</a></td>
	<td width='13%' class='right'>2008-07-02&nbsp;16:57</td>
</tr>
<tr><td colspan=3>Text</td></tr>
</table>
*/