    var NS = false;
		var IE = false;
		if(window.navigator.appName.toLowerCase().indexOf("netscape") > -1) { NS = true; }
		if (window.navigator.appName.toLowerCase().indexOf("microsoft internet explorer") > -1){ IE = true; }
		
    var ValidChar = /[^0-9a-zA-Z\-.\ \!\@\#\$\%\^\&\*\(\)\{\[\}\]\:\;\"\'\,\<\>\?\\/\|\\]/gi;
		var InValidExp = /[$\\@\\\#%\^\&\*\[\]\(\)\+\_\{\}\~\=\|\?\;\:\`\<\>\!\,\.\^\/\d]/;
		var NumericOnly = /[$\\@\\\#%\^\&\*\(\)\[\]\+\_\{\}\`\~\=\|\?\;\<\>\!\,\.\-\/\a-z\A-Z]/;
		
		
    //FUNCTION INSERTED ON 3/10/2008 TO COUNT WORDS
    function cnt(w){
      //var y=w.value;
      var r = 0;
      a=w.replace(/\s/g,' ');
      a=a.split(' ');
      for (z=0; z<a.length; z++) {if (a[z].length > 0) r++;}
      //cnt=r;
      return r;
    }
       
    function CheckText(strText){
			strText.value = strText.value.replace(ValidChar,'');
		}
		//FUNCTION ALLOWING THE COUNTRY CODE TO BE ADDED TO THE TELEPHONE INPUT BOX
    function fcnChangeCode(selVal) {
    	var selVal1 = HtmlElement("dlCountryCode").options[HtmlElement("dlCountryCode").selectedIndex].value;
      if (selVal1.length > 0) {
      	var telVal = HtmlElement("txtPhone").value;
        HtmlElement("txtPhone").value = "(+"+selVal1+") ";
      }
    }
    function fcnCountryCode() {
    	var labCountry = HtmlElement("dlJCountry").options[HtmlElement("dlJCountry").selectedIndex].label;
      var answer = '';
      var telVal;
      for (var i = 0; i <HtmlElement("dlCountryCode").options.length; i++) {
				if (HtmlElement("dlCountryCode").options[i].label == labCountry) {
					HtmlElement("dlCountryCode").options[i].selected = true;
          answer = HtmlElement("dlCountryCode").options[i].value
      		telVal = HtmlElement("txtPhone").value;
        	HtmlElement("txtPhone").value = "(+"+answer+") ";
        }
      }
    }
		//Code for Counting TextArea Characters
		function TxtField(field, count, max) {
  		if (field.value.length > max)
  			field.value = field.value.substring(0, max);
  		else 
  			count.value = max - field.value.length;
  	}
		
		function CheckField(FieldVal) {
  		var ValField = FieldVal.value;
  		var FieldLen = ValField.length;
  		var lchar = FieldVal.value.charAt((FieldLen) - 1);
  		if(lchar.search(InValidExp) != -1) {
  			var checked = FieldVal.value.substring(0, (FieldLen) - 1);
  			FieldVal.value = checked;
  		}
		}

		function CheckNumeric(FieldVal) {
  		var ValField = FieldVal.value;
  		var FieldLen = ValField.length;
  		var lchar = FieldVal.value.charAt((FieldLen) - 1);
  		if(lchar.search(NumericOnly) != -1) {
  			var checked = FieldVal.value.substring(0, (FieldLen) - 1);
  			FieldVal.value = checked;
  		}
		}

		function ValidateMe() {
			error = "<b>Missing data:</b><br />";
      
      //PARTICIPANTS FIELDS
      if (HtmlElement("inpFirstName").value == 0) {
      	error += "&nbsp;&bull;&nbsp;PARTICIPANT/2. First name<br />"; 
      }   
      if (HtmlElement("inpLastName").value == 0) {
      	error += "&nbsp;&bull;&nbsp;PARTICIPANT/3. Last name<br />"; 
			}
      if (HtmlElement("cmbCountry").options[HtmlElement("cmbCountry").selectedIndex].value == 0)
			{ error += "&nbsp;&bull;&nbsp;PARTICIPANT/4. Country<br />"; }
      
      if (HtmlElement("inpTown").value == 0) {
      	error += "&nbsp;&bull;&nbsp;PARTICIPANT/5. Town<br />"; 
      }
      if (HtmlElement("inpEmail").value == 0) {
      	error += "&nbsp;&bull;&nbsp;PARTICIPANT/7. Main e-mail<br />"; 
      }
     

      //GUARDIAN FIELDS
      if (HtmlElement("inpNameGuard").value == 0) {
      	error += "&nbsp;&bull;&nbsp;GUARDIAN/9. First-last name<br />"; 
      }
      if (HtmlElement("inpEmailGuard").value == 0) {
      	error += "&nbsp;&bull;&nbsp;GUARDIAN/10. Main e-mail<br />"; 
      }
      
      //ADAPT FIELDS
      if (document.getElementById("radCategory4").checked) {
        if (HtmlElement("txtTitle").value == 0) {
        	error += "&nbsp;&bull;&nbsp;Adapt with local knowledge/12. Title<br />"; 
        }
        if (HtmlElement("txtIntro").value == 0) {
        	error += "&nbsp;&bull;&nbsp;Adapt with local knowledge/13. Introduction<br />"; 
        }
        if (HtmlElement("txtUsed").value == 0) {
        	error += "&nbsp;&bull;&nbsp;Adapt with local knowledge/14. Where...<br />"; 
        }
        if (HtmlElement("txtWho").value == 0) {
        	error += "&nbsp;&bull;&nbsp;Adapt with local knowledge/15. Who...<br />"; 
        }
        if (HtmlElement("txtDesign").value == 0) {
        	error += "&nbsp;&bull;&nbsp;Adapt with local knowledge/16. Design...<br />"; 
        }
        if (HtmlElement("txtMaintenance").value == 0) {
        	error += "&nbsp;&bull;&nbsp;Adapt with local knowledge/17. Use...<br />"; 
        }
        if (HtmlElement("txtHow").value == 0) {
        	error += "&nbsp;&bull;&nbsp;Adapt with local knowledge/18. How long...<br />"; 
        }        
        if (HtmlElement("txtWhere").value == 0) {
        	error += "&nbsp;&bull;&nbsp;Adapt with local knowledge/19. Where can't...<br />"; 
        }        
        if (HtmlElement("txtBenefits").value == 0) {
        	error += "&nbsp;&bull;&nbsp;Adapt with local knowledge/20. ..benefits<br />"; 
        }        
        if (HtmlElement("txtReferences").value == 0) {
        	error += "&nbsp;&bull;&nbsp;Adapt with local knowledge/21. References...<br />"; 
        }         
        if (HtmlElement("txtCredits").value == 0) {
        	error += "&nbsp;&bull;&nbsp;Adapt with local knowledge/22. Credits...<br />"; 
        }         
        
        
        
        
      }

	  
      //VISA FIELDS
      /*if (document.getElementById("radVisa1").checked) {
        
        if (HtmlElement("txtVNAtionality").value == 0) {
        	error += "&nbsp;&bull;&nbsp;VISA/Nationality<br />"; 
        }
        if (HtmlElement("txtVDOB").value == 0) {
        	error += "&nbsp;&bull;&nbsp;VISA/Date of birth<br />"; 
        }
        if (HtmlElement("txtVPasspno").value == 0) {
        	error += "&nbsp;&bull;&nbsp;VISA/Passport No.<br />"; 
        }
        if (HtmlElement("txtVDOI").value == 0) {
        	error += "&nbsp;&bull;&nbsp;VISA/Date of issue<br />"; 
        }
        if (HtmlElement("txtVPOI").value == 0) {
        	error += "&nbsp;&bull;&nbsp;VISA/Place of issue<br />"; 
        }
        if (HtmlElement("txtVExpiration").value == 0) {
        	error += "&nbsp;&bull;&nbsp;VISA/Expiration date<br />"; 
        }
        if (HtmlElement("txtVAddress").value == 0) {
        	error += "&nbsp;&bull;&nbsp;VISA/Address<br />"; 
        }
        if (HtmlElement("txtVPostcode").value == 0) {
        	error += "&nbsp;&bull;&nbsp;VISA/Postal code<br />"; 
        }
        if (HtmlElement("txtVCity").value == 0) {
        	error += "&nbsp;&bull;&nbsp;VISA/City<br />"; 
        }
        if (HtmlElement("dlVCountry").options[HtmlElement("dlVCountry").selectedIndex].value == 0)
  			{ error += "&nbsp;&bull;&nbsp;VISA/Country<br />"; }
        
        if (HtmlElement("txtVArrivDate").value == 0) {
        	error += "&nbsp;&bull;&nbsp;VISA/Arrival date<br />"; 
        }
        if (HtmlElement("txtVDepartDate").value == 0) {
        	error += "&nbsp;&bull;&nbsp;VISA/Depart. date<br />"; 
        }
      }*/

      
			
			if (error == "<b>Missing data:</b><br />") {
				return true;
			} else {
				ErrorMsg(true);
				HtmlElement("lblMessage").style.display = 'none';
				HtmlElement("IsError").style.display = '';
				HtmlElement("IsError").innerHTML = error;
        alert("Missing mandatory information! See list at the page top.");
				HtmlElement("txtError").focus();
				return false;
			}
		}
		// ----------- End FUNCTION VALIDATE ME -----------
		
		function HtmlElement(strName){
			if(IE) return document.all(strName);
			if(NS) return document.getElementById(strName);
			return null;
		}
		
		var Changes = 0;
	  function rChanges()
		{
			Changes++;
		}
		
		function ErrorMsg(TAction){
		if(TAction == true){
				HtmlElement("ErrorMsg").style.display = '';
				}
			else {
				HtmlElement("ErrorMsg").style.display = 'none';
				}
		}
		
		function ShowSave(TAction){
		if(TAction == true){
			ErrorMsg(true);
			HtmlElement("IsError").style.display = 'none';
			}	
		}
		
		function Logic() {
			if (ValidateMe() == true) {
				return true;
			} else {
				return false;
			}
		}
    
/* ********************************************************/    
function emailCheck (emailStr,what) {
  /* The following pattern is used to check if the entered e-mail address
     fits the user@domain format.  It also is used to separate the username
     from the domain. */
  var emailPat=/^(.+)@(.+)$/
  /* The following string represents the pattern for matching all special
     characters.  We don't want to allow special characters in the address. 
     These characters include ( ) < > @ , ; : \ " . [ ]    */
  var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
  /* The following string represents the range of characters allowed in a 
     username or domainname.  It really states which chars aren't allowed. */
  var validChars="\[^\\s" + specialChars + "\]"
  /* The following pattern applies if the "user" is a quoted string (in
     which case, there are no rules about which characters are allowed
     and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
     is a legal e-mail address. */
  var quotedUser="(\"[^\"]*\")"
  /* The following pattern applies for domains that are IP addresses,
     rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
     e-mail address. NOTE: The square brackets are required. */
  var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
  /* The following string represents an atom (basically a series of
     non-special characters.) */
  var atom=validChars + '+'
  /* The following string represents one word in the typical username.
     For example, in john.doe@somewhere.com, john and doe are words.
     Basically, a word is either an atom or quoted string. */
  var word="(" + atom + "|" + quotedUser + ")"
  // The following pattern describes the structure of the user
  var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
  /* The following pattern describes the structure of a normal symbolic
     domain, as opposed to ipDomainPat, shown above. */
  var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
  /* Finally, let's start trying to figure out if the supplied address is
     valid. */
  
  /* Begin with the coarse pattern to simply break up user@domain into
     different pieces that are easy to analyze. */
  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("Email address, "+what+", seems incorrect (check @ and .'s)")
  	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("The username, "+what+", doesn't seem to be valid.")
      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("Destination IP address, "+what+", is invalid!")
				return false
	    }
    }
    return true
  }
// Domain is symbolic name
  var domainArray=domain.match(domainPat)
  if (domainArray==null) {
  	alert("The domain name, "+what+", doesn't seem to be valid.")
      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>3) {
     // the address must end in a two letter or three letter word.
     alert("The address, "+what+", must end in a three-letter domain, or two letter country.")
     return false
  }
// Make sure there's a host name preceding the domain.
  if (len<2) {
     var errStr="This address, "+what+", is missing a hostname!"
     alert(errStr)
     return false
  }
// If we've gotten this far, everything's valid!
	return true;
}
