var sysPath=pPageName+"/System/Constructor/"
var nowSubMenuId="";
document.onmousemove=sidMouseMove;
document.onmouseover=sidMouseOver;
document.onmouseout=sidMouseOut;
document.onclick=sidMouseClick;
document.onkeydown=sidKeyDown;
window.onunload=sidUnload;
window.onresize=sidResize;
function  getE(s){ return(document.getElementById(s))}
function sidHide(s){ if(getE(s)) getE(s).style.visibility="hidden";}
function sidShow(s){ if(getE(s)) getE(s).style.visibility="visible";}
function sidShowCenter(s)
{ el=getE(s);
  eBody=document.body;
  if(el) 
  {  el.style.top=(eBody.clientHeight-el.clientHeight)/2+eBody.scrollTop;
     el.style.left=(eBody.clientWidth-el.clientWidth)/2+eBody.scrollLeft; 
     sidShow(s);
  }   
}
function sidShowWait(strin){}
function sidLoadIAct(sFile){ getE("iAct").src=sFile;}
function getEventElement(ev)
{ var el;
  if (NS && !Oper) 
  { if(!ev.target.tagName || ev.target.tagName=="IMG") el=ev.target.parentNode
    else el=ev.target;
  }
  else
  { el=event.srcElement;
    if (!el) return el;
    if (event.srcElement.tagName=="IMG") el=event.srcElement.parentNode; else el=event.srcElement;
  }
  return el
}
function getEventElement1(ev)
{ var el;
  if (NS && !Oper) el=ev.target.parentNode;
  else 
  { el=event.srcElement;
    if (!el) return el;
    if (event.srcElement.tagName=="IMG") el=event.srcElement.parentNode; else el=event.srcElement;    
  }  
  return el   
}
function sidTreeAct(el)
{ id=el.getAttribute("IM",false); 
  if (!id) return;
  var elChild;
  aIt=getE("admObject6value" + id).getAttribute("MENUSTYLE",false).split(",");
  if (el.cells[0].className=="TI") elChild=el.cells[0]
     else elChild=el.cells[1]
  if (el.className=="FO")
     { elChild.innerHTML=aIt[1];
       el.className="FC";
       act="block";
     }
  else
     { elChild.innerHTML=aIt[0];
       el.className="FO";
       act="none";
     }
  childDiv=el.parentNode.parentNode.parentNode.childNodes;  
  for (i=1;i<childDiv.length;i++) if (childDiv[i].className=="tree") childDiv[i].style.display=act;
}
function sidShowDiv(id)
{  
var el=getE("LHMenu" + id);
var elUpMenu=getE(id);
   if (!el) return;
   if (elUpMenu.offsetTop>2||NS6)
       { iLeft=elUpMenu.offsetLeft;
         iTop=elUpMenu.offsetTop;   
       }
   else
       { iLeft=0;
         iTop=0;
         el1=elUpMenu;
         tagName=el1.tagName;
         while (tagName!="BODY")
             { if (tagName=="TD" || tagName=="TABLE")
               { iTop+=el1.offsetTop;
                 iLeft+=el1.offsetLeft;
               }  
               el1=el1.parentNode;
               tagName=el1.tagName;
             }
        }     
   iTop+=elUpMenu.offsetHeight-5;
   el.style.top=iTop;
   el.style.left=iLeft;
   el.style.visibility="visible";
   if (nowSubMenuId!="" && nowSubMenuId!=elUpMenu.id) getE("LHMenu" + nowSubMenuId).style.visibility="hidden";
   nowSubMenuId=elUpMenu.id;
}
function sidMenuWithSelect(el)
{ if (el.value!="0") 
  { tmpArray=el.value.split(",");
    el.blur()
    subLink(tmpArray[0],tmpArray[1],tmpArray[2]);
  }  
}  

function sidMouseClick(ev)
{ var el;
  el=getEventElement(ev).parentNode;
  if (el.className=="FO" || el.className=="FC") sidTreeAct(el)
  else sidPageClick(el);
  sidExtendedDocumentOnClick();
}

function sidMouseOver(ev)
{ var el=getEventElement(ev);
  if (!el) return;
  sidPageMouseOver();
  sidExtendedDocumentOnMouseOver(el);
}
function sidMouseOut(ev)
{ var el=getEventElement(ev);
  if (!el) return;
  sidPageMouseOut();
  sidExtendedDocumentOnMouseOut(el);
}
function sidMouseMove(ev)
{ if(!bStart) return;
  sidExtendedDocumentOnMouseMove();
  if (nowSubMenuId!="")
      { el=getEventElement(ev);
        if (!getE(nowSubMenuId)) return;
        while ( el.tagName!="BODY")
              { if (el.id==getE(nowSubMenuId).id) return;
                if (el.id==getE("LHMenu" + nowSubMenuId).id) return;
                el=el.parentNode;
              };
        getE("LHMenu" + nowSubMenuId).style.visibility="hidden";
        nowSubMenuId="";
      }
}
function sidKeyDown(e)
{ sidExtendedDocumentOnKeyDown();
  if (NS) return;
  e=self.event;
  if (e.ctrlKey && e.keyCode==68)
     { e.returnValue=false;
       e.cancelBubble=true;
       sidAddFavorite()
     }  
}
function sidGetHeight(iAll,sH)
{ if (sH=="") sH="0";
  if (isNaN(sH)) return parseInt(iAll / 100 * parseInt(sH.replace("%","")));
  else return parseInt(sH);
}
function sidResize()
{ if (windowName!="sidMainWindow" || (NS && !Oper)) return;
  if (pageEdit) return;
  var iAllH,iH=0;  
  iAllH=sidGetHeight(document.body.clientHeight-1,sidPageHeightS);
  if(getE("Head")) iH=getE("Head").offsetHeight;
  if(getE("HMenu")) iH+=getE("HMenu").offsetHeight;
  if(getE("Footer")) iH+=getE("Footer").offsetHeight;
  iAllH-=iH;
  if(!getE("centerTable")) return;
  if (iAllH<100) return;
  getE("centerTable").height=iAllH;
//  if (Oper) 
  iAllH-=15;
  if(getE("DocumentSection1") && getE("DocumentSection3"))
    {
     var iTemp=iAllH-(getE("DocumentSection1").offsetHeight+getE("DocumentSection3").offsetHeight)
     if(iTemp>0) getE("DocumentSection2").style.height=iAllH-(getE("DocumentSection1").offsetHeight+getE("DocumentSection3").offsetHeight)
       else getE("DocumentSection2").style.height=iAllH;
    }
  else getE("DocumentSection2").style.height=iAllH;
}
var sidClickedLink;
function preLink(sUrl,iType,iWin)
{ if (!NS)
     { var el=self.event.srcElement;
       if (parseInt(iWin)==1)
          { if (sidClickedLink) sidClickedLink.style.filter='';
            sidClickedLink=el.parentNode;
            sidClickedLink.style.filter='Alpha(Opacity="50")';
          }
     }
  subLink(sUrl,iType,iWin);
}
function subLink(sUrl,iType,iWin,lay,pBody,pArchive)
{
  if(sUrl=="http://") return;
  if(!bStart) return;
  if(!lay) lay=""
  else
  {  if (getE(lay).style.display=="block") 
        { getE(lay).style.display="none";
          return;
        }  
     else 
        { getE(lay).style.display="block";
          if (getE(lay).innerHTML!="") return;
        }  
   }
  var loc=document.location
  if(!pBody) pBody="";
  if(!pArchive) pArchive="";
  var sFile=sysPath+"load.asp?iType="+iType+"&sValue="+sUrl+"&paramName="+lay+"&pBody="+pBody+"&Archive="+pArchive+sidNoCashe("&");
  var vUrl=vImagePath+sUrl;
  var vFilesUrl=vFilesPath+sUrl;
  var prm="";
  var wnd=parseInt(iWin);
  if(wnd > 1)
    { for(var i=0;i<afldId.length;i++)
          if((parseInt(afldId[i])) == wnd)
          { prm="width="+afldWidth[i]+",height="+afldHeight[i]+
                ",scrollbars="+afldScroll[i]+
                ",location="+afldShow[i]+",menubar="+afldShow[i]+",toolbar="+afldShow[i]+
                ",status="+afldShow[i]+",resizable=1";
            break;
          }
    }
  switch(parseInt(iType)) 
        {
         case 1:
              if(prm == "")
                { if(sUrl.indexOf(".asps",0) > 0) getE("DocumentSection2").innerHTML="<IFRAME ID='inFrame' FRAMEBORDER = 0 SCROLLING=Auto  SRC="+sUrl.replace(".asps",".asp")+" BORDER=0 WIDTH=100% HEIGHT=400></IFRAME>"
                  else
                    {
                     if(sUrl.indexOf("?",0) > 0) sUrl=sUrl+sidNoCashe("&"); else sUrl=sUrl+sidNoCashe("?");
                     if(sUrl.indexOf(".aspa",0) > 0) sidLoadIAct(sUrl.replace(".aspa",".asp"));
                     else loc.href=sUrl;
                    }  
                 }
               else 
                 { 
                   sUrl=sUrl.replace(".aspa",".asp")
                   newWnd=window.open(sUrl.replace(".asps",".asp"),"",prm);
                 }  
               return;
         case 3:
              if(prm == "")
                { if(windowName == "sidMainWindow") getE("DocumentSection2").innerHTML="<SPAN ID=admObject3value" + escape(vUrl) + "><IMG SRC="+escape(vUrl)+" BORDER=0 ALT=''></SPAN>";
                  else loc.href=escape(vUrl);
                }
              else newWnd=window.open(sysPath+"PictureView.asp?sidPictureSrc="+escape(vUrl)+sidNoCashe("&"),"","width=100,height=100,scrollbars=0,location=0,menubar=0,toolbar=0,status=0,resizable=1");//,left=3000,top=3000
              return;
         case 7:
              if(prm == "") loc.href="default.asp?id="+sUrl;
              else newWnd=window.open("default.asp?id="+sUrl+sidNoCashe("&"),"",prm);
              return;
         case 8:
              loc.href=vFilesUrl;
              return;
         case 9:
              if(prm == "") loc.href=pPageName+"/chat/default.asp"+sidNoCashe("?");
              else newWnd=window.open(pPageName+"/chat/default.asp"+sidNoCashe("?"),"",prm);
              return;
         case 10:
              if(prm == "") loc.href=pPageName+"/forum/default.asp"+sidNoCashe("?");
              else newWnd=window.open(pPageName+"/forum/default.asp?sidNewWin=1"+sidNoCashe("&"),"",prm);
              return;
         case 11:
              if(prm == "") loc.href=pPageName+"/GuestBook/default.asp"+sidNoCashe("?");
              else newWnd=window.open(pPageName+"/GuestBook/default.asp?sidNewWin=1"+sidNoCashe("&"),"",prm);
              return;
         case 15:
              if(prm == "") loc.href=pPageName+"/Shop/default.asp?id="+sUrl+sidNoCashe("&");
              else newWnd=window.open(pPageName+"/Shop/default.asp?shopid=" +sUrl+ "&sidNewWin=1"+sidNoCashe("&"),"",prm);
              return;
         case 16:
              sidAddFavorite();
              return;
         case 17: 
              var vUrl=sysPath+"load.asp?iType=17&sValue=/site/images/"+sUrl+sidNoCashe("&");
              sidLoadIAct(vUrl);
              return;              
        }
  if(sUrl=="") return;        
  if(prm == "")
    { if(windowName == "sidMainWindow") sidLoadIAct(sFile);
      else loc.href=sFile+"&newWin=1";
    }
  else 
    { var sPos="";
      if (afldWidth[i]!="" && afldHeight[i]!="") sPos=",Left="+getLeft(afldWidth[i])+",Top="+getTop(afldHeight[i]);
      newWnd=window.open(sFile+"&newWin=1","",prm+sPos);
    }
}
function sidExtendedDocumentOnKeyDown(){}
function sidExtendedDocumentOnMouseMove(){}
function sidExtendedDocumentOnMouseOut(el){}
function sidExtendedDocumentOnMouseOver(el){}
function sidExtendedDocumentOnClick(){}
sidScriptCounter++;
function viewSearch(sql)
{ var sFile=sysPath+"load.asp?iType=12&sValue="+sql+"&pBody=1"+sidNoCashe("&");
  if(windowName == "sidMainWindow") sidLoadIAct(sFile)
  else document.location.href=sFile+"&newWin=1";
}
function sidSimpleSearch(cSite)
{
  var sql=" "+
          "      (fldTitle like '%"+getE("admSearch").admFldSearch.value+"%' or "+
                 "fldName like '%"+getE("admSearch").admFldSearch.value+"%' or "+
                 "fldText like '%"+getE("admSearch").admFldSearch.value+"%') And "+
                 "fldSite="+cSite+" And fldType=1 And fldStatus=1 And fldIncludedInSearch=1 "+
          "Order By fldTitle,fldName"+
          "||"+
          "Search in news"+
          "||"+
          "Search in forum"+
          "||"+
          getE("admSearch").admFldSearch.value;
   if(getE("admSearch").admFldSearch.value.length!=0) viewSearch(escape(sql));
}
function sidAdvancedSearch()
{ searchWnd=window.open(sysPath+"search.asp?name=" +getE("admSearch").admFldSearch.value,"search","scrollbars=0,location=0,menubar=0,toolbar=0,"+
                        "status=0,resizable=0,width=350,height=190,left="+getLeft(350)+",top="+getTop(190));  
}
function sidAddFavorite()
{ if (NS) return;
  var sidUrl,sidTitle;
  sidUrl=document.location.href;
  if(document.title.length==0) sidTitle=document.location.href
  else sidTitle=document.title;
  if(sidUrl.indexOf("load.asp")<0)
  { var sidTemp,q,q2;
    sidTemp="";
    for(q in document.all.tags("SPAN"))
       { if(q.indexOf("admObject")==0)
           { q2=document.all(q).parentNode;
             while(q2.tagName!="BODY")
                  { if(q2.id.indexOf("DocumentSection2")==0) sidTemp=q;
                    q2=q2.parentNode;
                  }
            }
       }
     if(sidUrl.indexOf("?")>0) sidUrl=sidUrl.substr(0,sidUrl.indexOf("?"));
     sidUrl=sidUrl + "?sidFavorites=1&id=" + sidPageId;
     if(sidTemp.lenght!=0)
      { sidTemp=sidTemp.replace("admObject","");
        sidUrl=sidUrl + "&sidObjectValue=" + sidTemp.substr(sidTemp.indexOf("value")+5) +
                        "&sidObjectType=" + sidTemp.substr(0,sidTemp.indexOf("value"));
      }
  }
  window.external.AddFavorite(sidUrl,sidTitle);
}
function sidSetSearchColors()
{  el=getE("admObject13value")
   if(el)
    { if(el.parentNode.style.backgroundColor)
        { var tmpColor=getE("admObject13value").parentNode.style.color;
          var tmpBorderColor=getE("admObject13value").parentNode.style.backgroundColor;
          stSearch=getE("sidSearchbtnSearch");
          stSearch.style.backgroundColor=tmpBorderColor;
          stSearch.style.border="1px solid " + tmpColor;
          stSearch.style.color=tmpColor;
          stSearchAdv=getE("sidSearchbtnAdvSearch").style;
          stSearchAdv.backgroundColor=tmpBorderColor;
          stSearchAdv.border="1px solid " + tmpColor;
          stSearchAdv.color=tmpColor;
          getE("sidSearchfldTxt").style.border="1px solid " + tmpColor;
        }
      else
        { var tmpColor=el.parentNode.parentNode.parentNode.parentNode.parentNode.bgColor;
          getE("sidSearchbtnSearch").style.backgroundColor=tmpColor;
          getE("sidSearchbtnAdvSearch").style.backgroundColor=tmpColor;
        }
    }
}
function sidReturnCalendar(id,sValue)
{ var sFile=sysPath+"load.asp?iType=5&sValue="+id+"&Archive=0&dateArchive="+SQLDate(sValue)+sidNoCashe("&");
  if(windowName == "sidMainWindow") sidLoadIAct(sFile);
  else document.location.href=sFile+"&newWin=1";
}
function SQLDate(pDate)
{ var q=new Date(pDate);
  return q.getFullYear() + "-" + parseInt(q.getMonth()+1) + "-" + q.getDate();
}
function getTop(iTop)    { return parseInt((screen.height-iTop)/2) }
function getLeft(iWidth) { return parseInt((screen.width-iWidth)/2)}

function sidShowCalendar(sDate,sName,sType)
{ calWnd=window.open(sysPath+"calendar.asp?name=" +sName+ "&type="+ sType,"calend","scrollbars=0,location=0,menubar=0,toolbar=0,"+
                     "status=0,resizable=0,width=167,height=194,left="+getLeft(167)+",top="+getTop(174)); 
}
function viewFolder(id,idDoc,TopDirId)
{ if(TopDirId == 0) TopDirId="";
  var sFile=sysPath+"load.asp?iType=2&sValue="+id+"&documentInFolder="+idDoc+"&TopDirId="+TopDirId+sidNoCashe("&");
  if(windowName == "sidMainWindow") sidLoadIAct(sFile)
  else document.location.href=sFile+"&newWin=1";
}
function sidAccess() {
  var aCookie = document.cookie.split(";");
  var acc=false;
  for (var i = 0; i < aCookie.length; i++) {
       var aCrumb = (aCookie[i]).split("=");
       if ("sidUser" == aCrumb[0].replace(" ","") && aCrumb[1]=="enable") acc=true;
  }
  if (!acc) {
      alert("Страница доступна только зарегистрированным пользователям");
      document.location.reload();
  }
}
function sidUnload() {
  document.cookie='sidUser=disable;path=/';
}
var bStart=true;

