function validate() {

            var elInput = document.form.elements;
            var toAlert = '';
            var valid = 0;
            for (j = 0; j < document.form.elements.length; j++) {

                if (elInput[j].value == "") {
//Michael's code placed the 'Address' and 'city' field on next line as the 'radio' type 
                    if (elInput[j].type != 'radio' && elInput[j].id != 'Address' && elInput[j].id != 'city' && elInput[j].id != 'otherDept' && elInput[j].id != 'zip' && elInput[j].id != '00N30000003nwae' && elInput[j].type != 'select-one') {
                        valid++;
                    }
                    try {
                        elInput[j].focus();

                        var err_text = elInput[j].id + "_err";
						//Michael's code placed the 'Address' and 'city' field on next line as the 'radio' type 
                        if (elInput[j].type != 'radio' && elInput[j].id != 'Address' && elInput[j].id != 'city' && elInput[j].id != 'otherDept' && elInput[j].id != 'zip' && elInput[j].id != '00N30000003nwae') {
                            toAlert += 'Please enter a value for ' + elInput[j].id + '\n\r';
                        }
						
                    }
                    catch (err) {
                    }

                }
                else {
                    var err_text = elInput[j].id + "_err";
                    try {
                        document.getElementById(err_text).innerText = '';
                    }
                    catch (err) {
                    }
                }

                if (elInput[j].id == 'email') {
                    //check email format
                    var valEml = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/; //regular expression defining an email
                    if (elInput[j].value.search(valEml) == -1 && elInput[j].value != "") //if text has been entered and match failed
                    {
                        valid++;
                        var err_text = elInput[j].id + "_err";
                        toAlert += 'Please enter a valid email' + '\n\r';
                    }
                }

                //if (elInput[j].id == 'phone') {
                    //check phone number format
                  //  var valPhone = /^\d{11}$/ //regular expression defining a 11 digit number

                    //if (elInput[j].value.search(valPhone) == -1 && elInput[j].value != "") //if text has been entered and match failed
                    //{
                      //  valid++;
                        //var err_text = elInput[j].id + "_err";
                        //toAlert += 'Please enter a valid phone number' + '\n\r';
                    //}
                //}
                var toReturn;
                if (valid > 0) {

                    toReturn = false;
                }
                else {
                    toReturn = true;
                }
            }
            if (toReturn == false)
                alert(toAlert);
            return toReturn;

        }


/* This script and many more are available free online at

The JavaScript Source!! http://javascript.internet.com

Cookie script - Scott Andrew

Popup script, Copyright 2005, Sandeep Gangadharan */

function newCookie(name,value,days) {

 var days = 360;   // the number at the left reflects the number of days for the cookie to last

                 // modify it according to your needs

 if (days) {

   var date = new Date();

   date.setTime(date.getTime()+(days*24*60*60*1000));

   var expires = "; expires="+date.toGMTString(); }

   else var expires = "";

   document.cookie = name+"="+value+expires+"; path=/"; 

}

function readCookie(name) {

   var nameSG = name + "=";

   var nuller = '';

  if (document.cookie.indexOf(nameSG) == -1)

    return nuller;

   var ca = document.cookie.split(';');

  for(var i=0; i<ca.length; i++) {

    var c = ca[i];

    while (c.charAt(0)==' ') c = c.substring(1,c.length);

  if (c.indexOf(nameSG) == 0) 

  	return c.substring(nameSG.length,c.length); }

    return null; 

}

function eraseCookie(name) {

  newCookie(name,"",1); 

 }

function toMem(a) {

    newCookie('theFirstName', document.form.first_name.value);     // add a new cookie as shown at left for every

	newCookie('theLastName', document.form.last_name.value);

    newCookie('theEmail', document.form.email.value);   // field you wish to have the script remember

	newCookie('theTitle', document.form.title.value);

	newCookie('theCompany', document.form.company.value);

	newCookie('theAddress', document.form.Address.value);

	newCookie('theCity', document.form.city.value);

	newCookie('theZip', document.form.zip.value);

	newCookie('thePhone', document.form.phone.value);

	newCookie('theState', document.form.state.selectedIndex);

}

function delMem(a) {

  eraseCookie('theFirstName');   // make sure to add the eraseCookie function for every field

  eraseCookie('theLastName');

  eraseCookie('theEmail');

  eraseCookie('theZip');

  eraseCookie('theTitle');

  eraseCookie('theCompany');

  eraseCookie('theAddress');

  eraseCookie('theCity');

  eraseCookie('thePhone');

  eraseCookie('theState');

   //document.form.first_name.value = '';   // add a line for every field

   document.form.last_name.value = '';

   document.form.zip.value = '';

   document.form.email.value = '';

   document.form.title.value = '';

   document.form.company.value = '';

   document.form.Address.value = '';

   document.form.city.value = '';

   document.form.phone.value = '';

   document.form.state.selectedIndex = 0;

   }

function remCookie() {

	if(document.form.checker) { //check to see if the "remember me" checkbox is on the form//

		document.form.first_name.value = readCookie("theFirstName");

		document.form.last_name.value = readCookie("theLastName");

		document.form.zip.value = readCookie("theZip");

		document.form.email.value = readCookie("theEmail");

		//if(readCookie("theTitle")) {

			document.form.title.value = readCookie("theTitle");

		//}

		document.form.company.value = readCookie("theCompany");

		document.form.Address.value = readCookie("theAddress");

		document.form.city.value = readCookie("theCity");

		document.form.phone.value = readCookie("thePhone");

		document.form.state.selectedIndex = readCookie("theState");

		document.form.checker.checked = true;

	}

}







// Multiple onload function created by: Simon Willison



// http://simon.incutio.com/archive/2004/05/26/addLoadEvent



function addLoadEvent(func) {



  var oldonload = window.onload;



  if (typeof window.onload != 'function') {



    window.onload = func;



  } else {



    window.onload = function() {



      if (oldonload) {



        oldonload();



      }



      func();



    }



  }



}







addLoadEvent(function() {



  remCookie();



});







//Show/hide functionality for forms







function el(tid) { //gets an element by its ID.



	return document.getElementById(tid);



}







//a show-hide toggle function



function showme(s) {



	var elmt = el(s);



	var els = elmt.style;



	if (els.display && els.display != "none") {



		elmt._sty_disp_bk = els.display ? els.display : "none";



		elmt.style.display = "none";



	} else {



		elmt.style.display = elmt._sty_disp_bk || "block";



	return 1;



	}



}







function hide(s) {



	el(s).style.display = "none";



}







function show(s) {



	el(s).style.display = "block";



}



function updateStates(selectedCountry){

	var countrieslist = document.form.country;

	var stateslist = document.form.state;

	var states=new Array()

	states[0]=""

	states[1]=["--|", "AK|AK", "AL|AL", "AR|AR", "AZ|AZ", "CA|CA", "CO|CO", "CT|CT", "DC|DC", "DE|DE", "FL|FL", "GA|GA", "HI|HI", "IA|IA", "ID|ID", "IL|IL", "IN|IN", "KS|KS", "KY|KY", "LA|LA", "MA|MA", "MD|MD", "ME|ME", "MI|MI", "MN|MN", "MO|MO", "MS|MS", "MT|MT", "NC|NC", "ND|ND", "NE|NE", "NH|NH", "NJ|NJ", "NM|NM", "NV|NV", "NY|NY", "OH|OH", "OK|OK", "OR|OR", "PA|PA", "RI|RI", "SC|SC", "SD|SD", "TN|TN", "TX|TX", "UT|UT", "VA|VA", "VT|VT", "WA|WA", "WI|WI", "WV|WV", "WY|WY"];



	states[2]=[ "--|", "---England---|", "Bedfordshire|Bedfordshire", "Berkshire|Berkshire", "Bristol|Bristol", "Buckinghamshire|Buckinghamshire", "Cambridgeshire|Cambridgeshire", "Cheshire|Cheshire", "City of London|City of London", "Cornwall|Cornwall", "Cumbria|Cumbria", "Derbyshire|Derbyshire", "Devon|Devon", "Dorset|Dorset", "Durham|Durham",



"East Riding of Yorkshire|East Riding of Yorkshire", "East Sussex|East Sussex", "Essex|Essex",



"Gloucestershire|Gloucestershire", "Greater London|Greater London", "Greater Manchester|Greater Manchester", "Hampshire|Hampshire", "Herefordshire|Herefordshire", "Hertfordshire|Hertfordshire", "Isle of Wight|Isle of Wight", "Kent|Kent", "Lancashire|Lancashire", "Leicestershire|Leicestershire", "Lincolnshire|Lincolnshire", "Merseyside|Merseyside", "Norfolk|Norfolk", "North Yorkshire|North Yorkshire", "Northamptonshire|Northamptonshire", "Northumberland|Northumberland", "Nottinghamshire|Nottinghamshire", "Oxfordshire|Oxfordshire", "Rutland|Rutland", "Shropshire|Shropshire", "Somerset|Somerset", "South Yorkshire|South Yorkshire", "Staffordshire|Staffordshire",



"Suffolk|Suffolk", "Surrey|Surrey", "Tyne and Wear|Tyne and Wear", "Warwickshire|Warwickshire", "West Midlands|West Midlands", "West Sussex|West Sussex", "West Yorkshire|West Yorkshire", "Wiltshire|Wiltshire", "Worcestershire|Worcestershire", "---Wales---|", "Anglesey|Anglesey", "Brecknockshire|Brecknockshire", "Caernarfonshire|Caernarfonshire", "Carmarthenshire|Carmarthenshire", "Cardiganshire|Cardiganshire",



"Denbighshire|Denbighshire", "Flintshire|Flintshire", "Glamorgan|Glamorgan", "Merioneth|Merioneth",



"Monmouthshire|Monmouthshire", "Montgomeryshire|Montgomeryshire", "Pembrokeshire|Pembrokeshire", "Radnorshire|Radnorshire", "---Scotland---|", "Aberdeenshire|Aberdeenshire", "Angus|Angus", "Argyllshire|Argyllshire", "Ayrshire|Ayrshire",



"Banffshire|Banffshire", "Berwickshire|Berwickshire", "Buteshire|Buteshire", "Cromartyshire|Cromartyshire",



"Caithness|Caithness", "Clackmannanshire|Clackmannanshire", "Dumfriesshire|Dumfriesshire", "Dunbartonshire|Dunbartonshire", "East Lothian|East Lothian", "Fife|Fife", "Inverness-shire|Inverness-shire", "Kincardineshire|Kincardineshire",



"Kinross|Kinross", "Kirkcudbrightshire|Kirkcudbrightshire", "Lanarkshire|Lanarkshire", "Midlothian|Midlothian",



"Morayshire|Morayshire", "Nairnshire|Nairnshire", "Orkney|Orkney", "Peeblesshire|Peeblesshire", "Perthshire|Perthshire",



"Renfrewshire|Renfrewshire", "Ross-shire|Ross-shire", "Roxburghshire|Roxburghshire", "Selkirkshire|Selkirkshire",



"Shetland|Shetland", "Stirlingshire|Stirlingshire", "Sutherland|Sutherland", "West Lothian|West Lothian",



"Wigtownshire|Wigtownshire", "---Northern Ireland---|","Antrim|Antrim", "Armagh|Armagh", "Down|Down", "Fermanagh|Fermanagh", "Londonderry|Londonderry", "Tyrone|Tyrone"];

	

	states[229]=[ "--|", "---England---|", "Bedfordshire|Bedfordshire", "Berkshire|Berkshire", "Bristol|Bristol", "Buckinghamshire|Buckinghamshire", "Cambridgeshire|Cambridgeshire", "Cheshire|Cheshire", "City of London|City of London", "Cornwall|Cornwall", "Cumbria|Cumbria", "Derbyshire|Derbyshire", "Devon|Devon", "Dorset|Dorset", "Durham|Durham",



"East Riding of Yorkshire|East Riding of Yorkshire", "East Sussex|East Sussex", "Essex|Essex",



"Gloucestershire|Gloucestershire", "Greater London|Greater London", "Greater Manchester|Greater Manchester", "Hampshire|Hampshire", "Herefordshire|Herefordshire", "Hertfordshire|Hertfordshire", "Isle of Wight|Isle of Wight", "Kent|Kent", "Lancashire|Lancashire", "Leicestershire|Leicestershire", "Lincolnshire|Lincolnshire", "Merseyside|Merseyside", "Norfolk|Norfolk", "North Yorkshire|North Yorkshire", "Northamptonshire|Northamptonshire", "Northumberland|Northumberland", "Nottinghamshire|Nottinghamshire", "Oxfordshire|Oxfordshire", "Rutland|Rutland", "Shropshire|Shropshire", "Somerset|Somerset", "South Yorkshire|South Yorkshire", "Staffordshire|Staffordshire",



"Suffolk|Suffolk", "Surrey|Surrey", "Tyne and Wear|Tyne and Wear", "Warwickshire|Warwickshire", "West Midlands|West Midlands", "West Sussex|West Sussex", "West Yorkshire|West Yorkshire", "Wiltshire|Wiltshire", "Worcestershire|Worcestershire", "---Wales---|", "Anglesey|Anglesey", "Brecknockshire|Brecknockshire", "Caernarfonshire|Caernarfonshire", "Carmarthenshire|Carmarthenshire", "Cardiganshire|Cardiganshire",



"Denbighshire|Denbighshire", "Flintshire|Flintshire", "Glamorgan|Glamorgan", "Merioneth|Merioneth",



"Monmouthshire|Monmouthshire", "Montgomeryshire|Montgomeryshire", "Pembrokeshire|Pembrokeshire", "Radnorshire|Radnorshire", "---Scotland---|", "Aberdeenshire|Aberdeenshire", "Angus|Angus", "Argyllshire|Argyllshire", "Ayrshire|Ayrshire",



"Banffshire|Banffshire", "Berwickshire|Berwickshire", "Buteshire|Buteshire", "Cromartyshire|Cromartyshire",



"Caithness|Caithness", "Clackmannanshire|Clackmannanshire", "Dumfriesshire|Dumfriesshire", "Dunbartonshire|Dunbartonshire", "East Lothian|East Lothian", "Fife|Fife", "Inverness-shire|Inverness-shire", "Kincardineshire|Kincardineshire",



"Kinross|Kinross", "Kirkcudbrightshire|Kirkcudbrightshire", "Lanarkshire|Lanarkshire", "Midlothian|Midlothian",



"Morayshire|Morayshire", "Nairnshire|Nairnshire", "Orkney|Orkney", "Peeblesshire|Peeblesshire", "Perthshire|Perthshire",



"Renfrewshire|Renfrewshire", "Ross-shire|Ross-shire", "Roxburghshire|Roxburghshire", "Selkirkshire|Selkirkshire",



"Shetland|Shetland", "Stirlingshire|Stirlingshire", "Sutherland|Sutherland", "West Lothian|West Lothian",



"Wigtownshire|Wigtownshire", "---Northern Ireland---|","Antrim|Antrim", "Armagh|Armagh", "Down|Down", "Fermanagh|Fermanagh", "Londonderry|Londonderry", "Tyrone|Tyrone"];

	

	states[230]=["--|", "AK|AK", "AL|AL", "AR|AR", "AZ|AZ", "CA|CA", "CO|CO", "CT|CT", "DC|DC", "DE|DE", "FL|FL", "GA|GA", "HI|HI", "IA|IA", "ID|ID", "IL|IL", "IN|IN", "KS|KS", "KY|KY", "LA|LA", "MA|MA", "MD|MD", "ME|ME", "MI|MI", "MN|MN", "MO|MO", "MS|MS", "MT|MT", "NC|NC", "ND|ND", "NE|NE", "NH|NH", "NJ|NJ", "NM|NM", "NV|NV", "NY|NY", "OH|OH", "OK|OK", "OR|OR", "PA|PA", "RI|RI", "SC|SC", "SD|SD", "TN|TN", "TX|TX", "UT|UT", "VA|VA", "VT|VT", "WA|WA", "WI|WI", "WV|WV", "WY|WY"];



	stateslist.options.length=0

	var countryVal = document.form.country.options[selectedCountry].value;

	//alert(countryVal);

	if (countryVal == 'United States' || countryVal=='United Kingdom' || countryVal=='GB' || countryVal=='US'){ 

	//added two-character codes for new demo download form

		if(countryVal == 'United States' || countryVal == 'US') { 

			var countryIndex = 1;

			show('stateSelection');

			document.form.state.focus();

			show('stateLabel');

			hide('countyLabel');

			hide('blankLabel');

		}

		if(countryVal == 'United Kingdom' || countryVal == 'GB') {

			var countryIndex = 2;

			show('stateSelection');

			document.form.state.focus();

			show('countyLabel');

			hide('stateLabel');

			hide('blankLabel');

			

		}

		for (i=0; i<states[countryIndex].length; i++)

			stateslist.options[stateslist.options.length] = new Option(states[countryIndex][i].split("|")[0], states[countryIndex][i].split("|")[1]/*, states[selectedCountry][i].split("|")[2] */)

	} else {

		hide('stateSelection');

	}

	//alert(document.form.state.value);



}
