/*###########################################################################
jazz file de pagina de detalle
###########################################################################*/
var detail_Class	= function () {


	var URL	= document.URL;

	var images_location	= (URL.indexOf('/RAD/') == -1)?"..":"../..";




/*===========================================================
onload
===========================================================*/
this.tail_onload	= function (id) {

	var first	= 'ok';

	detail_Class.tail_write_form(id);
	detail_Class.tail_join(id, first);
}



/*===========================================================
boton de escribir comentario.

tail_join_func	-> "formato"
===========================================================*/
var Process_form	= {

	tail_join_func	: function () {

		var tail_list	= document.getElementById('tail_list');
		var body_tag	= REQ.responseXML.getElementsByTagName('body_tag')[0];
		var items		= body_tag.getElementsByTagName('items');
		//var query		= REQ.responseXML.getElementsByTagName('query')[0].firstChild.nodeValue;
		var mode		= REQ.responseXML.getElementsByTagName('mode')[0].firstChild.nodeValue;
		var result		= REQ.responseXML.getElementsByTagName('result')[0].firstChild.nodeValue;
		var manage		= REQ.responseXML.getElementsByTagName('manage')[0].firstChild.nodeValue;
		var price_re_write	= REQ.responseXML.getElementsByTagName('price_re_write')[0].firstChild.nodeValue;

		if(document.forms['tail2'])
			document.tail2.reset();

		switch(mode) {

			case "tail_join_func":
				alert('Registrado.');
				break;

			case "tail_delete_func":

				if(result == 'ok')
					alert('Eliminado.');
				else
					alert('El password no coincide.');
				break;

			case "tail_update_func":
				alert('Editado con éxito.');
				break;
		}




		outhtml	= "<table width='100%' border='0' cellspacing='0' cellpadding='0'>";
		if(items.length) {

			for(var i=0; i<items.length; i++){//
				var item = items[i];

				var seq			= item.getAttribute("seq");//numero de articulo
				var name		= item.getElementsByTagName("name")[0].firstChild.nodeValue;//nombre
				var rdate		= item.getElementsByTagName("rdate")[0].firstChild.nodeValue;//fecha de registro
				var content		= item.getElementsByTagName("content")[0].firstChild.nodeValue;//contenido
				var id			= item.getElementsByTagName("id")[0].firstChild.nodeValue;//
				var login_id	= item.getElementsByTagName("login_id")[0].firstChild.nodeValue;//

				outhtml	+= "<tr>";
				outhtml	+= "<td height='27'>Autor: "+name+" </td>";
				outhtml	+= "<td align='right'>"+rdate;


				
				var view_form	= (manage=='ok' || id && (login_id == id))?"detail_Class.tail_delete('delete','"+seq+"','"+i+"');":"detail_Class.passwd_form('delete','"+seq+"','"+i+"');";


				//se muestra el boton de eliminar si es su articulo o articulo de invitado.
				if(manage=='ok' || (login_id==id) || id=='No hay')
					outhtml	+= "&nbsp;&nbsp;&nbsp;<a href=\"javascript:"+view_form+"\"><img src='"+images_location+"/images/b_sdel.gif' border='0' align='absbottom'></a>";
				outhtml	+= "<div id='tool_form[]' style=\"position: absolute; margin-left:-180px; margin-top:22px; z-index: 1; width: 180px; border: 0 black solid; display: none\"></div></td>";
				outhtml	+= "</tr>";
				outhtml	+= "<tr>";
				outhtml	+= "<td height='1' colspan='2' bgcolor='e4e4e4'></td>";
				outhtml	+= "</tr>";
				outhtml	+= "<tr>";
				outhtml	+= "<td colspan='2' bgcolor='f7f7f7'>";
				outhtml	+= "<table width='100%' border='0' cellspacing='0' cellpadding='10'>";
				outhtml	+= "<tr>";
				outhtml	+= "<td>"+content+"</td>";
				outhtml	+= "</tr>";
				outhtml	+= "</table>";
				outhtml	+= "</td>";
				outhtml	+= "</tr>";
				outhtml	+= "<tr>";
				outhtml	+= "<td height='10'></td>";
				outhtml	+= "</tr>";
			}
		}
		outhtml	+= "</table>";


		/*-----------------------------------------------------
		si no tiene autorizacion para leer comentario, se devuelve valor de no, y no se opera  tail_list.innerHTML	= outhtml; 
		-----------------------------------------------------*/
		if(price_re_write == 'yes'){
		//	tail_list.innerHTML	= outhtml;
		}
	}
};



	/*================================================================
	tool box.
	formato de ingresar password.
	================================================================*/
	this.passwd_form		= function (type, no, i_val) {

		var tool_form	= document.getElementsByName('tool_form[]');
		document.getElementById('type').value	= type;
		document.getElementById('no').value		= no;

		tool_form[i_val].style.display	= (tool_form[i_val].style.display=='')?"none":"";

		outhtml	= "<table width='100%' border='0' cellspacing='1' cellpadding='2' bgcolor=d4d4d4>";
		outhtml	+= "<tr bgcolor=ffffff align=center>";
		outhtml	+= "<td bgcolor=f4f4f4 class=num>Password</td>";
		outhtml	+= "<td><input type='password' name='passwd_tool' size='10' class=simpleform></td>";
		outhtml	+= "<td><input type='image' src='"+images_location+"/images/b_sdel.gif'></td>";
		outhtml	+= "</tr>";
		outhtml	+= "</table>";

		tool_form[i_val].innerHTML	= outhtml;
	}



	/*================================================================
	tool box.
	formato de escribir
	================================================================*/
	this.tail_write_form	= function (id) {

		var tail_write	= document.getElementById('tail_write');

		outhtml	= "<table width='100%' border='0' cellspacing='0' cellpadding='0'>";
		outhtml	+= "<tr><td width='1'></td>";
		outhtml	+= "<td>";
		outhtml	+= "	<table width='100%' border='0' cellspacing='0' cellpadding='10'>";
		outhtml	+= "	<tr><td>";
		outhtml	+= "		<table width='100%' border='0' cellspacing='0' cellpadding='0'>";
		outhtml	+= "		<tr>";
		if(!id)	outhtml	+= "<td class='num'>Nombre</td><td><input type='text' name='name' id='name'size='12' class='simpleform'></td><td class='num'>Password</td><td><input type='password' name='passwd' id='dpasswd' size='12' class='simpleform'></td>";
		outhtml	+= "		<td width='50'><input type='image' src='"+images_location+"/images/car_detail_ment05.gif' onfocus='blur()'></td><td width='320'></td></tr>";
		outhtml	+= "		<tr><td height='5'></td></tr>";
		outhtml	+= "		<tr><td colspan='6'><textarea name='content' id='content' style='width:100%; height:70px'></textarea></td></tr>";
		outhtml	+= "		</table>";
		outhtml	+= "	</td>";
		outhtml	+= "	</tr>";
		outhtml	+= "	</table>";
		outhtml	+= "</td>";
		outhtml	+= "<td width='1'></td>";
		outhtml	+= "</tr>";
		outhtml	+= "<tr>";
		outhtml	+= "<td colspan='3'></td>";
		outhtml	+= "</tr>";
		outhtml	+= "</table>";

		if(document.getElementById('tail_write'))
			tail_write.innerHTML	= outhtml;
	}













/*===========================================================
clic boton de escribir comentario.
===========================================================*/
	this.tail_join		= function (id, first) {

		var name		= (document.getElementById('name'))?document.getElementById('name'):"";
		var dpasswd		= (document.getElementById('dpasswd'))?document.getElementById('dpasswd'):"";
		var content		= (document.getElementById('content'))?document.getElementById('content'):"";
		var code_tail	= (document.getElementById('code_tail'))?document.getElementById('code_tail'):"";
		var pno			= (document.getElementById('pno'))?document.getElementById('pno'):"";
		var mode	= (document.getElementById('content') && content.value)?"tail_join_func":"tail_list_func";


		if(!id && !first) {

			if(!name.value) {

				alert('Ingresa el nombre.');
				name.focus();
				return false;
			}

			if(!dpasswd.value) {

				alert('Ingresa el password.');
				dpasswd.focus();
				return false;
			}
		}

		if(!first) {

			if(!content.value) {

				alert('Ingresa contenido.');
				content.focus();
				return false;
			}
		}

		var obj	= new detail_Class.tail_join_obj(name, dpasswd, content, code_tail, pno, mode);
		obj.tail_write_Ajax_Engine();
	}



/*===========================================================
juntar valor de escribir comentario
===========================================================*/
	this.tail_join_obj	= function (name, passwd, content, code_tail, pno, mode) {

		if(name)	this.name		= name.value;
		if(passwd)	this.passwd		= passwd.value;
		this.content	= content.value;
		this.code_tail	= code_tail.value;
		this.pno		= pno.value;
		this.mode		= mode;
	}









/*===========================================================
donde das clic a eliminar comentario
===========================================================*/
	this.tail_delete	= function (type, seq, i) {

		var passwd_tool	= (document.getElementById('passwd_tool'))?document.getElementById('passwd_tool').value:"";
		var type		= (type)?type:document.getElementById('type').value;
		var pno			= document.getElementById('pno').value;
		var code_tail	= document.getElementById('code_tail').value;
		var no			= (seq)?seq:document.getElementById('no').value;
		var mode		= (type=='delete')?"tail_delete_func":"tail_update_func";


		var obj	= new detail_Class.tail_delete_obj(no, pno, code_tail, type, passwd_tool, mode);
		obj.tail_delete_Ajax_Engine();
	}

/*===========================================================
lugar donde guarda valor de eliminar comentario
===========================================================*/
	this.tail_delete_obj	= function (no, pno, code_tail, type, passwd_tool, mode) {

		this.no				= no;
		this.pno			= pno;
		this.code_tail		= code_tail;
		this.type			= type;
		this.passwd_tool	= passwd_tool;
		this.mode			= mode;
	}





/*===========================================================
funcion que se opera al dar clic al boton de escribir comentario.
===========================================================*/
	this.tail_join_obj.prototype.tail_write_Ajax_Engine	= function () {

		REQ	= xmlhttprequest_class.newXMLHttpRequest();
		var handle	= detail_Class.tail_Process;
		REQ.onreadystatechange	= handle;
		REQ.open("POST", images_location+"/Ajax_php/detail_Class.php", true);
		REQ.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		REQ.send("mode="+this.mode+"&name="+encodeURIComponent(this.name)+"&passwd="+encodeURIComponent(this.passwd)+"&content="+encodeURIComponent(this.content)+"&code_tail="+encodeURIComponent(this.code_tail)+"&pno="+this.pno);
	}



/*===========================================================
Funcion que se opera al eliminar comentario
===========================================================*/
	this.tail_delete_obj.prototype.tail_delete_Ajax_Engine	= function () {

		REQ	= xmlhttprequest_class.newXMLHttpRequest();
		var handle	= detail_Class.tail_Process;
		REQ.onreadystatechange	= handle;
		REQ.open("POST", images_location+"/Ajax_php/detail_Class.php", true);
		REQ.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		REQ.send("mode="+this.mode+"&code_tail="+this.code_tail+"&no="+this.no+"&pno="+this.pno+"&type="+this.type+"&passwd_tool="+this.passwd_tool);
	}



/*===========================================================
valor resultado despues de escribir comentario.
===========================================================*/
	this.tail_Process	= function () {

		if(REQ.readyState==4) {

			if(REQ.status==200) {

				Process_form.tail_join_func();
			}
		}
	}




	this.tail_update	= function () {
	}
}

