
function calcRanks(category, newrank) {
    
    currank = cat[category];
    
    
    if (currank > newrank) {
//        alert(currank +'  >>>> ' +newrank);
        
//        alert("current rank is" + currank);
//        alert("new rank is" + newrank);
        
        for (var i in cat) {
            
            if ((cat[i]>=newrank) && (cat[i]<currank)) {
//                alert('cat[i] is  '+cat[i]);
                document.getElementById('rank_' + i).selectedIndex = cat[i];
                cat[i] = parseInt(cat[i]) + parseInt(1);
            }
        }
        document.getElementById('rank_' + category).selectedIndex = newrank-1;
//        x = newrank-1;
//        alert('category id ='+ category + '    selectedIndex =' + x);
        cat[category] = newrank;

//        for (var j in cat) {
//            alert(j +'  =  '+ cat[j]);
//        }
                
    } else if (currank < newrank) {
//        alert(currank +'  <<<< ' +newrank);
        
        
//        alert("current rank is" + currank);
//        alert("new rank is" + newrank);
        
        for (var i in cat) {
           
           
            if ((cat[i]>currank)&&(cat[i]<=newrank)) {
//                alert('cat[i]'+cat[i]);
                cat[i] = parseInt(cat[i]) - parseInt(1);
                document.getElementById('rank_' + i).selectedIndex = cat[i] - 1;
            }
        }
        document.getElementById('rank_' + category).selectedIndex = newrank-1;
//        x = newrank-1;
//        alert('category id ='+ category + '    selectedIndex =' + x);
        cat[category] = newrank;
        
//        for (var j in cat) {
//            alert(j +'  =  '+ cat[j]);
//        }
        
    } else {
        
//        alert('nothing done');
        
    }
}



function calcRanksTree(category, newrank, cat) {
    
    currank = cat[category];
    
    
    if (currank > newrank) {
//        alert(currank +'  >>>> ' +newrank);
        
//        alert("current rank is" + currank);
//        alert("new rank is" + newrank);
        
        for (var i in cat) {
            
            if ((cat[i]>=newrank) && (cat[i]<currank)) {
//                alert('cat[i] is  '+cat[i]);
                document.getElementById('rank_' + i).selectedIndex = cat[i];
                cat[i] = parseInt(cat[i]) + parseInt(1);
            }
        }
        document.getElementById('rank_' + category).selectedIndex = newrank-1;
//        x = newrank-1;
//        alert('category id ='+ category + '    selectedIndex =' + x);
        cat[category] = newrank;

//        for (var j in cat) {
//            alert(j +'  =  '+ cat[j]);
//        }
                
    } else if (currank < newrank) {
//        alert(currank +'  <<<< ' +newrank);
        
        
//        alert("current rank is" + currank);
//        alert("new rank is" + newrank);
        
        for (var i in cat) {
           
           
            if ((cat[i]>currank)&&(cat[i]<=newrank)) {
//                alert('cat[i]'+cat[i]);
                cat[i] = parseInt(cat[i]) - parseInt(1);
                document.getElementById('rank_' + i).selectedIndex = cat[i] - 1;
            }
        }
        document.getElementById('rank_' + category).selectedIndex = newrank-1;
//        x = newrank-1;
//        alert('category id ='+ category + '    selectedIndex =' + x);
        cat[category] = newrank;
        
//        for (var j in cat) {
//            alert(j +'  =  '+ cat[j]);
//        }
        
    } else {
        
//        alert('nothing done');
        
    }
}




function resetRanks(base_url) {
    window.location= base_url +"index.php/resetranks/";
}

function setRows(base_url, action, categoryId, current, rows) {
    
    window.location=base_url +"index.php/" + action + "/category/" + categoryId + "/page/" + current + "/rows/" + rows + "/";
}

function popup(url)	{
    
	var win = window.open(url, 'status', 'width=880,height=600,titlebar=no,addressbar=no,scrollbars=yes,resizable=yes');
	
	if (parseInt(navigator.appVersion) >= 4 ) { 
        win.window.focus(); 
    }
}

function getServices(distance, base_url, action) {
    
    window.location=base_url +"index.php/" + action + "/distance/" + distance + "/";
    
}

function getServices2(category, distance, base_url, action) {
    
    window.location=base_url +"index.php/" + action + "/category/" + category + "/distance/" + distance + "/";
    
}

function getServices3(category, offer, show , distance, base_url, action) {
    
    window.location=base_url +"index.php/" + action + "/category/" + category + "/offer/" + offer + "/show/" + show + "/distance/" + distance + "/";
    
}

function increaseFont(fontsize) {
    
    if (fontsize == '') {
        fontsize = 1;
    }
    
    fontsize = parseFloat(fontsize);
    
    //alert(fontsize);
    
    if(fontsize >= 1.6) {
        return false;
    }
    
    fontsize = (fontsize + 0.2) + 'em';
    
    document.getElementById('bid').style.fontSize = fontsize;
    
    setFontSize(fontsize);
}

function decreaseFont(fontsize) {
    
    if (fontsize == '') {
        fontsize = 1;
    }
    
    fontsize = parseFloat(fontsize);
    
    //alert(fontsize);
    
    if(fontsize <= 1.0) {
        return false;
    }
    
    fontsize = (fontsize - 0.2) + 'em';
    
    document.getElementById('bid').style.fontSize = fontsize;
    
    setFontSize(fontsize);
}

function setFontSize(fontsize) {
    
    setCookie('current_fontsize', fontsize, 365);
}


function setCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function getFontSize() {
    
    fontsize = getCookie('current_fontsize');
    
    //alert(fontsize);
    
    if(fontsize!=null) {
        document.getElementById('bid').style.fontSize = fontsize;
    }
}

function initSelect(name) {
    
    _sel = document.getElementById(name);
    
    _sel.selectedIndex = 0;
}

function showInParents() {
    
    document.getElementById('show_articles_in_parents').style.display = 'table-row';
}


function showServices(id, e) {
    
//    _a = document.getElementById('topic_' + id);
    _ul = document.getElementById('service_list_' + id);
    
    _class = e.className;
    
//    alert(_class);
    
    if(_class == null) {
        
        _class = 'hidden'
    }
    
    if(_class == 'hidden') {
    
        e.className = 'expand';
        _ul.style.display = 'block';    
    
    } else if(_class == 'expand') {
        
        e.className = 'hidden';
        _ul.style.display = 'none';    
    }
    
    return false;
}
