function $(id)
{
	return document.getElementById(id);
}

function xframeclientOnload(frameid) {
	if($('___xloading')) {
		$('___xloading').style.display='none';		
	}
	try{
	//	alert(extractIFrame(frameid));
		eval(extractIFrame(frameid));
	} 
	catch(err) {
		alert('Ошибка клиентской стороны!');
	}			
}

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 makeoptgroup(label) {
	optgroup = document.createElement('optgroup');
	optgroup.label = label;
	return optgroup;
	
}

function makeoption(text,value,selected) {
	var newoption = document.createElement("OPTION");
	newoption.text = text;
	newoption.value = value;
	return newoption;	
}


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 ajax() {
   var _request = null;
   var _this = null;

   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 (_request) _request.send(Data);
   }
       
   this.Close = function()  {
      if (_request) _request.abort();
   }
       
   //---------------------------
   // Public Event Declarations.
   //---------------------------
   this.OnUninitialize = function() { };
   this.OnLoading = function() {
   		//$('label_loading').style.display='block';   	
   };
   this.OnLoaded = function() { 
 	  	//$('label_loading').style.display='none';
   };
   this.OnInteractive = function() { };
   this.OnSuccess = function() { };
   this.OnFailure = function() { 
   		alert('Неудалось соединиться с сервером. Ошибка #044');
   };
       
   //---------------------------
   // Private Event Declarations
   //---------------------------
   function _OnUninitialize() { _this.OnUninitialize(); };
   function _OnLoading() { _this.OnLoading(); };
   function _OnLoaded() { _this.OnLoaded(); };
   function _OnInteractive() { _this.OnInteractive(); };
   function _OnSuccess() { _this.OnSuccess(); };
   function _OnFailure() { _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 fade(amt,div) {
	if(amt <= 100) {
		setFade(amt,div);
		amt += 10;
		setTimeout("fade("+amt+",'"+div+"')", 5);
    }
}

function setFade(amt,div) {
	obj = document.getElementById(div);
	
	amt = (amt == 100)?99.999:amt;
  
	// IE
	obj.style.filter = "alpha(opacity:"+amt+")";
  
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = amt/100;
  
	// Mozilla and Firefox
	obj.style.MozOpacity = amt/100;
  
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = amt/100;
}

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();
