function ifChn(b,id,html){
        if (b){
                 var obj=document.getElementById(id);
                 if(obj){
                  var parent=obj.parentNode;
                  var odiv=document.createElement('span');
                  parent.replaceChild(odiv, obj);
                  odiv.innerHTML=html;
                 }
        }
}


function getCookieVal (offset){
         var endstr = document.cookie.indexOf (";", offset);
         if (endstr == -1)
         endstr = document.cookie.length;
         return unescape(document.cookie.substring(offset, endstr));
}


function GetCookie (name) {
        var arg = name + "=";
        var alen = arg.length;
        var clen = document.cookie.length;
        var i = 0;
        while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
        return getCookieVal (j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0)
        break;
        }
        return null;
}


function SetCookie (name, value, period) {
        var argv = SetCookie.arguments;
        var argc = SetCookie.arguments.length;
        now= new Date();
        var expires = (period==null) ? "" : new Date(now.getMonth()+1+'-'+(now.getDate()+period)+'-'+now.getYear()+" "+now.getHours()+":"+now.getMinutes()+":"+now.getSeconds());
        var path = (3 < argc) ? argv[3] : null;
        var domain = (4 < argc) ? argv[4] : null;
        var secure = (5 < argc) ? argv[5] : false;


        document.cookie = name + "=" + escape (value) +
        ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +

        ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
        ((path == null) ? "" : ("; path=" + path)) +
        ((domain == null) ? "" : ("; domain=" + domain)) +
        ((secure == true) ? "; secure" : "");
}


function CheckForm (Frm) {
        var i;
        for (i=0; i<Frm.length; i++) {
                 k=Frm.elements[i].value;
                 if ((Frm.elements[i].value == "" )&&(Frm.elements[i].id!="")&&(Frm.elements[i].id.indexOf('!!')==-1)) {
                          alert('Пожалуйста, введите ' + Frm.elements[i].id);
                          Frm.elements[i].focus();
                          return false;
                  }else
                         if ((k.length<2)&&(Frm.elements[i].id!="")&&(Frm.elements[i].id.indexOf('!!')==-1)){
                          alert(Frm.elements[i].id + ' введено некорректно.');
                          Frm.elements[i].focus();
                          return false;
                  }
        }
        return true;
}

function openPopupS(url,w,h) {
         if (zzcms_new_popup2) zzcms_new_popup2.close();

         w=(w)?w:550;
         h=(h)?h:550;

         pl=(document.all)?top.screenLeft:top.screenX;
         pt=(document.all)?top.screenTop:top.screenY;
         ph=(document.all)?document.body.offsetHeight:top.outerHeight;
         pw=(document.all)?document.body.offsetWidth:top.outerWidth;
         l=pl+(pw/2)-(w/2);
         t=pt+(ph/2)-(h/2);

         var posy= (document.body.offsetWidth)/2-275;
         var posx=(document.body.offsetHeight)/2-215;
         var zzcms_new_popup2=window.open(url,'big','width='+w+',height='+h+', toolbar=0,location=0,status=1,menubar=0,scrollbars=1,resizable=0,left='+l+',top='+t)
         zzcms_new_popup2.focus();
}


 var site_new_popup

 function openImagePopup(url,title,w,h) {
        if (site_new_popup) site_new_popup.close();
         pl=(document.all)?top.screenLeft:top.screenX;
         pt=(document.all)?top.screenTop:top.screenY;
         ph=(document.all)?document.body.offsetHeight:top.outerHeight;
         pw=(document.all)?document.body.offsetWidth:top.outerWidth;
         l=pl+(pw/2)-(w/2);
         t=pt+(ph/2)-(h/2);

        w=(w)?w:550;
        h=(h)?h:550;

        if (w>pw) w=pw;
        if (h>ph) h=ph;

        var posy= (document.body.offsetWidth)/2-275;
        var posx=(document.body.offsetHeight)/2-215;
        var site_new_popup=window.open(url,'big','width='+w+',height='+h+', toolbar=0,location=0,status=1,menubar=0,scrollbars=1,resizable=0,left='+l+',top='+t)

         popuphtml='<html><head><title>';
         popuphtml+=title;
         popuphtml+='</title><meta http-equiv="Content-Type" content="text/html; charset=windows-1251"></head><body style="padding:0px; margin:0px;" onclick="self.close()" style="overflow:auto">';
         popuphtml+='<img alt="'+title+'" src="'+url+'">';
         popuphtml+='</body></html>';

         site_new_popup.document.open();
         site_new_popup.document.write(popuphtml);
         site_new_popup.document.close();

        site_new_popup.focus();
}


var IE = (navigator.userAgent && (navigator.userAgent.indexOf("MSIE") != -1));
var FF = (navigator.userAgent && (navigator.userAgent.indexOf("Firefox") != -1));
var OP = (navigator.userAgent && (navigator.userAgent.indexOf("Opera") != -1));

if (IE || OP){
           document.attachEvent("onkeydown",globalKeyCatch);
}else{
           document.addEventListener("keypress",globalKeyCatch,true);
}


function globalKeyCatch(e) {
        var code;
        elem = (!e)?window.event.srcElement:e.target;
        if (!e) e = window.event;

        if (e.keyCode) code = e.keyCode;
        else if (e.which) code = e.which;

        if (!elem || (elem.tagName!="INPUT" && elem.tagName!="TEXTAREA")){

                if ((code == 37) && (e.ctrlKey == true)) {
                        var destination = document.getElementById('previous_page');
                        if (destination) location.href = destination.href;
                }
                if ((code == 39) && (e.ctrlKey == true)) {
                        var destination = document.getElementById('next_page');
                        if (destination) location.href = destination.href;
                }
        }
}


function insertFlash(bnFlash,bnW,bnH,flashV,params,nocashe,transp){
        var rnd = Math.round(Math.random()*1048576);
        var flashID=bnFlash;
        if (bnFlash.indexOf('/')!=-1){
                flashID=bnFlash.split('/');
                flashID=flashID[flashID.length-1];
        }
        flashID=flashID.split('.');
        flashID=flashID[0];

        var flashHtm='';
        flashHtm+='<object codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+bnW+'" height="'+bnH+'" id="'+flashID+'" align="middle">';
        flashHtm+='<param name="allowScriptAccess" value="sameDomain" />';
        flashHtm+=(nocashe)?'<param name="movie" value="'+bnFlash+'?rnd='+rnd+'" />':'<param name="movie" value="'+bnFlash+'" />';
        flashHtm+='<param name="quality" value="high" />';
        flashHtm+='<param name="flashVars" value="'+params+'" />';
        flashHtm+='<param name="bgcolor" value="#ffffff" />';
        if (!transp) flashHtm+='<param name="wmode" value="transparent" />';
        if (!transp)
        flashHtm+='<embed src="'+bnFlash+'" wmode="transparent" flashVars="'+params+'" quality="high" width="'+bnW+'" height="'+bnH+'" name="'+flashID+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
        else
        flashHtm+='<embed src="'+bnFlash+'" flashVars="'+params+'" quality="high" width="'+bnW+'" height="'+bnH+'" name="'+flashID+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
        flashHtm+='</object>';
        document.write(flashHtm);
}



function insertFlash2(bnFlash,bnW,bnH,flashV,params,nocashe,bgcolor){
        var rnd = Math.round(Math.random()*1048576);
        var flashID=bnFlash;
        if (bnFlash.indexOf('/')!=-1){
                flashID=bnFlash.split('/');
                flashID=flashID[flashID.length-1];
        }
        flashID=flashID.split('.');
        flashID=flashID[0];

        var flashHtm='';
        flashHtm+='<object codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+bnW+'" height="'+bnH+'" id="'+flashID+'" align="middle">';
        flashHtm+='<param name="allowScriptAccess" value="sameDomain" />';
        flashHtm+=(nocashe)?'<param name="movie" value="'+bnFlash+'?rnd='+rnd+'" />':'<param name="movie" value="'+bnFlash+'" />';
        flashHtm+='<param name="quality" value="high" />';
        flashHtm+='<param name="flashVars" value="'+params+'" />';
        if (!bgcolor){
             flashHtm+='<param name="wmode" value="transparent" />';
             flashHtm+='<embed src="'+bnFlash+'" wmode="transparent" flashVars="'+params+'" quality="high" width="'+bnW+'" height="'+bnH+'" name="'+flashID+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
        }else{
             flashHtm+='<param name="bgcolor" value="'+bgcolor+'" />';
             flashHtm+='<embed src="'+bnFlash+'" flashVars="'+params+'" quality="high" bgcolor="'+bgcolor+'" width="'+bnW+'" height="'+bnH+'" name="'+flashID+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
        }
        flashHtm+='</object>';
        document.write(flashHtm);
}








//Функция отправки запроса на удаленный URL методом GET. 2й параметр - ф-ия после выполнения запроса

var ajaxReq=false;

function loadXMLDoc(url,func,params) {
        ajaxReq = (window.XMLHttpRequest)?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP");
        ajaxReq.onreadystatechange = func;
        ajaxReq.open("POST",url, true);
        ajaxReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        ajaxReq.setRequestHeader("Accept-Charset", "windows-1251");
        ajaxReq.setRequestHeader("Content-Length",params.length);
        ajaxReq.send(params);
}

function processReqChange() {
        if (ajaxReq){
            abort = window.setTimeout("ajaxReq.abort();", 10000);
            if (ajaxReq.readyState == 4) {
                clearTimeout(abort);
                if (ajaxReq.status == 200) {
                                alert(ajaxReq.responseText);
                } else {
                    alert("Неудачный запрос серверу:n" + ajaxReq.statusText);
                }
            }
    }
}

//------Упрощенная функция отправки запроса (Адрес, ID контейнера, Параметры)

//------Упрощенная функция отправки запроса (Адрес, ID контейнера, Параметры)

function sXMLSendReq(url,id,params){
        var sajaxReqz = (window.XMLHttpRequest)?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP");
        //sajaxReqz.sajaxReqHTMLid=id;
        sajaxReqz.onreadystatechange = function(){sXMLgetReq(sajaxReqz,id)};
        sajaxReqz.open("POST",url, true);
        if (params){
                sajaxReqz.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                sajaxReqz.setRequestHeader("Accept-Charset", "windows-1251");
                sajaxReqz.setRequestHeader("Content-Length",params.length);
        }
        sajaxReqz.send(params);
}

function sXMLgetReq(sajaxReq,sajaxReqHTMLid){

     if (sajaxReq){
                if (sajaxReq.readyState == 4){
                     if (sajaxReq.status == 200 && sajaxReqHTMLid && document.getElementById(sajaxReqHTMLid)){
                          document.getElementById(sajaxReqHTMLid).className="";
                                document.getElementById(sajaxReqHTMLid).innerHTML=sajaxReq.responseText;
                  }else{
                          //   alert("К сожалению, сервер не вернул ответа на посланный запрос. Повторите попутку позднее. " + sajaxReq.statusText);
                    }
             }
     }
}



function objectHTMLById(objectHTMLByIdid,objectHTMLByIdtext){
        if ((objectHTMLByIdobj=document.getElementById(objectHTMLByIdid)) && (objectHTMLByIdtext))
                objectHTMLByIdobj.innerHTML=objectHTMLByIdtext;
}

function getObjectHTML(wid){
        if (getObjectHTMLobj=document.getElementById(wid))
                return (getObjectHTMLobj.innerHTML);
        else
             return false;
}

function objectById(objectByIdid){
        return document.getElementById(objectByIdid);
}

//*------------Крнец функций AJAX



function cfm(prt,url) { //v2.0
  if (confirm(prt))
  {
        location.href=url;

  };
}


var but={
        over:function(obj,width){
                //obj.onmouseover=function(){obj.style.backgroundPosition='-'+width;};
                obj.onmousedown=function(){obj.style.backgroundPosition='-'+width*2;};
                obj.onmouseout=function(){obj.style.backgroundPosition='0';};
                obj.onmouseup=function(){obj.style.backgroundPosition='-'+width;};
                obj.style.backgroundPosition='-'+width;
        }
}
