tempclass="";
tempobj = null;
tempobjbox = null;
temparea = null;
previoustext = "";
comparingtext = "";
var newLine = (navigator.appVersion.lastIndexOf('Win') != -1) ? "\r\n" : "\n";

function createFlash(movie, base)
{
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="730" height="336" id="insomniac" align="">'+
						'<param name="movie" value="'+movie+'">'+
						'<param name="base" value="'+base+'">'+
						'<param name="menu" value="false">'+
						'<param name="quality" value="high">'+
						'<param name="bgcolor" value="#565f66">'+
						'<param name="wmode" value="transparent"> '+
						'<embed src="'+movie+'" base="'+base+'" menu="false" quality="high" bgcolor="565f66" wmode="transparent" width="730" height="336" name="insomniac" align="" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>'+
					'</object>');
}

function makeVisible(){
	table = 'maintable';

	if (document.layers)
		document.layers[table].visibility = 'visible';
	else if (document.all)
		document.all[table].style.visibility = 'visible';
	else if (document.getElementById)
		document.getElementById(table).style.visibility = 'visible';
}
	
	
function autoSize(txtBox) {
	txtBox.rows = getNbRows(txtBox.value, txtBox.cols)+1; 
} 

function getNbRows(text, cols) {  
	textLength = text.length; 
	rowCount = 0; 
	lineCount = 0;
	
	for (i=0;i<textLength;i++) {
		if (text.charAt(i) == "\n" || ++lineCount >= cols){
			lineCount = 0;
			rowCount++;
		}
	}
	
	if (rowCount < 0)
		rowCount = 0;
		
	return rowCount;
} 

function closeAll(){
	if (tempobj != null)
		lock();
	if (tempobjbox != null)
		lockbox();
}

  
function unlockbox(objbox, field){
	closeAll();
	tempobjbox = objbox;

	previoustext = objbox.innerHTML;
	
	objbox.innerHTML = '<textarea id="editbox" cols="115" name="'+field+'" onblur="lockbox()" onkeyup="autoSize(this)" style="overflow: hidden">'+objbox.innerHTML.replace(/<BR>[\n\r]*/gi, "\n")+'</textarea>';

	temparea = document.getElementById("editbox");
	comparingtext = temparea.value;
	autoSize(temparea);
	temparea.focus();
	temparea.select();
}
  
function lockbox(){
	if(comparingtext != temparea.value && confirm("This action will update the edited textarea.")) {
		temparea.form.submit();
	}else{
		tempobjbox.innerHTML = previoustext;
		tempobjbox = null;
		temparea = null;
	}
}
  
function unlock(obj){
	closeAll();
	tempobj = obj;
	tempclass = obj.className;
	previoustext = obj.value;
	comparingtext = obj.value;

	
	obj.readOnly = false;
	obj.className = "edititem";
	obj.focus();
	obj.select();
}

function lock(){
	if(comparingtext != tempobj.value && confirm("This action will update the edited textbox.")) {
		tempobj.form.submit();
	}else{
		tempobj.value = previoustext;
		tempobj.readOnly = true;
		tempobj.className = tempclass;
		tempobj = null;
	}
}

function confirmDelete(){
	return confirm("This action will delete the item.");
}

// CONFIRMATION

function confirm(form)
{
	if(has_confirmed())
	{
		form.btnConfirm.disabled=true;
		return true;
	}
	else
	{
		form.btnConfirm.disabled=false;
		document.getElementById("commentForm").style.display = "none";
		document.getElementById("commentConfirm").style.display = "block";
		return false;
	}
}
function has_confirmed()
{
	return document.getElementById("commentForm").style.display == "none";
}
function back_to_comment()
{
	document.getElementById("commentForm").style.display = "block";
	document.getElementById("commentConfirm").style.display = "none";
}

