
function checkAccomChecked(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return;
         }
      }
   } else {
      if (buttonGroup.checked) { return; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
	alert("Please select a chalet.");
   return false;
	
}

function getPage()
{
with (document.pageSelect.pgnm)
	{
	var choice = options[selectedIndex].value;
	location.replace('index.php?pgnm=' + choice);
	}
}
function disableContactId(color1, color2)
{
if(document.bookingForm.enterContactId.checked) {
	disableContactDetails(color1, color2);
	}
else {
	enableContactDetails(color1, color2);
	}	
}

function disableContactDetails(color1, color2)
{
document.bookingForm.name.disabled = true;	
document.bookingForm.emailAddress.disabled = true;	
document.bookingForm.homeAddress.disabled = true;	
document.bookingForm.phoneNumber.disabled = true;	
document.bookingForm.memberPassword.disabled = false;	
document.bookingForm.contactId.disabled = false;	
document.getElementById("name").style.backgroundColor = color2;	
document.getElementById("emailAddress").style.backgroundColor = color2;	
document.getElementById("homeAddress").style.backgroundColor = color2;	
document.getElementById("phoneNumber").style.backgroundColor = color2;	
document.getElementById("memberPassword").style.backgroundColor = color1;	
document.getElementById("contactId").style.backgroundColor = color1;	
focusOn();
focusColor('contactId')
}
function enableContactDetails(color1, color2)
{
document.bookingForm.name.disabled = false;	
document.bookingForm.emailAddress.disabled = false;	
document.bookingForm.homeAddress.disabled = false;	
document.bookingForm.phoneNumber.disabled = false;	
document.bookingForm.memberPassword.disabled = true;	
document.bookingForm.contactId.disabled = true;	
document.getElementById("name").style.backgroundColor = color1;	
document.getElementById("emailAddress").style.backgroundColor = color1;	
document.getElementById("homeAddress").style.backgroundColor = color1;	
document.getElementById("phoneNumber").style.backgroundColor = color1;	
document.getElementById("memberPassword").style.backgroundColor = color2;	
document.getElementById("contactId").style.backgroundColor = color2;	
focusOn();
focusColor('name')
}
// more than 12 days hire alert
function moreHire()
{
days = document.forms[0].elements["boardHireDuration"].value;
if(days=="more")
	{
	alert("If you want to hire a board for more than two weeks you might as well buy one, it would pay for itself in two seasons!\nPlease contact us for a quote.");
	}
}

// less than a week alert

function lessWeek()
{
weeks = document.bookingForm.elements["duration"].value;
if(weeks=="less")
	{
	alert("You can use this form to book holidays of less than a week but\n you should contact us by phone/email to get a quote\n\nAt present you will be automaticaly invoiced for the price of a full weeks holiday, please ignore this invoice,\nwe will send you an adjusted invoice when we have had a chance to check your booking.\n\nThankyou for your patience while we update the functionality of our website.");
	}
}
// Self Catered alert

function selfCatered()
{
accom = document.forms[0].elements["chalet"].value;
if(accom=="self_catered")
	{
	alert("We do not normally do self catered holidays in Chamonix in the summer but if you want to make us an offer, please mention it in the 'special requirements' box below.");
	}
}

// email filter


function checkEmailAddress()
{
strAddress = document.forms[0].elements["emailAddress"].value;

if ((strAddress.indexOf("@") != -1)&&(strAddress.indexOf(".") >= 2))	// contains @ somewhere
	{
	return;
	}
else
	{
	alert("Please make sure you have entered a full email address.");
	return false;
	}


}

// tandc

function checkAGroupIdForm()
{
	aGroupId = document.forms[0].elements["aGroupId"].value;
	strippedPN = stripCharsNotInBag (aGroupId, "0123456789");
	if (strippedPN.length < 3 || strippedPN.length < aGroupId.length)
		{
		alert("Please enter a valid Group Id");
		return false;
		}

}

function checkBookingForm() {
	if(document.bookingForm.enterContactId.checked) {
		contactId = document.bookingForm.contactId.value;
		strippedCId = stripCharsNotInBag (contactId, "0123456789");
		if (strippedCId.length < 1) {
			alert("Contact ID Not Long Enough");
			return false;
		}

	}
	else {
		leader = document.bookingForm.elements["name"].value;
		while (leader.substring(0,1) == ' ') leader = leader.substring(1);
		if (leader == "") {
			alert("Please make sure you have entered your name.");
			return false;
		}

		strAddress = document.bookingForm.elements["emailAddress"].value;
		if (strAddress.indexOf("@") == -1) { // contains @ somewhere
			alert("Please make sure you have entered a full email address!");
			return false;
		}

		phonenumber = document.bookingForm.elements["phoneNumber"].value;
		strippedPN = stripCharsNotInBag (phonenumber, "0123456789");
		if (strippedPN.length < 10) {
			alert("Phone Number Not Long Enough");
			return false;
		}
	
		address = document.bookingForm.elements["homeAddress"].value;
		while (address.substring(0,1) == ' ') address = address.substring(1);
		if (address == "") {
			alert("Please make sure you have entered a postal address where we can send confirmation!");
			return false;
		}
	}

	dur = document.bookingForm.elements["duration"].value;
	if ((dur == "noDur") && (acc != "seasonal")) {
		alert("Please select a duration (in weeks) for your holiday. For holidays over 4 weeks, please select 1 week and say how long you would like to stay in the 'Dietry/Other requirements' section!");
		return false;
	}

	ischecked = eval("document.bookingForm.tandc.checked");
	if (ischecked == false) {
		alert("Please check the box to confirm that you have read the Terms and Conditions!");
		return false;
	}
}

function stripCharsNotInBag (s, bag)

{   var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) != -1) returnString += c;
    }

    return returnString;
}

// count for instances of a character or word in a string
function countInstances(string, word) {
  var substrings = string.split(word);
  return substrings.length - 1;
}
// no self-catering popup

function noSelfCatered()
{
if (document.bookingForm.chalet.value=="self_catered")
	{
	alert("For Self-Catered holidays please DO NOT use this booking form, instead email us (by clicking the link at the bottom of the window)");
	}
}

// disable duration select box

var newwin;
function launchwin(winurl,winname,winfeatures)
{
newwin = window.open(winurl,winname,winfeatures);
}


var preloadFlag = false;


function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
preloadFlag = true;
}




function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

