var comment = new Object();comment = {	id:null,	idArea:null,	idItem:null,	idDivNew:'div_comment_new',	idDivForm:'div_comment_form',	idDivList:'div_comment_list',	idDivMore:'div_comment_more',	minChar: 3,	maxChar:140,//-1 to unlimit	start: function(idArea,idItem){		if (idArea){			comment.setIdArea(idArea);		}		if (idItem){			comment.setIdItem(idItem);		}		comment.add.setStatus(-1);	},	setId: function(n){		comment.id = n;	},	getId: function(){		return comment.id;	},	setIdArea: function(n){		comment.idArea = n;	},	getIdArea: function(){		return comment.idArea;	},	setIdItem: function(n){		comment.idItem = n;	},	getIdItem: function(){		return comment.idItem;	},	setMinChar: function (n){		comment.minChar = n;	},	getMinChar: function(){		return comment.minChar;	},	setMaxChar: function(n){		comment.maxChar = n;	},	getMaxChar: function(){		return comment.maxChar;	},	setIdDivNew: function(s){		comment.idDivNew = s;	},	getIdDivNew: function(){		return comment.idDivNew;	},	setIdDivForm: function(s){		comment.idDivForm = s;	},	getIdDivForm: function(){		return comment.idDivForm;	},	setIdDivList: function(s){		comment.idDivList = s;	},	getIdDivList: function(){		return comment.idDivList;	},	setIdDivMore: function(s){		comment.idDivMore = s;	},	getIdDivMore: function(){		return comment.idDivMore;	},	form: {		obj: null,		setObj: function(s){			var s1 = document.forms[s] ? document.forms[s] : s;			if (s1){				comment.form.obj = s1;			}		},		getObj: function(){			return comment.form.obj;		},		draw: function(){			var s = '';			s+='<form id="form_comment_'+comment.getIdArea()+'_'+comment.getIdItem()+'" style="margin-top:3px;margin-bottom:3px">';			s+='<input type="text" name="content" style="width:300px;height:18px;border:1px solid lightgrey" class="comment_off" value="escreva um comentário aqui" '+(comment.getMaxChar()>-1 ? 'maxlength="'+comment.getMaxChar()+'"': '')+' />';			s+='<input type="hidden" name="id_area" value="'+comment.getIdArea()+'" />';			s+='<input type="hidden" name="id_item" value="'+comment.getIdItem()+'" />';			s+='&nbsp;&nbsp;&nbsp;';			s+='<input type="submit" value="postar" />';			s+='</form>';			s+='<style>';			s+='.comment_off{color:#999999;font-style:italic}';			s+='.comment_on{color:#000000;font-style:none}';			s+='</style>';			global.div.Write(comment.getIdDivForm()+'_'+comment.getIdArea()+'_'+comment.getIdItem(),s);			comment.form.setObj('form_comment_'+comment.getIdArea()+'_'+comment.getIdItem());			comment.form.enableEvent();		},		enableEvent: function(){			var f = comment.form.getObj();			f.onsubmit = function(){				//alert(f.id);				var s = f.id;				var d = s.split('_');				comment.start(d[2],d[3]);				comment.form.setObj('form_comment_'+comment.getIdArea()+'_'+comment.getIdItem());				comment.add.Do();				return false;			}			f.content.value = 'escreva um comentário aqui';			f.content.onfocus = function(){				if (f.content.value=='escreva um comentário aqui'){					f.content.value = '';				}				f.content.className = 'comment_on';			}			f.content.onblur = function(){				if (f.content.value.length<1){					f.content.value = 'escreva um comentário aqui';					f.content.className = 'comment_off';				}				if (f.content.value == 'escreva um comentário aqui'){					f.content.className = 'comment_off';				}			}		}	},	isValid: function(){		var f = comment.form.getObj();		//envio em progresso?		if (comment.add.getStatus()>-1){			return false;		}		if (!f){			gLoader.show('Objeto do formulário não encontrado','info',7);			return false;;		}		if (!user.isLogged()){			gLoader.show('Usuário não logado','info',7);			return false;		}		if (f.content.value=='escreva um comentário aqui'){			gLoader.show('Campo de comentário está vazio','info',7);			return false;		}		if (f.content.value.length<comment.getMinChar()){			gLoader.show('O comentário é muito pequeno','info',7);			return false;		}		if (f.content.value.length>comment.getMaxChar()){			gLoader.show('O comentário é muito grande','info',7);			return false;		}		return true;	},	getBuild: function(id,content,timeRFC,avatarUrl,avatarWidth,avatarHeight,name,firstName,lastName,url,userId){		var s = '';		var title = '';		if (firstName.length>0){			title+=firstName;			if (lastName.length>0){				title+=' '+lastName;			}		}else{			title = name;		}		s+='<div class="comment" id="div_comment_'+id+'">';		s+='<div class="wrap">';		s+='<div class="left">';		s+='<a href="'+url+'">';		s+='<img src="'+avatarUrl+'" width="'+Math.round(avatarWidth/2)+'" height="'+Math.round(avatarHeight/2)+'" alt="'+title+'" title="'+title+'" />';		s+='</a>';		s+='</div>';//left		s+='<div class="right">';		s+='<div class="right_top">';		s+='<div class="title">';		s+='<a href="'+url+'">'+title+'</a>';		s+='</div>';//title		s+='<div class="time" id="div_comment_time_'+id+'"></div><script language="javascript" type="text/javascript">new gDate("'+timeRFC+'","div_comment_time_'+id+'","shortLeft");</script>';		s+='<script language="javascript" type="text/javascript">if (userTo.isMe() || user.getId()=='+userId+'){global.div.WriteAdd("div_comment_time_'+id+'",\'<a href="javascript:void(0)" onclick="comment.remove.Do('+id+')" title="Remover"><img src="http://club.gamevicio.com.br/files/images/icons/trash.png" alt="Remover" style="border:none;padding-left:3px;padding-right:3px" /></a>\')};</script>';		s+='</div>';//right_top		s+='<div class="right_center">'+content+'</div>';		s+='</div>';//right		s+='</div>';//wrap		s+='</div>';//comment		return s;	}}comment.add = {	ajax: null,	status:-1,	setStatus: function(n){		comment.add.status = n;	},	getStatus: function(){		return comment.add.status;	},	Do: function(){		//validar		if (!comment.isValid()){			return;		}		var ajax = gAjax('post',global.RelativeRoot() + 'misc/ajax/main.php?mode=comment_add');		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");		ajax.setVars(global.form.CreateQuery(comment.form.getObj()));		ajax.addEvent(1,'gLoader.show("Enviando comentário","progress")');		var f = comment.form.getObj();		ajax.addEvent(4,'comment.add.parseDo('+f.id_area.value+','+f.id_item.value+')');		comment.add.ajax = ajax;		ajax.send();		comment.add.setStatus(0);	},	parseDo: function(idArea,idItem){		var ajax = comment.add.ajax;		if (ajax.isResponseXML()){			if (ajax.getQueryXML().exists('error->description')){				comment.add.setStatus(-1);				gLoader.show('Erro: '+ajax.getQueryXML().getValue('error->description'),'info',7);				return;			}		}else{			gLoader.show('Erro: '+ajax.getResponseText(),'info',7);			comment.add.setStatus(-1);			return;		}		ajax = ajax.getQueryXML();		var s = '';		var id,content,timeRFC,avatarUrl,avatarWidth,avatarHeight,name,firstName,lastName,url,userId;		id = ajax.getValue('item_details->id');		content = ajax.getValue('item_details->content');		timeRFC = ajax.getValue('item_details->time_rfc');		avatarUrl = ajax.getValue('item_details->user->avatar->path');		avatarWidth = ajax.getValue('item_details->user->avatar->width');		avatarHeight = ajax.getValue('item_details->user->avatar->height');		name = ajax.getValue('item_details->user->name');		firstName = ajax.getValue('item_details->user->first_name');		lastName = ajax.getValue('item_details->user->last_name');		url = ajax.getValue('item_details->user->url->internal');		userId = ajax.getValue('item_details->user->id');		var	s = comment.getBuild(id,content,timeRFC,avatarUrl,avatarWidth,avatarHeight,name,firstName,lastName,url,userId);		s+='<div class="hr"></div>';		global.div.WriteAdd(comment.getIdDivNew()+'_'+idArea+'_'+idItem, s);		global.evalScripts(s);		comment.form.getObj().reset();		comment.form.getObj().content.className = 'comment_off';		comment.add.setStatus(1);		gLoader.show('Comentário postado com sucesso','info',7);	}}comment.add.can = {	ajax: null,	Do: function(){		if (!user.isLogged()){			comment.add.can.onError();			return;		}		if (comment.add.can.ajax!=null){			comment.add.can.parseDo();			return;		}		var ajax = new gAjax('get',global.RelativeRoot() + 'misc/ajax/main.php?mode=comment_can_add&id_area='+comment.getIdArea()+'&id_item='+comment.getIdItem());		ajax.addEvent(4,'comment.add.can.parseDo()');		comment.add.can.ajax = ajax;		ajax.send();	},	parseDo: function(){		var ajax = comment.add.can.ajax;		if (!ajax.isResponseXML()){			return comment.add.can.onError();		}		ajax = ajax.getQueryXML();		if (ajax.getValue('attributes()->status')=='fail'){			return comment.add.can.onError();		}		if (ajax.getValue('item_details->permission->enabled')=='true'){			comment.add.can.onSuccess();		}else{			comment.add.can.onError();		}	},	onError: function(){},	onSuccess: function(){		comment.form.draw();	}}comment.remove = {	ajax:null,	Do: function(id){		comment.setId(id);		var ajax = new gAjax('get',global.RelativeRoot() + 'misc/ajax/main.php?mode=comment_remove&id='+comment.getId());		ajax.addEvent(1,'gLoader.show("Removendo comentário","progress")');		ajax.addEvent(4,'comment.remove.parseDo()');		comment.remove.ajax = ajax;		ajax.send();	},	parseDo: function(){		var ajax = comment.remove.ajax;		if (!ajax.isResponseXML()){			gLoader.show(ajax.getResponseText(),'info',7);			return;		}		ajax = ajax.getQueryXML();		var s		if (ajax.getValue('attributes()->status') == 'ok'){			gLoader.show('Comentário removido','info',7);			global.div.Write('div_comment_'+comment.getId(),'');		}else{			gLoader.show(ajax.getValue('error->description'),'info',7);		}	}}comment.list = {	ajax: new Array(),	page:1,	limit:10,	setPage: function(n){		comment.list.page = n;	},	getPage: function(){		return comment.list.page;	},	setLimit: function(n){		comment.list.limit = n;	},	getLimit: function(){		return comment.list.limit;	},	Do: function(page){		if (page){			comment.list.setPage(page);		}		var ajax = new gAjax('get',global.RelativeRoot() + 'misc/ajax/main.php?mode=comment_get_list&id_area='+comment.getIdArea()+'&id_item='+comment.getIdItem()+'&page='+comment.list.getPage()+'&limit='+comment.list.getLimit());		if (comment.list.getPage()>1){			ajax.addEvent(1,'gLoader.show("Listando comentários","progress")');		}		ajax.addEvent(4,'comment.list.parseDo('+comment.list.ajax.length+','+comment.getIdArea()+','+comment.getIdItem()+')');		comment.list.ajax.push(ajax);		ajax.send();	},	parseDo: function(order,idArea,idItem){		gLoader.close();		var ajax = comment.list.ajax[order];		if (!ajax.isResponseXML()){			gLoader.show(ajax.getResponseText());			return;		}		ajax = ajax.getQueryXML();		if (ajax.getValue('attributes()->status')=='fail'){			//gLoader.show(ajax.getValue('error->description'),'info',7);			return;		}		var a = new Array();		var s = '';		var id,content,timeRFC,avatarUrl,avatarWidth,avatarHeight,name,firstName,lastName,url,userId;		//getBuild: function(id,content,timeRFC,avatarUrl,avatarWidth,avatarHeight,name,firstName,lastName,url){		for(var n=0;n!=ajax.getValue('item_list->summary->partial->items');n++){			id = ajax.getValue('item_list->item_details->item['+n+']->id');			content = ajax.getValue('item_list->item_details->item['+n+']->content');			timeRFC = ajax.getValue('item_list->item_details->item['+n+']->time_rfc');			avatarUrl = ajax.getValue('item_list->item_details->item['+n+']->user->avatar->path');			avatarWidth = ajax.getValue('item_list->item_details->item['+n+']->user->avatar->width');			avatarHeight = ajax.getValue('item_list->item_details->item['+n+']->user->avatar->height');			name = ajax.getValue('item_list->item_details->item['+n+']->user->name');			firstName = ajax.getValue('item_list->item_details->item['+n+']->user->first_name');			lastName = ajax.getValue('item_list->item_details->item['+n+']->user->last_name');			url = ajax.getValue('item_list->item_details->item['+n+']->user->url->internal');			userId = ajax.getValue('item_list->item_details->item['+n+']->user->id');			s = comment.getBuild(id,content,timeRFC,avatarUrl,avatarWidth,avatarHeight,name,firstName,lastName,url,userId);			a.push(s);		}		s = a.join('<div class="hr"></div>');		if (parseInt(ajax.getValue('item_list->summary->partial->page'))>1){			s = '<div class="hr"></div>' + s;		}		global.div.WriteAdd(comment.getIdDivList()+'_'+idArea+'_'+idItem,s);		global.evalScripts(s);		s = ajax.getValue('item_list->summary->total->pages') != ajax.getValue('item_list->summary->partial->page') ? '<a href="javascript:void(0)" onclick="comment.start('+idArea+','+idItem+');comment.list.Do('+(parseInt(ajax.getValue('item_list->summary->partial->page'))+1)+')">ver mais</a>' : '';		global.div.Write(comment.getIdDivMore()+'_'+idArea+'_'+idItem,s);	}}
