// Created by Webmaster Joel Purra 20011101
// Do not copy. Copyrighted. www.Fröer.nu

function doAlpha(thing, what)
{
	if (thing.toggled !== true) thing.toggled = false;
	if (what == 'toggle')
	{
		if (thing.toggled === false)
		{
			thing.style.filter = 'alpha(opacity: 100)'; thing.toggled = true;
		} else
		{
			thing.style.filter = 'alpha(opacity: 50)'; thing.toggled = false;
		}
	} else
	{
		if (what === true && !thing.toggled) { thing.style.filter = 'alpha(opacity: 100)'; }
		if (what === false && !thing.toggled) { thing.style.filter = 'alpha(opacity: 50)'; }
	}
}

// Created by Webmaster Joel Purra 20020109
// Do not copy. Copyrighted. www.Fröer.nu

function makeTipWindow(url)
{
	NewWindow(url, 'tipwindow', 550, 200, 'yes');
	return false;
}

function showWordHelp(help_inp)
{
	NewWindow(help_inp, 'helpwindow', 550, 400, 'yes')
	return false;
}

function testUserInput(mail_input)
{
	if (document.all)
	{
		mail_input = new String(mail_input).toLowerCase();
		var test_rx = new RegExp("^[a-z0-9][a-z0-9_\.\-]*@[a-z0-9\.\-]{3,}\.[a-z]{2,5}$", "i");
		if (test_rx.test(mail_input))
		{
			return true;
		} else
		{
			return false;
		}
	} else
	{
		return true;
	}
}

function check(selector, ID, inValue)
{
	var i;
	if (selector.type == "checkbox")
	{
		selector.checked = (ID.toLowerCase() == "true" ? true : false);
	} else
	{
		for (i = 0; i < selector.length; i++)
		{
			if (selector[i].value == ID) { selector.selectedIndex = i; break; }
			if (selector[i].innerText == ID) { selector.selectedIndex = i; break; }
		}
	}
}

function setCheckboxRadioValue(input, value)
{
	for (i = 0; i < input.length; i++)
	{
		if (input[i].value == value)
		{
			input[i].checked = true;
			return true;
		}
	}
	return false;
}
function getCheckboxRadioValue(input)
{
	for (i = 0; i < input.length; i++)
	{
		if (input[i].checked)
		{
			return input[i].value;
			break;
		}
	}
	return null;
}
function setCheckboxRadioDisabled(input, disabled)
{
	for (i = 0; i < input.length; i++)
	{
		input[i].disabled = disabled;
	}
}
function setInputNumberedDisabled(input, from, to, disabled)
{
	for (i = from; i < to; i++)
	{
		eval(input + i + ".disabled = " + disabled + ";");
	}
}

function PIDsOnly(value)
{
	if (/[^\d\s]/g.test(new String(value)))
	{
		alert('Använd endast siffror i artikelnummersökningen');
		return false;
	} else
	{
		return true;
	}
}

/*
Auto center window script- Eric King (http://redrival.com/eak/)
Permission granted to Dynamic Drive to feature script in archive
For full source, usage terms, and 100's more DHTML scripts, visit http://dynamicdrive.com
*/
/**********************************************************************************
*   Changes by Joel Purra, joel@froer.nu
*   In use @ www.fröer.nu. Thank you Eric King!
**********************************************************************************/

var mywin = null;
function NewWindow(mypage, myname, myw, myh, myscroll)
{
	myLeftPosition = (screen.width) ? (screen.width - myw) / 2 : 50;
	myTopPosition = (screen.height) ? (screen.height - myh) / 2 : 50;
	mysettings = 'height=' + myh + ',width=' + myw + ',top=' + myTopPosition + ',left=' + myLeftPosition + ',scrollbars=' + myscroll + ', directories=false, location=false, menubar=false, resizable=yes, status=false, toolbar=false';
	mywin = window.open(mypage, myname, mysettings);
	return false;
}
