//-------------------------------------------------------------------------- //
// Este script está registrado no Registro de Títulos e Documentos           //
// de Petrópolis / RJ Protocolado no livro nº 35101 livro B13 selo RDT50443  //
// A cópia não autorizada deste script acarretará em ação judicial (art 127) // 
// Desenvolvido por Peter M Jordan - tocando@tocando.com.br                  //
//-------------------------------------------------------------------------- //




































function derivacoes(chord)
{
chord = replaceChars(chord, '+', '%2b')
chord = replaceChars(chord, '#', '%23')
window.open('frm_dicionario.asp?acorde=' + chord, 'deriva', 'width=500, height=600')
}
function replaceChars(entry, out, add)
 {
	temp = ""  + entry;
	while (temp.indexOf(out)>-1) {
	pos= temp.indexOf(out);
	temp = "" + (temp.substring(0, pos) + add + temp.substring((pos + out.length), temp.length));
	}
	return temp;
}

function variaAcorde(spanId, Titulo)
{
	totalAcordes = arrAcordes[spanId - 1].length
	arrPosAcorde[spanId - 1] = (((arrPosAcorde[spanId - 1] + 1) >= totalAcordes) ? 0 : arrPosAcorde[spanId - 1] + 1);
	strAcorde = arrAcordes[spanId - 1][arrPosAcorde[spanId - 1]] 
	leftX = ((spanId % 6) == 0 ? 6 * 100 : (spanId % 6) * 100) - 100
	desenhaAcorde(spanId, Titulo, strAcorde)
}
function replaceSubstring(inputString, fromString, toString) {
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { 
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { 
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } 
	     while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } 
   return temp; 
} 


function le(txt)
{
	rtxt = replaceSubstring(txt,  "A" , "2")
	rtxt = replaceSubstring(rtxt, "S" , "3")
	rtxt = replaceSubstring(rtxt, "D" , "0")
	rtxt = replaceSubstring(rtxt, "F" , "1")
	rtxt = replaceSubstring(rtxt, "G" , "5")
	rtxt = replaceSubstring(rtxt, "H" , "4")
	rtxt = replaceSubstring(rtxt, "J" , "6")
	rtxt = replaceSubstring(rtxt, "K" , "7")
	rtxt = replaceSubstring(rtxt, "L" , "8")
	rtxt = replaceSubstring(rtxt, "O" , "9")
	return rtxt
}
function desenhaAcorde(spanId, Titulo, strAcorde){
if (document.referrer  != '' && document.referrer.substr(0, 25) != 'http://www.tocando.com.br' && document.referrer.substr(0, 24) != 'http://www.cifras.com.br' && document.referrer.substr(0, 20) != 'http://cifras.com.br' && document.referrer.substr(0, 21) != 'http://tocando.com.br') return
//strAcorde = le(strAcorde)
spanAcorde = eval ("document.all.acorde" + spanId)
spanNotas = eval ("document.all.notas" + spanId)
arrAcorde = strAcorde.split(' ')
var min = 100
var max = toques = 0
var bolTonica = true
for (n = 0; n < arrAcorde.length; n++){
arrAc = arrAcorde[n]
if (arrAc != "X"){
if (arrAc != "0" && parseInt(arrAc) < min) min = parseInt(arrAc)
if (parseInt(arrAc) > max) max = parseInt(arrAc)
if (arrAc.substring(0,1) != "P" && arrAc != "0") toques ++
if (bolTonica) {tonica = n; bolTonica = false;}}}
var primeiroTraste = min
if (max <=5) min = 1
acorde = "<table border=0><tr><td width=17 valign=top align=right class=smalltext><br>" + (min == 1 ? "" : min + "ª") + "</td><td class='smalltext'><b><a class=acorde style='cursor:hand' onMouseOut='closeAcorde()' onMouseOver='acordeClassico(\"" + Titulo  + "\")' onclick='derivacoes(\"" + Titulo  + "\")'>" + Titulo + "</a></b>" + ((print==0) ? "<img onClick=ouvir(\"" + Titulo  + "\") src=images/ouvir.gif><br>" : "<br>");
acorde +="<img src='images/viola.gif'>"
if (spanId != 1000 && arrAcordes[spanId - 1].length > 1) {
acorde +="<table border=0 width=54 cellpadding=0 cellspacing=0 height=20>"
acorde +="<tr><td colspan=2 align=center><br><a style='cursor:hand' class=smalltext onClick=\"variaAcorde(" + spanId + ", '" + Titulo + "');\">variation</a></td></tr></table>"}
acorde +="</td></tr><tr><td></td><td> </td</tr></table>"
notas = "<br><img height=3><br><table border=0 cellpadding=0 cellspacing=0 width=55 height=85>"
dedo = 1
for (traste = min; traste <= min + 4; traste ++){
notas +="<tr height=16>"
pestana = false
trasteVazio = true;
for (corda = 0; corda <= 4; corda ++){
notas +="<td width=11 valign=bottom height=16>" 
posPestana = (arrAcorde[corda]  == "P" + traste)
if (arrAcorde[corda] == traste || pestana || posPestana){
trasteVazio = false;
if ((toques > 4 && traste == primeiroTraste) || pestana || posPestana){
if (!pestana) dedo ++
pestana = true
notas += "<img src='images/pestana.bmp' width=11 height=3 align=top>"}
else
{notas += "<img src=images/" + dedo + ".gif align=absmiddle>"; dedo ++}}
notas += "</td>"} 
if (trasteVazio && dedo > 1 && dedo < 3 && toques <4) dedo ++
notas +="</tr>"}
notas +="<tr height=16>"
for (n = 0; n < arrAcorde.length; n++){
notas += "<td width=11 class='smalltext' align=center>" + (arrAcorde[n] == "X" ? "<img src='images/x.gif' align=absmiddle>" : (tonica == n ? "<img src='images/o_minusculo.gif' align=absmiddle>" :"<img src='images/o_minusculo2.gif' align=absmiddle>")) + "</td>"}
notas +="</tr>"
notas +="</table>"
spanAcorde.innerHTML = acorde;
if (spanId != 1000) {
spanAcorde.style.left = leftX + 30;
spanNotas.style.left = leftX + 20 + 30;}
spanNotas.innerHTML = notas;
leftX += 100
if (leftX == 600) leftX = 0}

function ouvir(pAcorde){
for (n = 0; n < arrDesenhos.length; n++)
{ if (pAcorde == arrDesenhos[n]) {digitacao = le(arrAcordes[n][arrPosAcorde[n]]); break;} }
arrDig = digitacao.split(' ');digitacao = '';
for (n=arrDig.length - 1; n>=0; n--){digitacao += arrDig[n] + ' ';};digitacao = replaceSubstring(digitacao, 'X', '-1');	digitacao = replaceSubstring(digitacao, ' ', ':');parent.som.location = 'http://www.wholenote.com/cgi-bin/cpb.pl?pitches=' + digitacao + '&patch=3'}

function closeAcorde(){
acorde2000.innerHTML = ''
notas2000.innerHTML = ''}
function acordeClassico(pAcorde)
{
for (n=0; n< arrDesenhos.length; n++){if (pAcorde == arrDesenhos[n] || pAcorde == arrDesenhos[n]) break	}
totalAcordes = arrAcordes[n].length
digitacao = arrAcordes[n][arrPosAcorde[n]] 
digitacao = le(digitacao.replace('P', ''))
spanAcorde = eval ("document.all.acorde2000" )
spanNotas = eval ("document.all.notas2000" )
arrAcorde = digitacao.split(' ')
var min = 100
var max = toques = 0
var bolTonica = true
for (n = 0; n < arrAcorde.length; n++){
arrAc = arrAcorde[n]
if (arrAc != "X"){
if (arrAc != "0" && parseInt(arrAc) < min) min = parseInt(arrAc)
if (parseInt(arrAc) > max) max = parseInt(arrAc)
if (arrAc.substring(0,1) != "P" && arrAc != "0") toques ++
if (bolTonica) {tonica = n; bolTonica = false;}
}}
var primeiroTraste = min
if (max >= 6) primeiroTraste = min - 1; else primeiroTraste=0
acorde = '<table width=280 bgcolor=#F9F9F9 cellpadding=0 cellspacing=0 border=0><tr><td align=center><br><img src="images/viola.png"><br><br></td></tr></table>'
spNotas = '<table cellpadding=0 cellspacing=0 border=0>'
spNotas += '<tr height=18><td width=46></td><td width=46></td><td width=46></td><td width=46></td>'
if (max >= 6) spNotas += '<td width=46 valign=bottom><b>' + (primeiroTraste+1) + 'ª</b></td></tr>'; else spNotas += '<td width=46></td></tr>'
for (corda = 0; corda <= 4; corda ++)
{
	//alert(parseInt(arrAcorde[corda]))
	spNotas += '<tr height=18>'
	for (traste = 5; traste>= 0; traste--)
	{
		spNotas += '<td width=46>'
		if ( parseInt(arrAcorde[corda]) == 0 && traste==0) spNotas += '<img src=images/o_minusculo2.gif>'
		else if ( parseInt(arrAcorde[corda] - primeiroTraste) == traste ) spNotas += '<img src=images/solta.gif>'
		else if ( arrAcorde[corda] == "X" && traste == 0 ) spNotas += '<img src=images/x.gif>'
		spNotas += '</td>'
	}
	spNotas += '</tr>'
}
spNotas += '</table>'
spanAcorde.innerHTML = acorde;
spanNotas.innerHTML = spNotas;
spanNotas.style.top = window.event.y+document.body.scrollTop - 128
spanAcorde.style.top = window.event.y+document.body.scrollTop - 120
spanNotas.style.left = window.event.x + 40
spanAcorde.style.left = window.event.x + 10
spanAcorde.style.filter = 'progid:DXImageTransform.Microsoft.Shadow(direction=130,color=gray,strength=8);'
}

-->
