function JS_Redireccionar(url) {
	document.location.href = url;
}
function JS_RemplazarStr(str, esto, porEsto) {
	if (str == "") {	return ""; }
	return str.replace(esto, porEsto); 
}
function JS_GetNum(str) {
	if ((str==undefined) || (str=="")) { str="0"; }
	return parseFloat(str.replace(",", ".")); 
}
function JS_FormatNum(num, numDecimales) {
	return num.toFixed(numDecimales);
}
function JS_FormatMonedaStr(num) {
	return JS_FormatMoneda(num).replace(".", ","); 
}
function JS_FormatMoneda(num) {
	return num.toFixed(2);
}
function JS_FormatMonedaComa(num) {
	return JS_RemplazarStr(JS_FormatMoneda(num), ".", ",");
}
function JS_GetNumMoneda(str) {
	return JS_FormatMoneda(JS_GetNum(str));
}
function JS_AutoFormat(id) {
	return JS_Value(id, JS_FormatMonedaComa(JS_GetNum(JS_GetValue(id))));
}
function JS_AutoFormatMe(r) {
	r.value = JS_FormatMonedaComa(JS_GetNum(r.value));
}
function JS_SetNum(num) {
	return JS_Round(num).toString().replace(".", ","); 
}
function JS_Round(num) {
	return Math.round(num*100)/100; 
}
function JS_NS4() {   	return (document.layers); }
function JS_NS6() {   	return (document.getElementById); }
function JS_IE() {		return (document.all); }
function JS_GetPP(layerID) {
	if (JS_NS4()) {		return eval('window.parent.parent.document.' + layerID); }
	if (JS_NS6()) {		return eval('window.parent.parent.document.getElementById("' + layerID + '")'); }
	if (JS_IE()) {		return eval('window.parent.parent.document.all.' + layerID); }
}
function JS_GetPPS(layerID) {
	if (!JS_GetPP(layerID)) { return null; } 
	if (JS_NS4()) {		return eval('window.parent.parent.document.' + layerID); }
	if (JS_NS6()) {		return eval('window.parent.parent.document.getElementById("' + layerID + '").style'); }
	if (JS_IE()) {		return eval('window.parent.parent.document.all.' + layerID + '.style'); }
}
function JS_GetP(layerID) {
	if (JS_NS4()) {		return eval('window.parent.document.' + layerID); }
	if (JS_NS6()) {		return eval('window.parent.document.getElementById("' + layerID + '")'); }
	if (JS_IE()) {		return eval('window.parent.document.all.' + layerID); }
}
function JS_GetPS(layerID) {
	if (!JS_GetP(layerID)) { return null; } 
	if (JS_NS4()) {		return eval('window.parent.document.' + layerID); }
	if (JS_NS6()) {		return eval('window.parent.document.getElementById("' + layerID + '").style'); }
	if (JS_IE()) {		return eval('window.parent.document.all.' + layerID + '.style'); }
}
function JS_Get(layerID) {
	if (JS_NS4()) {		return eval('document.' + layerID); }
	if (JS_NS6()) {		return eval('document.getElementById("' + layerID + '")'); }
	if (JS_IE()) {		return eval('document.all.' + layerID); }
}
function JS_GetByName(layerID) {
	return eval('document.getElementsByName("' + layerID + '")');
}
function JS_GetS(layerID) {
	if (!JS_Get(layerID)) { return null; } 
	if (JS_NS4()) {		return eval('document.' + layerID); }
	if (JS_NS6()) {		return eval('document.getElementById("' + layerID + '").style'); }
	if (JS_IE()) {		return eval('document.all.' + layerID + '.style'); }
}
function JS_AbrirPopup(pagina, titulo, w, h, conMenu, conScroll, resiz) {
	var menuStr = (conMenu)?"yes":"no";
	var scrollStr = (conScroll)?"yes":"no";
	var resizeStr = (resiz)?"yes":"no";

	winopt ="menubar="+menuStr+",scrollbars="+scrollStr+",resizable="+resizeStr+",";
	winopt +="marginwidth=0, marginheight=0, leftmargin=0, topmargin=0,";
	winopt +="width="+w+",height="+h+",";
	winopt +="left=0,top=0,screenLeft=0,screenTop=0";
	
	var vent = window.open(pagina,"",winopt);
	vent.focus();
}
function JS_ClassNameObj(obj, css) {
	if (obj) { obj.className = css; }
}
function JS_ClassName(id, css) {
	var r = JS_Get(id);
	if (r) { r.className = css; }
}
function JS_ClassNameP(id, css) {
	var r = JS_GetP(id);
	if (r) { r.className = css; }
}
function JS_Tab(t, n, a, d, tag, css) {
	css = (css == "") ? "tab" : css;
	var imprimir = JS_GetValue("hidImprimir");
	for (var i=1; i<=n; i++) {
		JS_Display("divTab"+tag+"_"+i, ((i==t) || (imprimir == 1)));
		JS_ClassName("idTab"+tag+"_"+i, ((i==t) ? "css_"+css+"_on" : "css_"+css+""));
		if (i==t) {
			r = JS_Get("hidPestanaGoogleMap");
			//JS_LoadGMap();
			if (r) { if (r.value==t) { if (JS_GetValue("hidGMapLoaded") != "si") { load(); } } }
		}
	}
	arr = d.toString().split(",");
	for (var i=0; i<arr.length; i++) {
		r = JS_Get(arr[i]); if (r) { r.width = a; }
	}
	JS_Value("hidTab"+tag, t);
}
function JS_SetWidth(tagID, w) {
	var r = JS_Get(tagID);		if (r) { r.width = parseInt(w); }
}
function JS_SetHeight(tagID, h) {
	var r = JS_Get(tagID);		if (r) { r.height = parseInt(h); }
}
function JS_Src(tagID, txt) {
	var r = JS_Get(tagID);		if (r) { r.src = txt; }
}
function JS_SrcPP(tagID, txt) {
	var r = JS_GetPP(tagID);	if (r) { r.src = txt; }
}
function JS_GetInner(tagID) {
	var r = JS_Get(tagID); if (r) {  return r.value; }
}
function JS_Inner(tagID, txt) {
	var r = JS_Get(tagID);	if (r) { r.innerHTML = txt; }
}
function JS_InnerP(tagID, txt) {
	var r = JS_GetP(tagID);	if (r) { r.innerHTML = txt; }
}
function JS_InnerPP(tagID, txt) {
	var r = JS_GetPP(tagID);	if (r) { r.innerHTML = txt; }
}
function JS_GetValue(tagID) {
	var r = JS_Get(tagID);	if (r) { return r.value; }
	return "err";
}
function JS_GetValueP(tagID) {
	var r = JS_GetP(tagID);	if (r) { return r.value; }
	return "err";
}
function JS_Value(tagID, txt) {
	var r = JS_Get(tagID);	if (r) { r.value = txt; }
}
function JS_ValueP(tagID, txt) {
	var r = JS_GetP(tagID);	if (r) { r.value = txt; }
}
function JS_GetSelecValue(selID, id) {
	var r = JS_Get(selID);
	if (r) { return r[r.selectedIndex].value; }
	return "";
}
function JS_SelecIndex(selID, id) {
	var r = JS_Get(selID);
	JS_SelecIndexObj(r, id);
}
function JS_GetRadioValue(selID) {
	var r = JS_GetByName(selID);
	for (var i=0;i<r.length;i++){ 
		if (r[i].checked) {
			return r[i].value; 
		}
	}
	return "";
}
function JS_SelecIndexP(selID, id) {
	var r = JS_GetP(selID);
	JS_SelecIndexObj(r, id);
}
function JS_SelecIndexObj(r, id) {
	if (!r) { return; }
	var n = r.length;
	r.selectedIndex = 0;
	for (var i=0; i<n; i++) {
		if (parseInt(r.options[i].value) == parseInt(id)) {
			r.selectedIndex = i;
		}
	}
}
function JS_SelecFF1(f, letra) {
	var anio 	= f.selecAnio[f.selecAnio.selectedIndex].value;
	var mes 	= (f.selecMes) ? f.selecMes[f.selecMes.selectedIndex].value : -1;
	var dia 	= (f.selecDia) ? f.selecDia[f.selecDia.selectedIndex].value : -1;
	JS_Redireccionar("?rff"+letra+"=1&anio"+letra+"="+anio+"&mes"+letra+"="+mes+"&dia"+letra+"="+dia);
}
function JS_SelecFF2(f, letra) {
	var desde = f.txtFechaFiltroDesde.value;
	var hasta = f.txtFechaFiltroHasta.value;
	
	desde = (desde=="") ? "-cualquiera-" : desde;
	hasta = (hasta=="") ? "-cualquiera-" : hasta;
	
	JS_Redireccionar("?rff"+letra+"=2&desde"+letra+"="+desde+"&hasta"+letra+"="+hasta);
}
function JS_ValuePP(tagID, txt) {
	var r = JS_GetPP(tagID);	if (r) { r.value = txt; }
}
function JS_Mostrar(tagID, siNo) {
	var r = JS_GetS(tagID);
	if (r) { r.visibility = (siNo)?"visible":"hidden"; }
}
function JS_SetDisabled(tagID, siNo) {
	var r = JS_Get(tagID);
	if (r) { r.disabled = (siNo); }
}
function JS_Display(tagID, siNo) {
	var r = JS_GetS(tagID);
	if (r) { r.display = (siNo)?"block":"none"; }
}
function JS_DisplayP(tagID, siNo) {
	var r = JS_GetPS(tagID);
	if (r) { r.display = (siNo)?"block":"none"; }
}
function JS_DisplayPP(tagID, siNo) {
	var r = JS_GetPPS(tagID);
	if (r) { r.display = (siNo)?"block":"none"; }
}
function JS_ToggleDisplay(id) {
	var r = JS_GetS(id);
	if (r) { r.display = (r.display=="none") ? "block" : "none"; }
}
function JS_Checked(id) {
	var r = JS_Get(id);
	if (r) { return r.checked; }
	return false;
}
function JS_SetCheck(id, valor) {
	var r = JS_Get(id);
	if (r) { r.checked = valor; }
}
function JS_ToggleCheck(id, img) {
	var r = JS_Get(id);
	if (r) { r.checked = !r.checked; }
	r = JS_Src(id + "_img", "../imgs/" + img + ((r.checked) ? "_on" : "_off") + ".gif");
}
function JS_Copiar(id) {
	var r = JS_Get(id);
	if (r) { if (window.clipboardData) { window.clipboardData.setData("Text", r.innerHTML); } }
}
function JS_CambiarTextoCheck(lbl, siNo, a, b) {
	var r = JS_Get(lbl);
	r.innerHTML = (siNo)? a : b;
}
function JS_CambiarTextoCheckSiNo(lbl, siNo, strSi, strNo) {
	if (siNo == undefined) { return; }
	var r = JS_Get(lbl);
	r.innerHTML = (siNo)? strSi: strNo;
}
function JS_HuboCambios() {
	JS_Value("hidGuardado", "no");
}
//JS_SalirSinGuardar
function JS_SSG() {
	var r = JS_Get("hidGuardado");
	if (!r) { return true; }
	if (r.value != "si") {
		if (!confirm("¿Desea salir de este formulario sin guardar los cambios realizados?")) {
			return false;
		}
	}
	return true;
}
function JS_TxtOn(txt, css) {
	JS_ClassNameObj(txt, css+'_on');
}
function JS_TxtOff(txt, css) {
	JS_ClassNameObj(txt, css);
}
function JS_SelectReponerValor(sel, tagID) {
	var valor = JS_GetValue(tagID);
	for (i=0; i<sel.options.length; i++) {
		if (sel.options[i].value == valor) { sel.selectedIndex = i; break; }
	}
}
function JS_CambiarEmpresa(sel, vble, cod) {
	if (!JS_SSG()) { 
		JS_SelectReponerValor(sel, "hidEmpresaSelec");
		return false; 
	}
	var pars = (parseInt(cod) > 0) ? "&cod="+cod+"" : "";
	JS_Redireccionar('?'+vble+'='+sel[sel.selectedIndex].value+pars);
	return true; 
}
function JS_CambiarInst(sel) {
	if (!JS_SSG()) { 
		JS_SelectReponerValor(sel, "hidInstSelec");
		return false; 
	}
	JS_FiltroSelectOnChange(sel, 'empresa=-1&instalacion');
	return true;
}
function JS_FiltroSelectOnChange(sel, vble) {
	JS_Redireccionar('?'+vble+'='+sel[sel.selectedIndex].value);
}
function JS_FiltroCheckOnClickImg(ckbID, vble) {
	JS_Redireccionar('?'+vble+'='+((JS_Checked(ckbID))?"si":"no"));
}
function JS_FiltroCheckOnClick(ckb, vble) {
	JS_Redireccionar('?'+vble+'='+((ckb.checked)?"si":"no"));
}
function JS_Timer(a, b, t) {
	JS_Inner(a, b);
	setTimeout('JS_Timer(\''+a+'\',\''+b+'\','+t+')', t) ;
}
function JS_Timer2(a, b, t, v) {
	if (v==undefined) { v=1; }
	v = parseInt(v);
	JS_Inner(a, "<iframe src='"+b+"&v="+v+"' width=0 height=0></iframe>");
	v=v+1;
	setTimeout('JS_Timer2(\''+a+'\',\''+b+'\','+t+', '+v+')', t) ;
}
function JS_TimerRecargarPagina(pagina, t) {
	setTimeout('JS_Redireccionar(\''+pagina+'\');', t) ;
}
function JS_SubirFoto(n, opc) {
	JS_Display("spanActual"+n, (opc==1));
	JS_Display("spanFile"+n, (opc==2));
	JS_Display("spanPie"+n, (opc==2));
	JS_Display("spanSelec"+n, (opc==3));
}
function JS_MostrarFoto(sel, imgID, dir) {
	var foto = sel[sel.selectedIndex].value;
	JS_Src(imgID, dir+foto);
}
function JS_SetBGColor(id, color) {
	r = JS_GetS(id);
	if (r) { r.backgroundColor = color; }
}
function JS_SeleccionarFila(nombre, n) {
	var modoEdicion = parseInt(JS_GetValue("hidFilaEstaModoEdicion_"+n));
	if (modoEdicion) { return false; }
	JS_SetBGColor(nombre + n, 0xE2CE94);

	var codAnt = JS_GetValue("hidFilaSelecAnterior");
	
	deseleccionar = (codAnt == n);
	JS_SetBGColor(nombre+n, ((deseleccionar)?"":0xE2CE94))

	JS_Value("hidFilaSelecAnterior", ((deseleccionar)?"":n));
	if ((codAnt != "") && (!deseleccionar)) { JS_SetBGColor(nombre+codAnt, ""); }
	
	return deseleccionar;
}
function JS_ModoEdicion(cod, modoEdicion, num) {
	JS_Value("hidFilaEstaModoEdicion_"+cod, (modoEdicion?1:0));
	for (var i=1; i<=num; i++) {
		JS_Display("divEdicion_"+i+"_"+cod+"_on", modoEdicion);
		JS_Display("divEdicion_"+i+"_"+cod+"_off", !modoEdicion);
	}
}
function JS_ModoEdicionP(cod, modoEdicion, num) {
	JS_ValueP("hidFilaEstaModoEdicion_"+cod, (modoEdicion?1:0));
	for (var i=1; i<=num; i++) {
		JS_DisplayP("divEdicion_"+i+"_"+cod+"_on", modoEdicion);
		JS_DisplayP("divEdicion_"+i+"_"+cod+"_off", !modoEdicion);
	}
}
function JS_EditarFila(cod, num) {
	var modoEdicion = !parseInt(JS_GetValue("hidFilaEstaModoEdicion_"+cod));
	JS_ModoEdicion(cod, modoEdicion, num);
	codAnt = parseInt(JS_GetValue("hidFilaEditAnterior"));
	esLaMisma = (codAnt == cod);
	if (!esLaMisma) {
		JS_Value("hidFilaEditAnterior", ((esLaMisma)?"":cod));
		JS_ModoEdicion(codAnt, false, num);
	}
	//JS_SeleccionarFila("trFila_"+cod, cod);
}
function JS_EditarFilaP(cod, num) {
	var modoEdicion = !parseInt(JS_GetValueP("hidFilaEstaModoEdicion_"+cod));
	JS_ModoEdicionP(cod, modoEdicion, num);
	codAnt = parseInt(JS_GetValueP("hidFilaEditAnterior"));
	esLaMisma = (codAnt == cod);
	if (!esLaMisma) {
		JS_ValueP("hidFilaEditAnterior", ((esLaMisma)?"":cod));
		JS_ModoEdicionP(codAnt, false, num);
	}
	//JS_SeleccionarFila("trFila_"+cod, cod);
}
function JS_QuitarTagsHTML(Word) {
	a = Word.indexOf("<");
	b = Word.indexOf(">");
	len = Word.length;
	c = Word.substring(0, a);
	if(b == -1)
	b = a;
	d = Word.substring((b + 1), len);
	Word = c + d;
	tagCheck = Word.indexOf("<");
	if(tagCheck != -1)
	Word = JS_QuitarTagsHTML(Word);
	return Word;
}
function JS_AbrirSelector(data,ocultar,js,t,f,w,h,hid,cod,a,b,c,d,i,r,s) {
	JS_Display(a, true);
	buscar = JS_GetValue(s); buscar = ((buscar == undefined) || (buscar== "err")) ? "" : buscar;
	if (cod == "_get_") { cod = JS_GetValue(hid); }
	JS_Inner(b, '<iframe id="'+i+'" name="'+i+'" src="'+r+'comun/inc_selector_ventana.php?r='+r+'&data='+data+'&ocultar='+ocultar+'&js='+js+'&w='+w+'&h='+h+'&hid='+hid+'&cod='+cod+'&a='+a+'&b='+b+'&c='+c+'&d='+d+'&i='+i+'&t='+t+'&f='+f+'&buscar='+buscar+'" allowtransparency=true width='+w+' height='+h+' frameborder=0 scrolling=no></iframe>');
}
function JS_MensajeOver(msg) {
	window.status = msg; return true;
}
function JS_MensajeOut() {
	window.status = ""; return true;
}

function JS_ValidarEmail(c) { 
	return !(c.search(/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/ig));
}
function JS_ValidarHayTexto(txt, msg) {
	if (txt.value != "") {
		return true;
	}
	alert(msg);		
	txt.focus();
	return false;
}
function JS_ValidarEsNumero(txt) {
	if (parseFloat(JS_RemplazarStr(txt.value, ",", "."))) { return true; }
	if ((txt.value == "0") || (JS_RemplazarStr(txt.value, ",", ".") == "0.00")) { return true; }
	alert("Debe introducir un valor numérico.");		
	txt.focus();
	txt.select();
	return false;
}
function JS_ValidarEsNumeroPositivo(txt) {
	if (!JS_ValidarEsNumero(txt)) {
		return false;
	}
	if (parseFloat(JS_RemplazarStr(txt.value, ",", ".")) < 0) {
		alert("Debe introducir un número positivo.");		
		txt.focus();
		txt.select();
		return false;
	}
	return true;
}
function JS_ValidarHayNumero(txt, msg) {
	if (!JS_ValidarHayTexto(txt, msg)) {
		return false;
	}
	if (!JS_ValidarEsNumero(txt)) {
		return false;
	}
	return true;
}
function JS_Focus(tagID) {
	r = JS_Get(tagID);
	if (r) { r.focus(); }
}
function JS_ValidarOpcionSelecSinFocus(sel, msg) {
	if ((sel.selectedIndex > 0) || (sel.selectedIndex == -2)) {
		return true;
	}
	alert(msg);		
	return false;
}
function JS_ValidarOpcionSelec(sel, msg) {
	if (sel.selectedIndex == undefined)
		return true;
	if ((sel.selectedIndex > 0) || (sel.selectedIndex == -2)) {
		return true;
	}
	alert(msg);		
	sel.focus();
	return false;
}
function JS_ValidarSelectorSelec(hid, msg) {
	if (hid.value > 0) {
		return true;
	}
	alert(msg);		
	return false;
}
function JS_NM_Fechas_Val_Calendar(txt, msg) {
	if (txt.value != "") {
		if (!calendar.parseDate(txt.value)) {
			alert(msg);
			txt.focus();
			txt.select();
			return false;
		}
	}
	return true;
}
function JS_ActualizarDatosDesdeIframe(cod, ifrID, divID, doit) {
	JS_Src(ifrID, "../comun/"+doit+".php?cod="+cod+"&div="+divID);
}
function JS_ActualizarDatosTag(tag, ifrID, divID, doit) {
	var r = JS_Get(tag)
	JS_ActualizarDatosDesdeIframe(r.value, ifrID, divID, doit);
}
function JS_ActualizarDatosSelector(sel, ifrID, divID, doit) {
	JS_ActualizarDatosDesdeIframe(sel[sel.selectedIndex].value, ifrID, divID, doit);
}
function JS_ActualizarDatosDesdeIframePP(cod, ifrID, divID, doit) {
	JS_SrcPP(ifrID, "../comun/"+doit+".php?cod="+cod+"&div="+divID);
}
function JS_ActualizarDatosTagExtraPP(tag, ifrID, divID, doit, extra) {
	var r = JS_GetPP(tag)
	var pars = r.value;
	var strArr = extra.split(",");
	for (var i=0; i<strArr.length; i++) {
		parArr = strArr[i].split("=", 2);
		par = parArr[0];
		valor = parArr[1];
		r = JS_GetPP(valor);
		if (r) { valor = r.value; }
		pars = pars + "&" + par + "=" + valor;
	}
	JS_ActualizarDatosDesdeIframePP(pars, ifrID, divID, doit);
}
function JS_ActualizarDatosTagPP(tag, ifrID, divID, doit) {
	var r = JS_GetPP(tag)
	JS_ActualizarDatosDesdeIframePP(r.value, ifrID, divID, doit);
}
function JS_FiltrarPorDia(ckbID, txtID, vble1, vble2) {
	var fecha = "";
	var filtrarDia = 0;
	var ckb = JS_Get(ckbID);
	var txt = JS_Get(txtID);
	if (txt) { fecha = txt.value; }
	if (ckb) { filtrarDia = (ckb.checked) ? 1 : 0; }
	if (!filtrarDia) { 
		fecha = "null"; 
	} else {
		if (fecha == "") { alert("Seleccione el día por el que desea filtrar."); return; }
	}
	JS_Redireccionar("?"+vble1+"="+filtrarDia+"&"+vble2+"="+fecha);
}
function JS_ActualizarImporteFacturaP() {

	desgloseBases = false;

	r = JS_GetP("txtBase1");
	if (r) { desgloseBases = true; }
	
	if (desgloseBases) {

		//r = JS_GetP("ckbConBase1");
		conBase1 = true //r.checked;

		r = JS_GetP("txtBase1");
		base1 = JS_GetNum(r.value);

		r = JS_GetP("selecIva1");
		valor = r[r.selectedIndex].value;
		arr = valor.split("#", 2);
		idIva1 = JS_GetNum(arr[0]);
		ivaPorciento1 = JS_GetNum(arr[1]);
		if (ivaPorciento1 < 0) { ivaPorciento1 = 0; }

		ivaImporte1 = parseFloat(base1) * parseFloat(ivaPorciento1) / 100;
		baseConIva1 = parseFloat(base1) + parseFloat(ivaImporte1);

		JS_ValueP("hidIvaImporte1", 	JS_FormatMonedaStr(ivaImporte1));
		JS_InnerP("divIvaImporte1",		JS_FormatMonedaStr(ivaImporte1)+"&nbsp;&euro;");
		JS_InnerP("divBaseConIva1", 	JS_FormatMonedaStr(baseConIva1)+"&nbsp;&euro;");
		
		r = JS_GetP("ckbConBase2");
		conBase2 = r.checked;

		r = JS_GetP("txtBase2");
		base2 = JS_GetNum(r.value);

		r = JS_GetP("selecIva2");
		valor = r[r.selectedIndex].value;
		arr = valor.split("#", 2);
		idIva2 = JS_GetNum(arr[0]);
		ivaPorciento2 = JS_GetNum(arr[1]);
		if (ivaPorciento2 < 0) { ivaPorciento2 = 0; }

		ivaImporte2 = parseFloat(base2) * parseFloat(ivaPorciento2) / 100;
		baseConIva2 = parseFloat(base2) + parseFloat(ivaImporte2);

		JS_ValueP("hidIvaImporte2", 	JS_FormatMonedaStr(ivaImporte2));
		JS_InnerP("divIvaImporte2",		JS_FormatMonedaStr(ivaImporte2)+"&nbsp;&euro;");
		JS_InnerP("divBaseConIva2", 	JS_FormatMonedaStr(baseConIva2)+"&nbsp;&euro;");
		
		r = JS_GetP("ckbConBase3");
		conBase3 = r.checked;

		r = JS_GetP("txtBase3");
		base3 = JS_GetNum(r.value);

		r = JS_GetP("selecIva3");
		valor = r[r.selectedIndex].value;
		arr = valor.split("#", 2);
		idIva3 = JS_GetNum(arr[0]);
		ivaPorciento3 = JS_GetNum(arr[1]);
		if (ivaPorciento3 < 0) { ivaPorciento3 = 0; }

		ivaImporte3 = parseFloat(base3) * parseFloat(ivaPorciento3) / 100;
		baseConIva3 = parseFloat(base3) + parseFloat(ivaImporte3);

		JS_ValueP("hidIvaImporte3", 	JS_FormatMonedaStr(ivaImporte3));
		JS_InnerP("divIvaImporte3",		JS_FormatMonedaStr(ivaImporte3)+"&nbsp;&euro;");
		JS_InnerP("divBaseConIva3", 	JS_FormatMonedaStr(baseConIva3)+"&nbsp;&euro;");
		
		if (!conBase1) {		base1 = 0; ivaImporte1 = 0;	ivaPorciento1 = 0; baseConIva1 = 0;		}
		if (!conBase2) {		base2 = 0; ivaImporte2 = 0;	ivaPorciento2 = 0; baseConIva2 = 0;		}
		if (!conBase3) {		base3 = 0; ivaImporte3 = 0;	ivaPorciento3 = 0; baseConIva3 = 0;		}

		base = parseFloat(base1) + parseFloat(base2) + parseFloat(base3);
		ivaImporte = parseFloat(ivaImporte1) + parseFloat(ivaImporte2) + parseFloat(ivaImporte3);
		baseConIva = parseFloat(baseConIva1) + parseFloat(baseConIva2) + parseFloat(baseConIva3);
		if (!conBase2 && !conBase2) {
			ivaPorciento = ivaPorciento1;
		} else {
			ivaPorciento = 0;
		}
		
		JS_Display("divBase1A", conBase1); JS_Display("divBase1B", conBase1); 
		JS_Display("divBase1C", conBase1); JS_Display("divBase1D", conBase1);
		JS_Display("divBase2A", conBase2); JS_Display("divBase2B", conBase2); 
		JS_Display("divBase2C", conBase2); JS_Display("divBase2D", conBase2);
		JS_Display("divBase3A", conBase3); JS_Display("divBase3B", conBase3); 
		JS_Display("divBase3C", conBase3); JS_Display("divBase3D", conBase3);

	} else {

		r = JS_GetP("txtBase");
		base = JS_GetNum(r.value);
		
		r = JS_GetP("selecIva");
		valor = r[r.selectedIndex].value;
		arr = valor.split("#", 2);
		idIva = JS_GetNum(arr[0]);
		ivaPorciento = JS_GetNum(arr[1]);
		if (ivaPorciento < 0) { ivaPorciento = 0; }

		ivaImporte = parseFloat(base) * parseFloat(ivaPorciento) / 100;
		baseConIva = parseFloat(base) + parseFloat(ivaImporte);
	}
	
	r = JS_GetP("txtExento");
	exento = JS_GetNum(r.value);

	r = JS_GetP("ckbExento");
	if (r) { if (!r.checked) { exento =  0; } }
	
	r = JS_GetP("hidRetencionImporte");
	retenciones = JS_GetNum(r.value);

	r = JS_GetP("selecRetencion");
	valor = r[r.selectedIndex].value;
	arr = valor.split("#", 2);
	idPorciento = JS_GetNum(arr[0]);
	retencionPorciento = JS_GetNum(arr[1]);
	if (retencionPorciento < 0) { retencionPorciento = 0; }
	
	r = JS_GetP("ckbRetenciones");
	tieneRetenciones = r.checked;
	retencionBase = (parseFloat(base) + parseFloat(exento));
	if (!tieneRetenciones) {
		retencionPorciento = 0;
		retencionImporte = 0;
	} else {
		retencionImporte = parseFloat(retencionBase) * parseFloat(retencionPorciento) / 100;
	}

	r = JS_GetP("txtDescuento");
	descuento = JS_GetNum(r.value);
	r = JS_GetP("ckbDescuento");
	tieneDescuento = r.checked;
	if (!tieneDescuento) {
		descuento = 0;
	}

	totalFactura = (parseFloat(base) + parseFloat(ivaImporte) + parseFloat(exento) - parseFloat(retencionImporte) - parseFloat(descuento));

	JS_InnerP("divBase",				JS_FormatMonedaStr(base)+"&nbsp;&euro;");
	JS_InnerP("divIvaImporte",			JS_FormatMonedaStr(ivaImporte)+"&nbsp;&euro;");
	JS_InnerP("divBaseConIva",			JS_FormatMonedaStr(baseConIva)+"&nbsp;&euro;");
	JS_ValueP("txtBase", 				JS_SetNum(base));
	JS_ValueP("txtBaseConIva", 			JS_SetNum(baseConIva));
	JS_ValueP("hidIvaImporte", 			JS_SetNum(ivaImporte));
	JS_ValueP("txtIvaImporte", 			JS_SetNum(ivaImporte));
	JS_InnerP("divRetencionBase",		JS_FormatMonedaStr(retencionBase));
	JS_InnerP("divRetencionImporte",	JS_FormatMonedaStr(retencionImporte));
	JS_ValueP("hidRetencionImporte", 	JS_SetNum(retencionImporte));
	JS_InnerP("divTotalFactura", 		JS_SetNum(totalFactura));
	JS_ValueP("hidTotalFactura", 		JS_SetNum(totalFactura));
	JS_ValueP("txtTotalFactura", 		JS_FormatMonedaStr(totalFactura));
}
function JS_ActualizarImporteFactura() {

	desgloseBases = false;

	r = JS_Get("txtBase1");
	if (r) { desgloseBases = true; }
	
	if (desgloseBases) {

		//r = JS_Get("ckbConBase1");
		conBase1 = true //r.checked;

		r = JS_Get("txtBase1");
		base1 = JS_GetNum(r.value);

		r = JS_Get("selecIva1");
		valor = r[r.selectedIndex].value;
		arr = valor.split("#", 2);
		idIva1 = JS_GetNum(arr[0]);
		ivaPorciento1 = JS_GetNum(arr[1]);
		if (ivaPorciento1 < 0) { ivaPorciento1 = 0; }

		ivaImporte1 = parseFloat(base1) * parseFloat(ivaPorciento1) / 100;
		baseConIva1 = parseFloat(base1) + parseFloat(ivaImporte1);

		JS_Value("hidIvaImporte1", 		JS_FormatMonedaStr(ivaImporte1));
		JS_Inner("divIvaImporte1",		JS_FormatMonedaStr(ivaImporte1)+"&nbsp;&euro;");
		JS_Inner("divBaseConIva1", 		JS_FormatMonedaStr(baseConIva1)+"&nbsp;&euro;");
		
		r = JS_Get("ckbConBase2");
		conBase2 = r.checked;

		r = JS_Get("txtBase2");
		base2 = JS_GetNum(r.value);

		r = JS_Get("selecIva2");
		valor = r[r.selectedIndex].value;
		arr = valor.split("#", 2);
		idIva2 = JS_GetNum(arr[0]);
		ivaPorciento2 = JS_GetNum(arr[1]);
		if (ivaPorciento2 < 0) { ivaPorciento2 = 0; }

		ivaImporte2 = parseFloat(base2) * parseFloat(ivaPorciento2) / 100;
		baseConIva2 = parseFloat(base2) + parseFloat(ivaImporte2);

		JS_Value("hidIvaImporte2", 		JS_FormatMonedaStr(ivaImporte2));
		JS_Inner("divIvaImporte2",		JS_FormatMonedaStr(ivaImporte2)+"&nbsp;&euro;");
		JS_Inner("divBaseConIva2", 		JS_FormatMonedaStr(baseConIva2)+"&nbsp;&euro;");
		
		r = JS_Get("ckbConBase3");
		conBase3 = r.checked;

		r = JS_Get("txtBase3");
		base3 = JS_GetNum(r.value);

		r = JS_Get("selecIva3");
		valor = r[r.selectedIndex].value;
		arr = valor.split("#", 2);
		idIva3 = JS_GetNum(arr[0]);
		ivaPorciento3 = JS_GetNum(arr[1]);
		if (ivaPorciento3 < 0) { ivaPorciento3 = 0; }

		ivaImporte3 = parseFloat(base3) * parseFloat(ivaPorciento3) / 100;
		baseConIva3 = parseFloat(base3) + parseFloat(ivaImporte3);

		JS_Value("hidIvaImporte3", 		JS_FormatMonedaStr(ivaImporte3));
		JS_Inner("divIvaImporte3",		JS_FormatMonedaStr(ivaImporte3)+"&nbsp;&euro;");
		JS_Inner("divBaseConIva3", 		JS_FormatMonedaStr(baseConIva3)+"&nbsp;&euro;");
		
		if (!conBase1) {		base1 = 0; ivaImporte1 = 0;	ivaPorciento1 = 0; baseConIva1 = 0;		}
		if (!conBase2) {		base2 = 0; ivaImporte2 = 0;	ivaPorciento2 = 0; baseConIva2 = 0;		}
		if (!conBase3) {		base3 = 0; ivaImporte3 = 0;	ivaPorciento3 = 0; baseConIva3 = 0;		}

		base = parseFloat(base1) + parseFloat(base2) + parseFloat(base3);
		ivaImporte = parseFloat(ivaImporte1) + parseFloat(ivaImporte2) + parseFloat(ivaImporte3);
		baseConIva = parseFloat(baseConIva1) + parseFloat(baseConIva2) + parseFloat(baseConIva3);
		if (!conBase2 && !conBase2) {
			ivaPorciento = ivaPorciento1;
		} else {
			ivaPorciento = 0;
		}
		
		JS_Display("divBase1A", conBase1); JS_Display("divBase1B", conBase1); 
		JS_Display("divBase1C", conBase1); JS_Display("divBase1D", conBase1);
		JS_Display("divBase2A", conBase2); JS_Display("divBase2B", conBase2); 
		JS_Display("divBase2C", conBase2); JS_Display("divBase2D", conBase2);
		JS_Display("divBase3A", conBase3); JS_Display("divBase3B", conBase3); 
		JS_Display("divBase3C", conBase3); JS_Display("divBase3D", conBase3);

	} else {

		r = JS_Get("txtBase");
		base = JS_GetNum(r.value);
		
		r = JS_Get("selecIva");
		valor = r[r.selectedIndex].value;
		arr = valor.split("#", 2);
		idIva = JS_GetNum(arr[0]);
		ivaPorciento = JS_GetNum(arr[1]);
		if (ivaPorciento < 0) { ivaPorciento = 0; }

		ivaImporte = parseFloat(base) * parseFloat(ivaPorciento) / 100;
		baseConIva = parseFloat(base) + parseFloat(ivaImporte);
	}
	
	r = JS_Get("txtExento");
	exento = JS_GetNum(r.value);

	r = JS_Get("ckbExento");
	if (r) { if (!r.checked) { exento =  0; } }
	
	r = JS_Get("hidRetencionImporte");
	retenciones = JS_GetNum(r.value);

	r = JS_Get("selecRetencion");
	valor = r[r.selectedIndex].value;
	arr = valor.split("#", 2);
	idPorciento = JS_GetNum(arr[0]);
	retencionPorciento = JS_GetNum(arr[1]);
	if (retencionPorciento < 0) { retencionPorciento = 0; }
	
	r = JS_Get("ckbRetenciones");
	tieneRetenciones = r.checked;
	retencionBase = (parseFloat(base) + parseFloat(exento));
	if (!tieneRetenciones) {
		retencionPorciento = 0;
		retencionImporte = 0;
	} else {
		retencionImporte = parseFloat(retencionBase) * parseFloat(retencionPorciento) / 100;
	}

	r = JS_Get("txtDescuento");
	descuento = JS_GetNum(r.value);
	r = JS_Get("ckbDescuento");
	tieneDescuento = r.checked;
	if (!tieneDescuento) {
		descuento = 0;
	}

	totalFactura = (parseFloat(base) + parseFloat(ivaImporte) + parseFloat(exento) - parseFloat(retencionImporte) - parseFloat(descuento));

	JS_Inner("divBase",				JS_FormatMonedaStr(base)+"&nbsp;&euro;");
	JS_Inner("divIvaImporte",		JS_FormatMonedaStr(ivaImporte)+"&nbsp;&euro;");
	JS_Inner("divBaseConIva",		JS_FormatMonedaStr(baseConIva)+"&nbsp;&euro;");
	JS_Value("txtBase", 			JS_SetNum(base));
	JS_Value("txtBaseConIva", 		JS_SetNum(baseConIva));
	JS_Value("hidIvaImporte", 		JS_SetNum(ivaImporte));
	JS_Value("txtIvaImporte", 		JS_SetNum(ivaImporte));
	JS_Inner("divRetencionBase",	JS_FormatMonedaStr(retencionBase));
	JS_Inner("divRetencionImporte",	JS_SetNum(retencionImporte));
	JS_Value("hidRetencionImporte", JS_FormatMonedaStr(retencionImporte));
	JS_Inner("divTotalFactura", 	JS_SetNum(totalFactura));
	JS_Value("hidTotalFactura", 	JS_SetNum(totalFactura));
	JS_Value("txtTotalFactura", 	JS_FormatMonedaStr(totalFactura));
}

function JS_Traducir(lbl, lang, url) { 
	divID = "tr_"+lbl;
	divId2 = "tr2_"+lbl;
	r = JS_Get(divID);
	if (r) {
		JS_ToggleDisplay(divID);
		str = "<iframe src='../comun/doit_traducir.php?lang="+lang+"&lbl="+lbl+"&url="+url+"' width=220 height=80 frameborder=0 />";
	}
	JS_Inner(divId2, str);
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

