// Popup Window
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// Image Zoom
function zoomImage(productCode){
	LeftPosition = (screen.width) ? (screen.width-320)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-240)/2 : 0;	
	window.open('productImageZoom.asp?ProductCode=' + productCode,'ImageZoom','height=240,width=320,top='+TopPosition+',left='+LeftPosition+',scrollbars=no,resizable=yes')
}

// Form Validation Functions
var pcrex = new RegExp("^([A-PR-UWYZ0-9][A-HK-Y0-9][AEHMNPRTVXY0-9]?[ABEHMNPRVWXY0-9]? {1,2}[0-9][ABD-HJLN-UW-Z]{2}|GIR 0AA)$","i");

function isValidEmail(str) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str)){
		return true;
	}
	else {
		return false;
	}
}

function checkquicksearch(){
	if (document.quicksearch.sCriteria.value==''){
		alert('Please enter your Search Criteria.');
		return false;
	}
	else {
		return true;
	}
}

function checkenquiry(){
	var ftxt = '';
	
	if (document.enquiry.Name.value==''){
		ftxt += '\n- Please enter your Name.';
	}
	
	if (document.enquiry.Telephone.value==''){
		ftxt += '\n- Please enter your Telephone Number.';
	}
	
	if (isValidEmail(document.enquiry.email.value)==false){
		ftxt += '\n- Please enter your Email Address.';
	}
	
	if (document.enquiry.subject.value==''){
		ftxt += '\n- Please select the Subject of this email.';
	}
	
	if (ftxt!==''){
		alert('One or more errors were found while submitting this form. The errors found are displayed below.\n' + ftxt + '\n\nPlease correct the above errors and try again.');
		return false;
	}
	else {
		return true;
	}
}

function checklogin(){
	var ftxt = '';
	
	if (document.login.AccountNumber.value==''){
		ftxt += '\n- Please enter your Account Number.';
	}
		
	if (document.login.Password.value==''){
		ftxt += '\n- Please enter your Password.';
	}

	if (ftxt!==''){
		alert('One or more errors were found while submitting this form. The errors found are displayed below.\n' + ftxt + '\n\nPlease correct the above errors and try again.');
		return false;
	}
	else {
		return true;
	}
}

function checkforgottenpassword(){
	var ftxt = '';
	
	if (document.forgottenpassword.AccountNumber.value==''){
		ftxt += '\n- Please enter your Account Number.';
	}
	
	if (isValidEmail(document.forgottenpassword.EmailAddress.value)==false){
		ftxt += '\n- Please enter your Email Address.';
	}

	if (ftxt!==''){
		alert('One or more errors were found while submitting this form. The errors found are displayed below.\n' + ftxt + '\n\nPlease correct the above errors and try again.');
		return false;
	}
	else {
		return true;
	}
}

function checkregisterform(){
	var ftxt = '';
	
	// Personal Details
	var ptxt = '';
	if (document.registerform.BillingName.value==''){
		ptxt += '\n- Please enter your Name.'
	}
	
	if (isValidEmail(document.registerform.EmailAddress.value)==false){
		ptxt += '\n- Please enter your Email Address.';
	}
	
	if (document.registerform.LandlinePhone.value==''){
		ptxt += '\n- Please enter your Landline Telephone Number.';
	}
	
	if (document.registerform.DetailsFrom.value==''){
		ptxt += '\n- Please select Where you heard about us from.';
	}
	
	if (ptxt!==''){
		ftxt += '\n** Personal Details **\n' + ptxt;
	}
	
	// Security Details
	var stxt = '';
	if (document.registerform.Password.value!==document.registerform.Password_Rpt.value){
		stxt += '\n- Please ensure Both New Password\'s Match.';
	}
	else if (document.registerform.Password.value.length<6){
		stxt += '\n- Please ensure your passwird is a minimum of 6 characters long.';
	}
	
	if (stxt!==''){
		if (ftxt!==''){
			ftxt += '\n';
		}
		ftxt += '\n** Security Details **\n' + stxt;		
	}
	
	// Billing Address Details
	var btxt = '';
	if (document.registerform.BillingAddress1.value==''){
		btxt += '\n- Please enter your Billing Address Line 1.';
	}	
	
	if (document.registerform.BillingCity.value==''){
		btxt += '\n- Please enter your Billing City.';
	}
	
	if (document.registerform.BillingCounty.value==''){
		btxt += '\n- Please enter your Billing County.';
	}
	
	if (pcrex.test(document.registerform.BillingPostcode.value)==false){
		btxt += '\n- Please enter your Billing Postcode.';
	}
	
	if (btxt!==''){
		if (ftxt!==''){
			ftxt += '\n';
		}
		ftxt += '\n** Billing Address Details **\n' + btxt;		
	}
	
	if (document.registerform.AcceptedTerms.checked==false){
		if (ftxt!==''){
			ftxt += '\n';
		}
		ftxt += '\n- You must agree to the Terms & Conditions to proceed.';
	}

	if (ftxt!==''){
		alert('One or more errors were found while submitting this form. The errors found are displayed below.\n' + ftxt + '\n\nPlease correct the above errors and try again.');
		return false;
	}
	else {
		return true;
	}
}

function checkeditregistrationform(){
	var ftxt = '';
	
	// Personal Details
	var ptxt = '';
	if (document.editregistrationform.BillingName.value==''){
		ptxt += '\n- Please enter your Name.'
	}
	
	if (isValidEmail(document.editregistrationform.EmailAddress.value)==false){
		ptxt += '\n- Please enter your Email Address.';
	}
	
	if (document.editregistrationform.LandlinePhone.value==''){
		ptxt += '\n- Please enter your Landline Telephone Number.';
	}
		
	if (ptxt!==''){
		ftxt += '\n** Personal Details **\n' + ptxt;
	}
	
	// Security Details
	var stxt = '';
	if (document.editregistrationform.Password.value!==document.editregistrationform.Password_Rpt.value){
		stxt += '\n- Please ensure Both New Password\'s Match.';
	}
	else if ((document.editregistrationform.Password.value!==''&&document.editregistrationform.Password_Rpt.value!=='')&&document.editregistrationform.Password.value.length<6){
		stxt += '\n- Please ensure your passwird is a minimum of 6 characters long.';
	}
	
	if (stxt!==''){
		if (ftxt!==''){
			ftxt += '\n';
		}
		ftxt += '\n** Security Details **\n' + stxt;		
	}
	
	// Billing Address Details
	var btxt = '';
	if (document.editregistrationform.BillingAddress1.value==''){
		btxt += '\n- Please enter your Billing Address Line 1.';
	}	
	
	if (document.editregistrationform.BillingCity.value==''){
		btxt += '\n- Please enter your Billing City.';
	}
	
	if (document.editregistrationform.BillingCounty.value==''){
		btxt += '\n- Please enter your Billing County.';
	}
	
	if (pcrex.test(document.editregistrationform.BillingPostcode.value)==false){
		btxt += '\n- Please enter your Billing Postcode.';
	}
	
	if (btxt!==''){
		if (ftxt!==''){
			ftxt += '\n';
		}
		ftxt += '\n** Billing Address Details **\n' + btxt;		
	}
	
	if (ftxt!==''){
		alert('One or more errors were found while submitting this form. The errors found are displayed below.\n' + ftxt + '\n\nPlease correct the above errors and try again.');
		return false;
	}
	else {
		return true;
	}
}

function checkcheckout(){
	var bpaymentselected = false;
	for (var i=0;i<3;i++){
		if (document.checkout.PaymentMethod[i].checked==true){
			bpaymentselected = true;
		}
	}
	if (bpaymentselected==false){
		alert('Please select a Payment Method.');
		return false;
	}
	else {
		return true;
	}
}

function confirmLogout(){
	if (confirm('Are you sure you want to logout?')){
		location.href='myaccount_home.asp?Logout=True';
	}
}