function reemplazar(cadena,txtSearch,txtNuevo) {
  while (cadena.indexOf(txtSearch)>-1) {
    pos = cadena.indexOf(txtSearch);
    cadena = "" + (cadena.substring(0, pos) + txtNuevo + cadena.substring((pos + txtSearch.length), cadena.length));
  }
  return cadena;
}
function isNumber(input) {
    var allowed = "0123456789";
    if (input.length==0) {
        return false;
    };
    for (i=0;i<input.length;i++){
        if (allowed.indexOf(input.charAt(i))==-1){
            return false;
        }
    }
    return true;
}
var bbandera = false;
function setBandera() {
  if(bbandera) {
     bbandera=false;
  }
}
function isChecaCampo(ItemNombre,valor,tipo)
{
 if (bbandera)
   return false;
 if (valor != "")
 {
   switch (tipo)
   {
    case 'N' :
       if(!isNumber(valor))
       {
         alert("Debe teclear un n?mero Por Favor");
         ItemNombre.focus();
         ItemNombre.select();
         return false;
       }
       else
         return true;
      break;
    default:
       alert("Error no es posible validar:\nTipo de dato no reconocido.");
       return false;
      break;
   }
 }
}
function validaDirEmail(estr) {
  var s = estr;
  s = s.replace(/^\s*|\s*$/g, "");
  if (s == "undefined" || s.length < 6) {return false;}
  re = /\s+/g
  if (re.test(s)) {return false;}
  re = /^(\w|[^_]\.|[\-])+((\@){1}([^_]))(([a-z]|[\d]|[\-]|\.)+|([^_]\.[^_])*)+\.[a-z]{2,6}$/i
  re = /\.(a[c-gil-oq-uwz]|b[a-bd-jm-or-tvwyz]|c[acdf-ik-orsuvx-z]|d[ejkmoz]|e[ceghr-u]|f[i-kmorx]|g[abd-ilmnp-uwy]|h[kmnrtu]|i[delm-oq-t]|j[emop]|k[eg-imnprwyz]|l[a-cikr-vy]|m[acdghk-z]|n[ace-giloprtuz]|om|p[ae-hk-nrtwy]|qa|r[eouw]|s[a-eg-ort-vyz]|t[cdf-hjkm-prtvwz]|u[agkmsyz]|v[aceginu]|w[fs]|y[etu]|z[admrw]|com|edu|net|org|mil|gov|biz|pro|aero|coop|info|name|museum)$/i
  if (!re.test(s)) {return false;}
  re = /\@\@/
  return(!re.test(s));
}
var sMensaje = "";
function getDias(iMes,iAnyo)
{
 var iDias = 31
 if (iMes == 4 || iMes == 6 || iMes == 9 || iMes == 11)
  iDias = 30;
 if (iMes == 2 && (iAnyo/4) != Math.floor(iAnyo/4))
  iDias = 28;
 if (iMes == 2 && (iAnyo/4) == Math.floor(iAnyo/4))
  iDias = 29;
 return iDias;
}
function isFecha(sFecha)
{
  /* Nos indica el formato de fecha                                           */
  var mPatronFecha = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/;

  /* Divide sFecha de acuerdo a patro establecido y lo guarda en un array     */
  var arrayMatch = sFecha.match(mPatronFecha);

  /* Si sFecha no corresponde al patron                                       */
  if (arrayMatch == null)
  {
    sMensaje += "Introduzca la fecha con el formato: \"[DD] [MM] [YYYY]\" ";
    return false;
  }

  /* Guardamos las partes divididas por el metodo match en variables          */
  var iDia  = arrayMatch[1];
  var iMes  = arrayMatch[2];
  var iAnyo = arrayMatch[3];

  if (iAnyo>2100 || iAnyo<1800)
  {
   sMensaje += "A?o no reconocido.";
   return false;
  }
  if (iMes>12 || iMes<1)
  {
   sMensaje += "Mes debe ser entre 1 y 12";
   return false;
  }
  if (iDia>getDias(iMes,iAnyo) || iDia<1)
  {
   sMensaje += "Dia debe ser entre 1 y "+getDias(iMes,iAnyo);
   return false;
  }
  return true;
}
function validaForm() {
 var f = document.fContac;
 var mMsg = "";
 var mFecNac = f.mFecNacDia.value+'/'+f.mFecNacMes.value+'/'+f.mFecNacAnyo.value;
 var mVacio = false;
 sMensaje = "";


 if(f.mNombre.value==''){ mMsg = mMsg + "El Nombre es obligatorio!\n"; }
 if(f.mApellidoP.value==''){ mMsg = mMsg + "El Apellido Paterno es obligatorio!\n"; }
 if(f.mApellidoM.value==''){ mMsg = mMsg + "El Apellido Materno es obligatorio!\n"; }
 if(f.mTel.value==''){ mMsg = mMsg + "El Teléfono es obligatorio!\n"; }
 if(!validaDirEmail(f.mEmail.value)){ mMsg = mMsg + "El correo es obligatorio!\no bien no es correcto\n"; }
 if(f.mFecNacDia.value=='' || f.mFecNacMes.value=='' || f.mFecNacAnyo.value==''){
//   mMsg = mMsg + "La fecha de nacimiento es obligatorio!\n";
   mVacio = true;
 }

 if(f.mRequerimiento.value==''){ mMsg = mMsg + "El Requerimiento es obligatorio!\n"; }

 if(!mVacio && !isFecha(mFecNac)){ mMsg = mMsg + sMensaje; }

 if(mMsg!=''){ alert(mMsg); }

 f.mRequerimiento.value=reemplazar(f.mRequerimiento.value,"<"," ")
 f.mRequerimiento.value=reemplazar(f.mRequerimiento.value,">"," ")
 f.mRequerimiento.value=reemplazar(f.mRequerimiento.value,"&"," ")

 return (mMsg=='');
}

function validaFormSeParte() {
 var f = document.fContacS;
 var mMsg = "";
 var mVacio = false;
 sMensaje = "";

 if(f.mNombre.value==''){ mMsg = mMsg + "El Nombre es obligatorio!\n"; }
 if(f.mApellidos.value==''){ mMsg = mMsg + "Los Apellidos son obligatorios!\n"; }
 if(f.mEdad.value==''){ mMsg = mMsg + "La edad es obligatorio!\n"; }
 if(f.mCalleNo.value==''){ mMsg = mMsg + "La Calle y Numero es obligatorio!\n"; }
 if(f.mCol.value==''){ mMsg = mMsg + "La colonia es obligatorio!\n"; }
 if(f.mCd.value==''){ mMsg = mMsg + "La ciudad de domicilio es obligatorio!\n"; }
 if(f.mCP.value==''){ mMsg = mMsg + "El C.P. es obligatorio!\n"; }
 if(f.mEdo.value==''){ mMsg = mMsg + "El Estado de domicilio es obligatorio!\n"; }
 if(f.mTelCas.value==''){ mMsg = mMsg + "El telefono de Casa es obligatorio!\n"; }
 if(f.mTelRec.value==''){ mMsg = mMsg + "El telefono Recados es obligatorio!\n"; }
 if(!validaDirEmail(f.mEmail.value)){ mMsg = mMsg + "El E-mail es obligatorio!\n\to bien no es correcto\n"; }
 if(f.mNivelEst.value==''){ mMsg = mMsg + "El Nivel de estudios es obligatorio!\n"; }
 if(f.mCarr.value==''){ mMsg = mMsg + "La Carrera es obligatorio!\n"; }
 if(f.mUltEmp.value==''){ mMsg = mMsg + "El ultimo empleo es obligatorio!\n"; }
 if(f.mEmp.value==''){ mMsg = mMsg + "La empresa es obligatorio!\n"; }
 if(f.mPuesto.value==''){ mMsg = mMsg + "El Puesto de experiencia es obligatorio!\n"; }
 if(f.mActiv.value==''){ mMsg = mMsg + "Las Actividades que realizaba es obligatorio!\n"; }
 if(f.mCdExp.value==''){ mMsg = mMsg + "Ciudad de Experiencia es obligatorio!\n"; }

 if(mMsg!=''){ alert(mMsg); }

 return (mMsg=='');
}
function mLimTxt(campo, maxlimit) {
 if (campo.value.length>maxlimit)
  campo.value = campo.value.substring(0, maxlimit);
}

function validaClubPilotos() {
 var f = document.fContacPilotos;
 var mMsg = "";
 var mVacio = false;
 sMensaje = "";

 if(f.mNombre.value==''){ mMsg = mMsg + "El Nombre es obligatorio!\n"; }
 if(f.mApellidoP.value==''){ mMsg = mMsg + "El Apellido Paterno es obligatorio!\n"; }
 if(f.mApellidoM.value==''){ mMsg = mMsg + "El Apellido Materno es obligatorio!\n"; }
 if(!validaDirEmail(f.mEmail.value)){ mMsg = mMsg + "El correo es obligatorio!\no bien no es correcto\n"; }
 if(f.mRfc.value==''){ mMsg = mMsg + "El Rfc es obligatorio!\n"; }
 
 if(mMsg!=''){ alert(mMsg); }

 return (mMsg=='');
}

function validaNvoAgente() {
 var f = document.fNvoAgent;
 var mMsg = "";
 var mVacio = false;
 sMensaje = "";

 if(f.mNombre.value==''){ mMsg = mMsg + "El Nombre es obligatorio!\n"; }
 if(f.mApellidoP.value==''){ mMsg = mMsg + "El Apellido Paterno es obligatorio!\n"; }
 if(f.mApellidoM.value==''){ mMsg = mMsg + "El Apellido Materno es obligatorio!\n"; }
  
  if(f.mEdad.value==''){ mMsg = mMsg + "La Edad es obligatoria!\n"; }
  if(f.mTel.value==''){ mMsg = mMsg + "El Teléfono es obligatorio!\n"; }
  
 
 
 if(f.mCalle==''){ mMsg = mMsg + "La Calle es obligatoria!\n"; }
   if(f.mExt.value==''){ mMsg = mMsg + "El no. Exterior es obligatorio!\n"; }
   
    if(f.mCol.value==''){ mMsg = mMsg + "La Colonia es obligatorio!\n"; }
    if(f.mDel.value==''){ mMsg = mMsg + "La Delegación es obligatoria!\n"; }
    if(f.mCp.value==''){ mMsg = mMsg + "El C.P. es obligatorio!\n"; }
  if(f.mEstado.value==''){ mMsg = mMsg + "El Estado de domicilio es obligatorio!\n"; }
 
   if(f.mCiudad.value==''){ mMsg = mMsg + "La Ciudad de domicilio es obligatorio!\n"; }
    if(f.mAnnosAgen.value==''){ mMsg = mMsg + "Los a?os de experiencia son obligatorios!\n"; }
   if(f.mCedula.value==''){ mMsg = mMsg + "El Tipo de cedula es obligatorio obligatorio!\n"; }
  if(f.mValorCart.value==''){ mMsg = mMsg + "El Valor de la cartera es obligatorio obligatorio!\n"; }
   if(f.mCarDanos.value==''){ mMsg = mMsg + "El Porcentaje de cartera de Daños es obligatorio!\n"; }
   if(f.mCarPersonas.value==''){ mMsg = mMsg + "El Porcentaje de cartera de Personas es obligatorio!\n"; }
   if(f.mInf.value==''){ mMsg = mMsg + "El comentario de por que quieres trabajar en RSA es obligatorio!\n"; }
  

 if(f.mWeb.value=='Si'){
  	if(f.mWww.value==''){ mMsg = mMsg + "El Nombre es obligatorio!\n"; }
  }
  if(f.mEmail.value=='Si'){
   if(!validaDirEmail(f.mEmail.value)){ mMsg = mMsg + "El correo es obligatorio!\no bien no es correcto\n"; }
 }
  
 if(mMsg!=''){ alert(mMsg); }

 return (mMsg=='');
}
function validaAutomaster() {
 var f = document.fAutomaster;
 var mMsg = "";
 var mVacio = false;
 sMensaje = "";

 if(f.mNombre.value==''){ mMsg = mMsg + "El Nombre es obligatorio!\n"; }
 if(f.mApellidoP.value==''){ mMsg = mMsg + "El Apellido Paterno es obligatorio!\n"; }
 if(f.mApellidoM.value==''){ mMsg = mMsg + "El Apellido Materno es obligatorio!\n"; }
 //if(f.mIdAgente.value==''){ mMsg = mMsg + "La clave de Agente es obligatoria!\n"; }
 if(!validaDirEmail(f.mEmail.value)){ mMsg = mMsg + "El correo es obligatorio!\no bien no es correcto\n"; }


 //if( f.mEquipo.checked && f.mEquipo.value=='Si' ){
  // 	if(f.mTipo.value==''){ mMsg = mMsg + "El Tipo de Equipo PDA es obligatorio!\n"; }
  //}

 if(mMsg!=''){ alert(mMsg); }

 return (mMsg=='');
}

function validared() {
	 var f = document.fRedmed;
	 var mMsg = "";
	 var mVacio = false;
	 sMensaje = "";

	 if(f.mNombre.value==''){ mMsg = mMsg + "El Nombre es obligatorio!\n"; }

	 if(mMsg!=''){ alert(mMsg); }

	 return (mMsg=='');
	 

	}
function validaPilotosAutos() {
	 var f = document.fPilotosAuto;
	 var mMsg = "";
	 var mVacio = false;
	 sMensaje = "";

	 if(f.mNombre.value==''){ mMsg = mMsg + "El Nombre es obligatorio!\n"; }
	 if(f.mApellidoP.value==''){ mMsg = mMsg + "El Apellido Paterno es obligatorio!\n"; }
	 if(f.mApellidoM.value==''){ mMsg = mMsg + "El Apellido Materno es obligatorio!\n"; }
	 if(!validaDirEmail(f.mEmail.value)){ mMsg = mMsg + "El correo es obligatorio!\no bien no es correcto\n"; }
	 if(f.mRfc.value==''){ mMsg = mMsg + "El Rfc es obligatorio!\n"; }

	 if(f.mNNomina.value==''){ mMsg = mMsg + "El numero de nomina es obligatorio!\n"; }
	 if(f.mMarca.value==''){ mMsg = mMsg + "La marca es obligatorio!\n"; }
	 if(f.mSubmarca.value==''){ mMsg = mMsg + "La submarca es obligatoria!\n"; }
	 if(f.mModelo.value==''){ mMsg = mMsg + "El modelo es obligatorio!\n"; }
	 if(f.mDescripcion.value==''){ mMsg = mMsg + "La descripcion es obligatorio!\n"; }


	 
	
	 for (var iii=0; iii<f.mEmision.length;iii++)
	 {	
	 	if(f.mEmision[iii].checked && f.mEmision[iii].value=='EMISION')
	 	{
	 		if(f.mSerie.value==''){ mMsg = mMsg + "El no. de serie es obligatorio!\n"; }
		 	if(f.mMotor.value==''){ mMsg = mMsg + "El no. de motor es obligatorio!\n"; }
		 	if(f.mPlacas.value==''){ mMsg = mMsg + "Las placas son obligatorias!\n"; }
	 	}
	 	
	 
	 }
	 
	 

	 if(mMsg!=''){ alert(mMsg); }

	 return (mMsg=='');
	}
	
	
	function validaGolf() {
	var f = document.fContacGolf;
 	var mMsg = "";
 	var mVacio = false;
 	sMensaje = "";
 	if(f.mNombre.value==''){ mMsg = mMsg + "El Nombre es obligatorio!\n"; }
 	if(f.mApellidoP.value==''){ mMsg = mMsg + "El Apellido Paterno es obligatorio!\n"; }
 	if(f.mApellidoM.value==''){ mMsg = mMsg + "El Apellido Materno es obligatorio!\n"; }
 	if(f.mEjecutivo.value==''){ mMsg = mMsg + "El Ejecutivo es obligatorio!\n"; }
 	if(f.mTel.value==''){ mMsg = mMsg + "El telefono de Casa es obligatorio!\n"; }
 	if(f.mHandi.value==''){ mMsg = mMsg + "El Handicap es obligatorio!\n"; }
			 if(mMsg!=''){ alert(mMsg); }

	 return (mMsg=='');
	}
	
	
	
	function validaEncuestaAge(){
		var f = document.fEncuestaAge;
	 	var mMsg = "";
	 	var mVacio = false;
	 	sMensaje = "";
		if (f.nombre.value==""){mMsg = mMsg +  "La opción de Nombre esta vacia\n";}
		if (f.apaterno.value==""){mMsg = mMsg + "La opción de Apellido Paterno esta vacia\n";}

		if (f.cveAgente.value==""){mMsg = mMsg + "La opción de Clave del Agente esta vacia\n";}

		if (f.estado.value==""){mMsg = mMsg + "La opción Estado esta vacia\n";}
		if (f.ciudad.value==""){mMsg = mMsg + "La opción Ciudad esta vacia\n";} 

		if (f.telefono.value==""){mMsg = mMsg + "La opción Teléfono esta vacia\n";}
	
		if (f.lada.value==""){mMsg = mMsg + "La opción de Lada esta vacia\n";}

		if(!validaDirEmail(f.correo.value)){ mMsg = mMsg + "El correo es obligatorio!\no bien no es correcto\n"; }

		 if(mMsg!=''){ alert(mMsg); }

		 return (mMsg=='');
		
	}
	

	
	
	function validaEncuestaAs(){
		 var f = document.fEncuestaAs;
		 var mMsg = "";
		 var mVacio = false;
		 sMensaje = "";

		 if(f.mNombre.value==''){ mMsg = mMsg + "El Nombre es obligatorio!\n"; }
		 if(f.mApellidoP.value==''){ mMsg = mMsg + "El Apellido Paterno es obligatorio!\n"; }
		 if(f.mApellidoM.value==''){ mMsg = mMsg + "El Apellido Materno es obligatorio!\n"; }
		  
		if (f.telefono.value==""){mMsg = mMsg + "La opción Teléfono esta vacia\n";}
	
		if (f.lada.value==""){mMsg = mMsg + "La opción de Lada esta vacia\n";}
		 
		 if(f.mCalle==''){ mMsg = mMsg + "La Calle es obligatoria!\n"; }
		   if(f.mExt.value==''){ mMsg = mMsg + "El no. Exterior es obligatorio!\n"; }
		   
		    if(f.mCol.value==''){ mMsg = mMsg + "La Colonia es obligatorio!\n"; }
		    if(f.mDel.value==''){ mMsg = mMsg + "La Delegación es obligatoria!\n"; }
		    if(f.mCp.value==''){ mMsg = mMsg + "El C.P. es obligatorio!\n"; }
		  if(f.mEstado.value==''){ mMsg = mMsg + "El Estado de domicilio es obligatorio!\n"; }
		 
		   if(f.mCiudad.value==''){ mMsg = mMsg + "La Ciudad de domicilio es obligatorio!\n"; }

		  
		 if(mMsg!=''){ alert(mMsg); }

		 return (mMsg=='');
		}
	
	
	
