String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

/* funciones de validacion de ingreso de datos*/

function ValidarNombre(oNombre)
{
  if ((oNombre.value).trim() == '')
  {
    alert('Por favor ingresa el nombre');
    oNombre.focus();
    return false;
  }
  else
    return true;
}

function ValidarApellido(oApellido)
{
  if ((oApellido.value).trim() == '')
  {
    alert('Por favor ingresa el apellido');
    oApellido.focus();
    return false;
  }
  else
    return true;
}

function ValidarDocumento(oDocumento)
{
  if ((oDocumento.value).trim() == '')
  {
    alert('Por favor ingresa el documento');
    oDocumento.focus();
    return false;
  }
  else
    return true;
}

function ValidarEmail(oEmail)
{
  var oRegExp = /[a-z_0-9\-]+(\.[a-z_0-9\-]+)*@[a-z_0-9\-]+(\.[a-z_0-9\-]+)*\.([a-z]{2}|[a-z]{3}|[a-z]{4})$/i;
  if ((oEmail.value).trim() == '')
  {
    alert('Por favor ingresa el email');
    oEmail.focus();
    return false;
  }	
    
  if (!(oRegExp.test(oEmail.value)))
  {
    alert("El email tiene caracteres incorrectos");
	  oEmail.focus();	
    return false;
  }
  return true;
}

function ValidarReingresoEmail(oEmail, oReingresoEmail)
{
  if (ValidarEmail(oEmail))
  {
    if (oEmail.value != oReingresoEmail.value)
    {
      alert('Por favor verifica la confirmacion de email');
      oReingresoEmail.focus();
      return false;
    }
    else
      return true;
  }
}

function ValidarClave(oClave)
{
  if ((oClave.value).trim() == '')
  {
    alert('Por favor ingresa la clave');
    oClave.focus();
    return false;
  }
  else
    return true;  
}

function ValidarTelefono(oCodigoArea, oTelefono)
{
  if (((oCodigoArea.value).trim() == '') || ((oTelefono.value).trim() == ''))
  {
    alert('Por favor ingresa el codigo de area y el telefono');
    if ((oCodigoArea.value).trim() == '') 
      oCodigoArea.focus();
    else
      oTelefono.focus();
    return false;
  }
  else
    if ((oTelefono.value).length < 6)  
    {
      alert('El telefono no es correcto');
      oTelefono.focus();
    }
    else
      return true;
}

function ValidarReingresoTelefono(oCodigoArea, oTelefono, oInterno, oReingresoCodigoArea, oReingresoTelefono, oConfirmaInterno)
{
  if (ValidarTelefono(oCodigoArea, oTelefono))
  {
    if ((oCodigoArea.value != oReingresoCodigoArea.value) || (oTelefono.value != oReingresoTelefono.value) || (oInterno.value != oConfirmaInterno.value))
    {
      alert('Por favor verifica la confirmacion del telefono');
      if ((oReingresoCodigoArea.value).trim() == '') 
        oReingresoCodigoArea.focus();
      else if ((oReingresoTelefono.value).trim() == '') 
        oReingresoTelefono.focus();
      else
        oConfirmaInterno.focus();
      return false;
    }
    else
      return true;    
  }
}

function ValidarTelefonoMovil(oTelefono)
{
   if ((oTelefono.value).trim() == '')
   {
      alert('Por favor ingresa el telefono movil');
      oTelefono.focus();
      return false;
   }
   else
      return true;    
}

function ValidarCalle(oCalle)
{
  if ((oCalle.value).trim() == '')
  {
    alert('Por favor ingresa el domicilio');
    oCalle.focus();
    return false;
  }
  else
    return true;
}

function ValidarNumeroCalle(oNumeroCalle)
{
  if ((oNumeroCalle.value).trim() == '')
  {
    alert('Por favor ingresa la numeracion del domicilio o 0(cero) si no tiene');
    oNumeroCalle.focus();
    return false;
  }
  else
    return true;
}

function ValidarCP(oCP)
{
  if ((oCP.value).trim() == '')
  {
    alert('Por favor ingresa el CP del domicilio');
    oCP.focus();
    return false;
  }
  else
    return true;
}

function ValidarDatosAsociadosCP(oCP, oGastosEnvio, oPrecioEnvio)
{
  if ((oCP.value).trim() == '')
  {
    alert('Por favor ingresa el CP del domicilio');
    oCP.focus();
    return false;
  }
  else
  {
    if (((oCP.value).substr(0,1) == '0') || ((oCP.value).substr(0,2) == '00') || ((oCP.value).substr(0,3) == '000') || (oCP.value == '0000') || (oGastosEnvio.innerHTML == '') || (oPrecioEnvio.value == ''))
    {
      alert('Por favor ingresa correctamente el CP del domicilio');
      oCP.value = '';
      oCP.focus();
      return false;
    }
    else
      return true;
  }
}

function ValidarFecha(sDia, sMes, sAnio)
{
	dateFecha = new Date(sMes + '/' + sDia + '/' + sAnio );
	sDiaConv = '0' + dateFecha.getDate();
	sDiaConv = sDiaConv.substr(sDiaConv.length - 2, sDiaConv.length);
	sMesConv = '0' + (dateFecha.getMonth() + 1);
	sMesConv = sMesConv.substr(sMesConv.length - 2, sMesConv.length);
	if (sDia == sDiaConv && sMes == sMesConv)
		return true;
	else
		return false;
}

function ValidarFechaNacimiento(oDia, oMes, oAnio)
{
  if (ValidarFecha(oDia[oDia.selectedIndex].value, oMes[oMes.selectedIndex].value, oAnio[oAnio.selectedIndex].value) == false)
  {
    alert('Por favor ingresa una fecha de nacimiento correcta');
    oDia.focus();
    return false;
  }
  else
    return true;
}

/* funciones de validacion de KeyPress*/
var isIE = document.all?true:false;

function InputMaskNumeric(oEvent)
{
  var iKeyCode = (isIE) ? window.event.keyCode:oEvent.which;
  if(iKeyCode>=48 && iKeyCode<=57) return true;
	if(iKeyCode < 32)
	   return true;
  return false;
}

function InputMaskChar(oEvent) 
{
  var key = (isIE) ? window.event.keyCode : oEvent.which;
  var isNum = ((key==0) || (key==8) || (key==9) || (key==46) || (key > 64 && key < 91) || (key > 96 && key < 123) || (key==165) || (key==164) || (key==32) || (key==209) || (key==241)) ? true:false;
  return (isNum);
}

function InputMaskCharNumeric(oEvent) 
{
  var key = (isIE) ? window.event.keyCode : oEvent.which;
  var isCharNum = ((key==0) || (key==8) || (key==9) || (key==46) || (key >= 48 && key <= 57) || (key > 64 && key < 91) || (key > 96 && key < 123) || (key==118) || (key==165) || (key==164) ||  (key==209) || (key==241)) ? true:false;
  return (isCharNum);
}

