leftX = 0
var arrAcordes = new Array()
var arrPosAcorde = new Array()

var arrAcordes_teclado = new Array()
var arrPosAcorde_teclado = new Array()


function desenhaTeclado(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') return

//strAcorde = '1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33' //(strAcorde)
strAcorde = le(strAcorde)


spanAcorde = eval ("document.all.acorde" + spanId)
spanNotas = eval ("document.all.notas" + spanId)
arrAcorde = strAcorde.split(' ')
acorde = '<table border=0><tr><td> <br><table width=205 height=55 border=0 cellpadding="0" cellspacing="0"><tr height=68><td width=3><img src="images/teclado.png"></td></tr></table></td></tr></table>'
notas = '<table border=0><tr><td> <a href=""><b>' + Titulo + '</b></a><br><table width=205 height=68 border=0 cellpadding="0" cellspacing="0"><tr height=68><td width=3></td>'
posArray = 0
tecla = 0
for (n=1; n<=33; n++){
if (n != 6 && n != 14 && n!= 20 && n!= 28) tecla ++
if (tecla == 13) tecla = 1
if (tecla==parseInt(arrAcorde[posArray])){
if (tecla == 2 || tecla == 4 || tecla == 7 || tecla == 9 || tecla == 11)
{notas += '<td align=right width=6><br><img src=images/o_branco2.gif><br><br><br></td>'}
else
{notas += '<td align=right width=6><br><br><br><img src=images/o_preto.gif></td>'}
posArray ++}
else
{notas += '<td align=right width=6></td>'}}
notas += "<td width=6></td></tr></table></td></tr><tr><td colspan=33 align=center>"
//if (spanId != 1000 && arrAcordes[spanId - 1].length > 1) 
//{notas += '<a style=cursor:hand onClick=\'variaTeclado(' + spanId + ',\"' + Titulo + '\")\' class=font1>variation</a>'}
//else
notas += " "
notas += "</td></tr></table>"
if (spanId != 1000) {
spanAcorde.style.left = leftX + 15;
spanNotas.style.left = leftX + 17}
spanAcorde.innerHTML = acorde;
spanNotas.innerHTML = notas;
leftX += 220
if (leftX == 660) leftX = 0}

stop=1;
function NN2(){
if(stop==1){return false;}
}
function IE4(){
if(stop==1){event.returnValue=false;}
}

if(document.layers){
	window.captureEvents(Event.MOUSEDOWN);
	window.onselectstart=NN2;
}
if(document.all){
	document.onselectstart=IE4;
}

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,  "S" , "0")
	rtxt = replaceSubstring(rtxt, "A" , "1")
	rtxt = replaceSubstring(rtxt, "D" , "2")
	rtxt = replaceSubstring(rtxt, "F" , "3")
	rtxt = replaceSubstring(rtxt, "G" , "4")
	rtxt = replaceSubstring(rtxt, "H" , "5")
	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){
dc = document.referrer
//if (dc.substring(0,20) != "http://cifras.com.br" && dc.substring(0,25) != 'http://www.tocando.com.br' && dc !='' && dc.substring(0,24) != "http://www.cifras.com.br" && dc.substring(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><b class=black>" + (min == 1 ? "" : min ) + "</b></td><td class='smalltext'><b>" + Titulo + "</b><br>"
acorde +="<img src='images/braco.gif'>"
acorde +="<table border=0 width=65 cellpadding=0 cellspacing=0 height=20>"
acorde +="</table>"
notas = "<br><img height=3><br><table border=0 cellpadding=0 cellspacing=0 width=66 height=85>"
dedo = 1
for (traste = min; traste <= min + 4; traste ++)
{
notas +="<tr height=16>"
pestana = false
trasteVazio = true;
for (corda = 0; corda <= 5; corda ++)
{
notas +="<td width=11 height=16 valign=bottom>" 
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 ++}
}else{
//notas += "<img width=1 height=14>"
}
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 += "<tr><td colspan=6><a href='personal_library.asp?addchord=" + replaceSubstring(replaceSubstring(Titulo, '+', '%2B'), '#','%23') + "&addfing=" + strAcorde + "' class=font1><img border=0 src='images/expand.gif' align=absmiddle alt='click to remove this chord'></a></td></tr>";

notas +="</table>"
spanAcorde.style.left = leftX;
spanAcorde.innerHTML = acorde;
spanNotas.style.left = leftX + 20;
spanNotas.innerHTML = notas;
leftX += 120
if (leftX == 480) leftX = 0
}


function desenhaCavaquinho(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><b>" + (min == 1 ? "" : min ) + "</b></td><td class='smalltext'><b><a class=acorde style='cursor:hand'>" + Titulo + "</a></b><br>";
acorde +="<img src='images/cavaq.gif'>"

//if (spanId != 1000 && arrAcordes[spanId - 1].length > 1) {
acorde +="<table border=0 width=48 cellpadding=0 cellspacing=0 height=20>"
//acorde +="<tr><td colspan=2 align=center><br><a style=cursor:hand class=smalltext onClick=\"variaAcorde(" + spanId + ", ",",",",",",",",'" + Titulo + "');\">variação</a></td></tr></table>"}
acorde +="<tr><td colspan=2 align=center><br></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=52 height=85>"
dedo = 1
//-----

for (traste = min; traste <= min + 4; traste ++){
notas +="<tr height=16>"
pestana = false
trasteVazio = true;
for (corda = 0; corda <= 3; corda ++){
notas +="<td width=13 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=13 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=13 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 += 80
if (leftX == 640) leftX = 0


}
