

window.onload=function() {
	/* Sustituimos los botones submit por imágenes. Hack para explorer 6 / 7
	 * que no aceptan botones de tipo type=image
	 */
	sustituirSubmitPorImagen('boton_comprar','/images/btn_comprar.jpg');
	sustituirSubmitPorImagen('boton_calcularprecio_arriba','/images/btn_calcularprecio.jpg'); 	
	sustituirSubmitPorImagen('boton_calcularprecio_abajo','/images/btn_calcularprecio.jpg');

	
	var formid = 'clienteditform'
	document.getElementById('boton_comprar').parentNode.onclick = function () {
		var action   = getActionHiddenField(formid)
		action.name  ='buy'
		action.value = 'comprar'
		document.getElementById(formid).submit()
	}
	document.getElementById('boton_calcularprecio_arriba').parentNode.onclick = function () {
		var action   = getActionHiddenField(formid)
		action.name  = 'calcular_precio'
		action.value = 1
		document.getElementById(formid).submit()
	}
	document.getElementById('boton_calcularprecio_abajo').parentNode.onclick = function () {
		var action   = getActionHiddenField(formid);
		action.name  ='calcular_precio'
		action.value = 1
		document.getElementById(formid).submit();
	}}

function sustituirSubmitPorImagen(id, src) {
	var boton = document.getElementById(id)
	
	var img   = document.createElement('img')
	img.src   = src
	img.id    = boton.id
	img.style.cursor = 'pointer' 
	img.setAttribute('class', 'btnanyadir') 
	boton.parentNode.replaceChild(img,boton)
}

function getActionHiddenField(formid) {
	var action = null
	if (!document.getElementById('form_action')) {
		action = document.createElement('input')
		action.id='form_action'
		action.type = 'hidden'
		document.getElementById(formid).appendChild(action)
	} else {
		action = document.getElementById('form_action')	
	}
	
	return action
}

