/**
 * Simple wrapper for document.getElementById() method
 */
function ID(ID)
{
	return document.getElementById(ID);
}

/**
 * Simple wrapper for document.getElementsByTagName() method
 */
function Tag(Tag)
{
	return document.getElementsByTagName(Tag);
}

/**
 * Simple wrapper for document.getElementsByName() method
 */
function Name(Name)
{
	return document.getElementsByName(Name);
}

/**
 * Custom implementation of HTML5 document.getElementsByClassName() method
 */
function ClassName(ClassName)
{
	var TagIndex = 0;
	var TagMatched = 0;
	var Elements = new Array();

	var Tags = document.getElementsByTagName('*');
	var Condition = ' ' + ClassName + ' ';
	for (TagIndex = 0; TagIndex < Tags.length; TagIndex++)
	{
		var Pattern = ' ' + Tags[TagIndex].className + ' ';
		if (Pattern.indexOf(Condition) != -1)
		{
			Elements[TagMatched] = Tags[TagIndex];
			TagMatched++;
		}
	}
	return Elements;
}

/**
 * Validates e-mail address
 */
function IsEmail(Email)
{
	var Pattern = /^[a-z0-9-_]+(\.[a-z0-9-_]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/;
	if (Email.length > 0)
	{
		return (Pattern.test(Email)) ?  true : false;
	}
	else
	{
		return false;
	}
}

/**
 * Simple wrapper for confirm method + Redirect if uses answered 'yes'
 */
function Confirm(Text, Url)
{
	if (confirm(Text)) Redirect(Url);
}

/**
 * Simple redirection
 */
function Redirect(Url)
{
	top.location.href = Url;
}

/**
 * Sets cookie
 */
function SetCookie(Name, Value, Days)
{
	if (Days)
	{
		var date = new Date();
		date.setTime(date.getTime() + (Days * 24 * 60 * 60 * 1000));
		var Expires = '; expires=' + date.toGMTString();
	}
	else
	{
		var Expires = '';
	}
	document.cookie = Name + '=' + Value + Expires + '; path=/';
}

/**
 * Gets cookie value
 */
function GetCookie(Name)
{
	var NameEQ = Name + '=';
	var Ca = document.cookie.split(';');
	for (var i = 0; i < Ca.length; i++)
	{
		var C = Ca[i];
		while (C.charAt(0) == ' ') C = C.substring(1, C.length);
		if (C.indexOf(NameEQ) == 0) return C.substring(NameEQ.length, C.length);
	}
	return null;
}

/**
 * Removes cookie
 */
function DeleteCookie(Name)
{
	SetCookie(Name, '', -1);
}

/**
 * Adds window.onload methods preserving ones added previously
 */
function AddOnLoad(OnLoad)
{
	if (typeof OldOnLoad != 'function')
	{
		window.onload = OnLoad;
	}
	else
	{
		window.onload = function()
		{
			OldOnLoad();
			OnLoad();
		}
	}
}