/* Dirección de las imágenes. Cada página actualiza este valor que será usado en la función v()*/
tmpPathImagenes = "";

/**
 * Abre una ventana popup con la url que se le pasa como parametro
 * @param url Direccion a abrir
 */
function openWindow(url) {
	var ancho = screen.availWidth * 3/4;
	var alto = screen.availHeight * 19/20;
	var leftGeneral = (screen.availWidth - ancho)/2;
	var topGeneral = (screen.availHeight - alto)/2;
	
	var x = window.open(url,"foto","width="+ancho+",height="+alto+",left="+leftGeneral+",top="+topGeneral+",menubar=0,resizable=1,scrollbars=1,toolbar=0,directories=0,status=0,alwaysRaised=yes");
}

var xOp7Up,xOp6Dn,xIE4Up,xIE4,xIE5,xNN4,xUA=navigator.userAgent.toLowerCase();
if(window.opera){
	var i=xUA.indexOf('opera');
	if(i!=-1){
		var v=parseInt(xUA.charAt(i+6));
		xOp7Up=v>=7;
		xOp6Dn=v<7;
	}
}else if(navigator.vendor!='KDE' && document.all && xUA.indexOf('msie')!=-1){
	xIE4Up=parseFloat(navigator.appVersion)>=4;
	xIE4=xUA.indexOf('msie 4')!=-1;
	xIE5=xUA.indexOf('msie 5')!=-1;
}else if(document.layers){
	xNN4=true;
}
xMac=xUA.indexOf('mac')!=-1;

function getAltoCliente(){
	var h=0;
	if(xOp6Dn) h=window.innerHeight;
	else if(document.compatMode == 'CSS1Compat' && !window.opera && document.documentElement && document.documentElement.clientHeight)h=document.documentElement.clientHeight;
	else if(document.body && document.body.clientHeight)h=document.body.clientHeight;
	else if(isDef(window.innerWidth,window.innerHeight,document.width)) {
		h=window.innerHeight;
		if(document.width>window.innerWidth) h-=16;
	}
	return h;
}
function getAnchoCliente(){
	var w=0;
	if(xOp6Dn) w=window.innerWidth;
	else if(document.compatMode == 'CSS1Compat' && !window.opera && document.documentElement && document.documentElement.clientWidth)w=document.documentElement.clientWidth;
	else if(document.body && document.body.clientWidth)w=document.body.clientWidth;
	else if(isDef(window.innerWidth,window.innerHeight,document.height)) {
		w=window.innerWidth;
		if(document.height>window.innerHeight) w-=16;
	}
	return w;
}
function isDef(){
	for(var i=0;i<arguments.length;++i){
		if(typeof(arguments[i])=='undefined') return false;
	}
	return true;
}
function getEstilo(oEle, sProp, bInt){
	var s, p = 'undefined';
	var dv = document.defaultView;
	if(dv && dv.getComputedStyle){
		s = dv.getComputedStyle(oEle,'');
		if (s) p = s.getPropertyValue(sProp);
	}else if(oEle.currentStyle) {
		var a = sProp.split('-');
		sProp = a[0];
		for (var i=1; i<a.length; ++i) {
			c = a[i].charAt(0);
			sProp += a[i].replace(c, c.toUpperCase());
		}
		p = oEle.currentStyle[sProp];
	}	else return null;
	return bInt ? (parseInt(p) || 0) : p;
}

function xGetElementById(e){
	if(typeof(e)!='string') return e;
	if(document.getElementById) e=document.getElementById(e);
	else if(document.all) e=document.all[e];
	else e=null;
	return e;
}
function getAlto(e,h){
	if(!(e=xGetElementById(e))) return 0;
	if (esNum(h)) {
		if (h<0) h = 0;
		else h=Math.round(h);
	}
	else h=-1;
	var css=isDef(e.style);
	if (e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') {
		h = getAltoCliente();
	}else if(css && isDef(e.offsetHeight) && isCadena(e.style.height)) {
		if(h>=0) {
			var pt=0,pb=0,bt=0,bb=0;
			if (document.compatMode=='CSS1Compat') {
				var gcs = getEstilo;
				pt=gcs(e,'padding-top',1);
				if (pt !== null) {
					pb=gcs(e,'padding-bottom',1);
					bt=gcs(e,'border-top-width',1);
					bb=gcs(e,'border-bottom-width',1);
				}
				else if(isDef(e.offsetHeight,e.style.height)){
					e.style.height=h+'px';
					pt=e.offsetHeight-h;
				}
			}
			h-=(pt+pb+bt+bb);
			if(isNaN(h)||h<0) return;
			else e.style.height=h+'px';
		}
		h=e.offsetHeight;
	}else if(css && isDef(e.style.pixelHeight)) {
		if(h>=0) e.style.pixelHeight=h;
		h=e.style.pixelHeight;
	}
	return h;
}

function ocultar(e){
	return getVisibilidad(e,0);
}

function meterHtml(e,h){
	if(!(e=xGetElementById(e)) || !isCadena(e.innerHTML)) return null;
	var s = e.innerHTML;
	if (isCadena(h)) {
		e.innerHTML = h;
	}
	return s;
}

function izquierda(e, iX){
	if(!(e=xGetElementById(e))) return 0;
	var css=isDef(e.style);
	if (css && isCadena(e.style.left)) {
		if(esNum(iX)) e.style.left=iX+'px';
		else {
			iX=parseInt(e.style.left);
			if(isNaN(iX)) iX=0;
		}
	}else if(css && isDef(e.style.pixelLeft)) {
		if(esNum(iX)) e.style.pixelLeft=iX;
		else iX=e.style.pixelLeft;
	}
	return iX;
}

function moverA(e,x,y){
	izquierda(e,x);
	alto(e,y);
}

function esNum(){
	for(var i=0; i<arguments.length; ++i){
		if(isNaN(arguments[i]) || typeof(arguments[i])!='number') return false;
	}
	return true;
}

function getAltoScroll(e, bWin){
	var offset=0;
	if (!isDef(e) || bWin || e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') {
		var w = window;
		if (bWin && e) w = e;
		if(w.document.documentElement && w.document.documentElement.scrollTop) offset=w.document.documentElement.scrollTop;
		else if(w.document.body && isDef(w.document.body.scrollTop)) offset=w.document.body.scrollTop;
	}else {
		e = xGetElementById(e);
		if (e && esNum(e.scrollTop)) offset = e.scrollTop;
	}
	return offset;
}

function mostrar(e) {
	return getVisibilidad(e,1);
}

function isCadena(s){
	for(var i=0; i<arguments.length; ++i){
		if(typeof(arguments[i])!='string') return false;
	}
	return true;
}

function alto(e, iY){
	if(!(e=xGetElementById(e))) return 0;
	var css=isDef(e.style);
	if(css && isCadena(e.style.top)) {
		if(esNum(iY)) e.style.top=iY+'px';
		else {
			iY=parseInt(e.style.top);
			if(isNaN(iY)) iY=0;
		}
	}
	else if(css && isDef(e.style.pixelTop)) {
		if(esNum(iY)) e.style.pixelTop=iY;
		else iY=e.style.pixelTop;
	}
	return iY;
}

function getVisibilidad(e, bShow){
	if(!(e=xGetElementById(e))) return null;
	if(e.style && isDef(e.style.visibility)) {
		if (isDef(bShow)) e.style.visibility = bShow ? 'visible' : 'hidden';
		return e.style.visibility;
	}
	return null;
}

function getAncho(e,w){
	if(!(e=xGetElementById(e))) return 0;
	if (esNum(w)) {
		if (w<0) w = 0;
		else w=Math.round(w);
	}else w=-1;
	var css=isDef(e.style);
	if (e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') {
		w = getAnchoCliente();
	}
	else if(css && isDef(e.offsetWidth) && isCadena(e.style.width)) {
		if(w>=0) {
			var pl=0,pr=0,bl=0,br=0;
			if (document.compatMode=='CSS1Compat') {
				var gcs = getEstilo;
				pl=gcs(e,'padding-left',1);
				if (pl !== null) {
					pr=gcs(e,'padding-right',1);
					bl=gcs(e,'border-left-width',1);
					br=gcs(e,'border-right-width',1);
				} else if(isDef(e.offsetWidth,e.style.width)){
					e.style.width=w+'px';
					pl=e.offsetWidth-w;
				}
			}
			w-=(pl+pr+bl+br);
			if(isNaN(w)||w<0) return;
			else e.style.width=w+'px';
		}
		w=e.offsetWidth;
	}else if(css && isDef(e.style.pixelWidth)) {
		if(w>=0) e.style.pixelWidth=w;
		w=e.style.pixelWidth;
	}
	return w;
}

function v(id,archivo,ancho,alto){
	if (ancho == undefined) {
		ancho = 245;
	}
	if (alto == undefined) {
		alto = 275;
	}
	archivo = tmpPathImagenes + archivo;
	getAncho('foto',ancho + 2+15);
	getAlto('foto',alto + 6 + 20+20 + 30);
	getAncho('c1',ancho + 6+1);
	getAlto('c1',alto+15-5);
	//getAncho('cerrarfoto',ancho - 6);
	var tabla = '<table border="0" width="100%" >';
	tabla += '<tr><td>' + '<img width="250px" src="' + archivo + '"/>' + '</td>' 
		+ '<td class="DatosCabecera"></td></tr></table>';
	tabla = '<img width="250px" src="' + archivo + '"/>';
	meterHtml('c1',tabla);
	var botonQuiero = '<input name="quiero" value="' + LIT_LoQuiero + '" onclick="javascript:comprarOficio(\'' + archivo + '\', ' + "'" + id + "'" +');" type="button">';
	//alert(botonQuiero);
	meterHtml('botonQuiero', botonQuiero);
	
	posIzq = parseInt((getAnchoCliente()-ancho+3)/2);
	if (getAltoCliente() < alto){
		posAlto = getAltoScroll() + 10;
	}else{
		posAlto = getAltoScroll() + parseInt((getAltoCliente() - alto - 20) / 2);
	}
	posIzq = posIzq + 250;
	moverA('foto',posIzq,posAlto);
	setTimeout("mostrar('foto')",50);
}
function cerrar_foto(){
	ocultar('foto');
}

function vcar(archivo,idcar,nombre,ancho,alto){
	if (ancho == undefined) {
		ancho = 245;
	}
	if (alto == undefined) {
		alto = 275;
	}
	if (archivo == "noImagen.jpg") {
		archivo = "images/" + archivo;
	} else {
		archivo = tmpPathImagenes + archivo;
	}
	getAncho('foto',ancho + 2);
	getAlto('foto',alto + 6 + 20+12);
	getAncho('c1',ancho + 6);
	getAlto('c1',alto);
	getAncho('cerrarfoto',ancho - 6);
	var tabla = getTablaCarGastos(archivo,idcar,nombre);
	meterHtml('c1',tabla);
	posIzq = parseInt((getAnchoCliente()-ancho+3)/2);
	posIzq =  20;
	if (getAltoCliente() < alto){
		posAlto = getAltoScroll() + 10;
	}else{
		posAlto = getAltoScroll() + parseInt((getAltoCliente() - alto - 20) / 2);
	}
	posAlto = posAlto - 50;
	/*posIzq = posIzq + 300;*/
	moverA('foto',posIzq,posAlto);
	setTimeout("mostrar('foto')",50);
}

function getTablaCar(archivo, idcar, idtd) {
	var numCar = 0;
	for (i = 0; i < arrayCaracteristicas.length; i++) {
		if (arrayCaracteristicas[i][CAR_id] == idcar) {
			numCar = i;
			break;
		}
	}
	var masGastos = LIT_masGastos;
	masGastos = masGastos.replace('{1}', arrayCaracteristicas[numCar][CAR_gastosEnvio] + ' ' + LIT_euro);
	var tabla = '<table border="0" width="99%" height="100%" style="background-color:#2A1B0A;" cellpadding="10">';
	var nombre = window.document.getElementById('g' + idtd).innerHTML;
	var numero = window.document.getElementById('n' + idtd).innerHTML;
	
	tabla = tabla + '<tr><td style="background-color:#F6E3CE;" align="center">' + '<img src="' + archivo + '"/>' + '</td>' 
		+ '<td>'
			+ '<table border="0" class="DatosCabeceraMasPeque">'
				+ '<tr><td colspan="2" class="DatosGrabados"><b>' + numero + '&nbsp;&nbsp;&nbsp;' + nombre + '</b></td></tr>'
				+ '<tr><td>&nbsp;</td></tr>'
				+ '<tr><td colspan="2"><B><U>'
				+ ((arrayCaracteristicas[numCar][CAR_isColor] == 'false') ? LIT_aguafuerteTinta : LIT_aguafuerteColor)
				+ '</U></B></td></tr>'
				+ '<tr><td>' + LIT_plancha + ':</td><td>' + arrayCaracteristicas[numCar][CAR_planchaAncho] + ' x ' + arrayCaracteristicas[numCar][CAR_planchaAlto] + ' ' + LIT_cm + '</td></tr>'
				+ '<tr><td>' + LIT_papel + ':</td><td>' + arrayCaracteristicas[numCar][CAR_papelAncho] + ' x ' + arrayCaracteristicas[numCar][CAR_papelAlto] + ' ' + LIT_cm + '</td></tr>'
				+ ((arrayCaracteristicas[numCar][CAR_isTiradaLimitada] == 'true') ? '<tr><td colspan="2">' + LIT_tiradaLimitada + '</td></tr>' : '')
				+ ((arrayCaracteristicas[numCar][CAR_tirada] != '0') ? '<tr><td>' + LIT_tirada + ':</td><td>' + arrayCaracteristicas[numCar][CAR_tirada] + ' ' + LIT_ejemplares + '</td></tr>' : '')
				
				+ ((arrayCaracteristicas[numCar][CAR_isPruebaAutor] == 'true') ? '<tr><td colspan="2">' + LIT_pruebaAutor + '</td></tr>' : '')
				+ ((arrayCaracteristicas[numCar][CAR_pedidoMinimo] != '0') ? '<tr><td>' + LIT_pedidoMin +  ':</td><td>' + arrayCaracteristicas[numCar][CAR_pedidoMinimo] + ' ' + LIT_ejemplares + ' (*) </td></tr>' : '')
				+ '<tr><td>' + LIT_precioEjemplar + ':</td><td>' + arrayCaracteristicas[numCar][CAR_precioEjemplar] + ' ' + LIT_euro + ' (' + ((arrayCaracteristicas[numCar][CAR_gastosEnvio] == '0') ? LIT_sinGastosEspana : masGastos) + ')' + '</td></tr>'
				+ '<tr><td><b>' + LIT_total + ':</b></td><td><b>' + arrayCaracteristicas[numCar][CAR_total] + ' ' + LIT_euro + '</b>' +  ((arrayCaracteristicas[numCar][CAR_pedidoMinimo] != '0') ? ' (**)' : '')  + '</td></tr>'
				
				+ '<tr><td>&nbsp;</td></tr><tr><td>&nbsp;</td></tr><tr><td colspan="2" class="DatosLeyenda">' + LIT_ofertavariospedidos + '</td></tr>'
				+ ((arrayCaracteristicas[numCar][CAR_pedidoMinimo] != '0') ? '<tr><td colspan="2" class="DatosLeyenda">' + LIT_variosEjemplares + '</td></tr>' : '')
				+ ((arrayCaracteristicas[numCar][CAR_pedidoMinimo] != '0') ? '<tr><td colspan="2" class="DatosLeyenda">' + LIT_totalVarios + '</td></tr>' : '')
			+ '</table>'
		+ '</td></tr>'
		+ '</table>';
	return tabla;
}

function getTablaCarGastos(archivo, idcar, idtd) {
	var numCar = 0;
	for (i = 0; i < arrayCaracteristicas.length; i++) {
		if (arrayCaracteristicas[i][CAR_id] == idcar) {
			numCar = i;
			break;
		}
	}
	var masGastos = LIT_masGastos;
	masGastos = masGastos.replace('{1}', arrayCaracteristicas[numCar][CAR_gastosEnvio] + ' ' + LIT_euro);
	var tabla = '<table border="0" width="99%" height="100%" style="background-color:#2A1B0A;" cellpadding="10">';
	var nombre = window.document.getElementById('g' + idtd).innerHTML;
	var numero = window.document.getElementById('n' + idtd).innerHTML;
	
	tabla = tabla + '<tr><td style="background-color:#F6E3CE;" align="center">' + '<img src="' + archivo + '"/>' + '</td>' 
		+ '<td>'
			+ '<table border="0" class="DatosCabeceraMasPeque">'
				+ '<tr><td colspan="3" class="DatosGrabados" align="center"><b><u>' + numero + '&nbsp;-&nbsp;' + nombre + '</u></b></td></tr>'
				+ '<tr><td colspan="3">&nbsp;</td></tr>'
				+ '<tr><td colspan="3"><B><U>'
					+ ((arrayCaracteristicas[numCar][CAR_isColor] == 'false') ? LIT_aguafuerteTinta : LIT_aguafuerteColor)
					+ '</U></B></td></tr>'
				+ '<tr><td>' + LIT_plancha + ':</td><td colspan="2" width="70%">' + arrayCaracteristicas[numCar][CAR_planchaAncho] + ' x ' + arrayCaracteristicas[numCar][CAR_planchaAlto] + ' ' + LIT_cm + '</td></tr>'
				+ '<tr><td>' + LIT_papel + ':</td><td colspan="2">' + arrayCaracteristicas[numCar][CAR_papelAncho] + ' x ' + arrayCaracteristicas[numCar][CAR_papelAlto] + ' ' + LIT_cm + '</td></tr>'
				+ ((arrayCaracteristicas[numCar][CAR_isTiradaLimitada] == 'true') ? '<tr><td colspan="3">' + LIT_tiradaLimitada + '</td></tr>' : '')
				+ ((arrayCaracteristicas[numCar][CAR_tirada] != '0') ? '<tr><td>' + LIT_tirada + ':</td><td colspan="2">' + arrayCaracteristicas[numCar][CAR_tirada] + ' ' + LIT_ejemplares + '</td></tr>' : '')
				
				+ ((arrayCaracteristicas[numCar][CAR_isPruebaAutor] == 'true') ? '<tr><td colspan="3">' + LIT_pruebaAutor + '</td></tr>' : '')
				+ '<tr><td nowrap="nowrap"><b>' + LIT_precioEjemplar + ':</b></td><td colspan="2"><b>' + arrayCaracteristicas[numCar][CAR_precioEjemplar] + ' ' + LIT_euro + '</b></td></tr>'
				
				+ '<tr><td colspan="3">' + getTablaGastos() + '</td></tr>'
			+ '</table>'
		+ '</td></tr>'
		+ '</table>';
	return tabla;
}

function getTablaGastos(esModoPopup) {

	if (esModoPopup != undefined && esModoPopup == true) {
		tmpLIT_enviosGastos = opener.LIT_enviosGastos;
		tmpLIT_enviosEspana = opener.LIT_enviosEspana;
		tmpGastoEspana = opener.gastoEspana;
		tmpLIT_enviosEuropa = opener.LIT_enviosEuropa;
		tmpGastoEuropa = opener.gastoEuropa;
		tmpLIT_enviosResto = opener.LIT_enviosResto;
		tmpGastoResto = opener.gastoResto;
	} else {
		tmpLIT_enviosGastos = LIT_enviosGastos;
		tmpLIT_enviosEspana = LIT_enviosEspana;
		tmpGastoEspana = gastoEspana;
		tmpLIT_enviosEuropa = LIT_enviosEuropa;
		tmpGastoEuropa = gastoEuropa;
		tmpLIT_enviosResto = LIT_enviosResto;
		tmpGastoResto = gastoResto;
	}
	var tablaGastos = '<table border="0" class="TablaGastos">';
	tablaGastos = tablaGastos
		+ '<tr>'
			+ '<td class="TablaGastosTitulo" colspan="2">'+tmpLIT_enviosGastos+'<\/td>'
		+ '<\/tr>'
		+ '<tr>'
			+ '<td class="TablaGastosHorizontal">'+tmpLIT_enviosEspana+'<\/td>'
			+ '<td class="TablaGastosVertical">'+tmpGastoEspana+' &#8364;<\/td>'
		+ '<\/tr>'
		+ '<tr>'
			+ '<td class="TablaGastosHorizontal">'+tmpLIT_enviosEuropa+'<\/td>'
			+ '<td class="TablaGastosVertical">'+tmpGastoEuropa+' &#8364;<\/td>'
		+ '<\/tr>'
		+ '<tr>'
			+ '<td class="TablaGastosHorizontal">'+tmpLIT_enviosResto+'<\/td>'
			+ '<td class="TablaGastosVertical">'+tmpGastoResto+' &#8364;<\/td>'
		+ '<\/tr>'
		+ '<\/table>';
	return tablaGastos;
}

function getTablaGastosOficios() {
	var tablaGastos = '<table border="1" class="TablaGastos">';
	tablaGastos = tablaGastos
		+ '<tr>'
			+ '<td class="TablaGastosVertical" colspan="2">'+LIT_enviosGastos+'<\/td>'
		+ '<\/tr>'
		+ '<tr>'
			+ '<td class="TablaGastosHorizontal">'+LIT_enviosEspana+'<\/td>'
			+ '<td class="TablaGastosVertical">'+gastoOficio+' &#8364;<\/td>'
		+ '<\/tr>'
		+ '<tr>'
			+ '<td class="TablaGastosHorizontal">'+LIT_enviosResto+'<\/td>'
			+ '<td class="TablaGastosVertical">'+gastoRestoOficio+' &#8364;<\/td>'
		+ '<\/tr>'
		+ '<\/table>';
	return tablaGastos;
}


function paginarPopup(bSiguiente) {
	/*alert('ID_CAR=' + ID_CAR + ', ID_TD=' + ID_TD);*/
	var next = parseInt(ID_TD);
	var url = '';
	if (bSiguiente == true) {
		if (bIsOtraCarac == false && opener.document.getElementById('b'+next) != undefined) {
			url = new String(opener.document.getElementById('b'+next));
			bIsOtraCarac = true;
		} else {
			next = next + 1;
			if (next < 0) {
				next = opener.iNumGrabados - 1;
			}
			if (next > opener.iNumGrabados - 1) {
				next = 0;
			}
			url = new String(opener.document.getElementById('a'+next));
			bIsOtraCarac = false;
		}
	} else {
		if (bIsOtraCarac == true) {
			url = new String(opener.document.getElementById('a'+next));
			bIsOtraCarac = false;
		} else {
			next = next - 1;
			if (next < 0) {
				next = opener.iNumGrabados - 1;
			}
			if (next > opener.iNumGrabados - 1) {
				next = 0;
			}
			if (opener.document.getElementById('b'+next) != undefined) {
				url = new String(opener.document.getElementById('b'+next));
				bIsOtraCarac = true;
			} else {
				url = new String(opener.document.getElementById('a'+next));
				bIsOtraCarac = false;
			}
		}
	}
	if (opener.document.getElementById('a'+next) != undefined) {
		url = url.split('\'');
		url = new String(url[1]);
		var param = url.split('?');
		param = new String(param[1]);
		param = param.split('&');
		var nombreFoto = new String(param[0]);
		ID_CAR = new String(param[1]);
		ID_TD = new String(param[2]);
		/*alert('nombreFoto='+nombreFoto+', ID_CAR=' + ID_CAR + ', ID_TD=' + ID_TD);*/
		meterHtml('tablita',getTablaCarGastos(nombreFoto, ID_CAR, ID_TD,opener.P_ANCHO,opener.P_ALTO));
	}
}

// Hace el enlace mailto: con javascript para que los robots de spam no capturen la dirección
function antispam(user, dominio) 
{
	window.location = "mailto:" + user + "@" + dominio;
}
function showEmail(usuario, dominio)
{
	var obj = document.getElementById('email');
	if (obj && obj.innerHTML)
		obj.innerHTML = 'email: ' + usuario + '@' + dominio;
}
function comprar(ID,g,c,i) { 
	var pag;
	var nom = window.document.getElementById('g' + i).innerHTML;
	pag="meteGrabado.php?id=" + ID + "&g=" + g + "&c=" + c + "&nom=" + nom + "&foto=";
//	alert("pag=" + pag);
	ventana_comprar=window.open(pag,'COMPRAR','toolbar= 0,location= 0,directories= 0,status= 0,menubar= 0,scrollbars= 0,resizable= 0,copyhistory= 0,width=380,height=90'); 
}
function actGasto(gasto) {
	try {
		var tdsuma = document.getElementById('suma');
		var tdgastos = document.getElementById('gastoenvio');
		var ocu_suma = document.getElementById('ocu_suma').value;
		//alert('tdsuma=' + tdsuma + 'ocu_suma=' + ocu_suma + ', gasto=' + gasto);
		var total = parseInt(ocu_suma);
		var gastosEnvio = gastoEspana;
		if (gasto == 'es') {
			gastosEnvio = gastoEspana;
		} else if (gasto == 'eu') {
			gastosEnvio = gastoEuropa;
		} else {
			gastosEnvio = gastoResto;
		}
		total = total + gastosEnvio;
		//alert('total=' + total);
		document.getElementById('ocu_sumayenvio').value = total;
		tdsuma.innerHTML = '<b>' + total + ' &euro;</b>';
		tdgastos.innerHTML = '<b>' + gastosEnvio + ' &euro;</b>';
	} catch (e) {}
}

function trim(texto) {
	str = "";
	if (texto != undefined && texto.length > 0) {
		str = texto.replace(/^\s*|\s*$/g,"");
	}
	return str;
}
function validaPedido(form) {
	invalido = true;
	mensaje = LIT_camposVacios;
	invalido = (trim(form.nombre.value).length == 0) 
		//|| (trim(form.direccion.value).length == 0)
		//|| (trim(form.cp.value).length == 0)
		//|| (trim(form.poblacion.value).length == 0)
		//|| (trim(form.provincia.value).length == 0)
		//|| (trim(form.pais.value).length == 0)
		|| (trim(form.email.value).length == 0)
		;
	var b=/^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/;
	if (b.test(trim(form.email.value)) == false) {
		invalido = true;
		mensaje = LIT_emailFormato;
	}
	if (invalido) {
		alert(mensaje);
	}
	return !invalido;
}

function comprarOficio(foto, id) {
	var pag;
	var nom = trim(window.document.getElementById('g' + id).innerHTML);
	//alert('id=' + id + ', oficio=' + foto + ', nom=' + nom);
	pag="meteGrabado.php?id=" + id + "&g=12&c=false&nom=" + nom + "&foto=" + foto;
	//alert("pag=" + pag);
	ventana_comprar=window.open(pag,'COMPRAR','toolbar= 0,location= 0,directories= 0,status= 0,menubar= 0,scrollbars= 0,resizable= 0,copyhistory= 0,width=380,height=90');
	
}
