// function to open error window to help debugging whilst scripting is in development
	onerror = errWindow
	
	function errWindow(errMsg,location,lineNum) {
		debugWin = window.open("","debugWin","height=200,width=300,resize=yes")
		debugWin.document.write("<h2>There was an error at line " + lineNum)
		debugWin.document.write("<br />The error was: " + errMsg + "<\/h2>")
		debugWin.document.close()
		return true
	}

	//Creating new object images for navigation rollovers

		
		bookHov = new Image
		bookOff = new Image

		noteHov = new Image
		noteOff = new Image

		mailHov = new Image
		mailOff = new Image


		bookHov.src = "images/bar2_ro.jpg"
		bookOff.src = "images/bar2.jpg"

		noteHov.src = "images/bar4_ro.jpg"
		noteOff.src = "images/bar4.jpg"

		mailHov.src = "images/bar5_ro.jpg"
		mailOff.src = "images/bar5.jpg"


//Function to change images to create rollovers
	//'imgField' is the name of the original image
	//and 'newImg' is the image to replace it upon mouseOver.

	function chgImg(imgField,newImg) {
		if (document.images) {
			document[imgField].src= eval(newImg + ".src")
		}
	}



// Function to add text to a node by node ID - parameters are 'nodeID' and 'Text'

	function addNode(nodeID, Text) {
		if(document.getElementById){	
		newGraf = document.createElement("p")
		newText = document.createTextNode(Text)
		newGraf.appendChild(newText)

		node = document.getElementById(nodeID);
		node.appendChild(newGraf)
		return false
		}
	}

// Function to remove last child of a node by 'node ID'

	function delNode(nodeID) {
		if(document.getElementById){
		node = document.getElementById(nodeID);
		node.removeChild(node.lastChild);
		}
	}



//
//FORM VALIDATION
//


//Function to check if input is a number, parameter is 'passedVal'

	function isNum(passedVal) {		
		if (passedVal == "") {
			return false
		}
		for (i=0; i<passedVal.length; i++) {
			if (passedVal.charAt(i) < "0") {
			return false
		}
		if (passedVal.charAt(i) > "9") {
			return false
		}
	}
	return true

	}

//function using Regular expression to check for email address validity

	re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/	

	function validEmail(mail) {
		if(re.test(mail)) {
			return true
		}
		else
			return false
		}



//Function to verify fields upon form submittal which in turn calls 'sub-functions'(above)

	function submitIt(myForm) {

	//ensure that they have agreed to terms and conditions

		if (!myForm.terms.checked) {
		alert ("You must Read and Agree to our Terms Before Booking")
		myForm.terms.focus()
	return false
		}

	//ensure that Grooms name is filled in

		if (myForm.GroomName.value=="") {
		alert ("You must Enter The Groom's Name")
		myForm.GroomName.focus()
		myForm.GroomName.select()
	return false
		}

	//ensure that Brides name is filled in

		if (myForm.BrideName.value=="") {
		alert ("You must Enter The Bride's Name")
		myForm.BrideName.focus()
		myForm.BrideName.select()
	return false
		}

	//ensure that Year is filled in

		if (myForm.years.value=="") {
		alert ("You must Select the Year of the Wedding")
		myForm.years.focus()
	return false
		}

	//ensure that Month is filled in

		if (myForm.months.value=="") {
		alert ("You must Select the Month of the Wedding")
		myForm.months.focus()
	return false
		}



	//ensure that Hour is filled in

		if (myForm.hours.value=="") {
		alert ("You must Select the Time of the Wedding")
		myForm.hours.focus()
	return false
		}

	//ensure that Minutes is filled in

		if (myForm.minutes.value=="") {
		alert ("You must Select the Time of the Wedding")
		myForm.minutes.focus()
	return false
		}

	//ensure that am/pm is filled in

		if (myForm.ampm.value=="") {
		alert ("You must Select the Time as morning or afternoon")
		myForm.ampm.focus()
	return false
		}

	//ensure that Wedding Address is filled in

		if (myForm.wedAddr.value=="") {
		alert ("You must enter the Full address of the Wedding")
		myForm.wedAddr.focus()
		myForm.wedAddr.select()
	return false
		}

	//ensure that Wedding Address Postcode is filled in

		if (myForm.wedPostCode.value=="") {
		alert ("You must enter the Postcode of the Wedding")
		myForm.wedPostCode.focus()
		myForm.wedPostCode.select()
	return false
		}

	//ensure that Contacts Name is filled in

		if (myForm.ContactName.value=="") {
		alert ("You must enter a Contact Name")
		myForm.ContactName.focus()
		myForm.ContactName.select()
	return false
		}

	//ensure that Contact's Address is filled in

		if (myForm.contAddr.value=="") {
		alert ("You must enter the Full address for the Contact Person")
		myForm.contAddr.focus()
		myForm.contAddr.select()
	return false
		}

	//ensure that Contact's Address Postcode is filled in

		if (myForm.contPostCode.value=="") {
		alert ("You must enter the Postcode for the Contact Person")
		myForm.contPostCode.focus()
		myForm.contPostCode.select()
	return false
		}

	//ensure that Contact's Phone Number is filled in

		if (myForm.HomePhoneNumber.value=="") {
		alert ("You must enter a Phone Number for the Contact Person")
		myForm.HomePhoneNumber.focus()
		myForm.HomePhoneNumber.select()
	return false
		}


	//ensure that the Required Service is filled in

		if (myForm.service.value=="") {
		alert ("You must select a type of service")
		myForm.service.focus()
	return false
		}



return true
}


//function to check for valid postcode format and to deliver prompt on screen if not
	pcRe=/^([A-Za-z]{1,2})([0-9]{1,2})\s?([0-9]{1,2})([A-Za-z]{2})$/	//Postcode regular expression

	function validPostcode(code) {
		if(pcRe.test(code.value)) {
		
			return true
		}
		else
		alert ("Incorrect Postcode Format - e.g. SW1 3LF or sw13lf")				
		return false
		}


	//ensure that Contact's Phone Number is numeric
	function validPhone(telno) {
		if (isNum(telno.value)) {
			return true
		}
		else
		alert ("Please enter a valid Phone Number for the Contact Person (numbers only, no dashes or spaces)")
		myForm.HomePhoneNumber.focus()
		myForm.HomePhoneNumber.select()
	return false
		}

// function to put correct number of days in drop-down after month has been selected

		monthDays = new Array(31,28,31,30,31,30,31,31,30,31,30,31)
	
		function populateDays(monthChosen) {
			monthStr = monthChosen.options[monthChosen.selectedIndex].value
			if (monthStr != "") {
				theMonth=parseInt(monthStr)
							
				document.myForm.days.options.length = 0
				for(i=0;i<monthDays[theMonth];i++) {
					document.myForm.days.options[i] = new Option(i+1)
				}
			}
		}



//pop up window func

	function newWindow(pagename) {
		fullName = pagename + ".htm"
		winName = pagename + "Win"
		bookWindow = window.open(fullName,winName,"width=400,height=400,scrollbars=yes,resizable=yes")
		bookWindow.focus()
	}
	
