// JavaScript Document
var AsSelf = new Array(15)
var AsSelfr = new Array(15)
var AsSelc = new Array(15)
var AsSelcr = new Array(15)
var AsValor= new Array(15)

UltAsSel = 0
UltAsSelNN = 0
imagen1=new Image
imagen1.src="iconos/libre16.jpg"
imagen2=new Image
imagen2.src="iconos/seleccionado16.jpg"
var i=1

function ApuntarNoNum(asiento,fila,filareal,columna,columnareal) {
	if (UltAsSelNN<15){
		AsValor[UltAsSelNN+1]=asiento
		AsSelf[UltAsSelNN+1]=fila
		AsSelfr[UltAsSelNN+1]=filareal
		AsSelc[UltAsSelNN+1]=columna
		AsSelcr[UltAsSelNN+1]=columnareal
		UltAsSelNN=UltAsSelNN+1
		
		AsValor[UltAsSelNN+1]=0
		AsSelf[UltAsSelNN+1]=0
		AsSelfr[UltAsSelNN+1]=0
		AsSelc[UltAsSelNN+1]=0
		AsSelcr[UltAsSelNN+1]=0
	}
}
   
function cambiar(asiento,fila,filareal,columna,columnareal) {
	var encontrado=0;
	for (k=1;k<=11;k++)
		{
		if (AsValor[k]==asiento)
			{
			encontrado=1
			aux=k
			k=20
			}
		}
	if (encontrado==0)
		{
		if (UltAsSel==0)
			{
			if (UltAsSel<10)
				{
				document.images[asiento].src=imagen2.src

				
				AsValor[UltAsSel+1]=asiento
				AsSelf[UltAsSel+1]=fila
				AsSelfr[UltAsSel+1]=filareal
				AsSelc[UltAsSel+1]=columna
				AsSelcr[UltAsSel+1]=columnareal
				UltAsSel=UltAsSel+1
				//window.alert(UltAsSel)
				}
			else
				{
				window.alert("No se pueden seleccionar mas de 10 asientos")
				}
			}
		else
			{
			if (AsSelf[UltAsSel]==fila && contiguo(columna, UltAsSel)==1)
				{
				if (UltAsSel<10)
					{
					document.images[asiento].src=imagen2.src
					AsValor[UltAsSel+1]=asiento
					AsSelf[UltAsSel+1]=fila
					AsSelfr[UltAsSel+1]=filareal
					AsSelc[UltAsSel+1]=columna
					AsSelcr[UltAsSel+1]=columnareal
					UltAsSel=UltAsSel+1					
					}
				else
					{
					window.alert("No se pueden seleccionar mas de 10 asientos")
					}
				}
			else
				{
				window.alert("Los asientos deben ser contiguos y en la misma fila")
				}
			}
		}
	else
		{
		document.images[asiento].src=imagen1.src
		for (k=aux;k<11;k++)
			{
			AsValor[k]=AsValor[k+1]
			AsSelf[k]=AsSelf[k+1]
			AsSelfr[k]=AsSelfr[k+1]
			AsSelc[k]=AsSelc[k+1]
			AsSelcr[k]=AsSelcr[k+1]
			}
		UltAsSel=UltAsSel-1
		//window.alert(UltAsSel)			
		AsValor[11]=0
		AsSelf[11]=0
		AsSelfr[11]=0
		AsSelc[11]=0
		AsSelcr[11]=0
		}

   }
   
function contiguo(columna, ultimo){
	var j=1
	var contiguo=0
	for (j=1;j<=ultimo;j++){
		if (AsSelc[j]==columna+1 || AsSelc[j]==columna-1)
			{
			contiguo=1
			}
		}	
	return contiguo
	}
	
function MuestraSel(){
	var j=1
	for (j=1;j<11;j++){
		document.write(AsSelf[j])
		document.write(AsSelc[j])
		document.write("XX")
		}
	}
	
function incrementar(){
	if (counter<8){
		counter++;
	}
	contador.innerHTML=counter;	
	//document.getElementsByName("contador").value=counter;
	//alert("H");
}
function decrementar(){
	if (counter>1){
		counter--;
	}
	contador.innerHTML=counter;
	//document.getElementsByName("contador").value=counter;
}
	
function IniciarVenta(cine,sesion){
	var j=1
	if (UltAsSel!=0){
		window.status="Procesando"
		window.top.location.href="preparadatos.php?UltAsSel="+UltAsSel+"&AsSelf="+AsSelf+"&AsSelfr="+AsSelfr+"&AsSelc="+AsSelc+"&AsSelcr="+AsSelcr+"&Cine="+cine+"&Sesion="+sesion;
	}

}

function IniciarVenta2(){
	var j=1
	if (UltAsSel!=0){
		window.status="Procesando"
		window.top.location.href="preparadatos2.php?UltAsSel="+UltAsSel+"&AsSelf="+AsSelf+"&AsSelfr="+AsSelfr+"&AsSelc="+AsSelc+"&AsSelcr="+AsSelcr
	}

}

function IniciarVentaNoNum(cine,sesion){
	var j=1
	window.status="Procesando"
	window.top.location.href="preparadatosNoNum.php?NumBut="+counter+"&UltimaButaca="+UltAsSelNN+"&AsSelf="+AsSelf+"&AsSelfr="+AsSelfr+"&AsSelc="+AsSelc+"&AsSelcr="+AsSelcr+"&Cine="+cine+"&Sesion="+sesion;
	
	}
	
function IniciarVentaEventos(cine,sesion){
	var j=1
	window.status="Procesando"
	window.top.location.href="../preparadatoseventos.php?NumBut="+counter+"&UltimaButaca="+UltAsSelNN+"&AsSelf="+AsSelf+"&AsSelfr="+AsSelfr+"&AsSelc="+AsSelc+"&AsSelcr="+AsSelcr+"&Cine="+cine+"&Sesion="+sesion;
	
	}
