﻿var SEARCH_MIN_SIZE=2;
function selectRegion(){
  $("selectregion").show();
}

function closeRegion(){
  $("selectregion").hide();
}

function selectRubric(){
  $("select_rubric").show();
  $("select_district").hide();
}

function closeRubric(){
  opened_what = 0;
  $("select_rubric").hide();
}

function selectDistrict() {
  $("select_district").show();
  $("select_rubric").hide();
}

function closeDistrict() {
  opened_where = 0;
  $("select_district").hide();
}

function startSearch(e){  
  if($('what').getValue()=='название компании, деятельность, телефон'){
    $('what').setValue('');
  }
  if($('where').getValue()=='улица, район, станция метро'){
    $('where').setValue('');
  }
  if (($('what').getValue().trim()=='')&&($('where').getValue().trim()=='')){
    e.stop();
    blurInput();
    return false
  }else{
    var what_size = $F('what').trim().length;
    var where_size = $('where').getValue().trim().length;	
	
    if (((what_size==0)&&(where_size<SEARCH_MIN_SIZE))||
        ((where_size==0)&&(what_size<SEARCH_MIN_SIZE))||
        ((where_size<SEARCH_MIN_SIZE)&&(what_size<SEARCH_MIN_SIZE))){
      alert('Для поиска надо задать слово не менее чем из '+SEARCH_MIN_SIZE+' букв');
      e.stop();
      blurInput();
      return false
    }
  }
}

function focusWhat(){        
  if($('what').getValue()=='название компании, деятельность, телефон'){
    $('what').style.color = 'black';
    $('what').setValue('');
  }
  if($('where').getValue()==''){
    $('where').style.color = 'gray';
    $('where').setValue('улица, район, станция метро');
  }
}
function focusWhere(){
  if($('what').getValue()==''){
    $('what').style.color = 'gray';
    $('what').setValue('название компании, деятельность, телефон');
  }
  if($('where').getValue()=='улица, район, станция метро'){
    $('where').style.color = 'black';
    $('where').setValue('');
  }
}

if(typeof String.prototype.trim !== 'function') {
    String.prototype.trim = function() {
      return this.replace(/^\s+|\s+$/g, ''); 
    }
  } 

function blurInput(){
   
  if($('what').getValue().trim()==''){
    $('what').style.color = 'gray';
    $('what').setValue('название компании, деятельность, телефон');
  }
  if($('where').getValue().trim()==''){
    $('where').style.color = 'gray';
    $('where').setValue('улица, район, станция метро');
  }
  if (document.loginForm3){
    if(document.loginForm3.user.value==''){
      document.loginForm3.user.value='логин';
    }
    if(document.loginForm3.password.value==''){
      document.loginForm3.password.value='пароль';
    }
  }
}

function focusLogin(){
  if(document.loginForm3.user.value=='логин'){
    document.loginForm3.user.style.color='black';
    document.loginForm3.user.value='';
  }
  if(document.loginForm3.password.value==''){
    document.loginForm3.password.style.color='gray';    
    document.loginForm3.password.value='пароль';    
  }
}

function focusPassword(){
  if(document.loginForm3.user.value==''){
    document.loginForm3.user.style.color='gray';
    document.loginForm3.user.value='логин';
  }
  if(document.loginForm3.password.value=='пароль'){
    document.loginForm3.password.style.color='black';
    document.loginForm3.password.value='';
  }
}

function focusFilter(){
  if($('fname').getValue()==''){
    $('fname').style.color = 'gray';
    $('fname').setValue('ключевое слово');
  }
  if($('fname').getValue()=='ключевое слово'){
    $('fname').style.color = 'black';
    $('fname').setValue('');
  }
}

function getBrowserInfo(){
 var t,v = undefined;
 if (window.opera) t = 'Opera';
 else if (document.all) {
  t = 'IE';
  var nv = navigator.appVersion;
  var s = nv.indexOf('MSIE')+5;
  v = nv.substring(s,s+1);
 }
 else if (navigator.appName) t = 'Netscape';
 return {type:t,version:v};
}
 
function addBookmark(a){
 var url = window.document.location;
 var title = window.document.title;
 var b = getBrowserInfo();
 if (b.type == 'IE') window.external.AddFavorite(url,title);
 else if (b.type == 'Opera'){
  a.href = url;
  a.rel = "sidebar";
  a.title = title;
  return true;
 }
 else if (b.type == "Netscape") window.sidebar.addPanel(title,url,"");
 else alert("������� CTRL-D, ����� �������� �������� � ��������.");

 return false;
}

function setHome(a){
  a.style.behavior='url(#default#homepage)';
  a.setHomePage(window.document.location);
  return false;
}

