<!--var strFieldValue = new String("");var bolValueChanged = new Boolean(false);function queryChanged(){	if(bolValueChanged==true)		if(strFieldValue.length>0){			bolValueChanged = false;			return true;		}	return false;} 	// end queryChanged()function removeCookie() {if( document.cookie.indexOf( 'SAVisitorCookie' ) == -1 ) {}else 	{	document.cookie="SAVisitorCookie=hello;path=/;  expires= Fri, 02-Jan-1970 00:00:00 GMT"	window.status = 'The Organic Directory registration cookie removed.'	}if( document.cookie.indexOf( 'cartid' ) == -1 ) {}else 	{	document.cookie="cartid=hello;path=/;  expires= Fri, 02-Jan-1970 00:00:00 GMT"	window.status = 'Cart Id cookie removed.'	}}function WM_toggle(id){	if (document.all){		if(document.all[id].style.display == 'none'){			document.all[id].style.display = '';		} else {			document.all[id].style.display = 'none';		}		return false;	} else if (document.getElementById){		if(document.getElementById(id).style.display == 'none'){			document.getElementById(id).style.display = 'block';		} else {			document.getElementById(id).style.display = 'none';		}		return false;	}}	// end of WM_togglefunction doSearch( formname, fieldname, cat ) {	var FieldsForm = document.forms[ 'Fields' ]if ( typeof FieldsForm == 'undefined' ) FieldsForm = document.forms[ 0 ]	var form = document.forms[ formname ]if ( typeof form == 'undefined' ) form = document.forms[ 0 ]var searchFor = form[ fieldname ].valueif( searchFor == '' ) return	var viewname = 'GlobalSearch'	if ( fieldname == 'library_search' )		viewname = 'LibrarySearch'	if ( fieldname == 'news_OL_search' )		viewname = 'news_OL'		if ( fieldname == 'news_FG_search' )		viewname = 'news_FG'	if ( fieldname == 'news_MR_search' )		viewname = 'news_MR'		if ( fieldname == 'news_GE_search' )		viewname = 'news_GE'	if ( fieldname == 'news_ALL_search' )		viewname = 'news_ALL'		if ( fieldname == 'PressRelSC_search' )		viewname = 'PressRelSC'		if ( fieldname == 'ImagesSearch' )		viewname = 'ImagesSearch'		if ( fieldname == 'questions_search' )		viewname = 'FAQ'		if ( fieldname == 'Store_Search' )	{		viewname = 'StoreSearch'		if ( cat == 'Books' )			viewname = 'BookSearch'		if ( cat == 'Magazines' )			viewname = 'MagazineSearch'		if ( cat == 'Packaging' )			viewname = 'PackagingSearch'	}		if ( fieldname == 'contacts_search' )		viewname = 'ContactsSearch'	if ( fieldname == 'recipes_search' )		viewname = 'RecipesSearch'var viewpath = ""// bodge to cope with theorganicdirectory.co.uk using this code...if( typeof form.SAWebDb == 'undefined' ) {		// Are we in the Directory db ?viewpath = 'http://www.soilassociation.org/' + FieldsForm.webDBname.value + '/' + viewname	// No.}else {viewpath = 'http://www.soilassociation.org/' + FieldsForm.SAWebDb.value + '/' + viewname	// Yes, we're either in the tod or in www.tod.co.uk.}	window.location = viewpath + '?SearchView&SearchOrder=1&SearchWv=TRUE&SearchFuzzy=TRUE&SearchThesaurus=TRUE&Query=' + searchFor 	// sort order of results remains the same.return false}	// end of doSearchfunction handleKey (evt) { 	if (navigator.appName == 'Netscape') {		if (evt.which == 13) { Enter();} }		else 			if (navigator.appName == 'Microsoft Internet Explorer') {				if (evt.keyCode == 13 ) { Enter(); }				else				{ }	} }	// end of handleKeyfunction Enter(){	doSearch( );}function goURL( url ){var form = document.forms[ 'Fields' ]if ( typeof form == 'undefined' ) form = document.forms[ 0 ]var path = ''if( typeof form.SAWebDb == 'undefined' ) {		// ie we're not in the Directory db.	path = 'http://www.soilassociation.org/' + form.webDBname.value}else {path = 'http://www.soilassociation.org/' + form.SAWebDb.value	// we're either in the tod or in www.tod.co.uk.}window.location = path + "/" + url}// Login	- NO LONGER USED as logins performed using Form Action.function logIn(){	var thisForm = document.forms[ 'Fields' ]	if ( typeof thisForm == 'undefined' ) thisForm = document.forms[ 0 ]	if( thisForm.username.value == '' || thisForm.username.length == 0 ) {}	else {		var tmpname = thisForm.username.value		tmpname = replaceString( tmpname, " ", "%20" )		var newLocation  = "/names.nsf?Login"// "/names.nsf?Login&UserName=" + tmpname + "&Password=" + thisForm.password.value +"&RedirectTo=" + location.pathname + "?Open&login=1";//		alert( newLocation )		self.location = newLocation	}}	// end of logIn()// Registerfunction doRegister () {	var thisForm = document.forms[ 'Fields' ]	if ( typeof thisForm == 'undefined' ) thisForm = document.forms[ 0 ]	rlOpenDependentWindow( "/namesSAS.nsf/frmSASMember?OpenForm", "SAReg")}	// end of doRegister()// GiftAidfunction doGiftAid () {	var thisForm = document.forms[ 'Fields' ]	if ( typeof thisForm == 'undefined' ) thisForm = document.forms[ 0 ]	rlOpenDependentWindow( "/Web/SA/SAWeb.nsf/giftaid?OpenForm", "GiftAid")}	// end of GiftAid()// Jobsfunction doJobs () {	var thisForm = document.forms[ 'Fields' ]	if ( typeof thisForm == 'undefined' ) thisForm = document.forms[ 0 ]	rlOpenDependentWindow( "/Web/SA/SAWeb.nsf/jobsform?OpenPage", "jobs")}	// end of doJobs()// Consumerfunction doConsumer () {	var thisForm = document.forms[ 'Fields' ]	if ( typeof thisForm == 'undefined' ) thisForm = document.forms[ 0 ]	rlOpenDependentWindow( "/namesSAS.nsf/consumer?OpenForm", "Consumer")}	// end of doConsumer()// Whycertifyfunction doWhycertify () {	var thisForm = document.forms[ 'Fields' ]	if ( typeof thisForm == 'undefined' ) thisForm = document.forms[ 0 ]	rlOpenDependentWindow( "/namesSAS.nsf/whycertify?OpenForm", "Why")}	// end of doWhycertify()// DownloadHelpfunction doDownloadHelp () {	var thisForm = document.forms[ 'Fields' ]	if ( typeof thisForm == 'undefined' ) thisForm = document.forms[ 0 ]	rlOpenDependentWindow( "/Web/SA/SAWeb.nsf/DownloadHelp?OpenForm", "Why")}	// end of doDownloadHelp()// Chocolatefunction doChocolate () {	var thisForm = document.forms[ 'Fields' ]	if ( typeof thisForm == 'undefined' ) thisForm = document.forms[ 0 ]	rlOpenDependentWindow( "/namesSAS.nsf/Chocolate?OpenForm", "Choc")}	// end of doChocolate()// Biodiversityfunction doBiodiversity () {	var thisForm = document.forms[ 'Fields' ]	if ( typeof thisForm == 'undefined' ) thisForm = document.forms[ 0 ]	rlOpenDependentWindow( "/namesSAS.nsf/biodiversity?OpenForm", "Why")}	// end of doBiodiversity()// Converterfunction doConverter () {	var thisForm = document.forms[ 'Fields' ]	if ( typeof thisForm == 'undefined' ) thisForm = document.forms[ 0 ]	rlOpenDependentWindow( "/Web/SA/SAWeb.nsf/popup_converter.html?OpenForm", "Convert")}	// end of doConverter()// Amend Profilefunction doAmendProfile () {	var thisForm = document.forms[ 'Fields' ]	if ( typeof thisForm == 'undefined' ) thisForm = document.forms[ 0 ]	rlOpenDependentWindow( "/namesSAS.nsf/($Users)/" + thisForm.usenam.value + "?EditDocument", "SAReg")}	// end of doAmendProfile()function VeriSignSiteSeal() {var url = 'https://servicecenter.verisign.com/cgi-bin/Xquery.exe?Template=authCertByIssuer&remote_host=https://digitalid.trustwise.com/globalServer/cgi-bin/haydn.exe&form_file=../fdf/authCertByIssuer.fdf&issuerSerial=b55b96b88447a0ee300363a3a6e7a211' ;// Instructions from https://digitalid.trustwise.com/globalServer/SecureSeal.htm// Obtain Issuer Digest from https://digitalid.trustwise.com/globalServer/SearchDigitalIDs.htm // 2003 replacement b55b96b88447a0ee300363a3a6e7a211 // 2002/3 b4242ecfc3d1a71a77e6d0ee219406b7// 2001/2 ec61f65d7344d8abba9afdd40b4f9d81sealWin = open( url, 'VeriSignSiteSeal', 'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,Width=750,height=450');self.name= 'MainWin'}function MM_jumpMenu(targ,selObj,restore){ //v3.0  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");  if (restore) selObj.selectedIndex=0;}function MM_openBrWindow(theURL,winName,features) { //v2.0  window.open(theURL,winName,features);}// Image termsfunction doImageTerms () {	var thisForm = document.forms[ 'Fields' ]	if ( typeof thisForm == 'undefined' ) thisForm = document.forms[ 0 ]	rlOpenDependentWindow( "/Web/SA/SAWeb.nsf/ImageTerms?OpenForm", "ImageTerms")}	// end of doImageTerms()// ********************************************************************// Risk Participation Application windows// ********************************************************************// Keep an array of all windows opened so we can refocus to themvar rlibDependentWindows = new Object;// ====================================================================// function rlOpenDependentWindow// Creates/focuses a dependent window// The variable rlibDependentWindows contains properties for all already open// RPA windows (identified by the underlying document's UNID)// You can add menubar=yes, to the list of window parameters for debugging purposes.// ====================================================================function rlOpenDependentWindow( urlToOpen, windowName){	if ( typeof( rlibDependentWindows[ windowName] ) == "undefined" || 		rlibDependentWindows[ windowName ].closed )	{     	rlibDependentWindows[ windowName] =open( urlToOpen, windowName, 			'scrollbars=yes,resizable=yes,width=600,height=400,top=50,left=100');		if ( rlibDependentWindows[ windowName].opener == null)   			rlibDependentWindows[ windowName].opener = self;	}	else	{		rlibDependentWindows[ windowName].focus();	}}// ====================================================================// function rlNotifyDependentWindowClosed// Called by RPA windows when they close - we can release the handle to it in the rlibDependentWindows array// ====================================================================function rlNotifyDependentWindowClosed( windowName){    if ( !(typeof( rlibDependentWindows[ windowName] ) == "undefined"))	    delete rlibDependentWindows[ windowName];}// ====================================================================// functions rlDependentWindowOnUnload & rlDependentWindowOnUnloadReload// Should be called by Risk Participation Application windows when they// are closed to notify the opener that they have done so.// The function first checks that window.opener is valid, // then that it implements the function rlNotifyDependentWindowClosed, // before calling that function.// ====================================================================function rlDependentWindowOnUnload(){    if ( window.opener != null)    {        if ( typeof( window.opener.rlNotifyDependentWindowClosed) != "undefined") {            window.opener.rlNotifyDependentWindowClosed( window.name);		}    }    }function rlDependentWindowOnUnloadReload(){    if ( window.opener != null)    {        if ( typeof( window.opener.rlNotifyDependentWindowClosed) != "undefined") {            window.opener.rlNotifyDependentWindowClosed( window.name);		window.opener.navigate(window.opener.document.location.href);//		window.opener.reload( true )	// refresh the view in the right-hand frame.		}    }    }function rlDependentWindowCloseGotoNewLocation( newloc ){    if ( window.opener != null)    {        if ( typeof( window.opener.rlNotifyDependentWindowClosed) != "undefined") {		window.close()            window.opener.rlNotifyDependentWindowClosed( window.name);		window.opener.location = newloc		}    }}//********************************************************************************************************// String Functions from JS Library Chap 26 example 08. (inRange Chap 28 eg 3.//********************************************************************************************************// BE WARNED - getFront & getEnd return "null" if searchStr is not found !function getFront( mainStr, searchStr ) {// getFront extracts the front part of a string prior to searchString.	foundOffset = mainStr.indexOf(searchStr)	if (foundOffset == -1) {		return null	}	return mainStr.substring(0,foundOffset) }function getEnd(mainStr,searchStr) {// getEnd extracts the back end of string after searchString	foundOffset = mainStr.indexOf(searchStr)	if (foundOffset == -1) {		return null	}	return mainStr.substring(foundOffset+searchStr.length,mainStr.length) }function insertString(mainStr,searchStr,insertStr) {// insert insertString immediately before searchString	var front = getFront(mainStr,searchStr)	var end = getEnd(mainStr,searchStr)	if (front != null && end != null) {		return front + insertStr + searchStr + end 	}	return mainStr }function deleteString(mainStr,deleteStr) {// remove deleteString from the mainStr	return replaceString(mainStr,deleteStr,"") }function replaceString(mainStr,searchStr,replaceStr) {// replace searchString in mainStr with replaceString	var tmpStr = mainStr	while ( tmpStr.indexOf( searchStr ) >= 0 ) {		var front = getFront( tmpStr,searchStr)		var end = getEnd( tmpStr,searchStr)		if (front != null && end != null) {			tmpStr = front + replaceStr + end 	}	}	return tmpStr }function inRange(inputStr, lo, hi) {// function inRange determines if inputStr is in acceptable range of hi and lo.	var num = parseInt(inputStr, 10)	if (num < lo || num > hi) {		return false	}	return true }//********************************************************************************************************// end of String Functions //********************************************************************************************************function getField( fieldName, formObj) {// Returns the field with given name from specified form, or null if the field is not found.   // Default to document.forms[0]   if ( arguments.length < 2 )      formObj = document.forms[0];      var field = formObj[ fieldName ];      // If field not found, return null, else return the field   return ( typeof field == "undefined") ? null : field;}function resolveToFieldObj( f) {// f may be either a field object or a string which is the name of a field   var field;      if ( typeof f == "string")      field = getField( f);   else      field = f;             return field;}function getFieldType( f ) {      field = resolveToFieldObj( f );      // If the type attribute is undefined then this is a multi-element field e.g. radio button/checkbox   if ( typeof field.type == "undefined")      return field[0].type;   else      return field.type;}function getFieldValue( f ) {// depending on what type the specified field is, extract and return its value.   var field = resolveToFieldObj( f );      var fieldValue;   switch ( getFieldType( field)) {   case "radio":   case "checkbox":      for ( i = 0; i < field.length; i++ ) {         if ( field[ i].checked) {            fieldValue = field[ i].value;            break;         }      }      if ( fieldValue == null)         fieldValue = "";      break;   case "select-one":   case "select-multiple":      var i = field.selectedIndex;      if ( i == -1)         fieldValue = "";      else         fieldValue = field.options[ i].text;      break;       default:      fieldValue = field.value   }    return fieldValue;}function emailCheck (emailStr) {/* The following variable tells the rest of the function whether or notto verify that the address ends in a two-letter country or well-knownTLD.  1 means check it, 0 means don't. */var checkTLD=1;/* The following is the list of known TLDs that an e-mail address must end with. */var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;/* 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("Your Email Address seems incorrect (check @ and .'s)");return false;}var user=matchArray[1];var domain=matchArray[2];/* Start by checking that only basic ASCII characters are in the strings (0-127). */for (i=0; i<user.length; i++) {if (user.charCodeAt(i)>127) {alert("Your Email Address contains invalid characters.");return false;   }}for (i=0; i<domain.length; i++) {if (domain.charCodeAt(i)>127) {alert("Your Email Address domain name contains invalid characters.");return false;   }}/* See if "user" is valid */if (user.match(userPat)==null) {/* user is not valid */alert("Your Email Address does not 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("Your Email Address Destination IP address is invalid!");return false;   }}return true;}/* Domain is symbolic name.  Check if it's valid. */ var atomPat=new RegExp("^" + atom + "$");domain = domain.toLowerCase()var domArr=domain.split(".");var len=domArr.length;for (i=0;i<len;i++) {if (domArr[i].search(atomPat)==-1) {alert("Your Email Address domain name does not seem to be valid.");return false;   }}/* domain name seems valid, but now make sure that it ends in aknown top-level domain (like com, edu, gov) or a two-letter word,representing country (uk, nl), and that there's a hostname preceding the domain or country. */if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) {alert("Your Email Address must end in a well-known domain eg .com or a two letter country code eg .uk.");return false;}/* Make sure there's a host name preceding the domain. */if (len<2) {alert("Your Email Address must end in a well-known domain eg .com or a two letter country code eg .uk.");return false;}/* If we've gotten this far, everything's valid! */return true;}	// end of function emailCheck // Visa / Switch / MasterCard / Electron / Solo / Deltavar Cards = new makeArray(8);Cards[0] = new CardType("Visa", "4", "13,16");var Swicth = Cards[0];Cards[1] = new CardType("Switch", "91", "16");		// we need to find out the leading digits of these "9n" cards !!!var Visa = Cards[1];Cards[2] = new CardType("MasterCard", "51,52,53,54,55", "16");var MasterCard = Cards[2];Cards[3] = new CardType("Electron", "92", "16");var Solo = Cards[3];Cards[4] = new CardType("Solo", "93", "16");var Delta = Cards[4];Cards[5] = new CardType("Delta", "94", "16");var enRouteCard = Cards[5];Cards[6] = new CardType("JCBCard", "3088,3096,3112,3158,3337,3528", "16");		// filler from original code, so can be ignored.var JCBCard = Cards[6];var LuhnCheckSum = Cards[7] = new CardType();/*************************************************************************\CheckCardNumber(form)	!!!! Careful with the case of these functions !!!!Original:  Simon Tneoh (tneohcb@pc.jaring.my) \*************************************************************************/function CheckCardNumber(form) {if (form.CardNumber.value.length == 0) {alert("Please enter a Card Number.")form.CardNumber.focus()return;}var tmpyear = getFieldValue( 'ExpiryDate2' )if ( tmpyear.length == 0) {alert("Please enter the Expiration Year.")form.ExpiryDate2.focus()return;}if ( tmpyear > 96) {tmpyear = "19" + tmpyear}else { 	if ( tmpyear < 21) tmpyear = "20" + tmpyearelse {alert("The Expiration Year is not valid.")return}}tmpmonth = getFieldValue( 'ExpiryDate1' );// The following line doesn't work in IE3, you need to change it// to something like "(new CardType())...".// if (!CardType().isExpiryDate(tmpyear, tmpmonth)) {if ( !(new CardType()).isExpiryDate(tmpyear, tmpmonth ) ) {alert("This card has already expired.");return;}return true// var card = getFieldValue( 'CardType' )// var retval = eval(card + '.checkCardNumber("' + form.CardNumber.value + '", ' + tmpyear + ', ' + tmpmonth + ');' );// cardname = "";// if ( ! retval ) {//	return true// }// else {// The cardnumber has the valid luhn checksum, but we want to know which// cardtype it belongs to.// for (var n = 0; n < Cards.size; n++) {// if (Cards[n].checkCardNumber(form.CardNumber.value, tmpyear, tmpmonth)) {// cardname = Cards[n].getCardType(); // break;// }// }// if (cardname.length > 0) // alert("This looks like a " + cardname + " number, not a " + card + " number.")// else// alert("This card number is not valid.");// return false// }}	// end of CheckCardNumber function/*************************************************************************\Object CardType([String cardtype, String rules, String len, int year, int month])cardtype    : type of card, eg: MasterCard, Visa, etc.rules       : rules of the cardnumber, eg: "4", "6011", "34,37".len         : valid length of cardnumber, eg: "16,19", "13,16".year        : year of expiry date.month       : month of expiry date.eg:var VisaCard = new CardType("Visa", "4", "16");var AmExCard = new CardType("AmEx", "34,37", "15");\*************************************************************************/function CardType() {var n;var argv = CardType.arguments;var argc = CardType.arguments.length;this.objname = "object CardType";var tmpcardtype = (argc > 0) ? argv[0] : "CardObject";var tmprules = (argc > 1) ? argv[1] : "0,1,2,3,4,5,6,7,8,9";var tmplen = (argc > 2) ? argv[2] : "13,14,15,16,19";this.setCardNumber = setCardNumber;  	// set CardNumber method.this.setCardType = setCardType;  		// setCardType method.this.setLen = setLen;  			// setLen method.this.setRules = setRules;  			// setRules method.this.setExpiryDate = setExpiryDate;  		// setExpiryDate method.this.setCardType(tmpcardtype);this.setLen(tmplen);this.setRules(tmprules);if (argc > 4)this.setExpiryDate(argv[3], argv[4]);this.checkCardNumber = checkCardNumber;  	// checkCardNumber method.this.getExpiryDate = getExpiryDate;  			// getExpiryDate method.this.getCardType = getCardType;  			// getCardType method.this.isCardNumber = isCardNumber;  		// isCardNumber method.this.isExpiryDate = isExpiryDate;  			// isExpiryDate method.this.luhnCheck = luhnCheck;				// luhnCheck method.return this;}/*************************************************************************\boolean checkCardNumber([String cardnumber, int year, int month])	!!!! Careful with the case of these functions !!!!return true if cardnumber pass the luhncheck and the expiry date isvalid, else return false.\*************************************************************************/function checkCardNumber() {var argv = checkCardNumber.arguments;var argc = checkCardNumber.arguments.length;var cardnumber = (argc > 0) ? argv[0] : this.cardnumber;var year = (argc > 1) ? argv[1] : this.year;var month = (argc > 2) ? argv[2] : this.month;this.setCardNumber(cardnumber);this.setExpiryDate(year, month);if (!this.isCardNumber())return false;if (!this.isExpiryDate())return false;return true;}/*************************************************************************\String getCardType()return the cardtype.\*************************************************************************/function getCardType() {return this.cardtype;}/*************************************************************************\String getExpiryDate()return the expiry date.\*************************************************************************/function getExpiryDate() {return this.month + "/" + this.year;}/*************************************************************************\boolean isCardNumber([String cardnumber])return true if cardnumber pass the luhncheck and the rules, else returnfalse.\*************************************************************************/function isCardNumber() {var argv = isCardNumber.arguments;var argc = isCardNumber.arguments.length;var cardnumber = (argc > 0) ? argv[0] : this.cardnumber;if (!this.luhnCheck())return false;for (var n = 0; n < this.len.size; n++)if (cardnumber.toString().length == this.len[n]) {for (var m = 0; m < this.rules.size; m++) {var headdigit = cardnumber.substring(0, this.rules[m].toString().length);if (headdigit == this.rules[m])return true;}return false;}return false;}/*************************************************************************\boolean isExpiryDate([int year, int month])return true if the date is a valid expiry date,else return false.\*************************************************************************/function isExpiryDate() {var argv = isExpiryDate.arguments;var argc = isExpiryDate.arguments.length;year = argc > 0 ? argv[0] : this.year;month = argc > 1 ? argv[1] : this.month;if (!isNum(year+""))return false;if (!isNum(month+""))return false;today = new Date();expiry = new Date(year, month);if (today.getTime() > expiry.getTime())return false;elsereturn true;}/*************************************************************************\boolean isNum(String argvalue)return true if argvalue contains only numeric characters,else return false.\*************************************************************************/function isNum(argvalue) {argvalue = argvalue.toString();if (argvalue.length == 0)return false;for (var n = 0; n < argvalue.length; n++)if (argvalue.substring(n, n+1) < "0" || argvalue.substring(n, n+1) > "9")return false;return true;}/*************************************************************************\boolean luhnCheck([String CardNumber])return true if CardNumber passes the luhn check else return false.Reference: http://www.ling.nwu.edu/~sburke/pub/luhn_lib.pl\*************************************************************************/function luhnCheck() {var argv = luhnCheck.arguments;var argc = luhnCheck.arguments.length;var CardNumber = argc > 0 ? argv[0] : this.cardnumber;if (! isNum(CardNumber)) {return false;  }var no_digit = CardNumber.length;var oddoeven = no_digit & 1;var sum = 0;for (var count = 0; count < no_digit; count++) {var digit = parseInt(CardNumber.charAt(count));if (!((count & 1) ^ oddoeven)) {digit *= 2;if (digit > 9)digit -= 9;}sum += digit;}if (sum % 10 == 0)return true;elsereturn false;}/*************************************************************************\ArrayObject makeArray(int size)return the array object in the size specified.\*************************************************************************/function makeArray(size) {this.size = size;return this;}/*************************************************************************\CardType setCardNumber(cardnumber)return the CardType object.\*************************************************************************/function setCardNumber(cardnumber) {this.cardnumber = cardnumber;return this;}/*************************************************************************\CardType setCardType(cardtype)return the CardType object.\*************************************************************************/function setCardType(cardtype) {this.cardtype = cardtype;return this;}/*************************************************************************\CardType setExpiryDate(year, month)return the CardType object.\*************************************************************************/function setExpiryDate(year, month) {this.year = year;this.month = month;return this;}/*************************************************************************\CardType setLen(len)return the CardType object.\*************************************************************************/function setLen(len) {// Create the len array.if (len.length == 0 || len == null)len = "13,14,15,16,19";var tmplen = len;n = 1;while (tmplen.indexOf(",") != -1) {tmplen = tmplen.substring(tmplen.indexOf(",") + 1, tmplen.length);n++;}this.len = new makeArray(n);n = 0;while (len.indexOf(",") != -1) {var tmpstr = len.substring(0, len.indexOf(","));this.len[n] = tmpstr;len = len.substring(len.indexOf(",") + 1, len.length);n++;}this.len[n] = len;return this;}/*************************************************************************\CardType setRules()return the CardType object.\*************************************************************************/function setRules(rules) {// Create the rules array.if (rules.length == 0 || rules == null)rules = "0,1,2,3,4,5,6,7,8,9";  var tmprules = rules;n = 1;while (tmprules.indexOf(",") != -1) {tmprules = tmprules.substring(tmprules.indexOf(",") + 1, tmprules.length);n++;}this.rules = new makeArray(n);n = 0;while (rules.indexOf(",") != -1) {var tmpstr = rules.substring(0, rules.indexOf(","));this.rules[n] = tmpstr;rules = rules.substring(rules.indexOf(",") + 1, rules.length);n++;}this.rules[n] = rules;return this;}//  End -->