/*
	2007.09.06	gricke
				<checkSubscribeSuccess>	New function checks if being routed from Thomson email alert subscription final phase			
*/
function checkSubscribeSuccess(){
	if(getQueryVariable('subscribe') == 'success'){
		document.getElementById('emailAlertForm').innerHTML = "<h2>Thank you.</h2>Your email alert subscription has been completed.";
	}
}
function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
  	}
	return "999";
}
function validateForm(){
	if(document.emailAlert.BonsaiEx_control_AlertEmail.value == ''){
		alert('Your email is required');
		return false;
	}
	if(emailvalidation(document.emailAlert.BonsaiEx_control_AlertEmail,'Email does not appear to be in the proper format')){
		if(checkEmailSelection() == false){
			alert('You did not choose an E-mail alert');
		}else{
			document.forms['emailAlert'].submit();
		}
	}
}
function emailvalidation(entered, alertbox)
{
	with (entered){
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");
		lastpos=value.length-1;
		if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) {
			if (alertbox){
				alert(alertbox);
			}
			return false;
		}else{
			return true;
		}
	}
	return false;
}
function checkEmailSelection(){
	var checkBoxes = document.emailAlert.getElementsByTagName('input');
	var checkSelections = '';
	for (i=0; i<checkBoxes.length;i++) {
		if(checkBoxes[i].type == 'checkbox'){
			if(checkBoxes[i].checked){
				checkSelections = checkSelections + checkBoxes[i].value;
			}
		}
	}
	if(checkSelections.length == 0){
		return false;
	}else{
		return true;
	}
}
