function isPostcode(code){
	var result;
	result = code.match(/^[a-zA-Z][0-9][a-zA-Z][ ]?[0-9][a-zA-Z][0-9]$/);
	if ( result )
		return true;
	else{
		result = code.match(/(^\d{5}$)|(^\d{5}-\d{4}$)/);
		if ( result )
			return true;
	}
	return false;
}
function isDate(code){
	var result;
	result = code.match(/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/);
	if ( result )
		return true;
	return false; 
}
function isPhone(code){
	var result;
	result = code.match(/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/);
	if ( result )
		return true;
	return false; 
}
function isExtension(code){
	var result;
	result = code.match(/^[0-9]+$/);
	if ( result )
		return true;
	return false; 
}
function isNumber(code){
	var result;
	result = code.match(/^[0-9]+$/);
	if ( result )
		return true;
	return false; 
}
function isPhoneWithExtension(code){
	var result;
	result = code.match(/^[0-9]{3}-[0-9]{3}-[0-9]{4} (x[0-9])?$/);
	if ( result )
		return true;
	return false;
}
function isEmail(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 +")*$")

var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
	alert("E-mail address seems incorrect (check @ and .'s)")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

if (user.match(userPat)==null) {
    alert("The username doesn't seem to be valid.")
    return false
}

var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("Destination IP address is invalid!")
		return false
	    }
    }
    return true
}

var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("The domain name doesn't seem to be valid.")
    return false
}

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) {
   alert("The address must end in a three-letter domain, or two letter country.")
   return false
}

if (len<2) {
   var errStr="This address is missing a hostname!"
   alert(errStr)
   return false
}

return true;
}
function urlencode(instr){
	var rstr = instr;
	rstr = rstr.replace("%", "%25");
	rstr = rstr.replace("!", "%21");
	rstr = rstr.replace("*", "%2A");
	rstr = rstr.replace("'", "%27");
	rstr = rstr.replace("(", "%28");
	rstr = rstr.replace(")", "%29");
	rstr = rstr.replace(";", "%3B");
	rstr = rstr.replace(":", "%3A");
	rstr = rstr.replace("@", "%40");
	rstr = rstr.replace("&", "%26");
	rstr = rstr.replace("=", "%3D");
	rstr = rstr.replace("+", "%2B");
	rstr = rstr.replace("$", "%24");
	rstr = rstr.replace(",", "%2C");
	rstr = rstr.replace("/", "%2F");
	rstr = rstr.replace("?", "%3F");
	rstr = rstr.replace("#", "%23");
	rstr = rstr.replace("[", "%5B");
	rstr = rstr.replace("]", "%5D");
	return rstr;
}

