// ********************* Funciones Para los menus que siempre te salgan en pantalla con el nombre tabla_desplazar



function findScrollTop() {
	if (window.pageYOffset != null)
		return window.pageYOffset;
	if (document.body.scrollWidth != null)
		return document.body.scrollTop;
	return null;
}
var offsetTablaInicial = null;

function miOnScroll() {
	var top;
	//alert("scroll");
	if ( offsetTablaInicial==null) {
		offsetTablaInicial = document.all["tabla_desplazar"].offsetTop;
	} else {
		top = findScrollTop();
		if (top!=null) {
			if (top>offsetTablaInicial) {
				document.all["tabla_desplazar"].style.top = top;				
			} else {
				document.all["tabla_desplazar"].style.top = offsetTablaInicial;
			}
		}				
	}
}


function eliminarEntradaAsiento(numero) {
	if (confirm("¿Seguro que desea eliminar esta linea?")) {
		eval("document.formulario.importe_"+numero+".value='';");
		eval("document.formulario.cuenta_"+numero+".value='';");
	}
	return;
}

function changeDisplay(id) {
	//Permite ocultar o ver un elemento:
	var nodo=document.all[id];
	if (nodo.style.display=="none") {
		nodo.style.display="block";
	} else {
		nodo.style.display="none";
	}
}

function openWindow(url, ancho, alto) {
	strancho=ancho;
	stralto=alto;
	if (ancho==null) strancho = 600;
	if (alto==null) stralto = 360;
	window.open(url,"","resizable=yes,status=1,scrollbars=1,width="+strancho+",height="+stralto,false);
}

function esVacio(cadena) {
	if (trim(cadena)=="") return true;
	else return false;
}


function openLogin() {
	var url="popup_login.php";
	window.open(url,"","resizable=0,status=0,scrollbars=0,width=200,height=140",false);
	//window.open(url,"","",false);
}

function openBigWindow(url) {
	window.open(url,"","resizable=yes,status=1,scrollbars=1,width=540,height=480",false);
}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

function resaltarGuardar() {
	var element = document.getElementById("boton_guardar");
	if (element!=null) {
		element.innerHTML ="* Guardar *";
	}
}

function abrirMail() {
	if (event.ctrlKey) {
		event.returnValue=false;
		window.open('http://www.varaderoweb.com/cgi-bin/sqwebmail');
		return false;
	}
}

function getElement( id, doc ) {
	var element, ndoc;
	if (doc==null) ndoc = document;
	else ndoc=doc; 
	if (ndoc.getElementById==null) {
		element = ndoc.all[id];
	} else {
		element = ndoc.getElementById(id);
	}
	return element;
}

function toggleOcultacion(partner) {
	var table = getElement(partner);
	if (table!=null) {
		if (table.style.display=="none") table.style.display="block";
		else table.style.display="none";
	}
}

function mostrarOcultacion(partner) {
	var table = getElement(partner);
	table.style.display="block";	
}

function ocultarOcultacion(partner) {
	var table = getElement(partner);
	table.style.display="none";	
}

function onchange_data() {
	var f = document.form_q;
	var seccion=f.seccion.options[f.seccion.selectedIndex].value;
	var proveedor=f.proveedor.options[f.proveedor.selectedIndex].value;
	var marca=f.marca.options[f.marca.selectedIndex].value;
	var modelo=f.modelo.value;
	window.location.href="cm_ls_productos.php?seccion="+seccion+"&proveedor="+proveedor+"&marca="+marca+"&modelo="+modelo;
}

function urlencode(ch) {
   ch = escape(ch);
   ch = ch.replace(/[+]/g,"%2B");
   return  ch;
}


function esTodoDigitos(campo) {
	var emailReg = /^[0-9]+/i
    return emailReg.test(campo);
}
	
function esMail(_email) {
	var emailReg = /^[a-z][a-z-_0-9\.]+@[a-z-_=>0-9\.]+\.[a-z]{2,3}$/i
    return emailReg.test(_email);
}

var urlXml, idpadre, strIdNodo, id, inputNodeValue, strIdElement, nEsforzado;
strIdNodo="";
urlXml="";

function mostrarTr(strid, strelemento, doc) {
	//alert("mostrarTr");
	var res=false;
	var nodo1 = getElement("th_"+strid, doc);
	var nodo2 = getElement("nodo_"+strelemento, doc);
	var nodo3 = getElement("persona_"+strelemento, doc);
	var nodo4 = getElement("ponencia_"+strelemento, doc);
	if (nodo2!=null) {
		if (nodo2.style.display=="block") res=true;
	}
	if (nodo3!=null) {
		if (nodo3.style.display=="block") res=true;
		nodo5 = nodo3.nextSibling;
		if (nodo5!=null) {
			if (nodo5.style.display=="block") res=true;
		} 

	} 
	if (nodo4!=null) {
		if (nodo4.style.display=="block") res=true;
		nodo5 = nodo4.previousSibling;
		if (nodo5!=null) {
			if (nodo5.style.display=="block") res=true;
		} 
	} 
	if (res) {
		nodo1.style.display="block";
	} else {
		nodo1.style.display="none";
	}
	//alert(nodo1.style.display);
	return res;
}

function expandir(strid, nif, doc) {
	var nodo, display;
	nodo = getElement("nodo_"+strid, doc);
	if (nodo!=null) {
		display = nodo.style.display;
		if ( (display=="block") || (display=="") ) {
			nodo.style.display="none";
		} else {
			nodo.style.display="block";
			nodo = getElement("nodo_"+strid, doc);
			if (nodo!=null) {
				nodo.innerHTML="Cargando datos ...";
				urlXml="xml_html_getponencias";
				strIdNodo="nodo_"+strid;
				getXml("xml_html_getponencias.php?nif="+nif);
			}
		}
	}
	mostrarTr(strid, strid, doc);
}


function expandirPersona(stroculto, strelemento, strid, doc) {
	var nodo, display;
	nodo = getElement("persona_"+strelemento,doc);
	if (nodo!=null) {
		display = nodo.style.display;
		if ( (display=="block") || (display=="") ) {
			nodo.style.display="none";
		} else {			
			nodo.style.display="block";
			nodo = getElement("persona_"+strelemento,doc);
			if (nodo!=null) {
				nodo.innerHTML="Cargando datos ...";
				urlXml="xml_html_popup_persona";
				strIdNodo="persona_"+strelemento;
				url="xml_html_popup_persona.php?id="+strid+"&idoculto=th_"+stroculto+"&idelemento="+strelemento;
				getXml(url);
			}
		}
	}
	mostrarTr(stroculto, strelemento, doc);
}


function expandirPonencia(stroculto, strid, doc) {
	var nodo, display;
	nodo = getElement("ponencia_"+strid, doc);
	if (nodo!=null) {
		display = nodo.style.display;
		if ( (display=="block") || (display=="") ) {
			nodo.style.display="none";
		} else {
			nodo.style.display="block";
			nodo = getElement("ponencia_"+strid,doc);
			if (nodo!=null) {
				nodo.innerHTML="Cargando datos ...";
				urlXml="xml_html_popup_persona";
				strIdNodo="ponencia_"+strid;
				url="xml_html_popup_ponencia.php?id="+strid+"&idoculto=th_"+stroculto;
				getXml(url);
			}
		}
	}
	mostrarTr(stroculto, stroculto, doc);
}

function getXml(url, doc) {
	var nodo = getElement("xmlisland",doc);
	nodo.src=url;
}

function loadXml() {
	var res;
	var doc = document;
	var xmlNode = xmlisland.XMLDocument;
	//alert("loadXml: "+xmlNode);

	if (urlXml=="xml_html_getponencias") {
		nodo = getElement(strIdNodo);
		if (nodo!=null) {
			nodo.innerHTML=xmlNode.text;
		}
	} else if (urlXml=="xml_html_popup_persona") {
		nodo = getElement(strIdNodo);
		if (nodo!=null) {
			nodo.innerHTML=xmlNode.text;
		}
	} else if (urlXml=="xml_html_popup_ponencia") {
		nodo = getElement(strIdNodo);
		if (nodo!=null) {
			nodo.innerHTML=xmlNode.text;
		}
	}
	urlXml="";
}

function expandirResumen(strid) {
	var str_buffer;
	var nodo = getElement(strid);
	if (nodo!=null) {
		str_buffer = nodo.innerHTML;
		var vWinCal = window.open("", "Resumen", 
			"width=400,height=310,status=no,resizable=yes,top=200,left=200");
		vWinCal.opener = self;
		var calc_doc = vWinCal.document;
		calc_doc.write ("<LINK REL='stylesheet' TYPE='text/css' HREF='conama.css'></link>\n<body style='margin:8px;'>");
		calc_doc.write (str_buffer);
		calc_doc.close();
	}
}