String.prototype.strip_tags = function(){
tags = this;
stripped = tags.replace(/<\/?[^>]+>/gi, '');
return stripped;
}
String.prototype.trim = function(){ return this.replace(/^\s+|\s+$/g,'') }

// Devuelve el "value" de un "input" en funcion de su tipo
// NOTA:	faltan tipos por definir
function obtenerValor(formulario, campo) {
	var s
	if (input = document.forms[formulario].elements[campo]) {
		if (input.type == undefined)
			tipo = document.forms[formulario].elements[campo][0].type
		else
			tipo = input.type
		switch (tipo) {
			case "text":
			case "password":
			case "textarea":
			case "hidden":			return input.value.strip_tags().trim();
										break
			case "checkbox":		if (input.checked)
											return input.value
										break
			case "radio":			if (input.length) {
											for (s = 0; s < input.length; s++) {
												if (input[s].checked) {
													return input[s].value
												}
											}
										} else {
											if (input.checked) return input.value
										}
                                        return false;
										break
			case "select-one":	return input.options[input.selectedIndex].value
										break

			case "file": 		return input.value
										break

			default: 			return false
		}
	} else {
		return false
	}
}

// Establece (o selecciona) el valor de un "input" en funcion de su tipo
// NOTA:	faltan tipos por definir
function cambiarValor(formul, elem, valor) {
	var i
	if (input = document.forms[formul].elements[elem]) {
		if (input.type == undefined)
			tipo = document.forms[formulario].elements[campo][0].type
		else
			tipo = input.type
		switch (tipo) {
			case "text":
			case "hidden":
			case "textarea":	input.value = valor
								break
			case "checkbox":	input.checked = (input.value == valor)
								break
			case "radio":
			case "select-one":	for (i = 0; i < input.length; i++) {
									if (input.options[i].value == valor) {
										input.selectedIndex = i
									}
								}
								break
			default:			return false
		}
	} else {
		return false
	}
}

// Asigna el foco a un "input" teniendo en cuenta su tipo
// NOTA:	faltan casos por definir
function foco(formulario, campo) {
	if (input = document.forms[formulario].elements[campo]) {
		if (input.type == undefined)
			tipo = document.forms[formulario].elements[campo][0].type
		else
			tipo = input.type
		switch (tipo) {
			case "radio":	if (input[0])
									input[0].focus()
								break
			default:			input.focus()
		}
	} else {
		return false
	}
}

// Devuelve un vector con los nombre de todos los campos del formulario
function nombres_elementos(formulario) {
	var e
	var res = new Array()
	for (e = 0; e < document.forms[formulario].elements.length; e++) {
		res[res.length] = document.forms[formulario].elements[e].name
	}
	return res
}

// Elimina todas las opciones de un "select"
function vaciarSelect(sel) {
	while (sel.options.length > 0) {
		sel.options[0] = null
	}
}

// Aņade una "option" seleccionada al final de un "select"
function agnadirOpcion(sel, option) {
	sel.options[sel.options.length] = new Option(option[0], option[1])
}

// Select anidado de categorias y subcategorias de Ofertas
function cargar_subcategorias() {
  var sc = document.getElementById('sel_categoria')
  var padre = sc.options[sc.selectedIndex].value
  var ss = document.getElementById('sel_subcategoria')

  vaciarSelect(ss)
  if (subcat = eval("subcategorias_" + padre)) {
    for (i = 0; i < subcat.length; i++) {
      agnadirOpcion(ss, subcat[i])
    }
  }
}
