function popup(url,width,height) {

	newwin = window.open(url, 'newwin', 'height='+height+',width='+width+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no');
}

function emailValidate() {

	var goodEmail = document.getUsername.email.value.match(/^[a-z0-9\-\_\.\+]+\@[a-z0-9\-\.]+\.[a-z]{2,4}$/i);
	var goodUsername = document.getUsername.username.value.match(/^[\w\.-]+$/i);
	if (goodEmail) {
		if (document.getUsername.email.value == document.getUsername.emailConfirm.value) {
			good = true
		} else {
			alert('Your email address entries do not match. Please re-confirm')
			good = false;
			document.getUsername.emailConfirm.focus()
			return;
		}
	} else {
		alert('Please enter a valid e-mail address.')
		good = false;
		if (!good) {
			document.getUsername.email.focus()
			return;
		}
	}
	
		if (goodUsername) {
		if (document.getUsername.username.value == document.getUsername.verifyusername.value) {
			goodu = true
		} else {
			alert('Your usernames do not match. Please re-confirm')
			goodu = false;
			document.getUsername.verifyusername.focus()
			return;
		}
	} else {
		alert('Please enter a valid username.')
		goodu = false;
		if (!goodu) {
			document.getUsername.username.focus()
			return;
		}
	}

	if (good && goodu) {
		//alert("Name and email address fields verified good.")
		document.getUsername.submit();
	}

}// END endPage()


function createAccountValidate() {

	var goodEmail = document.createAccount.email.value.match(/^[a-z0-9\-\_\.\+]+\@[a-z0-9\-\.]+\.[a-z]{2,4}$/i);

	if  (document.createAccount.firstName.value == "") {
		alert('Please enter a valid First Name.')
		good = false;
		if (!good) {
			document.createAccount.firstName.focus()
			return;
		}
	}

	if  (document.createAccount.lastName.value == "") {
		alert('Please enter a valid Last Name.')
		good = false;
		if (!good) {
			document.createAccount.lastName.focus()
			return;
		}
	}
	
	/*if  (document.createAccount.companyName.value == "") {
		alert('Please enter a valid Company Name.')
		good = false;
		if (!good) {
			document.createAccount.companyName.focus()
			return;
		}
	}*/

	if  (document.createAccount.address1.value == "") {
		alert('Please enter a valid street address.')
		good = false;
		if (!good) {
			document.createAccount.address1.focus()
			return;
		}
	}

	if  (document.createAccount.city.value == "") {
		alert('Please enter a valid city.')
		good = false;
		if (!good) {
			document.createAccount.city.focus()
			return;
		}
	}

	//if  (document.createAccount.county.value == "") {
		//alert('Please enter a valid county.')
		//good = false;
		//if (!good) {
		//	document.createAccount.county.focus()
		//	return;
		//}
	//}

	if  (document.createAccount.postCode.value == "") {
		alert('Please enter a valid postcode.')
		good = false;
		if (!good) {
			document.createAccount.postCode.focus()
			return;
		}
	}

	if  (document.createAccount.phone.value == "") {
		alert('Please enter a valid phone number.')
		good = false;
		if (!good) {
			document.createAccount.phone.focus()
			return;
		}
	}
	
	if (goodEmail) {
		if (document.createAccount.email.value == document.createAccount.emailConfirm.value) {
			good = true
		} else {
			alert('Your email address entries do not match. Please re-confirm')
			good = false;
			document.createAccount.emailConfirm.focus()
			return;
		}
	} else {
		alert('Please enter a valid e-mail address.')
		good = false;
		if (!good) {
			document.createAccount.email.focus()
			return;
		}
	}

	if (good) {
		//alert("Name and email address fields verified good.")
		document.createAccount.submit();
	}

}// END endPage()

function changeCase(frmObj) 
{
		var index;
		var tmpStr;
		var tmpChar;
		var preString;
		var postString;
		var strlen;
	
		tmpStr = frmObj.value.toLowerCase();
		strLen = tmpStr.length;
			if (strLen > 0)  
				{
					for (index = 0; index < strLen; index++)  
						{
							if (index == 0)  
								{
									tmpChar = tmpStr.substring(0,1).toUpperCase();
									postString = tmpStr.substring(1,strLen);
									tmpStr = tmpChar + postString;
								}
							else 
								{
									tmpChar = tmpStr.substring(index, index+1);
										if (tmpChar == " " && index < (strLen-1))  
											{
												tmpChar = tmpStr.substring(index+1, index+2).toUpperCase();
												preString = tmpStr.substring(0, index+1);
												postString = tmpStr.substring(index+2,strLen);
												tmpStr = preString + tmpChar + postString;
									         }
							    }
						   }
				 }
frmObj.value = tmpStr;
}
// END changeCase

function checkPostCode(frmObj) {
	var tmpStr;
	var strlen;
	var tmpString = "";
	var tmpPostCode = "";
	var PostCodeLen;

	tmpStr = frmObj.value.toUpperCase();
	strLen = tmpStr.length;


	for (index = 0; index < strLen; index++) {

		tmpChar = tmpStr.substring(index, index+1);
		if (tmpString == 0) {
			tmpString = tmpStr.substring(index, index+1);
		} else {
			if (tmpChar != ' ') {
				tmpString = tmpString + tmpStr.substring(index, index+1);
			}
		}
	}

	PostCodeLen = tmpString.length;


	if (PostCodeLen == 6) {

		for (index = 0; index < PostCodeLen; index++) {
			if (index == 3) {
				tmpPostCode = tmpPostCode + ' ' + tmpString.substring(index, index+1);
			} else {
				tmpPostCode = tmpPostCode + tmpString.substring(index, index+1);
			}
		}
	} else {
		for (index = 0; index < PostCodeLen; index++) {

		if (index == 4) {
			tmpPostCode = tmpPostCode + ' ' + tmpString.substring(index, index+1);
		} else {
			tmpPostCode = tmpPostCode + tmpString.substring(index, index+1);
		}
		}
	}
	frmObj.value = tmpPostCode;
} //END CheckPostCode

function createAccountValidateBusiness() {

	var goodEmail = document.createAccount.email.value.match(/^[a-z0-9\-\_\.\+]+\@[a-z0-9\-\.]+\.[a-z]{2,4}$/i);

	if  (document.createAccount.firstName.value == "") {
		alert('Please enter a valid First Name.')
		good = false;
		if (!good) {
			document.createAccount.firstName.focus()
			return;
		}
	}

	if  (document.createAccount.lastName.value == "") {
		alert('Please enter a valid Last Name.')
		good = false;
		if (!good) {
			document.createAccount.lastName.focus()
			return;
		}
	}
	
	if  (document.createAccount.companyName.value == "") {
		alert('Please enter a valid Company Name.')
		good = false;
		if (!good) {
			document.createAccount.companyName.focus()
			return;
		}
	}

	if  (document.createAccount.address1.value == "") {
		alert('Please enter a valid street address.')
		good = false;
		if (!good) {
			document.createAccount.address1.focus()
			return;
		}
	}

	if  (document.createAccount.city.value == "") {
		alert('Please enter a valid city.')
		good = false;
		if (!good) {
			document.createAccount.city.focus()
			return;
		}
	}

	//if  (document.createAccount.county.value == "") {
		//alert('Please enter a valid county.')
		//good = false;
		//if (!good) {
		//	document.createAccount.county.focus()
		//	return;
		//}
	//}

	if  (document.createAccount.postCode.value == "") {
		alert('Please enter a valid postcode.')
		good = false;
		if (!good) {
			document.createAccount.postCode.focus()
			return;
		}
	}

	if  (document.createAccount.phone.value == "") {
		alert('Please enter a valid phone number.')
		good = false;
		if (!good) {
			document.createAccount.phone.focus()
			return;
		}
	}
	
	if (goodEmail) {
		if (document.createAccount.email.value == document.createAccount.emailConfirm.value) {
			good = true
		} else {
			alert('Your email address entries do not match. Please re-confirm')
			good = false;
			document.createAccount.emailConfirm.focus()
			return;
		}
	} else {
		alert('Please enter a valid e-mail address.')
		good = false;
		if (!good) {
			document.createAccount.email.focus()
			return;
		}
	}

	if (good) {
		//alert("Name and email address fields verified good.")
		document.createAccount.submit();
	}

}// END endPage()

function commonInit(e) {

    if (document.getElementById('activity_machine_select')) {

        addEvent(document.getElementById('activity_machine_select'),'change',activityMachineSelectChange,false);

    }



}

function activityMachineSelectChange(e) {

    var activityMachineSelect = document.getElementById('activity_machine_select');

    var machineSelected = activityMachineSelect.value;

    if (machineSelected!=0) {

        document.getElementById('machineform_id').value = machineSelected;
        document.getElementById('machineform').submit();

    }

}

addEvent(window,'load',commonInit,false);

