/************************************************************************/
function direcciona(pagina){
	window.top.document.location.href=pagina;
}

function largo_textarea(tam,objeto){
   var txt = objeto.value.length;
   if(txt >tam){
       objeto.value = objeto.value.substr(0,tam);
       alert('El largo maximo para el campo es de '+tam+ ' caracteres');
   }
}

function cierra_load(){
    try{document.getElementById('espera').style.display = 'none';} catch(e){}
}

function controlador(pagina,capa,valores){
    $.ajax({
            url: pagina,
            data: valores,
            async:true,
            beforeSend: function(objeto){
                 try{ document.getElementById('espera').style.display = 'block';} catch(e){}
            },
            complete: function(objeto, exito){
                setTimeout('cierra_load();',700);
            },
            contentType: "application/x-www-form-urlencoded",
            dataType: "html",
            error: function(objeto, quepaso, otroobj){
                alert("Estas viendo esto por que fallé");
                alert("Pasó lo siguiente: "+quepaso);
            },
            global: true,
            ifModified: false,
            processData:true,
            success: function(datos){
                 document.getElementById(capa).innerHTML = datos;
            },
            timeout: 10000,
            type: "POST"
    });

}



/*Funciones validacion*/

      msg_error = '';
      obs_error = new Array();
      cnt_error = 1;
      
        //expresion_regular(id_objeto,tipo,obligatorio);
        // Ejemplo:
            //            expresion_regular('forename','cadena',true);

     function expresion_regular(id_objeto,tipo,obligatorio){
        
        var error = false;
        
        // Arreglo con todas las expresiones regulares 
        expresiones = new Array();
        expresiones['cadena']       = /.*/;
        expresiones['numero']       = /^[0-9]*$/;
        expresiones['correo']       = /^[\w-\.\']{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,}$/;
        expresiones['alfanumerico'] = /.*/;
        expresiones['rfc'] = /^([A-Z]{3,4}[0-9]{6}[0-9|A-Z]{0,3})*$/;
        
        // Conocer el objeto
        var objeto = document.getElementById(id_objeto);
        var valor = objeto.value;
        // Validar si es un campo obligatorio
        if ( objeto.value != '' ){
            
            // Valida con expresiones regulares
            if( !expresiones[tipo].test(valor) ){
                error = true;
                msg_error += cnt_error+'.- Datos invalidos en el campo '+objeto.name+'\n';
            }
        } else  { 
                    if(obligatorio){
                        error = true;
                        msg_error += cnt_error+'.- El campo '+objeto.name+' es obligatorio\n';
                    }
               }
        
        // Verificar si hubo error
        if(error){
            // Colocar el error al campo
            obs_error.push(objeto);
            cnt_error++;            
            objeto.style.backgroundColor= '#FF6A6A';
            
        } else {
                    // Quitarle el error al campo
                    objeto.style.backgroundColor= 'transparent';
               }
               
        return error;
        
    } 
    
    
    
    function envia_contacto(){
        msg_error = '';
        obs_error = new Array();
        cnt_error = 1;
      
        var aObjetos = new Array();
            // Declarar arreglo con campos a validar
            aObjetos[0] = new Array('nombre','alfanumerico',true);
            aObjetos[1] = new Array('correo','correo',true);
            aObjetos[2] = new Array('empresa','alfanumerico',false);
            aObjetos[2] = new Array('telefono','alfanumerico',false);
			aObjetos[3] = new Array('comentarios','alfanumerico',true);



        for (var i=0; i<aObjetos.length; i++){
            datos = aObjetos[i].slice();            
            expresion_regular(datos[0],datos[1],datos[2]);
        }

        if(cnt_error > 1){
            // Informa de los errores
            alert(msg_error);
            // colocar foco en el primer elemento
            obs_error[0].focus();
            
            return false;
            
        } 
        
        return true;
    }
    

    
    
    function valida_registro(){
        msg_error = '';
        obs_error = new Array();
        cnt_error = 1;
      
        var aObjetos = new Array();
            // Declarar arreglo con campos a validar
            aObjetos[0] = new Array('area','numero',true);
            aObjetos[1] = new Array('puesto','numero',true);
            aObjetos[2] = new Array('otro_area','numero',false);
			aObjetos[3] = new Array('otro_nivel','numero',false);
			aObjetos[4] = new Array('nombre','alfanumerico',true);
            aObjetos[5] = new Array('paterno','alfanumerico',true);
            aObjetos[6] = new Array('materno','alfanumerico',true);
            aObjetos[7] = new Array('cual','alfanumerico',false);
			aObjetos[8] = new Array('nacimiento','alfanumerico',true);
			aObjetos[9] = new Array('calle','alfanumerico',true);
            aObjetos[10] = new Array('numero_calle','alfanumerico',true);
            aObjetos[11] = new Array('colonia','alfanumerico',true);
            aObjetos[12] = new Array('municipio','alfanumerico',true);
			aObjetos[13] = new Array('postal','numero',true);
            
			aObjetos[14] = new Array('estado','alfanumerico',true);
			aObjetos[15] = new Array('pais','alfanumerico',true);
			aObjetos[16] = new Array('ciudad','alfanumerico',true);
			aObjetos[17] = new Array('mail','correo',true);
			aObjetos[18] = new Array('casa','alfanumerico',true);
			aObjetos[19] = new Array('oficina','alfanumerico',true);
			aObjetos[20] = new Array('extencion','numero',true);
			aObjetos[21] = new Array('rfc','rfc',true);
			aObjetos[22] = new Array('cv','alfanumerico',true);



        for (var i=0; i<aObjetos.length; i++){
            datos = aObjetos[i].slice();            
            expresion_regular(datos[0],datos[1],datos[2]);
        }
        
        if(cnt_error > 1){
            // Informa de los errores
            alert(msg_error);
            // colocar foco en el primer elemento
            obs_error[0].focus();
            
            return false;
            
        } 
        
        return true;
    }

    
 
 
/*Inicializa*/ 

// $(document).ready(function() {  try{initMenus();}catch(e){} });

/*Fin Inicializa*/ 



/*particulares paginaminicio*/
function visualiza_otro(sel,elem){
var ind = sel.selectedIndex;
var lar = sel.length;
ind ++;

if( ind == lar ){
	$('#'+elem).val('');
	$('#'+elem).css('display','block');
} else{
		$('#'+elem).val('');
		$('#'+elem).css('display','none');
	  }
}

function envia_vacante(obj,ide){
	direcciona('vacante_detalle.php?vct_id='+ide+'&');
}

function valida_formularios(indice){
	switch(indice){
		case 0:
			var confirma = confirm('Desea dejar el formulario: '+indice);
		break;
		
		case 1:
			var confirma = confirm('Desea dejar el formulario: '+indice);
		break;
		
		case 2:
			var confirma = confirm('Desea dejar el formulario: '+indice);
		break;
		
		default:
			var confirma = false;
		break;
	}
	
	return confirma;
}
/*particulares pagina fin*/


/**/
function enable_smooth_scroll() {
    function filterPath(string) {
        return string
                .replace(/^\//,'')
                .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
                .replace(/\/$/,'');
    }

    var locationPath = filterPath(location.pathname);
    
    var scrollElement = 'html, body';
    $('html, body').each(function () {
        var initScrollTop = $(this).attr('scrollTop');
        $(this).attr('scrollTop', initScrollTop + 1);
        if ($(this).attr('scrollTop') == initScrollTop + 1) {
            scrollElement = this.nodeName.toLowerCase();
            $(this).attr('scrollTop', initScrollTop);
            return false;
        }    
    });
    
    $('a[href*=#]').each(function() {
        var thisPath = filterPath(this.pathname) || locationPath;
        if  (   locationPath == thisPath
                && (location.hostname == this.hostname || !this.hostname)
                && this.hash.replace(/#/, '')
            ) {
                if ($(this.hash).length) {
                    $(this).click(function(event) {
                        var targetOffset = $(this.hash).offset().top;
                        var target = this.hash;
                        event.preventDefault();
                        $(scrollElement).animate(
                            {scrollTop: targetOffset},
                            500,
                            function() {
                                location.hash = target;
                        });
                    });
                }
        }
    });
}


/**/