//-----------------------------------------------------------------------------
//  mailLink
//-----------------------------------------------------------------------------

function mailLink(name, domain)
{
    var at = String.fromCharCode(64);
    document.write('<a h' + 'ref="mai' + 'lto:' + name + at + domain + '">' + name + at + domain + '</a>');
}

//-----------------------------------------------------------------------------
//  initialisePage
//-----------------------------------------------------------------------------

function initialisePage()
{
}

//-----------------------------------------------------------------------------
//  submitForm
//-----------------------------------------------------------------------------

function submitForm(formName, action, target)
{
    myForm = document.getElementById(formName);

    if (myAction = document.getElementById("action"))
    {
        myAction.value = action;
    }

    if (target)
    {
        myForm.target = target;
    }

    myForm.submit();
}

//-----------------------------------------------------------------------------
//  buyNow
//-----------------------------------------------------------------------------

function buyNow(itemno, itemdesc, price, quantity)
{
    var hover = new Image();
    var down = new Image();
    hover.src = "/site/images/buynow2.png";
    down.src = "/site/images/buynow3.png";

    var quantityField;

    if (quantity)
    {
        quantityField = 'Quantity <input name="quantity" size="2">';
    }

    document.write(
        '<table>' +
          '<tr>' +
            '<td style="vertical-align:middle; text-align:right; padding-top:10px; padding-right:10px; padding-bottom:20px">' +
              '<form id="item' + itemno + '" method="POST" action="/shop/additem.pl">' +
                '<input type="hidden" name="itemno" value="' + itemno + '">' +
                '<input type="hidden" name="itemdesc" value="' + itemdesc + '">' +
                '<input type="hidden" name="price" value="' + price + '">' +
                quantityField +
                '<br>' +
                '<span style="font-size:10pt; color:#000000">Item No: ' +
                  itemno +
                '</span>' +
              '</form>' +
            '</td>' +
            '<td style="padding-top:10px; padding-bottom:20px">' +
              '<span style="text-align:right; vertical-align:bottom">'
        );

    buyButton('item' + itemno);

    document.write(
              '</span>' +
            '</td>' +
          '</tr>' +
        '</table>'
        );
}

function buyButton(formid)
{
    document.write(
        '<a href="javascript:document.getElementById(\'' + formid + '\').submit()">' +
          '<img style="border:0; margin-top:0px; margin-left:0px; margin-bottom:0px; float:right;"' +
          'src="/site/images/buynow1.png"' +
          'onclick="javascript:document.getElementById(\'' + formid + '\').submit()"' +
          'onmouseover="this.src=\'/site/images/buynow2.png\'"' +
          'onmouseout="this.src=\'/site/images/buynow1.png\'"' +
          'onmousedown="this.src=\'/site/images/buynow3.png\'"' +
          'onmouseup="this.src=\'/site/images/buynow2.png\'">' +
        '</a>'
        )
}

function giftCard (design, itemno, itemdesc, price)
{
    document.write(
        '<input type="hidden" name="itemno' + design + '" value="' + itemno + '">' +
        '<input type="hidden" name="itemdesc' + design + '" value="' + itemdesc + '">' +
        '<input type="hidden" name="price' + design + '" value="' + price + '">' +
        'Quantity <input name="quantity' + design + '" size="2">'
    );
}

//-----------------------------------------------------------------------------
//  showPostage
//-----------------------------------------------------------------------------

function postAndPacking()
{
    html = 'plus <a href="#postdiv" rel="facebox">post and packing</a>' +
           '<div id="postdiv" style="display:none; z-index:100">' +
           '<h1>Post and Packing Rates</h1>'+
           '<table border="0" cellpadding="0" cellspacing="0" id="table1"> '+
           '  <tr> '+
           '      <td class="text"> '+
           '      <td class="text" style="width:150px;white-space:nowrap;padding-right:20px">United Kingdom</td> '+
           '      <td class="text" style="white-space:nowrap">' + postage_uk1 + ' for the first item and ' + postage_uk2 + ' for  '+
           '      each additional item</td> '+
           '  </tr> '+
           '  <tr> '+
           '      <td class="text"> '+
           '      <td class="text">Europe</td> '+
           '      <td class="text">£3.00 for the first item and £1.00 for  '+
           '      each additional item</td> '+
           '  </tr> '+
           '  <tr> '+
           '      <td class="text"> '+
           '      <td class="text" style="width:150px;white-space:nowrap">Outside Europe</td> '+
           '      <td class="text">£5.50 for the first item and £1.50 for  '+
           '      each additional item</td> '+
           '  </tr> '+
           '</table>' +
           '</div>';

    document.write(html);
}

//-----------------------------------------------------------------------------
//  shoppingBasket
//-----------------------------------------------------------------------------

function shoppingBasket()
{
    var basket = getCookie("basket");
    var bar2;

    if (basket)
    {
        var shop = document.getElementById("shop");

        items = basket.split("||");

        itemsString = (items.length == 2) ? "1 item" : items.length - 1 + " items";

        var hover = new Image();
        hover.src = "/site/images/items2.png";

        shop.innerHTML = "<div style='width:170px; float:right'>" +
                           "<div style='position:absolute; text-align:center; margin-top:15px; width:190px'>" +
                             "<a class='basket' href='/shop/viewbasket.pl' title='View shopping basket'>" +
                               "<img id='basket' src='/site/images/items1.png' onmouseover='this.src=\"/site/images/items2.png\"' onmouseout='this.src=\"/site/images/items1.png\"'>" +
                             "</a>" +
                             "<div style='position:absolute; white-space:nowrap; text-align:right; top:13px; left:87px' onmouseover='javascript:basket2()' onmouseout='javascript:basket1()' >" +
                               "<a class='basket' href='/shop/viewbasket.pl' title='View shopping basket'>" +
                                 itemsString +
                               "</a>" +
                             "</div>" +
                           "</div>" +
                         "</div>" ;
    }
}

function basket1()
{
    document.getElementById("basket").src="/site/images/items1.png";
}

function basket2()
{
    document.getElementById("basket").src="/site/images/items2.png";
}

//-----------------------------------------------------------------------------
//  Get Cookie
//-----------------------------------------------------------------------------

function getCookie(name)
{
    try
    {
        wholeCookie = document.cookie;

        allCookies=wholeCookie.split(";");

        for (a=0; a < allCookies.length; a++)
        {
            thisCookie = allCookies[a].split("=");

            key = thisCookie[0];

            for (b=0; b < key.length; b++)
            {
                if (key.substr(0,1) == " ")
                {
                    key = key.substr(1);
                }
            }

            if (key == name)
            {
                return thisCookie[1];
            }
        }
    }
    catch(e){;}
}

//-----------------------------------------------------------------------------
//  Set Cookie
//-----------------------------------------------------------------------------

function setCookie(name, value)
{
    document.cookie = name + "=" + value + ";expires;path=/"
}


