<!--

function trim(value)
{
	return ltrim(rtrim(value));
}

function ltrim(value)
{
	return value.replace(/^\s*/, "");
}

function rtrim(value)
{
	return value.replace(/\s*$/, "");
}
/*
function trim(value)
{
	return ltrim(rtrim(value));
}

function ltrim(value)
{
	return value.match(/^\s*(.*?)$/)[1];
}

function rtrim(value)
{
	return value.match(/^(.*?)\s*$/)[1];
}
*/

function isEmpty(value)
{
	return trim(value) == "";
}

function isPhone(pElement, pAllowBlanks)
{
	dataValue = trim(pElement.value);
	if (pAllowBlanks && dataValue=="") { return true; }

	var phone_test1 = /^\s*(\d{3})\s*-?\s*(\d{3})\s*-?\s*(\d{4})\s*$/;
	var phone_test2 = /^\s*\((\d{3})\)\s*-?\s*(\d{3})\s*-?\s*(\d{4})\s*$/;

	if ( matchValue = dataValue.match (phone_test1) )
	{
		pElement.value = "(" + matchValue[1] + ") " + matchValue[2] + "-" + matchValue[3];
		return true;  
	}
	else if ( matchValue = dataValue.match (phone_test2) )
	{
		pElement.value = "(" + matchValue[1] + ") " + matchValue[2] + "-" + matchValue[3];
		return true;	
	}
	return false;
}

function isEmailAddress(pElement, pAllowBlanks)
/*****
 Author: Stephen George <SGeorge [AT] MSandYou [DOT] org> - Technically, that's not a valid email address. Appreciate the irony...
 Version: v1.2c, 9/29/2007
 vx.xa: single quotes allowed (CONST_allow_single_quotes == true)
 vx.xb: single quotes NOT allowed (CONST_allow_single_quotes == false)
 Credit: This script is based on a regular expression-based e-mail address validator developed by Steve Brockman.
 References:
 The criteria for this email address checker is based on data from the following documents
 http://tools.ietf.org/html/rfc2822
 http://tools.ietf.org/html/rfc3696#section-3
 http://www.rfc-editor.org/cgi-bin/errataSearch.pl?rfc=3696
 Notes:
 This checker is more restrictive than the RFC 2822 allows. For instance, this checker only allows one single-quote,
 prohibits many special characters: ! # $ % & * + = ? ^ ` { | } ~
 Certain valid TLDs are prohibited as well.
 Procedure:
 1. Test for blank addresses
 2. Check for general email address validity
 3. Check for single quotes in the local-part of the address (i.e., LOC'AL-PA'RT@domain.com)
 4. Check for full-stops (.) in the beginning/ending of local-part of the address (i.e., .LOCAL-PART.@domain.com)
 5. Check that the TLD is valid
 Examples:
 Addresses that will validate:
 Pat.O'Donnell@domain.com
 Pat.O'Donnell@domain.ru
 Pat.O.Donnell@domain.ru
 Pat.O.Donnell@domain.com
 PatODonnell@domain.ru
 Pat.O.Donnell@p.com
 P@p.com
 PatODonnell@domain.CoM
 PatODonnell@domain.COM
 PatODonnell@domain.domain.ru
 PatODonnell@domain.domain.domain.ru
 Addresses that will NOT validate:
 bob@somewhere.nsset
 'Pat.ODonnell@domain.com
 Pat.ODonnell'@domain.com
 Pat.O''Donnell@domain.com
 .PatODonnell@domain.com
 PatODonnell.@domain.com
 PatODonnell@domain.blah
 PatODonnell@domain.b
 PatODonnell@domain.
 @domain.com
 Pat@.com
 Pat@..com
 Pat@com
 '@domain.com
 .@domain.com
 .pat@domain.com
 pat.@domain.com
 .pat.@domain.com
 pat.@domain..com
 pat.@.domain.com
 pat.@domain..domain.com
 P@p.com.
*****/
{
	var CONST_allow_single_quotes = false; // changeable behavior

	dataValue = trim(pElement.value);
	if (pAllowBlanks && dataValue=="") { return true; }
	
	//Pattern for a valid email address
	var email_pattern = /^([A-Za-z0-9\_\-\.\']+)@(([A-Za-z0-9\-])+\.)+(\w+)$/;
	
	//Pattern for allowing up to to one single-quote in the local-part, with but not as the first or last character, i.e...:
	//Pat.O'Donnell@domain.com .... PASS
	//'Pat.ODonnell@domain.com .... FAIL
	//Pat.ODonnell'@domain.com .... FAIL
	//Pat.O''Donnell@domain.com .... FAIL
	
	//This pattern should NOT be matched. If it matches, the email address is rejected
	//pattern omitted because it did not work on Netscape 4.8: var local_part_fail_pattern1 = /(^')|('$)|('.*')/;
	var local_part_fail_pattern1 = /^('.*|.*'.*'.*|.*')$/;
	
	//Pattern for allowing full-stops (.) in the local-part, with but not as the first or last character, and not two consecutive full-stops i.e...:
	//Pat.O.Donnell@domain.com .... PASS
	//Pat..ODonnell@domain.com .... FAIL
	//.PatODonnell@domain.com .... FAIL
	//PatODonnell.@domain.com .... FAIL


	//This pattern should NOT be matched. If it matches, the email address is rejected
	//pattern omitted because it did not work on Netscape 4.8: var local_part_fail_pattern2 = /(^\.)|(\.\.)|(\.$)/;
	var local_part_fail_pattern2 = /^(\..*|.*\.\..*|.*\.)$/;

	if (pAllowBlanks && dataValue=="")
	{
		return true;
	}

	if (test_value = dataValue.match(email_pattern))
	{
		var local_part = test_value[1];
		var tld_part = test_value[4];
		
		//Single Quotes
		if (CONST_allow_single_quotes)
		{
			if (test_value = local_part.match(local_part_fail_pattern1))
			{
				return false;
			}
		}
		else if (dataValue.indexOf("'") != -1)
		{
			return false;
		}
		
		//Full Stops (.)
		if (test_value = local_part.match(local_part_fail_pattern2))
		{
			return false;
		}
		
		//TLD
		if (isTLD(tld_part)) { return true; }
	}
	
	return false;
}

function isTLD(pValue)
// Author: Stephen George <SGeorge [AT] MSandYou [DOT] org>
// Version: v1.2, 11/27/2006
{
	// A dot-seperated list of all tlds, based on data from
	// http://data.iana.org/TLD/tlds-alpha-by-domain.txt
	// # Version 2006112501, Last Updated Sun Nov 26 09:07:01 2006 UTC
	// Note: the following TLDs have been manually removed for the list below: .arpa,.cm,.co,.om
	var TLDs = ".ac.ad.ae.aero.af.ag.ai.al.am.an.ao.aq.ar.as.at.au.aw.ax.az.ba.bb.bd.be.bf.bg.bh.bi.biz.bj.bm.bn.bo.br.bs.bt.bv.bw.by.bz.ca.cat.cc.cd.cf.cg.ch.ci.ck.cl.cn.com.coop.cr.cu.cv.cx.cy.cz.de.dj.dk.dm.do.dz.ec.edu.ee.eg.er.es.et.eu.fi.fj.fk.fm.fo.fr.ga.gb.gd.ge.gf.gg.gh.gi.gl.gm.gn.gov.gp.gq.gr.gs.gt.gu.gw.gy.hk.hm.hn.hr.ht.hu.id.ie.il.im.in.info.int.io.iq.ir.is.it.je.jm.jo.jobs.jp.ke.kg.kh.ki.km.kn.kr.kw.ky.kz.la.lb.lc.li.lk.lr.ls.lt.lu.lv.ly.ma.mc.md.mg.mh.mil.mk.ml.mm.mn.mo.mobi.mp.mq.mr.ms.mt.mu.museum.mv.mw.mx.my.mz.na.name.nc.ne.net.nf.ng.ni.nl.no.np.nr.nu.nz.org.pa.pe.pf.pg.ph.pk.pl.pm.pn.pr.pro.ps.pt.pw.py.qa.re.ro.ru.rw.sa.sb.sc.sd.se.sg.sh.si.sj.sk.sl.sm.sn.so.sr.st.su.sv.sy.sz.tc.td.tf.tg.th.tj.tk.tl.tm.tn.to.tp.tr.travel.tt.tv.tw.tz.ua.ug.uk.um.us.uy.uz.va.vc.ve.vg.vi.vn.vu.wf.ws.ye.yt.yu.za.zm.zw.";
	
	
	var search_string = "." + pValue.toLowerCase() + ".";
	return pValue.length != 0 && TLDs.indexOf(search_string) != -1;
}

//-->