function objetoAjax(){
	var xmlhttp=false;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
		   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
  		}
	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}
/*
function objetoAjax(file) {
    xmlhttp=false;
    this.AjaxFailedAlert = "Su navegador no soporta las funciónalidades de este sitio y podria experimentarlo de forma diferente a la que fue pensada. Por favor habilite javascript en su navegador para verlo normalmente.\n";
    this.requestFile = file;
    this.encodeURIString = true;
    this.execute = false;
    if (window.XMLHttpRequest) { 
        this.xmlhttp = new XMLHttpRequest();
        if (this.xmlhttp.overrideMimeType) {
            this.xmlhttp.overrideMimeType('text/xml');
        }
    } 
    else if (window.ActiveXObject) { // IE
        try {
            this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        }catch (e) {
            try {
                this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
                this.xmlhttp = null;
            }
        }
        if (!this.xmlhttp && typeof XMLHttpRequest!='undefined') {
            this.xmlhttp = new XMLHttpRequest();
            if (!this.xmlhttp){
                this.failed = true; 
            }
        } 
    }
    return this.xmlhttp ;
}
*/

function enviarDatos(method,url,variables,divResult){
	
  //instanciamos el objetoAjax
  ajax=objetoAjax();
  ajax.open(method,url,true);
  ajax.onreadystatechange = function() {
    switch(ajax.readyState){
        case 0:
        case 1:
        case 2:
		divHTMLText(divResult,"Iniciando proceso...");
        break;
        
        case 3:
		divHTMLText(divResult,"Procesando...");
        break;
        
        case 4:
        switch (ajax.status){
          case 200:
		  divHTMLText(divResult,ajax.responseText);
          break;
          default:
		  divHTMLText(divResult,"Problemas al ejecutar la consulta.<br>"+ajax.statusText);
          break;
        } // END switch
        break;
    } // END switch
  }
	switch(method){
		case "POST":
  		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		ajax.send(variables);
		break;
		case "GET":
		ajax.send(null);
		break;
	}
}

function clearForm(form) {
	formulario = eval('document.'+form+'.reset()');
	return false;
}

function showHideLayer(idDiv){
	capa = document.getElementById(idDiv).style;
	displayStatus = capa.display;
	switch(displayStatus){
		case "none":
		capa.display = "block";
		break;		
		case "block":
		capa.display = "none";
		break;		
	}
}

function divHTMLText(idDiv,HTMLText){
	document.getElementById(idDiv).innerHTML = HTMLText;
}

function inputCopyPasteText(idOrigen,idDestino){
	texto_origen = document.getElementById(idOrigen).value;
	document.getElementById(idDestino).value = texto_origen;
}

function switchButtonType(idButton,buttonType){
	alert(buttonType);
	//document.getElementById(idButton).type = buttonType;	
}
function getRadioValue(radio){
	for(i=0;i<radio.length;i++)
    if(radio[i].checked) return radio[i].value;
}
