//========================================================================================================//
function tbout (img) { img.src = String(img.src).replace(/_on\.gif/,'.gif'); }
function tbover (img) { img.src = String(img.src).replace(/\.gif/,'_on.gif'); }
//========================================================================================================//
function myaccount(url) { try { document.app.windowAccountEdit.callEvent('Update,Show') } catch(e) {} }
function login(url) { if(!defined(url)) url = ''; try { document.app.windowAccountLogin.callEvent('Update,Show',{'backUrl':url}) } catch(e) {} }
function uprofile() { try { document.app.windowUserProfile.callEvent('Update,Show') } catch(e) {} }
function upc(select) { if (select.jslibCompiled) { document.app.update({'act' : 'loadUserProfileComplete','name':select.form.name.value,'birth':select.form.birth.value,'gender':select.form.gender.options[select.form.gender.selectedIndex].value,'profession':select.options[select.selectedIndex].value}); } }
//========================================================================================================//
function pconf() { try { document.app.windowPanelConfig.callEvent('Update,Show') } catch(e) {} }
function pdelete() { document.app.update({'act':'panelDelete'}) }
//========================================================================================================//
function pcreate(from) { try { if (!defined(from)) from=''; document.app.windowPanelCreate.callEvent('Update,Show',{'from':from,'options':'import'}) } catch(e) {} }
//========================================================================================================//
function pcemail() { try {
	document.app.formPanelCreate.setValue('passport','email');
	document.app.dataPanelCreateLogin.setStyle('display','none');
	document.app.dataPanelCreateEmail.setStyle('display','block');
	var f = document.app.formPanelCreate.getNode();
	f.elements['lemail'].removeAttribute('validate');
	f.elements['cemail'].setAttribute('validate','email');
	f.elements['cemailre'].setAttribute('validate','match');
	f.elements['lemail'].setAttribute('validateEmpty','false');
	f.elements['password'].setAttribute('validateEmpty','false');
	f.elements['cemail'].setAttribute('validateEmpty','true');
	f.elements['cemailre'].setAttribute('validateEmpty','true');
} catch(e) {} }
//========================================================================================================//
function pclogin() { try {
	document.app.formPanelCreate.setValue('passport','login');
	document.app.dataPanelCreateEmail.setStyle('display','none');
	document.app.dataPanelCreateLogin.setStyle('display','block');
	var f = document.app.formPanelCreate.getNode();
	f.elements['lemail'].setAttribute('validate','email');
	f.elements['cemail'].removeAttribute('validate');
	f.elements['cemailre'].removeAttribute('validate');
	f.elements['lemail'].setAttribute('validateEmpty','true');
	f.elements['password'].setAttribute('validateEmpty','true');
	f.elements['cemail'].setAttribute('validateEmpty','false');
	f.elements['cemailre'].setAttribute('validateEmpty','false');
} catch(e) {} }
//========================================================================================================//
function iichoose() { try {
	document.app.formItemImport.setValue('mode','choose');
	document.getElementById('iicreate').style.display='none';
	document.getElementById('iichoose').style.display='block';
	document.app.formItemImport.getNode().elements['name'].setAttribute('validateEmpty','false');
	document.app.formItemImport.getNode().elements['iicat'].focus();
} catch(e) {} }
//========================================================================================================//
function iicreate() { try {
	document.app.formItemImport.setValue('mode','create');
	document.getElementById('iichoose').style.display='none';
	document.getElementById('iicreate').style.display='block';
	document.app.formItemImport.getNode().elements['name'].setAttribute('validateEmpty','true');
	document.app.formItemImport.getNode().elements['name'].select();
	document.app.formItemImport.getNode().elements['name'].focus();
} catch(e) {} }
//========================================================================================================//
function iicheck(msg) {
	if (document.getElementById('iicreate').style.display=='block') {
		if (String(document.app.formItemImport.getNode().elements['name'].value).search(/\w/) > -1) {
			return true;
		} else {
			alert(makeStringValue(msg));
			return false;
		}
	} else {
		return true;
	}
}
//========================================================================================================//
function imchoose() { try {
	document.app.formItemMove.setValue('mode','choose');
	document.getElementById('imcreate').style.display='none';
	document.getElementById('imchoose').style.display='block';
	document.app.formItemMove.getNode().elements['name'].setAttribute('validateEmpty','false');
	document.app.formItemMove.getNode().elements['newcat'].focus();
} catch(e) {} }
//========================================================================================================//
function imcreate() { try {
	document.app.formItemMove.setValue('mode','create');
	document.getElementById('imchoose').style.display='none';
	document.getElementById('imcreate').style.display='block';
	document.app.formItemMove.getNode().elements['name'].setAttribute('validateEmpty','true');
	document.app.formItemMove.getNode().elements['name'].select();
	document.app.formItemMove.getNode().elements['name'].focus();
} catch(e) {} }
//========================================================================================================//
function imcheck(msg) {
	if (document.getElementById('imcreate').style.display=='block') {
		if (String(document.app.formItemMove.getNode().elements['name'].value).search(/\w/) > -1) {
			return true;
		} else {
			alert(makeStringValue(msg));
			return false;
		}
	} else {
		return true;
	}
}
//========================================================================================================//
function closemsg() {
	var s = document.app.shapePanelMessage.getNode();
	while (s.childNodes.length > 0) {
		s.removeChild(s.firstChild);
	}
}
//========================================================================================================//
var curitem = 0;
var curtitle = 0;
var pitems = {};
//========================================================================================================//
function fadd() { try { document.app.windowFeedAdd.callEvent('Update,Show') } catch(e) {} }
function iadd(id) { try { if (defined(id)) { document.app.windowItemAdd.callEvent('Update,Show',{'_formItemAddContent':'View,Bottom','content':id}) } else { document.app.windowItemAdd.callEvent('Update,Show') } } catch(e) {} }
function isend(object) { var item = (object) ? iobject(object) : curitem; document.app.windowItemSend.callEvent('Update,Show',{'item':item}) }
function imove() { document.app.windowItemMove.callEvent('Update,Show',{'item':curitem}) }
function ilist() { try { document.app.formItemAdd.clearParams(); document.app.windowItemAdd.callEvent('Update,Show',{'_formItemAddContent' : 'List,Bottom'}) } catch(e) {} }
function isetup(id) { pitems[id] = new PItem(id); }
function idelete() { if (curitem > 0) { try { document.app.windowItemDelete.callEvent('Update,Show',{'item':curitem,'title':curtitle}) } catch(e) {} } }
function iinclude(content,submit) { var f = document.app.formItemAdd; f.setValue('content',content); f.setSubmit(submit); f.submitAjax(); }
function iimport(id,title) { try { document.app.update({'act':'importItem','item':id,'title':title}) } catch(e) {} }
function icolor(color) { if (curitem > 0) { try { document.app.update({'act':'setItemColor','item':curitem,'color':color}) } catch(e) {} } }
function iobject(object) { var item; if (typeof(object) == 'object') { for (var i = 0; i < 50; i++) { item = getProp(object,'item'); if (item > 0) { break; } else { object = object.parentNode; } } } return item; }
function icall(object,method,params,modal) { document.app.update({'act':'itemInterface','item':iobject(object),'imethod':method,'iparams':cxEscape(makeQueryString(params))},modal) }
//========================================================================================================//
function removeItem(id) { try { var item = document.getElementById('i'+id); item.parentNode.removeChild(item); chkPos(0); } catch (e) {} }
//========================================================================================================//
function saveItemPos(pos) { document.app.update({'act':'saveItemPos','pos':pos},false) }
function changeItemCat(item,newcat) { document.app.update({'act':'changeItemCategory','item':item,'newcat':newcat}); }
//========================================================================================================//
function cadd() { try { document.app.windowCategoryAdd.callEvent('Update,Show') } catch(e) {} }
function cedit() { try { document.app.windowCategoryEdit.callEvent('Update,Show'); } catch(e) {} }
function cdelete() { try { document.app.windowCategoryDelete.callEvent('Update,Show'); } catch(e) {} }
function cpublish() { try { document.app.windowCategoryPublish.callEvent('Update,Show'); } catch(e) {} }
function crestrict() { try { document.app.windowCategoryRestrict.callEvent('Update,Show'); } catch(e) {} }
function cimport() { try { document.app.update({'act':'importCategory'}); } catch(e) {} }
//========================================================================================================//
function gadd() { try { document.app.update({'act':'contentAdd'}) } catch(e) {} }
function gedit(id) { try { document.app.update({'act':'contentEdit','content':id}) } catch(e) {} }
function gdelete(id,msg) { if (confirm(makeStringValue(msg))) { document.app.update({'act':'contentDelete','content':id}); } }
//========================================================================================================//
// processa resposta do item
//========================================================================================================//
AppLayer.prototype.processUpdateCatMenu = function(xml) {
//========================================================================================================//
	document.getElementById('phcmenu').innerHTML = getNodeValue(xml);
}
//========================================================================================================//
// processa resposta do item
//========================================================================================================//
AppLayer.prototype.processGetPanelItem = function(xml) {
//========================================================================================================//
	var id = xml.getAttribute('ID');
	if (pitems[id]) {
		pitems[id].processXML(xml);
	}
	return;
}
//========================================================================================================//
// copia conteúdo para clipboard
//========================================================================================================//
function copy_clip(meintext) {
//========================================================================================================//
	if (window.clipboardData) {
	   window.clipboardData.setData("Text", meintext);
	} else if (window.netscape) {
		netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
		var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
		if (!clip) return;
		var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
		if (!trans) return;
		trans.addDataFlavor('text/unicode');
		var str = new Object();
		var len = new Object();
		var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
		var copytext=meintext;
		str.data=copytext;
		trans.setTransferData("text/unicode",str,copytext.length*2);
		var clipid=Components.interfaces.nsIClipboard;
		if (!clip) return false;
		clip.setData(trans,null,clipid.kGlobalClipboard);
   }
   return false;
}
//========================================================================================================//
// checa sessão do apssport
//========================================================================================================//
var passportCheckSession;
var passportExpireSession;
//========================================================================================================//
function updateSession(expireSecs,sessionID) {
//========================================================================================================//
	if (passportExpireSession) {
		clearTimeout(passportExpireSession);
	}
	var expireSession = expireSecs * 1000;
	passportExpireSession = setTimeout(function() { document.location.href=document.location.href },expireSession);
	if (sessionID != '') {
		if (passportCheckSession) {
			clearTimeout(passportCheckSession);
		}
		passportCheckSession = setInterval(function() {
			var sessionCookie = document.app.getCookie('CentralxPassport');
			if (String(sessionCookie).length > 0) {
				if (String(sessionCookie).indexOf(sessionID) == -1) {
					document.app.sessionExpired = true;
					clearInterval(passportCheckSession);
					document.location.href=document.location.href;
				}
			}
		},2000);
	}
	return;
}
//========================================================================================================//
// ------------------------------------------------------------------------------------------------------ //
//========================================================================================================//
// abre pesquisa na documentação
//========================================================================================================//
function keyOpenDocs(url,field,event) {
//========================================================================================================//
	if (window.event) {
		event = window.event;
	}
	if (event.keyCode == 13) {
		if (url) {
			if (field) {
				if (field.value != '') {
					window.open(url+escape(field.value));
				}
			}
		}
		return false;
	}
	return true;
}
//========================================================================================================//
// abre pesquisa na documentação
//========================================================================================================//
function btnOpenDocs(url,caption,event) {
//========================================================================================================//
	if (url) {
		var field = document.getElementById('phskey');
		if (field) {
			if (field.value != '') {
				if (field.value != caption) {
					window.open(url+escape(field.value));
				}
			}
		}
	}
}
//========================================================================================================//
// ------------------------------------------------------------------------------------------------------ //
//========================================================================================================//
