<!--
function appendOptionLast(optiontext)
{
  var elOptNew = document.createElement('option');
  elOptNew.text = optiontext;
  elOptNew.value = optiontext;
  var elSel = document.getElementById('stage1cill');

  try {
    elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
  }
  catch(ex) {
    elSel.add(elOptNew); // IE only
  }
}

function removeOptionLast()
{
  var elSel = document.getElementById('stage1cill');
  if (elSel.length > 0)
  {
    elSel.remove(elSel.length - 1);
  }
}
//-->


function updatehelp(control){
//alert (control.toString());
switch (control.toString())
  {
    case "stage1typeofdoor": {helpbox.innerHTML="Please choose if you want our Smarts Durafold 1000 or Continental bi-folds."; break }
    case "stage1width": {helpbox.innerHTML="Please enter the overall width. This will be the manufactured size - so make this approx 10-20mm less than the opening width (this is a guide only and will vary depending fitter preferences).<br /><br />Min width is 1400mm, Standard max width is 6000mm.<br />Widths greater than 6 metres can be manufactured but not priced on the website. Please call our Sales Dept."; break }
    case "stage1height": { helpbox.innerHTML="Please enter the overall height. This is the overall height INCLUDING ANY CILL and should be your opening size less approx 10-20mm (this is a guide only and will vary depending fitter preferences).<br /><br />Min height is 500mm for a window and 1950mm for a door, 2400mm on Smarts Durafold 1000 and 3000mm on our Continental doors."; break }
    case "stage1cill": { helpbox.innerHTML="Please select a projection cill size, or none if not required."; break }
    case "stage1inout": { helpbox.innerHTML="Please select if the door leafs are to open into the room or outisde, when viewed from outside."; break }

    case "stage2style": { helpbox.innerHTML="The possible styles listed are shown for your opening width. Please select your preferred style as viewed from the outside."; break }

    case "stage3framecolour": { helpbox.innerHTML="Please choose a colour for your bi-fold doors.<br />Standard colours are listed, or you may choose a RAL colour or a woodgrain finish.<br /><br />If choosing RAL you will need to give us the RAL code and gloss level when you order."; break }
    case "stage3handlecolour": { helpbox.innerHTML="Please choose the handle colour you require."; break }

    case "stage4cillhorns": { helpbox.innerHTML="Please choose the cill horn extensions, or 'None'.<br />Sizes are per side.<br />This is only applicable if you selected a projection cill in step 1."; break }
    case "stage4threshold": { helpbox.innerHTML="Higher thresholds give the best weather performance, with lower thresholds offering a nearly-flush fit.<br /><br />See our technical drawings for more information."; break }
    case "stage4glazing": { helpbox.innerHTML="Select the required glazing."; break }
    case "stage4ventilation": { helpbox.innerHTML="Please choose if trickle vents are required. They come in several colours to blend with your frame colour."; break }
    case "stage4comments": { helpbox.innerHTML="Please use this box to make any comments that will help you.  e.g. a reference number."; break }
    case "stage4integratedblinds": { helpbox.innerHTML="If you would like blinds within the glazing units please choose a colour."; break }

    case "stage5email": { helpbox.innerHTML="Please enter your email address. We can then send you this summary plus an estimated price. We will NOT use this address for any purpose other than correspondance for this and related estimates."; break }
    case "stage5vat": { helpbox.innerHTML="Please enter your VAT registration number. If you do not have a VAT number then we cannot give you our trade prices - we will supply our non-trade price."; break }
    case "stage5companyname": { helpbox.innerHTML="Please enter your company name. This is used to help deal with your estimate more efficiently if you contact us in the future."; break }
    case "stage5promocode": { helpbox.innerHTML="Please enter your promotional code if you have one."; break }

    default: { helpbox.innerHTML="Use this section of the screen to see help for each question. As you move between questions this section will change to give you help for that question."; break }
  }


//alert ('update help script called' + control.toString());
}



function emailCheck (emailStr) {
var emailPat=/^(.+)@(.+)$/
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
var validChars="\[^\\s" + specialChars + "\]"
var quotedUser="(\"[^\"]*\")"
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
var atom=validChars + '+'
var word="(" + atom + "|" + quotedUser + ")"
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

/* Finally, let's start trying to figure out if the supplied address is
   valid. */

var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	alert("Your email address seems incorrect, please check it and try again.")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
	alert("Your email address seems incorrect, please check it and try again.")
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
			alert("Your email address seems incorrect, please check it and try again.")
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("Your email address seems incorrect, please check it and try again.")
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>4) {
   // the address must end in a two letter or three or 4 letter word.
	alert("Your email address seems incorrect, please check it and try again.")
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
	alert("Your email address seems incorrect, please check it and try again.")
   alert(errStr)
   return false
}

// If we've gotten this far, everything's valid!
return true;
}


function checkcillsetcform(){
//basic checks before submitting.
	var problems = ""
	
	if (frmcillsetc.stage4cillhorns.selectedIndex == 0)
	{
		problems += "Please select one of the listed cill horn extensions, or 'None'.\n"
	}
	
	if (frmcillsetc.stage4threshold.selectedIndex == 0)
	{
		problems += "Please select one of the listed thresholds.\n"
	}

	if (frmcillsetc.stage4glazing.selectedIndex == 0)
	{
		problems += "Please select one of the listed glazed or unglazed options.\n"
	}

	if (frmcillsetc.stage4integratedblinds.selectedIndex == 0)
	{
		problems += "Please select an integrated blind option, or 'None'.\n"
	}
	
	if (frmcillsetc.stage4ventilation.selectedIndex == 0)
	{
		problems += "Please select one of the listed ventilation options, or 'None'.\n"
	}

	if (problems.length > 0)
	{
		alert(problems);
		return false;
	}
	else
	{
		return true;
	}
	
}


function checkcoloursform(){
//basic checks before submitting.
	var problems = ""
	
	if (frmcolours.stage3framecolour.selectedIndex == 0)
	{
		problems += "Please choose a frame colour.\n"
	}

	if (frmcolours.stage3handlecolour.selectedIndex == 0)
	{
		problems += "Please choose a handle colour.\n"
	}

	

	if (problems.length > 0)
	{
		alert(problems);
		return false;
	}
	else
	{
		return true;
	}
	


}


function checksizeform(){
//basic checks before submitting.
	var problems = ""
	
	if (frmsizes.stage1typeofdoor.selectedIndex == 0)
	{
		problems += "Please choose your preferred door system.\n"
	}

	if (frmsizes.stage1width.value.length == 0)
	{
		problems += "Please enter an overall width.\n"
	}

	if (frmsizes.stage1height.value.length == 0)
	{
		problems += "Please enter an overall height.\n"
	}

	if (frmsizes.stage1cill.selectedIndex == 0)
	{
		problems += "Please choose cill size or 'None'\n"
	}

	if (frmsizes.stage1inout.selectedIndex == 0)
	{
		problems += "Please choose if the door opens in or out.\n"
	}

	if (problems.length > 0)
	{
		alert(problems);
		return false;
	}
	else
	{
		return true;
	}

}


function checkstyleform(){
//basic checks before submitting.
	var problems = ""
	
	if (frmstyles.stage2style.selectedIndex == 0)
	{
		problems += "Please select one of the listed styles.\n"
	}

	if (problems.length > 0)
	{
		alert(problems);
		return false;
	}
	else
	{
		return true;
	}
	
}

