var d=document;
var ScreenW=0;
var ScreenH=0;
var regionCurrent=0;
var beforeWidth=0;
function ge(obj){
   if(document.getElementById(obj)) {
     obj = document.getElementById(obj);
     return obj;
   } else {
     return false;
   }
}
function size_screen()
{
        var nav = navigator.appName;            
        if((nav!="Netscape")&&(nav!="Opera")) 
        {
        ScreenW = d.body.clientWidth;
        ScreenH = d.body.clientHeight;   
        }
        else
        {               
          ScreenW = window.innerWidth;
          ScreenH = window.innerHeight;
        }
        if(ScreenW<1100)
          HideBlock('navigation');
        else
         ShowBlock('navigation');
        	
}
function HideBlock(id)
{
	ge(id).style.display='none';
}
function ShowBlock(id)
{
	ge(id).style.display='block';
}
function InvertBlock(id)
{
	if(ge(id))
	{
		if(ge(id).style.display=='block')
			HideBlock(id)
		else	
			ShowBlock(id)
	}
}
function selectblock(id) {
	if(regionCurrent != 0)
	{
		document.getElementById(regionCurrent).className = '';
	}
	//alert(document.getElementById(id).className);
	document.getElementById(id).className = 'sel';
	document.getElementById(id).blur();
	regionCurrent = id;
	return false;
}
function my_position(id){
	
	afterWidth=getDocSize().docWidth;	
	deltaWidth=afterWidth-beforeWidth;
	elem = getBounds(id);
	if(deltaWidth!=0)
	{	
		deltaWidth=deltaWidth+20;
		ge(id).style.left=-deltaWidth+'px';
	}	
	else
	{	
		
		cw=elem.left+elem.width;
		if(cw==afterWidth)
		{				
			deltaWidth=deltaWidth+20;
			ge(id).style.left=-deltaWidth+'px';
		}		
		
	}
}
function doLoad(div,action,value) {
    var req = new JsHttpRequest();
    
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            switch(action){       
            	case 'options':
            		ge(div).style.left='10px';
            		ge(div).innerHTML = req.responseText;           		
            		beforeWidth = getDocSize().docWidth;        		
            		
            	break;
              default:
                ge(div).innerHTML = req.responseText;
              break;
            }
            if(req.responseJS)
            	if(req.responseJS['src'])
            		eval(req.responseJS['src']);
            
        }
    }
    rnd = Math.random(1);         
    req.open(null, '/ajax.php', true);  
    req.send( { q: value ,div: div, action:action,rnd:rnd} );    	
}
function check_str(){ 
     ge('find_form').submit();
}
function switchcol(colnum,flag) {
	
    var tbl = ge('tbl_catalog');
    for (i=0;i<tbl.rows.length;i++) {
    	for (k=0;k<tbl.rows[i].cells.length;k++) {
    		if (colnum == k)
    			if (flag==0) tbl.rows[i].cells[k].style.display='none';
    			else tbl.rows[i].cells[k].style.display='';
    	}
    }
}
function add_span(id,back_num) {
	//if (ge('cols').innerHTML=='') qt=''; else 
	qt=';&nbsp;';
	inner = ge('cols').innerHTML;
	ge('cols').innerHTML = inner + '<span id="span_' + id + '" class="colsspan"><a onclick="rem_span(\'' + id + '\');switchcol(' + back_num + ',1);doLoad(\'\',\'col_update\',{opt:\''+ id + '\',opt_show:1});return false;" class="cols_a">' + ge('t_'+id).innerHTML + '</a>' + qt + '</span>';
}
function rem_span(id) {
	ge('span_' + id).parentNode.removeChild(ge('span_' + id));
}
function invert_row(id) {
	if(ge('tr_info_'+id)) {
		if (ge('tr_info_'+id).style.display=='') {
			ge('tr_info_'+id).style.display='none';
			tmp=ge('tr_'+id).className;
			ge('tr_'+id).className=tmp.replace('tr_open','');
		}
		else {
			ge('tr_info_'+id).style.display='';
			ge('tr_'+id).className=ge('tr_'+id).className+' tr_open';
			
		}
	}
}

function invert_row2(id) {
	if(ge(id)) {
		if (ge(id).style.display=='') {
			ge(id).style.display='none';
		}
		else {
			ge(id).style.display='';			
		}
	}
}

function show_row(id) {
	
	if (ge(id)) ge(id).style.display='';
}
function hide_row(id) {
	if (ge(id)) ge(id).style.display='none';
}
function tr_message(id) {
	if (ge('filter_mess').innerHTML=='') qt=''; else qt='; ';	
	if (!ge('mess_'+id)) {
		tmp=ge('filter_mess').innerHTML;
		ge('filter_mess').innerHTML = "<span id='mess_" + id + "'>" + ge('t_'+id).innerHTML + "</span>" + qt + tmp;
	}
}
function getBounds(element)
{
	element = document.getElementById(element);
	if(element)
	{
	var left = element.offsetLeft;
	var top = element.offsetTop;
	for (var parent = element.offsetParent; parent; parent = parent.offsetParent)
	{
		left += parent.offsetLeft - parent.scrollLeft;
		top += parent.offsetTop - parent.scrollTop
	}
	
	return {left: left, top: top, width: element.offsetWidth, height: element.offsetHeight};
	}
}
function getWinBounds(){
	var width = document.innerWidth?document.innerWidth:document.body.clientWidth;
	var height = document.innerHeight?document.innerHeight:document.body.clientHeight;
	return {width: width, height: height};
}
function getDocSize() {
    var D = document;
 
    return {
        "docWidth":     Math.max(
                            Math.max(D.body.scrollWidth, D.documentElement.scrollWidth),
                            Math.max(D.body.offsetWidth, D.documentElement.offsetWidth),
                            Math.max(D.body.clientWidth, D.documentElement.clientWidth)
                        ),
        "docHeight":    Math.max(
                            Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
                            Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
                            Math.max(D.body.clientHeight, D.documentElement.clientHeight)
                        )
    }
} 
function clear_frm(form,part) {
	form = document.forms[form];
	for (var i = 0; i < form.length; i++) {
  		if (form[i].id.indexOf(part)>-1 && form[i].type=="text") form[i].value='Все'; 
	}
	ge('filter_mess').innerHTML='';
}
function selectItem(li) {
	
	if( li == null ) var sValue = "Ничего не выбрано!";
	if( !!li.extra ) var sValue = li.extra[0];
	else var sValue = li.selectValue;
}
function invertmenu(flag) {
	if (flag==1) {
		ge('left').style.width=0;
		ge('left').style.display='none';
		ge('right').style.width='95%';
	} else {
		ge('left').style.width='22%';
		ge('left').style.display='';
		ge('right').style.width='67%';
	}
}
function change_filter(opt,title){
	//alert(opt+'--'+title);
	if(opt!='opt008')
	{	
		var v='';
		if(ge('filter_'+opt)){		
			v = ge('filter_'+opt).value;			
		}
		if(v=='Все' || v=='')
			$('#flt_'+opt).empty();		
		else
		{		
			if(!ge('flt_'+opt)){
				ge('filter_mess').innerHTML=ge('filter_mess').innerHTML+'<span id=\'flt_'+opt+'\'>'+title+';&nbsp;</span>';
			}	
			else		
				ge('flt_'+opt).innerHTML=title+';&nbsp;';		
			if(arr_old_filter[opt]!=v)
				ge('filter_last_change').innerHTML='<br />Нажмите применить для обновления данных<br />';
			show_row('tbl_message');
		}
	}
}
function selecttr(id,flag,class_) {
	a=" "+class_;
	if (flag) ge(id).className=ge(id).className+a;
	else {
		tmp=ge(id).className;
		ge(id).className=tmp.replace(class_,'');
	}
}
