<!--

/*
*
*	Rate Alert Functions
*
*/

function removeOption() {
	var totalproducts = productsArray.length ;
	var newProductsArray = new Array(totalproducts - 1) ;
	var remOpt = document.ratealertdetails.sendme.value ;
	var counter = 0 ;
	
	//copy the array without the current value
	for(var i=0;i<totalproducts;i++) {
		if(productsArray[i] != remOpt) {
			newProductsArray[counter] = productsArray[i] ;
			counter++ ;
		}
	}
	populateSelectList(newProductsArray, "dontsendme") ;
}

function populateSelectList(listArray, selectName) {

	var theList = eval("document.ratealertdetails." + selectName) ;
	//remove current options
	if(theList.options.length > 0){
		while(theList.length>0) {
			theList.options[0] = null ;
		}
	}

	var opt;
	//add the blank option
	opt = new Option("", "") ;
	theList.options[0] = opt ;
	//populate with the new array
	for(i = 0;i<listArray.length;i++) {
		opt = new Option(listArray[i], listArray[i]) ;
		theList.options[theList.options.length] = opt ;
	}
}

function getUserAge(d,m,y)
{
	m--;
	var currentDate = new Date();
	var diff = currentDate.getFullYear() - y;
	
	if(currentDate.getMonth() < m || (currentDate.getMonth() == m && currentDate.getDate() < d))
	{
		diff--;
	}
	
	return diff;
}


/*
*
*	Rate Alert Validation
*
*/

//rate alert default page
function submitFareAlert(theForm)	{
		
		
	if (!isFieldValidAndFocus(theForm.userEmail, 'email', true, true, 'Your email address'))	{	
		return false;
	}
	
	if (!isFieldValidAndFocus(theForm.userEmailConfirm, 'email', true, true, 'Your confirmation email address'))	{	
		return false;
	}
	
	if (theForm.userEmail.value != theForm.userEmailConfirm.value)	{
		alert("Your confirmation of email does not match your email address.")
		theForm.userEmailConfirm.focus()
		return false
	}
	
	return true;
}

function submitFareAlertExtra(theForm)
{
	
	if (theForm.title.selectedIndex == 0) {
		alert("Please select your title");
		theForm.title.focus();
		return false;
	}
	if (!isFieldValidAndFocus(theForm.forname,"alpha", true, true, 'Forename')) {
		return false;
	}
	if (!isFieldValidAndFocus(theForm.surname,"alpha", true, true, 'Surname')) {
		return false;
	}
	//check the user is over 18
	var userage = getUserAge(parseInt(theForm.dobd.value) ,parseInt(theForm.dobm.value) ,parseInt(theForm.doby.value))
	if (userage < 18)
	{
		alert("Sorry, You must be over 18 to apply for this promotion");
		return false;
	}
	
	if (!isFieldValidAndFocus(theForm.dobd,"Day", true, true, 'Day of Birth')) {
		return false;
	}
	 if (!isFieldValidAndFocus(theForm.dobm,"Month", true, true, 'Month of Birth'))	{
		return false;
	}		
	 	if (!isFieldValidAndFocus(theForm.doby,"Year", true, true, 'Year of Birth'))	{
		return false;
	}
	if (!isFieldValidAndFocus(theForm.postcode,"Postcode", true, false, 'Postcode'))	{
		return false;
	}
	
	return true;
}

function submitFareAlertRecommend() {
	
	if (!isFieldValidAndFocus(document.RecommendAFriend.FriendEmailAdd, 'email', true, true, 'Email Address'))  {
		return false;
	}
	return true;
	
}

//rate alert extra details page
function submitFareAlertDetails() {

	var theForm = document.ratealertdetails ;
	
	if ((!theForm.rate.checked) && (!theForm.fare.checked)) {
		alert("You must select either fare or rate alerts to qualify for the promotion");
		return false;
	}
	
	if (theForm.title.selectedIndex == 0) {
		alert("Please select your title");
		theForm.title.focus();
		return false;
	}
	
	if (!isFieldValidAndFocus(theForm.forname,"alpha", true, true, 'Forename')) {
		return false;
	}
	if (!isFieldValidAndFocus(theForm.surname,"alpha", true, true, 'Surname')) {
		return false;
	}
	if (!isFieldValidAndFocus(theForm.dobd,"Day", true, true, 'Day of Birth')) {
		return false;
	}
  	if (!isFieldValidAndFocus(theForm.dobm,"Month", true, true, 'Month of Birth'))	{
		return false;
	}		
  	if (!isFieldValidAndFocus(theForm.doby,"Year", true, true, 'Year of Birth'))	{
		return false;
	}
	if (!isFieldValidAndFocus(theForm.postcode,"Postcode", true, false, 'Postcode'))	{
		return false;
	}
	if (!isFieldValidAndFocus(theForm.EmailAdd, 'email', true, true, 'Email Address'))  {
		return false;
	}

	return true;
}


//-->
