<!--
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_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_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];}
}
function chequearTodos(form,chkbox) {
	for (var i=0;i < form.elements.length;i++)	{
		var elemento = form.elements[i];
		if (elemento.type == "checkbox") {
			elemento.checked = chkbox.checked
		}
	}
}
function compruebaChecks(form) {
	var todos=true;
	var ninguno=true;
	
	for (var i=0;i < form.elements.length;i++) {
		var elemento = form.elements[i];
	//                                 if (elemento.name!='chkTodos') {
		if (elemento.name.substring(0,8)=='checkbox') {
			if (elemento.checked == true) {
				ninguno = false;
			}
			if (elemento.checked == false) {
				todos = false;
			}
		}
	}
	
	if (ninguno==true) {
		form.chktodos.checked=false;
	} else {
		if (todos==true) {
			form.chktodos.checked=true;
		} else {
			form.chktodos.checked=false;
		}
	}
}

//-------------------------------------------------------------
//-------------------------------------------------------------
//-------------------------------------------------------------
var plusImage = "img/img_desarrollo/mas01.gif";
var minusImage = "img/img_desarrollo/menos01.gif";

function sel_menu(op){

	estado = document.getElementById('men_' + op).style.display;

	if (estado=='none')	{
		document.getElementById('men_' + op).style.display="";
		document.getElementById('ImageOpc' + op).src = minusImage;
	}
	else{
		document.getElementById('men_' + op).style.display="none";
		document.getElementById('ImageOpc' + op).src = plusImage;
	}
}
function paginar(form, pagina){
	form.hdPagina.value=pagina;
	form.submit();
}
function aplicarOrden(form, orden){
	form.hdOrden.value=orden;
	form.submit();
}
function alta(pagina) {
	window.location=pagina+'?M=A';
}
function modificarFila(param, pagina) {
	window.location = pagina+'?'+param;		
}
function modificarBtn(form, pagina) {
var nombre;
var contadorChks=0;
var checkSel;
var param;

	for (var i=0;i < form.elements.length;i++)	{
		var elemento = form.elements[i];
		if (elemento.name.substring(0,8)=='checkbox') {
			if (elemento.checked == true) {
				contadorChks++;
				nombre=elemento.value;
			}
		}
	}

	if (contadorChks==0) {
		alert('seleccione el registro que desea modificar.');
		return true;
	}

	if (contadorChks>1) {
		alert('seleccione un solo registro para modificar.');
		return true;
	}


	checkSel=nombre.substring(8,12);

	param='';
	param=param+'c='+checkSel+'&';
	param=param+'M=M';
	window.location = pagina+'?'+param;		
}

function ajaxobj() {
	try {
		_ajaxobj = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			_ajaxobj = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			_ajaxobj = false;
		}
	}
   
	if (!_ajaxobj && typeof XMLHttpRequest!='undefined') {
		_ajaxobj = new XMLHttpRequest();
	}
	
	return _ajaxobj;
}
function cargaCboProvincias(pais, todos) {
	var ajax = ajaxobj();
	ajax.open("POST", "../includes/cargaProvincias.php", true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			var obj = document.getElementById("cboProvincia");

			tamanio=obj.options.length;
			for (var i=0; i<=tamanio; i++) {
				obj.options[0]=null;
			}

			inicio=0;
			if (todos!="") {
				obj.options[0] = new Option("-- "+todos+" --", "XX");
				inicio=1;
			}	

			var datos = ajax.responseXML;
			provincias = datos.getElementsByTagName("provincia");
	
			
			for (i=0;i<provincias.length;i++) {
				codigo=provincias[i].getElementsByTagName("codigo").item(0).firstChild.data
				descripcion=provincias[i].getElementsByTagName("descripcion").item(0).firstChild.data
				obj.options[i+inicio] = new Option(descripcion, codigo);

			}
		}
	}
	ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	ajax.send("&p="+pais);
}
function cargaCboUsuarios(cliente, todos, nombre) {

	var ajax = ajaxobj();
	ajax.open("POST", "../includes/cargaUsuarios.php", true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {

			var obj = document.getElementById(nombre);

			if (obj==null) {
//				se busca el objeto combo con el for porque el getElementById devuelve null
				for (var i=0;i < document.forms[0].elements.length;i++)	{
					if (document.forms[0].elements[i].name.substring(0,3)=='cbo') {
						if (document.forms[0].elements[i].name==nombre) obj=document.forms[0].elements[i];
					}
				}
			}

			tamanio=obj.options.length;
			for (var i=1; i<=tamanio; i++) {
				obj.removeChild(obj.childNodes[0]);
			}

			if (obj!=null) {
				inicio=0;
				if (todos!="") {
					obj.options[0] = new Option("-- "+todos+" --", "XX");
					inicio=1;
				}	
	
				var datos = ajax.responseXML
				usuarios = datos.getElementsByTagName("usuario");
				
				for (i=0;i<usuarios.length;i++) {
					codigo=usuarios[i].getElementsByTagName("codigo").item(0).firstChild.data
					descripcion=usuarios[i].getElementsByTagName("nombre").item(0).firstChild.data
					obj.options[i+inicio] = new Option(descripcion, codigo);
	
				}
			} else {
				alert("no se encontró el combo '"+nombre+"'");
			}
		}
	}
	ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	ajax.send("&c="+cliente);
}

function cargaCboClientes(tipoCliente, todos, nombre) {
	var ajax = ajaxobj();
	ajax.open("POST", "../includes/cargaClientes.php", true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {

			var obj = document.getElementById(nombre);
			if (obj==null) {
//				se busca el objeto combo con el for porque el getElementById devuelve null
				for (var i=0;i < document.forms[0].elements.length;i++)	{
					if (document.forms[0].elements[i].name.substring(0,3)=='cbo') {
						if (document.forms[0].elements[i].name==nombre) obj=document.forms[0].elements[i];
					}
				}
			}
			tamanio=obj.options.length;
			for (var i=0; i<=tamanio; i++) {
				obj.options[0]=null;
			}

			inicio=0;
			if (todos!="") {
				obj.options[0] = new Option("-- "+todos+" --", "XX");
				inicio=1;
			}	


			var datos = ajax.responseXML
			
			clientes = datos.getElementsByTagName("cliente");
			
			for (i=0;i<clientes.length;i++) {
				codigo=clientes[i].getElementsByTagName("codigo").item(0).firstChild.data
				descripcion=clientes[i].getElementsByTagName("nombre").item(0).firstChild.data
				obj.options[i+inicio] = new Option(descripcion, codigo);
			}
		}
	}
	ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	ajax.send("&tc="+tipoCliente);
}
function CalculaNIF(NIF, LetraNIF) {

var varNIF;        

            if (NIF.value=="") return false;

            if (NIF.value.substring(0,1)=="0") {

                        alert("el NIF no puede empezar por 0");

                        LetraNIF.value = "";

                        NIF.value = "";

                        return false;

            }

            varNIF = parseInt(NIF.value);

 

            if (isNaN(varNIF)) {

                        LetraNIF.value = "";

                        NIF.value = "";

                        return false;

            }

            cadena="TRWAGMYFPDXBNJZSQVHLCKET";

            posicion = varNIF % 23;

            letra = cadena.substring(posicion,posicion+1);

            LetraNIF.value = letra;

  NIF.value = varNIF;

}
function validacionCIF(CIF) {
	var dc;
	var ud;
	if (CIF.value!='') {
		if (CompruebaCIF(CIF, 'el CIF debe tener una longitud de 9 dígitos', 'el primer caracter debe ser una letra de las siguientes A,B,C,D,E,F,G,H,K,L,M,N,P,Q,S')==true) {
			dc=ValidaCIF(CIF, 'El dígito de control es: J ó 0');
			ud=parseInt(CIF.value.substr(8,1));
			if (dc!=ud) {
				alert('El dígito de control no coincide');
				CIF.select(); 
				CIF.focus();
				return false;
			}
		}
		else {
			CIF.select(); 
			CIF.focus();
			return false;
		}				
	}
	return true;
}

function CompruebaCIF(CIF,msg1,msg2) {
	var res=false;
	var aux=CIF.value.toUpperCase(); 
	if (!/^[A-Za-z0-9]{9}$/.test(aux)) alert (msg1); //"Longitud incorrecta, un CIF consta de 9 dígitos"

	else if (!/^[ABCDEFGHKLMNPQS]/.test(aux)) alert (msg2); //"El primer dígito es incorrecto, debe ser una letra de las siguientes: A,B,C,D,E,F,G,H,K,L,M,N,P,Q,S"

	else res = true;

	return res;
}
function ValidaCIF(CIF,msg1) {
	var arrN = new Array(0,2,4,6,8,1,3,5,7,9); 
	var aux = 0; 

	for(i=2;i<=6;i+=2 ) {
		aux = aux + arrN[parseInt(CIF.value.substr(i-1,1))];
		aux = aux + parseInt(CIF.value.substr(i,1));
	}

	aux = aux + arrN[parseInt(CIF.value.substr(7,1))];
	aux = (10 - ( aux % 10));

	if(aux==10) {
		return 0;
//	    alert(msg1); //"El dígito de control es: J ó 0"
	}
	else {
		return aux;
	}

	return aux;
}

function ContadorCaracteres(campo, maxcaracteres) {
	var tamaniocampo;
	
	tamaniocampo=campo.value.length;
	if (tamaniocampo > maxcaracteres)	{
		campo.value = campo.value.substring(0, maxcaracteres);
	}
}

//-->
