function progress(id,number)
{
    var el_b=document.getElementById(id);
    var el_t=document.getElementById('text-' + id);
    number=number+2;
    if (number>100)
    {number=100;}
    el_b.style.width=number + 'px';
    el_t.innerHtml=number + '%';
    sendRequest('type=photogallery-photo&action=add&id=1');
    upload=setTimeout("progress('" + id + "'," + number + ")", 1000);
}

function uploadFile(id)
{
    id=1;
    document.getElementById('uploaded').submit();
    tmp=''
    tmp+='<div style="float:left;width:125px;height:220px;margin:2px;padding:4px;text-align:center;" id="item-0" name="photogallery-photo" onmouseover="item_album_on(\'0\');" onmouseout="item_album_off(\'0\');">';
    //tmp+='<div class="center index padding">';
    //tmp+='<a href="javascript:item_remove(\'0\');" class="cervena underline_red">Odstrániť</a>';
    //tmp+='</div>';
    tmp+='<div id="photo-bar" style="background-color:green;width:1%;height:10px;"></div>';
    tmp+='<div id="text-photo-bar">1%</div>';
    tmp+='<div style="height:145px;"><a href="#" id="photo-href"><img src="" alt="" title="" id="photo-img" /></a></div>';
    tmp+='<div><input type="text" id="name-0" style="width:89%;font-size:11px;text-align:center;" onblur="set_value(\'name-0\',\'photo-name\');" value=""  /></div>';
    tmp+='<div><textarea id="description-0" style="width:89%;height:30px;font-size:11px;text-align:center;" onblur="set_value(\'description-0\',\'photo-description\');" onfocus="" cols="10" rows="5">popis</textarea></div>';
    tmp+='</div>';
    div=document.createElement('div');
    div.innerHTML=tmp;
    el=document.getElementById('photogallery-photo');
    el.insertBefore(div,el.firstChild);
    upload=setTimeout("progress('photo-bar',1)", 1000);
}

function get_alert(data){create_p('alert',1,'alert',data);}
function add_photoalbum(){create_p('add_photoalbum',1,'add_photoalbum',0,650,305);}
function edit_photoalbum(id){create_p('edit_photoalbum',1,'edit_photoalbum',id,650,305);}
function item_remove(id){create_p('remove',1,id);}

function add_fav_album(id)
{
    sendRequest('type=photogallery-album&action=add-favourite&id=' + id);
}

function ajax_remove(id)
{
    close_p(id);
    var e=document.getElementById('item-' + id);
    sendRequest('type=' + e.getAttribute('name') + '&action=remove&id=' + id);
}

function set_select(id,value)
{
    select=document.getElementById(id);
    for(var i=0;i<select.length;i++)
    {
        if(select[i].value==value)
        {select.selectedIndex=i;}
    }
}

function set_radio(name,value)
{
    radio=document.getElementsByName(name);
    for(var i=0;i<radio.length;i++)
    {
        radio[i].checked=false;
        if(radio[i].value==value)
        {radio[i].checked=true;}
    }
}

function destruct_item(id)
{
    if (!IE)
    {depacity('item-' + id,100);}
    else
    {document.getElementById('item-' + id).style.display='none';}
}

function opacity2(item,opacity)
{
    ratio=opacity / 100;
    if (opacity > 100){opacity=100; }
    document.getElementById(item).style.opacity=ratio;
    document.getElementById(item).style.filter='alpha(opacity=' + (ratio * 100) + ')';
    visibility_timer=window.setTimeout("opacity('" + item + "'," + (opacity + 2) + ");",10);
    if (opacity==100){window.clearTimeout(visibility_timer);}
}

//##opacity efekt - zviditelnenie

function depacity(item,opacity)
{
    ratio=opacity / 100;
    if (opacity < 0){opacity=0; }
    document.getElementById(item).style.opacity=ratio;
    document.getElementById(item).style.filter='alpha(opacity=' + (ratio * 100) + ')';
    visibility_timer=window.setTimeout("depacity('" + item + "'," + (opacity - 2) + ");",10)
    if (opacity==0)
    {
        window.clearTimeout(visibility_timer);
        var e_c=document.getElementById(item);
        var e_p=document.getElementById('parent-' + item);
        if (e_p)
        {
            var height=e_c.offsetHeight;
            e_p.style.height=height + 'px';
            e_c.style.display='none';
            reduced('parent-' + item,height);
        }
        else
        {e_c.style.display='none';}
    }
}

function create_photoalbum(id)
{
    var v_type='';
    var e_name=document.getElementById('smille_add');
    var e_category=document.getElementById('album_category');
    var e_type=document.getElementsByName('album_type');
    var e_pwd=document.getElementById('album_password');
    for(i=0;i<e_type.length;i++)
    {
        if(e_type[i].checked){v_type=e_type[i].value;}
    }
    var v_pwd=e_pwd.value;
    var v_name=e_name.value;
    var v_category=e_category.options[e_category.selectedIndex].value;

    var error='';
    if(v_name.length < 3 || v_name.length > 60){error += label[78] + '<br />';}
    if(v_category.length < 1 || v_category==0){error+=label[79] + '<br />';}
    if (v_type!='')
    {
        if(v_type=='password' && (v_pwd.length<4 || v_pwd.length>20))
        {error+=label[80] + '<br />';}
    }
    else
    {error+='Prosím vyberte typ fotoalbumu.<br />';}

    if (error=='')
    {
        if (id==0)
        {document.getElementById('create_album').submit();}
        else
        {sendRequest('type=photogallery-album&action=update&id=' + id + '&a_name=' + escape(trim(v_name)) + '&a_category=' + v_category.replace('&','~') + '&a_type=' + v_type + '&a_pwd=' + escape(trim(v_pwd)));}
    }
    else
    {get_alert(error);}
}

function set_photo_bar(data)
{
    for(i=0;i<6;i++)
    {
        var e=document.getElementById('photo-' + (i+1));
        e.src=link_root + 'chat/resize.php?gallery=' + data[i].file + '&type=x';
        e.name=data[i].position;
        //if (data[i].file=='undefined')
        //{e.style.width=80 + 'px';alert('hmm');}
    }
}

function set_photo(id)
{
    var e_s=document.getElementById(id);
    if (e_s.name!='')
    {
        var e_b=document.getElementById('photo-big');
        var e_m=document.getElementById('photo-min');
        var e_a=document.getElementById('album');
        e_b.src=e_s.src.replace('&type=x','&type=xl');
        e_m.src=e_s.src;
        sendRequest('get_photo=' + e_s.name + '&album=' + e_a.value);
    }
}

//##################################################funkcie pre fotoalbum

function item_show_hide(id)
{
    var item='category_' + id;
    var el=document.getElementById(item);
    switch (el.style.display)
    {
        case 'none':el.style.display='block';break;
        case 'block':el.style.display='none';break;
    }
}

//##################################################funkcie pre katalog

function f_chat_friend_add()
{
    var user=document.getElementById('pw_chat_friend_add_login_hidden').value;
    document.getElementById('pw_chat_friend_add_login').value=user;
    var group=document.getElementById('pw_chat_friend_add_group').value;
    var message=document.getElementById('pw_chat_friend_add_message').value;
    if (!(user.length<3))
    {sendRequest('user=' + user + '&group=' + group + '&message=' + message);}
    else
    {alert('login musi obsahovat minimalne tri znaky');}
}

function f_chat_friend_delete(data)
{
    sendRequest('chat_friend_delete=' + data);
    var item='item_' + data;
    document.getElementById(item).style.display='none';
}

function f_chat_friend_foes_add(data)
{
    sendRequest('chat_friend_foes_add=' + data);
    var item='item_' + data;
    document.getElementById(item).style.display='none';
}

function f_chat_friend_foes_remove(data)
{
    sendRequest('chat_friend_foes_remove=' + data);
    var item='item_' + data;
    document.getElementById(item).style.display='none';
}

function f_chat_friend_group_delete(data)
{
    sendRequest('chat_friend_group_delete=' + data);
    var item='item_' + data;
    document.getElementById(item).style.display='none';
}

function f_chat_friend_group_edit(id)
{
    var name=document.getElementById('pw_chat_friend_group_edit_name').value;
    var item='name_' + id;
    if (!(name.length<4))
    {
        sendRequest('chat_friend_group_edit=' + id + '&name=' + name);
        document.getElementById(item).innerHTML=name;
    }
    else
    {alert('skupina musí obsahovať minimálne 4 znaky');}
}

//##################################################funkcie pre priatelov

function set_value(id,type)
{
    var data=escape(trim(document.getElementById(id).value));
    switch(type)
    {
        case 'photo-name':sendRequest('photo-name=' + data + '&id=' + id.replace('name-',''));break;
        case 'photo-description':sendRequest('photo-description=' + data + '&id=' + id.replace('description-',''));break;
    }
}

function get_search_login(ktory)
{sendRequest('login=' + document.getElementById(ktory).value);}

function get_region()
{
    var country=document.getElementById('add_country').value;
    sendRequest('get_region=' + country);
}

function get_city()
{
    var country=document.getElementById('add_country').value;
    var region=document.getElementById('add_region').value;
    sendRequest('get_city=' + region + '&get_city2=' + country);
}

function get_loader()
{
    var sirka=(screen.width-100)/2;
    var vyska=(screen.height-100)/2-100;
    img=document.createElement('img');
    img.style.left=sirka + 'px';
    img.style.top=vyska + 'px';
    img.style.position='fixed';
    img.src=link_root + 'public/img/loader.gif';
    document.body.appendChild(img);
}

function insert_smille(smille)
{
    var el=document.getElementById('smille_add');
    el.value += unescape(smille);
    el.focus();
    create_popup('show_smilles',0);
}

//##################################################globalne funkcie

function select_all(co)
{
if (co=='head')
{odkial=document.formmenu.select_all_head.checked;}

if (co=='foot')
{odkial=document.formmenu.select_all_foot.checked;}

for (var index=0;index<document.formmenu.elements.length;index++)
{
if (document.formmenu.elements[index].type=="checkbox")
{document.formmenu.elements[index].checked=odkial;}
}
}

function show_portrait(zobrazit,ktory)
{
if (zobrazit=='block')
{
sirka=(screen.width-700)/2;
vyska=(screen.height-400)/2-100;
document.getElementById("window_portrait").style.left = sirka + 'px';
document.getElementById("window_portrait").style.top = vyska + 'px';
document.getElementById("naserver").name = 'naserver[' + ktory + ']';
}
document.getElementById("window_portrait").style.display = zobrazit;
}

function show_settings(zobrazit, odkial, ktore)
{
if (zobrazit=='block')
{
sirka=(screen.width-200)/2;
vyska=(screen.height-130)/2-100;
document.getElementById("window_settings").style.left = sirka + 'px';
document.getElementById("window_settings").style.top = vyska + 'px';

if (odkial=='favourite_album')
{
document.getElementById("settings_edit").value = label[84];
document.getElementById("settings_edit").name = "settings_favourite_album";
}

if (odkial=='album')
{
document.getElementById("settings_edit").value = label[85];
document.getElementById("settings_edit").name = "settings_album";
}

if (odkial=='komentare')
{
document.getElementById("settings_edit").value = label[86];
document.getElementById("settings_edit").name = "settings_comment";
}

if (odkial=='status')
{
document.getElementById("settings_edit").value = label[87];
document.getElementById("settings_edit").name = "settings_status";
}

if (odkial=='my_friends')
{
document.getElementById("settings_edit").value = label[88];
document.getElementById("settings_edit").name = "settings_my_friends";
}

if (odkial=='iam_friends')
{
document.getElementById("settings_edit").value = label[89];
document.getElementById("settings_edit").name = "settings_iam_friends";
}

if (odkial=='common_friends')
{
document.getElementById("settings_edit").value = label[90];
document.getElementById("settings_edit").name = "settings_common_friends";
}

if (odkial=='symposium')
{
document.getElementById("settings_edit").value = label[91];
document.getElementById("settings_edit").name = "settings_symposium";
}

if (ktore==0)
{document.getElementById("all").checked=true;}
if (ktore==1)
{document.getElementById("friend").checked=true;}
if (ktore==2)
{document.getElementById("none").checked=true;}

}

document.getElementById("window_settings").style.display = zobrazit;
}

function show_status(zobrazit)
{
sirka=(screen.width-700)/2;
vyska=(screen.height-300)/2-100;
document.getElementById("window_status").style.left = sirka + 'px';
document.getElementById("window_status").style.top = vyska + 'px';
cover(zobrazit);
document.getElementById("window_status").style.display = zobrazit;
}

function show_report(zobrazit, id)
{
sirka=(screen.width-500)/2;
vyska=(screen.height-300)/2-100;
document.getElementById("window_report").style.left = sirka + 'px';
document.getElementById("window_report").style.top = vyska + 'px';
document.getElementById("window_report").style.display = zobrazit;
}

function show_delete(zobrazit, odkial, ktore)
{
if (zobrazit=='block')
{
sirka=(screen.width-250)/2;
vyska=(screen.height-90)/2-100;
document.getElementById("window_delete").style.left = sirka + 'px';
document.getElementById("window_delete").style.top = vyska + 'px';
document.getElementById("delete_id").name = odkial;
document.getElementById("delete_id").value = ktore;
}

document.getElementById("window_delete").style.display = zobrazit;
}

function insertCode(aky)
{
aky = unescape(aky);
var el = document.getElementById("smille_add");
el.value += aky;
el.focus();
show_smille('none');
}

function getLoader()
{
sirka=(screen.width-100)/2;
vyska=(screen.height-100)/2-100;
document.getElementById("window_loader").style.left = sirka +'px';
document.getElementById("window_loader").style.top = vyska +'px';
document.getElementById('window_loader').style.display = 'block';
}

function showColorBox(id)
{
tento = id;
var el = document.getElementById(tento);
el.style.display = "block";
}

function selectColor(val,id)
{
color = val;
tento = id + '_input';
var el = document.getElementById(tento);
el.value = val;
if (val == '#transp')
{val = '#000000';}
tento = id;
hideColorBox(tento);
}

function hideColorBox(id)
{
tento = id;
var el = document.getElementById(tento);
el.style.display = "none";
}

function item_on(item)
{document.getElementById(item).style.background='#DAEEFD';}

function item_off(item)
{document.getElementById(item).style.background='transparent';}


function select_item(item)
{
if (document.getElementById(item).checked==false)
{document.getElementById(item).checked=true;}
else
{document.getElementById(item).checked=false;}
}