Num = Math.floor (Math.random()*1000000);
Num2 = Math.floor (Math.random()*1000000);
function ordem(){
  for(i = 0; i < ordem.arguments.length; i++){
    this.tagsPublicidade += '<scr'+'ipt src="'+ordem.arguments[i]+'"></scr'+'ipt>';
  }
}

var searchReq2 = getXmlHttpRequestObject();
var procurar = true;
var strold="";
var tipoold=0;
var tipo2old=0;
var resultados=new Array();
var sugestoes=false;
//Starts the AJAX request.

function strip_tags(v){
	var re=/<\S[^>]*>/g;
	v = v.replace(re,"");
	return v;
}

function texto_negrito(texto, tprocura)
{
	v=strip_tags(tprocura);
	v=tprocura.split(' ');
    for(n in v)
	{
	   pos=texto.toLowerCase().indexOf(v[n].toLowerCase());
	   if (pos != -1 && v[n].length > 1)
	   {
			t=texto.substring(0,pos);
			t+='<b>'+texto.substring(pos,pos+v[n].length)+'</b>';
			texto=t+texto.substring(pos+v[n].length);
	   }
	}
	return texto;
}


function ajax(str,tipo,sufixo) {

	    if(!str) var str = document.getElementById('q').value;
	    if(!tipo2) var tipo2 = document.getElementById('tipo2').value;
	    if(!tipo)
	    {
         var Radio=null;
         Radio= document.fp.onde;
         for(var controle=0;controle<Radio.length;controle++) {
          if(Radio[controle].checked) {
            var tipo = Radio[controle].value;
           }
         }
	    }
    	if(strold.length>str.length || str.indexOf(' ')!=-1 || tipoold!=tipo || tipo2old!=tipo2)
    	{
    	 procurar=true;
    	 sugestoes=false;
    	}
		strold=str;
		tipoold=tipo;
		tipo2old=tipo2;
    	if(sugestoes==true)
    	{
    	  var suggest ='';
	  	  var ss = document.getElementById('ajax');
	  	  var a=0;
	      for(i=1;i< resultados.length;i++)
	  	  {
	   		if(resultados[i][2].toUpperCase().indexOf(str.toUpperCase())!=-1)
	        {
	   		 a++;
	   		 suggest += '<li><a href="http://cifraclub.terra.com.br/cifras/' + resultados[i][0] + '/'+((!sufixo)?'':sufixo)+((resultados[i][1]!='')?resultados[i][1]+'/">':'">')+texto_negrito(resultados[i][2],str)+'</a></li>';
	   		}
	  	  }

	  if(a>0){
	  	ss.style.visibility='visible';
	  	ss.innerHTML = '<ul>'+suggest+'</ul><small>'+a+' resultado'+((a>1)?'s':'')+' (<a href="#"onclick="document.getElementById(\'fbs\').submit();">ver mais</a>)</small>';}
	  else{ ss.style.visibility='hidden';}
}
else {
	if (procurar&&(searchReq2.readyState == 4 || searchReq2.readyState == 0 && ((tipo==1 || tipo==2) && str.length > 0) )) {
		resultados=new Array();
		searchReq2.open("GET", '/ajax2.php?tipo='+tipo+'&tipo2='+tipo2+'&search=' + escape(str), true);
		searchReq2.onreadystatechange = handleSearchSuggest;
		searchReq2.send(null);
	}
}
}
//Called when the AJAX response is returned.
function handleSearchSuggest() {
	if (searchReq2.readyState == 4) {
         var ss = document.getElementById('ajax');
		ss.innerHTML = '';
		var p=document.getElementById('q').value;
		var suggest ='';
		var str = searchReq2.responseText.split("\n");
		var quan = str[0];
		if (quan > 0)
		{
		 ss.style.visibility='visible';
         for(i=1; i < str.length - 1; i++) {
           var texto = str[i].split("|");
		   suggest += '<li><a href="http://cifraclub.terra.com.br/cifras/'+texto[0]+'/'+((texto[1]!='')?texto[1]+'">':'">')+texto_negrito(texto[2],p)+'</a></li>';
		   if(quan<10)
		   {
		   	sugestoes=true;
		   	resultados[i]=new Array();
		    resultados[i][0]=texto[0];
		    resultados[i][1]=texto[1];
		    resultados[i][2]=texto[2];
		   }
         }
		}
		else
		{ss.style.visibility='hidden';
		 procurar=false;
		}

		ss.innerHTML = '<ul>'+suggest+'</ul><small>'+str[0]+' resultado'+((str[0]>1)?'s':'')+' (<a href="#"onclick="document.getElementById(\'fbs\').submit();">ver mais</a>)</small>';
	}
}
function anuncios(){
  this.tagsPublicidade="";
  this.ordem = ordem;
  this.mostra = function (){document.write(this.tagsPublicidade);}
}

function getXmlHttpRequestObject(){
	//verifica se o browser tem suporte a ajax
	try{
		return new ActiveXObject('Microsoft.XMLHTTP');
	}
	catch(e){
		try{
			return new ActiveXObject('Msxml2.XMLHTTP');
		}
		catch(ex){
			try{
				return new XMLHttpRequest();
			}
			catch(exc){
				alert('Esse browser não tem recursos para uso do Ajax');
				return null;
			}
		}
	}
}

function toggle_bt () {
	var ul = document.getElementById('lst-bcr');
	var classp = ul.getAttribute('class');
	if (classp.indexOf('on') == -1) {
		ul.innerHTML = '<style type="text/css">.lst-bcr a {background-image: url(http://stf.terra.com.br/portal/apps/headerfooter/_img/btn-navigation-v3.gif);}</style>' + ul.innerHTML;
		ul.className='lst-bcr on';
	}
	
	var bt = document.getElementById('bt');
	var classc = bt.getAttribute('class');
	if (classc == null || classc.indexOf('ativo') == -1) {
		bt.className+=' ativo';
	}
	else {
		bt.className=bt.className.replace(" ativo","");
	}
}

function verifica_tempo(antes, url){
	var da = new Date();
	var depois = da.getTime ();
	var total = depois - antes;
	var resolucao = screen.width+' x '+screen.height;
	var rand = Math.random();
	var url_array = new Array(
		'audioware.cifraclub.terra.com.br/',
		'audioware.cifraclub.terra.com.br/programas-5.html',
		'audioware.cifraclub.terra.com.br/programas-2.html',
		'audioware.cifraclub.terra.com.br/download-113-emule.html',
		'audioware.cifraclub.terra.com.br/download-96-digital-guitar-tuner.html'
	);
	for(var i = 0;i < 5;i++){
		if(url == url_array[i]){
			if(rand < 0.2){
				var searchReq = getXmlHttpRequestObject();
				searchReq.open('GET', '/lado_cliente.php?resolucao='+resolucao+'&total='+total+'&url='+url+'', true);
				searchReq.send(null);
			}
		}
	}
}

anuncioEsquerda = new anuncios();
anuncioDireita = new anuncios();
anuncioMiolo = new anuncios();
anuncioRodape = new anuncios();

espacador = "http://www.terra.com.br/ads/espaco.js";
superbanner = "http://ad.doubleclick.net/adj/br.terra.cifraclub/audioware;dcopt=ist;sz=728x90;kw=top;ord="+Num2+"?";
quadrado =  "http://ad.doubleclick.net/adj/br.terra.cifraclub/audioware;dcopt=ist;sz=300x250;ord="+Num+"?";

anuncioDireita.ordem(quadrado);
anuncioMiolo.ordem(superbanner);
anuncioRodape.ordem();


//Destaque
var index = 1; 
var menu_time = 6000; 
var anterior = 4; 
var timer = setTimeout('trocaMsg()',menu_time); 
function trocaMsg() { 
	index = index%4 +1; 
	channel(index); 
	tempo(); 
}          
function tempo() { 
	clearTimeout(timer);	
	timer = setTimeout("trocaMsg()",menu_time);
}
function channel(id) { 
	index = id; 
	document.getElementById("menu_" + anterior).className= ""; 
	document.getElementById("menu_" + id).className = "ativo"; 
	document.getElementById('tit_dest').innerHTML=document.getElementById('tit_' + id).innerHTML;
	document.getElementById('ds_dest').innerHTML=document.getElementById('ds_' + id).innerHTML;	
	anterior = id;
}
function trocaDestaque(id, out) {
	if (out == 1)	{ 
		clearTimeout(timer);	
		channel(id);} 
	else { 
		tempo();
	}
}