function selectAll(sender, name_prefix)
{
	var form = sender.form;
	var checked_flag = sender.checked;
	var name_len = name_prefix.length;
	
	for(i = 0; i < form.length; i++)
	{
		if(form[i].type == "checkbox" && form[i].name.substr(0,name_len) == name_prefix)
			form[i].checked = checked_flag
	}
	checked_flag = !checked_flag;
}

function isSelected(index)
{
	if(index > 0)
		return true;
	return false;
}

function isChecked(field)
{
	if(field.checked)
		return true;
	return false;
}

function lengthIsOK(input, length)
{
	if(input.length >= length)
		return true;
	return false;
}

function empty(input)
{
	return lengthIsOk(input, 0);
}

function isCC(input)
{
	var cc_pattern = /^([0-9]{16})$/;
	
	if (!input.match(cc_pattern)) 
	{
		return false;
	}
	return true;
}

function isKennitala(kennit) 
{
	kennit = kennit.replace(/(\d{6})-?(\d{4})/, '$1$2');
	if (kennit.length != 10) return false;
	
	// we should be okay by now, so let's start working on the input...
	var sum = kennit.charAt(0) * 3;
	sum = sum + kennit.charAt(1) * 2;
	sum = sum + kennit.charAt(2) * 7;
	sum = sum + kennit.charAt(3) * 6;
	sum = sum + kennit.charAt(4) * 5;
	sum = sum + kennit.charAt(5) * 4;
	sum = sum + kennit.charAt(6) * 3;
	sum = sum + kennit.charAt(7) * 2;
	
	// let's find out what vartala we got...
	var vartala = 11 - (sum % 11);
	if(vartala == 11)
		vartala = 0;
	
	// vartala should equal kennit.charAt(8)
	if(vartala == kennit.charAt(8)) 
	{
		return true;
	}
	else 
	{
		return false;
	}
}

function isEmail(e) 
{
	ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

	for(i=0; i < e.length ;i++)
	{
		if(ok.indexOf(e.charAt(i))<0)
		{ 	
			return (false);
		}	
	} 
	if (document.images) 
	{
		re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
		re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
		if (!e.match(re) && e.match(re_two)) 
		{
			return (-1);		
		} 
	}
}

function isPhone(p)
{
	p = p.replace(/\D/, '');

	if (p.length < 7) return false;
	
	return true;
}

function radioIsChecked(el)
{
	notChecked = (el.length || !el.checked);
	for (i=0,count=el.length; i < count; i++)
	{
		var e = el[i];
		notChecked = !e.checked && notChecked;
	}
	return !notChecked;
}

function checkIsChecked(form, base)
{
	var items = form.getElementsByTagName('INPUT');
	for (i=0, count=items.length; i < count; i++)
	{
		var item = items[i];
		if (item.type == 'checkbox' && item.id.match(base) && item.id.match(base).length > 0)
		{
			if (item.checked) return true;
		}
	}
	return false;
}
