

///// BUTTON 1
but1_1_0 = new Image();
but1_1_0.src = "img/but1_sub1_0.png";
but1_1_1 = new Image();
but1_1_1.src = "img/but1_sub1_1.png";

but1_2_0 = new Image();
but1_2_0.src = "img/but1_sub2_0.png";
but1_2_1 = new Image();
but1_2_1.src = "img/but1_sub2_1.png";

but1_3_0 = new Image();
but1_3_0.src = "img/but1_sub3_0.png";
but1_3_1 = new Image();
but1_3_1.src = "img/but1_sub3_1.png";

but1_4_0 = new Image();
but1_4_0.src = "img/but1_sub4_0.png";
but1_4_1 = new Image();
but1_4_1.src = "img/but1_sub4_1.png";

but1_5_0 = new Image();
but1_5_0.src = "img/but1_sub5_0.png";
but1_5_1 = new Image();
but1_5_1.src = "img/but1_sub5_1.png";

but1_6_0 = new Image();
but1_6_0.src = "img/but1_sub6_0.png";
but1_6_1 = new Image();
but1_6_1.src = "img/but1_sub6_1.png";

but1_small_0 = new Image();
but1_small_0.src = "img/but1_small.png";
but1_small_1 = new Image();
but1_small_1.src = "img/but1_small.gif";

///// BUTTON 2
but2_1_0 = new Image();
but2_1_0.src = "img/but2_sub1_0.png";
but2_1_1 = new Image();
but2_1_1.src = "img/but2_sub1_1.png";

but2_2_0 = new Image();
but2_2_0.src = "img/but2_sub2_0.png";
but2_2_1 = new Image();
but2_2_1.src = "img/but2_sub2_1.png";

but2_3_0 = new Image();
but2_3_0.src = "img/but2_sub3_0.png";
but2_3_1 = new Image();
but2_3_1.src = "img/but2_sub3_1.png";

but2_4_0 = new Image();
but2_4_0.src = "img/but2_sub4_0.png";
but2_4_1 = new Image();
but2_4_1.src = "img/but2_sub4_1.png";

but2_5_0 = new Image();
but2_5_0.src = "img/but2_sub5_0.gif";
but2_5_1 = new Image();
but2_5_1.src = "img/but2_sub5_1.gif";

but2_small_0 = new Image();
but2_small_0.src = "img/but2_small.png";
but2_small_1 = new Image();
but2_small_1.src = "img/but2_small.gif";


///// BUTTON 3
but3_1_0 = new Image();
but3_1_0.src = "img/but3_sub1_0.png";
but3_1_1 = new Image();
but3_1_1.src = "img/but3_sub1_1.png";

but3_2_0 = new Image();
but3_2_0.src = "img/but3_sub2_0.png";
but3_2_1 = new Image();
but3_2_1.src = "img/but3_sub2_1.png";

but3_3_0 = new Image();
but3_3_0.src = "img/but3_sub3_0.png";
but3_3_1 = new Image();
but3_3_1.src = "img/but3_sub3_1.png";

but3_4_0 = new Image();
but3_4_0.src = "img/but3_sub4_0.png";
but3_4_1 = new Image();
but3_4_1.src = "img/but3_sub4_1.png";

but3_5_0 = new Image();
but3_5_0.src = "img/but3_sub5_0.gif";
but3_5_1 = new Image();
but3_5_1.src = "img/but3_sub5_1.gif";

but3_small_0 = new Image();
but3_small_0.src = "img/but3_small.png";
but3_small_1 = new Image();
but3_small_1.src = "img/but3_small.gif";

var Vote=0;
var Votes=[];
var Question=0;
var SearchProps=[];
var SessKey='';
var YesNo=[['1','да'],['-1','нет']];

function AddVote(ch,v) {
 if (ch) {
   Votes.push(v);
 }
 else {
   for(l=0;l<=Votes.length;l++) {
     if (Votes[l]==v) {Votes.splice(l,1,null);}
   }
 }
}

function RequestFailure(resp) {
    alert(resp);
}

function MakeVote(main,qid) {
  if (!qid) {qid=Question;}
  if (!main) {main=false;}
  if (Vote==0) {Vote=$('voting_radio_'+qid).value;}
  request=new Ajax.Request(
                "ajax/makevote.php",
                {
                 method: 'post',
                 parameters: 'votes='+Votes.toString()+'&vote='+Vote+'&main='+main,
                 onComplete: function(resp) {
                   //alert(resp.responseText);
                   if (main) {
                     $('voting_content_main_'+qid).innerHTML=resp.responseText;
                   }
                   else
                   {
                     $('voting_content').innerHTML=resp.responseText;
                   }
                 }
                }
               );
}

function ClickBanner(sid) {
 // alert('click');
  request=new Ajax.Request(
                "ajax/banner.php",
                {
                 method: 'post',
                 parameters: 'sid='+sid
                }
               );
}


///////////////////////////////
 ModifyProps=function(pid,pvalue,multi,on,remove) {
   if (on==false) { multi=-1;}
   // multi=1 - множество значений
  // multi=-1 - удалить значение

  var str='';
  var tid=-1;
  var count=0;
            for(i=0;i<SearchProps.length;i++) {
             if (SearchProps[i][0]==pid) {
             tid=i;
             break;
             }
            }

  if ((pvalue!='0') || (pvalue==null)) {
      ///// Found value
      if (tid>-1) {
          if (remove) {SearchProps[tid][1]=[]; return null; }
          if (multi==1) { SearchProps[tid][2]=2; }
          var len=SearchProps[tid][1].length;
          var l=0;
          for(l=0;l<=len;l++) {
              if (SearchProps[tid][1][l]==pvalue) {
                  count++;
                  if ((on==false) || (multi==-1)) {
                  //SearchProps[tid][1].splice(l,1,null);return null;}
                              //if (multi==-1) {
                               SearchProps[tid][1][l]=null;
                               for(q=l;q<len-1;q++) {
                               // alert('ar['+q+']='+SearchProps[tid][1][q+1]);
                                SearchProps[tid][1][q]=SearchProps[tid][1][q+1];
                                SearchProps[tid][1][q+1]=null;
                               }
                               return null;
                  }
                  break;
              }
          }
          if (multi!=-1) {
              if (count==0) {
               //значение не найдено
               /// Множест
               if (multi==1) {
                if (SearchProps[tid][2]==2) {
                 SearchProps[tid][1][len]=pvalue;
                }
               }
               else  {
                SearchProps[tid][1]=[pvalue];
               }
              }
           }
       }
             else {
                SearchProps.push([pid,[pvalue],1]);
       }
  }
  var str='';
  var nSearch=[];
  for(i=0;i<SearchProps.length;i++) {
   for(j=0;j<SearchProps[i][1].length;j++) {
    if (SearchProps[i][1][j]!=null) { nSearch[j]=SearchProps[i][1][j]; }
   }
   SearchProps[i][1].length=0;
   for(j=0;j<nSearch.length;j++) {
    SearchProps[i][1][j]=nSearch[j];
   }
   nSearch.length=0;
   str+=SearchProps[i][0]+"="+SearchProps[i][1]+";";

  }
  if ($('props-container')) {
    $('props-container').innerHTML=str;
  }
 }

 GetModifiedProps=function(pval) { 
  var str='';
  for(i=0;i<SearchProps.length;i++) {
   if (SearchProps[i][0]==pval)   {
        if (str!='') {str+=', ';} 
        str+=SearchProps[i][1];
   }
  }
   return str;
 }


//////////// COMBO //////////
 SpecialCombo=new Class.create();

 SpecialCombo.prototype={

 initialize: function(masterId,slaveIds,objName) {
  this.ObjectName=objName;
  this.master=masterId;
  this.slaves=Array();
  for(i=0;i<slaveIds.length;i++) { this.slaves[i]=slaveIds[i]; }
  $(this.master).onchange=this.MasterChange.bind(this);
 },

 MasterChange: function() {
    this.ComboRequest(this.master,this.slaves);
    var tid=0;
    for(i=0;i<SearchProps.length;i++) {
     if (SearchProps[i][0]==this.master) { tid=i; break; }
    }
    ModifyProps(this.master,[$(this.master).value],0);
    for(l=0;l<this.slaves.length;l++) {
      ModifyProps(this.slaves[l],[0],0);
      this.BlockSlaves();
    }
 },

 BlockSlaves: function(flag) {
  for(i=0;i<this.slaves.length;i++) {
   if (flag==1) {
    $(this.slaves[i]).className="TheSelectInactive";
    $(this.slaves[i]).options.length=0;
    $(this.slaves[i]).options[0]=new Option('-',0);
   }
   var name=this.slaves[i]+'Combo';
   eval('if (typeof('+name+')!="undefined") { '+name+'.BlockSlaves(1); }');
  }
 },

 FillCombo: function(sId) {
  eval('OptionsArray='+sId+'FillArray');
  var el=$(sId);
  el.options.length=0;
  for(i=0;i<OptionsArray.length;i++) {
    el.options[i]=new Option(OptionsArray[i][0],OptionsArray[i][1]);
  }
  if (i==1) {
   el.disabled='disabled';
   el.className='TheSelectInactive';
  }
  else {
   if (i==2) {
      //ModuleCommon.ModifyProps(sId,el.options[1].value);
      //el.options[1].selected='selected';
    }
   el.disabled='';
   el.className='TheSelect';
  }
  eval(sId+'FillArray.length=0');
  OptionsArray.length=0;
  Loading(false);
 },

 ComboRequest: function(masterId,slaveIds) {
   var slave='';
   var back='';
   for(k=0;k<slaveIds.length;k++) {
    if ($(slaveIds[k]).style.display=='') {
     Loading(true);
    $(slaveIds[k]).options.length=0;
    $(slaveIds[k]).options[0]=new Option('Обновление списка...',0);
    if (slave!='') { slave+=',';}
    slave+=slaveIds[k];
    back+=this.ObjectName+'.FillCombo("'+slaveIds[k]+'");';
   }

    request=new Ajax.Request(
                'ajax/choose.php',
                {
                 method: 'post',
                 parameters: 'action=choose&master='+masterId+'&slave='+slave+'&value='+$(masterId).value,
                 onComplete: function(resp) {
                    // alert(resp.responseText);
                     eval(resp.responseText);
                     eval(back);
                 }
                }
               );
   }
 }
}

 ////////// LOADING
//isDOM=document.getElementById //DOM1 browser (MSIE 5+, Netscape 6, Opera 5+)
//isOpera=window.opera && isDOM //Opera 5+
//isMSIE=document.all && document.all.item && !isOpera //Microsoft Internet Explorer 4+
//isMozilla=isDOM && navigator.appName=="Netscape" //Mozilla или Netscape 6.*

// function getClientWidth()
//{
//  if ((isMSIE) || (isOpera)) { return document.body.offsetWidth; }
//  if (isMozilla) { return window.innerWidth; }
//}

// function getClientHeight()
//{
///  if ((isMSIE) || (isOpera)) { return document.body.offsetHeight; }
//  if (isMozilla) { return window.innerHeight; }
//}

 //////// WINDOW
 PopupWindow=function(txt,buttons,w,h,title,functions) {
  if (!w) {w=300;}
  if (!h) {h=50;}
  if (!title) {title='Форма';}
  var str="<table id=\"popup_window_table\" cellpadding=3><tr><td>"+txt+"</td></tr><tr><td>";
  for(i=0;i<buttons.length;i++) {
   if (i>0) { str+='&nbsp;&nbsp;'; }
   var k=i+1;
   if (typeof(functions)!='undefined') {
       if (functions[i]) {
           func=functions[i];
       } else {func='hideDialog()';}
   } else {func='hideDialog()';}
   str+="<input type=button value=\""+buttons[i]+"\" class=\"button_off\" onmouseover=\"this.className='button_on';\" onmouseout=\"this.className='button_off';\" onclick=\""+func+";return false;\">";
  }
  str+="</td></tr></table>";
  showDialog(title,str,'prompt',false,w,h);
 
 }



////////////////////////////
function Loading(fl) {
 if (fl==true) {
        html="<table width=100%><tr><td align=center><img src=\"img/loading.gif\"></td></tr></table>";
        showDialog('Загрузка',html,'prompt',false,200,25);
  } else {
       hideDialog();
  }
 }

function Sending(fl) {
 if (fl==true) {
     //   html="<table width=100%><tr><td align=center><img src=\"img/loading.gif\"></td></tr></table>";
      //  showDialog('Отправка заявки',html,'prompt',false,200,25);
      Ext.MessageBox.show({
           msg: 'Отправка заявки...',
           progressText: 'Отправка заявки...',
           width:300,
           wait:true
       });

  } else {
        Ext.MessageBox.hide();
        //hideDialog();

  }
 }

function Searching(fl) {
 if (fl==true) {
        html="<table width=100%><tr><td align=center><img src=\"img/loading.gif\"></td></tr></table>";
        showDialog('Поиск',html,'prompt',false,200,25);
  } else {
       hideDialog();
  }
}

 function Authorizing(fl) {
  if (fl==true) {
        html="<table width=100% class=main_text><tr><td align=center><div id=\"auth_msg_div\"><img src=\"img/loading.gif\"></div></td></tr></table>";
        showDialog('Авторизация пользователя',html,'prompt',false,250,70);
  } else {
        hideDialog();
  }
if (!fl) {fl=true;}
 }

 var Sliding=[];

function SlideUpDown(id) {
 if ($(id).style.display=='none') {
  new Effect.SlideDown(id);
 }
 else {
  new Effect.SlideUp(id);
 }
}

var ActiveTab='';

function HoverTab(el,flag,type) {
  if (type=='gray') {h='TabHoverGray';t='TabGray';} else {h='TabHover';t='Tab';}
  if (flag) {
    ActiveTab=el.className;
    el.className=h;
  }
  else {
    if (ActiveTab!='') {
      el.className=ActiveTab;
    }
    else {
      el.className=t;
    }
  }
}

////////////
function Authorize() {
 showDialog("Параметры авторизации",'action=login&hash='+hex_sha1($('login').value+$('password').value)+'&param1='+$('login').value,'success',true,500,100);
 //Authorizing(true);
   request=new Ajax.Request(
                'ajax/authorize.php',
                {
                 method: 'post',
                 parameters: 'action=login&hash='+hex_sha1($('login').value+$('password').value)+'&param1='+$('login').value,
                 onComplete: function(resp) {
                    showDialog("Результат",resp.responseText,'promt',true,500,100);
                    if (resp.responseText!='') {
                      eval(resp.responseText);
                    }                    
                    if (!document.cookie) {
                       PopupWindow('Для полноценной работы с сайтом Вам необходимо включить поддержку cookies в браузере.',['OK']);
                    }
                    if (SessKey=='') {
                     $('auth_msg_div').innerHTML=ErrorMsg+"<br><img src=\"/img/buttons/ok.gif\" id=\"auth_button\" style=\"cursor:pointer;\">";
                     $('auth_button').onclick=Authorizing;
                     $('auth_button').onmouseover=function() {this.src='/img/buttons/ok_on.gif';};
                     $('auth_button').onmouseout=function() {this.src='/img/buttons/ok.gif';};
                    }
                    else {
                        $('logins_div').innerHTML=Greetings;
                        if (($('login_corp_button')) && (typeof(Event)!='undefined')) {
                          eval("$('login_corp_button').onclick=function() {document.location='"+Event+"';};");
                          $('login_corp_button').onmouseover=function() {this.src='/img/buttons/corp_on.gif';}
                          $('login_corp_button').onmouseout=function() {this.src='/img/buttons/corp.gif';}
                        }
                    }
                    //Authorizing(false);
                 }
                }
               );
}




function SetMainRegion(id) {
     document.location="ajax/setregion.php?rid="+id;
}

function MainSearch() {
 var v=MainSearchField.getValue();
 if ((v!='') && (v!='Поиск')) {
   Searching(true);
   request=new Ajax.Request(
                "ajax/mainsearch.php",
                {
                 method: 'post',
                 parameters: 'word='+v,
                 onComplete: function(resp) {
                   if ($('content_div')) {
                     $('content_div').innerHTML=resp.responseText;
                   }
                   else if ($('content_div_wide')) {
                     $('content_div_wide').innerHTML=resp.responseText;
                   }
                   Searching(false);
                 }
                }
               );
 }
}


var ActiveCellId=null;
var ActiveArr=null;
function CreateEdition(el,arr,id) {
   if (!arr) {arr=[];}
    var old=el.innerHTML;
    var re=/\<input/;
    if (!re.test(old)) {
     if ($('edition_cell')) {
        var par=$('edition_cell').parentNode;
        var inn=$('edition_cell').value;
        if (ActiveArr) {ActiveArr[ActiveCellId]=inn;}
        par.innerHTML=inn;
     }
     var w=el.offsetWidth-5;

     el.innerHTML='<input type=text class="TheField" style="width:'+w+'px" value="'+old+'" id="edition_cell">';
     ActiveArr=arr;
     ActiveCellId=id;
     $('edition_cell').onfocus=function() {
        $('edition_cell').onblur=function() {
             if ($('edition_cell')) {
                 var par=$('edition_cell').parentNode;
                 var inn=$('edition_cell').value;
                 if (ActiveArr) {ActiveArr[ActiveCellId]=inn;}
                 par.innerHTML=inn;
              }
        }
     }
    }
 }

 var ActiveCell='';
 function HoverCell(el,flag,h) {
  //if (type=='gray') {h='TabHoverGray';t='TabGray';} else {h='TabHover';t='Tab';}
  if (flag) {
    ActiveCell=el.className;
    el.className=h;
  }
  else {
    if (ActiveCell!='') {
      el.className=ActiveCell;
    }
    else {
      el.className=t;
    }
  }
}

var ActiveDiv='';
function ReplaceDivs(n) {
   if (ActiveDiv!='') {$(ActiveDiv).className='hidden';}
    $(n).className='visible';
    ActiveDiv=n;
}










