
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];}
}


var web_path = "/";


var days_in_month = new Array( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );

function getDaysInMonth( month, year ) {
	var eom = days_in_month[ month ];
	if ( (month == 1) && (year % 4 == 0) && ((year % 100 != 0) || ((year % 100 == 0) && (year % 400 == 0))) )
		eom = 29;
	return eom;
}
function fixDaysInMonthPopup( dayObj, month, year ) {
	var eom = getDaysInMonth( month, year );
	if ( dayObj.length < eom ) {
		for ( var n = dayObj.length; n < eom; n++ )
			dayObj.options[n] = new Option( n + 1, n + 1 );
	}
	else if ( dayObj.length > eom ) {
		for ( var n = eom; n < dayObj.length; n++ )
			dayObj.options[n] == null;
	}
	dayObj.length = eom;
}

function newMonth( monthField, dayField, yearField ) {
	fixDaysInMonthPopup( document.forms['entry'][dayField], document.forms['entry'][monthField].value - 1, document.forms['entry'][yearField].value );
}


function setElementClass( inID, inClass ) {
	var elt = document.getElementById( inID );
	if ( elt )
		elt.className = inClass;
}
function validateForm( inFormName, inFields ) {
	var form = document.forms[ inFormName ];
	var emailRE = /^((?:(?:(?:\w[\.\-\+]?)*)\w)+)\@((?:(?:(?:\w[\.\-\+]?){0,62})\w)+)\.(\w{2,6})$/;
	var dateRE = new RegExp("^([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})$");

	var missing = false;
	var errors = "";
	var confirm = [];
	

	var validateField = function( fld ) {
		var validated = true;
		if ( form[fld.id] && form[fld.id].value.length > 0 ) {
			if ( fld.validate == "email" ) {
				if ( !form[fld.id].value.match(emailRE) ) {
					ok = false;
					validated = false;
					errors += "Your email address is invalid. ";
				}
			}
			else if ( fld.validate == "date" ) {
				var valid = false;
				var matches = dateRE.exec( form[fld.id].value );
				if ( matches ) {
					var date = new Date( matches[3], (matches[1] - 1), matches[2] );
					valid = ((date.getMonth() == (matches[1] - 1)) && (date.getDate() == matches[2]) && (date.getFullYear() == matches[3]));
				}
				if ( !valid ) {
					ok = false;
					validated = false;
					errors += fld.label + " is invalid. ";
				}
			}
		}
		else {
			ok = false;
			missing = true;
			validated = false;
		}
		return validated;
	}
	
	for ( var n = 0; n < inFields.length; n++ ) {
		var f = inFields[ n ];
		var ok = true;
		if ( f.either && f.or ) {
			var hase = true;
			for ( var e = 0; e < f.either.length; e++ ) {
				if ( form[f.either[e].id] && form[f.either[e].id].value.length == 0 )
					hase = false;
			}
			var haso = true;
			for ( var o = 0; o < f.or.length; o++ ) {
				if ( form[f.or[o].id] && form[f.or[o].id].value.length == 0 )
					haso = false;
			}
			var has = hase || haso;
			for ( var e = 0; e < f.either.length; e++ )
				setElementClass( f.either[e].id, has ? "verified" : "incorrect" );
			for ( var o = 0; o < f.or.length; o++ )
				setElementClass( f.or[o].id, has ? "verified" : "incorrect" );
			if ( !has ) {
				errors += f.msg;
				ok = false;
			}
			else {
				if ( hase ) {
					for ( var e = 0; e < f.either.length; e++ )
						setElementClass( f.either[e].id, validateField(f.either[e]) ? "verified" : "incorrect" );
				}
				if ( haso ) {
					for ( var o = 0; o < f.or.length; o++ )
						setElementClass( f.or[o].id, validateField(f.or[o]) ? "verified" : "incorrect" );
				}
			}
		}
		else {
			if ( f.reqd ) {
				validateField( f );
			}
			if ( f.confirm ) {
				confirm.push( {a:f.id, b:f.confirm, l:f.label} );
			}
			setElementClass( f.id, ok ? "verified" : "incorrect" );
		}
	}
	
	if ( missing )
		errors += "Some required fields are empty. ";
	
	for ( var n = 0; n < confirm.length; n++ ) {
		var c= confirm[ n ];
		if ( form[c.a] && form[c.b] && form[c.a].value.length > 0 && form[c.a].value != form[c.b].value ) {
			setElementClass( c.a, "incorrect" );
			setElementClass( c.b, "incorrect" );
			errors += ( "Your " + c.l + " and " + c.l + " confirmation don't match. " );
		}
	}
	if ( errors.length > 0 ) {
		errors += "Please correct this and try again.";
		alert( errors );
	}
	else
		return true;
			
	return false;
}


function loaded() {
	var fe = new FlashEmbed( web_path + "images/bannerimages.swf", 7, "620", "157", "#ffffff", "suffernbanner" );
	fe.create( 'show' );
	
	var adspot = document.getElementById( "adspot" );
	if ( adspot ) {
		fe = new FlashEmbed( web_path + "ads.swf?svroot=" + web_path + "servlet/", 7, "300", "70", "#ffffff", "suffernads" );
		fe.create( 'adspot' );
	}
	
	MM_preloadImages( web_path + 'images/home_over.jpg', web_path + 'images/map_over.jpg',
			web_path + 'images/history_over.jpg', web_path + 'images/points_over.jpg',
			web_path + 'images/shopdine_over.jpg', web_path + 'images/contact_over.jpg',
			web_path + 'images/bullbutt_over.jpg', web_path + 'images/mailbutt_over.jpg' );
}

window.onload = loaded;
