function setCookie(name, value, flag)	{
	var COOKIE;
  	if (flag) {
  		COOKIE = name + "=" + value + "; domain=" + location.protocol + "//" + location.hostname;
  	} else {
  		COOKIE = name + "=" + value + ";";  
  	}
  	document.cookie = COOKIE;
}


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 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 PopupMsgForm(msg, formname) {
  	if (confirm(msg))
		 document.forms[formname].submit();	
}


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='0' cellpadding='0' 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);
		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, http_url, copyrights, site, links) {
	var previewWin = window.open('', 'PrintVersion', 'dependent=1,status=0,scrollbars=yes,resizable=no,menubar=yes,location=no,titlebar=1');
	var prTop = '<html><head><title>'+title_tag+'</title><link href="'+css+'" rel="STYLESHEET" type="text/css" /><script type=\'text/javascript\' src=\''+http_url+'javascript/print.js\'></script></head><body>';
	var prTitle = '<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td class="title">'+title+'</td><td class="host"><a href="'+http_url+'">'+site+'</a> ['+http_url+']</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><div style="float:right; padding-top:10px; font-size:10px;"><a href=# onClick="window.print()">Распечатать</a></div><div style="padding-top:10px; font-size:10px;">'+copyrights+'</div>';
	var prBottom = '</body></html>';
	var col = findDOM(obj);
	var content = '<div id="content" style="padding:5px 0px 5px 0px;">'+col.innerHTML+'</div>';
	var links = '<div id="links" style="clear:both;"></div>';
	previewWin.document.open();
    previewWin.document.write(prTop+prTitle+content+links+prCopyrights+prBottom);
    previewWin.document.close();
}

var oldPubMon;
var PubMon;
function publicCalendar(objectID, defID) {
	  //PubMon = document.getElementById(objectID).style.display;
      if(!oldPubMon) 
	  	oldPubMon = document.getElementById(defID).style;
      if (oldPubMon) 
	  	oldPubMon.display = 'none';
      document.getElementById(objectID).style.display = "";
      oldPubMon = document.getElementById(objectID).style;
}

function publicAuth(elem) {
	   if (document.getElementById(elem).style.display != "") { 
           document.getElementById(elem).style.display = "";
        }
        else {
           document.getElementById(elem).style.display = "none";
        }
        return false;
}
