// JavaScript Document
// JavaScript Document
/* background flicker ie6 hack */
/*@cc_on
   /*@if (@_win32)
   document.execCommand("BackgroundImageCache",false,true); 
   /*@end
@*/

function submeterAmigo () {
	
 // Processar dados : AJAX
 Element.hide('cb_ajaxform'); 
 Element.show('cb_ajaxwait');
 
    var params = Form.serialize('form_contact');
	var url  = '/includes/ajax_sendform.inc.php';
	var pars = 'action=sendfriend&'+params;
		
	var myAjax = new Ajax.Updater(
			{success: 'cb_ajaxwait'},  
			url, 
			{
				method: 'post', 
				parameters: pars,
				onFailure: reportError
			});
	
 return false;
}
function reportError () { alert('Sorry. There was an error.'); }

function showContact () {
	
  Element.hide ('c_1'); Element.hide ('c_2'); Element.hide ('c_3'); Element.hide ('c_4'); Element.hide ('c_5'); Element.hide ('c_6'); Element.hide ('c_7'); Element.hide ('c_8'); Element.hide ('c_9');
  
  Element.show ('c_'+$F('contact_select'));

}

function showVideo (id){

	loc = (location.href.search('homepage') > 0)? 'hp' : '';

    var url   = '/includes/ajax_info.inc.php';
	var pars  = (loc == 'hp')? 'action=showvideo&hp=1&id='+ id : 'action=showvideo&id='+ id;

	var myAjax = new Ajax.Updater(
			{success: 'video_slot'},  
			url, 
			{
				evalJS: false,
				evalScripts: false,
				method: 'post', 
				parameters: pars,
				onFailure: reportError
			});

}

function showEvents(mes, pag){

    var url   = '/includes/ajax_info.inc.php';
	var pars  = 'action=getevents&mes='+ mes+ '&pag='+ pag;
		
	var myAjax = new Ajax.Request(
		url, 
		{
			method: 'post', 
			parameters: pars, 
			onSuccess: function (res) {

				$('evento_mes_div').update(res.responseText);
			},
			onFailure: reportError
		});
}

function showProject (idlang) {

    if ($F('projectos_select') == 0) return;

    new Insertion.After ('projectos_select', '<img src="/images/waitstatus.gif" alt="Please wait..." width="16" height="16" style="vertical-align:middle" id="waitstatus" style="margin-top:-5px;" />');
	
    var url   = '/includes/ajax_info.inc.php';
	var id    = $F('projectos_select');
	var pars  = 'action=getproject&idlang='+idlang+'&id='+id;
		
	var myAjax = new Ajax.Request(
			url, 
			{
				method: 'post', 
				parameters: pars, 
				onSuccess: function (res) {
                  $('content_principal').update(res.responseText);
				  Element.remove('waitstatus');
				  sIFRsetfonts();
				 },
				onFailure: reportError
			});					  
}
var lastSelectedBox= ''
function showInfo (selectbox) {
	
	if ( $F(selectbox+'_select') == 0) { new Effect.BlindUp(selectbox+'_info', {duration:0.3}); lastSelectedBox = ''; return; }
	
    var url   = '/includes/ajax_info.inc.php';
	var id    = $F(selectbox+'_select');
	var pars  = 'action=getinfo&id='+id;
		
	var myAjax = new Ajax.Request(
		url, 
		{
			method: 'post', 
			parameters: pars, 
			onSuccess: function (res) {

				$(selectbox+'_info').update(res.responseText);
			  
				if(lastSelectedBox!=selectbox){
					/* Efeito Accordion */
					if ( $F(selectbox+'_select') == 0 ) { new Effect.BlindUp(selectbox+'_info', {duration:0.3}); return; }
					if ($('empresas_info').style.display == '') { $('empresas_select').selectedIndex=0; new Effect.BlindUp('empresas_info', {duration:0.3}); }
					if ($('universidades_info').style.display == '') { $('universidades_select').selectedIndex=0; new Effect.BlindUp('universidades_info', {duration:0.3}); }
					if ($('instituicoes_info').style.display == '') { $('instituicoes_select').selectedIndex=0; new Effect.BlindUp('instituicoes_info', {duration:0.3}); }
					if ($('servicos_info').style.display == '') { $('servicos_select').selectedIndex=0; new Effect.BlindUp('servicos_info', {duration:0.3}); }
					new Effect.BlindDown(selectbox+'_info', {duration:0.3, queue: 'end'});
				}
				lastSelectedBox = selectbox;
			},
			onFailure: reportError
		});
}

function reportError () { alert('Sorry. There was an error.'); }

function MM_jumpMenu_parent (targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function MM_jumpMenu (targ,selObj,restore){ //v3.0
//  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  window.open(selObj.options[selObj.selectedIndex].value, 'newWin', '');
  if (restore) selObj.selectedIndex=0;
}

/* popup */
var newWindow = null;
function closeWin(){
	if (newWindow != null){
		if(!newWindow.closed)
			newWindow.close();
	}
}

function popUpWin(url, type, strWidth, strHeight){
	closeWin();
		
	type = type.toLowerCase();
	
	if (type == "fullscreen"){
		strWidth = screen.availWidth;
		strHeight = screen.availHeight;
	}
	var tools="";
	if (type == "standard") tools = "resizable,toolbar=no,location=yes,scrollbars=yes,menubar=no,width="+strWidth+",height="+strHeight+",top=0,left=0";
	if (type == "console" || type == "fullscreen") tools = "resizable,toolbar=no,location=no,scrollbars=no,width="+strWidth+",height="+strHeight+",left=0,top=0";
	newWindow = window.open(url, 'newWin', tools);
	newWindow.focus();
}
function doPopUp(e)
{
//set defaults - if nothing in rel attrib, these will be used
var t = "standard";
var w = "600";
var h = "480";
//look for parameters
attribs = this.rel.split(" ");
if (attribs[1]!=null) {t = attribs[1];}
if (attribs[2]!=null) {w = attribs[2];}
if (attribs[3]!=null) {h = attribs[3];}
//call the popup script
popUpWin(this.href,t,w,h);
//cancel the default link action if pop-up activated
if (window.event) 
	{
	window.event.returnValue = false;
	window.event.cancelBubble = true;
	} 
else if (e) 
	{
	e.stopPropagation();
	e.preventDefault();
	}
}
function findPopUps() {
var popups = document.getElementsByTagName("a");
for (i=0;i<popups.length;i++)
 {
 if (popups[i].rel.indexOf("popup")!=-1) {
  // attach popup behaviour
  popups[i].onclick = doPopUp;
  // add popup indicator

/*
  if (popups[i].rel.indexOf("noicon")==-1)
  //more of the 'no icon' thing in a moment ...
   {
   popups[i].style.backgroundImage = "url(pop-up.gif)";
   popups[i].style.backgroundPosition = "0 center";
   popups[i].style.backgroundRepeat = "no-repeat";
   popups[i].style.paddingLeft = "15px";
   }
*/

// add info to title attribute to alert fact that it's a pop-up window
  popups[i].title = popups[i].title + " [Abre em nova janela]";
  
 } else if (popups[i].rel.indexOf("external")!=-1) { 
   popups[i].target = '_blank';
   popups[i].title = popups[i].title + " [Abre em nova janela]";
 }
 }
}

function addEvent(elm, evType, fn, useCapture){if(elm.addEventListener){elm.addEventListener(evType, fn, useCapture);return true;}else if (elm.attachEvent){var r = elm.attachEvent('on' + evType, fn);return r;}else{elm['on' + evType] = fn;}}

addEvent(window, 'load', findPopUps, false);
/* popup: fim */