function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}



// commands for Information Request form

if (this.location.search.substr(1) == "military") {
		for (i = 0; i < document.forms[0].market.options.length; i++) {
			if (document.forms[0].market.options[i].value == "Association - Military Reunions")
				document.forms[0].market.selectedIndex = i;
		}
	}
	function validate(f) {
		var msg = "";
		var valid = true;
		if (f.meeting.value.length < 10) msg = "Please enter the meeting name for your event.\n";
		if (!IsEmailValid(f.email)) msg = "You must enter a valid e-mail address in order to submit your Information Request. It will only be used in connection with your event.\n";
		if (f.phone.value.length < 10) msg = "Enter a valid phone number for the contact name you entered.\n";
		if (f.street.value.length < 3 || f.city.value.length < 1 || f.state.value.length < 1 || f.zip.value.length < 1) msg = "Please include the street address of your organization in case we need to send you hardcopy information by mail.\n";
		if (f.organization.value.length < 3) msg = "Please enter the name of your organization.\n";
		if (f.name.value.length < 7) msg = "You did not enter a contact name.\n";
		if (msg) {
			alert(msg);
			valid = false;
		}
		return valid;
	}
	function IsEmailValid(field) {
		var email_ok = true;
		var AtSym    = field.value.indexOf('@');
		var Period   = field.value.lastIndexOf('.');
		var Space    = field.value.indexOf(' ');
		var Length   = field.value.length - 1;   // Array is from 0 to length-1
		if ((AtSym < 1) ||                     // '@' cannot be in first position
		    (Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
		    (Period == Length ) ||             // Must be atleast one valid char after '.'
		    (Space  != -1) ||                  // No empty spaces permitted
		    (Length <= 0))                     // Cannot be empty
		   {  
		      email_ok = false;
		   }
		return email_ok;
	}
	
// code for dropdown menus

function go1(){
if
(document.roadtrip.attractions.options[document.roadtrip.attractions.selectedIndex].value != "none") {
location = document.roadtrip.attractions.options[document.roadtrip.attractions.selectedIndex].value
  }
 }
 
function go2(){
if
(document.who_r_u.grouptype.options[document.who_r_u.grouptype.selectedIndex].value != "none") {
location = document.who_r_u.grouptype.options[document.who_r_u.grouptype.selectedIndex].value
  }
 }
 function go3(){
if
(document.greene_reasons.top10.options[document.greene_reasons.top10.selectedIndex].value != "none") {
location = document.greene_reasons.top10.options[document.greene_reasons.top10.selectedIndex].value
  }
 }
  function go4(){
if
(document.month_selector.months.options[document.month_selector.months.selectedIndex].value != "none") {
location = document.month_selector.months.options[document.month_selector.months.selectedIndex].value
  }
 }
 
 //generic functions for input validation

function isValidEmail (emailAddress) {
	var errorFound = new Boolean;
	errorFound = false;
	if (emailAddress != "") {
		var amphersand = emailAddress.indexOf('&');
		var atSymbol = emailAddress.indexOf('@');
		var dot = emailAddress.lastIndexOf('.');
		var whiteSpace = emailAddress.indexOf(' ');
		var wwwDot = emailAddress.indexOf('www.');
		var stringLength = emailAddress.length - 1;
			
		if ((atSymbol < 1) || (dot <= atSymbol+1) || (dot == stringLength ) || (whiteSpace  != -1) || (wwwDot == 0) || (amphersand != -1)) {
			errorFound = true;
		}
			
		if (wwwDot == 0) {
			errorFound = true;
		}
	}
	return !errorFound;
}

/**
 * DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function isValidPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function fixElement(element, message) {
	alert(message);
	element.focus();
}