 function addBookmark(url, title) {
 if (!url) url = location.href;
 if (!title) title = document.title;
 
 //Gecko
 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();*/
   alert('Ваш браузер не поддерживает' +
    'автоматическое добавление закладок. Нажмите, пожалуйста, Ctrl + D.');
 }
 else return false;
 
 return true;
}

/* функция позваляет определить выбранный элемент  */ 
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='" + selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function getSelectedValue (oListbox)
{

  var arrIndexes;
  for (var i=0; i < oListbox.options.length; i++)
  {
      if (oListbox.options[i].selected)
       {
            arrIndexes = oListbox.options[i].value;
       }
  }

  return arrIndexes;
}

function getSelectedValueStr (oListbox)
{
  var arrIndexes;
  for (var i=0; i < oListbox.options.length; i++)
  {
      if (oListbox.options[i].selected)
       {
            arrIndexes = oListbox.options[i].text;
       }
  }
  return arrIndexes;
}

function SetSelectedElem(name,index)
{
	var objSel = document.getElementById(name); 
 	objSel.selectedIndex = index;
}

/* переход на страничку src */	
function JumpPage(src)
{
 	self.location = src;
}

/*получить объект по запрошенному ID*/
var cashe = new Object();
function GetID(id)
{
	return (cashe[id]) ? cashe[id] : cashe[id] = document.getElementById(id);
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='" + selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


function setCookie (name, value, expires, path, domain, secure) {
      document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}


function getCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}
 
function getRand(min, max){
return Math.round(Math.random()*(max-min))+min;
}

/*Это скрипт, открывающий крупное фото в новом окне*/
function open_photo_window(url) {
	try {
		var title_el = url.parentNode.parentNode.parentNode.getElementsByTagName('h2');
		var title_text = (title_el[0]) ? title_el[0].innerHTML : '';
		var top = Math.ceil((screen.height-480)/2), left = Math.ceil((screen.width-640)/2);
		var properties = 'location=no,menubar=no,resizeble=no,scrollbars=no,status=no,toolbar=no,height=480,width=640,top='+top+',left='+left+'';
		var photo_win = window.open('','',properties)
		with (photo_win.document) {
			writeln('<html><head>');
			writeln('<title>'+title_text+'</title>');
			writeln('<style type="text/css">* {margin:0; paddimg:0} html, body {height:100%} #center {position:absolute; top:50%; left:50%; height:0; width:0} #preloader {position:relative; top:-50px; left:-50px}</style>');
			writeln('<scr'+'ipt type="text/javascript">');
			writeln('function img_loaded(obj) {');
			writeln('var new_height = obj.height - 480;');
			writeln('var new_width = obj.width - 640;');
			writeln('window.resizeBy(new_width, new_height);');
			writeln('var new_top = Math.ceil((screen.height-obj.height)/2), new_left = Math.ceil((screen.width-obj.width)/2);');
			writeln('window.moveTo(new_left, new_top);');
			writeln('document.getElementById(\'center\').style.display = \'none\';');
			writeln('obj.style.visibility = \'visible\';');
			writeln('}');
			writeln('</scr'+'ipt>');
			writeln('</head><body onload="self.focus()">');
			writeln('<div id="center"><img id="preloader" src="/images/loading.gif" width="100" height="100"></div>');
			writeln('<img src="'+url+'" onload="img_loaded(this)" style="visibility:hidden">');
			writeln('</body></html>');
			close();
		}
		return false;
	}
	catch(e) {return true}
	return true;
}



/*Это скрипт, открывающий крупное фото в новом окне*/
function new_window(url,height,width) {
	if(width == undefined)
		 width = 640;
		 
	if(height == undefined)
		 height = 480; 
		
 		var top = Math.ceil((screen.height-height)/2), left = Math.ceil((screen.width-width)/2);
		var properties = 'location=no,menubar=no,resizeble=no,scrollbars=no,status=no,toolbar=no,height='+height+',width='+width+',top='+top+',left='+left+'';
		var photo_win = window.open(url,'',properties)
  
}


function KeyCode(e)
{
	if (!e) e = event || null;  
 	if (!e) return;
	
	var n = e.keyCode?e.keyCode:e.charCode; //Код нажатой клавиши

	return n;
	
}
