function ge(id)

{

	return document.getElementById(id);

}







function showNotice(msg,error) {

	var div = document.createElement('div');

	div.style.position='absolute';

	div.id='__noticecontainer';

	div.style.top=document.documentElement.scrollTop + 'px';

	div.style.right='50px';

	div.style.width='200px';

	div.style.height='100px';

	if(!error) {

		div.style.background='#CAE1FF';

	} else {

		div.style.background='#ff9999';

	}

	div.style.padding='10px';

	div.innerHTML=msg;

	document.body.appendChild(div);

	setTimeout('hideNotice()',2000);

}



function hideNotice() {

	document.body.removeChild(ge('__noticecontainer'));

	

}



function extractIFrame(iframeid) {

	return document.getElementById(iframeid).contentWindow.document.body.innerHTML;		

}	



function xframeSubmit() {

	ajaxm.showLoading();

}





function xframeOnload(frameid) {

		try{

				eval(extractIFrame(frameid));

			

			} 

			catch(err) {

				alert('Ошибка!: '+extractIFrame(frameid));

				

			}	

				ajaxm.hideLoading();		

}





function nums(str) {

	

	var abc1 = Object();

	abc1["0"] = "0";

	abc1["1"] = "1";

	abc1["2"] = "2";

	abc1["3"] = "3";

	abc1["4"] = "4";

	abc1["5"] = "5";

	abc1["6"] = "6";

	abc1["7"] = "7";

	abc1["8"] = "8";

	abc1["9"] = "9";

	

	abc1['.'] = '.';

	abc1[','] = '.';



	//str = str.toLowerCase();

	var newstr='';

	for(var i=0;i<str.length;i++) {

		if(abc1[str.substr(i,1)]!==false && abc1[str.substr(i,1)]!=undefined) {	

			newstr=newstr+abc1[str.substr(i,1)];

		

		}		

	}

	return newstr;	

}



function latin(str) {

	

	var abc1 = Object();

	abc1['1'] = '1';

	abc1['2'] = '2';

	abc1['3'] = '3';

	abc1['4'] = '4';

	abc1['5'] = '5';

	abc1['6'] = '6';

	abc1['7'] = '7';

	abc1['8'] = '8';

	abc1['9'] = '9';

	abc1['0'] = '0';

	abc1['q'] = 'q';

	abc1['w'] = 'w';

	abc1['e'] = 'e';

	abc1['r'] = 'r';

	abc1['t'] = 't';

	abc1['y'] = 'y';

	abc1['u'] = 'u';

	abc1['i'] = 'i';

	abc1['o'] = 'o';

	abc1['p'] = 'p';

	abc1['a'] = 'a';

	abc1['s'] = 's';

	abc1['d'] = 'd';

	abc1['f'] = 'f';

	abc1['g'] = 'g';

	abc1['h'] = 'h';

	abc1['j'] = 'j';

	abc1['k'] = 'k';

	abc1['l'] = 'l';

	abc1['z'] = 'z';

	abc1['x'] = 'x';

	abc1['c'] = 'c';

	abc1['v'] = 'v';

	abc1['b'] = 'b';

	abc1['n'] = 'n';

	abc1['m'] = 'm';

	abc1['а'] = 'a';

	abc1['б'] = 'b';

	abc1['в'] = 'v';

	abc1['г'] = 'g';

	abc1['д'] = 'd';

	abc1['е'] = 'e';

	abc1['ё'] = 'jo';

	abc1['ж'] = 'zh';

	abc1['з'] = 'z';

	abc1['и'] = 'i';

	abc1['й'] = 'j';

	abc1['к'] = 'k';

	abc1['л'] = 'l';

	abc1['м'] = 'm';

	abc1['н'] = 'n';

	abc1['о'] = 'o';

	abc1['п'] = 'p';

	abc1['р'] = 'r';

	abc1['с'] = 's';

	abc1['т'] = 't';

	abc1['у'] = 'u';

	abc1['ф'] = 'f';

	abc1['х'] = 'h';

	abc1['ц'] = 'c';

	abc1['ч'] = 'ch';

	abc1['ш'] = 'sh';

	abc1['щ'] = 'w';

	abc1['ъ'] = '';

	abc1['ы'] = 'y';

	abc1['ь'] = '';

	abc1['э'] = 'je';

	abc1['ю'] = 'ju';

	abc1['я'] = 'ja';

	abc1[' '] = '_';

	abc1['_'] = '_';

	

	str = str.toLowerCase();

	var newstr='';

	for(var i=0;i<str.length;i++) {

		if(abc1[str.substr(i,1)]!==false && abc1[str.substr(i,1)]!=undefined) {	

			newstr=newstr+abc1[str.substr(i,1)];

		

		}		

	}

	return newstr;	

}





function ajax() {

   var _request = null;

   var _this = null;

   

  this.showLoading = function() {

  	if(ge('dws_loadingdiv')) {

  		ge('dws_loadingdiv').style.display='block';

  	} else {

	  	var bgdiv =  document.createElement('div');

		var opacity = 0.7;

		

		bgdiv.style.position='absolute';

		bgdiv.style.display="none";	

		bgdiv.style.filter = "alpha(opacity:"+(opacity*100)+")"; //IE

		bgdiv.style.KHTMLOpacity = opacity; // Safari<1.2, Konqueror

		bgdiv.style.MozOpacity = opacity;  // Mozilla and Firefox

		bgdiv.style.opacity = opacity; // Safari 1.2, newer Firefox and Mozilla, CSS3

		bgdiv.style.top = '0px';

		bgdiv.style.left = '0px';

		bgdiv.style.width = '100%';

			



		bgdiv.style.zIndex = '500';

		bgdiv.id='dws_loadingdiv';

		bgdiv.style.background = '#fff';

		document.body.appendChild(bgdiv);

		bgdiv.style.display='block';

  	}

  	if(ge('dws_loadingdivcontent')) {

  		ge('dws_loadingdivcontent').style.display='block';

  		ge('dws_loadingdivcontent').style.top = document.documentElement.scrollTop-20 + 'px';

  		window.onscroll = function() {

			ge('dws_loadingdivcontent').style.top = document.documentElement.scrollTop -20+'px';		

		}

	

  	} else {

		var picdiv = document.createElement('div');

		picdiv.innerHTML='<table width="100%"  style="position:absolute; width:200px; right:0px; top:0px;height:100px;"><tr><td valign="middle" align="right"><table width="200" style="background:#fff; height:50px;"><tr><td align="center"><img class="imageview" src="/admin/templates/img/ajax-loader.gif" /><br/>Загрузка...</td></tr></table></td></tr></table>';

		picdiv.id = 'dws_loadingdivcontent';

		picdiv.style.position='absolute';

		picdiv.style.top = document.documentElement.scrollTop-20 + 'px';

		picdiv.style.left = '0px';

		picdiv.style.width = '100%';

		picdiv.style.height = '50px';

		picdiv.style.zIndex='550';

		

		//picdiv.style.top = document.documentElement.scrollTop + 'px';

		window.onscroll = function() {

			

			ge('dws_loadingdivcontent').style.top = document.documentElement.scrollTop+'px';		

		}

		document.body.appendChild(picdiv);

  	}

  	

  }

  

  this.hideLoading = function() {



	//ge('dws_loadingdiv').style.display='none';

	if(ge('dws_loadingdiv')) ge('dws_loadingdiv').style.display='none';

	if(ge('dws_loadingdivcontent')) ge('dws_loadingdivcontent').style.display='none';

	window.onscroll = function() {

		

	}

	

	

	//if(ge('dws_loadingdivcontent')) document.body.removeChild(ge('dws_loadingdivcontent'))

	//if(ge('dws_loadingdiv')) document.body.removeChild(ge('dws_loadingdiv'));

  	

  }



   this.GetResponseXML = function() {

      return (_request) ? _request.responseXML : null;

   }

       

   this.GetResponseText = function()  {

      return (_request) ? _request.responseText : null;

   }

       

   this.GetRequestObject = function()  {

      return _request;

   }

       

   this.InitializeRequest = function(Method, Uri)  {

      _InitializeRequest();

      _this = this;

               

      switch (arguments.length) {

         case 2:

            _request.open(Method, Uri);

            break;

                               

         case 3:

            _request.open(Method, Uri, arguments[2]);

            break;

      }

               

      if (arguments.length >= 4) _request.open(Method, Uri, arguments[2], arguments[3]);

      this.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");

   }

       

   this.SetRequestHeader = function(Field, Value)   {

      if (_request) _request.setRequestHeader(Field, Value);

   }

       

   this.Commit = function(Data)   {

   	

   	  if(window.dwstemplate) Data+='&dwstemplate='+window.dwstemplate;

      if (_request) _request.send(Data);

   }

       

   this.Close = function()  {

      if (_request) _request.abort();

   }

       

   //---------------------------

   // Public Event Declarations.

   //---------------------------

   this.OnUninitialize = function() { };

   this.OnLoading = function() {

   		//ge('label_loading').style.display='block';   	

   };

   this.OnLoaded = function() { 

 	  	//ge('label_loading').style.display='none';

   };

   this.OnInteractive = function() { };

   this.OnSuccess = function() {  };

   this.OnFailure = function() { };

       

   //---------------------------

   // Private Event Declarations

   //---------------------------

   function _OnUninitialize() { _this.OnUninitialize(); };

   function _OnLoading() { 

  

   	_this.showLoading()	

   	_this.OnLoading();

    };

   function _OnLoaded() {   	_this.OnLoaded(); };

   function _OnInteractive() { _this.OnInteractive(); };

   function _OnSuccess() {

   	_this.hideLoading();

   	_this.OnSuccess(); };

   function _OnFailure() {

    _this.hideLoading();

   	alert('Неудалось соединиться с сервером.');

   	_this.OnFailure();

    };



   //------------------

   // Private Functions

   //------------------

   function _InitializeRequest()   {

      _request = _GetRequest();

      _request.onreadystatechange = _StateHandler;

   }

       

   function _StateHandler()   {

      switch (_request.readyState)

      {

         case 0:

            window.setTimeout("void(0)", 100);

            _OnUninitialize();

            break;

                               

         case 1:

            window.setTimeout("void(0)", 100);

            _OnLoading();

            break;

                               

         case 2:

            window.setTimeout("void(0)", 100);

            _OnLoaded();

            break;

                       

         case 3:

            window.setTimeout("void(0)", 100);

            _OnInteractive();

            break;

                               

         case 4:

            if (_request.status == 200)

               _OnSuccess();

            else

               _OnFailure();

                                       

            return;

            break;

      }

   }

       

   function _GetRequest()   {

      var obj;

               

      try    {

         obj = new XMLHttpRequest();

      }   catch (error)  {

         try  {

            obj = new ActiveXObject("Microsoft.XMLHTTP");

         }    catch (error)       {

            return null;

         }

      }

               

      return obj;

   }	

	

}

function postquery(params) {

	qs = "";

	for(var key in params) {

		if(typeof(params[key])=='object') {

			for(var kk in params[key]) {

				qs+=(qs=='')?'':'&';

				qs+=key+'['+kk+']='+params[key][kk];			

			}

		} else {

			qs+=(qs=='')?'':'&';

			qs+=key+'='+params[key];

		}

	}		

	return qs;

}



function execute(module,procedure,data) {

     if(window.module) data['__sender_module']=window.module;

     if(window.workspace) data['__sender_workspace']=window.workspace;

     data=postquery(data);     

     ajaxm.post('/ajaxprocedure.cp.php','module='+module+'&procedure='+procedure+'&'+data);     

}



function ajaxmanager() {

	this.post = function(link,data){

		if(typeof(data)=='object') data = postquery(data);

		this.InitializeRequest('POST', link);	

     	this.Commit(data);	

		

	}

	

	this.get = function(link) {

		this.InitializeRequest('GET', link);

     	this.Commit(null);

		

	}

	

	this.submitForm = function(method,link,formid,data) {

			if(!data) var data = Object();

			

			for(i=0; i<document[formid].elements.length; i++) {

				switch(document[formid].elements[i].type) {

					case 'text' :						

						data[document[formid].elements[i].name] = document[formid].elements[i].value;

					break;

					case 'password' :						

						data[document[formid].elements[i].name] = document[formid].elements[i].value;

					break;

					case 'hidden' :

						data[document[formid].elements[i].name] = document[formid].elements[i].value;					

					break;

					case 'checkbox' :

						if(document[formid].elements[i].checked==true) {

							data[document[formid].elements[i].name] = document[formid].elements[i].value;

						} 

					break;

					case 'textarea' :

						data[document[formid].elements[i].name] = document[formid].elements[i].value;

					break;

					case 'select-one' :						

						data[document[formid].elements[i].name] = document[formid].elements[i].options[document[formid].elements[i].selectedIndex].value;

					break;

				}

			}

			if(link == '') link = window.location;

			if(method=='GET') {

				this.aget(link,postquery(data));				

			} else {				

				this.post(link,postquery(data));

			}

	}

	

	this.aget = function(link,attr) {

		if(typeof(attr)=='object') attr = postquery(attr);

		this.InitializeRequest('GET', link+'?'+attr);

     	this.Commit(null);

	}

	



	

	

	this.OnSuccess = function()

      {

     //alert(this.GetResponseText());

	     eval(this.GetResponseText());

      }

	

	

}

ajaxmanager.prototype = new ajax();

var ajaxm = new ajaxmanager();

//Делает из дива с айдишником id всплывающее окно
function showwindow(id)
{
 document.overlay = $("#"+id).overlay({

  // custom top position
  top: '50%',
 
  // some mask tweaks suitable for facebox-looking dialogs
  mask: {
 
   // you might also consider a "transparent" color for the mask
   color: '#000000',
 
   // load mask a little faster
   loadSpeed: 200,
 
   // very transparent
   opacity: 0.5
  },
  
  api: true,
 
  // disable this for modal dialog-type of overlays
  closeOnClick: true,
 
  // load it immediately after the construction
  load: true
 
 });
 
 document.overlay.load();
}
