function openChat(id)
{
    window.open('/messenger/index/id/'+id+'/','','resizable=1,left=300,top=250,height=570,width=500');
}

function getButtonText(name)
{
    document.getElementById('bottontext').value = '<a href="http://www.tiga.by"><img src="http://www.tiga.by/img/catalog/'+name+'.gif" alt="TIGA.BY: Каталог, новости, погода, почта, работа, фото и многое другое" width="88" height="31" border="0"></a>';
    document.getElementById('button'+name).checked = true;
}

function invert()
{
    f=document.forms.fieldsForm;
        for(i=0;i<f.elements.length; i++){
            if(f.elements[i].type == "checkbox") {
                f.elements[i].checked = !f.elements[i].checked;
            }     
        }
}

/**
 * marks all rows and selects its first checkbox inside the given element
 * the given element is usaly a table or a div containing the table or tables
 *
 * @param    container    DOM element
 */

function markAllRows( container_id ) {
    var rows = document.getElementById(container_id).getElementsByTagName('tr');
    var unique_id;
    var checkbox;
    var marked_row = new Array;
    for ( var i = 0; i < rows.length; i++ ) {
        checkbox = rows[i].getElementsByTagName( 'input' )[0];
        if ( checkbox && checkbox.type == 'checkbox' ) {
            unique_id = checkbox.name + checkbox.value;
            if ( checkbox.disabled == false ) {
                checkbox.checked = true;
                if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) {
                    rows[i].className += ' marked';
                    marked_row[unique_id] = true;
                }
            }
        }
    }
    return true;
}

function unMarkAllRows( container_id ) {
    var rows = document.getElementById(container_id).getElementsByTagName('tr');
    var unique_id;
    var checkbox;
    var marked_row = new Array;
    for ( var i = 0; i < rows.length; i++ ) {
        checkbox = rows[i].getElementsByTagName( 'input' )[0];
        if ( checkbox && checkbox.type == 'checkbox' ) {
            unique_id = checkbox.name + checkbox.value;
            checkbox.checked = false;
            rows[i].className = rows[i].className.replace(' marked', '');
            marked_row[unique_id] = false;
        }
    }
    return true;
}


function show_hide(element)
{
	var id=document.getElementById(element);
	if (id.style.display==''){
		id.style.display='none';
		id.style.visibility='hidden';	
	}
	else{
		id.style.display='';
		id.style.visibility='visible';
	}
}



// поисковая строка
function sear(t, s1, s2)
{
    document.getElementById('search_form').action = '/search/' + t;
    document.getElementById('se1').className = s1;
    document.getElementById('se2').className = s2;
}


function previewHumor(id)
{
    document.open('/humor/element/id/'+id+'/','','width=700 , height = 400, resizable=0, toolbar=0, menubar=0, scrollbars=1');
}

function previewUserInfo(userId)
{
    document.open('/my/info/id/'+userId+'/','','width=500 , height = 175, resizable=0, toolbar=0, menubar=0, scrollbars=0');
}


function image_preview(width,height,imagename)
{    
    var f = open('', '', 'width='+width+', height='+height+', resizable=0, toolbar=0, menubar=0, scrollbars=0');
    f.document.write("<html><head></head><body><table width='100%' border ='0'><tr><td align='center' ><img src="+imagename+"></td></tr><tr><td align='center' ><a href='#' onClick='self.close();' style='font-size: 11px; color:#333; padding:1px;'>закрыть окно</a></td></tr></table></body></html>");
    f.document.close();
    f.focus();
}

function hide_value(id, value)
{
    var el = document.getElementById(id);
    if (el.value == value) el.value = '';
}

function editor(path, width, height)
{
    open('/editor/'+path, '', 'width='+width+', height='+height+', resizable=0, toolbar=0, menubar=0, scrollbars=1')
}

