

var code = new Array();
	
		function showCode(id){
			
		
		
			if(!code[id] || code[id]==0){
				code[id] = 1;
				document.getElementById('codeCont'+id).style.display = 'block';
			}
			else {
				
				code[id] = 0;
				document.getElementById('codeCont'+id).style.display = 'none';
			
			}
			
			//alert(code[id]);
			
		}


var s_divs =['s_price', 's_units', 's_firms', 's_second'];

function show_search(name){



document.getElementById(name).style.display = 'block';

var i = 0;

/*
	sh_s - s_second
	f_s - s_firms
	u_s - s_units
	pr_s - s_price
	
*/
	
	if(name == 's_second'){
		if (document.getElementById('sh_s')) {
			document.getElementById('sh_s').style.fontWeight = 'bold';
			document.getElementById('sh_s').style.textDecoration = 'none';
			
		}		
		if (document.getElementById('f_s')) {
			document.getElementById('f_s').style.fontWeight = 'normal';
			document.getElementById('f_s').style.textDecoration = 'underline';
		}
		
		if (document.getElementById('u_s')) {
			document.getElementById('u_s').style.fontWeight = 'normal';
			document.getElementById('u_s').style.textDecoration = 'underline';
		}
		if (document.getElementById('pr_s')) {
			document.getElementById('pr_s').style.fontWeight = 'normal';
			document.getElementById('pr_s').style.textDecoration = 'underline';
		}
	}
	
	if(name == 's_price'){
		
		
		if (document.getElementById('sh_s')) {
			document.getElementById('sh_s').style.fontWeight = 'normal';
			document.getElementById('sh_s').style.textDecoration = 'underline';
			
		}		
		if (document.getElementById('f_s')) {
			document.getElementById('f_s').style.fontWeight = 'normal';
			document.getElementById('f_s').style.textDecoration = 'underline';
		}
		
		if (document.getElementById('u_s')) {
			document.getElementById('u_s').style.fontWeight = 'normal';
			document.getElementById('u_s').style.textDecoration = 'underline';
		}
		if (document.getElementById('pr_s')) {
			document.getElementById('pr_s').style.fontWeight = 'bold';
			document.getElementById('pr_s').style.textDecoration = 'none';
		}
	
		
	}
	
	if(name == 's_units'){
		
			
		if (document.getElementById('sh_s')) {
			document.getElementById('sh_s').style.fontWeight = 'normal';
			document.getElementById('sh_s').style.textDecoration = 'underline';
			
		}		
		if (document.getElementById('f_s')) {
			document.getElementById('f_s').style.fontWeight = 'normal';
			document.getElementById('f_s').style.textDecoration = 'underline';
		}
		
		if (document.getElementById('u_s')) {
			document.getElementById('u_s').style.fontWeight = 'bold';
			document.getElementById('u_s').style.textDecoration = 'none';
		}
		if (document.getElementById('pr_s')) {
			document.getElementById('pr_s').style.fontWeight = 'normal';
			document.getElementById('pr_s').style.textDecoration = 'underline';
		}
	
		
	}
	
	if(name == 's_firms'){
		
		if (document.getElementById('sh_s')) {
			document.getElementById('sh_s').style.fontWeight = 'normal';
			document.getElementById('sh_s').style.textDecoration = 'underline';
			
		}		
		if (document.getElementById('f_s')) {
			document.getElementById('f_s').style.fontWeight = 'bold';
			document.getElementById('f_s').style.textDecoration = 'none';
		}
		
		if (document.getElementById('u_s')) {
			document.getElementById('u_s').style.fontWeight = 'normal';
			document.getElementById('u_s').style.textDecoration = 'underline';
		}
		if (document.getElementById('pr_s')) {
			document.getElementById('pr_s').style.fontWeight = 'normal';
			document.getElementById('pr_s').style.textDecoration = 'underline';
		}
	
		
	}
	


	while(s_divs){
//	for(i=0; i<=s_divs.length; i++){	
		if (s_divs[i] != name) {
			document.getElementById(s_divs[i]).style.display = 'none';
		}	
		i++;
	}

}


function move_up_new(up, down, name){
	
	if((new_cur_id - 1)>1){
		document.getElementById(up).className = 'av';
		document.getElementById(down).className = 'av';
	}
	else{
		document.getElementById(up).className = '';
	}
	
	if (new_cur_id > 1) {
		
		new_cur_id = new_cur_id-1;
		new_last_id = new_last_id-1;
		document.getElementById(name+''+new_cur_id).style.display = 'block';
		document.getElementById(name+''+new_last_id).style.display = 'none';
	}
	
	
}

function move_down_new(up, down, name){
	
	if(new_last_id<new_max_id){
		document.getElementById(down).className = 'av';
		document.getElementById(up).className = 'av';
	}
	else{
		document.getElementById(down).className = '';
	}
	
	if (new_last_id < (new_max_id+1)) {	
			
		document.getElementById(name+''+new_last_id).style.display = 'block';
		document.getElementById(name+''+new_cur_id).style.display = 'none';
		new_cur_id = new_cur_id+1;
		new_last_id = new_last_id+1;
	}
	
	
}

//-----------------------------------------------------------------------------------------
function move_up_best(up, down, name){
	
	if((best_cur_id - 1)>1){
		document.getElementById(up).className = 'av';
		document.getElementById(down).className = 'av';
	}
	else{
		document.getElementById(up).className = '';
	}
	
	if (best_cur_id > 1) {
		
		best_cur_id = best_cur_id-1;
		best_last_id = best_last_id-1;
		document.getElementById(name+''+best_cur_id).style.display = 'block';
		document.getElementById(name+''+best_last_id).style.display = 'none';
	}
	
	
}

function move_down_best(up, down, name){
	
	if(best_last_id<best_max_id){
		document.getElementById(down).className = 'av';
		document.getElementById(up).className = 'av';
	}
	else{
		document.getElementById(down).className = '';
	}
	
	if (best_last_id < (best_max_id+1)) {	
			
		document.getElementById(name+''+best_last_id).style.display = 'block';
		document.getElementById(name+''+best_cur_id).style.display = 'none';
		best_cur_id = best_cur_id+1;
		best_last_id = best_last_id+1;
	}
	
	
}

//-----------------------------------------------------------------------------------------
function move_up(up, down, name){
	
	if((cur_id - 1)>0){
		document.getElementById(up).className = 'av';
		document.getElementById(down).className = 'av';
	}
	else{
		document.getElementById(up).className = '';
	}
	
	if (cur_id > 0) {
		
		cur_id = cur_id-1;
		last_id = last_id-1;
		document.getElementById(name+''+cur_id).style.display = 'block';
		document.getElementById(name+''+last_id).style.display = 'none';
	}
	
	
}

function move_down(up, down, name){
	
	if((last_id+1)<max_id){
		document.getElementById(down).className = 'av';
		document.getElementById(up).className = 'av';
	}
	else{
		document.getElementById(down).className = '';
	}
	
	if (last_id < max_id) {	
			
		document.getElementById(name+''+last_id).style.display = 'block';
		document.getElementById(name+''+cur_id).style.display = 'none';
		cur_id = cur_id+1;
		last_id = last_id+1;
	}
	
	
}



//--------------------------------------------------------------------------------------
// hack for ie7+
document.getElementsByClassName = function(cl) { 
        var retnode = []; 
        var myclass = new RegExp('\\b'+cl+'\\b'); 
        var elem = this.getElementsByTagName('*'); 
        for (var i = 0; i < elem.length; i++) { 
        var classes = elem[i].className; 
        if (myclass.test(classes)) retnode.push(elem[i]); 
        } 
        return retnode;
};


//--------------------------------------------------------------------------------------

var dont = 1;
var e = document.getElementsByClassName('add-links');
var i = 0;

function show_third(id){
	
	if (dont != 0) {
	
		for (i = 0; i <= e.length; i++) {
			//alert(i);
			if (e[i]) {
				//alert(e[i].style.display);
				if (e[i].style.display == 'block') 
					e[i].style.display = 'none';
			}
		}
		
		document.getElementById('third[' + id + ']').style.display = 'block';
		
	}
	
}

function close_cur(id){
	document.getElementById('third[' + id + ']').style.display = 'none';
	dont = 0;
}



//----------------------------------------------------------------------------------------------------
function addEngine(engineURL) {
    if (window.external && ("AddSearchProvider" in window.external)) {
        window.external.AddSearchProvider(engineURL);
        return false;
    } else {
        alert(error_opensearch_unsupported);
        return true;
    }
}
function showmap(_firm_,_address_){
        var request=null;
        // пытаемся создать объект для MSXML 2 и старше
        if(!request) try {
                request=new ActiveXObject('Msxml2.XMLHTTP');
        } catch (e){}
        // не вышло... попробуем для MSXML 1
        if(!request) try {
                request=new ActiveXObject('Microsoft.XMLHTTP');
        } catch (e){}
        // не вышло... попробуем для Mozilla
        if(!request) try {
                request=new XMLHttpRequest();
        } catch (e){}
        if(!request){
                // ничего не получилось...
                alert('Не удалось открыть данные. Воспользуйтесь более новой версией браузера.');
                return "";
        }
        d = new Date();
        // делаем запрос содержимого
        webadr = "/showmap.php?address="+_address_+"&firm="+_firm_+"&rndtime="+d.getTime();
        //window.alert(webadr);
        request.open('GET', webadr, false);
        request.send(null);
        document.getElementById('map').innerHTML = request.responseText;
        return false;
}

function showLogin(){
  document.getElementById('hidecont').style.display = 'block';
  document.getElementById('alphadiv').style.display = 'block';
  document.getElementById('logindiv').style.display = 'block';
  document.getElementById('bodydiv').style.overflow = 'hidden';
  document.getElementById('bodydiv').style.height   = '100%';
  return false;
}

function closeLogin(){
  document.getElementById('hidecont').style.display = 'none';
  document.getElementById('alphadiv').style.display = 'none';
  document.getElementById('logindiv').style.display = 'none';
  document.getElementById('bodydiv').style.overflow = '';
  return false;
}

function showHelp(_which_){
  if (_which_ == 'search'){
    document.getElementById('helpsearch').style.display = 'block';
  }
  else{
    document.getElementById('help'+_which_).style.display = 'block';
  }
}

function hideHelp(_which_){
  if (_which_ == 'search'){
    document.getElementById('helpsearch').style.display = 'none';
  }
  else{
    document.getElementById('help'+_which_).style.display = 'none';
  }
}


function preload() {
  if (document.images) {
    var imgsrc = preload.arguments;
    arr=new Array(imgsrc.length);
    for (var j=0; j<imgsrc.length; j++) {
      arr[j] = new Image;
      arr[j].src = imgsrc[j];
    }
  }
}

function _openWindow_new(theURL,winName) {
	var r_w = 400
	var r_h = 180
	var w_h = screen.availHeight
	var w_w = screen.availWidth
	var w_l = (screen.availWidth/2)-(r_w/2)
	var w_t = (screen.availHeight/2)-(r_h/2)
	var params = "status=no,width=" + r_w + ",height=" + r_h + ", left=" + w_l + ", top="+ w_t
	window.open(theURL,winName,params);
}

function _openWindow_new2(theURL,winName) {
    var r_w = 400
    var r_h = 350
    var w_h = screen.availHeight
        var w_w = screen.availWidth
        var w_l = (screen.availWidth/2)-(r_w/2)
        var w_t = (screen.availHeight/2)-(r_h/2)

        var params = "scrollbars,status=no,width=" + r_w + ",height=" + r_h + ", left=" + w_l + ", top="+ w_t
  window.open(theURL,winName,params);
}
function _openWindow_prop(theURL,winName,r_w,r_h) {
    var w_h = screen.availHeight
        var w_w = screen.availWidth
        var w_l = (screen.availWidth/2)-(r_w/2)
        var w_t = (screen.availHeight/2)-(r_h/2)

        var params = "scrollbars,status=no,width=" + r_w + ",height=" + r_h + ", left=" + w_l + ", top="+ w_t
  window.open(theURL,winName,params);
}
function _openWindow_new3(theURL,winName) {
    var r_w = 700
    var r_h = 500
    var w_h = screen.availHeight
        var w_w = screen.availWidth
        var w_l = (screen.availWidth/2)-(r_w/2)
        var w_t = (screen.availHeight/2)-(r_h/2)

        var params = "scrollbars,status=no,width=" + r_w + ",height=" + r_h + ", left=" + w_l + ", top="+ w_t
  window.open(theURL,winName,params);
}

function showInfo(_text_) {
  divchik = document.getElementById('basketadddiv');
  _left_ = (document.body.clientWidth-400)/2;
  _top_ = (document.body.clientHeight-300)/2;

  if (window.scrollY) _topY_ = window.scrollY;
  else _topY_ = document.body.scrollTop;

  divchik.innerHTML=_text_;
  divchik.style.left=_left_;
  divchik.style.top=_topY_+_top_;
  divchik.style.display='block';

}

function pasteExample(_example_){
  document.getElementById('s').value  = _example_;
  document.getElementById('s2').value = _example_;

}


function $(id) {return document.getElementById(id);}

function input_rechange(default_value,id,act){
	if (act == 'click'){
		if (document.getElementById(id).value == default_value){
				document.getElementById(id).value = "";
		}
		document.getElementById(id).style.color = "000000";
	}
	if (act == 'blur'){
		if ($(id).value == "") {$(id).value = default_value;}
		if ($(id).value == default_value) {$(id).style.color = "808080";}
	}
}


function ajax_load_to(select_id, url) {
	var xmlhttp;
    if (window.XMLHttpRequest) {
        try {
            xmlhttp= new XMLHttpRequest();
        } catch (e){}
    } else if (window.ActiveXObject) {
        try {
            xmlhttp= new ActiveXObject('Msxml2.XMLHTTP');
        } catch (e){
          try {
              xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
          } catch (e){}
        }
    }

	this.http = xmlhttp;
	var http = this.http;
	this.http.open("GET", url, true);
	
	this.http.onreadystatechange = function() {
		if (http.readyState == 4){
			if(select_id!='')$(select_id).innerHTML=http.responseText;
		}
	}
	
	this.http.send(null);
	this.http=null;
}

//-------------------------------------------------------------------------------------------

function firm_focus_count(ip, firm, id){
	var tmp = new Date(); 
	var tmp = tmp.getTime();	
	var url = '/firm_focus_count.php?tmp='+tmp;
	var myAjax = new Ajax(url, {method: 'post', data: {ip : ip,
													   firm : firm,
													   id:id}, update: 'firm_cnt_div', evalScripts: true});
	myAjax.request();
}


//-------------------------------------------------------------------------------------------

function space_focus_count(ip, firm){
	var tmp = new Date(); 
	var tmp = tmp.getTime();	
	var url = '/space_focus_count.php?tmp='+tmp;
	var myAjax = new Ajax(url, {method: 'post', data: {ip : ip,
													   firm : firm}, update: 'firm_cnt_div', evalScripts: true});
	myAjax.request();
}

//-------------------------------------------------------------------------------------------

function send_form(url_from){
	var tmp = new Date(); 
	var tmp = tmp.getTime();	
	var url = '/send_mail.php?tmp='+tmp;
	
	var text = document.getElementById('ertext').value;
	var comment = document.getElementById('BoxPromptInput').value; 
	 
	var myAjax = new Ajax(url, {method: 'post', data: {text : text,
													   comment : comment,
													   url_from : url_from},  evalScripts: true});
	myAjax.request();
}
//-------------------------------------------------------------------------------------------
function spec_count(ip, from, to,fid){
	var tmp = new Date(); 
	var tmp = tmp.getTime();	
	var url = '/special_count.php?tmp='+tmp;
	var myAjax = new Ajax(url, {method: 'post', data: {ip : ip,
													   from : from,  
													   to : to, 
													   fid : fid}, update: 'special', evalScripts: true});
	myAjax.request();
}
