
function callback_PutResult(res) {
	el = res.context;
	if(document.all) {
		ele = document.all[el];
	} else {
		ele = document.getElementById(el);
	}
	if (res.value) {
		//05-03-2007prompt('', res.value);
		ele.innerHTML = res.value;
	} else {
		ele.innerHTML = "";
	}
}

function callback_PutResult2(res) {
	el = res.context;
	if(document.all) {
		ele = document.all[el];
	} else {
		ele = document.getElementById(el);
	}
	if (res.value) {
		ele.innerHTML = res.value;
		el = ele.parentNode;
		el.style.display = '';
	} else {
		el = ele.parentNode;
		el.style.display = 'none';
		ele.innerHTML = "";
	}
}

function goAjaxPage(id, page, element, plantilla) {
	try	{
		if(!plantilla) plantilla = 'ajax_contenido_navegacion';
		MyMethods.DisplayNews(id, page, plantilla, callback_PutResult, element);
	} catch(e) {
		alert("Error: " + e.description);
	}
}

function callback_PutResultPlantilla(res) {
	el = res.context;
	if(document.all) {
		ele = document.all[el];
	} else {
		ele = document.getElementById(el);
	}
	if (res.value) {
		ele.innerHTML = res.value;
		setTimeout("cargaDatosPlantilla()", 1000);

	} else {
				alert(res.value);

		ele.innerHTML = "";
	}
}


function colocaCargando(element) {
	ele = document.getElementById(element);	
	ele.innerHTML = "";
	icono = document.createElement("IMG");
	resultado = "/admin/images/html/cargando.gif";
	icono.src = resultado;
	icono.setAttribute('border', '0');
	icono.setAttribute('align', 'center');
	icono.className='img_cargando';
	ele.appendChild(icono);

}

function colocacontenido (posicion, cantidad, color, plantilla, element, i) {

	try	{
		MyMethods.CargaFormulario(posicion.options[posicion.options.selectedIndex].value, cantidad.value, color.value, plantilla, '', i, callback_PutResult, element);
	} catch(e) {
		//alert("Error: " + e.description);
	}	
}

function colocacontenido2 (posicion, cantidad, color, plantilla, element, i) {

	try	{
		MyMethods.CargaFormulario(posicion.options[posicion.options.selectedIndex].value, cantidad.value, color.value, plantilla, 'none', i, callback_PutResult, element);
	} catch(e) {
		//alert("Error: " + e.description);
	}	
}

function colocaplantilla (categoria_id, element) {

	try	{
		colocaCargando(element);
		MyMethods.CargaFormularioPlantilla(categoria_id, callback_PutResultPlantilla, element);
	} catch(e) {
		alert("Error: " + e.description);
	}	
}

function colocaplantillaBoletin (boletin_id, categoria_id, element) {

	try	{
		colocaCargando(element);
		MyMethods.CargaFormularioBoletin(boletin_id, categoria_id, callback_PutResult, element);
	} catch(e) {
		alert("Error: " + e.description);
	}	
}

function cargaDatosPlantilla (){
	for(i=1;i<=9;i++)
	{
		try
		{
			//colocacontenido2(this.form.zona_id_posicion1, this.form.cantidad_posicion1, this.form.color_posicion1, 'mail_posicion1.tpl.htm', 'posicion1');	
			colocacontenido2(this.form.elements['zona_id_posicion'+i], this.form.elements['cantidad_posicion'+i], this.form.elements['color_posicion'+i], 'mail_posicion.tpl.htm', 'posicion'+i, i);
		}
		catch(e){}
	}
}

function callback_Elements(res)
{
	el = res.context;
	if (res.value) {
		fillObjects(res.value, el);
	} else {
    	selectClear(el);
	//	alert('error al procesar solicitud');
	}
}

var dfirst_text = "Seleccione";
var first_text = dfirst_text;
function Elements(myclass, value, ele)
{
	var d = null;
	try	
	{
	    if (value != ''){
			res = MyMethods.Elements(myclass, value);
			if (res.value) {
				fillObjects(res.value, ele);
			} else {
			   	selectClear(ele);
			}
	    } else {
	    	selectClear(ele);
		}
	}
	catch(e)
	{
		alert("Error: " + e.description);
	}
}

function callback_ElementsAdmin(res)
{
	el = res.context;
	if (res.value) {
		fillObjects(res.value, el, 'Seleccione una opción');
		//AjaxUnLoading();
	} else {
		//alert('error al procesar solicitud');
		//AjaxUnLoading();
		selectClear(el);
		el.options[el.options.length] = new Option('Seleccione una opción', 0);
	}
}

function ElementsAdmin(myclass, _method, value, ele) {
	var d = null;
	try	{
		//AjaxLoading();
		MyMethods.ElementsAdmin(myclass, _method, value, callback_ElementsAdmin, ele);
		//alert (myclass+","+ _method+","+value+","+ ele);
	} catch(e) {
		alert("Error: " + e.description);
	}
}

function fillSelectFromArray(selectobj, array) {

	for(var i = 0; i < array.length; i++) {
		value = array[i]['value'];
		text = array[i]['text'];
		eval('text = ' + text + ";");
		opt = new Option(text, value);
		if (selectobj && value) {
			selectobj.options[selectobj.options.length] = opt;
			//selectobj.add(opt, selectobj.options.length);
		}
	}
	first_text = dfirst_text;
}

// unserializeArray: deserializa el parametro param y devuelve un arreglo hash 
function _unserializeArray(param) {
//	param = param.substr(0,param.length-1);
	var i, j, text, value, aux;
	objects = param.split("|");
	var aObjects = new Array();
	for(i = 0; i < objects.length; i++) {
		vars = objects[i].split("&");
		var object = new Array(vars.length);
		for (j = 0; j < vars.length; j++) {
			aux = vars[j].split("=");
			object[aux[0]] = aux[1];
			
		}
//		aObjects[aObjects.length] = object;
		aObjects.push(object);
	}
	return aObjects;
}

function fillObjects(data, select) {
	aDatas = _unserializeArray(data);
	selectClear(select);
	fillSelectFromArray(select, aDatas);
	return true;
}

function selectClear(lst){
	lst.options.length = 0;
	//opt = new Option(''+first_text+'', '0');
	//lst.options[lst.options.length] = opt;
	//lst.add(opt, lst.options.length); // mod by Jean (20060505)
}



var myDivAjax;
function AjaxLoading(mensaje)
{
	if(!mensaje) {
		mensaje = "CARGANDO...";
	}
	//alert(document.body.clientWidth);
	//myImageAjax = document.createElement("IMG");
	//myImageAjax.src = "/admin/images/html/loading.gif";

	ancho = (mensaje.length * 5)+'px';
	myDivAjax = document.createElement("DIV");
	myDivAjax.style.width = ancho;
	myDivAjax.height = "100px";
	//myDivAjax.style.overflow = "auto";
	myDivAjax.id = "myDivAjax";
	myDivAjax.style.position = "absolute";
	myDivAjax.style.right= 0; 
	myDivAjax.style.top= document.body.scrollTop;
	myDivAjax.style.display = 'block';
	myDivAjax.style.background = "red";
	myDivAjax.style.color = "#fff";
	myDivAjax.innerHTML = mensaje;
	myDivAjax.style.fontSize = "11px";
	
	//myDivAjax.appendChild(myImageAjax);
	document.body.appendChild(myDivAjax);
}
function AjaxUnLoading()
{
	if(typeof (myDivAjax)=="object")
	{
		myDivAjax.innerHTML = "LISTO";
		myDivAjax.style.display = 'none';
	}
}

function AjaxSubmitForm(form) 
{
	for(element in document.elements)
	{
		//
	}
}

	/***************************************
    * START END USER FUNCTIONS
    * Utilice las funciones siguientes para la interfaz de usuario.
    *
    * @access   public
    ****************************************/
	
	/**
	* Devuelve la subcategoria a partir de la categoria data
	*
	*
	*/
	
	
	function getTesauro(select){
		Elements('tesauro',-1,select);
		return true;
	}
	
	function getCategorias(tesauro_id,select){
		tesauro_id = parseInt(tesauro_id);
		Elements('categoria',tesauro_id,select);
		return true;
	}
	
	function getSubCategorias(categoria_id,select){
		categoria_id = parseInt(categoria_id);
		Elements('subcategoria', categoria_id, select);
	}
	
	function callback_documentos(res) {
		ele = document.getElementById('resultados');
		//if (typeof ele != 'undefined' && ele.innerHTML) {
			ele.innerHTML = "";
			ele.innerHTML = res.value;
		//}
	}

	//obtiene una plantilla cargada con los resultados
	function getDocumentos(texto,desde,hasta,orden,tesauro_id,categoria_id,subcategoria_id)
	{
		ele = document.getElementById('resultados');
		ele.innerHTML = "Un momento... Loading...";
		MyMethods.GetDocumentos(texto,desde,hasta,orden,tesauro_id,categoria_id,subcategoria_id,callback_documentos);
	}
	
	function cargando()
	{
		
	}

	/***************************************
    * FINISH END USER FUNCTIONS
    *
    * @access   public
    ****************************************/	