//##########
//#CHECKOUT#
//##########

function voucher(ID){
	document.Basket.OrderLineID.value=ID;
	document.Basket.action='/Checkout/Gift_Vouchers';
	document.Basket.submit();
}

function personal(ID, NewLink){

	document.personalise.OrderLineID.value=ID;
	document.personalise.action=NewLink;
	document.personalise.submit();		
	
}

function DeliveryDetailsCheckForm()
{
	var theForm = document.personalise;
	
if ( !RequiredInput(theForm.UserTitle,'Please enter a title') ) { return false; }
if ( !RequiredInput(theForm.FirstName,'Please enter a last name') ) { return false; }
if ( !RequiredInput(theForm.Surname,'Please enter a last name') ) { return false; }
if ( !RequiredInput(theForm.Address1,'Please enter a first address line') ) { return false; }
if ( !RequiredInput(theForm.Town,'Please enter a town') ) { return false; }
if ( !RequiredInput(theForm.PostCode,'Please enter a postcode') ) { return false; }
if ( !RequiredInput(theForm.Area,'Please select a delivery area') ) { return false; }

return true;
}

function MessageCountWords (this_field, show_word_count, show_char_count, Limit) {
	if (show_word_count == null) {
	show_word_count = true;
	}
	if (show_char_count == null) {
	show_char_count = false;
	}
		var char_count = this_field.value.length;
		var fullStr = this_field.value + " ";
		var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
		var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
		var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
		var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
		var splitString = cleanedStr.split(" ");
		var word_count = splitString.length -1;
		if (fullStr.length <2) {
		word_count = 0;
		}
		
		if (word_count == 1) {
			wordOrWords = " word";
		}
		else {
			wordOrWords = " words";
		}
		if (char_count == 1) {
			charOrChars = " character";
		} else {
			charOrChars = " characters";
		}

	var CharLeft = document.Continue.DescLimitHidden.value-char_count 

	if (CharLeft < 0){
		this_field.value = this_field.value.substring(0,Limit);
	}else{
	document.Continue.DescLimit.value = CharLeft	
	}	
return word_count;
}


function GiftcardCountWords (this_field, show_word_count, show_char_count, Limit) {
	if (show_word_count == null) {
	show_word_count = true;
	}
	if (show_char_count == null) {
	show_char_count = false;
	}
		var char_count = this_field.value.length;
		var fullStr = this_field.value + " ";
		var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
		var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
		var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
		var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
		var splitString = cleanedStr.split(" ");
		var word_count = splitString.length -1;
		if (fullStr.length <2) {
		word_count = 0;
		}
		
	var CharLeft = document.Continue.GiftcardLimitHidden.value-char_count 

	if (CharLeft < 0){
		this_field.value = this_field.value.substring(0,Limit);
	}else{
	document.Continue.GiftcardDescLimit.value = CharLeft	
	}	
return word_count;
}


//########
//#BASKET#
//########

function QuantityCheck(StockID,Quantity,PromoCode,Total,SubID){

	if ((Quantity=='')&&(Quantity!=0)){	
	alert('Please make sure you enter a quantity');
	return false
	}
	window.location='/Collection/frontend/basket/Basket-Add.cfm?ID='+StockID+'&quantity='+Quantity+'&PromoCode='+PromoCode+'&total='+Total+'&SubID='+SubID;

}

function PromoCheck(){

	if (document.Promo.PromoCode.value==''){
	alert('Please enter a promotional code');
	return false
	}
	document.Promo.submit();

}

//####################
//#FORGOTTEN PASSWORD#
//####################

function ForgottenCheckForm()
{
	var theForm = document.ProductEmail;

if ( !RequiredInput(theForm.ForgottenPassword,'Please enter your email address') ) { return false; }

return true;
}

//#########################
//#SEARCH LOCATION RESULTS#
//#########################

function SearchLinkCheck(NewLink, Region){
	document.SearchResults.SRLinkCLick.value=Region;
	document.SearchResults.action=NewLink;
	document.SearchResults.submit();
}

//##########
//#WISHLIST#
//##########

function WishListCheckForm()
{
	var theForm = document.ProductEmail;

if ( !RequiredInput(theForm.UserName,'Please enter your name') ) { return false; }
if ( !RequiredInput(theForm.UserEmail,'Please enter your email') ) { return false; }
if ( !RequiredInput(theForm.UserMessage,'Please enter a message for your email') ) { return false; }
if ( !RequiredInput(theForm.Email1,'Please enter an email to send to') ) { return false; }
if ( !ValidateEmail(theForm.Email1,'Please enter a correct email') ) { return false; }

if ( theForm.Email2.value!=''){
	if ( !ValidateEmail(theForm.Email2,'Please enter a correct email for emailaddress 2') ) { return false; }
}
if ( theForm.Email3.value!=''){
	if ( !ValidateEmail(theForm.Email3,'Please enter a correct email for emailaddress 3') ) { return false; }
}
if ( theForm.Email4.value!=''){
	if ( !ValidateEmail(theForm.Email4,'Please enter a correct email for emailaddress 4') ) { return false; }
}
if ( theForm.Email5.value!=''){
	if ( !ValidateEmail(theForm.Email5,'Please enter a correct email for emailaddress 5') ) { return false; }
}

return true;
}

function WishListLinkCheck(NewLink){

document.WishlistIndex.WLLinkCLick.value=NewLink;
document.WishlistIndex.action=NewLink;

document.WishlistIndex.submit();
}

//#################
//#EMAIL A PRODUCT#
//#################

function EmailProductCheckForm()
{
	var theForm = document.ProductEmail;

if ( !RequiredInput(theForm.UserName,'Please enter your name') ) { return false; }
if ( !RequiredInput(theForm.UserEmail,'Please enter a your email') ) { return false; }
if ( !RequiredInput(theForm.UserMessage,'Please enter a message for your email') ) { return false; }
if ( !RequiredInput(theForm.Email1,'Please enter an email address to send to') ) { return false; }
if ( !ValidateEmail(theForm.Email1,'Please enter a correct email') ) { return false; }

if ( theForm.Email2.value!=''){
	if ( !ValidateEmail(theForm.Email2,'Please enter a correct email for emailaddress 2') ) { return false; }
}
if ( theForm.Email3.value!=''){
	if ( !ValidateEmail(theForm.Email3,'Please enter a correct email for emailaddress 3') ) { return false; }
}
if ( theForm.Email4.value!=''){
	if ( !ValidateEmail(theForm.Email4,'Please enter a correct email for emailaddress 4') ) { return false; }
}
if ( theForm.Email5.value!=''){
	if ( !ValidateEmail(theForm.Email5,'Please enter a correct email for emailaddress 5') ) { return false; }
}

return true;
}

//############
//#NEED IDEAS#
//############

function URLChange(){
		var theForm = document.AimedAt ;

			if (theForm.ExpAimedAt.value!=''){
				theForm.action = theForm.ExpAimedAt.value;
				theForm.submit();	
			}
		}

function JoinList()
		{
			var theForm = document.MailList;
			
				if ( !RequiredInput(theForm.EmailSignUp,'Please enter your email address') ) { return false; }
				if ( !ValidateEmail(theForm.EmailSignUp,'Please enter a valid email address ') ) { return false; }
							
			return true;
		}
		
//########
//#SEARCH#
//########		

function PriceSelected(MinPrice, MaxPrice){

var theForm = document.search ;

theForm.MinPrice.value = MinPrice
theForm.MaxPrice.value = MaxPrice
theForm.SearchCriteria.value = ''

theForm.submit();
}

function SearchForm()
{
	var theForm = document.search;
	
	if ( !RequiredInput(theForm.SearchCriteria,'Please enter something to search on') ) { return false; }
	if ( theForm.SearchCriteria.value=='Search here' ){
	
	alert('Please enter something to search on');
	theForm.SearchCriteria.focus();
	return false;
	}
	return true;
}


//#############
//#PRODUCT SUB#
//#############	
function Quantity(id,dir){								
	var i='quantity'+id;						
	var a=document.getElementById(String(i));								
	if(a.value==''){a.value=1;return false;}									
	//Increment
	if(dir==1){																	
		if(a.value>=0){									
			var b=Number(a.value)+1;
			if(b<100){a.value=Number(a.value)+1;}else{alert('You can only order a maximum of 99 items at any one time.');}								
		}else{alert('This is not a real quantity. Please enter a numeric quantity.');}									
	}
	//decrement								
	if(dir==2){																
		if(a.value<=99){									
			var b=Number(a.value)-1;
			if(b>0){a.value=Number(a.value)-1;}							
		}else{alert('This is not a real quantity. Please enter a numeric quantity.');}									
	}					
}
