// Test if a date is valid in a field identified by "field_id".
// Date can be database Y-M-D format or Canadian/UK D-M-Y format or blank.
// If NOT a valid date, the field background is changed to red and the
//		focus is pulled back to the field.  When valid or empty the field
//		background is set to white.
// Use it like this:
//		<INPUT id='whatever' ... onBlur='isValidDate(this.id)'>
//		"this.id" will automatically work, no need to use actual field ID.
function isValidDate(field_id) {
	var dateString = document.getElementById(field_id).value;
	document.getElementById(field_id).style.background='#dfdfdf';
	document.getElementById(field_id).style.color='#000';
	if(dateString == '') {
		document.getElementById(field_id).value = "YYYY-MM-DD";
		document.getElementById(field_id).style.color='#999';
		return;
		}
	var datePieces = explode('-', dateString, false);
	var y = (datePieces[0]>31) ? datePieces[0] : datePieces[2];		// Y-M-D or D-M-Y formatting
	var m = datePieces[1];
	var d = (datePieces[0]>31) ? datePieces[2] : datePieces[0];
	var is_okay = (m>0&&m<13&&y>0&&y>1970&&y<2100&&d>0&&d<=(new Date(y,m,0)).getDate());
	if(!is_okay) {
		alert(dateString+' is not a valid date. You must enter a date in the form YYYY-MM-DD, click the calendar icon, or clear the box. You will not be able to navigate away from this field until you do one of these.');
		document.getElementById(field_id).focus();
		document.getElementById(field_id).style.background='red';
		}
	return;
	}
function explode(delimiter,string,limit) {
	var emptyArray={0:''};
	if(arguments.length<2||typeof arguments[0]=='undefined'||typeof arguments[1]=='undefined') {
		return null;
		}
	if(delimiter===''||delimiter===false||delimiter===null) {
		return false;
		}
	if(typeof delimiter=='function'||typeof delimiter=='object'||typeof string=='function'||typeof string=='object') {
		return emptyArray;
		}
	if(delimiter===true) {
		delimiter='1';
		}
	if(!limit) {
		return string.toString().split(delimiter.toString());
		}
	else {
		var splitted=string.toString().split(delimiter.toString());
		var partA=splitted.splice(0,limit-1);
		var partB=splitted.join(delimiter.toString());
		partA.push(partB);
		return partA;
		}
	}
function isNumberString (InString)  {
	if(InString.length==0) return (false);
	var RefString="1234567890";
	for (Count=0; Count < InString.length; Count++)  {
		TempChar= InString.substring (Count, Count+1);
		if (RefString.indexOf (TempChar, 0)==-1)
			return (false);
		}
	return (true);
	}
function sprintf ( ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Ash Searle (http://hexmen.com/blog/)
    // + namespaced by: Michael White (http://getsprink.com)
    // +    tweaked by: Jack
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Paulo Ricardo F. Santos
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: sprintf("%01.2f", 123.1);
    // *     returns 1: 123.10
    // *     example 2: sprintf("[%10s]", 'monkey');
    // *     returns 2: '[    monkey]'
    // *     example 3: sprintf("[%'#10s]", 'monkey');
    // *     returns 3: '[####monkey]'

    var regex = /%%|%(\d+\$)?([-+\'#0 ]*)(\*\d+\$|\*|\d+)?(\.(\*\d+\$|\*|\d+))?([scboxXuidfegEG])/g;
    var a = arguments, i = 0, format = a[i++];

    // pad()
    var pad = function (str, len, chr, leftJustify) {
        if (!chr) {chr = ' ';}
        var padding = (str.length >= len) ? '' : Array(1 + len - str.length >>> 0).join(chr);
        return leftJustify ? str + padding : padding + str;
    };

    // justify()
    var justify = function (value, prefix, leftJustify, minWidth, zeroPad, customPadChar) {
        var diff = minWidth - value.length;
        if (diff > 0) {
            if (leftJustify || !zeroPad) {
                value = pad(value, minWidth, customPadChar, leftJustify);
            } else {
                value = value.slice(0, prefix.length) + pad('', diff, '0', true) + value.slice(prefix.length);
            }
        }
        return value;
    };

    // formatBaseX()
    var formatBaseX = function (value, base, prefix, leftJustify, minWidth, precision, zeroPad) {
        // Note: casts negative numbers to positive ones
        var number = value >>> 0;
        prefix = prefix && number && {'2': '0b', '8': '0', '16': '0x'}[base] || '';
        value = prefix + pad(number.toString(base), precision || 0, '0', false);
        return justify(value, prefix, leftJustify, minWidth, zeroPad);
    };

    // formatString()
    var formatString = function (value, leftJustify, minWidth, precision, zeroPad, customPadChar) {
        if (precision != null) {
            value = value.slice(0, precision);
        }
        return justify(value, '', leftJustify, minWidth, zeroPad, customPadChar);
    };

    // doFormat()
    var doFormat = function (substring, valueIndex, flags, minWidth, _, precision, type) {
        var number;
        var prefix;
        var method;
        var textTransform;
        var value;

        if (substring == '%%') {return '%';}

        // parse flags
        var leftJustify = false, positivePrefix = '', zeroPad = false, prefixBaseX = false, customPadChar = ' ';
        var flagsl = flags.length;
        for (var j = 0; flags && j < flagsl; j++) {
            switch (flags.charAt(j)) {
                case ' ': positivePrefix = ' '; break;
                case '+': positivePrefix = '+'; break;
                case '-': leftJustify = true; break;
                case "'": customPadChar = flags.charAt(j+1); break;
                case '0': zeroPad = true; break;
                case '#': prefixBaseX = true; break;
            }
        }

        // parameters may be null, undefined, empty-string or real valued
        // we want to ignore null, undefined and empty-string values
        if (!minWidth) {
            minWidth = 0;
        } else if (minWidth == '*') {
            minWidth = +a[i++];
        } else if (minWidth.charAt(0) == '*') {
            minWidth = +a[minWidth.slice(1, -1)];
        } else {
            minWidth = +minWidth;
        }

        // Note: undocumented perl feature:
        if (minWidth < 0) {
            minWidth = -minWidth;
            leftJustify = true;
        }

        if (!isFinite(minWidth)) {
            throw new Error('sprintf: (minimum-)width must be finite');
        }

        if (!precision) {
            precision = 'fFeE'.indexOf(type) > -1 ? 6 : (type == 'd') ? 0 : undefined;
        } else if (precision == '*') {
            precision = +a[i++];
        } else if (precision.charAt(0) == '*') {
            precision = +a[precision.slice(1, -1)];
        } else {
            precision = +precision;
        }

        // grab value using valueIndex if required?
        value = valueIndex ? a[valueIndex.slice(0, -1)] : a[i++];

        switch (type) {
            case 's': return formatString(String(value), leftJustify, minWidth, precision, zeroPad, customPadChar);
            case 'c': return formatString(String.fromCharCode(+value), leftJustify, minWidth, precision, zeroPad);
            case 'b': return formatBaseX(value, 2, prefixBaseX, leftJustify, minWidth, precision, zeroPad);
            case 'o': return formatBaseX(value, 8, prefixBaseX, leftJustify, minWidth, precision, zeroPad);
            case 'x': return formatBaseX(value, 16, prefixBaseX, leftJustify, minWidth, precision, zeroPad);
            case 'X': return formatBaseX(value, 16, prefixBaseX, leftJustify, minWidth, precision, zeroPad).toUpperCase();
            case 'u': return formatBaseX(value, 10, prefixBaseX, leftJustify, minWidth, precision, zeroPad);
            case 'i':
            case 'd':
                number = parseInt(+value, 10);
                prefix = number < 0 ? '-' : positivePrefix;
                value = prefix + pad(String(Math.abs(number)), precision, '0', false);
                return justify(value, prefix, leftJustify, minWidth, zeroPad);
            case 'e':
            case 'E':
            case 'f':
            case 'F':
            case 'g':
            case 'G':
                number = +value;
                prefix = number < 0 ? '-' : positivePrefix;
                method = ['toExponential', 'toFixed', 'toPrecision']['efg'.indexOf(type.toLowerCase())];
                textTransform = ['toString', 'toUpperCase']['eEfFgG'.indexOf(type) % 2];
                value = prefix + Math.abs(number)[method](precision);
                return justify(value, prefix, leftJustify, minWidth, zeroPad)[textTransform]();
            default: return substring;
        }
    };

    return format.replace(regex, doFormat);
}


function buildCal(m, y, cM, cH, cDW, cD, brdr) {
	var mn=['January','February','March','April','May','June','July','August','September','October','November','December'];
	var dim=[31,0,31,30,31,30,31,31,30,31,30,31];
	var oD = new Date(y, m-1, 1);
	oD.od=oD.getDay()+1;
	var todaydate=new Date()
	var scanfortoday=(y==todaydate.getFullYear() && m==todaydate.getMonth()+1)? todaydate.getDate() : 0

	dim[1]=(((oD.getFullYear()%100!=0)&&(oD.getFullYear()%4==0))||(oD.getFullYear()%400==0))?29:28;
	var t='<div class="'+cM+'"><table class="'+cM+'" cols="7" cellpadding="0" border="'+brdr+'" cellspacing="0"><tr align="center">';
	t+='<td colspan="7" align="center" class="'+cH+'">'+mn[m-1]+' - '+y+'</td></tr><tr align="center">';
	for(s=0;s<7;s++) t+='<td class="'+cDW+'">'+"SMTWTFS".substr(s,1)+'</td>';
	t+='</tr><tr align="center">';
	for(i=1;i<=42;i++) {
		var x=((i-oD.od>=0)&&(i-oD.od<dim[m-1]))? i-oD.od+1 : '&nbsp;';
		if (x==scanfortoday)
			x='<span id="today">'+x+'</span>'
			t+='<td class="'+cD+'">'+x+'</td>';
		if(((i)%7==0)&&(i<36)) t+='</tr><tr align="center">';
		}
	return t+='</tr></table></div>';
	}

function getBrowserSize() {
	var winW = 780, winH = 460;
	if (document.body && document.body.offsetWidth) {
		winW = document.body.offsetWidth;
		winH = document.body.offsetHeight;
		}
	if (document.compatMode=='CSS1Compat'
		&& document.documentElement
		&& document.documentElement.offsetWidth ) {
		winW = document.documentElement.offsetWidth;
		winH = document.documentElement.offsetHeight;
		}
	if (window.innerWidth && window.innerHeight) {
		winW = window.innerWidth;
		winH = window.innerHeight;
		}
//	document.body.style.width = winW;
// document.writeln('Window width = '+winW);
// document.writeln('Window height = '+winH);
	return winW;
	}

function BrowserWidth() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
//	window.alert( 'Window is ' + myWidth + 'W x ' + myHeight + 'H' );
	return myWidth;
}

// telFormat assumes that phone numbers are 7-digits, area codes are 3, and country
// code is 1, 2, or 3 digits.  It's not perfect, but handles North America and many
// European countries.
//
function telFormat(tfield) {
	tspecial = tfield.value.replace(/\d/g,'');			// Save only non-digits
	if(tspecial != '') {											// User entered their own formatting?
		}
	tval     = tfield.value.replace(/\D/g,'');			// Save only digits
	flen = tval.length;
	if (flen == 10) {
		tval = tval.replace(/^(\d{3})(\d{3})/,'$1-$2-');
		}
	else if (flen == 11) {
		tval = tval.replace(/^(\d{1})(\d{3})(\d{3})(\d{4})/,'+$1-$2-$3-$4');
		}
	else if (flen == 12) {
		tval = tval.replace(/^(\d{2})(\d{3})(\d{3})(\d{4})/,'+$1 $2 $3 $4');
		}
	else if (flen == 13) {
		tval = tval.replace(/^(\d{3})(\d{3})(\d{3})(\d{4})/,'+$1 $2 $3 $4');
		}
	else {
		tval = tfield.value;		// Leave it as it was entered
		}
	tfield.value = tval;
	}

/*
 * Date Format 1.2.3
 * (c) 2007-2009 Steven Levithan <stevenlevithan.com>
 * MIT license
 *
 * Includes enhancements by Scott Trenda <scott.trenda.net>
 * and Kris Kowal <cixar.com/~kris.kowal/>
 *
 * Modified for Canada & Europe date format (d/m/y) by Angelo Babudro
 *
 * Accepts a date, a mask, or a date and a mask.
 * Returns a formatted version of the given date.
 * The date defaults to the current date/time.
 * The mask defaults to dateFormat.masks.default.
 */

var dateFormat = function () {
	var	token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,
		timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
		timezoneClip = /[^-+\dA-Z]/g,
		pad = function (val, len) {
			val = String(val);
			len = len || 2;
			while (val.length < len) val = "0" + val;
			return val;
		};

	// Regexes and supporting functions are cached through closure
	return function (date, mask, utc) {
		var dF = dateFormat;

		// You can't provide utc if you skip other args (use the "UTC:" mask prefix)
		if (arguments.length == 1 && Object.prototype.toString.call(date) == "[object String]" && !/\d/.test(date)) {
			mask = date;
			date = undefined;
		}

		// Passing date through Date applies Date.parse, if necessary
		date = date ? new Date(date) : new Date;
		if (isNaN(date)) throw SyntaxError("invalid date");

		mask = String(dF.masks[mask] || mask || dF.masks["default"]);

		// Allow setting the utc argument via the mask
		if (mask.slice(0, 4) == "UTC:") {
			mask = mask.slice(4);
			utc = true;
		}

		var	_ = utc ? "getUTC" : "get",
			d = date[_ + "Date"](),
			D = date[_ + "Day"](),
			m = date[_ + "Month"](),
			y = date[_ + "FullYear"](),
			H = date[_ + "Hours"](),
			M = date[_ + "Minutes"](),
			s = date[_ + "Seconds"](),
			L = date[_ + "Milliseconds"](),
			o = utc ? 0 : date.getTimezoneOffset(),
			flags = {
				d:    d,
				dd:   pad(d),
				ddd:  dF.i18n.dayNames[D],
				dddd: dF.i18n.dayNames[D + 7],
				m:    m + 1,
				mm:   pad(m + 1),
				mmm:  dF.i18n.monthNames[m],
				mmmm: dF.i18n.monthNames[m + 12],
				yy:   String(y).slice(2),
				yyyy: y,
				h:    H % 12 || 12,
				hh:   pad(H % 12 || 12),
				H:    H,
				HH:   pad(H),
				M:    M,
				MM:   pad(M),
				s:    s,
				ss:   pad(s),
				l:    pad(L, 3),
				L:    pad(L > 99 ? Math.round(L / 10) : L),
				t:    H < 12 ? "a"  : "p",
				tt:   H < 12 ? "am" : "pm",
				T:    H < 12 ? "A"  : "P",
				TT:   H < 12 ? "AM" : "PM",
				Z:    utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
				o:    (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
				S:    ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10]
			};

		return mask.replace(token, function ($0) {
			return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
		});
	};
}();

// Some common format strings
dateFormat.masks = {
	"default":      "ddd dd mmm yyyy HH:MM:ss",
	shortDate:      "d/m/yy",
	mediumDate:     "d mmm yyyy",
	longDate:       "d mmmm yyyy",
	fullDate:       "dddd d mmmm yyyy",
	shortTime:      "h:MM TT",
	mediumTime:     "h:MM:ss TT",
	longTime:       "h:MM:ss TT Z",
	isoDate:        "yyyy-mm-dd",
	isoTime:        "HH:MM:ss",
	isoDateTime:    "yyyy-mm-dd'T'HH:MM:ss",
	isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"
};

// Internationalization strings
dateFormat.i18n = {
	dayNames: [
		"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
		"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
	],
	monthNames: [
		"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
		"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
	]
};

// For convenience...
Date.prototype.format = function (mask, utc) {
	return dateFormat(this, mask, utc);
};

// Take 2-char country code and return the country name
// Return FALSE if code is invalid
//
function ValidateCountry(code) {
	switch (code) {
		case 'AD': return 'Andorra'; break;
		case 'AE': return 'United Arab Emirates'; break;
		case 'AF': return 'Afghanistan'; break;
		case 'AG': return 'Antigua and Barbuda'; break;
		case 'AI': return 'Anguilla'; break;
		case 'AL': return 'Albania'; break;
		case 'AM': return 'Armenia'; break;
		case 'AN': return 'Netherlands Antilles'; break;
		case 'AO': return 'Angola'; break;
		case 'AQ': return 'Antarctica'; break;
		case 'AR': return 'Argentina'; break;
		case 'AS': return 'American Samoa'; break;
		case 'AT': return 'Austria'; break;
		case 'AU': return 'Australia'; break;
		case 'AW': return 'Aruba'; break;
		case 'AX': return 'Aland Islands'; break;
		case 'AZ': return 'Azerbaijan'; break;
		case 'BA': return 'Bosnia and Herzegovina'; break;
		case 'BB': return 'Barbados'; break;
		case 'BD': return 'Bangladesh'; break;
		case 'BE': return 'Belgium'; break;
		case 'BF': return 'Burkina Faso'; break;
		case 'BG': return 'Bulgaria'; break;
		case 'BH': return 'Bahrain'; break;
		case 'BI': return 'Burundi'; break;
		case 'BJ': return 'Benin'; break;
		case 'BM': return 'Bermuda'; break;
		case 'BN': return 'Brunei Darussalam'; break;
		case 'BO': return 'Bolivia'; break;
		case 'BR': return 'Brazil'; break;
		case 'BS': return 'Bahamas'; break;
		case 'BT': return 'Bhutan'; break;
		case 'BV': return 'Bouvet Island'; break;
		case 'BW': return 'Botswana'; break;
		case 'BY': return 'Belarus'; break;
		case 'BZ': return 'Belize'; break;
		case 'CA': return 'Canada'; break;
		case 'CC': return 'Cocos (Keeling) Islands'; break;
		case 'CD': return 'Democratic Republic of the Congo'; break;
		case 'CF': return 'Central African Republic'; break;
		case 'CG': return 'Congo'; break;
		case 'CH': return 'Switzerland'; break;
		case 'CI': return 'Cote D\'Ivoire (Ivory Coast)'; break;
		case 'CK': return 'Cook Islands'; break;
		case 'CL': return 'Chile'; break;
		case 'CM': return 'Cameroon'; break;
		case 'CN': return 'China'; break;
		case 'CO': return 'Colombia'; break;
		case 'CR': return 'Costa Rica'; break;
		case 'CS': return 'Serbia and Montenegro'; break;
		case 'CU': return 'Cuba'; break;
		case 'CV': return 'Cape Verde'; break;
		case 'CX': return 'Christmas Island'; break;
		case 'CY': return 'Cyprus'; break;
		case 'CZ': return 'Czech Republic'; break;
		case 'DE': return 'Germany'; break;
		case 'DJ': return 'Djibouti'; break;
		case 'DK': return 'Denmark'; break;
		case 'DM': return 'Dominica'; break;
		case 'DO': return 'Dominican Republic'; break;
		case 'DZ': return 'Algeria'; break;
		case 'EC': return 'Ecuador'; break;
		case 'EE': return 'Estonia'; break;
		case 'EG': return 'Egypt'; break;
		case 'EH': return 'Western Sahara'; break;
		case 'ER': return 'Eritrea'; break;
		case 'ES': return 'Spain'; break;
		case 'ET': return 'Ethiopia'; break;
		case 'FI': return 'Finland'; break;
		case 'FJ': return 'Fiji'; break;
		case 'FK': return 'Falkland Islands (Malvinas)'; break;
		case 'FM': return 'Federated States of Micronesia'; break;
		case 'FO': return 'Faroe Islands'; break;
		case 'FR': return 'France'; break;
		case 'FX': return 'France, Metropolitan'; break;
		case 'GA': return 'Gabon'; break;
		case 'GB': return 'Great Britain (UK)'; break;
		case 'GD': return 'Grenada'; break;
		case 'GE': return 'Georgia'; break;
		case 'GF': return 'French Guiana'; break;
		case 'GH': return 'Ghana'; break;
		case 'GI': return 'Gibraltar'; break;
		case 'GL': return 'Greenland'; break;
		case 'GM': return 'Gambia'; break;
		case 'GN': return 'Guinea'; break;
		case 'GP': return 'Guadeloupe'; break;
		case 'GQ': return 'Equatorial Guinea'; break;
		case 'GR': return 'Greece'; break;
		case 'GS': return 'S. Georgia and S. Sandwich Islands'; break;
		case 'GT': return 'Guatemala'; break;
		case 'GU': return 'Guam'; break;
		case 'GW': return 'Guinea-Bissau'; break;
		case 'GY': return 'Guyana'; break;
		case 'HK': return 'Hong Kong'; break;
		case 'HM': return 'Heard Island and McDonald Islands'; break;
		case 'HN': return 'Honduras'; break;
		case 'HR': return 'Croatia (Hrvatska)'; break;
		case 'HT': return 'Haiti'; break;
		case 'HU': return 'Hungary'; break;
		case 'ID': return 'Indonesia'; break;
		case 'IE': return 'Ireland'; break;
		case 'IL': return 'Israel'; break;
		case 'IN': return 'India'; break;
		case 'IO': return 'British Indian Ocean Territory'; break;
		case 'IQ': return 'Iraq'; break;
		case 'IR': return 'Iran'; break;
		case 'IS': return 'Iceland'; break;
		case 'IT': return 'Italy'; break;
		case 'JM': return 'Jamaica'; break;
		case 'JO': return 'Jordan'; break;
		case 'JP': return 'Japan'; break;
		case 'KE': return 'Kenya'; break;
		case 'KG': return 'Kyrgyzstan'; break;
		case 'KH': return 'Cambodia'; break;
		case 'KI': return 'Kiribati'; break;
		case 'KM': return 'Comoros'; break;
		case 'KN': return 'Saint Kitts and Nevis'; break;
		case 'KP': return 'Korea (North)'; break;
		case 'KR': return 'Korea (South)'; break;
		case 'KW': return 'Kuwait'; break;
		case 'KY': return 'Cayman Islands'; break;
		case 'KZ': return 'Kazakhstan'; break;
		case 'LA': return 'Laos'; break;
		case 'LB': return 'Lebanon'; break;
		case 'LC': return 'Saint Lucia'; break;
		case 'LI': return 'Liechtenstein'; break;
		case 'LK': return 'Sri Lanka'; break;
		case 'LR': return 'Liberia'; break;
		case 'LS': return 'Lesotho'; break;
		case 'LT': return 'Lithuania'; break;
		case 'LU': return 'Luxembourg'; break;
		case 'LV': return 'Latvia'; break;
		case 'LY': return 'Libya'; break;
		case 'MA': return 'Morocco'; break;
		case 'MC': return 'Monaco'; break;
		case 'MD': return 'Moldova'; break;
		case 'MG': return 'Madagascar'; break;
		case 'MH': return 'Marshall Islands'; break;
		case 'MK': return 'Macedonia'; break;
		case 'ML': return 'Mali'; break;
		case 'MM': return 'Myanmar'; break;
		case 'MN': return 'Mongolia'; break;
		case 'MO': return 'Macao'; break;
		case 'MP': return 'Northern Mariana Islands'; break;
		case 'MQ': return 'Martinique'; break;
		case 'MR': return 'Mauritania'; break;
		case 'MS': return 'Montserrat'; break;
		case 'MT': return 'Malta'; break;
		case 'MU': return 'Mauritius'; break;
		case 'MV': return 'Maldives'; break;
		case 'MW': return 'Malawi'; break;
		case 'MX': return 'Mexico'; break;
		case 'MY': return 'Malaysia'; break;
		case 'MZ': return 'Mozambique'; break;
		case 'NA': return 'Namibia'; break;
		case 'NC': return 'New Caledonia'; break;
		case 'NE': return 'Niger'; break;
		case 'NF': return 'Norfolk Island'; break;
		case 'NG': return 'Nigeria'; break;
		case 'NI': return 'Nicaragua'; break;
		case 'NL': return 'Netherlands'; break;
		case 'NO': return 'Norway'; break;
		case 'NP': return 'Nepal'; break;
		case 'NR': return 'Nauru'; break;
		case 'NU': return 'Niue'; break;
		case 'NZ': return 'New Zealand (Aotearoa)'; break;
		case 'OM': return 'Oman'; break;
		case 'PA': return 'Panama'; break;
		case 'PE': return 'Peru'; break;
		case 'PF': return 'French Polynesia'; break;
		case 'PG': return 'Papua New Guinea'; break;
		case 'PH': return 'Philippines'; break;
		case 'PK': return 'Pakistan'; break;
		case 'PL': return 'Poland'; break;
		case 'PM': return 'Saint Pierre and Miquelon'; break;
		case 'PN': return 'Pitcairn'; break;
		case 'PR': return 'Puerto Rico'; break;
		case 'PS': return 'Palestinian Territory'; break;
		case 'PT': return 'Portugal'; break;
		case 'PW': return 'Palau'; break;
		case 'PY': return 'Paraguay'; break;
		case 'QA': return 'Qatar'; break;
		case 'RE': return 'Reunion'; break;
		case 'RO': return 'Romania'; break;
		case 'RU': return 'Russian Federation'; break;
		case 'RW': return 'Rwanda'; break;
		case 'SA': return 'Saudi Arabia'; break;
		case 'SB': return 'Solomon Islands'; break;
		case 'SC': return 'Seychelles'; break;
		case 'SD': return 'Sudan'; break;
		case 'SE': return 'Sweden'; break;
		case 'SG': return 'Singapore'; break;
		case 'SH': return 'Saint Helena'; break;
		case 'SI': return 'Slovenia'; break;
		case 'SJ': return 'Svalbard and Jan Mayen'; break;
		case 'SK': return 'Slovakia'; break;
		case 'SL': return 'Sierra Leone'; break;
		case 'SM': return 'San Marino'; break;
		case 'SN': return 'Senegal'; break;
		case 'SO': return 'Somalia'; break;
		case 'SR': return 'Suriname'; break;
		case 'ST': return 'Sao Tome and Principe'; break;
		case 'SV': return 'El Salvador'; break;
		case 'SY': return 'Syria'; break;
		case 'SZ': return 'Swaziland'; break;
		case 'TC': return 'Turks and Caicos Islands'; break;
		case 'TD': return 'Chad'; break;
		case 'TF': return 'French Southern Territories'; break;
		case 'TG': return 'Togo'; break;
		case 'TH': return 'Thailand'; break;
		case 'TJ': return 'Tajikistan'; break;
		case 'TK': return 'Tokelau'; break;
		case 'TL': return 'Timor-Leste'; break;
		case 'TM': return 'Turkmenistan'; break;
		case 'TN': return 'Tunisia'; break;
		case 'TO': return 'Tonga'; break;
		case 'TP': return 'East Timor'; break;
		case 'TR': return 'Turkey'; break;
		case 'TT': return 'Trinidad and Tobago'; break;
		case 'TV': return 'Tuvalu'; break;
		case 'TW': return 'Taiwan'; break;
		case 'TZ': return 'Tanzania'; break;
		case 'UA': return 'Ukraine'; break;
		case 'UG': return 'Uganda'; break;
		case 'UK': return 'United Kingdom'; break;
		case 'UM': return 'United States Minor Outlying Islands'; break;
		case 'US': return 'United States'; break;
		case 'UY': return 'Uruguay'; break;
		case 'UZ': return 'Uzbekistan'; break;
		case 'VA': return 'Vatican City State (Holy See)'; break;
		case 'VC': return 'Saint Vincent and the Grenadines'; break;
		case 'VE': return 'Venezuela'; break;
		case 'VG': return 'Virgin Islands (British)'; break;
		case 'VI': return 'Virgin Islands (U.S.)'; break;
		case 'VN': return 'Viet Nam'; break;
		case 'VU': return 'Vanuatu'; break;
		case 'WF': return 'Wallis and Futuna'; break;
		case 'WS': return 'Samoa'; break;
		case 'YE': return 'Yemen'; break;
		case 'YT': return 'Mayotte'; break;
		case 'ZA': return 'South Africa'; break;
		case 'ZM': return 'Zambia'; break;
		case 'ZW': return 'Zimbabwe'; break;
		}
	return false;
	}



function NumbersOnly(e) {
	var unicode=e.charCode ? e.charCode : e.keyCode;
// Permissible control keys:  TAB, BS, Right Arrow, Left Arrow, Delete, Home, End, and Refresh (F5)
	var valid_ctrl = (unicode == 8 || unicode == 9 || unicode == 35 || unicode == 36 || unicode == 37 || unicode == 39 || unicode == 46 || unicode == 116);
	if (!valid_ctrl && (unicode < 48 || unicode > 57)) {	//  and if not a number
		//alert("Only numbers are allowed (" + unicode + ").");
		return false							// ignore this key-press
		}
	}

function AlphaNumeric(e) {
	var unicode=e.charCode ? e.charCode : e.keyCode;
// Permissible control keys:  TAB, BS, Right Arrow, Left Arrow, Delete, Home, End, and Refresh (F5)
	var valid_ctrl = (unicode == 8 || unicode == 9 || unicode == 35 || unicode == 36 || unicode == 37 || unicode == 39 || unicode == 46 || unicode == 116);
	var is_number = (unicode > 47 && unicode < 58);
	var upper_case = (unicode > 64 && unicode < 91);						#|A-Z
	var lower_case = (unicode > 96 && unicode < 123);						#|a-z
	var valid_symbols = (unicode == 32 || unicode == 46 || unicode == 64);	#|Space, period, or at-sign
	if (!valid_ctrl && !is_number && !upper_case && !lower_case && !valid_symbols) {
		//alert("Character (" + unicode + ") is not allowed.");
		return false							// ignore this key-press
		}
	}

