var detailsWindow;
var familyWindow;

function ShowDetails(pref, userid)
{
	var sUrl = pref+"frames/userdetails.php?id="+userid;

	try
	{
		window.open(sUrl, "", "width=600,height=520,resizable=no,scrollbars=no,menubar=no,location=no");
	}
	catch(err) {alert('Не могу создать окно. Возможно, у Вас стоит блокировщик pop-up окон?');}
}

function ShowFamily(pref, family_id)
{
	var sUrl = pref+"frames/familydetails.php?id="+family_id;

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

	try
	{
		window.open(sUrl, "", "width=600,height=500,resizable=no,scrollbars=yes,menubar=no,location=no");
	}
	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));
}

function ImageGray(image)
{
	if(/*@cc_on!@*/false)
	{
		image.style.filter = 'gray';
	}
	else
	{
		var oldSrc = image.src;
		image.normalSrc = image.src;
		try
		{
			var myCanvas=document.createElement("canvas");
			var myCanvasContext=myCanvas.getContext("2d");
			
			var imgWidth=image.width;
			var imgHeight=image.height;
			myCanvas.width= imgWidth;
			myCanvas.height=imgHeight;
			myCanvasContext.drawImage(image,0,0);
			var imageData=myCanvasContext.getImageData(0,0, imgWidth, imgHeight);
			for (i=0; i<imageData.height; i++)
			{
				for (j=0; j<imageData.width; j++)
				{
					var index=(i*4)*imageData.width+(j*4);
					var red=imageData.data[index];
					var green=imageData.data[index+1];
					var blue=imageData.data[index+2];
					var alpha=imageData.data[index+3];
					var average=(red+green+blue)/3;
					imageData.data[index]=average;
					imageData.data[index+1]=average;
					imageData.data[index+2]=average;
					imageData.data[index+3]=alpha;
				}
			}
			myCanvasContext.putImageData(imageData,0,0,0,0, imageData.width, imageData.height);
			image.src = myCanvas.toDataURL();
		}
		catch(e)
		{
			image.src = oldSrc;
			image.normalSrc = '';
		}
	}
}

function ImageUngray(image)
{
	if(/*@cc_on!@*/false)
	{
		image.style.filter = '';
	}
	else
	{
		if(image.normalSrc && image.normalSrc != '')
		{
			image.src = image.normalSrc;
		}
	}
}

function ShowPageDialog(dialog_id)
{
	document.getElementById("lock_page").style.display = "block";
	document.getElementById("lock_page").style.height = document.body.scrollHeight;
	document.getElementById(dialog_id).style.display = "block";
	document.getElementById(dialog_id).style.top = 100 + document.body.scrollTop;
}

function HidePageDialog(dialog_id)
{
	document.getElementById("lock_page").style.display = "none";
	document.getElementById(dialog_id).style.display = "none";
}

