function Bottom (id, level)
{
    window.location.href=webroot+'/Admin/Site/Shop/Edit/Bottom/'+id+'/'+level+'.html';
}

function Right (id, level)
{
    window.location.href=webroot+'/Admin/Site/Shop/Edit/Right/'+id+'/'+level+'.html';
}

function Edit (type, id, cat)
{
    if (type == 'C')
    {
        window.location.href=webroot+'/Admin/Site/Shop/Edit/'+id+'.html';
    }
    else if (type == 'I')
    {
        window.location.href=webroot+'/Admin/Site/Shop/IEdit/'+id+'.html';
    }
    else if (type == 'O')
    {
        window.location.href=webroot+'/Admin/Site/Shop/OEdit/'+id+'/'+cat+'.html';
    }
}

function Delete (type, id, cat)
{
    if (type == 'C')
    {
        if (confirm ('Tikrai ištrinti?'))
        {
            window.location.href=webroot+'/Admin/Site/Shop/Delete/'+id+'.html';
        }
    }
    else if (type == 'I')
    {
        if (confirm ('Tikrai ištrinti?'))
        {
            window.location.href=webroot+'/Admin/Site/Shop/IDelete/'+id+'/'+cat+'.html';
        }
    }
    else if (type == 'O')
    {
        if (confirm ('Are you sure?'))
        {
            window.location.href=webroot+'/Admin/Site/Shop/ODelete/'+id+'/'+id+'.html';
        }
    }
}

function UploadPhoto (id)
{
    var ptime = document.getElementById('PTime');

    if (ptime.value != '')
    {
        url = id+'/'+ptime.value+'.html';
    }
    else
    {
        url = id+'.html';
    }

    window.open (webroot+'/Admin/Site/Shop/Photo/'+url, '', 'dependent=yes, width=300, height=300, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, copyhistory=yes, resizable=no, top=200, left=200');
}

function UploadUPhoto (id)
{
    var ptime = document.getElementById('PTime');

    if (ptime.value != '')
    {
        url = id+'/'+ptime.value+'.html';
    }
    else
    {
        url = id+'.html';
    }

    window.open (webroot+'/Shop/Photo/'+url, '', 'dependent=yes, width=300, height=300, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, copyhistory=yes, resizable=no, top=200, left=200');
}

function Uploaded (id, time)
{
    var place = document.getElementById('pp');
    var old = document.getElementById('op');

    if (old != null)
    {
        place.removeChild(old);
    }

    if (document.getElementById('up_'+id))
    {
        place.removeChild(document.getElementById('up_'+id));
    }

    var photo = document.createElement ('img');

    photo.setAttribute ('id', 'up_'+id);

    photo.src = webroot+'/MUP/Shop/item_'+id+'T_'+time+'.png';

    place.appendChild(photo);

    document.getElementById('PTime').setAttribute ('value', time);
}

function Preview (id)
{
    window.open (webroot+'/Admin/Site/Shop/Preview/'+id+'.html', '', 'width=500, height=400, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, copyhistory=yes, resizable=no');
}

function UPreview (id)
{
    window.open (webroot+'/Shop/Preview/'+id+'.html', '', 'width=500, height=400, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, copyhistory=yes, resizable=no');
}

function Resize ()
{
    var img = document.getElementById('photo');

    window.resizeTo(img.width+30, img.height+100);
}

function Display ()
{
    var ld = document.getElementById('ld');
    var bd = document.getElementById('Preview');

    ld.style.display = 'none';
    bd.style.display = 'block';
}

function Close ()
{
    window.close();
}

function Photos (count, id)
{
    var thumb = document.getElementById('Thumb_'+id);
    var num = document.getElementById('current_'+id);

    this.current = 1;

    this.next = function ()
    {
        if (this.current == count)
        {
            next = 1;
        }
        else
        {
            next = this.current+1;
        }

        this.current = next;
        num.innerHTML = this.current;

        thumb.src = webroot+'/MUP/Shop/item_'+id+'T_'+next+'.png';
    }

    this.previous = function ()
    {
        if (this.current == 1)
        {
            previous = count;
        }
        else
        {
            previous = this.current-1;
        }

        this.current = previous;
        num.innerHTML = this.current;

        thumb.src = webroot+'/MUP/Shop/item_'+id+'T_'+previous+'.png';
    }
}

var PhotoArray = new Array;
var Total = 0;

function BuildPhotoArray ()
{
    var div = document.getElementById('upload');

    for (i = 0; i < div.childNodes.length; i++)
    {
        if (div.childNodes[i].className == 'photoFrame')
        {
            var id = div.childNodes[i].id;
            var r_id = id.substr (6, id.length-5);
            PhotoArray['p'+r_id] = r_id;
            Total++;
        }
    }
}

function RemovePhoto (id, itemID)
{
    if (confirm ('Tikrai ištrinti?'))
    {
        var r = new Ajax ('/Admin/Site/Shop/RemovePhoto.html', 'PID='+PhotoArray['p'+id]+'&Item='+itemID, Loading, RPReady);
        r.makeRequest (1, id);
    }
}

function RPReady (response, id)
{
    var pdiv = document.getElementById('photo_'+id);

    for (i = 1; i <= Total; i++)
    {
        if (i > id)
        {
            PhotoArray['p'+i] = PhotoArray['p'+i]-1;
        }
    }

    pdiv.parentNode.removeChild(pdiv);

    Loading(0);
}

function ShowPreview (id)
{
    window.open(webroot+'/MUP/Shop/item_'+id+'_'+eval('ph_'+id+'.current')+'.png', 'Preview', 'width=650, height=500, resizable, scrollbars');
}

/*function ShowPreview (id)
{
    var div = document.getElementById('test_'+id);

    div.style.display = 'block';

    if (div.childNodes[0].tagName == 'IMG')
    {
        div.removeChild(div.childNodes[0]);
    }

    var imgt = document.createElement ('img');
    imgt.src = webroot+'/MUP/Shop/item_'+id+'_'+eval('ph_'+id+'.current')+'.png'

    div.insertBefore(imgt, div.childNodes[0]);
}
*/
function changeOrderType(select) {
    var val = select.options[select.selectedIndex].value;
    window.location.href=webroot+'/Admin/Site/Shop/Orders/'+val+'.html';
}

