/*-------------------------------------------------------------------------------------------
 *   iM JavaScript Functions
 *  (c) 2006 Interactive Multimedia Brazil
 *
 *  iM JavaScript Functions is freely distributable under the terms of an GNU-GPL license.
 *  For details, see the iM web site at http://www.interactivemultimedia.com.br/
 *
/*------------------------------------------------------------------------------------------*/

var callbacksGlobais = {
	onCreate: function(){
		Element.show('carregando');
	},
	onComplete: function() {
		if(Ajax.activeRequestCount == 0){
			Element.hide('carregando');
		}
	}
};
Ajax.Responders.register(callbacksGlobais);

function verificaIntegridade(formulario,acao){
	var url="ajax.php";
	var pars="modulo="+acao+"&"+Form.serialize(formulario);
	var myAjax = new Ajax.Request(url,{method: 'post',parameters: pars,onComplete: retornaResposta});
	function retornaResposta(resposta){
		var resposta = resposta.responseText.split("|");
		if(resposta[0]==''){
			formulario.submit();
			return false;
		}else{
	 		document.getElementById("alerta").innerHTML = resposta[0];
			document.getElementById(resposta[1]).select();
			window.scrollTo(0,280);
		}
	}
	return false;
}

function verificaIntrAcao(formulario,acao){
	formulario.action.value=acao;
	var url="ajax.php";
	var pars="modulo="+acao+"&"+Form.serialize(formulario);
	var myAjax = new Ajax.Request(url,{method: 'post',parameters: pars,onComplete: retornaResposta});
	function retornaResposta(resposta){
		var resposta = resposta.responseText.split("|");
		if(resposta[0]==''){
;			cm('central','intranet','pt-BR');
			return false;
		}else{
	 		document.getElementById("alerta").innerHTML = resposta[0];
			document.getElementById(resposta[1]).select();
			window.scrollTo(0,280);
		}
	}
	return false;
}

function novaCaptcha(){
	location.href = location.href;
} 

function cm(div,modulo,linguagem){
 	var url = 'ajax.php';
 	var pars = 'modulo=loadModule&im='+modulo+'&ln='+linguagem;
 	var myAjax = new Ajax.Updater(div, url, { asynchronous:true, evalScripts:true, method: 'get', parameters: pars });
	return false;
}

function cmc(div,modulo,c,linguagem){
 	var url = 'ajax.php';
 	var pars = 'modulo=loadModule&im='+modulo+'&c='+c+'&ln='+linguagem;
 	var myAjax = new Ajax.Updater(div, url, { asynchronous:true, evalScripts:true, method: 'get', parameters: pars });
	return false;
}

function cmcp(div,modulo,c,p,linguagem){
 	var url = 'ajax.php';
 	var pars = 'modulo=loadModule&im='+modulo+'&ln='+linguagem+'&c='+c+'&p='+p;
 	var myAjax = new Ajax.Updater(div, url, { asynchronous:true, evalScripts:true, method: 'get', parameters: pars });
	return false;
}

function iMPop(pagina,altura,largura){
	window.open(pagina,'iMpop','width='+altura+',height='+largura+',resizable=no');
}
function acao(formulario,action){
        formulario.action.value=action;
}
function enviaFormulario(form,tecla,ordem){
	if(tecla==13){
		acao(form,ordem);
		form.submit();
		return false;
	}else{
		return true;
	}
}

function cmcG(div,modulo,c,linguagem,pagina){
 	var url = 'ajax.php';
 	var pars = 'modulo=loadModule&im='+modulo+'&c='+c+'&pgr='+pagina+'&ln='+linguagem;
 	var myAjax = new Ajax.Updater(div, url, { asynchronous:true, evalScripts:true, method: 'get', parameters: pars });
	return false;
}

function ampliaImagem(div,modulo,c,linguagem){
	slideShowT.stop();
 	var url = 'ajax.php';
 	var pars = 'modulo=loadModule&im='+modulo+'&c='+c+'&ln='+linguagem;
 	var myAjax = new Ajax.Updater(div, url, { asynchronous:true, evalScripts:true, method: 'get', parameters: pars });
	return false;
}

 function SlideShow(slideList, image, speed, name){
         this.slideList = slideList;
         this.image = image;
         this.speed = speed;
         this.name = name;
         this.current = 0;
         this.timer = 0;
 }

function SlideShow_play(){
         with(this){
                 if(current++ == slideList.length-1) current = 0;
                 switchImage(image, slideList[current]);
                 clearTimeout(timer);
                 timer = setTimeout(name+'.play()', speed);
         }
 }

 function SlideShow_stop(){
         with(this){
                 clearTimeout(timer);
         }
 }

 function switchImage(imgName, imgSrc){
         if (document.images){
                 if (imgSrc != "none"){
                         document.images[imgName].src = imgSrc;
                 }
         }
 }

