var listPopup = null;

function listPopUp(url, width, height) 
{
    var winClosed = false;

    if (window.listPopup == null) winClosed = true;
    else 
        if (listPopup.closed) winClosed = true;

    if (!winClosed) 
        listPopup.location.href = url;
    else
        listPopup = window.open(url,"listpopupWindow","width=" + width + ",height=" + height+",scrollbars=yes,toolbars=0,statusbars=0,menubars=0,resizable=1");

    if (!listPopup.opener) 
        listPopup.opener = self;

    window.listPopup.focus();
}

function validateEmail(formObj)
{
    txt=formObj.Email.value;
    if (emptyField(formObj.Email))
    {
        alert("Please include your email address so we respond to your question or comment.")		
    } else
        return true;
    return false;
}

function validatePledgeEmail(formObj)
{
    txt=formObj.Email.value;
    if (emptyField(formObj.Email))
    {
        alert("Please include your email address.")		
    } else
        return true;
    return false;
}	
	
		
/* This is, at best, a perfunctory test of email address 
    entry validity.  Is there an "@" sign and sufficient
    letters prefixing it, is there a .net, .gov, .org or
    .com in the suffix? Alert user if questioned. */
	function emailCheck(formObj) {
			txt=formObj.Email.value;
			if (emptyField(formObj.Email))
				return true;
  		if (txt.indexOf("@")<3)
				alert("Your email address seems incorrect. Please check the prefix and '@' sign.");
			else if ((txt.indexOf(".com")<5) 
				&&(txt.indexOf(".org")<5)
  			&&(txt.indexOf(".gov")<5)
				&&(txt.indexOf(".net")<5)
				&&(txt.indexOf(".mil")<5)) {
  				alert("Your email address seems incorrect. Please"
   					+" check the suffix for accuracy. (It should include a "
 						+".com,.net,.org,.gov or .mil)");
  		}
			else if(Validate(formObj.Email)!=0)
      		return false;
			else return true;
			
			return false;
	}

	function Validate(email)
	{
		address = new String(email.value);
		// alert(address);
		if(address.length == 0) return 0; 
	
 		invalidchars = new Array(' ', ',', '[', ']', '/', '=', ';', '`', '+', '!', '#', '$', '%', '^', '&', '*', '(', ')', '~', ':', '\"', '\'', '\b', '<', '>', '?', '|', '{', '}');
		error_messages = new Array();
		error_messages[0] = "Valid";
		error_messages[1] = "Address must have an @ then a \'.\'\nand cannot begin with @";
		error_messages[2] = "Address cannot have \'.\' next to @ or as final character";
		error_messages[3] = "Spaces are invalid";
		error_messages[4] = "Commas are invalid";
		error_messages[5] = "Brackets are invalid";
		error_messages[6] = "Brackets are invalid";
		error_messages[7] = "Slashes are invalid";
		error_messages[8] = "Equals are invalid";
		error_messages[9] = "Semi-Colons are invalid";
		error_messages[10] = "Accents are invalid";
		error_messages[11] = "Plus signs are invalid";
		error_messages[12] = "Exclamations are invalid";
		error_messages[13] = "Pound signs are invalid";
		error_messages[14] = "Dollar signs are invalid";
		error_messages[15] = "Percents are invalid";
		error_messages[16] = "Not sign is invalid";
		error_messages[17] = "Ampersands are invalid";
		error_messages[18] = "Stars are invalid";
		error_messages[19] = "Parentheses are invalid";
		error_messages[20] = "Parentheses are invalid";
		error_messages[21] = "Approximation signs are invalid";
		error_messages[22] = "Colons are invalid";
		error_messages[23] = "Invalid charaters used";
		error_messages[24] = "Invalid charaters used";
		error_messages[25] = "Invalid charaters used";
		error_messages[26] = "Less-than signs are invalid";
		error_messages[27] = "Greater-than signs are invalid";
		error_messages[28] = "Question-mark signs are invalid";
		error_messages[29] = "Invalid charaters used";
		error_messages[30] = "Invalid charaters used";
		error_messages[31] = "Invalid charaters used";
		
		var atloc=address.indexOf('@');
		var dotloc=address.lastIndexOf('.');
		var strOpt="\n\nYou also may simply leave this field blank";
         
   // Tests For one '.' and one '@' in correct order
   // And makes sure first substring isn't null
	 // alert("@loc: " + atloc + " .Loc: " + dotloc);
		if(atloc<1||dotloc==-1||dotloc<atloc)
		{
			alert("\nInvalid E-Mail Address\n" + error_messages[1] + "\nExample: sam@somplace.com" + strOpt);           
			return 1;
		}
                
   // Tests second and third substrings for nullness
   	else if(dotloc < atloc+2 || address.length < dotloc+2)
		{
      alert("\nInvalid E-Mail Address\n"+error_messages[2] + "\nExample: sam@somplace.com" + strOpt);     
      return 2;
   	}             
        
   // Tests for individual syntax errors
   // Only common keystroke errors included!        
   	for(var ct=0;ct<invalidchars.length;ct++)
  	{
			status=invalidchars[ct];
      if(address.indexOf(invalidchars[ct])!=-1)
			{
				alert("\nInvalid E-mail Address\n" + error_messages[ct+3] + "\nExample: sam@somplace.com" + strOpt);
				return (ct+3);
      }
   }
	 return 0;
	}	
	
	// Check to see if field is empty
	function emptyField(textObj) {
		if (textObj.value.length == 0) return true;
		for (var i=0; i<textObj.value.length; ++i) {
			var ch = textObj.value.charAt(i);
			if (ch != ' ' && ch != '\t') return false;
		}
		return true;
	}
	
	
	function Checknumber(object_value)
	{
		//Returns true if value is a number or is NULL
			//otherwise returns false	

		if (object_value.length == 0)
			return true;

		//Returns true if value is a number defined as
		//   having an optional leading + or -.
		//   having at most 1 decimal point.
		//   otherwise containing only the characters 0-9.
		var start_format = " .+-0123456789";
		var number_format = " .0123456789";
		var check_char;
		var decimal = false;
		var trailing_blank = false;
		var digits = false;

		//The first character can be + - .  blank or a digit.
		check_char = start_format.indexOf(object_value.charAt(0))
		//Was it a decimal?
		if (check_char == 1)
			decimal = true;
		else if (check_char < 1)
			return false;
       
		//Remaining characters can be only . or a digit, but only one decimal.
		for (var i = 1; i < object_value.length; i++)
		{
			check_char = number_format.indexOf(object_value.charAt(i))
			if (check_char < 0)
				return false;
			else if (check_char == 1)
			{
				if (decimal)		// Second decimal.
					return false;
				else
					decimal = true;
			}
			else if (check_char == 0)
			{
				if (decimal || digits)	
					trailing_blank = true;
					// ignore leading blanks
			}
			else if (trailing_blank)
				return false;
			else
				digits = true;
		}	
		//All tests passed, so...
		return true
	}
	
function submitForm(action) 
{
    document.forms[0].action = action;
    this.document.forms[0].submit();
	return true;
}	


/*
	Javascript to style odd/even table rows
	Derived from 'Zebra Tables' by David F. Miller (http://www.alistapart.com/articles/zebratables/)

	Modified by Jop de Klein, february 2005
	jop at validweb.nl
	http://validweb.nl/artikelen/javascript/better-zebra-tables/
*/

var stripe = function() {
	var tables = document.getElementsByTagName("table");

	for(var x=0;x!=tables.length;x++){
		var table = tables[x];
		if (! table) { return; }

		var tbodies = table.getElementsByTagName("tbody");

		for (var h = 0; h < tbodies.length; h++) {
			var even = true;
			var trs = tbodies[h].getElementsByTagName("tr");

			for (var i = 0; i < trs.length; i++) {
				trs[i].onmouseover=function(){
					this.className += " ruled"; return false
				}
				trs[i].onmouseout=function(){
					this.className = this.className.replace("ruled", ""); return false
				}
				if(even)
					trs[i].className += " even";
				even = !even;
			}
		}
	}
}

/*
 * 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/>
 *
 * 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 mmm dd yyyy HH:MM:ss",
	shortDate:      "m/d/yy",
	mediumDate:     "mmm d, yyyy",
	longDate:       "mmmm d, yyyy",
	fullDate:       "dddd, mmmm d, 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);
};

