// Contiene referencias a las celdas de la fila correspondiente
/*var productRow;
// Controlar que solo haya una fila en modo edición
var editing = false;

var row_id;*/


// #####################
// Operaciones con AJAX
//######################

/*function nuevoAjax() {

	var xmlhttp=false;

 	try {
 		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 	} catch (e) {
		 // assume IE6 or older 
   		var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0", 
                                   		 "MSXML2.XMLHTTP.5.0", 
                                    	 "MSXML2.XMLHTTP.4.0", 
                                    	 "MSXML2.XMLHTTP.3.0", 
                                    	 "MSXML2.XMLHTTP", 
                                    	 "Microsoft.XMLHTTP"); 
		 
    		// try every prog id until one works 
    		for (var i=0; i<XmlHttpVersions.length && !xmlhttp; i++) { 
      		try {  
        		// try to create XMLHttpRequest object 
        		xmlhttp = new ActiveXObject(XmlHttpVersions[i]); 
     		 }  
     		 catch (e) {} 
    		} 

  	}

	if (!xmlhttp && typeof window.XMLHttpRequest!='undefined') {
 		xmlhttp = new window.XMLHttpRequest();
	}
	return xmlhttp;
}*/

function NuevoAjax(){
        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 cargarContenido(id_contenido) { 

	var contenedor=document.getElementById('contenido-principal');
	var url="contenido.php";
	var params="f="+id_contenido;
	
	var ajax=NuevoAjax();
	ajax.open("POST", url, true);

	
	ajax.onreadystatechange=function() {

                if (ajax.readyState==1) {
                        contenedor.innerHTML = "Cargando...";
                        //modificamos el estilo de la div, mostrando una imagen de fondo
                        //preloader.style.background = "url('loading.gif') no-repeat"; 
                } else if (ajax.readyState==4) {

                        if (ajax.status==200) {
                                //mostramos los datos dentro de la div
                                contenedor.innerHTML = ajax.responseText; 
                                //preloader.innerHTML = "Cargado.";
                                //preloader.style.background = "url('loaded.gif') no-repeat";
                        } else if (ajax.status==404) {
                                contenedor.innerHTML = "La página no existe";
                        } else {
                                //mostramos el posible error
                                contenedor.innerHTML = "Error:".ajax.status; 
                        }

                }

	}
	
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(params);


}

// ################################
// Operaciones directas en la tabla
// ################################

/*function editRow(id) {
	
	
if (editing == false) {

	// Accede a las celdas de la fila seleccionada
	productRow = document.getElementById(id).cells;
	
	// Introduce los valores actuales en una caja de texto
	// para poder ser modificados
	productRow[1].innerHTML =  
         '<input size="5" type="text" name="name" ' +  
         'value="' + productRow[1].innerHTML + '">';
		 
	productRow[2].innerHTML =  
         '<input size="5" type="text" name="price" ' +  
         'value="' + productRow[2].innerHTML + '">';
	
	// Al estar en modo edición, sustituye la opción "Edit" por "Save"
	// para poder guardar los cambios
	id = "'" + id + "'";
	productRow[3].innerHTML =
		'<a href="#" onclick="saveRow(' + id + ')">Save</a>/' + 
		'<a href="#" onclick="cancelEdit(' + id + ')">Cancel</a>';
	
	editing = true;
}

}

function saveRow(id) {
	productRow[1].innerHTML = document.forms.grid_form_id.name.value;  
	productRow[2].innerHTML = document.forms.grid_form_id.price.value; 
	id = "'" + id + "'";
	productRow[3].innerHTML = '<a href="#" onclick="editRow(' + id + ')"><img src="note05.gif"></a>';
	// Llamar a la función de actualización...
	editing = false;
}

function cancelEdit(id) {
	productRow[1].innerHTML = document.forms.grid_form_id.name.value;  
	productRow[2].innerHTML = document.forms.grid_form_id.price.value; 
	id = "'" + id + "'";
	productRow[3].innerHTML = '<a href="#" onclick="editRow(' + id + ')"><img src="note05.gif"></a>';
	editing = false;
}*/
