if (self.location==top.location) top.location="index.html"
var cookie_pedido = new Object();
var numero_item = 0;
var subtotal = 0;
var importe_total = 0;
var lista_articulos = new Object();
total = 0;
var unidades = 0;
var compra_minima =0;
var direccion = '';
var articulo = new Object();
var url = new Object();
var nombre = new Object();
url[0] = 'farticulos0.htm#00002'
nombre[0] = 'DESKJET 950C'
articulo[1]=''
url[1] = 'farticulos0.htm#00001'
nombre[1] = 'MP3 PD330'
articulo[2]=''
url[2] = 'farticulos0.htm#00003'
nombre[2] = 'K30'
articulo[3]=''
url[3] = 'farticulos0.htm#00004'
nombre[3] = 'PHOTOSMART 618'
articulo[4]=''
url[4] = 'farticulos0.htm#00005'
nombre[4] = 'Alta en directorio Business'
articulo[5]=''
url[5] = 'farticulos0.htm#00006'
nombre[5] = '3 cuotas mensuales en directorio Business'
articulo[6]=''
url[6] = 'farticulos0.htm#00007'
nombre[6] = 'Alta en directorio Comercio '
articulo[7]=''
url[7] = 'farticulos0.htm#00008'
nombre[7] = 'Buscar por internet '
articulo[8]=''
url[8] = 'farticulos0.htm#00009'
nombre[8] = 'Diseñar carta e-mail'
articulo[9]=''
url[9] = 'farticulos0.htm#00010'
nombre[9] = 'Paga y señal'
articulo[10]=''
url[10] = 'farticulos0.htm#00011'
nombre[10] = 'Alta en buscadores'
articulo[11]=''
url[12] = 'farticulos0.htm#00013'
nombre[12] = 'Ordenador Pentium III'
articulo[13]=''

var articulos=13;
function ventana(pagina)
{
window.open(pagina,'','width=450,height=350,location=0,status=0,directories=no,toolbar=no,resizable=yes,menubar=no,scrollbars=yes');
};
function buscar(){
var texto=prompt('Introduce el texto a buscar','');
if ((texto!='') && (texto!=null) && (texto.length >2)) {
var pantalla = parent.frames['pantalla'];
var resultcount=0;
var q;
var links='';
q=1;
for (q; q<=articulos; q=q+1)
{
if (articulo[q].toLowerCase().indexOf(texto.toLowerCase()) != -1){
resultcount += 1;
if (resultcount > eval(articulos))
{
break;
}else{
links=links + '<tr><td nowrap bgcolor=CDD8E6>';

links=links + eval(resultcount) + ')<font face="Arial" size=-2 color=663399><a href="' + url[q-1]+ '">' + nombre[q-1];
links=links + '</a></td>';
links = links + '</tr>';
continue;
   }
            }
}
pantalla.document.write('<html><head><title>Search Engine</title></head>');
pantalla.document.write('<body bgcolor=FFFFFF background="imagenes/fons.gif">');
pantalla.document.write('<p align=center><font face="Arial" size=-1 color=32269B>Resultados de la Búsqueda:');
pantalla.document.write(' ' + texto + "</p></font>");
if (links != '') {
pantalla.document.write('<table align=center cellspacing=2 cellpadding=4  width=85% border=0>');
pantalla.document.write('<tr><td bgcolor="663399" ><font face=Arial size=-2 color=FFFFFF>Nombre</font></td></tr>');
pantalla.document.write(links);
pantalla.document.write('</table>');
pantalla.document.write('<center><form><input type=button value="<< Volver" Onclick=history.go(-1) ></form></center>');
pantalla.document.write('</body></html>');
} else {
pantalla.document.write('<font face="Arial" size=-1 color=663399 >No existen artículos con esa descripción</font>');
pantalla.document.write('<form><input type=button value=Volver Onclick=history.go(-1)></form>');
pantalla.document.write('</body></html>');
};
}else{if (texto!=null){
alert('Introduzca más de dos caracteres');
buscar();
};
};
};
function inicio() {
window.top.location.href = 'index.html';
};

function corregir_decimales(total,corregir,dec){
var result=Math.floor(total)+'.';
var cents=100*(total-Math.floor(total))+0.5;
result += Math.floor(cents/10);
result += Math.floor(cents%10);
var valor="";
var pasos=0;
var x=result.length-1;
if (corregir!="no"){
while (x>=0){
    if (result.charAt(x)!="."){
        if (pasos==3){
            valor = result.charAt(x) + "," + valor;
            pasos = 0;
        }else{
             valor = (result.charAt(x)) + valor;
        };        pasos = pasos + 1;
       x = x - 1;    }else{
    pasos=0;
    valor = (result.charAt(x)) + valor
    x = x - 1;
    };};
    if (dec!='no'){
        return valor;
    }else{
        return valor.substring(0,valor.length-3);
    }
}else{
    if (dec!='no'){
        return result;
    }else{
        return result.substring(0,result.length-3);
    };
};
};
function cesta(id, opciones,cantidad) {
id = eval(id);
var cant = parseInt(cantidad);
var cant2 = cant.toString();
if ( ( cant2 != 'NaN') && (cantidad != null) && (cant2 != '0') ){
lista_articulos [numero_item] = id;
lista_articulos [numero_item+1] = cant;
lista_articulos [numero_item+2] = parent.frames['pantalla'].articulo[id][0];
lista_articulos [numero_item+3] = parent.frames['pantalla'].articulo[id][1];
lista_articulos [numero_item+4] = parent.frames['pantalla'].articulo[id][2];
lista_articulos [numero_item+5] = parent.frames['pantalla'].articulo[id][3];
lista_articulos [numero_item+6] = opciones;
numero_item = numero_item + 7;
total= eval(importe_total) + (cant* eval(parent.frames['pantalla'].articulo[id][1])); 
document.forms[0].total.value= corregir_decimales(total,'si','no');
importe_total = total
chequear_cesta();
}else{
alert('Valor no valido');
};
};

function reload_pedido(){
    numero_item=0;
    var cadena='';
    var ped= buscar_cookie('pedido');
    var id;
    var cant=0;
    if ((ped!=0) && (ped!=null) ) {
        var tam = ped.length;
        var i = 0;
        var t = 0;
        var tr=0;
        while (i < tam) {
            i = ped.indexOf('#',i);
            t = ped.indexOf('#',i+1);
            if (t!=-1) {
                if (tr<7) {
                    if (tr==0){
                        id=eval(ped.substring(i+1,t));
                        lista_articulos [numero_item] = id;
                    }
                    if (tr==1){
                        lista_articulos [numero_item+2] = ped.substring(i+1,t);
                    }
                    if (tr==2){
                        cant =  eval(ped.substring(i+1,t));
                        lista_articulos [numero_item+1] =cant;
                    }
                    if (tr==3){
                        lista_articulos [numero_item+3] = eval(ped.substring(i+1,t));
                    }
                    if (tr==4){
                        lista_articulos [numero_item+5] = eval(ped.substring(i+1,t));
                    }
                    if (tr==5){
                        lista_articulos [numero_item+4] = ped.substring(i+1,t);
                    }
                if (tr==6){
                    lista_articulos [numero_item+6] = ped.substring(i+1,t);
                    total= eval(importe_total) + eval(eval(cant)* eval(lista_articulos [numero_item+3]));
                   importe_total=total;
                    numero_item = numero_item + 7;
                    document.forms[0].total.value= corregir_decimales(total,'si','no');
                };
                tr = tr+1;
                }else{
                    tr = 0 ;
                    i--;
                };
            i++;
            }else{
                lista_articulos [numero_item+6] = ped.substring(ped.lastIndexOf('#')+1,tam);
                total= eval(importe_total) + eval(eval(cant)* eval(lista_articulos [numero_item+3]));
                importe_total=total;
                numero_item = numero_item + 7;
                document.forms[0].total.value= corregir_decimales(total,'si','no');
                break;
            }
        }
    }
};
function buscar_cookie(nombre){
var dc = document.cookie;
var prefix = nombre +'=';
var begin = dc.indexOf('; ' + prefix);
if (begin == -1) {
begin = dc.indexOf(prefix);
if (begin != 0) return null;
}else{
begin +=2};
var end = document.cookie.indexOf(';', begin);
if (end == -1){
end = dc.length;};
return unescape(dc.substring(begin + prefix.length, end));
};
function seleccion() {
if (document.forms[0].cesta.selectedIndex == 0){
chequear_cesta();
}else if (document.forms[0].cesta.selectedIndex == 1){
 vaciar_cesta();
 }else if (document.forms[0].cesta.selectedIndex == 2){
 inicio();
 } else if (document.forms[0].cesta.selectedIndex == 3){
 buscar();};
};
function mas_unidad(ref){
var i;
var total = 0;
ref = eval(ref);
lista_articulos [ref+1] = lista_articulos [ref+1] +1;
chequear_cesta();
document.forms[0].total.value= corregir_decimales(importe_total,'si','no');
};
function menos_unidad(ref){
var matriz_pedido='';
ref = eval(ref);
if (lista_articulos[ref+1]-1 >=1){
lista_articulos [ref+1] = lista_articulos [ref+1] -1;
chequear_cesta();
document.forms[0].total.value= corregir_decimales(importe_total,'si','no');
}else{
borrar_articulo(ref);
};
};
function chequear_cesta() {
var dir =parent.frames['pantalla'].location.href;
if (dir.substring(dir.lastIndexOf('/')+1, dir.length)!='cesta.htm'){
direccion = parent.frames['pantalla'].location.href;
}
var cesta = parent.frames['pantalla'];
cesta.document.write('<html><head><title>Cesta</title>');
cesta.document.write('</head>');
cesta.document.write('<body bgcolor=#FFFFFF background="imagenes/fons.gif">');
cesta.document.write('<center>');
cesta.document.write('<font face="Arial" color=663399 size=-1>');cesta.document.write('<b>Artículos seleccionados</b></font><p>');
cesta.document.write('<form>');
crear_cesta('si');
cesta.document.write('<input type=button value=Volver onClick=parent.frames["pantalla"].location.href="' + direccion.substring(direccion.lastIndexOf("/")+1, direccion.length) + '">');
if (importe_total!=0){
cesta.document.write('<input type=button value="Vaciar Cesta" onClick=parent.frames["cesta"].vaciar_cesta()>');
cesta.document.write('<input type=button value="Confirmar compra" onClick=parent.frames["cesta"].comprar()>');
};
cesta.document.write('</form></body></html>');
cesta.document.close();
};
function crear_cesta(borrado) {
var cesta = parent.frames['pantalla'];
subtotal=0;
importe_total=0;
unidades=0;
cookie_pedido = '' + '\n' ;
cesta.document.write('<table cellspacing=2 cellpadding=4  width=85% border=0>');
cesta.document.write('<tr><td bgcolor="663399" width="1%" align=center nowrap><font face="Arial" size=-2 color="FFFFFF">');
cesta.document.write('Unid.</font></td>');
cesta.document.write('<td bgcolor="663399" width="1%" nowrap><font face="Arial" size=-2 color="FFFFFF"> ');
cesta.document.write('Referencia</font></td>');
cesta.document.write('<td bgcolor="663399" align=center width="1%" nowrap><font face="Arial" size=-2 color="FFFFFF"> ');
cesta.document.write('Precio</font></td>');
cesta.document.write('<td bgcolor="663399" align=center width="1%" nowrap><font face="Arial" size=-2 color="FFFFFF">');cesta.document.write('Importe</font></td>');
cesta.document.write('<td bgcolor="663399" nowrap width="10%" align=center nowrap><font face="Arial" size=-2 color="FFFFFF">');cesta.document.write('Nombre</font></td>');
if (borrado!='no'){
cesta.document.write('<td bgcolor="663399" width="1%" align=center nowrap><font face="Arial" size=-2 color="FFFFFF">');cesta.document.write('Borrar</font></td>');
};
cesta.document.write('</tr>');
for (k=0; k<=numero_item-7; k=k+7){
if (lista_articulos[k] != -1){
cookie_pedido = cookie_pedido + '#' + lista_articulos[k] +  '#' + lista_articulos[k+2] + '' ;
cesta.document.write('<tr><td bgcolor="CDD8E6" width="1%" align=center nowrap><font face="Arial"  size=-2 color="663399" align=center>');
cesta.document.write('<input type=text name=unidades size=1 value=' + lista_articulos[k+1] + ' onfocus=blur()>');
unidades = unidades + lista_articulos[k+1]
cesta.document.write('<input type=button value=" + " onClick=parent.frames["cesta"].mas_unidad(' + k + ')>');
cesta.document.write('<input type=button value=" - " onClick=parent.frames["cesta"].menos_unidad(' + k + ')>');
cesta.document.write('</td>');
cookie_pedido = cookie_pedido + '#' + lista_articulos[k+1] + '' ;
cesta.document.write('<td bgcolor="CDD8E6" width=10><font face="Arial" size=-2 color="663399">' + lista_articulos[k+2] + '</td>');
cesta.document.write('<td bgcolor="CDD8E6" width="1%" align=right nowrap><font face="Arial" size=-2 color="663399" align=right >' + corregir_decimales(lista_articulos[k+3],'si','no')+ '&nbsp;&nbsp;&euro;</b></td>');
cookie_pedido = cookie_pedido + '#'+ corregir_decimales(lista_articulos[k+3],'no','no');
subtotal=(lista_articulos[k+1] * lista_articulos[k+3]);
cookie_pedido = cookie_pedido + '#'+ lista_articulos[k+5];;
importe_total = importe_total + subtotal;
cesta.document.write('<td bgcolor="CDD8E6" width="1%" align=right nowrap><font face="Arial" align=right size=-2 color="663399">' + corregir_decimales(subtotal,'si','no') + '&nbsp;&nbsp;&euro;</b></td>');
cesta.document.write('<td bgcolor="CDD8E6" width="1%" nowrap><font face="Arial" align=left size=-2 color="663399">' + lista_articulos[k+4] + '</b></td>');
cookie_pedido = cookie_pedido + '#'+ lista_articulos[k+4] + '' ;
cookie_pedido = cookie_pedido + '#'+ lista_articulos[k+6] + '\n' ;
if (borrado!='no'){
cesta.document.write('<td bgcolor="CDD8E6" align=center width="1%" nowrap><center><input type=button value=Borrar onClick=parent.frames["cesta"].borrar_articulo(' + k + ')></center>');
};
cesta.document.write('</tr>');
};
};
cesta.document.write('<tr><td bgcolor="663399" colspan=3><font face="Arial" size=-2 color="FFFFFF">');
cesta.document.write('Importe total</b></td>');
cesta.document.write('<td bgcolor="663399" align=right width="1%" nowrap><font face="Arial" align=right size=-2 color="FFFFFF">');
cesta.document.write(corregir_decimales(importe_total,'si','no') + '&nbsp;&nbsp;&euro;</font>');
document.cookie = 'pedido=' + escape(cookie_pedido);
document.cookie = 'total=' + escape(corregir_decimales(importe_total,'no','no'));
cesta.document.write('</td></tr></table>');
};
function borrar_articulo(id) {
var pric =id;
pric = eval(pric);
var cantidad = eval(lista_articulos[pric+1]);
var precio = eval(lista_articulos[pric+3]);
total = cantidad*precio;
document.forms[0].total.value= corregir_decimales(importe_total - total,'si','no');
lista_articulos[pric] = -1;
lista_articulos[pric+1] = '';
lista_articulos[pric+2] = '';
lista_articulos[pric+3] = '';
lista_articulos[pric+4] = '';
lista_articulos[pric+5] = '';
lista_articulos[pric+6] = '';
chequear_cesta('si');
total = eval(importe_total);
};
function vaciar_cesta() {
if(confirm('¿Esta seguro de vaciar su cesta?')){
total = 0;
document.forms[0].total.value=0;
for (i=0; i<=numero_item-7; i=i+7){
lista_articulos[i] = -1;
};};
chequear_cesta();
};
function comprar(){
window.top.location.href = 'caja.htm';
};

