// SCS Multimédia - JavaScript Document ---- T M G S ---- //


/**********************************************************************************   
ScrollText 
*   Copyright (C) 2001 Thomas Brattli
*   This script was released at DHTMLCentral.com
*   Visit for more great scripts!
*   This may be used and changed freely as long as this msg is intact!
*   We will also appreciate any links you could give us.
*
*   Made by Thomas Brattli
*
*   Script date: 09/23/2001 (keep this date to check versions) 
*********************************************************************************/
function lib_bwcheck(){ //Browsercheck (needed)
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=(navigator.userAgent.indexOf("Opera")>-1 && document.getElementById)?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}
var bw=lib_bwcheck()

/*****************

You set the width and height of the divs inside the style tag, you only have to
change the divScrollTextCont, Remember to set the clip the same as the width and height.
You can remove the divUp and divDown layers if you want. 
This script should also work if you make the divScrollTextCont position:relative.
Then you should be able to place this inside a table or something. Just remember
that Netscape crash very easily with relative positioned divs and tables.

Updated with a fix for error if moving over layer before pageload.

****************/


//If you want it to move faster you can set this lower, it's the timeout:

var speed = 30

//Sets variables to keep track of what's happening
var loop, timer

//Object constructor
function makeObj(obj,nest){
	//alert(obj + ' ' + nest)
    nest=(!nest) ? "":'document.'+nest+'.'
	this.el=bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):0;
  	this.css=bw.dom?document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+'document.'+obj):0;
	this.scrollHeight=bw.ns4?this.css.document.height:this.el.offsetHeight
	this.clipHeight=bw.ns4?this.css.clip.height:this.el.offsetHeight
	this.up=goUp;this.down=goDown;
	this.moveIt=moveIt; this.x=0; this.y=0;
    this.obj = obj + "Object"
    eval(this.obj + "=this")
    return this
}

// A unit of measure that will be added when setting the position of a layer.
var px = bw.ns4||window.opera?"":"px";

function moveIt(x,y){
	this.x = x
	this.y = y
	//original this.css.left = this.x+px
	//original this.css.top = this.y+px
	this.css.marginLeft = this.x+px
	this.css.marginTop = this.y+px
}

//Makes the object go up
function goDown(move){
	//alert("[" + this.y + "]  [" + this.scrollHeight + "]  [" + oCont.clipHeight + "]")
	if (this.y>-this.scrollHeight+oCont.clipHeight){
		this.moveIt(0,this.y-move)
			if (loop) setTimeout(this.obj+".down("+move+")",speed)
	}
}
//Makes the object go down
function goUp(move){
	//alert(this.y)
	if (this.y<0){
		this.moveIt(0,this.y-move)
		if (loop) setTimeout(this.obj+".up("+move+")",speed)
	}
}

//Calls the scrolling functions. Also checks whether the page is loaded or not.
function scroll(speed){
	if (scrollContentLoaded){
		//alert(speed)
		loop = true;
		if (speed>0) oScroll.down(speed)
		else oScroll.up(speed)
	}
}

//Stops the scrolling (called on mouseout)
function noScroll(){
	loop = false
	if (timer) clearTimeout(timer)
}

//Makes the object
var scrollContentLoaded = false
var lastContainer = ''

function scrollContentInit(divcontainer, divcontent, init) {
	//alert(divcontainer + ' ' + divcontent)
	if ((divcontainer != lastContainer) || (init == 1)) {
		if (init==1) {
			lastContainer = '' }
		else {
			lastContainer = divcontainer}
			
		oCont = new makeObj(divcontainer)
		oScroll = new makeObj(divcontent, divcontainer)
		
		//alert(oScroll.scrollHeight);
		//alert(oCont.clipHeight);
		
		//if ( oScroll.scrollHeight - oCont.clipHeight > 0 ){
			oScroll.moveIt(0,0)
			//oCont.css.visibility = "visible"
			scrollContentLoaded = true
			
			//showhideBtnScroll(divcontainer,'')
			
		//} else {
			
		//	showhideBtnScroll(divcontainer,'none')
			
		//}
	}
}

function scrollContentInit1(divcontainer, divcontent, divscroll, init) {

	showhideonediv(divscroll,'none');
	oCont = new makeObj(divcontainer)
	oScroll = new makeObj(divcontent, divcontainer)

	//alert(oScroll.scrollHeight);
	//alert(oCont.clipHeight);
	
	if ( oScroll.scrollHeight - oCont.clipHeight > 0 ){
		oScroll.moveIt(0,0)
		//oCont.css.visibility = "visible"
		scrollContentLoaded = true
		showhideonediv(divscroll,'');
	}
}

/****************************************************************************************
Multiple Scripts
If you have two or more scripts that use the onload event, probably only one will run (the last one).
Here is a solution for starting multiple scripts onload:
   1. Delete or comment out all the onload assignments, onload=initScroll and things like that.
   2. Put the onload assignments in the body tag like in this example, note that they must have braces ().
   Example: <body onload="initScroll(); initTooltips(); initMenu();">
******************************************************************************************/

//--------------------------------------- Script TMGS ------------------------------------------------------------------

var c = 1;
var j = 0;
var ni = 0;
var t = 0;
var p = 0;


function _slideshowImage(ar,rst,fr) {
	//alert(fr)
	if (rst == 0) {
		//alert('Olha o clearTimeout');
		window.clearTimeout(t);
		c=0;
		//rst = 1;
	}
	
	if (c >= 0) { //slideshow
	
		ni=c;
		c=c+1
		//alert(ar.length)
		if (c > ar.length) { ni=0; c=1 }
		
		//alert(ar[ni]);
		oObjcss.css.background='url(' + ar[ni] + ') no-repeat 0 0';
		
		var t=window.setTimeout("slideshowImage(aF,1,"+fr+")",fr)
		
	}
}

function slideshowImage(ar) {
	//alert(ar[c]);
	
	if (c>=0) {
	
		oObjcss.css.background='url(' + ar[c] + ') no-repeat 0 0';
		
		c=c+1;	
		
		if (c == ar.length) { c=0; }
	
	}
}


function changeImage(wid,img) {
	//alert(wid);
	document.getElementById(wid).src=img;
}

function changeImageBcssDiv(divfotos,shfotos,div,img) {
	//alert(div + ' ' + img);
	showhideonediv(divfotos,shfotos);
	oDivCss = new makeObjcss(div);
	oDivCss.css.background = '#4F1F91 url(' + img + ') no-repeat 0 0';
}

function changeBGcssDiv(div,cor,img) {
	//alert(div + ' ' + cor + ' ' + img);
	oDivCss = new makeObjcss(div);
	//oDivCss.css.background = '#4F1F91 url(' + img + ') no-repeat 0 0';
	oDivCss.css.background = '' + cor + ' url(' + img + ') no-repeat 0 0';
}

function changeImageTextBcssDiv(divfotos,shfotos,div,img,txt) {
	//alert(div + ' ' + img);
	//alert(txt);
	showhideonediv(divfotos,shfotos);
	oDivCss = new makeObjcss(div);
	oDivCss.css.background = '#4F1F91 url(' + img + ') no-repeat 0 0';
	if (txt != '') {
		document.getElementById('divtextocurso').innerHTML= txt;
		showhideonediv('divtextocurso','');
	} else { showhideonediv('divtextocurso','none'); }
	
}

function changeImageTextBcssDivEvento(divfotos,shfotos,div,img,txt) {
	//alert(div + ' ' + img);
	//alert(txt);
	showhideonediv(divfotos,shfotos);
	oDivCss = new makeObjcss(div);
	oDivCss.css.background = '#4F1F91 url(' + img + ') no-repeat 0 0';
	if (txt != '') {
		document.getElementById('divtextoevento').innerHTML= txt;
		showhideonediv('divtextoevento','');
	} else { showhideonediv('divtextoevento','none'); }
	
}

function changeImageTextDiv(divfotos,shfotos,div,img,txt) {
	//alert(div + ' ' + img);
	//alert(txt);
	showhideonediv(divfotos,shfotos);
	oDivCss = new makeObjcss(div);
	oDivCss.css.background = '#4F1F91 url(' + img + ') no-repeat 0 0';
	if (txt != '') {
		document.getElementById('divtexto').innerHTML= txt;
		showhideonediv('divtexto','');
	} else { showhideonediv('divtexto','none'); }
	
}

function changeImageTextDiv1(divfotos,shfotos,div,img,txt) {
	//alert(div + ' ' + img);
	//alert(txt);
	showhideonediv(divfotos,shfotos);
	oDivCss = new makeObjcss(div);
	oDivCss.css.background = '#4F1F91 url(' + img + ') no-repeat 0 0';
	if (txt != '') {
		document.getElementById('divtexto').innerHTML= txt;
		showhideonediv('divtexto','');
		scrollContentInit1('divtextoscroll','divtexto','divscroll_home',0);
	} else { 
		showhideonediv('divtexto','none'); 
	}
	
}

function changeSize() {
	j=j+2
	//alert(j)
	if (j<=276) { 
	//alert(j)
	
	oDivInfoProd.css.width = 84+j;
	
	var k=setTimeout("changeSize()",1)
	
	}
}

function showhideonediv(div,sh) {
	//alert(div)
	document.getElementById(div).style.display=sh
}

function hideallrows(nrows) {
	var i;
	for(i=1;i<=nrows;i++)
	{
		document.getElementById('rowlista' + i).style.display='none';
	}
}

function showhidetablerow(row,sh,nr) {
	hideallrows(nr);
	document.getElementById(row).style.display=sh;
}

function hideallimg(nimg) {
	//var i;
	for(i=1;i<=nimg;i++)
	{
		document.getElementById('acab' + i).style.display='none';
	}
}

function visibleElementByClass(classname,sh,tag){ 
 var inc=0; 
 var alltags=document.getElementsByTagName(tag); 
 for (i=0; i<alltags.length; i++){ 
   if (alltags[i].className==classname)
	 alltags[i].style.display=sh;
 } 
}

function changeStyleElementByClass(classname,chg,tag,sty){ 
 var inc=0; 
 var alltags=document.getElementsByTagName(tag); 
 for (i=0; i<alltags.length; i++){ 
   if (alltags[i].className==classname) {
	   
		switch (sty)
		{	   
			case 'color': alltags[i].style.color=chg; break;
			case 'color+back': alltags[i].style.color=chg; alltags[i].style.background=''; break
		}
	 
   }
 } 
}


// ------------------------------------------------- A J A X -------------------------------------------- //

/* The following function creates an XMLHttpRequest object... */

function createRequestObject(){
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer"){
		/* Create the object using MSIE's method */
		//alert(browser)
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}

/* You can get more specific with version information by using 
	parseInt(navigator.appVersion)
	Which will extract an integer value containing the version 
	of the browser being used.
*/
/* The variable http will hold our new XMLHttpRequest object. */
var http = createRequestObject(); 

function getEventos(lang,termin,opSel,mclassSel,tipo) {
	//alert(opSel);
	
	changeStyleElementByClass(mclassSel,'#ffffff','a','color+back');
	document.getElementById(opSel).style.color='#C6DB00';
	document.getElementById(opSel).style.background='url(imagens/optionsel.jpg) no-repeat center right';
	
	//http.open('get', 'diveventos.php?langu='+lang);
	//http.open('get', 'diveventos.php?langu='+lang+'&termin='+termin);
	http.open('get', 'diveventos.php?langu='+lang+'&termin='+termin+'&tipo='+tipo);
	//http.setRequestHeader('Content-Type','text/html; charset=ISO-8859-1');
	http.onreadystatechange = handleEventos; 
	http.send(null);
	
}

function handleEventos(){
	if(http.readyState == 4){ 
		var response = http.responseText;
		//document.getElementById('divmenu_right').innerHTML = response;
		document.getElementById('divlista').innerHTML = response;
		
		//scrollContentInit('divmenu_right', 'divlista', 1);
		scrollContentInit1('divmenu_right','divlista','divscroll_menu',0);
	}
}

function getCursos(lang,termin,opSel,mclassSel,tipo) {
	//alert(lang);
	
	changeStyleElementByClass(mclassSel,'#ffffff','a','color+back');
	document.getElementById(opSel).style.color='#C6DB00';
	document.getElementById(opSel).style.background='url(imagens/optionsel.jpg) no-repeat center right';
	
	//http.open('get', 'divcursos.php?langu='+lang+'&termin='+termin);
	http.open('get', 'divcursos.php?langu='+lang+'&termin='+termin+'&tipo='+tipo);
	//http.setRequestHeader('Content-Type','text/html; charset=ISO-8859-1');
	http.onreadystatechange = handleCursos; 
	http.send(null);
	
}

function handleCursos(){
	if(http.readyState == 4){ 
		var response = http.responseText;
		//document.getElementById('divmenu_right').innerHTML = response;
		document.getElementById('divlista').innerHTML = response;
		
		//scrollContentInit('divmenu_right', 'divlista', 1);
		scrollContentInit1('divmenu_right','divlista','divscroll_menu',0);
	}
}

function getProgramas(lang,activ,opSel,mclassSel,tipo) {
	//alert(lang);
	
	changeStyleElementByClass(mclassSel,'#ffffff','a','color+back');
	document.getElementById(opSel).style.color='#C6DB00';
	document.getElementById(opSel).style.background='url(imagens/optionsel.jpg) no-repeat center right';
	
	//http.open('get', 'divcursos.php?langu='+lang+'&termin='+termin);
	http.open('get', 'divprogramas.php?langu='+lang+'&activ='+activ+'&tipo='+tipo);
	//http.setRequestHeader('Content-Type','text/html; charset=ISO-8859-1');
	http.onreadystatechange = handleProgramas; 
	http.send(null);
	
}

function handleProgramas(){
	if(http.readyState == 4){ 
		var response = http.responseText;
		//document.getElementById('divmenu_right').innerHTML = response;
		document.getElementById('divlista').innerHTML = response;
		
		//scrollContentInit('divmenu_right', 'divlista', 1);
		scrollContentInit1('divmenu_right','divlista','divscroll_menu',0);
	}
}

function getContactos(lang,mclassSel) {
	//alert(lang);
	
	changeStyleElementByClass(mclassSel,'#ffffff','a','color+back');
	
	http.open('get', 'divcontactos.php?langu='+lang);
	//http.setRequestHeader('Content-Type','text/html; charset=ISO-8859-1');
	http.onreadystatechange = handleContactos; 
	http.send(null);
}

function handleContactos(){
	if(http.readyState == 4){ 
		var response = http.responseText;
		//document.getElementById('divmenu_right').innerHTML = response;
		document.getElementById('divlista').innerHTML = response;
		
		showhideonediv('divscroll_menu','none');
	}
}

function getQuemsomos(lang,mclassSel) {
	//alert(lang);
	
	changeStyleElementByClass(mclassSel,'#ffffff','a','color+back');
	
	http.open('get', 'divquemsomos.php?langu='+lang);
	http.onreadystatechange = handleQuemsomos; 
	http.send(null);
}

function handleQuemsomos(){
	if(http.readyState == 4){ 
		var response = http.responseText;
		//document.getElementById('divmenu_right').innerHTML = response;
		document.getElementById('divlista').innerHTML = response;
		
		showhideonediv('divscroll_menu','none');
	}
}

function saveSubscreveNews(lang,nm,snm,mor,cp,loc,emp,emai,prof) {
	//alert(lang);

	http.open('get', 'divsubscrevenews.php?langu='+lang+'&nm='+nm+'&snm='+snm+'&mor='+mor+'&cp='+cp+'&loc='+loc+'&emp='+emp+'&emai='+emai+'&prof='+prof);
	http.onreadystatechange = handlesaveSubscreveNews; 
	http.send(null);
}

function handlesaveSubscreveNews(){
	if(http.readyState == 4){ 
		var response = http.responseText;
		document.getElementById('msgSubmeter').innerHTML = response;
	}
}


// ------------------------------------------------- A J A X -------------------------------------------- //

var aF = new Array();
var aEV = new Array();
var aCR = new Array();
var aPR = new Array();
var aLK = new Array();

function links_onLoad() {
	oObjcss = new makeObjcss('banner');
	//alert(aLK);
	
	aLK=links_onLoad.arguments;
	//alert(aLK[0]);
	
	a_preloadImages(aLK);
	
	var t = window.setInterval("slideshowImage(aLK)",7500);
	
	scrollContentInit('divlinksscroll','divlinks',0);
}

function programas_onLoad() {
	oObjcss = new makeObjcss('banner');
	//alert(sF);
	
	aPR=programas_onLoad.arguments;
	//alert(aCR[0]);
	
	a_preloadImages(aPR);
	
	var t = window.setInterval("slideshowImage(aPR)",7500);
}

function cursos_onLoad() {
	oObjcss = new makeObjcss('banner');
	//alert(sF);
	
	aCR=cursos_onLoad.arguments;
	//alert(aCR[0]);
	
	a_preloadImages(aCR);
	
	var t = window.setInterval("slideshowImage(aCR)",7500);
}

function eventos_onLoad() {
	oObjcss = new makeObjcss('banner');
	//alert(sF);
	
	aEV=eventos_onLoad.arguments;
	//alert(aEV[1]);
	
	a_preloadImages(aEV);
	
	var t = window.setInterval("slideshowImage(aEV)",7500);
}

function enodestinos_onLoad() {
	oObjcss = new makeObjcss('showroom');
	//alert(sF);
	
	aF=enodestinos_onLoad.arguments;
	//alert(aF[1]);
	
	a_preloadImages(aF);
	//oObjcss.css.background='url(' + aF[0] + ') no-repeat 0 0';
	
	var t = window.setInterval("slideshowImage(aF)",7500);
	
	scrollContentInit1('divmenu_right','divlista','divscroll_menu',0);
}
// --------------------------------------------------------------------------------------------------- //


