function del(where){
    if(confirm("Napewno usun\u0105\u0107?")){
        HTTP.getText(where, populateDiv, 'content');
    }
}

function limit(field, left, length, text){
    if (field.value.length > length) {
        field.value = field.value.substring(0, length);
    }
    if(left!=null){
        document.getElementById(left).innerHTML =text + (length - field.value.length);
    }
}

function submitForm(f){
    var form = document.getElementById(f);
    if(form.onsubmit()){
        form.submit();
    }
}

function clearField(field, string){
    if(field.value == string){
        field.value = '';
    }
}

function restore(field, string){
    if(field.value == ''){
        field.value = string;
    }
}
function clickStar(name,ile){
    document.getElementById(name).value=ile;
    for(i=1;i<6;i++){
        if(i<=ile){
            document.getElementById(name+i).src='grafika/gui/user/d_on.jpg';
        }else{
            document.getElementById(name+i).src='grafika/gui/user/d_off.jpg';
        }
    }
}

function updateSearchForm(rc){
    var trade = document.forms.sortForm.trade.value;
    var voivode = document.forms.sortForm.voivode.value;
    if(rc){
        document.forms.sortForm.category.selectedIndex=0;
    }
    var category = document.forms.sortForm.category.value;
    var url = trade;
    if(category){
        if(url){
            url += "/"+category;
        }else{
            url = category;
        }
    }
    if(voivode){
        if(url){
            url += ","+voivode;
        }else{
            url = voivode;
        }
    }
    if(url){
        url += ".html";
    }else{
        url = "szukaj.html";
    }
    document.forms.sortForm.action='/'+url;

}

function markStar(name,ile){

    if(ile==0){
        ile = document.getElementById(name).value;
    }

    for(i=1;i<6;i++){
        if(i<=ile){
            document.getElementById(name+i).src='grafika/gui/user/d_on.jpg';
        }else{
            document.getElementById(name+i).src='grafika/gui/user/d_off.jpg';
        }
    }

    var desc = '&nbsp;';
    switch(ile){
        case 1:
            desc = 's\u0142aba';
            break;
        case 2:
            desc = 'dostateczna';
            break;
        case 3:
            desc = 'dobra';
            break;
        case 4:
            desc = 'bardzo dobra';
            break;
        case 5:
            desc = 'najlepsza';
            break;
    }

    document.getElementById(name+'D').innerHTML = desc;
}

var catCount = 1;
function addOfferCategory(cat, name){
    var div = document.getElementById('categories');
    var elem = '<div id="cs_'+catCount+'">'+ name +
    '<a href="javascript:void()" onclick="document.getElementById(\'cs_'+catCount+'\').innerHTML=\'\'" class="img">'+
    '<img src="/grafika/gui/usun_f.jpg" alt="usu\u0144"></a>'+
    '<input type="hidden" value="'+cat+'" name="category_'+catCount+'">'+
    '</div>';
    catCount+=1;
    div.innerHTML = div.innerHTML+elem;
    hideLightbox();
}

function addCategory(cat){
    HTTP.getText('/user.do?method=addCategory&cid='+cat, populateDiv, 'uct', null, 0);
    hideLightbox();
}

function rozwin(id){
    document.getElementById('z_'+id).style.display='none';
    document.getElementById('r_'+id).style.display='block';
}

function zwin(id){
    document.getElementById('r_'+id).style.display='none';
    document.getElementById('z_'+id).style.display='block';
}

function showHighlight(path){
    var ids = path.split('-');
    for (var i = 0; i < ids.length; i++) {
        var id = ids[i];
        var r_div = document.getElementById('ar_'+id);
        if(r_div){
            r_div.style.color='#0000bb';
        }
        var z_div = document.getElementById('az_'+id);
        if(z_div){
            z_div.style.color='#0000bb';
        }
        var c_div = document.getElementById('ac_'+id);
        if(c_div){
            c_div.style.color='#0000bb';
        }
    }
}

function hideHighlight(path){
    var ids = path.split('-');
    for (var i = 0; i < ids.length; i++) {
        var id = ids[i];
        var r_div = document.getElementById('ar_'+id);
        if(r_div){
            if(r_div.name!="sc_s"){
                r_div.style.color='#5a5a5a';
            }else{
                r_div.style.color='#00bb00';
            }
        }
        var z_div = document.getElementById('az_'+id);
        if(z_div){
            if(z_div.name!="sc_s"){
                z_div.style.color='#5a5a5a';
            }else{
                z_div.style.color='#00bb00';
            }
        }
        var c_div = document.getElementById('ac_'+id);
        if(c_div){
            if(c_div.name!="sc_s"){
                c_div.style.color='#5a5a5a';
            }else{
                c_div.style.color='#00bb00';
            }
        }
    }
}

function showToolTip(div, event){
    var tooltip = document.getElementById('tooltip');
    if(!tooltip){
        var objBody = document.getElementsByTagName("body").item(0);
        tooltip = document.createElement("div");
        tooltip.setAttribute('id','tooltip');
        tooltip.style.display = 'none';
        tooltip.style.position = 'absolute';
        tooltip.style.zIndex = '90';
        tooltip.style.top = '0';
        tooltip.style.left = '0';
        tooltip.style.width = '350px';
        tooltip.style.border= 'solid 1px black';
        tooltip.style.background = '#cccccc';
        tooltip.style.padding = '10px';
        tooltip.style['z-index'] = '999';
        objBody.insertBefore(tooltip, objBody.firstChild);
    }

    if(document.all){
        var c=getScrollXY();
        tooltip.style.left=(event.clientX+c[0]+20)+"px";
        tooltip.style.top=(event.clientY+c[1]-10)+"px"
    }else{
        tooltip.style.left=((event.pageX)+20)+"px";
        tooltip.style.top=((event.pageY)-10)+"px"
    }
    tooltip.innerHTML = document.getElementById(div).innerHTML;
    tooltip.style.display = "block";
}

function getScrollXY() {
    var scrOfX = 0, scrOfY = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    return [ scrOfX, scrOfY ];
}

function hideToolTip(){
    var tooltip = document.getElementById('tooltip');
    if(tooltip){
        tooltip.style.display='none';
    }
}

function selectRegistrationCategory(id, title, path){
    var cid = document.getElementById('cid');
    cid.value=id;
    var titleObject = document.getElementById('title');
    titleObject.innerHTML = title;
    hideLightbox();

    var selected = document.getElementsByName("sc_s");
    for(var i=0;i<selected.length;i++){
        selected[i].name = null;
        selected[i].style.color='#5a5a5a';
    }
    var ids = path.split('-');
    for (i = 0; i < ids.length; i++) {
        id = ids[i];
        var r_div = document.getElementById('ar_'+id);
        if(r_div){
            r_div.style.color='#00BB00';
            r_div.name="sc_s";
        }
        var z_div = document.getElementById('az_'+id);
        if(z_div){
            z_div.style.color='#00BB00';
            z_div.name="sc_s";
        }
        var c_div = document.getElementById('ac_'+id);
        if(c_div){
            c_div.style.color='#00BB00';
            c_div.name="sc_s";
        }
    }
}

function resetCity(ctg){
    var v = document.getElementById('vv').value;
    var action = ctg;
    if(v){
        if(ctg){
            action = ctg + ',' +v;
        }else{
            action = v;
        }
    }
    if(!action){
        action = 'szukaj.html';
    }else{
        action = action +'.html';
    }
    window.location = action;
}