function crossEvent (e)
{
	e = e ? e : (window.event ? window.event : null);
	
	if (e)
	{
		this.originalEvent = e;
		this.type = e.type;
		this.screenX = e.clientX;
		this.screenY = e.clientY;
	
		// IE: srcElement
		this.target = e.target ? e.target : e.srcElement;
	
		// N4: modificadores
		if (e.modifiers)
		{
			this.altKey   = e.modifiers & Event.ALT_MASK;
			this.ctrlKey  = e.modifiers & Event.CONTROL_MASK;
			this.shiftKey = e.modifiers & Event.SHIFT_MASK;
			this.metaKey  = e.modifiers & Event.META_MASK;
		}
		else
		{
			this.altKey   = e.altKey;
			this.ctrlKey  = e.ctrlKey;
			this.shiftKey = e.shiftKey;
			this.metaKey  = e.metaKey;
		}
	
		// N4: which // N6+: charCode
		this.charCode = !isNaN(e.charCode) ? e.charCode : !isNaN(e.keyCode) ? e.keyCode : e.which;
		this.keyCode = !isNaN(e.keyCode) ? e.keyCode : e.which;
		this.button = !isNaN(e.button) ? e.button: !isNaN(e.which) ? e.which-1 : null;
		this.debug = "c:" + e.charCode + " k:" + e.keyCode + " b:" + e.button + " w:" + e.which;
	}
}

function sha1 (formId)
{
	var form = $(formId);
	
	form.password.value = hex_sha1(form.passwdDraft.value);
	
	form.passwdDraft.value = '';
	
	form.submit ();
}

function showText (id)
{
	var boxes = new Array ('summary','reasons','goal','methodology','partners','team','comments');
	
	for (var i = 0 ; i < boxes.length ; i++)
		$('text_' + boxes [i]).style.display = 'none';
	
	$('text_' + id).style.display = 'block';
}

function validate ()
{
	if (document.getElementById ('actor_name').value.length < 1)
	{          
		 alert ("O campo nome não pode ser vazio!");
		 document.getElementById ('actor_name').focus ();
		 return false;
	}
	
	var reTipo = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	
	if (!reTipo.test (document.getElementById ('actor_email').value))
	{
		 alert ("O campo email não está preenchido corretamente!");
		 document.getElementById ('actor_email').focus ();
		 return false;	
	}
	
	if (document.getElementById ('actor_subject').value.length < 1)
	{          
		 alert ("O campo assunto não pode ser vazio!");
		 document.getElementById ('actor_subject').focus ();
		 return false;
	}
	
	if (document.getElementById ('actor_message').value.length < 1)
	{          
		 alert ("O campo mensagem não pode ser vazio!");
		 document.getElementById ('actor_message').focus ();
		 return false;
	}

	if (document.getElementById ('actor_spam').value.length < 1)
	{          
		 alert ("O campo de confirmação de imagem não pode ser vazio!");
		 document.getElementById ('actor_spam').focus ();
		 return false;
	}

	return true;
}

function showGallery (id)
{
	var gallery = $('gallery_' + id);
	var photos = $('photos_' + id);
	
	if (photos.style.display == '')
	{
		photos.style.display = 'none';
		gallery.style.border = '#CCCCCC 2px solid';
	}
	else
	{
		eval ('var lids = ids_' + id);
		
		if (lids.length)
		{
			for (var i = 0 ; i < lids.length ; i++)
			{
				var image = document.createElement ('img');
	
				$('thumb_' + lids [i]).appendChild (image);
				
				image.src = 'manager/titan.php?target=script&toSection=gallery&file=thumb&photoId=' + lids [i] + '&size=100x75';
			}
			
			eval ('ids_' + id + ' = new Array ();');
		}
		
		photos.style.display = '';
		gallery.style.border = '#333333 2px solid';
	}
}

function openHelp (id)
{
	var help = window.open ('http://chat.jbtop.com/x/chat?account=' + id,'HelpDesk','width=600,height=470,resizable=1');
	
	help.focus ();
}

function openPopUp (url, name, width, height, scrolling, status, resizable)
{
	if (!width)
		width = screen.availWidth - 10;
	
	if (!height)
		height = screen.availHeight - 40;
	
	if (!scrolling)
		scrolling = 'yes';
		
	if (!status)
		status = 'no';
	
	if (!resizable)
		resizable = 'yes';
	
	PopUp = window.open (url, name, 'width=' + width + ',height=' + height + ',scrollbars=' + scrolling + ',toolbar=no,location=no,status=' + status + ',menubar=no,resizable=' + resizable + ',left=100,top=100');
}

function changeNewsFocus (id)
{
	for (var i = 0 ; i < 4 ; i++)
	{
		$('photo_' + i).style.display = 'none';
		$('news_' + i).style.background = '#FFF';
		$('news_' + i).style.color = '#000';
	}
	
	$('news_' + id).style.background = '#EEE';
	$('news_' + id).style.color = '#900';
	$('photo_' + id).style.display = 'block';
}

function fontSize (signal)
{
	var max = 18;
	var min = 8;
	
	var n = $('textContainer').getElementsByTagName('div');
	
	for (var i = 0 ; i < n.length ; i++)
	{
		if (n [i].style.fontSize)
			s = parseInt (n [i].style.fontSize.replace ('px',''));
		else
			s = 11;
	
		switch (signal)
		{
			case '-':
				s = s > min ? s - 1 : s;
				
				n [i].style.fontSize = s + 'px';
				
				break;
			
			case '+':
				s = s < max ? s + 1 : s;
				
				n [i].style.fontSize = s + 'px';
				
				break;
			
			default:
				n [i].style.fontSize = '11px';
		}
	}
}

function formatCpf (field, e)
{
	var char = 48;
	
	if (e)
	{
		var obj = new crossEvent (e);
		
		char = obj.charCode;
	}
	
	if (char == 8 || char == 0)
		return true;
	
	if (char < 48 || char > 57)
		return false;
	
	if (e)
		char -= 48;
	else
		char = '';
	
	if (field.value.length > 14)
		return false;
	
	if (field.value.length == 3)
		field.value = field.value + '.';
	else if (field.value.length == 7)
		field.value = field.value + '.';
	else if (field.value.length == 11)
		field.value = field.value + '-';
		
	return true;
}

function showPrograms (id)
{
	var institution = $('institution_' + id);
	var programs = $('programs_' + id);
	
	if (programs.style.display == '')
	{
		programs.style.display = 'none';
		institution.style.fontWeight = 'normal';
		institution.style.color = '#000';
		institution.style.backgroundColor = '#FFF';
	}
	else
	{
		programs.style.display = '';
		institution.style.fontWeight = 'bold';
		institution.style.color = '#FFF';
		institution.style.backgroundColor = '#9A9698';
	}
}