
			function cleanCAPS(str) {
				capsallowed = 3; // Lowercase if more than ## CAPS in a row
				do {
					eval("re = /([A-Z]{" + (capsallowed+1) + ",})/g;");
					myArray = str.match(re);
					if (myArray) {
						eval("re = /" + myArray[0] + "/;");
						str = str.replace(re, ""+myArray[0].toLowerCase());
					   }
					} while (myArray);
				return str;
				}

			function validate_form() {

				if ( document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_title'].value == "" ) {
					alert ( "Please fill in the 'Event Title' field." );
					document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_title'].focus();
					return(false);
				}
				if ( document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_title'].value != "" ) {
					var alphaExp = /([A-Z]{3,})/g;
					if(document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_title'].value.match(alphaExp)){
						alert ( "'Event Title' field not permitted to have all Capital Letter words, ie WORDS." );
						document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_title'].focus();
						return(false);
					}

				}
				if ( document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_title'].value != "" ) {
					var alphaExp = /^[0-9a-zA-Z\s]+$/;
					if(document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_title'].value.match(alphaExp)){
					}
					else {
						alert ( "Please fill in the 'Event Title' field with only letters, numbers and spaces." );
						document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_title'].focus();
						return(false);
					}
				}


				if ( document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_description'].value == "" ) {
					alert ( "Please fill in the 'Description' field." );
					document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_description'].focus();
					return(false);
				}
				if ( document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_description'].value != "" ) {
					var alphaExp = /^[0-9a-zA-Z\s\,\'\.]+$/;
					if(document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_description'].value.match(alphaExp)){
					}
					else {
						alert ( "Please fill in the 'Description' field with only letters, numbers, spaces, commas, apostrophe's and full stops." );
						document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_description'].focus();
						return(false);
					}
				}
				if ( document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_description'].value != "" ) {
					var wwwExp = /(http|www)+/;
					if(document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_description'].value.match(wwwExp)){
						alert ( "Website addresses not permitted in the 'Description' field. Please fill in the 'Description' field with only letters, numbers, spaces, apostrophe's and full stops. www or http not permitted." );
						return(false);
					}
				}


				if ( document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_city'].value == "" ) {
					alert ( "Please fill in the 'City' field." );
					document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_city'].focus();
					return(false);
				}
				if ( document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_city'].value != "" ) {
					var alphaExp = /^[a-zA-Z\s]+$/;
					if(document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_city'].value.match(alphaExp)){
					}
					else {
						alert ( "Please fill in the 'City' field with only letters and spaces." );
						document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_city'].focus();
						return(false);
					}
				}


				if ( document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_state'].selectedIndex == "0" ) {
					alert ( "Please select a 'State'." );
					document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_state'].focus();
					return(false);
				}

				if ( document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_country'].selectedIndex == "0" ) {
					alert ( "Please select a 'Country'." );
					document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_country'].focus();
					return(false);
				}


				if ( document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_contact'].value == "" ) {
					alert ( "Please fill in the 'Contact Name' field." );
					document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_contact'].focus();
					return(false);
				}
				if ( document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_contact'].value != "" ) {
					var alphaExp = /^[a-zA-Z\s]+$/;
					if(document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_contact'].value.match(alphaExp)){
					}
					else {
						alert ( "Please fill in the 'Contact Name' field with only letters and spaces." );
						document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_contact'].focus();
						return(false);
					}
				}


				if (( document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_phone'].value == "" ) && ( document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_mobile'].value == "" )) {
					alert ( "Please fill in at least one of the 'Phone or Mobile' number fields." );
					document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_phone'].focus();
					return(false);
				}
				if ( document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_phone'].value != "" ) {
					var alphaExp = /^[0-9\s\+]+$/;
					if(document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_phone'].value.match(alphaExp)){
					}
					else {
						alert ( "Please fill in the 'Phone' field with only numbers,spaces and plus symbol +. i.e. 8555 5555  or  +61 8 8555 5555" );
						document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_phone'].focus();
						return(false);
					}
				}
				if ( document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_mobile'].value != "" ) {
					var alphaExp = /^[0-9\s\+]+$/;
					if(document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_mobile'].value.match(alphaExp)){
					}
					else {
						alert ( "Please fill in the 'Mobile' field with only numbers,spaces and plus symbol +. i.e. 0455 555 555 or +61 455 555 555 " );
						document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_mobile'].focus();
						return(false);
					}
				}


				if (document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_email'].value == "") {
					alert ( "Please fill in the \'Email\' field." );
					document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_email'].focus();
					return(false);
				}

				if (document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_email'].value != "") {
					var field = document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_email]']; // email field
					var str = field.value; // email string
					var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
					var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid

					if ((!reg1.test(str)) && (reg2.test(str))) { // if syntax is valid
					}
					else {
						alert("\"" + str + "\" is an invalid e-mail!"); // this is also optional
						field.focus();
						field.select();
						return false;
					}
				}


				if ( document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_website'].value != "" ) {
					var alphaExp = /^(http:\/\/|www\.)/;
					if(document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_website'].value.match(alphaExp)){
					}
					else {
						alert ( "'Website' field is invalid. Only links starting with www. or http permitted. " );
						document.tx_swagevents_pi2_submitForm['tx_swagevents_pi2_website'].focus();
						return(false);
					}
				}





			}


			function progressMeterShow() {
					document.getElementById("progressbar1").style.display='block';		// show progressbar1 div
			}
			function progressMeterHide() {
					document.getElementById("progressbar1").style.display='none';		// hide progressbar1 div
			}


			// textarea text counter with progress meter
			function textCounter(field,counter,maxlimit) {
				// text width//
				var fieldWidth =  parseInt(field.offsetWidth);
				var charcnt = field.value.length;        

				// trim the extra text
				if (charcnt > maxlimit) { 
					field.value = field.value.substring(0, maxlimit);
				}
				else { 
					// progress bar percentage
					var percentage = parseInt(100 - (( maxlimit - charcnt) * 100)/maxlimit) ;
					document.getElementById(counter).style.width =  parseInt((fieldWidth*percentage)/100)+"px";
					document.getElementById(counter).innerHTML="Word limit: "+percentage+"%"
					// color correction on style from CCFFF -> CC0000
					setcolor(document.getElementById(counter),percentage,"background-color");
				}
			}

			function setcolor(obj,percentage,prop){
				obj.style[prop] = "rgb(80%,"+(100-percentage)+"%,"+(100-percentage)+"%)";
			}