var d=document;var w=window;var p=parent;var Pref;

if(document.getElementById && navigator.userAgent.indexOf('Opera') < 0)
 Pref = 'document.getElementById(Id)';
else Pref = 'document.all[Id]';

function Wid(Id,Contents){eval(Pref+'.innerHTML = Contents;');}
 
function Widv(Id,Contents){eval(Pref+'.value = Contents');}
function WidSrc(Id,Contents){eval(Pref+'.src = Contents');}
 
function Rido(Id){
 if(eval(Pref) != null)
  if(eval(Pref+'.selectedIndex')!=null && eval(Pref+'.selectedIndex') >= 0)
   return eval(Pref+'.options['+eval(Pref+'.selectedIndex')+'].text');
  else return '';
 else return '';}

function Ridv(Id){
 if(eval(Pref) != null)
  return eval(Pref+'.value');
 else return '';}

function Ridi(Id){
 if(eval(Pref) != null)
  return eval(Pref+'.innerHTML');
 else return '';}
 
function WClass(Id,className){
 if(eval(Pref) != null)
  return eval(Pref+'.className = className');
 else return '';}

function RTag(Id){
 if(eval(Pref) != null)
  return eval(Pref+'.tagName');
 else return '';}


function WStyle(Id,Name,Value)
{
 if(eval(Pref) != null){
  if(document.getElementById)
   eval(Pref+'.style.'+Name+' = "'+Value+'"');
  else if(d.layers)
   eval('document.'+Id+'.'+Name+' = "'+Value+'"');
  else
   eval(Id+'.'+Name+' = "'+Value+'"');}
 else return null;}

function RStyle(Id,Name)
{
 if(eval(Pref) != null){
   return eval(Pref+'.style.'+Name)
 }
 else return null}

function SwapNav(id,act) {
 var dsp;
  if (act == '') { //переключаем видимость
   if (RStyle(id,'display')=='none') {
    dsp = 'block';
     if(RTag(id)=='TR') {
      if(navigator.userAgent.indexOf('Gecko') >= 0 || navigator.userAgent.indexOf('Opera') >= 0) {
       dsp = 'table-row';
      }
     }
   } else {
    dsp = 'none';
   }
  } else { //включаем/выключаем...
   if (act != 'show' || act == false) {
    dsp = 'none';
   } else {
    dsp = 'block';
     if(RTag(id)=='TR') {
      if(navigator.userAgent.indexOf('Gecko') >= 0 || navigator.userAgent.indexOf('Opera') >= 0) {
       dsp = 'table-row';
      }
     }
   }
  }
 WStyle(id,'display',dsp);
}
/*включает-отключает теги tagName с классом tagClassName в контейнере с id = containerId*/
function SwapNavGroup(containerId,tagName,tagClassName,act) {
 var dsp;
 tagName = tagName.toUpperCase(tagName);
 var hEls = document.getElementById(containerId).getElementsByTagName(tagName);
  for (var i=0, len=hEls.length; i<len; i++) {
   if (hEls[i].className.indexOf(tagClassName)>=0 | hEls[i].id.indexOf(tagClassName)>=0) {
    if (act != 'show') {
     dsp = 'none';
    } else {
     dsp = 'block';
      if(hEls[i].tagName=='TR') {
       if(navigator.userAgent.indexOf('Gecko') >= 0 || navigator.userAgent.indexOf('Opera') >= 0) {
        dsp = 'table-row';
       }
      }
    }
    hEls[i].style.display = dsp;
   }
  }
}

/*добавить в Избранное*/
function bookmark(title,url)
{
  if (!url) url = location.href;
  if (!title) title = document.title;
  //FF
  if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) window.sidebar.addPanel (title, url, "");
  //IE4+
  else if (typeof window.external == "object") window.external.AddFavorite(url, title);
  //Opera7+
  else if (window.opera && document.createElement)
  {
    var a = document.createElement('A');
    if (!a) return false; //IF Opera 6
    a.setAttribute('rel','sidebar');
    a.setAttribute('href',url);
    a.setAttribute('title',title);
    a.click();
  }
  else return false;
  return true;
}


function searchItemInSelect (id,searchvalue) {
    var obj = document.getElementById(id);
    for (var i=0;i<obj.options.length;i++) {
     if (searchvalue==obj.options[i].value) {
      obj[i].selected = true;
      break;
     }
    }
}


var Url = {
	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},

	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},

	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++) {

			var c = string.charCodeAt(n);

			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}

		}

		return utftext;
	},

	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;

		while ( i < utftext.length ) {

			c = utftext.charCodeAt(i);

			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}

		}

		return string;
	}
}

/*реализация функции trim*/
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

function showJSBanner(ZoneId) {
 document.write ('<scr' + 'ipt type="text/javascript" src="/BS/abm.asp?z='+ZoneId+'&amp;nt=' + String(Math.random()).substr(2,10) + '"><\/scri' + 'pt>');
 return true;
}

function qs_request(sParamName){
    var Params = location.search.substring(1).split("&"); // отсекаем <?> и вносим переменные и их значения в массив
    var variable = "";
    for (var i = 0; i < Params.length; i++){ // пробегаем весь массив
        if (Params[i].split("=")[0] == sParamName){ // если это искомая переменная - бинго!
            if (Params[i].split("=").length > 1) variable = Params[i].split("=")[1]; // если значение параметра задано, то возвращаем его
            return variable;
        }
    }
    return "";
}

