function setCookie(name, value, flag)	{
	var COOKIE;
  	if (flag) {
  		COOKIE = name + "=" + value + "; domain=" + location.protocol + "//" + location.hostname;
  	} else {
  		COOKIE = name + "=" + value + ";";  
  	}
  	document.cookie = COOKIE;
}

function getCookie(name) {
var dc = document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
} else
     begin += 2;
var end = document.cookie.indexOf(";", begin);
if (end == -1)
    end = dc.length;
return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) {
if (getCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
     }
}

var isDHTML = 0;
var isLayers = 0;
var isAll = 0;
var isID = 0;
if (document.getElementByID) {isID=1; isDHTML=1;}
else {
        if (document.all) {isAll=1; isDHTML=1;}
        else { browserVersion = parseInt(navigator.appVersion);
              if ((navigator.appName.indexOf('Netscape') !=-1) && (browserVersion == 4)) {isLayers = 1; isDHTML = 1;}
}}

function findDOMNested(objectID1, objectID2, withStyle) {
	if (withStyle == 1) {
		if (isID) {return (document.getElementById(objectID2).style); }
		else {
			if (isAll) {return (document.all[objectID2].style);}
			else {
				if (isLayers) {
					if (objectID1) {return (document.layers[objectID1]);}
					else {return (document.layers[objectID2]);}
				}
			};}
		}
	else {
		if (isID) {return (document.getElementById(objectID2));}
		else {
			if (isAll) {return (document.all[objectID2]);}
			else {
				if (isLayers)
					if (objectID1) {return (document.layers[objectID1].layers[objectID2]);}
					else {return (document.layers[objectID2]);}
			}
		};}
}

/*function findDOM(objectID,withStyle) {if (withStyle == 1) {if (isID)  {return(document.getElementById(objectID).style); }
                 else { if (isAll) {return (document.all[objectID].style); }
                 else { if (isLayers) {return(document.layers[objectID]); }
};}
}
else {
        if (isID) { return(document.getElementById(objectID));
}
else {
        if (isAll) {return(document.all[objectID]); }
else {
if (isLayers) {return(document.layers[objectID]); }
}
};}
}*/
function findDOM(objectID,withStyle) {
	return (document.getElementById(objectID).style);
}


function findDOMobj(objectID) {
if (isID)  {return(document.getElementById(objectID)); }
                 else { if (isAll) {return (document.all[objectID]); }
                 else { if (isLayers) {return(document.layers[objectID]); }
};}

}


function toggleClamShellSec(objectID) {
     if (isAll || isID) {
          domStyle = findDOM(objectID, 1);
          if (domStyle.display=='block') domStyle.display='none';
          else domStyle.display='block';
     }
     else {
          destination = objectID + '.html';
          self.location = destination;
     }
     return;
}

function RemovePage(filename) {
  		if (confirm('Вы уверены, что желаете удалить страницу?'))
			location.replace(filename); 
		}

function MessageWin(str) {
  			alert(str);
}


function SubRegForm(login, pass1, pass2, email)
{
var re, msg='', sub=1;
re = /([0-9a-zA-Z\.-_]+)@([0-9a-zA-Z\.-_]+)/;

if (login.length == 0) {msg=msg+"Введите логин!\r\n"; sub = 0;}
if (pass1.length == 0) {msg=msg+"Введите пароль!\r\n"; sub = 0;}
if (pass1 != pass2) {msg=msg+"Несовадающие пароли!\r\n"; sub = 0;}
if (email.match(re) == null) {msg=msg+"Неверен или отсутствует e-mail!\r\n"; sub = 0;}

if (sub == 0) window.alert(msg);
if (sub == 1) document.reguser.submit();
}
function MM_popupMsg(msg, filename) {
	if (msg != '') {
  	if (confirm(msg))
		location.replace(filename); 
	}
	else location.replace(filename);
}

function OpenImage(src, title, width, height, url) {
		//window.alert('test');
		if (width < 400) width = 400;
		if (height < 400) height = 400;
		
		if (width > (screen.availWidth-20)) width = screen.availWidth-20;
		if (height > (screen.availHeight-50)) height = screen.availHeight-50;
		//window.alert(height);
		
		var Form = "<html>" +
			"<head>" +
			"<title>"+title+"</title>" +
			"</head>\n" +
			"<body style='margin: 0px; padding:0px; background:#ffffff;'>\n" +
			"<table cellspacing='0px' cellpadding='0px' width='100%' height='100%' border='0'>" +
			"<tr><td style='text-align:center; vertical-align:middle;'>" +
			"<img src='"+src+"' border=0>" +
			"</td></tr>" +
			"</table>" +
			"</body>" +
			"</html>";
		var TabPanel = window.open(url,"TabPanel","dependent=1,width="+width+",height="+height+",status=yes");
		TabPanel.document.open();
        TabPanel.document.write(Form);
        TabPanel.document.close();
}

function menuSel(menu) { menu.className = "window_menu_sel"; }
function menuOut(menu) { menu.className = "window_menu_out"; }

function rowsSel(rows) { rows.className = "window_table_rows_sel"; }
function rowsOut(rows) { rows.className = "window_table_rows_out"; }

function SubAction (select_content, pageid, pagename, location, pagechild) {
	if (select_content == 'delete') {
		if (pagechild == 1) alert ('Нельзя удалить страницу «'+pagename+'».\r\nСначала удалите все вложенные страницы!');
		else MM_popupMsg('Удалить страницу «'+pagename+'» ?', location+'&del='+pageid); 
	}
	else if (select_content == 'move') {
		if(pagechild == 1) alert ('Нельзя переместить страницу «'+pagename+'», пока она имеет вложенные страницы!');
		else if(pagechild == 0) document.location.replace(location+'&move='+pageid);
	}
}

function SubmitSearchForm()
{
var searchwords, sub=1;
searchwords = document.sf.searchwords.value;

if (searchwords.length == 0) {sub = 0;}
if ((searchwords.length != 0) && (searchwords.length <3)) {window.alert('Длина поисковой фразы должна составлять не менее 3 символов'); sub = 0;}

if (sub == 1) document.sf.submit();
}

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 printVer(css, obj, title_tag, title, host, copyrights) {
	var previewWin = window.open('', 'PrintVersion', 'dependent=1,status=0,scrollbars=yes,resizable=nomenubar=yes,location=no,titlebar=0');
	var prTop = '<html><head><title>'+title_tag+'</title><link href="'+css+'" rel="STYLESHEET" type="text/css" /></head><body>';
	var prTitle = '<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td class="title">'+title+'</td><td class="host"><a href="'+host+'">'+host+'</a></td></tr></table><div style="height:7px; width:100%; background-color:#dadbde; font-size:0px;">&nbsp;</div>';
	var prCopyrights = '<div style="height:7px; width:100%; background-color:#dadbde; font-size:0px;">&nbsp;</div>';
	var prBottom = '</noindex><div style="text-align: center; border-top: 1px solid gray; clear: both; padding: 10px 0px;"><br /></div></body></html>';
	var col = findDOMobj(obj);
	var content = col.innerHTML;
	previewWin.document.open();
    previewWin.document.write(prTop+prTitle+content+prCopyrights+prBottom);
    previewWin.document.close();
}

 /* jsHover = function() {
    var hEls = document.getElementById("nav").getElementsByTagName("LI");
    for (var i=0, len=hEls.length; i<len; i++) {
      hEls[i].onmouseover=function() { this.className+=" jshover"; }
      hEls[i].onmouseout=function() { this.className=this.className.replace(" jshover", ""); }
    }
  }
  if (window.attachEvent && navigator.userAgent.indexOf("Opera")==-1) window.attachEvent("onload", jsHover);*/
