//Загрузка страницы
addEvent(window,'load',function(){

	var src = 'http://counter.yadro.ru/hit?t26.5;r'+
	escape(document.referrer)+((typeof(screen)=='undefined')?'':
	';s'+screen.width+'*'+screen.height+'*'+(screen.colorDepth?
	screen.colorDepth:screen.pixelDepth))+';u'+escape(document.URL)+
	';'+Math.random();
	
	var counter = document.getElementById('counter');
	counter.setAttribute('src',src);
	counter.setAttribute('border','0');
	counter.setAttribute('title','LiveInternet: показано число посетителей за сегодня' );
	counter.setAttribute('border','0');
	counter.setAttribute('width','88');
	counter.setAttribute('height','15');
	
	var a = createElement('a');
	a.setAttribute('href','http://www.liveinternet.ru/?' + location.hostname);
	counter.parentNode.insertBefore(a,counter);
	a.appendChild(counter);

});

// Значение select по событию
function getOption(e) {

	e = e || window.event;
	var el = e.target || e.srcElement;

	return el.options.item(el.selectedIndex).value;

}

// Определяем позицию прокрутки
function getScroll() {
	
	//document.body = document.body || document.getElementsByTagName('body')[0];
	
	var x = y = 0;
	// Gecko поддерживает свойства scrollX(scrollY)
	// Для IE & Opera приходится идти в обход
	x = window.pageXOffset || window.scrollX || document.documentElement.scrollLeft || (document.body && document.body.scrollLeft) || 0;
	y = window.pageYOffset || window.scrollY || document.documentElement.scrollTop || (document.body && document.body.scrollTop) || 0;
	
	return {x:x, y:y};
	
}

//Кодирование строки в url
function urlEncode(str)
{
	str=encodeURIComponent(str);
	return str.replace(/([\!\*\(\)])/g,function(s,p1){
		if(p1=='!'){return '%21'};
		if(p1=='*'){return '%2a'};
		if(p1=='('){return '%28'}else{return '%29'}
	})
}

//Создание элемента с учётом пространства имён
function createElement(name)
{
	if(document.createElementNS && document.documentElement.namespaceURI)
		return document.createElementNS(document.documentElement.namespaceURI,name);
	return document.createElement(name)
}

//Удаление всех детей узла
function removeChild(node)
{
	while(node.hasChildNodes())node.removeChild(node.lastChild)
}

//Навешивание события
function addEvent(obj,event,handler)
{
	if(obj && event && handler){
		if(obj.attachEvent){
			obj.attachEvent('on'+event,handler);
		}else if(obj.addEventListener){
			obj.addEventListener(event,handler,false);
		}
		return handler
	}
}

//Отвешиваем событие
function removeEvent(obj,event,handler)
{
	if(obj && event && handler){
		if(obj.removeEventListener){
			obj.removeEventListener(event,handler,false)
		}else if(obj.detachEvent){
			obj.detachEvent('on'+event,handler)
		}
	}
}

//Ajax запрос требуется расширение timeout для ie
function ajax(param){
	
	this._param=param;
	
	//Создание объекта XMLHttpRequest
	this._xmlhttp = function(){
		
		if(window.XMLHttpRequest){
			try{
				this._req = new XMLHttpRequest();
			}catch(e){}
		}else if(window.ActiveXObject){
			try{
				this._req = new ActiveXObject('Msxml2.XMLHTTP');
			}catch(e){
				try{
					this._req = new ActiveXObject('Microsoft.XMLHTTP');
				}catch(e){}
			}
		}
	}
	
	//Задаём таймаут
	this._setTimeOut = function(){
		
		if(this._param.timeout)
			this._timeOut = setTimeout(function(){this._req.abort();this._param.onFailure('Time over')},this._param.timeout);
	}
	
	//Отменяем таймаут
	this._clearTimeOut = function(){
		
		clearTimeout(this._timeOut)
	}
	
	//Создаём заголовки
	this._setHeaders = function(){
		
		this._req.setRequestHeader('X_REQUESTED_WITH','XMLHttpRequest');
		for(var i in this._param.headers){
			this._req.setRequestHeader(i,this._param.headers[i])
		}
	}
	
	//Инициализация и отправка
	this.send = function(){
		
		this._xmlhttp();
		
		if(this._req){

			this._setTimeOut();
			
			switch(this._param.method){
				case 'get':
					if(this._param.async==false){ //Синхронный
						this._req.open('GET',this._param.action,false);
						this._setHeaders(); //Заголовки
						this._req.send(null); //Отправка
						if(this._req.status == 200){
							this._clearTimeOut(); //Отмена таймаута
							this._param.onSuccess(this._req); //Вызов обработчика
						}else{
							this._param.onFailure('')
						}
					}else{ //Асинхронный
						this._req.open('GET',this._param.action,true);
						this._setHeaders(); //Заголовки
						var self=this;
						this._req.onreadystatechange=function(){
							self._clearTimeOut(); //Отмена таймаута
							if(self._req.readyState == 4){
								if(self._req.status == 200){
									self._param.onSuccess(self._req); //Вызов обработчика
								}else{
									self._param.onFailure('')
								}
							}
						}
						this._req.send(null); //Отправка
					}
					break;
				case 'post':
					if(this.param.async==false){ //Синхронный
						//this._req.open('POST',this._param.action,false)
					}else{ //Асинхронный
						//
					}
					break;
			}
		}
	}
}

/*Приводит IE к стандартному setTimeout и setInterval */
/*@cc_on @*/
/*@if (@_jscript)
function XpandDelaySetter(aMethod) {
    var fnOriginal = window[aMethod],
        bNative = /\[native\scode\]/.test(fnOriginal);
    if (!bNative) {
        return false;
    };
    window[aMethod] = function (aFunc, aDelay, aLang) {
        var oArgs = arguments,
            iLen = oArgs.length,
            iIter = 2,
            vCodeType = typeof (aFunc),
            bCheckLang = iLen === 3 &&
                /^(jscript|javascript|vbscript)$/i.test(aLang),
            bHostMeth = vCodeType == 'object' &&
                /function/.test(aFunc),
            bEval = !Function.prototype.apply || bHostMeth,
            vParams = bEval ? '' : [],
            sDiv = '',
            fnCallBack;
        if (vCodeType == 'string' || bCheckLang) {
            fnCallBack = aFunc;
        } else if ((vCodeType == 'function' || bHostMeth) &&
                iLen > iIter) {
            for (; iIter < iLen; iIter++) {
                bEval ? vParams += sDiv + 'oArgs[' + iIter + ']'
                      : vParams[vParams.length] = oArgs[iIter];
                sDiv = ', ';
            };
            fnCallBack = function () {
                return (bEval
                       ? eval('aFunc(' + vParams + ')')
                       : aFunc.apply(this, vParams));
            };
        };
        return fnOriginal(fnCallBack || aFunc, aDelay, aLang);
    };
};

if (window.execScript) {
    XpandDelaySetter('setTimeout');
    XpandDelaySetter('setInterval');
}
@end @*/