// JavaScript Document

/** ev_comment_line script **/
var ev_comment_line_xmlHttp;
var ev_comment_line_tableId_current;
var ev_comment_line_currentRowId = -1;
function ev_comment_line_deleteComment(site_url, app_type, main_id, srcCtrl, line_comment_id, tableId, tableRowId, login){
	if(!confirm("Do you want to delete the comment?")){return;}
	if(ev_comment_line_currentRowId > -1){alert("Please try again."); return;}
	var pwd, pwd_val="";
	if(!login){
		pwd = document.getElementById("cmtLineItemPwd_" + line_comment_id);
		if(pwd.value.trim() == ""){
			alert("Please input password.");
			pwd.focus();
			return;
		}
		pwd_val = pwd.value.trim();
	}
	ev_comment_line_xmlHttp=GetXmlHttpObject();
	if (ev_comment_line_xmlHttp==null)
 	{
 		alert ("Browser does not support HTTP Request");
 		return; 
 	}
	ev_comment_line_currentRowId = document.getElementById(tableRowId).id; //srcCtrl.parentElement.parentElement.rowIndex;
	ev_comment_line_tableId_current = tableId;
	var url=site_url+"ev_action.php";
	url=url+"?mode=delete_line_comment&app_type="+app_type+"&main_id="+main_id+"&line_comment_id=" + line_comment_id+ "&pwd="+pwd_val;
	ev_comment_line_xmlHttp.onreadystatechange=ev_comment_line_commentDeleted ;
	ev_comment_line_xmlHttp.open("GET",url,true);
	ev_comment_line_xmlHttp.send(null);
}
function ev_comment_line_commentDeleted(){
	if (ev_comment_line_xmlHttp.readyState==4 || ev_comment_line_xmlHttp.readyState=="complete")
 	{ 
		var txt = ev_comment_line_xmlHttp.responseText;		
		if(txt.length < 1) return;
		if(txt.substring(0,1)=="@"){
			alert(txt.substring(1));
			return;
		}
		if(txt == "true"){
			var tbl = document.getElementById(ev_comment_line_tableId_current);
			var tblRow = document.getElementById(ev_comment_line_currentRowId);
			tbl.deleteRow(tblRow.rowIndex);			
			tblRow.style.display = "none";
			ev_comment_line_currentRowId = -1;
		}
 	}
}

var ev_comment_line_newRowId;
var ev_comment_line_current_item_id;
function ev_comment_line_writeComment(site_url, app_type, main_id, ev_id, itemId, tableId, txtId, login){
	var txt_val, name_val="", pwd_val="";
	var txt= document.getElementById(txtId);
	if(txt.value.trim() == ""){
		alert("Please input comment!");
		txt.focus();
		return false;
	}
	txt_val =txt.value.trim();
	var name, pwd;
	if(login != "true"){
		name = document.getElementById("cmt_line_Name_" + itemId);
		pwd = document.getElementById("cmt_line_Pwd_" + itemId);
		if(name.value.trim() == ""){
			alert("Please input name.");
			name.focus();
			return;
		}
		if(pwd.value.trim() == ""){
			alert("Please input password.");
			pwd.focus();
			return;
		}
		name_val = name.value.trim();
		pwd_val = pwd.value.trim();
	}
	ev_comment_line_xmlHttp=GetXmlHttpObject();
	if (ev_comment_line_xmlHttp==null)
 	{
 		alert ("Browser does not support HTTP Request");
 		return false;
 	}
	ev_comment_line_current_item_id = itemId;
	ev_comment_line_tableId_current = tableId;
	ev_comment_line_newRowId = GetUID();
	var url=site_url+"ev_action.php";
	url=url+"?mode=write_line_comment&app_type="+app_type+"&main_id="+main_id+"&event="+ev_id+"&ev_item_id="+itemId + "&row_id="+ev_comment_line_newRowId+"&cmtName="+name_val+"&cmtPwd="+pwd_val+"&content=" + encodeURIComponent(txt_val);
	ev_comment_line_xmlHttp.onreadystatechange=ev_comment_line_commentWritten ;
	ev_comment_line_xmlHttp.open("GET",url,true);
	txt.value = "";
	ev_comment_line_xmlHttp.send(null);
}
function ev_comment_line_commentWritten(){
	if (ev_comment_line_xmlHttp.readyState==4 || ev_comment_line_xmlHttp.readyState=="complete")
 	{
		var txt = ev_comment_line_xmlHttp.responseText;
		if(txt.length < 1) return;
		if(txt.substring(0,1)=="@"){
			alert(txt.substring(1));
			return;
		}
		var tbl = document.getElementById(ev_comment_line_tableId_current);
		var row = tbl.insertRow(0);
		row.id = ev_comment_line_newRowId;
		var cell = row.insertCell(0);
		cell.innerHTML = txt;
		var cmtName = document.getElementById("cmt_line_Name_" + ev_comment_line_current_item_id);
		var cmtPwd = document.getElementById("cmt_line_Pwd_" + ev_comment_line_current_item_id);
		if(cmtName){
			cmtName.value = "";
			cmtPwd.value = "";
		}
 	}
}

function ev_delete_item(site_url, app_type, main_id, itemId, return_url){
	if(!confirm("Do you want to delete the post?")){return;}
	var url=site_url+"ev_action.php";
	url=url+"?mode=delete_item&app_type="+app_type+"&main_id="+main_id+"&ev_item_id="+itemId+"&url="+encodeURIComponent(return_url);
	window.location.href = url;
}

