
//--CREAR INSTANCIA AJAX
var patronNumero =/^(0|[1-9][0-9]*)$/;


function crearInstancia(){
	XMLHttp = false;
	if(window.XMLHttpRequest){
		return new XMLHttpRequest();
	}else if(window.ActiveXObject){
			var versiones = ["Msxml2.XMLHTTP.7.0", "Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "Msxml2.XMLHTTP.3.0", "Msxml2.XMLHTTP", "Microsoft.XMLHTTP"];
			for(var i=0; i<versiones.length;i++){
				try{
					XMLHttp = new ActiveXObject(versiones[i]);
					if(XMLHttp){
						return XMLHttp;
						break;
					}
				}catch (e){};				
			}
	}
}

String.prototype.trim = function(){
	var s = this.replace(/^\s+|\s+$/g,"");
	s = s.replace(/\s{2,}/g," ");	
	return s;
}

String.prototype.guionUTF8 = function(){
	var s = this.replace(/—/gi,"-");
	s = s.replace(/–/gi,"-");
	s = s.replace(/“/gi,"\"");
	s = s.replace(/”/gi,"\"");
	return s;
}

//FUNCION PARA INGRESAR SOLAMENTE NUMEROs
/*window.onload = function() {
  document.onkeyup = muestraInformacion;
  document.onkeypress = muestraInformacion;
  document.onkeydown = muestraInformacion;
}
 
function muestraInformacion(elEvento) {
  var evento = window.event || elEvento;
 
  var mensaje = "Tipo de evento: " + evento.type + "<br>" +
                "Propiedad keyCode: " + evento.keyCode + "<br>" +
                "Propiedad charCode: " + evento.charCode + "<br>" +
                "Carácter pulsado: " + String.fromCharCode(evento.charCode);
 
  alert(mensaje)
}
*/



//var nav4 = window.Event ? true : false;
function acceptNum(id){
/*	var valor = document.getElementById(id).value; //alert(valor);
	
	var b = isNaN(valor/valor);
	
	if(b==true){
		alert("Ingresar solo números.\n");
		var t =  valor.slice(0,-1);
		document.getElementById(id).value = t;		
	}
	document.getElementById(id).focus();
	return;*/
	
	
	//var evento = window.event || elEvento;
//	var key = evento.keyCode;
//	if(!(key <= 13 || (key >= 48 && key <= 57))){
//		alert("Ingresar solo números.\n");
//		return 0;
//	}
//	   return (key <= 13 || (key >= 48 && key <= 57));
}

function completaCeros(c,n){//c=cadena; n=longitud final
	//alert(c);
	var long = c.length;
	var t = n-long;
	var i=0;
	//alert(i);
	if(long==n){return c;}
	else{
		var agrega = "";
		for(i;i<t;i++){agrega+="0";}		
		c = agrega + c;
		return c;
	}	
}

//FUNCIONES PARA PODER SELECCIONAR NEGRITA, SUBRAYADO E ITALICA
function instag(tag){
	var input = document.getElementById('txtVoces');
	if(tag=="e"){
		tag = 'br';
		var start = input.selectionStart;
		var end = input.selectionEnd;
		var insText = input.value.substring(start, end);
		input.value = input.value.substr(0, start) + '' + insText + '<'+tag+'>'+ input.value.substr(end);
		input.focus();
		input.setSelectionRange(start+2+tag.length+insText.length+3+tag.length,start+2+tag.length+insText.length+3+tag.length);
		return;
	}
	if(typeof document.selection != 'undefined' && document.selection) {
		var str = document.selection.createRange().text;
		input.focus();
		var sel = document.selection.createRange();
		sel.text = "<" + tag + ">" + str + "</" +tag+ ">";
		sel.select();
		return;
	}else if(typeof input.selectionStart != 'undefined'){
		var start = input.selectionStart;
		var end = input.selectionEnd;
		var insText = input.value.substring(start, end);
		input.value = input.value.substr(0, start) + '<'+tag+'>' + insText + '</'+tag+'>'+ input.value.substr(end);
		input.focus();
		input.setSelectionRange(start+2+tag.length+insText.length+3+tag.length,start+2+tag.length+insText.length+3+tag.length);
		return;
	}else{
		input.value+=' <'+tag+'>Reemplace este texto</'+tag+'>';
		return;
	}
}


/*
function inslink(){
	var input = document.form1.contenido;
	if(typeof document.selection != 'undefined' && document.selection) {
		var str = document.selection.createRange().text;
		input.focus();
		var my_link = prompt("Enter URL:","http://");
		if (my_link != null) {
			if(str.length==0){
				str=my_link;
			}
			var sel = document.selection.createRange();
			sel.text = "[a href=\"" + my_link + "\"]" + str + "[/a]";
			sel.select();
		}
		return;
	}else if(typeof input.selectionStart != 'undefined'){
		var start = input.selectionStart;
		var end = input.selectionEnd;
		var insText = input.value.substring(start, end);
		var my_link = prompt("Enter URL:","http://");
		if (my_link != null) {
			if(insText.length==0){
				insText=my_link;
			}
		input.value = input.value.substr(0, start) +"[a href=\"" + my_link +"\"]" + insText + "[/a]"+ input.value.substr(end);
		input.focus();
		input.setSelectionRange(start+11+my_link.length+insText.length+4,start+11+my_link.length+insText.length+4);
		}
		return;
	}else{
		var my_link = prompt("Ingresar URL:","http://");
		var my_text = prompt("Ingresar el texto del link:","");
		input.value+=" [a href=\"" + my_link + "\"]" + my_text + "[/a]";
		return;
	}
}



/*
UTF8 = {
	encode: function(s){
		for(var c, i = -1, l = (s = s.split("")).length, o = String.fromCharCode; ++i < l;
			s[i] = (c = s[i].charCodeAt(0)) >= 127 ? o(0xc0 | (c >>> 6)) + o(0x80 | (c & 0x3f)) : s[i]
		);
		return s.join("");
	},
	decode: function(s){
		for(var a, b, i = -1, l = (s = s.split("")).length, o = String.fromCharCode, c = "charCodeAt"; ++i < l;
			((a = s[i][c](0)) & 0x80) &&
			(s[i] = (a & 0xfc) == 0xc0 && ((b = s[i + 1][c](0)) & 0xc0) == 0x80 ?
			o(((a & 0x03) << 6) + (b & 0x3f)) : o(128), s[++i] = "")
		);
		return s.join("");
	}
};

/*
UTF8.encode(s: String): String
    		Converts from ANSI to UTF-8
			s - string to be converted
	
UTF8.decode(s: String): String
    		Converts from UTF-8 to ANSI
			s - string to be converted
			
			
EJEMPLO
var s = "aáéíóúe";
var s = "—";

document.write(
    ('UTF8.encode("' + s + '") = ').bold(), UTF8.encode(s), "<br />",
    ('UTF8.decode(UTF8.encode("' + s + '"))) = ').bold(), UTF8.decode(UTF8.encode(s))
);
*/
