var searchUrl;

function  addtoUrl(opt)
    {
    ddd = $(opt);
    val = ddd.value;
    re = new RegExp("/", "g")

    if (val != '')
        {
        searchUrl = searchUrl + '/' + opt + '/' + val.replace(re, '-')
        }
    }

function  addtoUrl2(param, opt)
    {
    ddd = $(opt);
    val = ddd.value;
    re = new RegExp("/", "g")

    if (val != '')
        {
        searchUrl = searchUrl + '/' + param + '/' + val.replace(re, '-')
        }
    }

function SubmitSearch()
    {
    searchUrl = '/search';
    addtoUrl('ethnicity');
    addtoUrl('activity');
    addtoUrl('gender');
    addtoUrl('grouping');
    addtoUrl('haircolour');
    addtoUrl('beforedate');
    addtoUrl('afterdate');
    addtoUrl('productid');
    addtoUrl2('keyword', 'searchkeyword');
    window.document.location.href = searchUrl;
    }

function ClearSearch()
    {
    $('gender').selectedIndex = 0;
    $('ethnicity').selectedIndex = 0;
    $('haircolour').selectedIndex = 0;
    $('activity').selectedIndex = 0;
    $('grouping').selectedIndex = 0;
    s = $('beforedate').value = '';
    s = $('afterdate').value = '';
    s = $('productid').value = '';
    s = $('searchkeyword').value = '';
    }

function SubmitKeywordSearch()
    {
    searchUrl = '/browse';
    addtoUrl('keyword');
    window.document.location.href = searchUrl;
    }

function basketremove(id, format)
    {
    window.document.location.href = '/basket/remove?id=' + id + '&format=' + format;
    }

function wishlistremove(id, format)
    {
    window.document.location.href = '/wishlist/remove?id=' + id + '&format=' + format;
    }

function movetobasket(id, format)
    {
    window.document.location.href = '/wishlist/move?id=' + id + '&format=' + format;
    }

function movetowishlist(id, format)
    {
    window.document.location.href = '/basket/move?id=' + id + '&format=' + format;
    }

function downloadremove(id)
    {
    if (confirm('Are you Sure?'))
        {
        window.document.location.href = '/user/remove/id/' + id;
        }
    }

function downloadclip(id)
    {
    //window.document.location.href='/main_test.php/user/download/id/'+id;
    //window.document.location.href='/main_win.php/user/download/id/'+id;
    window.document.location.href = '/user/download/id/' + id;
    }

function addtowishlist()
    {
    form = $('basketform');
    form.action = '/wishlist/add';
    form.submit();
    return false;
    }

function addedtobasket(request)
    {
    ad = $('addedtext');

    if (request.responseText > 0)
        {
        ad.addClassName('green');
        $('basketcount').innerHTML = '[' + request.responseText + ']'
        ad.innerHTML = 'You have successfully added this item to your basket';
        }

    else
        {
        if (request.responseText == -1)
            {
            ad.addClassName('green');
            ad.innerHTML = 'This item is already in your basket';
            }
        }
    }

function addedtowishlist(request)
    {
    ad = $('addedtext');

    if (request.responseText > 0)
        {
        ad.addClassName('green');
        $('wishlistcount').innerHTML = '[' + request.responseText + ']'
        ad.innerHTML = 'You have successfully added this item to your wishlist';
        }

    else
        {
        if (request.responseText == -1)
            {
            ad.addClassName('green');
            ad.innerHTML = 'This item is already in your wishlist';
            }
        }
    }

function wishlistover()
    {
    $('wishlistcount').toggleClassName('whitetext');
    MM_swapImage('wishlistimg', '', '/images/layout/wishlistw.png', 1);
    }

function wishlistout()
    {
    $("wishlistcount").toggleClassName("whitetext");
    MM_swapImgRestore();
    }

function basketover()
    {
    $('basketcount').toggleClassName('whitetext');
    MM_swapImage('basketimg', '', '/images/layout/basketw.png', 1);
    }

function basketout()
    {
    $('basketcount').toggleClassName('whitetext');
    MM_swapImgRestore();
    }

function changeformat(f)
    {
    ad = $('addedtext');
    ad.removeClassName('green');
    ad.innerHTML = 'Please note that all prices are exclusive of VAT/Sales Tax';
    p = $('playerdiv');
    s = $('still');

    if (f == 4)
        {
        p.hide();
        s.show();
        }

    else
        {
        s.hide();
        p.show();
        }
    }

function logout(confirm)
    {
    if (confirm == 1)
        {
        document.logoutform.submit()
        }

    else
        {
        history.go(-1);
        }
    }

function unScramble(eMail1, eMail2, linkText, subjectText, statusText)
    {
    var a, b, c, d, e;
    a = eMail1;
    c = linkText;
    b = eMail2.substring(0, eMail2.length - 5);

    if (subjectText != "")
        {
        d = "?subject=" + escape(subjectText);
        }

    else
        {
        d = "";
        }

    if (statusText != "")
        {
        e = " onMouseOver=\"top.status=\'" + statusText +
            "\'\;return true\;\" onMouseOut=\"top.status=\'\'\;return true\;\"";
        }

    else
        {
        e = "";
        }
    document.write("<A class=\"greenlink\" HREF=\"mai" + "lto:" + a + "@" + b + d + "\"" + e + ">" + c + "</A>");
    }

function email()
    {
    unScramble(String.fromCharCode(105, 110, 102, 111), "mx-greenscreen.complete",
        'info@<span class="emaila">(remove)</span><span class="emailb">mx-gree</span>nscreen.com', "", "");
    }

function supportemail()
    {
    unScramble(String.fromCharCode(115, 117, 112, 112, 111, 114, 116), "mx-greenscreen.complete",
        'support@<span class="emaila">(remove)</span><span class="emailb">mx-gree</span>nscreen.com', "", "");
    }

function submitenter(myfield, e)
    {
    var keycode;

    if (window.event)
        keycode = window.event.keyCode;

    else if (e)
        keycode = e.which;

    else
        return true;

    if (keycode == 13)
        {
        SubmitKeywordSearch();
        return false;
        }

    else
        return true;
    }
