// JavaScript Document

function buscar_select(form,cadena,b){

  elementos = form.length;
  pos=0;
  
  for(i=0; i<elementos; i++){
  	text=form.options[i].text;
	valor=form.options[i].value;
	
	if(b==null || b==""){
		//buscamos por una cadena
		if(text == cadena){
			pos=i;
		}
		
	}else{
		//buscamos por un valor
		if(valor == cadena){
			pos=i;
		}
		
	}
	
  }

  form.selectedIndex = pos;

}


function popup(url,ancho,alto,barra){
	//barra use flag 0 or 1
	window.open(url, 'pubpopup', 'toolbar=0,location=0,status=0,menubar=0,scrollbars='+barra+',height='+ancho+',width='+alto);
	document.getElementById("x__idPaquete").value="";
}


function menu(pagina){
	location.href='index.php?op='+pagina;
}


function calculaTotal(){
	
	precio=document.formul.x__precio.value;
	meses=document.formul.x__PeriodoPago.value;
	descuento=document.formul.x__descuento.value;
	
	if(descuento==0 || descuento==null){
		descuento=0;
	}
	
	importe=precio*meses;
	descuentos=descuento * importe / 100;
	total=importe-descuentos;
	
	document.formul.importe.value=total;

}


function layer(){
//visible|hidden|collapse
var opcion=document.getElementById('recurrencia')[document.getElementById('recurrencia').selectedIndex].value;

	if(opcion==0){
		document.getElementById('RECURR').style.visibility='hidden';
		document.getElementById('NORECURR').style.visibility='hidden';
	}

	if(opcion==1){
		document.getElementById('RECURR').style.visibility='hidden';
		document.getElementById('NORECURR').style.visibility='visible';
		document.getElementById('x__prefijo').style.visibility='visible';
		document.getElementById('x__numero').style.visibility='visible';
	}
	
	if(opcion==2){
		document.getElementById('RECURR').style.visibility='visible';
		document.getElementById('NORECURR').style.visibility='hidden';
		document.getElementById('x__prefijo').style.visibility='hidden';
		document.getElementById('x__numero').style.visibility='hidden';
	}

}


function eliminar(tabla,campo,id){

 pregunta=confirm('Esta realmente seguro?\nSi continua no podrá deshacer la operacion...');
 
 if(pregunta==true){
	 location.href='index.php?op=eliminar&tabla='+tabla+'&campo='+campo+'&id='+id;
 }
}


function gotourl(form,pagina){
	var indice = form.selectedIndex 
    var valor = form.options[indice].value
    location.href=pagina+valor;
}

function gotourl2(form,pagina){
    var valor = form.value
    location.href=pagina+valor;
}



function winopen(url,w,h,barra){

if (barra=="yes"){
	barra="yes";
}else{
	barra="no";
	}

window.open(url,'ventana','toolbar=no,status=no,menubar=no,location=no,directories=no,resizable=no,scrollbars='+barra+',width='+w+',height='+h+',left=20,top=20');
}