/*$(document).ready(function(){
	$("body").attr( "style", "display: none" );
   $("body").fadeOut( "fast" ).fadeIn( "slow", function(){  checkErrores(); });
});
*/

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

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


function resetCampos(){
	$("input[type='text'], input[type='radio'], textarea").attr( "value", "" );
	$("input[type='radio']").removeAttr( "checked" );
}

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;}

function number_format(number, decimals, dec_point, thousands_sep) {
	var n = !isFinite(+number) ? 0 : +number,
	prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
	sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,        dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
	s = '',
	toFixedFix = function (n, prec) {
		var k = Math.pow(10, prec);
		return '' + Math.round(n * k) / k;
	};

	//Fix for IE parseFloat(0.55).toFixed(0) = 0;
	s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
	if (s[0].length > 3) {
		s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
	}
	if ((s[1] || '').length < prec) {
		s[1] = s[1] || '';
		s[1] += new Array(prec - s[1].length + 1).join('0');
	}

	return s.join(dec);
}

function str_replace (search, replace, subject, count) {
	var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
	f = [].concat(search),
	r = [].concat(replace),
	s = subject,
	ra = r instanceof Array, sa = s instanceof Array;    s = [].concat(s);
	if (count) {
		this.window[count] = 0;
	}

	for (i=0, sl=s.length; i < sl; i++) {
		if (s[i] === '') continue;

		for (j=0, fl=f.length; j < fl; j++) {
			temp = s[i]+'';
			repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
			s[i] = (temp).split(f[j]).join(repl);
			if (count && s[i] !== temp) {
				this.window[count] += (temp.length-s[i].length)/f[j].length;
			}
		}
	}

	return sa ? s : s[0];
}

function settype (vr, type) {
	var is_array = function (arr) {
        return typeof arr === 'object' && typeof arr.length === 'number' &&
                    !(arr.propertyIsEnumerable('length')) &&
                    typeof arr.splice === 'function';
    };    var v, mtch, i, obj;
    v = this[vr] ? this[vr] : vr;

    try {
        switch (type) {            case 'boolean':
                if (is_array(v) && v.length === 0) {this[vr]=false;}
                else if (v === '0') {this[vr]=false;}
                else if (typeof v === 'object' && !is_array(v)) {
                    var lgth = false;                    for (i in v) {
                        lgth = true;
                    }
                    this[vr]=lgth;
                }                else {this[vr] = !!v;}
                break;
            case 'integer':
                if (typeof v === 'number') {this[vr]=parseInt(v, 10);}
                else if (typeof v === 'string') {                    mtch = v.match(/^([+\-]?)(\d+)/);
                    if (!mtch) {this[vr]=0;}
                    else {this[vr]=parseInt(v, 10);}
                }
                else if (v === true) {this[vr]=1;}                else if (v === false || v === null) {this[vr]=0;}
                else if (is_array(v) && v.length === 0) {this[vr]=0;}
                else if (typeof v === 'object') {this[vr]=1;}

                break;            case 'float':
                if (typeof v === 'string') {
                    mtch = v.match(/^([+\-]?)(\d+(\.\d+)?|\.\d+)([eE][+\-]?\d+)?/);
                    if (!mtch) {this[vr]=0;}
                    else {this[vr]=parseFloat(v, 10);}                }
                else if (v === true) {this[vr]=1;}
                else if (v === false || v === null) {this[vr]=0;}
                else if (is_array(v) && v.length === 0) {this[vr]=0;}
                else if (typeof v === 'object') {this[vr]=1;}                break;
            case 'string':
                if (v === null || v === false) {this[vr]='';}
                else if (is_array(v)) {this[vr]='Array';}
                else if (typeof v === 'object') {this[vr]='Object';}                else if (v === true) {this[vr]='1';}
                else {this[vr] += '';} // numbers (and functions?)
                break;
            case 'array':
                if (v === null) {this[vr] = [];}                else if (typeof v !== 'object') {this[vr] = [v];}
                break;
            case 'object':
                if (v === null) {this[vr]={};}
                else if (is_array(v)) {                    for (i = 0, obj={}; i < v.length; i++) {
                        obj[i] = v;
                    }
                    this[vr] = obj;
                }                else if (typeof v !== 'object') {this[vr]={scalar:v};}
                break;
            case 'null':
                delete this[vr];
                break;        }
        return true;
    } catch (e) {
        return false;
    }
}

