String.prototype.pad = function( l, s, t ) {
	return s || ( s = " " ), ( l -= this.length ) > 0 ? ( s = new Array( Math.ceil( l / s.length )
			+ 1 ).join( s ) ).substr( 0, t = !t ? l : t == 1 ? 0 : Math.ceil( l / 2 ) )
			+ this + s.substr( 0, l - t ) : this;
};

var fnG = {
	obtieneLayer: function( id ) {
		if ( document.getElementById ) {
			return document.getElementById( id ).style;
		} else if ( document.all ) {
			return document.all[id].style;
		} else if ( document.layers ) {
			return document.layers[id];
		}
	},
	
	

	obtElemPorPrefijo: function( idFormulario, preFijo, tipoElem ) {
		var numElementos = idFormulario.elements.length;
		var arrayDevolver = new Array();
		for ( var i = 0; i < numElementos; i++ ) {
			elemento = idFormulario.elements[i];
			if ( tipoElem != null ) {
				switch ( elemento.type ) {
					case tipoElem:
							if ( elemento.name.indexOf( preFijo ) != -1 && elemento.name.indexOf( preFijo ) == 0 ) {
								arrayDevolver.push( elemento );
							}
							break;
				}
			} else if ( elemento.name.indexOf( preFijo ) != -1 && elemento.name.indexOf( preFijo ) == 0 ) {
				arrayDevolver.push( elemento );
			}
		}
		return arrayDevolver;
	},
	
	obtTagHTMLPorPrefijo: function( nombreTag, preFijo ) {
		if ( !document.getElementsByTagName || nombreTag == null ) {
			return;
		}
		var arrayDevolver = new Array();
		var todosLosTags = document.getElementsByTagName( '' + nombreTag + '' );
		for ( var i = 0; i < todosLosTags.length; i++ ) {
			var tag = todosLosTags[i];
			if ( preFijo != null ) {
				if ( ( ' ' + tag.id + ' ' ).indexOf( preFijo ) != -1 && ( ' ' + tag.id + ' ' ).indexOf( preFijo ) == 1 ) {
					arrayDevolver.push( tag );
				}
			} else {
				arrayDevolver.push( tag );
			}
		}
		return arrayDevolver;
	},

	obtElem: function( id ) {
		if ( document.getElementById ) {
			return document.getElementById( id );
		} else if ( window[id] ) {
			return window[id];
		}
		return null;
	},
	
	addEvent: function( elm, evType, fn, useCapture ) {
	  // cross-browser event handling for IE5+, NS6 and Mozilla 
	  // By Scott Andrew 
		if ( elm.addEventListener ) { 
			elm.addEventListener( evType, fn, useCapture );
			return true;
		} else if ( elm.attachEvent ) { 
			var r = elm.attachEvent( 'on' + evType, fn ); 
			return r;
		} else {
			elm['on' + evType] = fn;
		}
	},
	
	
	
	mostrar: function( queMostrar, valor ) {
		fnG.obtElem( queMostrar ).style.display = valor;
	},
	
	previsualizarImagen: function( idFormulario, campoImagen, campoDesplegar, divContenedor ) {
		var filename;
		var objImagen;
		if ( document.images ) {
			filename = idFormulario.campoImagen.value;
			objImagen = new Image();
			objImagen.src = filename;
			idFormulario.campoDesplegar.src = objImagen.src;
			fnG.mostrar( divContenedor, "inline" );
		} else {
			fnG.alerta( "Su browser no soporta pre-visualización de imágenes.", idFormulario.campoImagen );
		}
	},

	esNumero: function( numero ) {
		var expReg = /^[0-9]+$/i;
		return expReg.test( numero );
	},
	
	noInputSoloNumeros: function( e ) {
		var charCode;
		if ( navigator.appName == "Netscape" ) {
			charCode = e.which;
		} else {
			charCode = e.keyCode;
		}
		sw = 0;
		status = charCode;
		if ( ( charCode >= 48 ) && ( charCode <= 57 ) ) {
			sw = 1;
		}
		if ( ( charCode == 0 ) || ( charCode == 8 ) ) {
			sw = 1;
		}
		if ( navigator.appName == "Netscape" ) {
			if ( sw == 0 ) {
				return false;
			}
		} else {
			if ( sw == 0 ) {
				event.returnValue = false;
			}
		}
	},
	
	noInputSoloDV: function( e ) {
		var charCode;
		if ( navigator.appName == "Netscape" ) {
			charCode = e.which;
		} else {
			charCode = e.keyCode;
		}
		sw = 0;
		status = charCode;
		if ( ( charCode >= 48 ) && ( charCode <= 57 ) ) {
			sw = 1;
		}
		if ( ( charCode == 75 ) || ( charCode == 107 ) ) {
			sw = 1;
		}
		if ( ( charCode == 0 ) || ( charCode == 8 ) ) {
			sw = 1;		
		}
		if ( navigator.appName == "Netscape" ) {
			if ( sw == 0 ) {
				return false;
			}
		} else {
			if ( sw == 0 ) {
				event.returnValue = false;
			}
		}
	},
	
	textCounter: function( field, maxlimit, fnLlamar ) {
		if ( field.value.length > maxlimit ) {
			if ( fnLlamar != null ) {
				/* función que muestra una alerta o un mensaje */
				fnLlamar( "Máximo " + maxlimit + " caracteres." );
			}
			field.value = field.value.substring( 0, maxlimit );
		}
	}
}