
function fscroll(){
//alert(document.body.clientHeight+'  '+document.html.offsetHeight);
//mago.style.top=document.body.clientHeight + document.body.scrollTop - (mago.offsetHeight+20);
//mago.style.left=document.body.clientWidth + document.body.scrollLeft - (mago.offsetWidth+20);

}

function fload(){
//alert('111');
//mt=mago.offsetTop;
//ml=mago.offsetLeft;
//mago.style.left=ml;
//mago.style.top=mt;
//mago.onmousedown=fmd;
//mago.onmouseup=fmu;
//mago.onmousemove=fmm;
//mago.onmouseover=fmo;
//mago.style.display='none';
}

function hb(){
mago.style.visibility='hidden';
//mago.style.display='none';
}

function getCook(name){
 cookie = document.cookie;
 var cname = name+'=';
 var from  = cookie.indexOf(cname);
 if ( from != -1 ) {
    from += cname.length;
    to    = cookie.indexOf( ';', from );
    if ( to == -1 ) to = cookie.length;
    return unescape( cookie.substring(from, to) );
 }
 return null;
}

function delCook(name,path,domain){
   expires = new Date();
   expires.setTime(0);
 document.cookie=name+"='';expires="+expires.toGMTString()+";path="+path+";domain="+domain+";";
}

function unl(){delCook('zakaz','/',document.domain);}

onload=fload;
onscroll=fscroll;

tzk=document.getElementById('baskettable');
smz=document.getElementById('sm');
mago=document.getElementById('basket');
f1=document.getElementById('f11');
var summ=0;
var str_zak=getCook('zakaz');

if (str_zak){
ars=str_zak.split('&');
 for(i=0;i<ars.length-1;i++){
   arz=ars[i].split('#');
nrzk=tzk.insertRow(tzk.rows.length-1);
nrzk.className='tableline';
nrzk.vAlign='middle';
nrzk.sss=arz[3];
col1=nrzk.insertCell(0);
col2=nrzk.insertCell(1);
col3=nrzk.insertCell(2);
col1.innerHTML=arz[2];
tl=arz[2].split('<');
col1.titl=tl[0];
inp=document.createElement('INPUT');
inp.type='text';inp.name=arz[0];inp.size=2;inp.maxlength=2;
inp.align='right';inp.onchange=ch;inp.onkeyup=ch;inp.onblur=bl;inp.value=arz[1];
col2.appendChild(inp);

but=document.createElement('IMG');
but.name='delz';but.width=13;but.height=13;but.onclick=dlz;but.src='img/rem.gif';
but.title='Удалить эту позицию';
col3.appendChild(but);
col3.align='center';
 }
summ=0;
 for (i=1;i<tzk.rows.length-1;i++){summ+=parseInt(tzk.rows[i].sss)*parseInt(tzk.rows[i].cells[1].childNodes[0].value); }
smz.innerHTML=Math.floor(summ.toString()/100);
mago.style.visibility='';
}
else{hb();}

function dlz(){
tzk.deleteRow(this.parentNode.parentNode.rowIndex)
mago.style.visibility='hidden';
setDate();
summ=0;
 for (i=1;i<tzk.rows.length-1;i++){ summ+=parseInt(tzk.rows[i].sss)*parseInt(tzk.rows[i].cells[1].childNodes[0].value); }
kop=Math.round(((summ.toString()/100)-Math.floor(summ.toString()/100))*100);
smz.innerHTML=Math.floor(summ.toString()/100)+'-'+kop.toString();
if (tzk.rows.length>2){mago.style.visibility='';}
}

function ch(){
if (isNaN(this.value)){alert('Вы неправильно указали количество');this.value=1;}
setDate();
summ=0;
 for (i=1;i<tzk.rows.length-1;i++){ summ+=parseInt(tzk.rows[i].sss)*parseInt(tzk.rows[i].cells[1].childNodes[0].value); }
kop=Math.round(((summ.toString()/100)-Math.floor(summ.toString()/100))*100);
smz.innerHTML=Math.floor(summ.toString()/100)+'-'+kop.toString();
}

function bl(){
if (isNaN(this.value)||(this.value=='')){alert('Вы неправильно указали количество');this.value=1;}
setDate();
summ=0;
 for (i=1;i<tzk.rows.length-1;i++){ summ+=parseInt(tzk.rows[i].sss)*parseInt(tzk.rows[i].cells[1].childNodes[0].value); }
kop=Math.round(((summ.toString()/100)-Math.floor(summ.toString()/100))*100);
smz.innerHTML=Math.floor(summ.toString()/100)+'-'+kop.toString();
}

function zk(el){
titl=document.getElementById('tit').innerHTML;
avtr=document.getElementById('avt').firstChild.innerHTML;
ars=document.getElementById('pri').innerHTML.split(' ');
 for (i=1;i<tzk.rows.length-1;i++){
 if (tzk.rows[i].cells[0].titl==titl){
    tzk.rows[i].cells[1].childNodes[0].value++; 
setDate();
    summ=0;
    for (i=1;i<tzk.rows.length-1;i++){ summ+=parseInt(tzk.rows[i].sss)*parseInt(tzk.rows[i].cells[1].childNodes[0].value); }
kop=Math.round(((summ.toString()/100)-Math.floor(summ.toString()/100))*100);
smz.innerHTML=Math.floor(summ.toString()/100)+'-'+kop.toString();
//mago.style.display='';
mago.style.visibility='';
    return;
 } 
}
nrzk=tzk.insertRow(tzk.rows.length-1);
nrzk.className='tableline';
nrzk.vAlign='middle';
ars=ars[0].split('.');
nrzk.sss=parseInt(Math.round(ars[0].valueOf()*100))+parseInt(Math.round(ars[1].valueOf()));
col1=nrzk.insertCell(0);
col2=nrzk.insertCell(1);
col3=nrzk.insertCell(2);
col1.innerHTML=titl+'<br><i> '+avtr+' </i><br><b> ' +ars[0]+'-'+ars[1]+' руб.</b>';
col1.titl=titl;

ara=titl.split('.');
art=ara[0].split(' ',3);
ara=avtr.split(',');
ara=ara[0].split(' ');
var idk='';
for (i=0;i<art.length;i++){ idk=idk+art[i]+ '_';  }
idk=idk+ara[1];

inp=document.createElement('INPUT');
inp.type='text';inp.name=idk;inp.size=2;inp.maxlength=2;
inp.align='right';inp.onchange=ch;inp.onkeyup=ch;inp.onblur=bl;inp.value='1';
col2.appendChild(inp);

but=document.createElement('IMG');
but.name='delz';but.width=13;but.height=13;but.onclick=dlz;but.src='img/rem.gif';
but.title='Удалить эту позицию';
col3.appendChild(but);
col3.align='center';

setDate();

summ=0;
 for (i=1;i<tzk.rows.length-1;i++){ summ+=parseInt(tzk.rows[i].sss)*parseInt(tzk.rows[i].cells[1].childNodes[0].value); }
kop=Math.round(((summ.toString()/100)-Math.floor(summ.toString()/100))*100);
smz.innerHTML=Math.floor(summ.toString()/100)+'-'+kop.toString();
//mago.style.display='';
mago.style.visibility='';
}


function subm(){
if(f1.elements.length<1){alert('Ваша корзина пуста');}
//else if (summ/100<300){alert('Минимальная сумма заказа: 300.00 рублей');}
else{f1.submit();}
}


function cl(el){
f1.action=el.href;
if (navigator.appName != 'Netscape' ){event.cancelBubble=true;}
f1.submit();
return false;
}

function setDate(){
str_zak='';
 for (i=1;i<tzk.rows.length-1;i++){ str_zak+=tzk.rows[i].cells[1].childNodes[0].name+'#'+tzk.rows[i].cells[1].childNodes[0].value+'#'+tzk.rows[i].cells[0].innerHTML+'#'+tzk.rows[i].sss+'&'; }
setCook('zakaz',str_zak,'/',document.domain);
}

function setCook(name,data,path,domain) {
   expires = new Date();
   expires.setTime(expires.getTime()+3600*1000);
 document.cookie=name+"="+escape(data)+";expires="+expires.toGMTString()+";path="+path+";domain="+domain+";";
}

