// CHECKOUT.js

	//*************************
	//validateYourDetails()
	//This function validates the personal/delivery details within stage 3
	function validateYourDetails(){

		//disable the button
		$('btnContinue').disable();		

		//initialise the error variables
		errorList 		= "";
		errorCount 		= 0;
		errorMessage 	= "";
		
		//title
		if(isBlank($('Title').value)){
			errorList 	+= "\n- You must enter your title.     ";
			errorCount 	+= 1;
		}
		//forename
		if(isBlank($('Forename').value)){
			errorList 	+= "\n- You must enter your forename.     ";
			errorCount 	+= 1;
		}
		//surname
		if(isBlank($('Surname').value)){
			errorList 	+= "\n- You must enter your surname.     ";
			errorCount 	+= 1;
		}
		//address1
		if(isBlank($('Address1').value)){
			errorList 	+= "\n- You must enter the first line of your address.     ";
			errorCount 	+= 1;
		}
		//address2
		if(isBlank($('Address2').value)){
			errorList 	+= "\n- You must enter the second line of your address.     ";
			errorCount 	+= 1;
		}
		//postcode
		if(isBlank($('Postcode').value)){
			errorList 	+= "\n- You must enter your postcode.     ";
			errorCount 	+= 1;
		}
		//telephone
		if(isBlank($('TelephoneHome').value) && isBlank($('TelephoneWork').value) && isBlank($('Mobile').value)){
			errorList 	+= "\n- You must enter one of your telephone numbers.     ";
			errorCount 	+= 1;
		}
		//email
		if(!isEmail($('Email').value)){
			errorList 	+= "\n- You must enter a valid email address.     ";
			errorCount 	+= 1;
		}

		//delivery details - if Delivery Address line 1 has value
		if($('DeliveryAddress1').value != ""){

			//postcode
			if(isBlank($('DeliveryPostcode').value)){
				errorList 	+= "\n- You must enter a delivery postcode.     ";
				errorCount 	+= 1;	
			}
			//telephone
			if(isBlank($('DeliveryTelephone').value)){
				errorList 	+= "\n- You must enter a delivery telephone number.     ";
				errorCount 	+= 1;
			}
		}

		//hear about
		if(isBlank($('HearAbout').value)){
			errorList 	+= "\n- You must enter how you found us.     ";
			errorCount 	+= 1;
		}



		//check for errors!
		if(errorCount > 0){
			
			if(errorCount == 1){
				errorMessage = "The following error occurred whilst processing your details.     ";
				errorMessage += "\n" + errorList + "\n";
				errorMessage += "\nPlease fix this error before clicking 'Submit My Details'.     ";
			} else {
				errorMessage = "The following errors occurred whilst processing your details.     ";
				errorMessage += "\n" + errorList + "\n";
				errorMessage += "\nPlease fix these errors before clicking 'Submit My Details'.     ";	
			}
			alert(errorMessage);
			returnVal = false;
			
			//disable the button
			$('btnContinue').enable();
		} 
		else {
			returnVal = true;
			
		}
		
		return returnVal;
	}
	//*************************



	//*************************
	//validatePayment()
	//This function checks the payment details
	function validatePayment(){

		//disable the button
		$('btnContinue').disable();		
		
		//initialise the error variables
		errorList 		= "";
		errorCount 		= 0;
		errorMessage 	= "";
		
		bol_expiry		= false;
		bol_start		= false;

		cardType 		= selectValues('CardType','value');
		cardNumber 		= $('CardNumber').value;
		cardStartMonth 	= selectValues('CardStartMonth','value');
		cardStartYear 	= selectValues('CardStartYear','value');
		cardExpiryMonth = selectValues('CardExpiryMonth','value');
		cardExpiryYear 	= selectValues('CardExpiryYear','value');
		cardCVC			= $('CardCVC').value;


//		if($('CompleteOrder').checked == true){
//			returnVal = true;
//		}
//		else {

			//cardType
			if(isBlank(cardType)){
				errorList 	+= "\n- You must select a card type.     ";
				errorCount 	+= 1;
			}
			//cardNumber
			if(cardNumber.length < 16 || !isNumeric(cardNumber)){
				errorList 	+= "\n- Card Number must be at least 16 characters long and contain numbers only.     ";
				errorCount 	+= 1;
			}
			//cardExpiryMonth!
			if(isBlank(cardExpiryMonth)){
				errorList 	+= "\n- You must select the month your card expires.     ";
				errorCount 	+= 1;
			} 
			//cardExpiryYear!
			if(isBlank(cardExpiryYear)){
				errorList 	+= "\n- You must select the year your card expires.     ";
				errorCount 	+= 1;
			}
			//has the card expired?
			if(!isBlank(cardExpiryMonth) && !isBlank(cardExpiryYear)){
	
				//create the dates
				cardExpiry 		 = Number(String(cardExpiryYear) + String(cardExpiryMonth));
				currentYearMonth = Number(String($('CurrentYear').value) + String($('CurrentMonth').value));
				
				//check the dates against one another
				if(cardExpiry < currentYearMonth){
					errorList 	+= "\n- The expiry date you have entered has passed. Please check if your card has expired.     ";
					errorCount 	+= 1;
				}
				else {
					bol_expiry = true;
				}
			}
			
			//cardStart
			if(!isBlank(cardStartMonth) && !isBlank(cardStartYear)){
				//create the dates
				cardStart 		 = Number(String(cardStartYear) + String(cardStartMonth));
				currentYearMonth = Number(String($('CurrentYear').value) + String($('CurrentMonth').value));
				
				//check the dates against one another
				if(cardStart > currentYearMonth){
					errorList 	+= "\n- The start date you have entered is in the future. Please check if your card is valid.     ";
					errorCount 	+= 1;
				}
				else {
					bol_start = true;
				}
			}
			else if(!isBlank(cardStartMonth) || !isBlank(cardStartYear)){
				errorList 	+= "\n- You must select the full start date for your card.     ";
				errorCount 	+= 1;
			}

			//cardStart & cardExpiry
			if(bol_expiry == true && bol_start == true){
				//create dates
				cardStart	= Number(String(cardStartYear) + String(cardStartMonth));
				cardExpiry  = Number(String(cardExpiryYear) + String(cardExpiryMonth));
				
				//check expiry date is after start date
				if(cardExpiry < cardStart){
					errorList 	+= "\n- The expiry date must be after the start date.     ";
					errorCount 	+= 1;
				}
			}
			
			//cardCVC
			if(cardCVC.length < 3 || !isNumeric(cardCVC)){
				errorList 	+= "\n- You must enter your CVC Number.     ";
				errorCount 	+= 1;
			}
	
	
			//check for errors!
			if(errorCount > 0){
				if(errorCount == 1){
					errorMessage = "The following error occurred whilst processing your details.     ";
					errorMessage += "\n" + errorList + "\n";
					errorMessage += "\nPlease fix this error before clicking 'Submit My Details'.     ";
				} 
				else {
					errorMessage = "The following errors occurred whilst processing your details.     ";
					errorMessage += "\n" + errorList + "\n";
					errorMessage += "\nPlease fix these errors before clicking 'Submit My Details'.     ";	
				}
				alert(errorMessage);
				returnVal = false;
				
				//disable the button
				$('btnContinue').enable();
			} 
			else {
				returnVal = true;
			}
//		}
		
		
		return returnVal;
	}
	//*************************

