
  var additionalResources = new Array();
	var ourPartners = new Array();

  //*******************************************************************
  // confirmation message to cancel registration
  //*******************************************************************
  function doCancel() {
		if (confirm("All information entered up to this point will be lost. Are you sure you want to cancel?")) { 
		  var fullURL = parent.document.URL;
      token = fullURL.substring(fullURL.indexOf('?'), fullURL.length)
		  location.href="registration-cancel.php"+token;
		}
	}

  //*******************************************************************
	// display popup div tag
  //*******************************************************************
	function showPopup(aElementId) {
		var cvr = document.getElementById("cover")
		var dlg = document.getElementById(aElementId)
		cvr.style.display = "block"
		dlg.style.display = "block"
		if (document.body.style.overflow = "hidden") {
			cvr.style.width = "100%"
			cvr.style.height = "100%"
		}
	}

  //*******************************************************************
	// hide popup div tag
  //*******************************************************************
  function closePopup(aElementId) {
		var cvr = document.getElementById("cover")
		var dlg = document.getElementById(aElementId)
		cvr.style.display = "none"
		dlg.style.display = "none"
		document.body.style.overflowY = "scroll"
	}

  //*******************************************************************
  // set the state in order to display the correct resources
  //*******************************************************************
  function setState(aState, aStateName, aFromMap ) {
		var html = '';
		if (aState!='') {
  		html = '<img src="images/states/'+aState+'-small.png" align="absmiddle"/>&nbsp;&nbsp;' + aStateName;
		} else {
	  	html = '<img src="images/states/US-small.png" align="absmiddle"/>&nbsp;&nbsp;Select your State...';
		}

    var element = document.getElementById("state-selection");
		element.innerHTML = html;
		document.cookie = 'warwithin-state='+aState;
		
		setVisible( 'state-dropdown', false );
		
		// check if we need to navigate the flash map
		if(typeof openState == 'function' && !aFromMap) {
  		if (aState!='')
    		openState( 'FCMap_'+aStateName.replace( ' ', '' ), aState, aStateName, true );
			else
			  openUs(true);
		}
		
		if ( document.getElementById("additional-resources"))
  		loadAdditionalResources(aState);

    if ( document.getElementById("ourpartners"))
  		loadOurPartners(aState);
	}

  //*******************************************************************
  // show/hide the state dropdown
  //*******************************************************************
  function dropdownStates(aForceHide) {
		var visible = false;
		if (!aForceHide){
  		var element = document.getElementById("state-dropdown");
  		visible = element.style.display == 'none';
		}

    // attach an event on the document (is it is not already attached) to hide the dropdown 
		// if clicked anywhere else but in the dropdown
    if (visible) {
			if (document.addEventListener) {
				document.addEventListener('click',documentClick, false );
			}
		} else {
  		document.removeEventListener( 'click', documentClick, false );
		}
		
		setVisible( 'state-dropdown', visible );
	}
	
  //*******************************************************************
	// event to handle hiding of dropdown
  //*******************************************************************
	function documentClick(e) {
    var target = (e && e.target) || (event && event.srcElement); 
		if ( target.id != 'state-selection' && target.parentNode.id != 'state-selection') {
			setVisible( 'state-dropdown', false );
  		document.removeEventListener( 'click', documentClick, false );
		}
	}
	
  //*******************************************************************
	// load partners for state
  //*******************************************************************
	function loadOurPartners( aState ) {
		if (!ourPartners[aState]) {
  		ajaxGet( "ourpartners-ajax.php?state="+aState, ourPartnersLoaded, aState );
		} else {
			ourPartnersLoaded( ourPartners[aState] );
		}
	}

  //*******************************************************************
  // the partners to the state were loaded
  //*******************************************************************
	function ourPartnersLoaded( aData, aState ) {
		if (!ourPartners[aState]) {
  		ourPartners[aState] = aData;
		}

    var element = document.getElementById("ourpartners");
		element.innerHTML = aData;
  }

  //*******************************************************************
  // load additional resources for selected state
  //*******************************************************************
	function loadAdditionalResources( aState ) {
		if (!additionalResources[aState]) {
  		ajaxGet( "additional-resources-ajax.php?state="+aState, additionalResourcesLoaded, aState );
		} else {
			additionalResourcesLoaded( additionalResources[aState] );
		}
	}

  //*******************************************************************
  // the resources to the state were loaded
  //*******************************************************************
	function additionalResourcesLoaded( aData, aState ) {
		if (!additionalResources[aState]) {
  		additionalResources[aState] = aData;
		}

    var element = document.getElementById("additional-resources");
		element.innerHTML = aData;
  }

  //*******************************************************************
  // create an ajax call to the server and then call the passed javascript function. customData is passed through as a parameter
  //*******************************************************************
	function ajaxGet(aURL, aLoadingDone, aCustomData) {
			var xmlHttpReq = false;
			var self = this;
			// Mozilla/Safari
			if (window.XMLHttpRequest) {
					self.xmlHttpReq = new XMLHttpRequest();
			}
			// IE
			else if (window.ActiveXObject) {
				self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
			}
			self.xmlHttpReq.onreadystatechange = function() {
					if (self.xmlHttpReq.readyState == 4) {
							aLoadingDone(self.xmlHttpReq.responseText, aCustomData);
					}
			}
			self.xmlHttpReq.open('GET', aURL, true);
			self.xmlHttpReq.send(null);
	 }
	
  //*******************************************************************
  // set the visibility of a tag with a given ID
  //*******************************************************************
	function setVisible(aId,aVisible) {
    element = document.getElementById( aId );

		if (aVisible) {
      if ( element.tagName == 'TR' )
  		  element.style.display = 'table-row';
			else
      if ( element.tagName == 'TD' )
  		  element.style.display = 'table-cell';
			else
      if ( element.tagName == 'SPAN' )
  		  element.style.display = 'inline';
			else
      if ( element.tagName == 'INPUT' )
  		  element.style.display = 'inline';
			else
      if ( element.tagName == 'DIV' )
  		  element.style.display = 'block';
			else
  		  element.removeAttribute('style');			
		} else
		  element.style.display = 'none';
	}
	
	function mysqlTimeStampToDate(timestamp) {
    //function parses mysql datetime string and returns javascript Date object
    //input has to be in this format: 2007-06-05 15:26:02
    var regex=/^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9]) (?:([0-2][0-9]):([0-5][0-9]):([0-5][0-9]))?$/;
    var parts=timestamp.replace(regex,"$1 $2 $3 $4 $5 $6").split(' ');
    return new Date(parts[0],parts[1]-1,parts[2],parts[3],parts[4],parts[5]);
  }
	
	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);
};



