//************************************************FUNÇOES ÚTEIS USADAS NA PAGINA DE VIDEOS DO YOUTUBE
function changeClassName(objID, objClassName){	
	obj = document.getElementById(objID);
	obj.className = objClassName;
}
function clearClass(objPrefix, objNum){	
	for(x=0;x<objNum;x++){
		objID = objPrefix+x;		
		obj = document.getElementById(objID);
		obj.className = " ";
	}
}
//************************************************MENU PRINCIPAL
var foo = null; // object	
function doMove() {
	  /*if(foo.style.height != "140px"){
		  foo.style.height = parseInt(foo.style.height)+20+'px';			  
	  } else {*/
	  		//mude link para fechar
			document.getElementById("bt_menu_open").style.display = "none";
			document.getElementById("bt_menu_close").style.display = "block";
			foo.style.height = "160px";
			foo.style.display = "block";
			return false;
	  //}	
	  //setTimeout(doMove,0); // call doMove in 20msec*/
	  
}
function doUnMove() {
	  /*if(foo.style.height != "0px"){
		  foo.style.height = parseInt(foo.style.height)-20+'px';			 
	  }	else {*/
		  //mude link para abrir
		  document.getElementById("bt_menu_open").style.display = "block";
		  document.getElementById("bt_menu_close").style.display = "none";
		  //foo.style.height = "0px";
		  foo.style.display = "none";
		  return false;
	  //}
	  //setTimeout(doUnMove,0); // call doMove in 20msec*/
	 
}

function init(x) {
	  if(x == "abrir"){
			foo = document.getElementById('MenuNavegacao'); // get the "foo" object
			//foo.style.height = '0px'; // set its initial position to 0px
			doMove(); // start animating	
			//foo.style.display="block";
			//foo.style.height="auto !important";
	  }else{
			foo = document.getElementById('MenuNavegacao'); // get the "foo" object
			//foo.style.height = '140px'; // set its initial position to 0px
			doUnMove(); // start animating
			//foo.style.display="none";
	  }	  
}
//************************************************OPEN WIN
janela = null;
function openWindow(theURL,winName,features) { //v2.0 */
	if (janela != null)
		{
			if (!janela.closed)
			{
				janela.close();
			}
		}	
  	janela = window.open(theURL,winName,features);
}
//************************************************BÍBLIA ONLINE
var no = /\D{1,}/;
expressao = "";
function livroSelect(myForm) {
   if (!no.test(myForm.lvBiblia.value)) {
    	expressao = "Testamento ou Livro\n"
   }   	
   if (!expressao){
       return true
   }
   else {
        expressao = "Informe:\n\n" + expressao
        alert(expressao)
        expressao=""
        return false
   }
}
//************************************************MOSTRA/ESCONDE - MENUS
function SwitchMenu(obj){
 if(document.getElementById){
 var el = document.getElementById(obj);
 var ar = document.getElementById("cont").getElementsByTagName("DIV");
  if(el.style.display == "none"){
   for (var i=0; i<ar.length; i++){
    ar[i].style.display = "none";
   }
   el.style.display = "block";
  }else{
   el.style.display = "none";
  }
 }
}
function mostra(idTag){
	var x = document.getElementById(idTag);
	x.className = "mostra";
}
function esconde(idTag){
	var x = document.getElementById(idTag);
	x.className = "esconde";
}
/* fim - funcao mostra/esconde */
function mudaCor (objetoReferencia, cor) {
		objetoReferencia.style.background = cor;
}
//***********************************************browser detect
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

//************************************************AJAX


Function.Empty = function( ) { };
function JsAjax( method, type, header ) {
	this.method = method||JsAjax.GET;
	this.type = type||JsAjax.TEXT;
	this.header = header||null;
}
// Submit types.
JsAjax.GET = "GET";
JsAjax.POST = "POST";
JsAjax.HEAD = "HEAD";
// Response Types.
JsAjax.TEXT = "text";
JsAjax.XML = "xml";
var _ms_XMLHttpRequest_ActiveX = "";
//Create the Request.
JsAjax.CreateHttpRequest = function() {
	
	var self = this;
	//alert(BrowserDetect.browser);
	//alert(BrowserDetect.version);
	//alert(BrowserDetect.OS);	
	
    // check the dom to see if this is IE or not
    if (window.XMLHttpRequest && !(BrowserDetect.browser == "Explorer" && BrowserDetect.version == "7")) {		
	// Not IE
        //self.AJAX = new XMLHttpRequest();
		try{return new XMLHttpRequest();}catch(exception){}		
		throw new Error("Browser não possui suporte ao Ajax.");		
    } else {	
	// Hello IE!
        // Instantiate the latest MS ActiveX Objects
        if (_ms_XMLHttpRequest_ActiveX) {            
			//self.AJAX = new ActiveXObject(_ms_XMLHttpRequest_ActiveX);			
			try{return new ActiveXObject(_ms_XMLHttpRequest_ActiveX);}catch(exception){}			
			throw new Error("Browser não possui suporte ao Ajax.");
        } else {			
	    // loops through the various versions of XMLHTTP to ensure we're using the latest
	    var versions = ["Msxml2.XMLHTTP.7.0", "Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP",
                        "Microsoft.XMLHTTP"];

            for (var i = 0; i < versions.length ; i++) {               
				/*try {
		    // try to create the object
		    // if it doesn't work, we'll try again
		    // if it does work, we'll save a reference to the proper one to speed up future instantiations
                    self.AJAX = new ActiveXObject(versions[i]);

                    if (self.AJAX) {
                        _ms_XMLHttpRequest_ActiveX = versions[i];
                        break;
                    }
                }
                catch (objException) {
                // trap; try next one
                } ;*/
				try{return new ActiveXObject(versions[i]);				
					_ms_XMLHttpRequest_ActiveX = versions[i];
					 break;
				}catch (objException) {
                // trap; try next one
                }
            }

            ;
        }
    }
	
	/*
	try{return new XMLHttpRequest();}catch(exception){}
	try{return new ActiveXObject("Msxml2.XMLHTTP" );}catch(exception){}
	try{return new ActiveXObject("Microsoft.XMLHTTP");}catch(exception){}
	throw new Error("Browser não possui suporte ao Ajax.");
	*/
}

/** Event's */
JsAjax.prototype.onSend = Function.Empty;
JsAjax.prototype.onUninitialized = Function.Empty;
JsAjax.prototype.onLoading = Function.Empty;
JsAjax.prototype.onLoaded = Function.Empty;
JsAjax.prototype.onComplete = Function.Empty;
JsAjax.prototype.onInteractive = Function.Empty;
JsAjax.prototype.onReadText = Function.Empty;
JsAjax.prototype.onReadXml = Function.Empty;
JsAjax.prototype.onError = function( strError ) { alert( strError ); }

/** Method's */
JsAjax.prototype.send = function( strUrl, objHeader, strContent ) {
	try {
		var handle = this;
		var request = JsAjax.CreateHttpRequest( );
		request.onreadystatechange = function( ) {
			switch ( request.readyState ) {
				case 0 : //uninitialized
					handle.onUninitialized( );
					break;
				case 1 : //loading
					handle.onLoading( );
					break;
				case 2 : //loaded
					handle.onLoaded( );
					break;
				case 3 : //interactive
					handle.onInteractive( );
					break;
				case 4 : //complete
					handle.onComplete( );
					if ( handle.type == JsAjax.XML && (request.status == 0 || request.status == 200) ) {
						handle.onReadXml( request.responseXml );
					} else if ( request.status == 0 || request.status == 200 ) {
						handle.onReadText( request.responseText );
					} else {
						handle.onError( "(" + request.status + ") Ajax request error." );
					}
					break;
			};
		}
		request.open( handle.method , strUrl, true );// Ajax (Async) -> true
		// Utiliza atributos de Header.
		if( typeof objHeader == "object" ) {
			for( var header in objHeader ) {
				request.setRequestHeader( header, objHeader[header] );
			}
		}
		handle.onSend( );
		request.send( strContent||false );
	} catch( exception ) {
		handle.onError( "AjaxError: " + exception.message );
	}
}
function fCarregaLista(url, idDestination, hide, show){
		var carregaLista = new JsAjax( );			
		carregaLista.divContent = document.getElementById(idDestination);
		carregaLista.onSend = function( ) {
			this.divContent.innerHTML = "<span class='ajaxLoadIco'><img src='layouts/images/ajax_load_snake.gif'> carregando...</span>";
			//this.divContent.innerHTML = "<span class='ajaxLoadIco'><img src='layouts/images/ajax_load_snake.gif'> Aguarde...</span>";
		}
		carregaLista.onComplete = function( ) {
			this.divContent.innerHTML = "<span class='ajaxLoadIco'><img src='layouts/images/ajax_load_snake.gif'> concluindo...</span>";
			//this.divContent.innerHTML = "<span class='ajaxLoadIco'><img src='layouts/images/ajax_load_snake.gif'> Processando...</span>";
			if(hide != ""){			
				hideById(hide);			
			}
			if(show != ""){			
				showById(show);			
			}
		}
		carregaLista.onError = function( strText ) {
			this.divContent.innerHTML = "<span class='ajaxLoadIco'><img src='layouts/images/ajax_load_snake.gif'> Desculpe, erro ao processar ação!</span>";
			
			if(hide != ""){			
				hideById(hide);			
			}
			if(show != ""){			
				showById(show);			
			}
			
		}
		carregaLista.onReadText = function( strText ) { // pode ser onReadXml
			this.divContent.innerHTML = strText;
		}
		carregaLista.send(url);
		carregaLista = null;		
		
}
function setLiAndLink( idUl,classNoSelected,classSelected,liSelect,url,idDestination, hide, show ){		
		if(hide != ""){			
			hideById(hide);			
		}
		if(show != ""){			
			showById(show);			
		}
		url = url + "&amp;tab=" + classSelected;
		var ullist=document.getElementById(idUl).getElementsByTagName("li");
		for (var i=0; i<ullist.length; i++)
		ullist[i].className=classNoSelected;	
		
		ullist[liSelect - 1].className=classSelected;
		fCarregaLista(url, idDestination, show, hide);
}
function setLiClassAndLoad( idUl,classNoSelected,classSelected,liSelect,url,idDestination){			
		//alert(liSelect);
		url = url + "&amp;tab=" + classSelected;
		var ullist=document.getElementById(idUl).getElementsByTagName("li");
		for (var i=0; i<ullist.length; i++)
		ullist[i].className=classNoSelected;		
		ullist[liSelect - 1].className=classSelected;
		fCarregaLista(url, idDestination, '', '');
}
//************************************************
function hideById(id){		
			document.getElementById(id).style.display = "none";			
}
function showById(id){		
			document.getElementById(id).style.display = "block";			
}
//*************************************************
//************************************************* SCRIPT ATIVACAO FLASH
//v1.0
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}

function close(x){
	var obj;
	obj = document.getElementById(x);
	obj.style.display = "none";
}
function show(x){
	var obj;
	obj = document.getElementById(x);
	obj.style.display = "block";
}

/* FUNCAO SELECT MENU */
function changeLocation(menuObj)
{
   var i = menuObj.selectedIndex;
   var url	
   if(i > 0)
   {
      url = menuObj.options[i].value;
	  window.open(url,"MenuPopup");
   }
}
/* FUNCAO SELECT MENU END */
