var detailsWindow;
var familyWindow;

function ShowDetails(pref, userid)
{
	var sUrl = pref+"frames/userdetails.php?id="+userid;
	
	try
	{
		if (!detailsWindow || detailsWindow.closed) detailsWindow = window.open(sUrl, "", "width=600,height=515,resizable=no,scrollbars=no,menubar=no,location=no");
		else
		{
			if (detailsWindow.document.URL != sUrl) detailsWindow.location = sUrl;
			detailsWindow.focus();
		}
	}
	catch(err) {alert('Не могу создать окно. Возможно, у Вас стоит блокировщик pop-up окон?');}
}

function ShowFamily(pref, family_id)
{
	var sUrl = pref+"frames/familydetails.php?id="+family_id;
	
	try
	{
		if (!familyWindow || familyWindow.closed) familyWindow = window.open(sUrl, "", "width=600,height=500,resizable=no,scrollbars=no,menubar=no,location=no");
		else
		{
			if (familyWindow.document.URL != sUrl) familyWindow.location = sUrl;
			familyWindow.focus();
		}
	}
	catch(err) {alert('Не могу создать окно. Возможно, у Вас стоит блокировщик pop-up окон?');}
}
function ShowFamilyTree(pref, user_id)
{
	var sUrl = pref+"frames/familytree.php?id="+user_id;
	
	try
	{
		if (!familyWindow || familyWindow.closed) familyWindow = window.open(sUrl, "", "width=600,height=500,resizable=no,scrollbars=yes,menubar=no,location=no");
		else
		{
			if (familyWindow.document.URL != sUrl) familyWindow.location = sUrl;
			familyWindow.focus();
		}
	}
	catch(err) {alert('Не могу создать окно. Возможно, у Вас стоит блокировщик pop-up окон?');}
}

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

function getCookie(name) 
{
	var prefix = name + "=";
	var cookieStartIndex = document.cookie.indexOf(prefix);
	if (cookieStartIndex == -1) return null;
	var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);
	if (cookieEndIndex == -1) cookieEndIndex = document.cookie.length;
	return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}

function CheckFieldLen(field, len)
{
	if (field.value.length > len)
	{
		field.value = field.value.substring(0, len);
		return false;
	}
	return true;
}

function rand (n)
{
	return (Math.floor(Math.random()*n+1));
}