function ProcessGroupEMail()
{
	var myform = document.forms[0];	
	var strList = "";
	var bMultEmails = 0;
	var arrList = new Array();
	var nArrNum = 0;
	for (var i=0; i < myform.elements.length; i++)
	{
		if (myform.elements[i].type == "checkbox")
		{
			if (myform.elements[i].checked == true)
			{
				// There is a limit of 2048 characters for the mailto URL - Q208427
				// Long lists must be split up into several lists - so split it much earlier(1800)
				if (strList.length > 800)
				{
		//alert(strList.length);
					bMultEmails = 1;
					strList = strList + myform.elements[i].value + ";";
					nArrNum = nArrNum + 1;
					arrList[nArrNum - 1] = strList;
					strList = "";
		//alert(nArrNum);
				}
				else
				{
					strList = strList + myform.elements[i].value + ";";
				}
			}
		}		
	}

	// Grab the rest of the addresses (if necessary) once we're done looping
	// Note that this length will be < 1800 chars
	if (bMultEmails == 1)
	{
		nArrNum = nArrNum + 1;
		arrList[nArrNum - 1] = strList;
	}

	if ((strList.length == 0) && (bMultEmails == 0))
	{
		alert("You haven't selected anyone. Please click the 'Group EMail' checkbox for at least one person.");
	}
	else
	{
		// open an email message
		if (bMultEmails == 1)
		{
			alert("The selected email list has a character length greater than 2048 characters.\n\nTherefore, it will be split into " + nArrNum + " emails.");

			// Loop thru each arr ele for the mailto list
			var strEleList = "";
			for (var j=0; j < nArrNum; j++)
			{
//alert(j);
				strEleList = "mailto:" + arrList[j];
				location.href = strEleList;
				for (var k=0; k < 10000; k++)
				{
					var m = 0;
					m = m + 1;
				}

//				var picWin = null;

//		if (picWin == null || picWin.closed)
//		{
			//window.open(strEleList);
			//window.setInterval(OpenWindow(strEleList), 2000);
//		}
//	else
//		{
//			picWin.location = file;
//			picWin.focus();
//		}
//	}








			}
		}
		else
		{
			// Open the one and only strList
			location.href = "mailto:" + strList;
		}
	}
}

function SelectAll()
{
	var myform = document.forms[0];
	for (var i=0; i < myform.elements.length; i++)
	{
		if (myform.elements[i].type == "checkbox")
		{
			myform.elements[i].checked = true;
		}		
	}
}

function Validate()
{
	var myform = document.forms[0];
	var fname = myform.first.value;		//required
	var lname = myform.last.value;		//required
	var country = myform.country.value;	//required
	var model = myform.model.value;		//required
	var year = myform.year.value;		//required
	var city = myform.city.value;		//required
	var color = myform.color.value;		//required
	
	//firstname
	fname = TrimBlanks(fname);
	if (fname == "")
	{
		myform.first.value = "";
		alert("Please enter a first name.");
		myform.first.focus();
		return false;
	}
	
	//lastname
	lname = TrimBlanks(lname);
	if (lname == "")
	{
		myform.last.value = "";
		alert("Please enter a last name.");
		myform.last.focus();
		return false;
	}
	
	//country
	if (country == "none")
	{
		alert("Please select a country.");
		myform.country.focus();
		return false;	
	}

	//state - always check this (do not use else if)
	if (country == "US")
	{
		if (myform.state.value == "none" || myform.state.value == "")
		{
			alert("Please select a state.");
			myform.state.focus();
			return false;
		}
	}
	else
	{
		if (myform.other.value == "")
		{
			alert("Please enter a Country or Province.");
			myform.other.focus();
			return false;
		}
	}
	
	//model
	if (model == "none")
	{
		alert("Please select a model.");
		myform.model.focus();
		return false;
	}
	
	//year
	if (year == "none")
	{
		alert("Please select a year.");
		myform.year.focus();
		return false;
	}
	
	//city
	city = TrimBlanks(city);
	if (city == "")
	{
		myform.city.value = "";
		alert("Please enter a city.");
		myform.city.focus();
		return false;
	}

	//color
	color = TrimBlanks(color);
	if (color == "")
	{
		myform.color.value = "";
		alert("Please enter a color.");
		myform.color.focus();
		return false;
	}

	return ValidateEmail(myform);
}

function ValidateEmail(myform)
{
	var email = myform.email.value;		//required
	email = TrimBlanks(email);
	if (email == "" || (email.indexOf("@") == -1) || (email.indexOf(".") == -1))
	{
		myform.email.value = "";
		alert("Please enter a valid email address.");
		myform.email.focus();
		return false;
	}
}

function TrimBlanks(str)
{
	var newStr = "";
	newStr = str.replace(/ */,""); // trim leading spaces
	newStr = newStr.replace(/ *$/,""); // trim trailing spaces
	return newStr;
}

function ChangeCountry(thisCtrl, firstTime)
{
	var myform = document.forms[0];
	var val = thisCtrl.options[thisCtrl.selectedIndex].value;

	if (val == "CAN")
	{
		myform.state.value = "CAN";
		myform.state.disabled = true;

		ShowFreeTextField(1, "Province:");
	}
	else if (val == "OTHER")
	{
		myform.state.value = "OTH";
		myform.state.disabled = true;
		
		ShowFreeTextField(1, "Country Name:");
	}
	else
	{
		myform.state.disabled = false;
		if (firstTime == 0)
		{
			myform.state.value = "none";
//		myform.state.selectedIndex = 0;
		}
		
		ShowFreeTextField(0, "State:");
	}
}

function ShowFreeTextField(bShow, Title)
{
	if (document.all)
	{
		if (bShow == 1)
		{
			// Hide the state dropdown
			document.all.stateInput.disabled = true;
				
			// Show the freeform text input for either Province(Canada) or Country for other
			document.all.textInput.style.visibility = "visible";
		}
		else
		{
			// Show the state dropdown
			document.all.stateInput.disabled = false;
				
			// Hide the freeform text input for either Province(Canada) or Country for other
			document.all.textInput.style.visibility = "hidden";
		}

		// Change the state title
		document.all.stateTitle.innerText = Title;
	}
	else
	{
		if (bShow == 1)
		{
			// Hide the state dropdown
			document.stateInput.disabled = true;
				
			// Show the freeform text input for either Province(Canada) or Country for other
			document.textInput.visibility = "show";
		}
		else
		{
			// Show the state dropdown
			document.stateInput.disabled = false;
				
			// Hide the freeform text input for either Province(Canada) or Country for other
			document.textInput.visibility = "hide";
		}

		// Change the state title
		document.stateTitle.innerText = Title;
	}
}
