/*

$(document).ready(function(){

	$(document).ready(function(){

   	$("body").attr( "style", "display: none" );

   	$("body").fadeOut( "fast", function(){

   		$("body").fadeIn( "slow", function(){

				checkErrores();

			});

		});

	});

});

*/



// Modif by Jeans

$(document).ready(function(){



    checkErrores();

    /*

	$("body").attr( "style", "display: none" );

   $("body").fadeOut( 0 ).fadeIn( 0, function(){  checkErrores(); });

   */

});



function quickAjax( url, func, send, extra ) {var method = send == null ? 'GET' : 'POST';

var text = null;

var req = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject( 'Microsoft.XMLHTTP' );;

var ok = false;

try{req.onreadystatechange = function(){if( req.readyState == 4 && ! ok ) {if( func ) func( req.responseText, extra );

text = req.responseText;

ok = true;}}

req.onload = function(){if( ! ok ) {if( func ) func( req.responseText, extra );

text = req.responseText;

ok = true;}}

} catch( e ){}

try {req.open( method, url, func ? true : false );} catch( e ) {return 'error en req.open';}

if( method == 'POST' ) {req.setRequestHeader( 'Content-type', 'application/x-www-form-urlencoded' );

req.setRequestHeader( 'Connection', 'close' );}

req.send( send );

if( ! func ) return text;}



String.prototype.trims = function() {

        return this.replace(/^\s+|\s+$/g,"");

}





function trim(input, solo_texto){

	if ( solo_texto ){

		s = input;

	}else{

		input = document.getElementById( input );

		s = input.value;

	}



	s = s.replace(/^\s+/, "");

	s = s.replace(/\s+$/, "");



	if ( solo_texto ){
		return s;
	}else{
		input.value = s;
	}
}



function toggle(){
    for( var i = 0; i < toggle.arguments.length; i++ ) {
        var e = document.getElementById( toggle.arguments[i] );
        if( e ) e.style.display = e.style.display == 'none' ? '' : 'none';
    }
    return void(0);
}



function validaRut(T){
	T = T.replace('.', '');
	T = T.split('-');	
	if ( !T[1] ) return 0;
	var M=0,S=1;for(;T[0];T[0]=Math.floor(T[0]/10))
	S=(S+T[0]%10*(9-M++%6))%11; var dv = S?S-1:'k'; return dv == T[1].toLowerCase();
}



function validaEmail(valor) {

	return (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)) ? 1 : 0;

}



function validaEntero ( valor ) {

    return (/^[0-9]+$/.test(valor));

}

/* Valida solo letras y espacios */
function validarNombre( str ){
/*
	if(/[^a-zA-Z]/.test(nombre)){
		return true;
	}else{
		return false;
	}
*/

	// Return immediately if an invalid value was passed in
	if (str+"" == "undefined" || str+"" == "null" || str+"" == "")	
		return false;
	var isValid = true;
	
	// convert to a string for performing string comparisons.
   	str += "";	
	// Loop through length of string and test for any alpha numeric 
	// characters
   	for (i = 0; i < str.length; i++)
   	{
		// Alpha must be between "A"-"Z", or "a"-"z"
      	if ( !( ((str.charAt(i) >= "a") && (str.charAt(i) <= "z")) ||
      			((str.charAt(i) >= "A") && (str.charAt(i) <= "Z"))))
			{
				isValid = false;
				break;
			}	
   	} // END for   
   
   	return isValid;


}

/* Valida solo letras , numeros y espacios */
function validarAlfaNum(cadAlfNum){

	if(/[^a-zA-Z0-9]/.test(cadAlfNum)){
		return true;
	}else{
		return false;
	}

}


function IsAlphaNum( str ) {
	// Return immediately if an invalid value was passed in
	if (str+"" == "undefined" || str+"" == "null" || str+"" == "")	
		return false;
	var isValid = true;
	
	// convert to a string for performing string comparisons.
   	str += "";
	str.replace(/^\s+|\s+$/g, "");
	// Loop through length of string and test for any alpha numeric 
	// characters
   	for (i = 0; i < str.length; i++)
   	{
			// Alphanumeric must be between "0"-"9", "A"-"Z", or "a"-"z"
      	if (!(((str.charAt(i) >= "0") && (str.charAt(i) <= "9")) || 
      			((str.charAt(i) >= "a") && (str.charAt(i) <= "z")) ||
      			((str.charAt(i) >= "A") && (str.charAt(i) <= "Z"))))
			{
				isValid = false;
				break;
			}	
   	} // END for   
   
   	return isValid;
}  // end IsAlphaNum



function checkErrores(){
	if ( $("#lista_errores").html() ){
		var lista = $("#lista_errores").html().split( ',' );
		for( var i=0; i < lista.length; i++ ){
			document.getElementById( lista[i] ).className += " error";
			document.getElementById( "_" + lista[i] ).className += " error";
		}
	}
}



function cancelar(){
	$("body").find( "input[type=text], textarea" ).attr( "value", "" );
	$("body select").attr( "value", 0 );
}

function soloNumeros(evt){
	
	//asignamos el valor de la tecla a keynum
	if(window.event){// IE
		keynum = evt.keyCode;
	}else{
		keynum = evt.which;
	}

	//comprobamos si se encuentra en el rango
	if(keynum>47 && keynum<58){
		return true;
	}else{
		return false;
	}

}

