String.prototype.trim = function() {
	var new_str = this.replace(new RegExp("^[ ]+", "g"), "")
	return new_str.replace(new RegExp("[ ]+$", "g"), "");
};
Array.prototype.hasElement = function( needle ) {
	for ( var y=0; y<this.length; y++)
	{
		if ( this[y] == needle )
		{
			return true;
		}
	}
	return false;
};
document.getFrameById = function( frame_id ) {
	var iframe = document.getElementById(frame_id);
	var doc =	(iframe.contentDocument) ? iframe.contentDocument :
				(iframe.contentWindow) ? iframe.contentWindow.document :
				(iframe.document) ? iframe.document : null;
	return doc;
};

///////////////////////////// TABS ////////////////////////////////////
var config_tabs = new DynTabs('NoArrowTabs');
var opciones_1 = new Array("Configuración", "Su Empresa");
config_tabs.setItemNames( opciones_1 );
config_tabs.setSelectedItemNames( opciones_1 );
config_tabs.setItemIds( new Array("config", "su_empresa") );
config_tabs.setTargetId("configuraciones");

var product_tabs = new DynTabs('NoArrowTabs');
product_tabs.setItemNames( new Array("1", "2", "3", "4") );
product_tabs.setSelectedItemNames( new Array("Producto 1", "Producto 2", "Producto 3", "Producto 4") );
product_tabs.setItemIds( new Array("producto_1", "producto_2", "producto_3", "producto_4") );
product_tabs.setTargetId("productos");

var promo_tabs = new DynTabs('NoArrowTabs');
promo_tabs.setItemNames( new Array("Promociones", "Legales") );
promo_tabs.setSelectedItemNames( new Array("Promociones", "Legales") );
promo_tabs.setItemIds( new Array("promos", "legales") );
promo_tabs.setTargetId("promo_legales");

var accesories_tabs = new DynTabs('NoArrowTabs');
var opciones_2 = new Array("Accesorios Grupo 1", "Accesorios Grupo 2");
accesories_tabs.setItemNames( opciones_2 );
accesories_tabs.setSelectedItemNames( opciones_2 );
accesories_tabs.setItemIds( new Array("accesorio_1", "accesorio_2") );
accesories_tabs.setTargetId("accesorios");


///////////////////////////// ble /////////////////////////////
TemplateParser.TEMPLATES_DIR = '/la/edesigner/templates/';

var Edesigner = {};

Edesigner.DEBUG = false;

Edesigner.SELECT_EMPTY_VALUE		= 'none';
Edesigner.TINY_MCE_CLASS			= 'mceEditor';
Edesigner.ACTIVATE_CONTROL_PREFIX	= 'sub.';
Edesigner.FORM_NAME					= 'EdesignerForm';
Edesigner.IFRAME_ID					= 'EdesignerPrevis';
Edesigner.SELECT_WITH_VALUE_CLASS	= 'with_value';
Edesigner.NUMBER_OF_PRODUCTS		= 4;
Edesigner.XML_PATH					= '/la/edesigner/';

// --> Prefijos de ids de elementos del formulario
Edesigner.PRODUCT_FAMILY_COMBO_PREFIX		= 'product.';
Edesigner.PRODUCT_FAMILY_COMBO_SUFFIX		= '.family';
Edesigner.PRODUCT_NAME_COMBO_PREFIX			= 'product.';
Edesigner.PRODUCT_NAME_COMBO_SUFFIX			= '';
Edesigner.PRODUCT_PARTNUMBER_COMBO_PREFIX	= 'product.';
Edesigner.PRODUCT_PARTNUMBER_COMBO_SUFFIX	= '.title';
Edesigner.PRODUCT_DESCRIPTION_COMBO_PREFIX	= 'product.';
Edesigner.PRODUCT_DESCRIPTION_COMBO_SUFFIX	= '.spec';
Edesigner.PRODUCT_OTHERPN_COMBO_SUFFIX		= '.opcion';
Edesigner.PRODUCT_OTHERPN_TEXT				= 'Otro:';
// <--

// --> Nombres de tags importantes de los xmls
Edesigner.PRODUCTS_NAME_TAG	= 'family_code';	// tag que delimita el nombre de producto
Edesigner.PRODUCTS_TAG		= 'row';			// tag que delimita un producto
Edesigner.MACHINE_TYPE		= 'machine_type';	// tag que delimita el tipo de maquina
Edesigner.MACHINE_MODEL		= 'model';			// tag que delimita el modelo
// <--

Edesigner.xml_dictionary;

Edesigner.MENSAJE_COMBO_VACIO	= 'Elija una opción';
Edesigner.VALOR_COMBO_VACIO		= 'none';

Edesigner.xml_docs				= new Array();

///////////////////// METODOS //////////////////////////////////

// El ActiveControl es un indicador para saber si un elemento debe ser parseado o no
Edesigner.ActiveControl = {};
Edesigner.setActiveControl = function( control_id, requirements ) {
	this.ActiveControl[control_id] = requirements;
}
Edesigner.getIsControlActive = function( control_id ) {
	var is_active = false;
	for ( var i=0; i<Edesigner.ActiveControl[control_id].length; i++ ) {
		var control = document.getElementById(Edesigner.ActiveControl[control_id][i]);
		switch (control.nodeName.toUpperCase()) {
			case 'INPUT':	/*alert( control.id+": "+control.value.trim().length );*/ is_active = (control.value.trim().length > 0) ? true : is_active; break;
			case 'SELECT':	is_active = ( !(control.options[control.selectedIndex].value == Edesigner.SELECT_EMPTY_VALUE || control.options[control.selectedIndex].value == "") ) ? true : is_active; break;
			case 'TEXTAREA': 
				if ( getHasClass(Edesigner.TINY_MCE_CLASS, control) ) {
					is_active = (MCE_getTextareaContent(control.id).trim().length > 0) ? true : is_active;
				} else {
					is_active = (control.value.trim().length != 0) ? true : is_active;
				}
				break;
		}
		if ( is_active == true ) {
			break;
		}
	}
	return is_active;
}

Edesigner.populateSelectors = function() {
	for ( var i=1; i<=Edesigner.NUMBER_OF_PRODUCTS; i++ ) {
		this.Families.loadSelect( document.getElementById("product."+i+".family"), '/la/edesigner/familias.txt' );
	}
};
Edesigner.SelectLoader = {
	selects: new Array(),
	data: {}
};
Edesigner.SelectLoader.populateSelect = function( select, data ) {
	select.options.length = 0;
	for ( var x in data )
	{
		var _option = document.createElement("option");
		_option.value = x;
		_option.text = data[x].text;
		try {
			select.add(_option,null); // standards compliant
		} catch(ex) {
			select.add(_option); // IE only
		}
	}
};
Edesigner.SelectLoader.displayLoading = function( select ) {
	select.disabled = true;
	var offset = $(select).offset();
	var x = offset.left-16;
	var y = offset.top;
	var img_div = document.createElement("div");
	$(img_div).css({position: "absolute", left: x+"px", top: y+"px"}).addClass("loading");
	var img = document.createElement("img");
	img.alt = "Cargando...";
	img.src = "/la/images/loading6-0.gif";
	img_div.appendChild(img);
	select.parentNode.appendChild(img_div);
};
Edesigner.SelectLoader.destroyLoading = function( select ) {
	select.disabled = false;
	var childs = select.parentNode.getElementsByTagName("div");
	for ( var z=0; z<childs.length; z++ )
	{
		if ( getHasClass('loading', childs[z]) )
		{
			select.parentNode.removeChild(childs[z]);
		}
	}
};

Edesigner.Families = {
	data_url: '/la/edesigner/familias.txt',
	selects: new Array(),
	data: null
};
Edesigner.Families.loadSelect = function( select ) {
	this.selects.push(select);
	var id = this.selects.length-1;
	Edesigner.SelectLoader.displayLoading( this.selects[id] );
	if ( this.data ) {
		this.populateSelect( select, this.data );
		this.destroyLoading( select );
	} else {
		var data_url = this.data_url;
		$.ajax({
			url: data_url,
			dataType: 'json',
			success: function(result) {
				if ( !Edesigner.Families.data ) { Edesigner.Families.data = result; }
				Edesigner.SelectLoader.populateSelect( Edesigner.Families.selects[id], result );
				Edesigner.SelectLoader.destroyLoading( Edesigner.Families.selects[id] );
			}
		});
	}
};

// Devuelve la definicion de WORD perteneciente a la categoria CATEGORY en el diccionario DICTIONARY.
// La categoria se usa porque puede haber una misma palabra en muchas categorias.
// Por ejemplo: "si" y "no" pueden ser palabras para categorias como Bluetooth o Fingerprint Reader
Edesigner.getDefinition = function( dictionary, category, word ) {
	var definition = false;
	var categorias = dictionary.getElementsByTagName( category );
	// Si existe la categoría
	if ( categorias.length > 0 ) {
		var categoria = categorias[0];
		// Itero entre los elementos de la categoria...
		var dato = categoria.firstChild;
		while ( dato != null ) {
			//... hasta que el nombre del nodo valga igual que lo que busco
			if ( dato.nodeName == word ) {
				// guardo el valor y corto el loop
				definition = dato.firstChild.nodeValue;
				break;
			}
			dato = dato.nextSibling;
		}
	}
	return definition;
}
// Devuelve un arreglo con los nombres de producto correspondientes a la familia
Edesigner.getProductNames = function( family_data, with_definition ) {
	// obtengo todos los nombres de producto
	var all_names = family_data.getElementsByTagName( this.PRODUCTS_NAME_TAG );
	// creo un nuevo arreglo donde voy a ubicar los nombres de producto sin repeticiones
	var distinct_names = new Array();
	var valor;
	// itero a lo largo de todos los nombres de producto
	for ( x=0; x<all_names.length; x++) {
		valor = all_names[x].firstChild.nodeValue;
		if ( with_definition == true ) {
			valor = this.getDefinition( this.xml_dictionary, all_names[x].nodeName, valor );
		}
		// obtengo los elementos sin repeticiones
		if ( !in_array( valor, distinct_names ) ) {
			distinct_names.push( valor );
		}
	}
	return distinct_names;
}

// Devuelve un arreglo con todos los part numbers para el producto product
Edesigner.getPartNumbers = function( family_data, product ) {
	// Creo un arreglo donde guardare todos los part numbers
	var part_numbers = new Array();
	// obtengo todos los productos
	var all_products = family_data.getElementsByTagName( this.PRODUCTS_TAG );
	var producto_iterado;
	var tipo;
	var modelo;
	var nombre_producto;
	// recorro todos los productos de la familia
	for ( i=0; i<all_products.length; i++ )
	{
		producto_iterado = all_products[i].firstChild;
		tipo = '';
		modelo = '';
		nombre_producto = '';
		// recorro todas las ramas del producto
		while ( producto_iterado != null )
		{
			// --> guardo el nombre del producto, el tipo de maquina y el modelo
			if ( producto_iterado.nodeName == this.PRODUCTS_NAME_TAG )
			{
				nombre_producto = producto_iterado.firstChild.nodeValue;
			}
			else if ( producto_iterado.nodeName == this.MACHINE_TYPE )
			{
				tipo = producto_iterado.firstChild.nodeValue;
			}
			else if ( producto_iterado.nodeName == this.MACHINE_MODEL )
			{
				modelo = producto_iterado.firstChild.nodeValue;
			}
			// <--
			producto_iterado = producto_iterado.nextSibling;
		}
		// Si el nombre del producto coincide con el que busco y se encontraron tipo y modelo,
		// agrego el part number al arreglo
		if ( nombre_producto == product && tipo.length > 0 && modelo.length > 0)
		{
			//tipo.replace( /_/g, "" );
			//modelo.replace( /_/g, "" );
			part_numbers.push( tipo+modelo );
		}
	}
	return part_numbers;
};
// Devuelve el arreglo de part numbers retocado
// Los part numbers se graban en los xml con caracteres como "_" y con las letras en minuscula
// Para mostrarlos correctamente se les quita los guiones y se lo pone en mayuscula
Edesigner.retocarPartNumbers = function( arreglo_part_numbers ) {
	var nuevo_arreglo = new Array();
	for ( var i=0; i<arreglo_part_numbers.length; i++ )
	{
		nuevo_arreglo[i] = arreglo_part_numbers[i].replace( /_/g, '' );
		nuevo_arreglo[i] = arreglo_part_numbers[i].toUpperCase();
	}
	return nuevo_arreglo;
}

// Devuelve la descripcion del producto de tipo type y modelo model sacado de los datos family_data
Edesigner.getProductDescription = function( family_data, part_number ) {
	// --> Algunos part numbers tienen la forma _tipo_modelo
	// Para ellos el modelo vale _###, por lo que debo quitar 4 caracteres al final en lugar de 3
	var chequeo_guion = part_number.substr( part_number.length-4 );
	chequeo_guion = chequeo_guion.substr( 0, 1 );
	var largo_modelo = ( chequeo_guion == '_' ) ? 4 : 3;
	// <--
	// Obtengo del part number el tipo y el modelo
	var type = part_number.substr( 0, part_number.length-largo_modelo );
	var model = part_number.substr( part_number.length-largo_modelo );
	//alert( 'type= '+type+'\nmodel= '+model );
	var product_description = '';
	var all_products = family_data.getElementsByTagName( this.PRODUCTS_TAG );
	var producto_iterado;
	var tipo;
	var modelo;
	var tmp_description;
	var tmp_string;
	// recorro todos los productos de la familia
	for ( i=0; i<all_products.length; i++ ) {
		producto_iterado = all_products[i].firstChild;
		tipo = '';
		modelo = '';
		tmp_description = '';
		// recorro todas las ramas del producto
		while ( producto_iterado != null ) {
			// --> guardo el tipo de maquina y el modelo
			if ( producto_iterado.nodeName == this.MACHINE_TYPE ) {
				tipo = producto_iterado.firstChild.nodeValue;
			} else if ( producto_iterado.nodeName == this.MACHINE_MODEL ) {
				modelo = producto_iterado.firstChild.nodeValue;
			}
			// <--
			// guardo la descripcion (el resto de los campos menos el nombre)
																			// por diferencia de navegadores se debe mirar que
																			// siempre se traten de nodos elemento 
																			// (1 == nodo elemento)
			else if ( producto_iterado.nodeName != this.PRODUCTS_NAME_TAG && producto_iterado.nodeType == 1 ) {
				tmp_string = this.getDefinition( this.xml_dictionary, producto_iterado.nodeName, producto_iterado.firstChild.nodeValue );
				if ( tmp_string == false ) {
					if ( this.DEBUG == true ) {
						alert( "DEBUG: La caracteristica '"+producto_iterado.nodeName+"' no tiene definido el valor '"+producto_iterado.firstChild.nodeValue+"' en el diccionario." );
					}
				} else {
					tmp_description +=  tmp_string;
				}
			}
			producto_iterado = producto_iterado.nextSibling;
		}
		// Si el tipo y el modelo coinciden con los buscados,
		// agrego la descripcion
		if ( tipo == type && modelo == model ) {
			product_description = tmp_description;
			break;
		}
	}
	if ( product_description.substr(product_description.length-2) == ", " ) {
		product_description = product_description.substr(0, product_description.length-2)+".";
	}
	return product_description;
}


Edesigner.Parragraphs = {
	data: null
};
Edesigner.Parragraphs.loadSelect = function( select ) {
	Edesigner.SelectLoader.displayLoading( select );
	$.ajax({
		url: '/la/edesigner/parrafos.txt',
		dataType: 'json',
		success: function( result ) {
			Edesigner.Parragraphs.data = result;
			Edesigner.SelectLoader.populateSelect( select, result );
			Edesigner.SelectLoader.destroyLoading( select );
		}
	});
};
Edesigner.Parragraphs.onChange = function( select ) {
	if ( this.data != null ) {
		MCE_setTextareaContent( 'hero.mkt.text', this.data[select.options[select.selectedIndex].value].parragraph );
	}
	Edesigner.refreshPreview();
};

Edesigner.dynamicImageParameter = function( input ) {
	document.getElementById("promo.title.final").value = input.value.replace(/ /g, "%20");
	this.refreshPreview();
};

/* Lee todos los elementos del formulario del Edesigner. 
   Si el elemento es un ActiveControl, lo guarda para parsearlo luego.
   Si no, agrega su valor como contenido dinamico al TemplateParser.
*/
Edesigner.prepareTemplate = function( template_name ) {
	for ( var control_id in this.ActiveControl ) {
		TemplateParser.setDynamicContent( control_id, this.getIsControlActive(control_id) );
	}
	var form_elements = document.forms[Edesigner.FORM_NAME].elements;
	var sub_templates = new Array();
	for ( var i=0; i<form_elements.length; i++ ) {
		var actualizar = true;
		if ( form_elements[i].name ) {
			if ( form_elements[i].name.search(/show\./) > -1 ) {
				if ( !sub_templates.hasElement(form_elements[i].name) ) {
					sub_templates.push(form_elements[i].name);
				}
			} else {
				var element_value = "";
				var element_text = "";
				switch (form_elements[i].nodeName.toUpperCase())
				{
					case 'INPUT':	
						if ( form_elements[i].type == "radio" ) {
							if ( form_elements[i].checked == true ) {
								element_value = form_elements[i].value;
							} else {
								actualizar = false;
							}
						} else {
							element_value = form_elements[i].value;
						}
						break;
					case 'SELECT':
						if ( form_elements[i].selectedIndex < form_elements[i].options.length ) {
							element_value = form_elements[i].options[form_elements[i].selectedIndex].value;
							element_text = form_elements[i].options[form_elements[i].selectedIndex].text;
						}
						break;
					case 'TEXTAREA': 
						if ( getHasClass(Edesigner.TINY_MCE_CLASS, form_elements[i]) ) {
							element_value = MCE_getTextareaContent(form_elements[i].id);
							if ( element_value == "<p>&nbsp;</p>" ) {
								element_value = "";
							}
						} else {
							element_value = form_elements[i].value;
						}
						break;
				}
				if ( actualizar ) {
					TemplateParser.setDynamicContent( form_elements[i].name+".text", element_text );
					TemplateParser.setDynamicContent( form_elements[i].name, element_value );
				}
			}
		}
	}
}

/* Actualiza la previsualizacion */
Edesigner.refreshPreview = function() {
	if ( document.getElementsByName("automatico")[0].checked ) {
		var template_selector = document.getElementById("product.section");
		var edesigner_frame = document.getFrameById(Edesigner.IFRAME_ID).getElementsByTagName("body")[0];
		Edesigner.prepareTemplate();
		TemplateParser.parse( "template-"+template_selector.options[template_selector.selectedIndex].value, edesigner_frame );
	}
};

Edesigner.forcePreview = function() {
	var template_selector = document.getElementById("product.section");
	var edesigner_frame = document.getFrameById(Edesigner.IFRAME_ID).getElementsByTagName("body")[0];
	Edesigner.prepareTemplate();
	TemplateParser.parse( "template-"+template_selector.options[template_selector.selectedIndex].value, edesigner_frame );
};

Edesigner.save = function() {
	var template_selector = document.getElementById("product.section");
	document.getElementById("result").value = TemplateParser.parseTemplate( "template-"+template_selector.options[template_selector.selectedIndex].value );
	document.getElementById("company").value = document.getElementById("partner.name").value;
	document.getElementById("EdesignerSave").submit();
};

Edesigner.onAutomaticPreviewChange = function(checkbox) {
	var chkboxes = document.getElementsByName("automatico");
	for ( var i=0; i<chkboxes.length; i++ ) {
		chkboxes[i].checked = checkbox.checked;
	}
};

Edesigner.disableOtherPN = function( product_being_edited ) {
	document.getElementById( this.PRODUCT_DESCRIPTION_COMBO_PREFIX+product_being_edited+this.PRODUCT_OTHERPN_COMBO_SUFFIX ).disabled = "disabled";
	document.getElementById( this.PRODUCT_DESCRIPTION_COMBO_PREFIX+product_being_edited+this.PRODUCT_OTHERPN_COMBO_SUFFIX ).value = "";
	var selector = document.getElementById( this.PRODUCT_PARTNUMBER_COMBO_PREFIX+product_being_edited+this.PRODUCT_PARTNUMBER_COMBO_SUFFIX );
	selector.options[selector.options.length-1].text = this.PRODUCT_OTHERPN_TEXT;
}

Edesigner.tooltips = function() {
	$('.conTooltip').hover(function() {
		this.tip = this.title;
		$(this).find("img").tmpalt = $(this).find("img").alt;
		$(this).find("img").alt = "";
		$(this).append(
		 '<div class="toolTipWrapper" style="display: none;">'
			+'<div class="toolTipTop"></div>'
			+'<div class="toolTipMid">'
			+this.tip
			+'</div>'
			+'<div class="toolTipBtm"></div>'
		  +'</div>'
		);
		this.title = "";
		var offset = $(this).offset(); //offset of the element that summoned the tooltip
		var goes_right = offset.left+$('.toolTipWrapper').width() < $(window).width();
		var leftoffset = ( goes_right ) ? offset.left-58 : offset.left-$('.toolTipWrapper').width()+58;
		if ( goes_right ) {
			$('.toolTipTop').removeClass("right");
		} else {
			$('.toolTipTop').addClass("right");
		}
		$(this).find('.toolTipWrapper').css({left: leftoffset, top:offset.top+$(this).height()+1}).show();
	},
	function() {
		this.title = this.tip;
		$(this).find("img").alt = $(this).find("img").tmpalt;
		$(this).find('.toolTipWrapper').hide().remove();
	});
};


////////////////// EVENTOS ///////////////////////
Edesigner.beforeLoad = function() {
	this.xml_dictionary = loadXml('/la/edesigner/dictionary_es.xml');
};
Edesigner.onBodyLoad = function() {
	$(".mceEditor").each(function() {
		tinyMCE.execCommand('mceAddControl', true, this.id); 
	});
	var form_elements = document.forms[Edesigner.FORM_NAME].elements;
	for ( var i=0; i<form_elements.length; i++ ) {
		if ( form_elements[i].getAttribute("onchange") == null ) {
			form_elements[i].onchange = Edesigner.refreshPreview;
		}
	}
	this.populateSelectors();
	this.Parragraphs.loadSelect( document.getElementById("hero") );
	this.onTemplateChange(document.getElementById("product.section"));
	var auto_chkbox = document.getElementsByName("automatico")[0];
	auto_chkbox.checked = true;
	Edesigner.onAutomaticPreviewChange(auto_chkbox);
	document.getElementById("cargando").style.display = 'none';
	document.getElementById("principal").style.display = 'block';
	Edesigner.forcePreview();
	Edesigner.tooltips();
};
Edesigner.onTemplateChange = function(sself) {
	product_tabs.display(sself.options[sself.selectedIndex].value);
	if ( sself.selectedIndex > 0 ) {
		accesories_tabs.display(2);
	} else {
		accesories_tabs.display(1);
	}
	this.refreshPreview();
};
Edesigner.onFamilyChange = function( family_combo, product_being_edited ) {
	// Adaptado de Edesigner v2 (temporalmente)
	// Chequeo qué familia fue elegida
	var selected_family = family_combo.options[family_combo.selectedIndex].value;
	if ( selected_family == this.SELECT_EMPTY_VALUE ) {
		limpiarCombo( this.PRODUCT_NAME_COMBO_PREFIX+product_being_edited+this.PRODUCT_NAME_COMBO_SUFFIX, this.MENSAJE_COMBO_VACIO, this.SELECT_EMPTY_VALUE );
		deshabilitarCombo( this.PRODUCT_NAME_COMBO_PREFIX+product_being_edited+this.PRODUCT_NAME_COMBO_SUFFIX );
	} else {
		// Obtengo todos los nombres de producto de la familia y los cargo en su combo
		if ( this.xml_docs[selected_family] ) {
			var product_names = this.getProductNames( this.xml_docs[selected_family], true );
			var product_names_values = this.getProductNames( this.xml_docs[selected_family], false );
			llenarCombo( Edesigner.PRODUCT_NAME_COMBO_PREFIX+product_being_edited+Edesigner.PRODUCT_NAME_COMBO_SUFFIX, product_names, product_names_values, Edesigner.MENSAJE_COMBO_VACIO, Edesigner.SELECT_EMPTY_VALUE  );
			habilitarCombo( Edesigner.PRODUCT_NAME_COMBO_PREFIX+product_being_edited+Edesigner.PRODUCT_NAME_COMBO_SUFFIX );
		} else {
			var product_name_select = document.getElementById(this.PRODUCT_NAME_COMBO_PREFIX+product_being_edited+this.PRODUCT_NAME_COMBO_SUFFIX);
			this.SelectLoader.displayLoading( product_name_select );
			var target_url = Edesigner.XML_PATH+selected_family+".xml";
			var ajax_handler = new Ajax({
				url: target_url,
				dataType: 'xml',
				onSuccess: function(result) {
					Edesigner.xml_docs[selected_family] = result;
					var product_names = Edesigner.getProductNames( result, true );
					var product_names_values = Edesigner.getProductNames( result, false );
					llenarCombo( Edesigner.PRODUCT_NAME_COMBO_PREFIX+product_being_edited+Edesigner.PRODUCT_NAME_COMBO_SUFFIX, product_names, product_names_values, Edesigner.MENSAJE_COMBO_VACIO, Edesigner.SELECT_EMPTY_VALUE  );
					Edesigner.SelectLoader.destroyLoading( product_name_select );
				}
			});
		}
	}
	limpiarCombo( this.PRODUCT_PARTNUMBER_COMBO_PREFIX+product_being_edited+this.PRODUCT_PARTNUMBER_COMBO_SUFFIX, this.MENSAJE_COMBO_VACIO, this.SELECT_EMPTY_VALUE );
	deshabilitarCombo( this.PRODUCT_PARTNUMBER_COMBO_PREFIX+product_being_edited+this.PRODUCT_PARTNUMBER_COMBO_SUFFIX );
	this.disableOtherPN( product_being_edited )
	MCE_clearTextarea( this.PRODUCT_DESCRIPTION_COMBO_PREFIX+product_being_edited+this.PRODUCT_DESCRIPTION_COMBO_SUFFIX );
	this.refreshPreview();
};
Edesigner.onProductChange = function( selector, product_being_edited ) {
	// Chequeo qué familia fue elegida
	var family_combo = document.getElementById( this.PRODUCT_FAMILY_COMBO_PREFIX+product_being_edited+this.PRODUCT_FAMILY_COMBO_SUFFIX );
	var selected_family = family_combo.options[family_combo.selectedIndex].value;
	// Chequeo que producto fue elegido
	var product_name_combo = document.getElementById( this.PRODUCT_NAME_COMBO_PREFIX+product_being_edited+this.PRODUCT_NAME_COMBO_SUFFIX );
	var selected_product_name = product_name_combo.options[product_name_combo.selectedIndex].value;
	if ( selected_product_name == this.VALOR_COMBO_VACIO ) {
		limpiarCombo( this.PRODUCT_PARTNUMBER_COMBO_PREFIX+product_being_edited+this.PRODUCT_PARTNUMBER_COMBO_SUFFIX, this.MENSAJE_COMBO_VACIO, this.VALOR_COMBO_VACIO );
		deshabilitarCombo( this.PRODUCT_PARTNUMBER_COMBO_PREFIX+product_being_edited+this.PRODUCT_PARTNUMBER_COMBO_SUFFIX );
	} else {
		// Obtengo todos los part numbers correspondientes a ese producto y los cargo en su combo
		var part_numbers = this.getPartNumbers( this.xml_docs[selected_family], selected_product_name );
		var arreglo_part_numbers = this.retocarPartNumbers( part_numbers );
		part_numbers.push(" ");
		arreglo_part_numbers.push(this.PRODUCT_OTHERPN_TEXT);
		llenarCombo( this.PRODUCT_PARTNUMBER_COMBO_PREFIX+product_being_edited+this.PRODUCT_PARTNUMBER_COMBO_SUFFIX, arreglo_part_numbers, part_numbers, this.MENSAJE_COMBO_VACIO, this.VALOR_COMBO_VACIO  );
		habilitarCombo( this.PRODUCT_PARTNUMBER_COMBO_PREFIX+product_being_edited+this.PRODUCT_PARTNUMBER_COMBO_SUFFIX );
	}
	this.disableOtherPN( product_being_edited );
	MCE_clearTextarea( this.PRODUCT_DESCRIPTION_COMBO_PREFIX+product_being_edited+this.PRODUCT_DESCRIPTION_COMBO_SUFFIX );
	this.refreshPreview();
}
Edesigner.onPartNumberChange = function( selector, product_being_edited ) {
	// Chequeo qué familia fue elegida
	var family_combo = document.getElementById( this.PRODUCT_FAMILY_COMBO_PREFIX+product_being_edited+this.PRODUCT_FAMILY_COMBO_SUFFIX );
	var selected_family = family_combo.options[family_combo.selectedIndex].value;
	// Chequeo qué part number fue elegido
	var part_number_combo = document.getElementById( this.PRODUCT_PARTNUMBER_COMBO_PREFIX+product_being_edited+this.PRODUCT_PARTNUMBER_COMBO_SUFFIX );
	var selected_part_number = part_number_combo.options[part_number_combo.selectedIndex].value;
	// Obtengo la descripcion del producto y la cargo en el text area
	var descripcion = this.getProductDescription( this.xml_docs[selected_family], selected_part_number );
	descripcion = descripcion.replace( /<br\/>/g, '\n' );
	MCE_setTextareaContent( this.PRODUCT_DESCRIPTION_COMBO_PREFIX+product_being_edited+this.PRODUCT_DESCRIPTION_COMBO_SUFFIX, descripcion );
	if ( part_number_combo.options[part_number_combo.selectedIndex].text == this.PRODUCT_OTHERPN_TEXT ) {
		document.getElementById( this.PRODUCT_DESCRIPTION_COMBO_PREFIX+product_being_edited+this.PRODUCT_OTHERPN_COMBO_SUFFIX ).disabled = "";
	} else {
		this.disableOtherPN( product_being_edited )
	}
	this.refreshPreview();
}
Edesigner.onOtherChange = function( input, product_being_edited ) {
	var selector = document.getElementById( this.PRODUCT_PARTNUMBER_COMBO_PREFIX+product_being_edited+this.PRODUCT_PARTNUMBER_COMBO_SUFFIX );
	if ( input.value == "" || input.value == " " ) {
		selector.options[selector.options.length-1].text = this.PRODUCT_OTHERPN_TEXT;
	} else {
		selector.options[selector.options.length-1].text = input.value;
	}
	this.refreshPreview();
}