<!--
// JavaScript Document

function validar(form) {
	numCamp = document.forms[0].length;
 with(document.forms[0]) {
	if (nomUser.value.replace(/ /g, '') == '') {
		alert('El nombre es requerido');
		nomUser.style.backgroundColor = '#C4C4FF';
		nomUser.focus();
		nomUser.select();
		return false;
	}
	if (apellidosUser.value.replace(/ /g, '') =='') {
		alert('Los apellidos son requeridos');
		apellidosUser.style.backgroundColor = '#C4C4FF';
		apellidosUser.focus();
		apellidosUser.select();
		return false;
	}		  
	if (numIdentifica.value.replace(/ /g, '') =='') {
		alert('El número de identificación es requerido');
		numIdentifica.style.backgroundColor = '#C4C4FF';
		numIdentifica.focus();
		numIdentifica.select();
		return false;
	}
  numIden = tipoIdentifica.options[tipoIdentifica.selectedIndex].value;
   if ((numIden == 0) || (numIden == 1) || (numIden == 4)) {
		 cif = document.forms[0].numIdentifica.value;
        letra = cif.substring(0, 1);
       if (isNaN(letra)) {
        delante = 1;
       } else {
       delante = 0;
       }
      if (delante==0) {
       letra = cif.substring(cif.length-1,cif.length);

      if (isNaN(letra)) {
        detras = 1;
      } else {
        detras = 0;
      }
     }
     if (delante == 1) {
       numeros = cif.substring(1,cif.length);
      if (isNaN(numeros) || (numeros.length != 8)) {
	    alert("Escriba su número CIF con formato \'A00000000\' ,NIF o DNI con formato \'00000000A\'");
		numIdentifica.style.backgroundColor = '#C4C4FF';
		numIdentifica.focus();
		numIdentifica.select();
	    return false;
      }
     }
     if (detras==1) {
      numeros = cif.substring(0,cif.length-1);
       if (isNaN(numeros) || (numeros.length != 8)) {
	    alert("Escriba su número CIF con formato \'A00000000\' ,NIF o DNI con formato \'00000000A\'");
		numIdentifica.style.backgroundColor = '#C4C4FF';
		numIdentifica.focus();
		numIdentifica.select();
	    return false;
     }
    }
    if ((delante==0) && (detras==0)) {
     alert('El CIF/NIF o DNI no es correcto');
		numIdentifica.style.backgroundColor = '#C4C4FF';
		numIdentifica.focus();
		numIdentifica.select();
	    return false;
    }
 }
	if (email.value.replace(/ /g, '') =='') {
		alert('El email es requerido');
		email.style.backgroundColor = '#C4C4FF'; 
		email.focus();
		email.select();
		return false;
	}
	 mail = email.value;
 if ((mail.indexOf("@") == -1) || (mail.indexOf(".")==-1)) {
   alert('El e-mail no es correcto');
		email.style.backgroundColor = '#C4C4FF'; 
		email.focus();
		email.select();
		return false;
  }	
		
	/* if (login.value.replace(/ /g, '') =='') {
		alert('El nombre de usuario(login) es requerido');
		login.style.backgroundColor = '#C4C4FF';
		login.focus();
		login.select();
		return false;
	} */
	if ((pwd.value.replace(/ /g, '') =='') && (pwd1.value.replace(/ /g, '') == '')){
		alert('La contraseña es requerida');
		pwd.style.backgroundColor = '#C4C4FF'; pwd1.style.backgroundColor = '#C4C4FF';
		pwd.focus();
		pwd.select();
		return false;
	}
	if  (pwd.value != pwd1.value) {
		alert('Repita las contraseñas no son correctas');
		pwd.value = ""; pwd1.value="";
		pwd.style.backgroundColor = '#C4C4FF'; pwd1.style.backgroundColor = '#C4C4FF';
		pwd.focus();
		pwd.select();
		return false;
	}
	if  (pwd.value.length < 4) {
		alert('La contraseña debe tener como minímo 4 caracteres');
		pwd.value = ""; pwd1.value="";
		pwd.style.backgroundColor = '#C4C4FF'; pwd1.style.backgroundColor = '#C4C4FF';
		pwd.focus();
		pwd.select();
		return false;
	}
	if (preguntaPwd.value.replace(/ /g, '') =='') {
		alert('El número de identificación es requerido');
		preguntaPwd.style.backgroundColor = '#C4C4FF';
		preguntaPwd.focus();
		preguntaPwd.select();
		return false;
	}
	if (respuestaPwd.value.replace(/ /g, '') == '') {
		alert('La respuesta recordar contrase&ntilde;a es requerida');
		respuestaPwd.style.backgroundColor = '#C4C4FF';
		respuestaPwd.focus();
		respuestaPwd.select();
		return false;
	}
	if (nomVia.value.replace(/ /g, '') == '') {
		alert('El nombre de la via es requerido');
		nomVia.style.backgroundColor = '#C4C4FF';
		nomVia.focus();
		nomVia.select();
		return false;
	}
	if (localidad.value.replace(/ /g, '') == '') {
		alert('El nombre de la población es requerido');
		localidad.style.backgroundColor = '#C4C4FF';
		localidad.focus();
		localidad.select();
		return false;
	}
	if (codigoPostal.value.replace(/ /g, '') == '') {
		alert('El código postal es requerido');
		codigoPostal.style.backgroundColor = '#C4C4FF';
		codigoPostal.focus();
		codigoPostal.select();
		return false;
	}
	numCodPos = codigoPostal.value;
	paises = pais.options[pais.selectedIndex].value;
	if (paises == 11) {
		if (numCodPos.length != 5) {
		  alert('El código postal no es correcto');
		  codigoPostal.style.backgroundColor = '#C4C4FF';
		  codigoPostal.focus();
		  codigoPostal.select();
		  return false
		}
		ini = numCodPos.substr(0,1);
		if (ini == 0) {
			ini = numCodPos.slice(1,2);
		} else {
			ini= numCodPos.slice(0,2);
		}
		numProv1 = province.options[province.selectedIndex].value;
		if (ini != numProv1) {
		  alert('El código postal no es correcto');
		  codigoPostal.style.backgroundColor = '#C4C4FF';
		  codigoPostal.focus();
		  codigoPostal.select();
		  return false;
		}
	}
		if (telefono.value.replace(/ /g, '') == '') {
		alert('El teléfono es requerido');
		telefono.style.backgroundColor = '#C4C4FF';
		telefono.focus();
		telefono.select();
		return false;
	  }
	 tel = telefono.value;
    for (i=0; i < tel.length;i++) {
      tel1 = tel.substring(i, i+1);
      if ((tel1 < "0" || "9" < tel1 ) && (tel1 != " ") && (tel1 != ".") && (tel1 != "-") && (tel1 != "(")  && (tel1 != ")") && (tel1 != "+")) {
        alert('El teléfono no es correcto');
		  telefono.style.backgroundColor = '#C4C4FF';
		  telefono.focus();
		  telefono.select();
        return false;
     }
   }
 }
}


function roundOff(value, precision)
{
        value = "" + value //convert value to string
        precision = parseInt(precision);

        var whole = "" + Math.round(value * Math.pow(10, precision));

        var decPoint = whole.length - precision;

        if(decPoint != 0)
        {
                result = whole.substring(0, decPoint);
                result += ".";
                result += whole.substring(decPoint, whole.length);
        }
        else
        {
                result = 0;
                result += ".";
                result += whole.substring(decPoint, whole.length);
        }
        return result;
}

 
 function converJava(num) {
	  e=0;
	  pos2="";
	  num = num+''
	 for (i=0; i < num.length; i++) {
	    e = (i + 1);
		pos = num.slice(i, e);
		if (pos.indexOf(".") != -1) {
		  pos = "";
		}
		if (pos.indexOf(",") != -1) {
		  pos = ".";
		}
		pos2 += ""+pos;
		
	 }
	 return pos2;
 }
 
  function converSpain(num) {
	  e=0;
	  pos2="";
	  num = num +' ';
	  if (num.indexOf(".") != -1) {
		num = roundOff(num, 2)
	  }
	 for (i=0; i < num.length; i++) {
	    e = (i + 1);
		pos = num.slice(i, e);
		if (pos.indexOf(".") != -1) {
		  pos = ",";
		}
		posi = ""+pos;
		pos2 += posi;
	 }
	
	 pos2 = puntitos(pos2,3);
	 
	 return pos2;
 }
 
function puntitos(donde,caracter){
pat = /[\*,\+,\(,\),\?,\\,\$,\[,\],\^]/
valor = donde
largo = valor.length
var trozo;
crtr = true
if(isNaN(caracter) || pat.test(caracter) == true){
  if (pat.test(caracter)==true) {
    caracter = "\\" + caracter
     }
  carcter = new RegExp(caracter,"g")
  valor = valor.replace(carcter,"")
  donde = valor
  crtr = false
 }
else{
  var nums = new Array()
  cont = 0
  for(m=0;m<largo;m++){
     if(valor.charAt(m) == "." || valor.charAt(m) == " "){
      continue;
      }
    else{
      nums[cont] = valor.charAt(m)
      cont++
      }
   }
}

var cad1="",cad2="",tres=0
if(largo > 3 && crtr == true){
   for (k=nums.length-1;k>=0;k--){
     cad1 = nums[k]
     cad2 = cad1 + cad2
     tres++
     if((tres%3) == 0){
        if(k!=0){
          cad2 = "." + cad2
          }
        }
      }
    
	if (cad2.indexOf('.,') != -1) {
        trozo = cad2.substr(0, cad2.indexOf('.,'));
		trozo += cad2.substr(cad2.indexOf('.,')+1, cad2.length);
	}
	
	donde = trozo;
	return donde;
  }
} 

//sumar fechas
var aFinMes = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); 

  function finMes(nMes, nAno){ 
   return aFinMes[nMes - 1] + (((nMes == 2) && (nAno % 4) == 0)? 1: 0); 
  } 

   function padNmb(nStr, nLen, sChr){ 
    var sRes = String(nStr); 
    for (var i = 0; i < nLen - String(nStr).length; i++) 
     sRes = sChr + sRes; 
    return sRes; 
   } 

   function makeDateFormat(nDay, nMonth, nYear){ 
    var sRes; 
    sRes = padNmb(nDay, 2, "0") + "/" + padNmb(nMonth, 2, "0") + "/" + padNmb(nYear, 4, "0");
    return sRes; 
   } 
    
  function incDate(sFec0){ 
   var nDia = parseInt(sFec0.substr(0, 2), 10); 
   var nMes = parseInt(sFec0.substr(3, 2), 10); 
   var nAno = parseInt(sFec0.substr(6, 4), 10); 
   
   nDia += 1; 
   if (nDia > finMes(nMes, nAno)){ 
    nDia = 1; 
    nMes += 1; 
    if (nMes == 13){ 
     nMes = 1; 
     nAno += 1; 
    } 
   } 
   return makeDateFormat(nDia, nMes, nAno); 
  } 

  function decDate(sFec0){ 
   var nDia = Number(sFec0.substr(0, 2)); 
   var nMes = Number(sFec0.substr(3, 2)); 
   var nAno = Number(sFec0.substr(6, 4)); 
   nDia -= 1; 
   if (nDia == 0){ 
    nMes -= 1; 
    if (nMes == 0){ 
     nMes = 12; 
     nAno -= 1; 
    } 
    nDia = finMes(nMes, nAno); 
   } 
   return makeDateFormat(nDia, nMes, nAno); 
  } 

  function addToDate(sFec0, sInc){ 
   var nInc = Math.abs(parseInt(sInc)); 
   var sRes = sFec0; 
   if (parseInt(sInc) >= 0) 
    for (var i = 0; i < nInc; i++) sRes = incDate(sRes); 
   else 
    for (var i = 0; i < nInc; i++) sRes = decDate(sRes); 
	
   return sRes; 
  } 

  function recalcF1(){ 
   with (document.form2){ 

      //TmpEntrega.value = data.value+ 5; 
   } 
  } 

function envia(n, p) {
	var ruta = document.location.href;
	if (ruta.indexOf("Pagina=") != -1) {
		
	 ruta = ruta.substring(0, ruta.indexOf("Pagina=")-1)
	}
	var string = "";
	switch(n) {
		case 1:
		  string = 'Pagina=Primero';
		  break;
		case 2:
		   string = 'Pagina=Anterior';
		   break;
		 case 3:
		   string = 'Pagina=Siguiente';
		   break;
		  case 4:
		   string = 'Pagina=Ultimo&ind='+p;
		   break;
	}
	if (ruta.indexOf("?") == -1) {
		document.location.href = ruta + '?' + string;
	} else {
		document.location.href = ruta + '&' + string;
	}
}

function CreaXHR()
{
  var ref = false;

  try { // Procedimiento para crear un objeto
   // XMLHttpRequest compatible entre distintos
   ref = new ActiveXObject('Msxml2.XMLHTTP');
  } catch (e1) { // navegadores Web
   try {
     ref = 
        new ActiveXObject('Microsoft.XMLHTTP');
     }  catch (e2) {
     objXML = false;
   }
  }

  if (!ref && (typeof XMLHttpRequest != 'undefined' || window.XMLHttpRequest)) 
   ref = new XMLHttpRequest();  
   
  return ref;
}

function CargaGtos() {
 divListado = document.getElementById('gtos');
 ajax=CreaXHR();
 ajax.open("GET", "/asp/gtos.asp");
 ajax.onreadystatechange=function() {
  if (ajax.readyState==4) {
   divListado.innerHTML = ajax.responseText;
  }
 }
 ajax.send(null)
}

function CargaIdio(id) {
 divListado = document.getElementById('botiga');
 ajax=CreaXHR();
 ajax.open("GET", "cargar.asp?idi="+id);
 ajax.onreadystatechange=function() {
  if (ajax.readyState==4) {
   divListado.innerHTML = ajax.responseText;
  }
 }
 ajax.send(null)
}
//-->