var errorCount = 0;
tweeked = new Array();
var maxPax=8;

var highlight = '#aa0000';
var textcolour = '#ffffff';
/***********************************************
 * * Email Validation script- © Dynamic Drive (www.dynamicdrive.com)
 * * This notice must stay intact for legal use.
 * * Visit http://www.dynamicdrive.com/ for full source code
 * ***********************************************/

var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i

function checkmail(e){
	var returnval=emailfilter.test(e.value)
	if (returnval==false){
		alert("Please enter a valid email address.")
		e.select()
	}
	return returnval
}

function validateEmail() {
	var doc=document.prefs;
	var at = doc.addy.value.indexOf('@');
	if ( at == -1 ) {
		alert(errorMSG['NoAt']);
		doc.addy.style.background = highlight;
		doc.addy.style.color = textcolour;
	} else {
		doc.addy.style.background = '#ffffff';
		doc.addy.style.color = '#000000';
	}
	checkemail(doc.addy);
}

function validateForm() {
	var doc=document.prefs;
	if ( doc.addy.value == "" ) {
		alert(errorMSG['Email']);
		doc.addy.style.background = highlight;
		doc.addy.style.color = textcolour;
		return false;
	}
	if ( doc.addy.value == "Your email" ) {
		alert(errorMSG['Email']);
		doc.addy.style.background = highlight;
		doc.addy.style.color = textcolour;
		return false;
	}
	if ( doc.addy.value != doc.addy2.value ) {
		alert(errorMSG['NotSame']);
		doc.addy.style.background = highlight;
		doc.addy.style.color = textcolour;
		return false;
	}
	if (( doc.adults.selectedIndex < 1 ) || ( doc.adults.selectedIndex == -1 )) {
		alert(errorMSG['OneAdult']);
		doc.adults.focus();
		doc.adults.style.background = highlight;
		doc.adults.style.color = textcolour;
		return false;
	} else if ( doc.kids.selectedIndex > ( doc.adults.selectedIndex * 2  ) ) { 
		alert(errorMSG['TooManyKids']);
		doc.adults.focus();
		doc.adults.style.background = highlight;
		doc.adults.style.color = textcolour;
		return false;
	}
	if ( (doc.singles.selectedIndex == -1) && (doc.doubles.selectedIndex == -1) && (doc.twins.selectedIndex == -1) && (doc.triples.selectedIndex == -1)  ) {
		alert(errorMSG['RoomTypes']);
		doc.doubles.focus();
		doc.singles.style.background = highlight;
		doc.doubles.style.background = highlight;
		doc.twins.style.background = highlight;
		doc.triples.style.background = highlight;
		doc.singles.style.color = textcolour;
		doc.doubles.style.color = textcolour;
		doc.twins.style.color = textcolour;
		doc.triples.style.color = textcolour;
		return false;
	}
	if ( ( doc.singles.selectedIndex + (doc.doubles.selectedIndex + doc.twins.selectedIndex ) * 2 + doc.triples.selectedIndex * 3 ) != ( doc.adults.selectedIndex + doc.kids.selectedIndex ) ) {
		alert(errorMSG['RoomNumbers']);
		doc.doubles.focus();
		doc.singles.style.background = highlight;
		doc.doubles.style.background = highlight;
		doc.twins.style.background = highlight;
		doc.triples.style.background = highlight;
		doc.singles.style.color = textcolour;
		doc.doubles.style.color = textcolour;
		doc.twins.style.color = textcolour;
		doc.triples.style.color = textcolour;
		return false;
	}
	if ( (doc.adults.selectedIndex + doc.kids.selectedIndex ) > maxPax ) {
		alert(errorMSG['TooManyPax']);
	}
	if ( doc.ed.value == doc.sd.value ) {
		alert(errorMSG['SelectDates']);
		doc.sd.style.background = highlight;
		doc.ed.style.background = highlight;
		doc.sd.style.color = textcolour;
		doc.ed.style.color = textcolour;
		return false;
	}
}

function validateMoreinfo() {
    var doc=document.prefs;
	if ( doc.style.value  < 1 ) {
		alert(errorMSG['EnterStyle']);
		return false;
	}
	if ( doc.pace.value  < 1 ) {
		alert(errorMSG['EnterPace']);
		return false;
	}
}


/*
function checkTooLong(dDate,q,sDate,currentDate) {
	var doc=document.prefs;
        if ( dDate.getTime() > maxtriplength*24*3600000 ) {
		alert(errorMSG['TripTooLong']);
		var lDate = new Date(sDate.getTime() + maxtriplength*24*3600000);
		doc.eday.selectedIndex = lDate.getDate() - 2;
		doc.eMonYear.selectedIndex = lDate.getMonth() - currentDate.getMonth();
		doc.dur.value = maxtriplength;
	}
}

function howSoon(sDate,q,currentDate) {
	if ( (sDate.getTime() - currentDate.getTime()) < (tripsoon * 3600000) ) {
		alert(errorMSG['Soon']);
	}
}

*/
errorMSG = new Array();
errorMSG['Browser2Old'] = 'Sorry, Wild Things website is compatible with a wide range of browsers.\nHowever, because your browser is several years old it cannot\nbe used to make bookings on this site.\n\nUpdated versions of Mozilla, Netscape Navigator and Internet Explorer\nare available free of charge from the Mozilla, Netscape and Microsoft\nweb sites.';
errorMSG['DatePassed'] = 'Sorry, The date you\'ve selected has already passed. We\'ve changed\nyour selection to the earliest date available.';
errorMSG['ReturnB4Outbound'] = 'Sorry, You\'re planning to safari back in time?!\n This is not currently available. In the mean time, we\'ve\nmade the end date the day after your start one.\nPlease double-check these dates.';
errorMSG['FltSameday'] = 'Sorry, You\'re starting and ending on the same day.\nTrips are a minimum of 1 night.';
errorMSG['InvalidDate'] = 'Sorry, There aren\'t that many days in the month! We\'ve changed\nyour selection to the last day of your chosen month.';
errorMSG['Soon'] = 'Your start day is within 1 week, if this is correct, contact our Dar es Salaam office immediatly!.( Office number - +255 784 479 427 )\n';
errorMSG['TooManyKids'] = 'Sorry, There must be at least 1 adult for every 2 children.\n';
errorMSG['TooManyPax'] = 'Sorry, For trips of more than ' + maxPax  + ' people, you will be eligable for special discounts, but certain cultural locations may require the group to be split to minimise impact. \n';
errorMSG['OneAdult'] = 'Sorry, There must be at least one adult on the trip.\n';
errorMSG['NoAt'] = 'Sorry, Invalid email address.\n';
errorMSG['Email'] = 'Sorry, Please enter an email address.\n';
errorMSG['NotSame'] = 'Sorry, Your email addresses do not match.\n';
errorMSG['EnterDuration'] = 'Sorry, please enter trip length. \n';
errorMSG['EnterStyle'] = 'Sorry, please tell us what accommodation style you would like. \n';
errorMSG['EnterPace'] = 'Sorry, please tell us how action packed, or relaxing you would like your trip to be. \n';
errorMSG['RoomTypes'] = 'Sorry, please enter the type of rooms you require. \n';
errorMSG['RoomNumbers'] = 'Sorry, please check the type of rooms you require are correct for the number of people. \n';
errorMSG['SelectDates'] = 'Please select the dates for your trip. \n';

