function setevent(eventname,functionname)
{
	if (window.addEventListener)
	window.addEventListener(eventname, functionname, false)
	else if (window.attachEvent)
	window.attachEvent(eventname, functionname)
	else if (document.getElementById)
	window.eventname=functionname
}

function focusOnInput(field) {
	field.style.backgroundColor=error_color; field.select(); return true;	
}

function isEmail(field,errormessage) {
	if (field.value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) { field.style.backgroundColor=""; return true}
	else { alert(errormessage); field.style.backgroundColor=error_color;field.select(); return false;}
}

function alNum(field,errormessage) {
	if (field.value.search(/^[A-Za-z0-9]+$/) != -1) { field.style.backgroundColor=""; return true}
	else { alert(errormessage); field.style.backgroundColor=error_color;field.select(); return false;}
}


/********* FUNCTIONS FOR USER PROFILE ********/

function messID(field,errormessage) {
	if (field.value.search(/^[A-Za-z0-9._-]+$/) != -1) { field.style.backgroundColor=""; return true}
	else { alert(errormessage); field.style.backgroundColor=error_color;field.select(); return false;}
}

function optionPozitive(field,errormessage) {
	
	if ((field.value.search(/^[0-9]+$/) != -1) && (field.value > 0) ) { field.style.backgroundColor=""; return true}
	else { alert(errormessage); field.style.backgroundColor=error_color; return false;}
}

function YearMonthOption(field, errormessage) {
	
	if (field.value.search(/^[0-9]{4}-[0-9]{1,2}$/) != -1) { field.style.backgroundColor=""; return true}
	else { alert(errormessage); field.style.backgroundColor=error_color;field.select(); return false;}
	
}

function GameLeagueOption(field, errormessage) {
	
	if (field.value.search(/^[0-9]{2}-[0-9]{1,4}$/) != -1) { field.style.backgroundColor=""; return true}
	else { alert(errormessage); field.style.backgroundColor=error_color;field.select(); return false;}
	
}

/********* FUNCTIONS FOR USER PROFILE ********/

function IsPhone(sText,errormessage)
{
	var ValidChars = "0123456789\/-+#";
	var IsNumber=true;
	var Char;
	sText.style.backgroundColor="";
	if (!((sText.value.length==0)||(sText.value==null)))
	for (i = 0; i < sText.value.length && IsNumber == true; i++)
	{
		Char = sText.value.charAt(i);
		if (ValidChars.indexOf(Char) == -1)
		{
			IsNumber = false;
			sText.style.backgroundColor=error_color;
			alert(errormessage);
			sText.select();
			return IsNumber;
		}
	} else  {IsNumber=false;alert(errormessage);sText.style.backgroundColor=error_color;sText.select();}
	return IsNumber;
}

function IsNumeric(sText,errormessage)
{
	var ValidChars = "0123456789";
	var IsNumber=true;
	var Char;
	sText.style.backgroundColor="";
	if (!((sText.value.length==0)||(sText.value==null)))
	for (i = 0; i < sText.value.length && IsNumber == true; i++)
	{
		Char = sText.value.charAt(i);
		if (ValidChars.indexOf(Char) == -1)
		{
			IsNumber = false;
			sText.style.backgroundColor=error_color;
			alert(errormessage);
			sText.select();
			return IsNumber;
		}
	} else  {IsNumber=false;alert(errormessage);sText.style.backgroundColor=error_color;sText.select();}
	return IsNumber;
}

function IsEmpty(aTextField,errormessage) {
	if ((aTextField.value.length==0) || (aTextField.value==null))  { alert(errormessage);aTextField.select();aTextField.style.backgroundColor=error_color; return false;}
	else { aTextField.style.backgroundColor=""; return true;}
}

function minLength(aTextField,minlength,errormessage)
{
	if (aTextField.value.length<minlength) {alert(errormessage);aTextField.select();aTextField.style.backgroundColor=error_color; return false;}
	else {aTextField.style.backgroundColor=""; return true;}
}

function maxLength(aTextField,maxlength,errormessage)
{
	if (aTextField.value.length>maxlength) {alert(errormessage);aTextField.select();aTextField.style.backgroundColor=error_color; return false;}
	else {aTextField.style.backgroundColor=""; return true;}
}

function checked(aTextField,errormessage)
{
	
	var counter;
	var accessBool = 0;
	
	for (counter=0; counter<aTextField.length; counter++) {
	
		if (aTextField[counter].checked == true) {
			
			accessBool++;
			
			break;
			
		}
	
	} 

	if (!accessBool)  { alert(errormessage);return false;}
	else {return true;}
}

function passwordMatch(input1,input2,errormessage)
{
	if ((input1.value!=input2.value)||(input1.value=="")||(input1.value==null)) {alert(errormessage);input1.style.backgroundColor=error_color;input2.style.backgroundColor=error_color;input1.select();return false;}
	else {input1.style.backgroundColor=""; input2.style.backgroundColor="";return true;}
}
