function mvClick(f, v, a)
{
	f.action = a;
	f.mv_click.value = v;
	f.submit();
}
function orderItem(sku)
{
	document.forms['orderform'].mv_order_quantity.value = document.getElementById('qty-'+sku).value;
	document.forms['orderform'].mv_order_item.value = sku;
}
function nlSignup(f)
{
	if (isEmptyText(f.email.value) || !validEmail(f.email.value))
	{
		alert('Please enter a valid email address before submitting the subscription request.');
		return false;
	}
	else
		return true;
}
function isEmptyText(theValue)
{
	while (theValue.length > 0 && (theValue.charAt(0) == ' ' || theValue.charAt(0) == '\t'))
		theValue = theValue.substring(1, theValue.length);
	while (theValue.length > 0 && (theValue.charAt(theValue.length - 1) == ' ' || theValue.charAt(theValue.length - 1) == '\t'))
		theValue = theValue.substring(0, theValue.length - 1);
	if (theValue == '')
		return true;
	else
		return false;
}
function validEmail(email)
{
        invalidChars = " /:,;";
        if (email == "")
                return false;
        for (i=0; i<invalidChars.length; i++)
	{
                badChar = invalidChars.charAt(i);
                if (email.indexOf(badChar,0) != -1)
                        return false;
        }
        atPos = email.indexOf("@",1);
        if (atPos == -1)
                return false;
        if (email.indexOf("@",atPos+1) != -1)
                return false;
        periodPos = email.indexOf(".",atPos);
        if (periodPos == -1)
                return false;
        if (periodPos+3 > email.length)
                return false;
        return true;
}
var prev_fname, prev_lname, prev_address1, prev_address2, prev_city, prev_state, prev_zip, prev_phone, prev_country;
function fillIt(type,theForm)
{
	if (type == 1)
	{
		prev_fname = theForm.elements['fname'].value;
		prev_lname = theForm.elements['lname'].value;
		prev_address1 = theForm.elements['address1'].value;
		prev_address2 = theForm.elements['address2'].value;
		prev_city = theForm.elements['city'].value;
		prev_state = theForm.elements['state'].value;
		prev_zip = theForm.elements['zip'].value;
		prev_phone = theForm.elements['phone'].value;
		theForm.elements['fname'].value = theForm.elements['b_fname'].value;
		theForm.elements['lname'].value = theForm.elements['b_lname'].value;
		theForm.elements['address1'].value = theForm.elements['b_address1'].value;
		theForm.elements['address2'].value = theForm.elements['b_address2'].value;
		theForm.elements['city'].value = theForm.elements['b_city'].value;
		theForm.elements['state'].value = theForm.elements['b_state'].value;
		theForm.elements['country'].value = theForm.elements['b_country'].value;
		theForm.elements['zip'].value = theForm.elements['b_zip'].value;
		theForm.elements['phone'].value = theForm.elements['b_phone'].value;
	}
	else if (type == 2)
	{
		theForm.elements['fname'].value = prev_fname;
		theForm.elements['lname'].value = prev_lname;
		theForm.elements['address1'].value = prev_address1;
		theForm.elements['address2'].value = prev_address2;
		theForm.elements['city'].value = prev_city;
		theForm.elements['state'].value = prev_state;
		theForm.elements['country'].value = prev_country;
		theForm.elements['zip'].value = prev_zip;
		theForm.elements['phone'].value = prev_phone;
	}
}
var poppedWin = null;
function NewWindow(url)
{
	if (arguments.length === 2)
		opts = arguments[1];
	else
		opts = {};

	var winLabel = opts['winLabel'] || '_blank';
	var width = opts['width'] || 400;
	var height = opts['height'] || 450;
	var scrollable = opts['scrollable'] || 'yes';
	var resizable = opts['resizable'] || 'yes';
	var stripped = opts['stripped'] || 'almost';

	var leftPosition = (screen.width) ? (screen.width-width)/2 : 0;
	var topPosition = (screen.height) ? (screen.height-height)/2 : 0;
	var chromeSettings = (stripped === 'yes' ? ',toolbar=no,location=no,directories=no,status=yes,menubar=no' : stripped === 'almost' ? ',toolbar=no,location=yes,directories=no,status=yes,menubar=no' : ',toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes');

	settings = 'height='+height+',width='+width+',top='+topPosition+',left='+leftPosition+',scrollbars='+scrollable+',resizable='+resizable + chromeSettings;

	if (opts['track'] && opts['ga_acct'])
	{
		var pageTracker = _gat._getTracker(opts['ga_acct']);
		pageTracker._trackPageview(url);
	}

	poppedWin = window.open(url, winLabel, settings);

	if(poppedWin)
		poppedWin.focus();

	return !!poppedWin;
}

