function haveAjax() {

   var xmlHttp; // The request object.
   try
   {
     xmlHttp=new XMLHttpRequest();
   }
   catch (e)
   {
       // Internet Explorer
       try
       {
           xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
       }
       catch (e)
       {
         try
         {
             xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
         }
         catch (e)
         {
             return false;
         }
       }
   }
   return true;
}

function scrolling(elem){
    //var scrollstart = document.body.scrollTop ? document.body.scrollTop/50 : document.documentElement.scrollTop/50;
    var scrollstart = $(elem).offsetTop/20;
    //var scroll = document.body.scrollTop ? document.body.scrollTop/50 : document.documentElement.scrollTop/50;
    var scroll = $(elem).offsetTop/20;
    var timer=setInterval(function(){
      var scrolltop = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
      //var scrolltop = $('positioning').offsetTop;
      //alert(parseInt(scrolltop)+" "+scroll);
      if ((parseInt(scrolltop)>$(elem).offsetTop) && (parseInt(scrolltop)-scroll>$('positioning').offsetTop)){
        window.scrollBy(0,-1*scroll);
        scrolltop = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
        //scrolltop = $('positioning').offsetTop;
        scroll = (scrolltop+scrollstart)/(scrollstart);
      } else {
        clearInterval(timer);
        window.scrollTo(0,$(elem).offsetTop);
      }

    },10);
}

function ajax(link,div,param,loader,dofunction){
        var xmlhttp=false;
        //alert(dofunction);
        //alert(link);
        if (div!=null&&parent.document.getElementById(div)&&(parent.document.getElementById(div).tagName=='DIV'||parent.document.getElementById(div).tagName=='TD')){
          if (loader==null||loader==undefined||loader=="") loader='/content/image/loader.gif';
          parent.document.getElementById(div).innerHTML = "<center><table width='100%' class='no'><tr><td align='right' style='text-align:right; vertical-align:middle;' width='40%'><img src='"+loader+"' style='border:0' alt='' title=''/></td><td style='text-align:left;padding-left:10px; vertical-align:middle;' width='60%' align='left'>подождите...</td></tr></table></center>";
        } else if (div!=null&&parent.document.getElementById(div)){
          parent.document.getElementById(div).setAttribute('style','opacity:0.6;');
          if (parent.document.getElementById(div).style.setAttribute) parent.document.getElementById(div).style.setAttribute("filter", "alpha(opacity=60);");
        }
        method="POST";

		if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
			try {
				xmlhttp = new XMLHttpRequest();
			} catch (e) {
				xmlhttp = false;
			}
		}
	    if (!xmlhttp) {
            try {
                xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
            	} catch (e) {
                try {
                       xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                    } catch (e) { }

		}
	    }
        var date=new Date();
        link=link+"?"+date.getTime();
		xmlhttp.open(method, link, true);
		xmlhttp.setRequestHeader("X-REQUESTED-WITH", "XMLHttpRequest");
		xmlhttp.setRequestHeader("AJAX", "AJAX");
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=WINDOWS-1251");
		xmlhttp.onreadystatechange = function()
        {
	        if (xmlhttp.readyState == 4) {
                if (xmlhttp.status == 200){
                    //alert(xmlhttp.responseText);
                    if (xmlhttp.responseText!=''){
                        try{
                        var answer=eval("("+xmlhttp.responseText+")");
                        } catch (e) {
                        var answer=new Object();
                        answer.result = xmlhttp.responseText;
                        }
    	                if (div!=null&&parent.document.getElementById(div)){
            	            if (div!=null&&parent.document.getElementById(div)&&xmlhttp.responseText!='true'){
            	                if ((parent.document.getElementById(div).tagName=='SPAN'||parent.document.getElementById(div).tagName=='A')){
    	                           parent.document.getElementById(div).setAttribute('style','opacity:1;');
    	                           if (parent.document.getElementById(div).style.setAttribute) parent.document.getElementById(div).style.setAttribute("filter", "alpha(opacity=100);");
    	                        }
    	                        if (answer.className!=undefined){
    	                            parent.document.getElementById(div).className=answer.className;
    	                        }
    	                        if (answer.tooltip!=undefined){
    	                            parent.document.getElementById(div).setAttribute('clhint',answer.tooltip);
    	                        }
    	                        if (answer.result!=undefined){
    	                          parent.document.getElementById(div).innerHTML = answer.result;
    	                          if (answer.result=='')
    	                            parent.document.getElementById(div).parentNode.removeChild(parent.document.getElementById(div));
    	                        }
                                }
    			        }
                        if (answer.alert!=undefined) {alert(answer.alert);}
                        if (answer.reload!=undefined) {window.location.reload(true);}
                        if (answer.relocate!=undefined) {document.location = answer.relocate;}
                        if (dofunction!=undefined) dofunction(answer);
                    }
                    xmlhttp=false;
                    if (div=='ajaxcontent')
                        scrolling('positioning');
                } else {
                  xmlhttp=false;
                }
            }
        }

		xmlhttp.send(param);
        return false;
}

function selectajax(link,param,select_id){
        var xmlhttp=false;
        if (select_id!=null&&parent.document.getElementById(select_id)){
          parent.document.getElementById(select_id).options.length=0;
          parent.document.getElementById(select_id).options.length=1; //обрезаем длину селекта до 1
          parent.document.getElementById(select_id).options[0]=new Option("Идет загрузка", 0); //создаем запись что нет элементов
          parent.document.getElementById(select_id).disabled=1; //ставим аттрибует дисаблед
        }
        method="POST";


		if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
			try {
				xmlhttp = new XMLHttpRequest();
			} catch (e) {
				xmlhttp = false;
			}
		}
	    if (!xmlhttp) {
            try {
                xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
            	} catch (e) {
                try {
                       xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                    } catch (e) {}

		}
	    }

		xmlhttp.open(method, link, true);
		xmlhttp.setRequestHeader("X-REQUESTED-WITH", "XMLHttpRequest");
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=WINDOWS-1251");
		xmlhttp.onreadystatechange = function()
        {
	        if (xmlhttp.readyState == 4) {
                if (xmlhttp.status == 200){
    	            if (select_id!=null&&parent.document.getElementById(select_id)){
                        parent.document.getElementById(select_id).options.length=0;
                        parent.document.getElementById(select_id).disabled=0;
                        var answer= xmlhttp.responseXML.documentElement;
                        var options = answer.getElementsByTagName("option");
                        for(i=0;options.length;i++){
                           var text = options[i].firstChild.data; //получаем название элемента
                           var value= options[i].getAttribute("value"); //его номер
                           parent.document.getElementById(select_id).options[i]=new Option(text, value); //добавляем option
                        }
                    }
                    xmlhttp=false;
                } else {
                  xmlhttp=false;
                }
            }
        }
		xmlhttp.send(param);
}

