

var ultimo = null;
var posi = 0;
var cnt  = 0;



//variante_combin = new Array(); 
//variante_traste = new Array(); 

CX=new Array(516,523,529,536,542,549,
			 482,489,495,502,508,515,
			 451,458,465,471,478,485,
			 423,430,437,445,452,459,
			 394,401,409,416,424,431,
			 370,378,385,393,400,408,
			 344,352,360,368,376,384,
			 321,329,337,345,353,361,
			 299,307,315,323,331,339,
			 280,288,296,305,313,321,
			 261,269,277,286,294,302,
			 242,250,259,267,276,284,
			 225,233,242,250,259,267,
			 209,217,226,235,243,252,
			 194,203,211,220,228,237,
			 178,187,196,204,213,222,
			 165,174,183,191,200,209,
			 152,161,170,179,188,197,
			 140,149,158,167,176,185,
			 128,137,146,156,165,174,
			 118,127,136,146,155,164,
			 107,116,125,135,144,153);

CY=new Array(335,342,348,355,361,368,
			 365,372,378,385,391,398,
			 398,405,412,418,425,432,
			 424,431,438,446,453,460,
			 452,459,467,474,482,489,
			 476,484,491,499,506,514,
			 499,507,515,523,531,539,
			 523,531,539,547,555,563,
			 543,551,559,567,575,583,
			 563,571,579,588,596,604,
			 582,590,598,607,615,623,
			 599,607,616,624,633,641,
			 616,624,633,641,650,658,
			 632,641,649,658,666,675,
			 646,655,663,672,680,689,
			 661,670,679,687,696,705,
			 674,683,692,700,709,718,
			 686,695,704,713,722,731,
			 697,706,715,724,733,742,
			 709,718,727,737,746,755,
			 719,728,737,747,756,765,
			 730,739,748,758,767,776
			);

CNX=new Array(534,594,621,648,675,702);
CNY=new Array(306,250,235,220,205,190);

var cntimg = 0;
var imageName = "guit1.jpg";
var counters = new Array("guit1.jpg","guit2.jpg","guit4.jpg","guit5.jpg","guit6.jpg","guit7.jpg","guit12.jpg","guit21.jpg","guit22.jpg","guit23.jpg","guit24.jpg","guit25.jpg","guit26.jpg","guit27.jpg","guit28.jpg","guit29.jpg","guit30.jpg","guit32.jpg","guit33.jpg","guit34.jpg");
 
function swapImg(el) {
if (cntimg == 19)
 cntimg = 0;
else
 cntimg = cntimg + 1;

el.src = counters[cntimg];
imageName = counters[cntimg];
}

function AsignoGuitarra(nombre){
var imagen;
imagen = document.getElementById('gt');
imagen.src = nombre;
imageName = nombre;
}


function dibujar(val){ 

var combi ; 
var trast ; 
var c1; 
var Dibujo = true; 
var posicion = -1; 
var posx; 
var posy; 
var posx1; 
var posy1; 
var ini; 
var fin; 
var resX = -83;
var resY = 0;
var acordev= '-';
var minimo ;
var hay1 = false;
var agt=navigator.userAgent.toLowerCase();
if (agt.indexOf("safari") != -1 || agt.indexOf("opera") != -1) resY = -12;

jg.clear();
jg.setColor("#ea1616"); 
jg.setFont("arial","18px",Font.ITALIC_BOLD);
combi = variante_combin[val]; 
trast = variante_traste[val]; 
c1 = 0; 
//determinar si hay 1
for (x = 1; x <= 6; x++) 
   if (combi.substring(x-1,x) == "1" ){hay1 = true; break;}
   
for (x = 1; x <= 6; x++) 
 { 
  switch (combi.substring(x-1,x)) { 
    case "X":  acordev = acordev + 'X-'; break; 
    case "1": posicion =  (parseFloat(trast) - 1) + parseFloat(combi.substring(x-1,x));  c1 = c1 + 1; 
	          acordev = acordev + posicion.toString() + '-'; hay1= true; break;
    case "2": posicion =  (parseFloat(trast) - 1) + parseFloat(combi.substring(x-1,x));  c1 = c1 + 1; 
	          acordev = acordev + posicion.toString() + '-'; break;
    case "3": posicion =  (parseFloat(trast) - 1) + parseFloat(combi.substring(x-1,x));  c1 = c1 + 1;
	          acordev = acordev + posicion.toString() + '-'; break;
    case "4": posicion =  (parseFloat(trast) - 1) + parseFloat(combi.substring(x-1,x));  c1 = c1 + 1; 
	          acordev = acordev + posicion.toString() + '-'; break;
    case "5": posicion =  (parseFloat(trast) - 1) + parseFloat(combi.substring(x-1,x));  c1 = c1 + 1; 
	          acordev = acordev + posicion.toString() + '-'; break;
    case "6": posicion =  (parseFloat(trast) - 1) + parseFloat(combi.substring(x-1,x));  c1 = c1 + 1;
	          acordev = acordev + posicion.toString() + '-'; break;
    default:  Dibujo  = false; acordev = acordev + '0-'; break;
    }
 if (Dibujo) { 
   if (combi.substring(x-1,x) == "X"){ 
	  if (hay1)
	     minimo = 0;
	  else
	     minimo = 1;
	  posx = CX[(((parseFloat(trast) -1 + minimo) * 6) + x) - 1] + resX;  
      posy = CY[(((parseFloat(trast) -1 + minimo) * 6) + x) - 1] + resY - 10; 
      jg.drawString("x",posx,posy); 
      jg.paint(); 
      } 
   else { 
      posx = CX[(((posicion - 1) * 6) + x) - 1] + resX;  
      posy = CY[(((posicion - 1) * 6) + x) - 1] + resY; 
      jg.fillEllipse(posx,posy,7,7); 
      jg.paint(); 
      } 
}
Dibujo = true; 
} 
// mirar si hay que dibujar cejilla ';
if (c1 > 4) { 
 for (x= 1; x<=6; x++){ 
   ini = combi.indexOf(x.toString()); 
   if (ini != -1) break; 
 } 
 posicion = (parseFloat(trast) - 1) + parseFloat(combi.substring(ini,ini+1)); 
 posx = CX[(((posicion - 1) * 6) + ini)] + resX; 
 posy = CY[(((posicion - 1) * 6) + ini)] + resY;  

 fin = combi.lastIndexOf(x.toString()); 
 posicion = (parseFloat(trast) - 1) + parseFloat(combi.substring(fin,fin+1)); 
 posx1 = CX[(((posicion - 1) * 6) + fin)] + resX; 
 posy1 = CY[(((posicion - 1) * 6) + fin)] + resY;   

 jg.setStroke(7);  
 jg.drawLine(posx, posy, posx1, posy1);  
 jg.paint(); 
} 
// Dibujar texto de la combinación
jg.setFont("arial","14px",Font.ITALIC_BOLD);
jg.drawString(acordev,770,80);
jg.paint(); 
} 



function ActDes(sn){
document.getElementById('mayor').disabled = sn;
document.getElementById('menor').disabled = sn;
document.getElementById('domin').disabled = sn;
document.getElementById('mayor1').disabled = sn;
document.getElementById('menor1').disabled = sn;
document.getElementById('septima').disabled = sn;
document.getElementById('dim').disabled = sn;
document.getElementById('sus2').disabled = sn;
document.getElementById('sus4').disabled = sn;
} 

function resetCombos(){
if (ultimo != null && ultimo.name != 'nota') 
 ultimo.selectedIndex = 0;
 
}

var nt = '';
function getCombo(sel) {
if (sel.name == "nota") {
   nt = sel.options[sel.selectedIndex].text;
   if (sel.selectedIndex > 0){
     ActDes(false);
	 }
  else
    ActDes(true);
}

  var adi = '';
  var valor = sel.options[sel.selectedIndex].text;
  switch (sel.name) {
  case "mayor1"  : adi = 'M'; break;
  case "menor1"  : adi = 'm'; break;
  case "septima" : adi = '7'; break;
  case "aum"     : adi = 'aum'; break;
  case "dim"     : adi = 'dim'; break;
  case "sus2"    : adi = 'sus2'; break;
  case "sus4"    : adi = 'sus4'; break;
  }
  totcadena = nt + adi + valor;  

if (ultimo != null && sel.name != 'nota') {
 cogervalor(totcadena);
}
// resetear el resto de combos
resetCombos();	
ultimo = sel;
}

function cogervalor(vl){
document.getElementById('criterio').value = vl + ',' +  imageName; 
auto();
}

function auto() {
   document.myform.submit();
}
 
