/*
$(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.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));
}

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 );
}