function BasketCount()
{
all=expand(readCookie("basket"))
sall=all.split("")
ps=0
for (n in sall)
{
    ps=ps+uncode(sall[n])
}
return ps;
}
function restart()
{
    parent.contents.window.location.reload()
    window.location = "home.asp"
}

function show(pn,stl)
{
    createCookie("csty",stl,0)
    createCookie("CP",pn,0)
    window.location = "picture.asp"
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return "";
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function cheque()
{
window.location = "cheque.asp"
}

function cancelorder()
{
c=confirm("Cancel Order?")
if (c==true)
{
    window.location="cancelorder.asp"
}
}

function mand(xi,yi)
{
	md = 0
	x = xi
	y = yi
        bn = binno(x)
        bp = binnop(x)
	while (x>0)
		{
       		bn = binno(x)
        	bp = binnop(x)
        	if (bp==y)
			{
			md = 1
			}
        	x = x - bn
    		}
	return md
}

function setlog(text,ln)
{
    text=expand(text)
	hp = Math.floor((ln-1) / 6)
	bt = ln - (hp * 6)
	hp = hp+1
	while (text.length < hp)
		{
        	text = text + "A"
    		}
	ch = text.charAt(hp-1)
	chd = uncode(ch)
	cr=mand(chd,bt)
	if (cr == 0)
		{
        	chd = chd + Math.pow(2,(bt - 1))
		}
	sl = code(chd)
	if (hp>1)
		{
		sl = text.slice(0,hp - 1) + sl
		}
	if (hp<(text.length))
		{
		sl=sl + text.slice(hp)
		}
	sl=compact(sl)
	return sl
}

function clearlog(text,ln)
{
    text=expand(text)
	hp = Math.floor((ln-1) / 6)
	bt = ln - (hp * 6)
	hp = hp + 1
	while (text.length < hp)
		{
        	text = text + "A"
    		}
	ch = text.charAt(hp-1)
	chd = uncode(ch)
	cr=mand(chd,bt)
	if (cr == 1)
		{
        	chd = chd - Math.pow(2,(bt - 1))
		}
	cllo = code(chd)
	if (hp>1)
		{
		cllo = text.slice(0,hp - 1) + cllo
		}
	if (hp<(text.length))
		{
		cllo=cllo + text.slice(hp)
		}
	cllo=compact(cllo)
	return cllo
}

function checklog(text,ln)
{
    text=expand(text)
	hp = Math.floor((ln-1) / 6)
	bt = ln - (hp * 6)
	hp = hp + 1
	while (text.length < hp)
		{
        	text = text + "A"
    		}
	ch = text.charAt(hp-1)
	chd = uncode(ch)
	chl = mand(chd,bt)
	return chl
}

function binno(v)
{
	nbin = 1
	bno = 0
	while (nbin <= v)
		{
		bno = nbin
		nbin = nbin * 2
    		}
	return bno
}
function binnop(s)
{
	nbin = 1
	bno = 0
	while (nbin <= s)
		{
		bno =bno+1
		nbin = nbin * 2
    		}
	return bno
}

function code(dec)
{
	line = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789$)"
	return line.charAt(dec)
}

function uncode(code)
{
	line = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789$)"
	return line.indexOf(code)
}

function compact(inp)
{
    calc=inp
    out=""
    for (cp=0;cp<=calc.length-1;cp++)
    {
        tb=cp
        if (tb<calc.length)
        {
            while (calc.charAt(tb)==calc.charAt(tb+1))
                {
                tb++
                }
        }
        bc=(tb-cp)+1
        while (bc>64)
            {
            out=out+":"+calc.charAt(cp)+")"
            bc=bc-64
            }
        if (bc>3)
        {
            out=out+":"+calc.charAt(cp)+code(bc-1)
        }
        else
        {
            out=out+calc.slice(cp,cp+bc)
        }
        cp=tb
    }
    return out
}

function expand(inp)
{
    out=""
    calc=inp
    for (cp=0;cp<=calc.length-1;cp++)
    {
        if (calc.charAt(cp)==":")
        {
            for (ct=0;ct<uncode(calc.charAt(cp+2))+1;ct++)
                {
                out=out+calc.charAt(cp+1)
                }
            cp=cp+2
        }
        else
        {
            out=out+calc.charAt(cp)
        }
    }
    return out
}
