if (self.location==top.location) top.location="home.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 = '';
function ventana(pagina)
{
window.open(pagina,'','width=550,height=450,location=0,status=0,directories=no,toolbar=no,resizable=yes,menubar=no,scrollbars=yes');
};
function buscar(){
window.top['pantalla'].location.href = 'buscador.htm';
};
function inicio() {
window.top.location.href = 'home.html';
};

function pone_miles(num) {
    var re = /(-?\d+)(\d{3})/
    while (re.test(num)) {
        num = num.replace(re,"$1.$2")
}
    return(num);
}
function corregir_decimales(n, d)
{  d = (d>10?10:d);
   d = (d<0?0:d);
   var r = "" + Math.round(n * Math.pow(10,d));
   return (d==0?r:r.substring(0,r.length-d)+"."+r.substring(r.length-d,r.length));
}
function formato_numeros(valor,decimales)
{
    var numero=corregir_decimales(valor,decimales);
if (numero.charAt(0)=='.')
{
        numero = "0" + numero;
}
if (decimales!=0) {
    var pos= numero.indexOf('.',0);
    if (pos!=0)
    {
        var entero=numero.substring(0,pos);
        return(pone_miles(entero)+ ',' + numero.substring(pos+1,numero.length));
    }
}else{
        return(pone_miles(numero.toString()));
}
}
function comprueba_cesta(id,opciones,cantidad,formulario,subtotal){
var encontrado;
var i;
    var docu = "parent.frames['pantalla']";
    var cant = parseInt(cantidad);
    encontrado=false;
    for (i=0;i<numero_item;i++)
    {
        if (lista_articulos[i+2]==eval(docu + "." + formulario + "[0]") && (lista_articulos[i+6]==opciones) && (lista_articulos[i]!="-1"))
        {
            //Se encuentra en la cesta, hay que añadirlo en la misma línea
            lista_articulos [i+1] = lista_articulos [i+1] + cant;
            lista_articulos [i+7] = subtotal;
            total= eval(importe_total) + Math.round(cant* subtotal* ((eval(docu + "." + formulario + "[4]")/100)+1));
            document.forms[0].total.value= formato_numeros(total,0);
            parent.frames.menu.document.forms[0].total.value= formato_numeros(total,0);
            importe_total = total
            window.top['pantalla'].location.href = 'carrito.htm';
            encontrado=true;
        }
    }
    if (encontrado==false)
    {
        return(false);
    }
    else
    {
        return(true);
    }
};
function cesta(id, opciones,cantidad,formulario,subtotal) {
id = eval(id);
var cant = parseInt(cantidad);
var cant2 = cant.toString();
if ( ( cant2 != 'NaN') && (cantidad != null) && (cant2 != '0') ){
var docu = "parent.frames['pantalla']";
if (comprueba_cesta(id,opciones,cantidad,formulario,subtotal)==false)
{
lista_articulos [numero_item] = id;
lista_articulos [numero_item+1] = cant;
lista_articulos [numero_item+2] = eval(docu + "." + formulario + "[0]");
lista_articulos [numero_item+3] = eval(docu + "." + formulario + "[1]");
lista_articulos [numero_item+4] = eval(docu + "." + formulario + "[2]");
lista_articulos [numero_item+5] = eval(docu + "." + formulario + "[3]");
lista_articulos [numero_item+6] = opciones;
lista_articulos [numero_item+7] = subtotal;
lista_articulos [numero_item+8] = eval(docu + "." + formulario + "[4]");
numero_item = numero_item + 9;
total= eval(importe_total) + (cant* subtotal* ((eval(docu + "." + formulario + "[4]") /100)+1)); 
document.forms[0].total.value= formato_numeros(total,2);
parent.frames.menu.document.forms[0].total.value= formato_numeros(total,2);
importe_total = total
window.top['pantalla'].location.href = 'carrito.htm';
}
}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<9) {
                    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);
                   }
                    if (tr==7)
                    {
                        lista_articulos [numero_item+7] = ped.substring(i+1,t);
                    }
                    if (tr==8)
                    {
                        lista_articulos [numero_item+8] = ped.substring(i+1,t);
                        total= eval(importe_total) + eval(eval(cant)* eval(lista_articulos [numero_item+7] * ((lista_articulos[8]/100)+1) ));
                        importe_total=total;
                        numero_item = numero_item + 9;
                        document.forms[0].total.value= formato_numeros(total,2);
                        parent.frames.menu.document.forms[0].total.value= formato_numeros(total,2);
                };
                tr = tr+1;
                }else{
                    tr = 0 ;
                    i--;
                };
            i++;
            }else{
                lista_articulos [numero_item+8] = ped.substring(ped.lastIndexOf('#')+1,tam);
                total= eval(importe_total) + eval(eval(cant)* eval(lista_articulos [numero_item+7] * ((lista_articulos[8]/100)+1) ));
                importe_total=total;
                numero_item = numero_item + 9;
                document.forms[0].total.value= formato_numeros(total,2);
while (parent.frames['menu'].cargado!=1) {
                parent.frames.menu.document.forms[0].total.value= formato_numeros(total,2);
                return false;
}
                break;
            }
        }
    }
loaded_it_yet = 1;
};
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 mas_unidad(ref){
var i;
var total = 0;
ref = eval(ref);
lista_articulos [ref+1] = lista_articulos [ref+1] +1;
window.top['pantalla'].location.href = 'carrito.htm';
};
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;
window.top['pantalla'].location.href = 'carrito.htm';
}else{
borrar_articulo(ref);
};
};
function chequear_cesta() {
window.top['pantalla'].location.href = 'carrito.htm';
document.forms[0].total.value= formato_numeros(total,2);
parent.frames.menu.document.forms[0].total.value= formato_numeros(total,2);
};
function botones()
{
var cesta = parent.frames['pantalla'];
if (importe_total!=0){
cesta.document.write(' ');
cesta.document.write('            </FONT></STRONG></TD></TR>');
cesta.document.write('        <TR>');
cesta.document.write('          <TD background="" bgColor=#1086ef colSpan=6><FONT face=Verdana ');
cesta.document.write('            color=#ffffff size=2><STRONG>Importe total</STRONG> </FONT></TD>');
cesta.document.write('          <TD noWrap align=right width="1%" bgColor=#1086ef><FONT face=Verdana ');
cesta.document.write('            color=#ffffff size=2><STRONG>' + formato_numeros(importe_total,2) + '</STRONG> ');
cesta.document.write('            <STRONG>€</STRONG> </FONT></TD></TR></TBODY></TABLE>');
cesta.document.write('      <P align=center><INPUT  type=button value=Volver name=volver onClick=parent.frames["pantalla"].location.href="javascript:history.go(-1)"> <INPUT  type=button value="Vaciar Carrito" name=vaciar onClick=parent.frames["cesta"].vaciar_cesta()> <INPUT  type=button value="Confirmar compra" name=comprar onClick=parent.frames["cesta"].comprar()> ');
cesta.document.write('      </P></TD></TR></TBODY></TABLE>');
cesta.document.write('<P>&nbsp;</P>');
cesta.document.write('<P align=center><A href="http://www.isotest.es/tienda/descuentos.htm"><FONT ');
cesta.document.write('color=#0000ff>Conozca nuestros descuentos por ');
cesta.document.write('cantidades</FONT></A></P>');
cesta.document.write(' </BODY>');
cesta.document.write('</html>');
}
else{
cesta.document.write(' ');
cesta.document.write('            </FONT></STRONG></TD></TR>');
cesta.document.write('        <TR>');
cesta.document.write('          <TD background="" bgColor=#1086ef colSpan=6><FONT face=Verdana ');
cesta.document.write('            color=#ffffff size=2><STRONG>Importe total</STRONG> </FONT></TD>');
cesta.document.write('          <TD noWrap align=right width="1%" bgColor=#1086ef><FONT face=Verdana ');
cesta.document.write('            color=#ffffff size=2><STRONG>' + formato_numeros(importe_total,2) + '</STRONG> ');
cesta.document.write('            <STRONG>€</STRONG> </FONT></TD></TR></TBODY></TABLE>');
cesta.document.write('      <P align=center><INPUT  type=button value=Volver name=volver onClick=parent.frames["pantalla"].location.href="javascript:history.go(-1)">   ');
cesta.document.write('      </P></TD></TR></TBODY></TABLE>');
cesta.document.write('<P>&nbsp;</P>');
cesta.document.write('<P align=center><A href="http://www.isotest.es/tienda/descuentos.htm"><FONT ');
cesta.document.write('color=#0000ff>Conozca nuestros descuentos por ');
cesta.document.write('cantidades</FONT></A></P>');
cesta.document.write(' </BODY>');
cesta.document.write('</html>');
};
cesta.document.close();
};
function crear_cesta(borrado) {
var cesta = parent.frames['pantalla'];
subtotal=0;
importe_total=0;
unidades=0;
cookie_pedido = '' + '\n' ;
if (numero_item==0)
{
cesta.document.write('La cesta no contiene artículos');
}
for (k=0; k<=numero_item-9; k=k+9){
if (lista_articulos[k] != -1){
cookie_pedido = cookie_pedido + '#' + lista_articulos[k] +  '#' + lista_articulos[k+2] + '' ;
unidades = unidades + lista_articulos[k+1]
cookie_pedido = cookie_pedido + '#' + lista_articulos[k+1] + '' ;
cookie_pedido = cookie_pedido + '#'+ lista_articulos[k+3];
subtotal=(lista_articulos[k+1] * lista_articulos[k+7]) + ((lista_articulos[k+1] * lista_articulos[k+7] * lista_articulos[k+8])/100);
cookie_pedido = cookie_pedido + '#'+ lista_articulos[k+5];
importe_total = importe_total + subtotal;
cookie_pedido = cookie_pedido + '#'+ lista_articulos[k+4] + '' ;
cookie_pedido = cookie_pedido + '#'+ lista_articulos[k+6] + '' ;
cookie_pedido = cookie_pedido + '#'+ lista_articulos[k+7] + '' ;
cookie_pedido = cookie_pedido + '#'+ lista_articulos[k+8] + '\n' ;
cesta.document.write('</TD></TR>');
cesta.document.write('        <TR>');
cesta.document.write('          <TD noWrap align=middle width="1%" background=""><input type=text name=unidades size=1 value=' + lista_articulos[k+1] + ' onfocus=blur()> <INPUT  type=button value=" + " name=mas onClick=parent.frames["cesta"].mas_unidad(' + k + ')> <INPUT  type=button value=" - " name=menos onClick=parent.frames["cesta"].menos_unidad(' + k + ')></TD>');
cesta.document.write('          <TD width=10 background=""><FONT face=Verdana color=#000000 ');
cesta.document.write('            size=2>' + lista_articulos[k+2] + '</FONT></TD>');
cesta.document.write('          <TD noWrap align=right width="1%" background=""><FONT ');
cesta.document.write('            color=#000000>' + lista_articulos[k+6] + '</FONT></TD>');
cesta.document.write('          <TD noWrap align=right width="1%" background=""><FONT face=Verdana ');
cesta.document.write('            color=#000000 size=2><FONT face="Times New Roman" ');
cesta.document.write('            size=3>' + formato_numeros(lista_articulos[k+3],2) + '</FONT>&nbsp; </FONT></TD>');
cesta.document.write('          <TD noWrap align=right width="1%" background=""><FONT face=Verdana ');
cesta.document.write('            color=#000000 size=2>' + formato_numeros(lista_articulos[k+7]*lista_articulos[k+1],2) + '</FONT></TD>');
cesta.document.write('          <TD noWrap align=right width="1%" background=""><FONT face=Verdana ');
cesta.document.write('            color=#000000 size=2>' + formato_numeros(subtotal,2) + ' €</FONT></TD>');
cesta.document.write('          <TD noWrap align=middle width="1%" background="">');
cesta.document.write('            <CENTER><STRONG><INPUT  type=button value=Borrar name=borrar onClick=parent.frames["cesta"].borrar_articulo(' + k + ')> ');
cesta.document.write('            </STRONG></CENTER></TD></TR>');
cesta.document.write('        <TR>');
cesta.document.write('          <TD colSpan=9><STRONG><FONT color=#6f6f00 size=1>');
};
};
document.cookie = 'pedido=' + escape(cookie_pedido);
document.cookie = 'total=' + escape(importe_total);
document.forms[0].total.value = formato_numeros(importe_total,2);
parent.frames.menu.document.forms[0].total.value = formato_numeros(importe_total,2);
};
function borrar_articulo(id) {
var pric =id;
pric = eval(pric);
var cantidad = eval(lista_articulos[pric+1]);
var precio = eval(lista_articulos[pric+7]);
total = cantidad*precio*((lista_articulos[pric+8]/100)+1);
document.forms[0].total.value= formato_numeros(importe_total - total,2);
parent.frames.menu.document.forms[0].total.value= formato_numeros(importe_total - total,2);
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] = '';
lista_articulos[pric+7] = '';
lista_articulos[pric+8] = '';
window.top['pantalla'].location.href = 'carrito.htm';total = eval(importe_total);
};
function vaciar_cesta() {
if(confirm('¿Esta seguro de vaciar su cesta?')){
total = 0;
document.forms[0].total.value=0;
parent.frames.menu.document.forms[0].total.value=0;
for (i=0; i<=numero_item-9; i=i+9){
lista_articulos[i] = -1;
numero_item=0;
};};
chequear_cesta();
};
function comprar(){
window.top.location.href = 'caja.htm';
};

