// JScript source code

function popupWindow(sURL, sWindowName, iHeight, iWidth) {
	sFeatures = 'height=' + iHeight + ',width=' + iWidth + ',scrollbars=no,resizable=no,location=no'
	window.open(sURL, sWindowName, sFeatures);
}

function isValidEmail(sEmail){
	if (sEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1){
		return false;
	} else {
		return true;
	}
}

function ValidateSendToAFriend(){
	if (document.TellAFriend.YourName.value == ''){		window.alert('Please enter your name');		return false;	}
	if (document.TellAFriend.YourEmailAddress.value == ''){		window.alert('Please enter your email address');		return false;	}
	var strThisEmail = document.TellAFriend.YourEmailAddress.value
	if (strThisEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1){
		window.alert('Your email address is not a valid \n please enter a valid email address');
		return false;
	}
	if (document.TellAFriend.FriendsName.value == ''){		window.alert('Please enter your friends name');		return false;	}
	if (document.TellAFriend.FriendsEmail.value == ''){		window.alert('Please enter your friends email address');		return false;	}
	var strFriendEmail = document.FriendsEmail.YourEmailAddress.value
	if (strFriendEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1){
		window.alert('Your friends email address is not valid \n please enter a valid email address');
		return false;
	}
	if (document.TellAFriend.Message.value == ''){		window.alert('Please type your message');		return false;	}
}

function validateEnewsSignUpform(){
	var strThisEmail = document.getElementById('EmailAddress').value
	if (strThisEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1){
		window.alert('Your email address is not a valid \n please enter a valid email address');
		return false;
	}
}

function checkForExistingAccount(sEmail1, sEmail2, sPassword1, sPassword2, sFirstName, sLastName, sAddress, sPostcode, iMMID){
	if (isValidEmail(sEmail1)){
		if (sEmail1 == sEmail2){
			if (sPassword1 != ''){
				if (sPassword1 == sPassword2){
					if (sFirstName != ''){
						if (sLastName != ''){
							if (sAddress != ''){
								if (sPostcode != ''){
									// Stuff to work out date (needed to make sure IE doesn't mess me about by caching the callbacks)
									var today = new Date();
									var iMinutes = today.getMinutes();
									var iSeconds = today.getSeconds();
									var iMilliseconds = today.getMilliseconds();
									// Make the URL
									var postURL = 'existingemailxmlhttpcallback.asp?now=' + iMinutes + iSeconds + iMilliseconds + '&m=' + iMMID + '&e=' + sEmail1
									if (window.XMLHttpRequest){
										// mozilla/firefox etc
										xmlhttp=new XMLHttpRequest();
										xmlhttp.open('GET',postURL,false);
										xmlhttp.send(null);
									}
									else if (window.ActiveXObject) {
										// internet explorer
										xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
										if (xmlhttp){
											xmlhttp.open('GET',postURL,false);
											xmlhttp.send();
										}
									}
									iCID = xmlhttp.responseText;	
									if (iCID == 0){
										return true;
									} else {
										window.alert('The email address ' + sEmail1 + ' is already registered to access this website.\nPlease try a different email address or use the Forgotten Password link \nto have your password emailed to you.');
										return false;						
									}
								} else {
									window.alert('Please enter your postcode');
									return false;
							}							
							} else {
								window.alert('Please enter your address');
								return false;
							}							
						} else {
							window.alert('Please enter your last name');
							return false;
						}				
					} else {
						window.alert('Please enter your first name');
						return false;
					}
				} else {
					window.alert('Please enter the same password into both password boxes');
					return false;
				}
			} else {
				window.alert('Please enter a password into both password boxes');
				return false;
			}
		} else {
			window.alert('Please enter the same email address into both email boxes');
			return false;	
		}
	} else {
		window.alert('Please enter a valid email address');
		return false;		
	}
}

function ValidateCreateAccountForm(){	if (document.getElementById('Email').value == ''){		window.alert('Please enter an email address');		return false;	}	if (document.getElementById('Password1').value == ''){		window.alert('You need to choose a password');		return false;	}	if (document.getElementById('Password2').value == ''){		window.alert('Please re-enter your password');		return false;	}	if (document.getElementById('Password1').value != document.getElementById('Password2').value){		window.alert('Please ensure you type the same password twice');		return false;	}	if (document.getElementById('PasswordHint').value == ''){		window.alert('Please enter a password hint');		return false;	}}function ValidateLoginForm(){	if (document.getElementById('EmailAddress').value == ''){		window.alert('Please enter your email address');		return false;	}	if (document.getElementById('Password').value == ''){		window.alert('Please enter your password');		return false;	}}function ValidateReviewsForm(){
	if(document.ReviewsForm.Review_title.value ==''){
		window.alert('Please enter a review title');
		return false;
	}
	if(document.ReviewsForm.Review_text.value ==''){
		window.alert('Please enter some review text');
		return false;
	}
}


function ValidateAddressBook(){
	if(document.getElementById('First_name').value ==''){
		window.alert('Please enter a first name');
		return false;
	}
	if(document.getElementById('Last_name').value ==''){
		window.alert('Please enter a Last name');
		return false;
	}
	if(document.getElementById('Address').value ==''){
		window.alert('Please enter an Address');
		return false;
	}
	if(document.getElementById('Postcode').value ==''){
		window.alert('Please enter a Postcode');
		return false;
	}
}

function setChosenCard(iCardID,bCvvFocus){
	try{
		iLastSelectedBox = document.getElementById('LastSelectedBox').value;
	}
	catch(err){
		iLastSelectedBox = 0
	}
	sCardBox = 'Box' + iLastSelectedBox;
	document.getElementById(sCardBox).className = 'CardUnselected';
	sCardBox = 'Box' + iCardID;
	document.getElementById(sCardBox).className = 'CardSelected';
	try{
		document.getElementById('LastSelectedBox').value=iCardID;
	}
	catch(err){
		// don't do anything	
	}
	if (bCvvFocus){
		sCvvBox = 'CVVBox' + iCardID;
		document.getElementById(sCvvBox).focus();
	}
	sCardRadio = 'CardRadio' + iCardID;
	document.getElementById(sCardRadio).checked=true;		
}

function checkForCvv(iCardID){
	if (iCardID > 0){
		sCvvBox = 'CVVBox' + iCardID;
		if (document.getElementById(sCvvBox).value == ''){
			window.alert('Please enter your card security number');
			document.getElementById(sCvvBox).focus();
			return false;
		}
	}else{
		if(CheckPaymentForm()==false){
			return false;
		}			
	}
}

function ChangePassword(){
	sOldPassword = document.getElementById('OldPassword').value;
	sNewPassword1 = document.getElementById('NewPassword1').value;
	sNewPassword2 = document.getElementById('NewPassword2').value;
	sPasswordHint = document.getElementById('PasswordHint').value;
	if (sOldPassword != '') {
		if (sNewPassword1 != '') {
			if (sNewPassword2 != '') {
				if (sNewPassword1 == sNewPassword2) {
					if (sPasswordHint != '') {
						if (sNewPassword1 == sPasswordHint) {
							window.alert('Your password hint cannot be the same as your password');
							return false;	
						} else {
							return true;						
						}
					} else {
						window.alert('Please enter a password hint');
						return false;							
					}
				} else {
					window.alert('Please make sure to enter the same new password twice');
					return false;						
				}
			} else {
				window.alert('Please confirm your new password');
				return false;					
			}
		} else {
			window.alert('Please enter your new password');
			return false;			
		}
	} else {
		window.alert('Please enter your old password');
		return false;
	}
}


function CheckPaymentForm(){	if (document.getElementById('Card_holder_name').value == ''){		window.alert('Please enter the name as it \nappears on your credit card');		return false;	}	if (document.getElementById('Card_number').value == ''){		window.alert('Please enter your card number');		return false;	}
	if (document.getElementById('Expires_end_year').value == '00'){		window.alert('Please enter your card expiry year');		return false;	}	if (document.getElementById('Expires_end_month').value == '00'){		window.alert('Please enter your card expiry month');		return false;	}		if (document.getElementById('CVV2_code').value == ''){		window.alert('Please enter your cards security code \nThis is the three digit code on the \nback of the signiture strip');		return false;	}	}



function ChangeEmail(){
	if(document.getElementById('NewEmail').value ==''){
		window.alert('Please enter a new email address');
		return false;
	}
	var strThisEmail = document.getElementById('NewEmail').value
	if (strThisEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1){
		window.alert('Your email address is not a valid \n please enter a valid email address');
		return false;
	}
	if((document.getElementById('NewEmail').value) == (document.getElementById('CurrentEmail').value)){
		window.alert('This is already your email address');
		return false;
	}
	if((document.getElementById('NewEmail').value) != (document.getElementById('ConfirmNewEmail').value)){
		window.alert('please make sure that you type the same email address twice');
		return false;
	}
	if(document.getElementById('Password').value ==''){
		window.alert('Please enter your password');
		return false;
	}
}

function ValidateMailingListSignUp(){
	if(document.getElementById('EmailAddress').value == ''){
		window.alert('Please enter your email address');
		return false;
	}
	var strThisEmail = document.getElementById('EmailAddress').value
	if (strThisEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1){
		window.alert('Your email address is not valid \n please enter a valid email address');
		return false;
	}
	if(document.getElementById('ConfirmEmailAddress').value ==''){
		window.alert('Please confirm your email address');
		return false;
	}
	if((document.getElementById('EmailAddress').value) != (document.getElementById('ConfirmEmailAddress').value)){
		window.alert('Please make sure you type the same email \n address into both boxes');
		return false;
	}
}

function showTab(iGroup,iTab,iTotalTabs,sStylePrefix){
	// Set up the class name variables
	sLeftClassOn = sStylePrefix + 'LHOn'
	sLeftClassOff = sStylePrefix + 'LHOff'
	sMiddleClassOn = sStylePrefix + 'MiddleOn'
	sMiddleClassOff = sStylePrefix + 'MiddleOff'
	sRightClassOn = sStylePrefix + 'RHOn'
	sRightClassOff = sStylePrefix + 'RHOff'	
	// Hide all the old content boxes and turn all the tabs off
	for (var iCount = 1; iCount <= iTotalTabs; iCount++){
	    // Hide content box
	    sThisTab = 'G' + iGroup + 'Tab' + iCount;
	    document.getElementById(sThisTab).style.display='none';
	    // Turn off tab
	    sOldTabLHImg = sThisTab + 'LH';
	    sOldTabMiddleImg = sThisTab + 'Middle';
	    sOldTabRHImg = sThisTab + 'RH';
	    document.getElementById(sOldTabLHImg).className=sLeftClassOff;
	    document.getElementById(sOldTabMiddleImg).className=sMiddleClassOff;
	    document.getElementById(sOldTabRHImg).className=sRightClassOff;
	}
	// Show the selected content box and turn on the tab
	sNewTab = 'G' + iGroup + 'Tab' + iTab;
	sNewTabLHImg = sNewTab + 'LH';
	sNewTabMiddleImg = sNewTab + 'Middle';
	sNewTabRHImg = sNewTab + 'RH';		
	// Show the selected content box
	document.getElementById(sNewTab).style.display='block';
	// Switch the images to on for the selected tab
	document.getElementById(sNewTabLHImg).className=sLeftClassOn;
	document.getElementById(sNewTabMiddleImg).className=sMiddleClassOn;
	document.getElementById(sNewTabRHImg).className=sRightClassOn;
}

function CountDown(){
	var now=new Date();
	now=Date.parse(now)/1000;
	var x=parseInt(counts-(now-start),10);
	if(x>0){
		timerID=setTimeout("CountDown()", 100)
	}else{
		location.href="/"
	}
}

function textCounter(field,cntfield,maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
cntfield.value = maxlimit - field.value.length;
}
//  End -->