<!-- PARA VALIDAR TELEFONO -->
// caracteres admitidos en nos de telefono
// funcion que quita espacios de mas en un campo de texto
var whitespace = " \t\n\r";

function cargar(action){
	if(action!='null'){
		document.getElementById('mainbody').src = action;
		document.getElementById('dvContenido').style.display = 'none';
	}
}

function enviarForm(frm,a) {
	frm.action = a;
	//frm.action = pintaAction(a);
	frm.submit(); 
}
function quitaEspacio(campo) { 
	var pBlanco, uBlanco, vBlanco , c1;
	pBlanco = /^ /; //espacios en blanco al principio
	uBlanco = / $/; // espacios en blanco al final
	vBlanco = /[ ]+/g; // espacios en blanco en medio
	var phoneChars1 = /[-]+/g; 
	var phoneChars2 = /[+]+/g; 
	var phoneChars3 = /[(]+/g; 
	var phoneChars4 = /[)]+/g; 
 	c1 = new String(campo);
 	c1 = c1.replace(vBlanco,"");
 	c1 = c1.replace(pBlanco,"");
 	c1 = c1.replace(uBlanco,"");
 	c1 = c1.replace(phoneChars1,"");
 	c1 = c1.replace(phoneChars2,"");
 	c1 = c1.replace(phoneChars3,"");
 	c1 = c1.replace(phoneChars4,"");
	//alert(" c1: "+ c1);
	return c1;
}

function isExist(obj){
	if (null == obj) return false;
	if ('undefined' == typeof(obj) ) return false;
	return true;
}
function pintaAction(a){
	
	var action = '<html:rewrite page="/web/'+ a +'.do"/>';
	//var action = '/web/'+ a + '.do';
	//alert(action);
	return action;
}
function abre(url, target) {

	var ventana = window.open(url,target,"toolbar=no,scrollbars=yes,status=yes,location=no,menubar=no,resizable=yes,top=30,left=60,width="+(screen.availWidth-screen.availWidth/2)+",height="+(screen.availHeight-screen.availHeight/2));
	ventana.focus();

}
function loadBotones(id, obj){
	var ok = isExist(obj);
	if (!ok) {
		ocultaCapa(id);
	}else{
		muestraCapa(id);
	}
}

function muestraCapa(capa) {
	capa.style.display="block";
}

function ocultaCapa(capa) {
	capa.style.display="none";
}

	
function switchDIV(idCapa) {
	
		var OCULTO="none";
		var VISIBLE="block";
		
		var d1 = document.getElementById(idCapa);
		 
	    d1.style.display = (d1.style.display == OCULTO ? VISIBLE : OCULTO );

	}
	
function OpenWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}


function validaNif (nif) {
	cadena="TRWAGMYFPDXBNJZSQVHLCKET"
	nif = nif.toUpperCase();
	nifNumero = nif.substring(0,nif.length-1);
	nifLetra = nif.substring(nif.length-1);
	posicion = nifNumero % 23
	letra = cadena.substring(posicion,posicion+1)

	if ( letra == nifLetra)
		return true;
	else
		return false;
}

function validaPasaporte (pasaporte) {
	return true;
}

function validaNie (nie) {
	nie = nie.toUpperCase();
	letra = nie.substring(0,1);
	nif = nie.substring(1,nie.length);
	
	if ( letra == "X" ){		
		return validaNif(nif);
	}else if (letra == "Y" ){	
		return validaNif("1"+nif);
	}else if (letra == "Z" ){		
		return validaNif("2"+nif);		
	}else{
		return false;
	}
}

function validaCif (cif) {
	var resul = false;
  var temp = cif.toUpperCase(); // pasar a may?sculas

  if (!/^[A-Za-z0-9]{9}$/.test(temp))  // Son 9 d?gitos?
     return false ;//alert ("Longitud incorrecta, un CIF consta de 9 d?gitos");

  else if (!/^[ABCDEFGHKLMNPQS]/.test(temp)) // Es una letra de las admitidas ?
     return false; //alert("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 {
	  var v1 = new Array(0,2,4,6,8,1,3,5,7,9);
	  var temp = 0;
	  var temp1;

	  for( i = 2; i <= 6; i += 2 )
	    {
	      temp = temp + v1[ parseInt(cif.substr(i-1,1)) ];
	      temp = temp + parseInt(cif.substr(i,1));
	    };

	  temp = temp + v1[ parseInt(cif.substr(7,1)) ];
	  temp = (10 - ( temp % 10));

	  if( temp == 10 )
			temp = 0;

		dc = parseInt(cif.substring(cif.length-1));
		if ( dc == temp )
			return true;
		else
	  	return false;
	}
}

function calculaDigitoControl (tarjeta) {
	sumaTotal = 0;
	for ( i=0; i<tarjeta.length-1; ++i ) {
		numero = parseInt(tarjeta.substring(i,i+1));
		if (i%2==1) {
			//N?mero par. Se suma
			sumaTotal += numero;
		} else {
			//Numero impar
			numero *= 2;
			if ( numero < 10 )
				sumaTotal += numero;
			else {
				strNumero = "" + numero;
				numero = parseInt(strNumero.substring(0,1)) + parseInt(strNumero.substring(1,2));
				sumaTotal += numero;
			}
		}
	}
	strNumero = "" + sumaTotal;
	numero = parseInt(strNumero.substring(1,2));
	if ( numero != 0 ) {
		numero = 10 - numero;
	}

	return numero;
}
function validaTarjeta(tarjeta) {
	digitoControl = parseInt(tarjeta.substring(tarjeta.length-1,tarjeta.length));
	if ( digitoControl == calculaDigitoControl(tarjeta) )
		return true;
	else
		return false;
}





function CompruebaDatos(cif)
{
  }



function trimAll(sString) {
       if(sString==null) 
          return null;
          
	   while (sString.substring(0,1) == ' ') {
	         sString = sString.substring(1, sString.length);
	   }

	   while (sString.substring(sString.length-1, sString.length) == ' '){
	         sString = sString.substring(0,sString.length-1);
	   }
	   return sString;
}





function currencyFormat(fld, milSep, decSep, e) {

//onKeyPress="return(currencyFormat(this,',','.',event))

  var sep = 0;
  var key = '';
  var i = j = 0;
  var len = len2 = 0;
  var strCheck = '0123456789';
  var aux = aux2 = '';
  var whichCode = (window.Event) ? e.which : e.keyCode;

  if (whichCode == 13) return true;  // Enter
  if (whichCode == 8) return true;  // Delete
  key = String.fromCharCode(whichCode);  // Get key value from key code
  if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
  len = fld.value.length;
  for(i = 0; i < len; i++)
  if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
  aux = '';
  for(; i < len; i++)
  if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
  aux += key;
  len = aux.length;
  if (len == 0) fld.value = '';
  if (len == 1) fld.value = '0'+ decSep + '0' + aux;
  if (len == 2) fld.value = '0'+ decSep + aux;
  if (len > 2) {
    aux2 = '';
    for (j = 0, i = len - 3; i >= 0; i--) {
      if (j == 3) {
        aux2 += milSep;
        j = 0;
      }
      aux2 += aux.charAt(i);
      j++;
    }
    fld.value = '';
    len2 = aux2.length;
    for (i = len2 - 1; i >= 0; i--)
    fld.value += aux2.charAt(i);
    fld.value += decSep + aux.substr(len - 2, len);
  }
  return false;
}


