function valida_camposforma(form)
{

	if (form.nombre.value=='')
	{	
		alert("Se requiere su nombre para procesar esta forma");
		form.nombre.focus();
		return false;
	}	

	if (form.estado.options[0].selected)
	 {
		 alert("Lo siento pero tiene que seleccionar\n un Estado válido");
		 form.estado.focus();
		 return false;
	 }

  if (!checkField(form.ladatelefono,isNumber,true,"Proporcione una clave lada válida"))
	{	
		form.ladatelefono.focus();
		return false;
	}		

  if (!checkField(form.telefono,isNumber,true,"Proporcione un número de teléfono válido"))
	{	
		form.telefono.focus();
		return false;
	}		
//  if (!checkField(form.ladafax,isNumber,true,"Proporcione una clave lada válida"))
//	{	
//		form.ladafax.focus();
//		return false;
//	}		

//  if (!checkField(form.fax,isNumber,true,"Proporcione un número de fax válido"))
//	{	
//		form.fax.focus();
//		return false;
//	}		

if (!checkField(form.correo,isEmail,false,"Su E-mail no es válido, por favor rectifiquelo"))
	{	
		form.correo.focus();
		return false;
	}					
	
	
	
	
	if (form.comentarios.value=='')
	{	
		alert("Se requiere que proporcione la información de su interés o su Comentario");
		form.comentarios.focus();
		return false;
	}	
   

//	if (!_CF_checkdate(form.fechacita.value))
//	{
//		alert("La fecha de la cita es invalida");
//		form.fechacita.focus();
 // 		return false;    
//	}
	
// if (!checkField(form.lada,isNumber,false,"Este campos sólo acepta números"))
//	{	
//		form.lada.focus();
//		return false;
//	}	
// if (!checkField(form.telefono,isNumber,false,"Este campos sólo acepta números"))
//	{	
//		form.telefono.focus();
//		return false;
//	}	
	
//if (!checkField(form.extension,isNumber,true,"Este campos sólo acepta números"))
//	{	
//		form.extension.focus();
//		return false;
//	}	
	
//if (!checkField(form.ladafax,isNumber,true,"Este campos sólo acepta números"))
//	{	
//		form.ladafax.focus();
//		return false;
//	}			
//if (!checkField(form.fax,isNumber,true,"Este campos sólo acepta números"))
//	{	
//		form.fax.focus();
//		return false;
//	}				
	
}

function checa(xurl,forma,forma2)
// Cuando se cambia ESTADO
{
	// alert(isval);
	
	//alert(forma.nombre.value);
//	xurl.options[xurl.selectedIndex].value +
	var xxurl = "contact.cfm?idnacionalidad=" + xurl.options[xurl.selectedIndex].value +
    "&nombre=" + quita_espacios(forma.nombre.value)  +
    "&calle=" + quita_espacios(forma.calle.value)  +
    "&cvefranquicia=" + quita_espacios(forma.cvefranquicia.value)  +
    "&ext=" + quita_espacios(forma.ext.value)  +
    "&int=" + quita_espacios(forma.int.value)  +
    "&colonia=" + quita_espacios(forma.colonia.value)  +
    "&ciudad=" + quita_espacios(forma.ciudad.value) +
    "&mpio=" + quita_espacios(forma.mpio.value) +
    "&ladatelefono=" + quita_espacios(forma.ladatelefono.value) +
	"&telefono=" + quita_espacios(forma.telefono.value) + 
	"&ladafax=" + quita_espacios(forma.ladafax.value) +
	"&fax=" + quita_espacios(forma.fax.value) + 
	"&correo=" + quita_espacios(forma.correo.value) + 
	"&comentarios=" + quita_espacios(forma.comentarios.value);


	//alert(xxurl);
	document.location.href=xxurl;
	//document.location.href= "instituciones.cfm?estado=11&nombre=esta+prueba"
	 
}


function _CF_onError(form_object, input_object, object_value, error_message)
    {
        alert(error_message);
        return false;   
    }



function _CF_hasValue(obj, obj_type)
    {
    if (obj_type == "TEXT" || obj_type == "PASSWORD")
        {
        if (obj.value.length == 0) 
                return false;
        else 
                return true;
        }
    else if (obj_type == "SELECT")
        {
        for (i=0; i < obj.length; i++)
                {
                if (obj.options[i].selected)
                        return true;
                }

        return false;   
        }
    else if (obj_type == "SINGLE_VALUE_RADIO" || obj_type == "SINGLE_VALUE_CHECKBOX")
        {

                if (obj.checked)
                        return true;
                else
                return false;   
        }
    else if (obj_type == "RADIO" || obj_type == "CHECKBOX")
        {

        for (i=0; i < obj.length; i++)
                {
                if (obj[i].checked)
                        return true;
                }

        return false;   
        }
        }



function _CF_checkdate(object_value)
    {
    //Returns true if value is a date format or is NULL
    //otherwise returns false   

    if (object_value.length == 0)
        return true;

    //Returns true if value is a date in the mm/dd/yyyy format
        isplit = object_value.indexOf('/');

        if (isplit == -1 || isplit == object_value.length)
                return false;

    sMonth = object_value.substring(0, isplit);
        isplit = object_value.indexOf('/', isplit + 1);

        if (isplit == -1 || (isplit + 1 ) == object_value.length)
                return false;

    sDay = object_value.substring((sMonth.length + 1), isplit);

        sYear = object_value.substring(isplit + 1);
			// intercambia mes con dia
			var temp=sDay;
			sDay=sMonth;
			sMonth=temp;

        if (!_CF_checkinteger(sMonth)) //check month
                return false;
        else
        if (!_CF_checkrange(sMonth, 1, 12)) //check month
                return false;
        else
        if (!_CF_checkinteger(sYear)) //check year
                return false;
        else
        if (!_CF_checkrange(sYear, 0, 9999)) //check year
                return false;
        else
        if (!_CF_checkinteger(sDay)) //check day
                return false;
        else
        if (!_CF_checkday(sYear, sMonth, sDay)) // check day
                return false;
        else
                return true;
    }



function _CF_checkday(checkYear, checkMonth, checkDay)
    {

        maxDay = 31;

        if (checkMonth == 4 || checkMonth == 6 ||
                        checkMonth == 9 || checkMonth == 11)
                maxDay = 30;
        else
        if (checkMonth == 2)
        {
                if (checkYear % 4 > 0)
                        maxDay =28;
                else
                if (checkYear % 100 == 0 && checkYear % 400 > 0)
                        maxDay = 28;
                else
                        maxDay = 29;
        }

        return _CF_checkrange(checkDay, 1, maxDay); //check day
    }



function _CF_checkinteger(object_value)
    {
    //Returns true if value is a number or is NULL
    //otherwise returns false   

    if (object_value.length == 0)
        return true;

    //Returns true if value is an integer defined as
    //   having an optional leading + or -.
    //   otherwise containing only the characters 0-9.
        var decimal_format = ".";
        var check_char;

    //The first character can be + -  blank or a digit.
        check_char = object_value.indexOf(decimal_format)
    //Was it a decimal?
    if (check_char < 1)
        return _CF_checknumber(object_value);
    else
        return false;
    }



function _CF_numberrange(object_value, min_value, max_value)
    {
    // check minimum
    if (min_value != null)
        {
        if (object_value < min_value)
                return false;
        }

    // check maximum
    if (max_value != null)
        {
        if (object_value > max_value)
                return false;
        }
        
    //All tests passed, so...
    return true;
    }



function _CF_checknumber(object_value)
    {
    //Returns true if value is a number or is NULL
    //otherwise returns false   

    if (object_value.length == 0)
        return true;

    //Returns true if value is a number defined as
    //   having an optional leading + or -.
    //   having at most 1 decimal point.
    //   otherwise containing only the characters 0-9.
        var start_format = " .+-0123456789";
        var number_format = " .0123456789";
        var check_char;
        var decimal = false;
        var trailing_blank = false;
        var digits = false;

    //The first character can be + - .  blank or a digit.
        check_char = start_format.indexOf(object_value.charAt(0))
    //Was it a decimal?
        if (check_char == 1)
            decimal = true;
        else if (check_char < 1)
                return false;
        
        //Remaining characters can be only . or a digit, but only one decimal.
        for (var i = 1; i < object_value.length; i++)
        {
                check_char = number_format.indexOf(object_value.charAt(i))
                if (check_char < 0)
                        return false;
                else if (check_char == 1)
                {
                        if (decimal)            // Second decimal.
                                return false;
                        else
                                decimal = true;
                }
                else if (check_char == 0)
                {
                        if (decimal || digits)  
                                trailing_blank = true;
        // ignore leading blanks

                }
                else if (trailing_blank)
                        return false;
                else
                        digits = true;
        }       
    //All tests passed, so...
    return true
    }



function _CF_checkrange(object_value, min_value, max_value)
    {
    //if value is in range then return true else return false

    if (object_value.length == 0)
        return true;


    if (!_CF_checknumber(object_value))
        {
        return false;
        }
    else
        {
        return (_CF_numberrange((eval(object_value)), min_value, max_value));
        }
        
    //All tests passed, so...
    return true;
    }


function  _CF_checkCFForm_1(_CF_this)

    {

    if  (!_CF_hasValue(_CF_this.atendieron, "RADIO" )) 

        {

        if  (!_CF_onError(_CF_this, _CF_this.atendieron, _CF_this.atendieron.value, "Se requiere calificarla atencion"))

            {

            return false; 

            }

        }


    if  (!_CF_hasValue(_CF_this.Recarga, "TEXT" )) 

        {

        if  (!_CF_onError(_CF_this, _CF_this.Recarga, _CF_this.Recarga.value, "Falta el valor de la recarga."))

            {

            return false; 

            }

        }


    if  (!_CF_checkdate(_CF_this.FechaLim.value))

        {

        if  (!_CF_onError(_CF_this, _CF_this.FechaLim, _CF_this.FechaLim.value, "Por favor escriba una fecha v&aacute;lida."))

            {

            return false; 

            }

        }


    return true;

    }

	
	
// ---------------------------------------------------------------------- //
//         
// ---------------------------------------------------------------------- //
// Rutinas para verificacion de formularios, basado en FormChek.js
// 
// ---------------------------------------------------------------------- //
//                             RESUMEN                                    //
// ---------------------------------------------------------------------- //
// 
// El objetivo de las siguientes funciones en JavaScript es
// validar los ingresos del usuario en un formulario antes
// de que estos datos vayan al servidor.
//
// Varias de ellas toman un parametro opcional E.O.K (eok) (emptyOK
// - true si se acepta que el valor este vacio, false si no
// se acepta). El valor por omision es el que indique la
// variable global defaultEmptyOK definida mas abajo.
//
// ---------------------------------------------------------------------- //
//                      SINTAXIS DE LAS FUNCIONES                         //
// ---------------------------------------------------------------------- //
//
// FUNCION PARA CHEQUEAR UN CAMPO DE INGRESO:
//
// checkField (theField, theFunction, [, s] [,eok])
//        verifica que el campo de ingreso theField cumpla con la
//        condicion indicada en la funcion theFunction (que puede ser
//        una de las descritas en "FUNCIONES DE VALIDACION" o cualquier
//        otra provista por el usuario). En caso contrario despliega el
//        string "s" (opcional, hay mensajes por default para las
//        funciones de validacion provistas aqui).
//
// FUNCIONES DE VALIDACION:
//
// isInteger (s [,eok])                s representa un entero
// isNumber (s [,eok])                 s es entero o tiene punto decimal
// isAlphabetic (s [,eok])             s tiene solo letras
// isAlphanumeric (s [,eok])           s tiene solo letras y/o numeros
// isPhoneNumber (s [,eok])            s tiene solo numeros, (,),-
// isEmail (s [,eok])                  s es una direccion de e-mail
//
// FUNCIONES INTERNAS:
//
// isWhitespace (s)                    s es vacio o solo son espacios
// isLetter (c)                        c es una letra
// isDigit (c)                         c es un digito
// isLetterOrDigit (c)                 c es letra o digito
//
// FUNCIONES PARA REFORMATEAR DATOS:
//
// stripCharsInBag (s, bag)            quita de s los caracteres en bag
// stripCharsNotInBag (s, bag)         quita de s los caracteres NO en bag
// stripWhitespace (s)                 quita el espacio dentro de s
// stripInitialWhitespace (s)          quita el espacio al principio de s
//
// FUNCIONES PARA PREGUNTARLE AL USUARIO:
//
// statBar (s)                         pone s en la barra de estado
// warnEmpty (theField, s)             indica que theField esta vacio
// warnInvalid (theField, s)           indica que theField es invalido
//
// ---------------------------------------------------------------------- //
//                                VARIABLES                               //
// ---------------------------------------------------------------------- //

// Esta variable indica si está bien dejar las casillas
// en blanco como regla general
var defaultEmptyOK = false

// listas de caracteres
var digits = "0123456789";
var lowercaseLetters = "abcdefghijklmnopqrstuvwxyzáéíóúñü"
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZÁÉÍÓÚÑ"
var whitespace = " \t\n\r";

// caracteres admitidos en nos de telefono
var phoneChars = "()-+alextALEXT ";

// ---------------------------------------------------------------------- //
//                     TEXTOS PARA LOS MENSAJES                           //
// ---------------------------------------------------------------------- //

// m abrevia "missing" (faltante)
var mMessage = "Error: no puede dejar este espacio sin datos"

// p abrevia "prompt"
var pPrompt = "Error: ";
var pAlphanumeric = "ingrese un texto que contenga solo letras y/o numeros";
var pAlphabetic   = "ingrese un texto que contenga solo letras";
var pInteger = "ingrese un numero entero";
var pNumber = "ingrese un numero";
var pPhoneNumber = "ingrese un número de teléfono";
var pEmail = "ingrese una dirección de correo electrónico válida";
var pName = "ingrese un texto que contenga solo letras, numeros o espacios";

// ---------------------------------------------------------------------- //
//                FUNCIONES PARA MANEJO DE ARREGLOS                       //
// ---------------------------------------------------------------------- //

// JavaScript 1.0 (Netscape 2.0) no tenia un constructor para arreglos,
// asi que ellos tenian que ser hechos a mano. Desde JavaScript 1.1 
// (Netscape 3.0) en adelante, las funciones de manejo de arreglos no
// son necesarias.





function makeArray(n) {
//*** BUG: If I put this line in, I get two error messages:
//(1) Window.length can't be set by assignment
//(2) daysInMonth has no property indexed by 4
//If I leave it out, the code works fine.
//   this.length = n;
   for (var i = 1; i <= n; i++) {
      this[i] = 0
   } 
   return this
}

// ---------------------------------------------------------------------- //
//                  CODIGO PARA FUNCIONES BASICAS                         //
// ---------------------------------------------------------------------- //


// s es vacio
function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

// s es vacio o solo caracteres de espacio
function isWhitespace (s)
{   var i;
    if (isEmpty(s)) return true;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        // si el caracter en que estoy no aparece en whitespace,
        // entonces retornar falso
        if (whitespace.indexOf(c) == -1) return false;
    }
    return true;
}

// Quita todos los caracteres que que estan en "bag" del string "s" s.
function stripCharsInBag (s, bag)
{   var i;
    var returnString = "";

    // Buscar por el string, si el caracter no esta en "bag", 
    // agregarlo a returnString
    
    for (i = 0; i < s.length; i++)
    {   var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
		
    }

    return returnString;
}

function los_quita (s, bag)
{   var i;
    var returnString = "";

    // Buscar por el string, si el caracter no esta en "bag", 
    // agregarlo a returnString
    
    for (i = 0; i < s.length; i++)
    {   var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
		else
			returnString +="+";
		
    }

    return returnString;
}
// Lo contrario, quitar todos los caracteres que no estan en "bag" de "s"
function stripCharsNotInBag (s, bag)
{   var i;
    var returnString = "";
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) != -1) returnString += c;
    }

    return returnString;
}


// Quitar todos los espacios en blanco de un string
function stripWhitespace (s)
{   return stripCharsInBag (s, whitespace)
}

// Quitar todos los espacios en blanco de un string
function quita_espacios (s)
{   return los_quita (s, whitespace)
}

// La rutina siguiente es para cubrir un bug en Netscape
// 2.0.2 - seria mejor usar indexOf, pero si se hace
// asi stripInitialWhitespace() no funcionaria

function charInString (c, s)
{   for (i = 0; i < s.length; i++)
    {   if (s.charAt(i) == c) return true;
    }
    return false
}

// Quita todos los espacios que antecedan al string
function stripInitialWhitespace (s)
{   var i = 0;
    while ((i < s.length) && charInString (s.charAt(i), whitespace))
       i++;
    return s.substring (i, s.length);
}

// c es una letra del alfabeto espanol
function isLetter (c)
{
    return( ( uppercaseLetters.indexOf( c ) != -1 ) ||
            ( lowercaseLetters.indexOf( c ) != -1 ) )
}

// c es un digito
function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

// c es letra o digito
function isLetterOrDigit (c)
{   return (isLetter(c) || isDigit(c))
}

// ---------------------------------------------------------------------- //
//                          NUMEROS                                       //
// ---------------------------------------------------------------------- //

// s es un numero entero (con o sin signo)
function isInteger (s)
{   var i;
    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);
    
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if( i != 0 ) {
            if (!isDigit(c)) return false;
        } else { 
            if (!isDigit(c) && (c != "-") || (c == "+")) return false;
        }
    }
    return true;
}

// s es un numero (entero o flotante, con o sin signo)
function isNumber (s)
{   var i;
    var dotAppeared;
    dotAppeared = false;
    if (isEmpty(s)) 
       if (isNumber.arguments.length == 1) return defaultEmptyOK;
       else return (isNumber.arguments[1] == true);
    
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if( i != 0 ) {
            if ( c == "." ) {
                if( !dotAppeared )
                    dotAppeared = true;
                else
                    return false;
            } else     
                if (!isDigit(c)) return false;
        } else { 
            if ( c == "." ) {
                if( !dotAppeared )
                    dotAppeared = true;
                else
                    return false;
            } else     
                if (!isDigit(c) && (c != "-") || (c == "+")) return false;
        }
    }
    return true;
}

// ---------------------------------------------------------------------- //
//                        STRINGS SIMPLES                                 //
// ---------------------------------------------------------------------- //

// s tiene solo letras
function isAlphabetic (s)
{   var i;

    if (isEmpty(s)) 
       if (isAlphabetic.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphabetic.arguments[1] == true);
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is letter.
        var c = s.charAt(i);

        if (!isLetter(c))
        return false;
    }
    return true;
}


// s tiene solo letras y numeros
function isAlphanumeric (s)
{   var i;

    if (isEmpty(s)) 
       if (isAlphanumeric.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphanumeric.arguments[1] == true);

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (! (isLetter(c) || isDigit(c) ) )
        return false;
    }

    return true;
}

// s tiene solo letras, numeros o espacios en blanco
function isName (s)
{
    if (isEmpty(s)) 
       if (isName.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphanumeric.arguments[1] == true);
    
    return( isAlphanumeric( stripCharsInBag( s, whitespace ) ) );
}

// ---------------------------------------------------------------------- //
//                           FONO o EMAIL                                 //
// ---------------------------------------------------------------------- //

// s es numero de telefono valido
function isPhoneNumber (s)
{   var modString;
    if (isEmpty(s)) 
       if (isPhoneNumber.arguments.length == 1) return defaultEmptyOK;
       else return (isPhoneNumber.arguments[1] == true);
    modString = stripCharsInBag( s, phoneChars );
    return (isInteger(modString))
}

// s es una direccion de correo valida
function isEmail (s)
{
    if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return true;
       else return (isEmail.arguments[1] == true);
    if (isWhitespace(s)) return false;
    var i = 1;
    var sLength = s.length;
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

// ---------------------------------------------------------------------- //
//                  FUNCIONES PARA RECLAMARLE AL USUARIO                  //
// ---------------------------------------------------------------------- //

// pone el string s en la barra de estado
function statBar (s)
{   window.status = s
}

// notificar que el campo theField esta vacio
function warnEmpty (theField)
{   theField.focus()
    alert(mMessage)
    statBar(mMessage)
    return false
}

// notificar que el campo theField es invalido
function warnInvalid (theField, s)
{   theField.focus()
    theField.select()
    alert(s)
    statBar(pPrompt + s)
    return false
}

function _CF_checknumber(object_value)
    {
    //Returns true if value is a number or is NULL
    //otherwise returns false   

    if (object_value.length == 0)
        return true;

    //Returns true if value is a number defined as
    //   having an optional leading + or -.
    //   having at most 1 decimal point.
    //   otherwise containing only the characters 0-9.
        var start_format = " .+-0123456789";
        var number_format = " .0123456789";
        var check_char;
        var decimal = false;
        var trailing_blank = false;
        var digits = false;

    //The first character can be + - .  blank or a digit.
        check_char = start_format.indexOf(object_value.charAt(0))
    //Was it a decimal?
        if (check_char == 1)
            decimal = true;
        else if (check_char < 1)
                return false;
        
        //Remaining characters can be only . or a digit, but only one decimal.
        for (var i = 1; i < object_value.length; i++)
        {
                check_char = number_format.indexOf(object_value.charAt(i))
                if (check_char < 0)
                        return false;
                else if (check_char == 1)
                {
                        if (decimal)            // Second decimal.
                                return false;
                        else
                                decimal = true;
                }
                else if (check_char == 0)
                {
                        if (decimal || digits)  
                                trailing_blank = true;
        // ignore leading blanks

                }
                else if (trailing_blank)
                        return false;
                else
                        digits = true;
        }       
    //All tests passed, so...
    return true
    }

	function _CF_checkrange(object_value, min_value, max_value)
    {
    //if value is in range then return true else return false

    if (object_value.length == 0)
        return true;


    if (!_CF_checknumber(object_value))
        {
        return false;
        }
    else
        {
        return (_CF_numberrange((eval(object_value)), min_value, max_value));
        }
        
    //All tests passed, so...
    return true;
    }

function _CF_numberrange(object_value, min_value, max_value)
    {
    // check minimum
    if (min_value != null)
        {
        if (object_value < min_value)
                return false;
        }

    // check maximum
    if (max_value != null)
        {
        if (object_value > max_value)
                return false;
        }
        
    //All tests passed, so...
    return true;
    }
	
// el corazon de todo: checkField
function checkField (theField, theFunction, emptyOK, s)
{   
    var msg;
    if (checkField.arguments.length < 3) emptyOK = defaultEmptyOK;
    if (checkField.arguments.length == 4) {
        msg = s;
    } else {
        if( theFunction == isAlphabetic ) msg = pAlphabetic;
        if( theFunction == isAlphanumeric ) msg = pAlphanumeric;
        if( theFunction == isInteger ) msg = pInteger;
        if( theFunction == isNumber ) msg = pNumber;
        if( theFunction == isEmail ) msg = pEmail;
        if( theFunction == isPhoneNumber ) msg = pPhoneNumber;
        if( theFunction == isName ) msg = pName;
    }
    
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;

    if ((emptyOK == false) && (isEmpty(theField.value))) 
        return warnEmpty(theField);

    if (theFunction(theField.value) == true) 
        return true;
    else
        return warnInvalid(theField,msg);

}


//-->
