/**
 *ajaxContent - jQuery plugin for accessible, unobtrusive and easy ajax behaviour.
 * @Version 2.1 Beta
 * 
 * @requires jQuery v 1.2+
 * 
 * http://www.andreacfm.com/index.cfm/jquery-plugins
 *
 * Copyright (c) 2007 Andrea Campolonghi (andreacfm.com)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 */
  //make $ surely available inside the PI as jQuery shortcut
(function($) {
	//call teh method with options arguments
	$.fn.ajaxContent = function(options) {
		//extend to defaults
		var defaults = $.extend({}, $.fn.ajaxContent.defaults, options);
			// debug if required		
			if(defaults.debug == 'true'){
				debug(this);
			};
			//Initilaize any instance looping on the match element
			return this.each(function(){
				//set local variables and extend to the metadata plugin if loaded
				var $obj = $(this);
				var href = $obj.attr('href');
				var o = $.metadata ? $.extend({}, defaults, $obj.metadata()) : defaults;
				// add binding change events on url if required
				if(o.bind != ''){
					var binds = o.bind.split(',');
					for(var i=0; i < binds.length ; i++){
						var queryString = setQueryString(binds);
						var url = href + queryString;
						$obj.attr({href:url});
						if ($(binds[i]).attr('type') == "radio" || $(binds[i]).attr('type') == "checkbox"){
							$('input[name=' + $(binds[i]).attr("name") + ']').change(function(){
								var queryString = setQueryString(binds);
								var url = href + queryString;
								$obj.attr({href:url});						
							});
							}else{
							$(binds[i]).change(function(){
								var queryString = setQueryString(binds);
								var url = href + queryString;
								$obj.attr({href:url});						
							});
						}							
					}
				}
				var $target = $(o.target);

			//bind the event
			$obj.bind(o.event, function(){
				// add loader if required
				if(o.loader == 'true'){
					if(o.loaderType == 'img'){
 							$target.html('<img src="' + o.loadingMsg + '"/>');
 						}else{
							 $target.html(o.loadingMsg);
 							}
 					} 
					//remove add current class
					$('a.' + o.currentClass).removeClass(o.currentClass);								
					$obj.addClass(o.currentClass);
					// make the call
					$.ajax({ 
  						type: o.type, 
  						url: $obj.attr('href'),
  						cache:'false',
  						beforeSend:function(){
  							if(typeof o.beforeSend == 'function'){
  								o.beforeSend($obj,$target);
  								}
  						},
  						success: function(msg){ 
    						$target.html(msg);
    						if(o.extend == 'true'){
    							$(o.filter,$target).ajaxContent({
    								target:o.ex_target,
									type:o.ex_type,
									event:o.ex_event,
									loader:o.ex_loader,
									loaderType:o.ex_loaderType,
									loadingMsg:o.ex_loadingMsg,
									errorMsg:o.ex_errorMsg,
									currentClass:o.ex_currentClass,
									success:o.ex_success,
									beforeSend:o.ex_beforeSend,
									error:o.ex_error,
									bind:o.ex_bind
    							});
    						}
    						//if a callback exist pass arguments ( object,target and receive message)
    						if(typeof o.success == 'function'){
    							o.success($obj,$target,msg);
    							}  						
    						},
						error: function(){
							$target.html("<p>" + o.errorMsg + "</p>");
							if(typeof o.error == 'function'){
    							o.error($target);
    							}  						
    					 
						}
					});
				return false;
			});
		});
	};	
  	function debug($obj) {
    if (window.console && window.console.log)
     window.console.log('selection count: ' + $obj.size() + '  with class:' + $obj.attr('class'));
  	};
  	function setQueryString(binds){
  		var queryString = '?';
  		for(var i=0; i < binds.length; i++){
  			if ($(binds[i]).attr('type') == "radio"){
				queryString += $('input[name=' + $(binds[i]).attr("name") + ']').fieldSerialize();
  			}else if($(binds[i]).attr('type') == "checkbox"){
  				queryString += $(binds[i]).attr("name") + '=' + $('input[name=' + $(binds[i]).attr("name") + ']').fieldValue();
  			}
  			else{
  				queryString += $(binds[i]).fieldSerialize();	
  			}	
  			if(i != binds.length - 1){
  				queryString += '&';
  			}
  		}
	return queryString;
  	};
})(jQuery);

$.fn.ajaxContent.defaults = {
		target: '#ajaxContent',
		type:'get',
		event:'click',
		loader:'true',
		loaderType:'text',
		loadingMsg:'Loading...',
		errorMsg:'An error occured during the page requesting process!',
		currentClass:'selected',
		success:'',
		beforeSend:'',
		error:'',
		bind:'',
		debug:'false',
		extend:'false',
		filter:'',
		ex_target:'',
		ex_type:'get',
		ex_event:'click',
		ex_loader:'true',
		ex_loaderType:'text',
		ex_loadingMsg:'Loading...',
		ex_errorMsg:'An error occured during the page requesting process!',
		ex_currentClass:'selected',
		ex_success:'',
		ex_beforeSend:'',
		ex_error:'',
		ex_bind:''
};

/*
 * jQuery jclock - Clock plugin - v 0.2.0
 * http://plugins.jquery.com/project/jclock
 *
 * Copyright (c) 2007-2008 Doug Sparling <http://www.dougsparling.com>
 * Licensed under the MIT License:
 *   http://www.opensource.org/licenses/mit-license.php
 */
(function($) {
  $.fn.jclock = function(options) {
    $.fn.jclock.timerID = null;
    $.fn.jclock.running = false;
    $.fn.jclock.el = null;
    var version = '0.2.0';

    // options
    var opts = $.extend({}, $.fn.jclock.defaults, options);
         
    return this.each(function() {
      $this = $(this);
      $.fn.jclock.el = $this;

      var o = $.meta ? $.extend({}, opts, $this.data()) : opts;

      $.fn.jclock.timeNotation = o.timeNotation;
      $.fn.jclock.am_pm = o.am_pm;
      $.fn.jclock.utc = o.utc;
      $.fn.jclock.utc_offset = o.utc_offset;

      $this.css({
        fontFamily: o.fontFamily,
        fontSize: o.fontSize,
        backgroundColor: o.background,
        color: o.foreground
      });

      $.fn.jclock.startClock();

    });
  };
       
  $.fn.jclock.startClock = function() {
    $.fn.jclock.stopClock();
    $.fn.jclock.displayTime();
  }
  $.fn.jclock.stopClock = function() {
    if($.fn.jclock.running) {
      clearTimeout(timerID);
    }
    $.fn.jclock.running = false;
  }
  $.fn.jclock.displayTime = function(el) {
    var time = $.fn.jclock.getTime();
    $.fn.jclock.el.html(time);
    timerID = setTimeout("$.fn.jclock.displayTime()",1000);
  }
  $.fn.jclock.getTime = function() {
    var now = new Date();
    var hours, minutes, seconds;

    if($.fn.jclock.utc == true) {
      if($.fn.jclock.utc_offset != 0) {
        now.setUTCHours(now.getUTCHours()+$.fn.jclock.utc_offset);
      }
      hours = now.getUTCHours();
      minutes = now.getUTCMinutes();
      seconds = now.getUTCSeconds();
    } else {
      hours = now.getHours();
      minutes = now.getMinutes();
      seconds = now.getSeconds();
    }

    var am_pm_text = '';
    (hours >= 12) ? am_pm_text = " PM" : am_pm_text = " AM";

    if ($.fn.jclock.timeNotation == '12h') {
      hours = ((hours > 12) ? hours - 12 : hours);
    } else {
      hours   = ((hours <  10) ? "0" : "") + hours;
    }

    minutes = ((minutes <  10) ? "0" : "") + minutes;
    seconds = ((seconds <  10) ? "0" : "") + seconds;

    var timeNow = hours + ":" + minutes + ":" + seconds;
    if ( ($.fn.jclock.timeNotation == '12h') && ($.fn.jclock.am_pm == true) ) {
     timeNow += am_pm_text;
    }

    return timeNow;
  };
       
  // plugin defaults
  $.fn.jclock.defaults = {
    timeNotation: '12h',
    am_pm: true,
    utc: false,
    fontFamily: '',
    fontSize: '',
    foreground: '',
    background: '',
    utc_offset: 0
  };
})(jQuery);

/**
 * jCarouselLite - jQuery plugin to navigate images/any content in a carousel style widget.
 * @requires jQuery v1.2 or above
 *
 * http://gmarwaha.com/jquery/jcarousellite/
 *
 * Copyright (c) 2007 Ganeshji Marwaha (gmarwaha.com)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 * Version: 1.0.1
 * Note: Requires jquery 1.2 or above from version 1.0.1
 */


eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(6($){$.1g.1w=6(o){o=$.1f({r:n,x:n,N:n,17:q,J:n,L:1a,16:n,y:q,u:12,H:3,B:0,k:1,K:n,I:n},o||{});8 G.R(6(){p b=q,A=o.y?"15":"w",P=o.y?"t":"s";p c=$(G),9=$("9",c),E=$("10",9),W=E.Y(),v=o.H;7(o.u){9.1h(E.D(W-v-1+1).V()).1d(E.D(0,v).V());o.B+=v}p f=$("10",9),l=f.Y(),4=o.B;c.5("1c","H");f.5({U:"T",1b:o.y?"S":"w"});9.5({19:"0",18:"0",Q:"13","1v-1s-1r":"S","z-14":"1"});c.5({U:"T",Q:"13","z-14":"2",w:"1q"});p g=o.y?t(f):s(f);p h=g*l;p j=g*v;f.5({s:f.s(),t:f.t()});9.5(P,h+"C").5(A,-(4*g));c.5(P,j+"C");7(o.r)$(o.r).O(6(){8 m(4-o.k)});7(o.x)$(o.x).O(6(){8 m(4+o.k)});7(o.N)$.R(o.N,6(i,a){$(a).O(6(){8 m(o.u?o.H+i:i)})});7(o.17&&c.11)c.11(6(e,d){8 d>0?m(4-o.k):m(4+o.k)});7(o.J)1p(6(){m(4+o.k)},o.J+o.L);6 M(){8 f.D(4).D(0,v)};6 m(a){7(!b){7(o.K)o.K.Z(G,M());7(o.u){7(a<=o.B-v-1){9.5(A,-((l-(v*2))*g)+"C");4=a==o.B-v-1?l-(v*2)-1:l-(v*2)-o.k}F 7(a>=l-v+1){9.5(A,-((v)*g)+"C");4=a==l-v+1?v+1:v+o.k}F 4=a}F{7(a<0||a>l-v)8;F 4=a}b=12;9.1o(A=="w"?{w:-(4*g)}:{15:-(4*g)},o.L,o.16,6(){7(o.I)o.I.Z(G,M());b=q});7(!o.u){$(o.r+","+o.x).1n("X");$((4-o.k<0&&o.r)||(4+o.k>l-v&&o.x)||[]).1m("X")}}8 q}})};6 5(a,b){8 1l($.5(a[0],b))||0};6 s(a){8 a[0].1k+5(a,\'1j\')+5(a,\'1i\')};6 t(a){8 a[0].1t+5(a,\'1u\')+5(a,\'1e\')}})(1x);',62,96,'||||curr|css|function|if|return|ul|||||||||||scroll|itemLength|go|null||var|false|btnPrev|width|height|circular||left|btnNext|vertical||animCss|start|px|slice|tLi|else|this|visible|afterEnd|auto|beforeStart|speed|vis|btnGo|click|sizeCss|position|each|none|hidden|overflow|clone|tl|disabled|size|call|li|mousewheel|true|relative|index|top|easing|mouseWheel|padding|margin|200|float|visibility|append|marginBottom|extend|fn|prepend|marginRight|marginLeft|offsetWidth|parseInt|addClass|removeClass|animate|setInterval|0px|type|style|offsetHeight|marginTop|list|jCarouselLite|jQuery'.split('|'),0,{}))


/**
*GreenbrierWV Specific Jquery JS
*/


$(document).ready(function() {
	    //Hide any neccessary divs
		$('#eNewsInterests,#photoInfo').hide();
		
		//Slide down eNews interests
		$('#eNewsEmail').one('focus',function() {
		$('div#eNewsInterests').slideDown('slow');
		});
		
		//Shrink/Enlarge photo area at the top
		$('span#expandPhoto').toggle(function(){
    	$('#headerPhotos').animate({height: 180}, 'slow');
		$('span#expandPhoto').addClass('expandPhotoActive');
  		},function(){
		$('#headerPhotos').animate({height: 280}, 'slow');
		$('span#expandPhoto').removeClass('expandPhotoActive');
		});
		
		//Show/Hide Map
		$('li.headlineLink a.headlineHideMap').toggle(function(){
		$('li.headlineLink a.headlineHideMap').text('Show Map');
		$('div#eseMap').slideUp('slow');
		$('li.headlineLink a.headlineHideMap').addClass('headlineShowMap');
		return false;
		},function(){
		$('li.headlineLink a.headlineHideMap').text('Hide Map');
		$('div#eseMap').slideDown('slow');
		$('li.headlineLink a.headlineHideMap').removeClass('headlineShowMap');
		return false;
		});
    	
  		
		//Display photo captions
		$('span#showPhotoInfo').click(function() {
    	$('div#photoInfo').toggle(400);
		$('span#showPhotoInfo').toggleClass('showPhotoInfoActive');
    	return false;
  		});
		
		//Display My GBC Story Form
		$('#gbcStory').hide();
		$('a.headlineStory').click(function() {
    	$('div#gbcStory').slideToggle(400);
    	return false;
  		});
		
		
		//Table hovers for Eat, Sleep, Explore results
		//$('#eseResults tr').css("cursor","pointer");
		$("#eseResults tbody tr").mouseover(function() {$(this).addClass("eseOver");}).mouseout(function() {$(this).removeClass("eseOver");});
		
		//Table stripe rows weather, and driving distances
		$("#weatherAvg tr:odd").addClass("weatherAvgOdd");
		$("#weatherAvg tbody tr").mouseover(function() {$(this).addClass("weatherAvgOver");}).mouseout(function() {$(this).removeClass("weatherAvgOver");})
		
		$("#distances tr:odd").addClass("distancesOdd");
		$("#distances tbody tr").mouseover(function() {$(this).addClass("distancesOver");}).mouseout(function() {$(this).removeClass("distancesOver");});
		
		//$('#eseResults tr').click(function(){
		//$(this).fadeTo("slow", 0.3);
		//var href= $(this).find('a').attr('href');
		//window.location= (href);
		//return false;
        //});
		
		$("#eventResults tbody tr").mouseover(function() {$(this).addClass("eseOver");}).mouseout(function() {$(this).removeClass("eseOver");});
		
		//Current time
		var optionsEST = {
		timeNotation: '12h',
        utc: true,
        utc_offset: -4
        }
        $('#currentTime').jclock(optionsEST);
		
	    //Ajax refreshes on the homepage
		$('.todoRefresh').ajaxContent({
		loaderType:'img',
		loadingMsg:'images/site/loading.gif',
		target:'#todoWrapper'
		});
		
	    //Ajax the press photos section and jcarousel
		$('.pPhoto').ajaxContent({
		loaderType:'img',
		loadingMsg:'/images/site/loading.gif',
		currentClass:'pPhotoCurrent',
		target:'#pPhotosDetail'
		});
		
		$(".pPhotosCarousel").jCarouselLite({
        btnNext: "#pPhotosNext",
        btnPrev: "#pPhotosPrev",
		visible: 7,
		circular: false
   		 });
  
		//Valid way to open links in new window
		$("a[@rel='external']").click(function(){window.open(this.href); return false;});
});

/**
 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16[_16.length]=key+"="+_18[key];}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){var axo=1;var _26=3;while(axo){try{_26++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+_26);_23=new deconcept.PlayerVersion([_26,0,0]);}catch(e){axo=null;}}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}}return _23;};deconcept.PlayerVersion=function(_29){this.major=_29[0]!=null?parseInt(_29[0]):0;this.minor=_29[1]!=null?parseInt(_29[1]):0;this.rev=_29[2]!=null?parseInt(_29[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_2b){var q=document.location.search||document.location.hash;if(_2b==null){return q;}if(q){var _2d=q.substring(1).split("&");for(var i=0;i<_2d.length;i++){if(_2d[i].substring(0,_2d[i].indexOf("="))==_2b){return _2d[i].substring((_2d[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2f=document.getElementsByTagName("OBJECT");for(var i=_2f.length-1;i>=0;i--){_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}}if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;

// Validation...
if(typeof rsv=='undefined')
  rsv={};
rsv.displayType="alert-all";
rsv.styleOffendingFields=true;
rsv.offendingFieldStyle="background-color: #F2F9FF";
rsv.errorTextIntro="Please fix the following error(s) and resubmit:";
rsv.errorJSItemBullet="* ";
rsv.errorHTMLItemBullet="&bull; ";
rsv.errorTargetElementId="rsvErrors";
rsv.customErrorHandler=null;
rsv.onCompleteHandler=null;

rsv.validate=function(form,rules)
{rsv.returnHash=[];for(var i=0;i<rules.length;i++)
{var row=rules[i].replace(/\\,/ig,"%%C%%");row=row.split(",");var satisfiesIfConditions=true;while(row[0].match("^if:"))
{var cond=row[0];cond=cond.replace("if:","");var comparison="equal";var parts=[];if(cond.search("!=")!=-1)
{parts=cond.split("!=");comparison="not_equal";}
else
parts=cond.split("=");var fieldToCheck=parts[0];var valueToCheck=parts[1];var fieldnameValue="";if(form[fieldToCheck].type==undefined)
{for(var j=0;j<form[fieldToCheck].length;j++)
{if(form[fieldToCheck][j].checked)
fieldnameValue=form[fieldToCheck][j].value;}}
else if(form[fieldToCheck].type=="checkbox")
{if(form[fieldToCheck].checked)
fieldnameValue=form[parts[0]].value;}
else
fieldnameValue=form[parts[0]].value;if(comparison=="equal"&&fieldnameValue!=valueToCheck)
{satisfiesIfConditions=false;break;}
else if(comparison=="not_equal"&&fieldnameValue==valueToCheck)
{satisfiesIfConditions=false;break;}
else
row.shift();}
if(!satisfiesIfConditions)
continue;var requirement=row[0];var fieldName=row[1];var fieldName2,fieldName3,errorMessage,lengthRequirements,date_flag;if(row.length==6)
{fieldName2=row[2];fieldName3=row[3];date_flag=row[4];errorMessage=row[5];}
else if(row.length==5)
{fieldName2=row[2];fieldName3=row[3];errorMessage=row[4];}
else if(row.length==4)
{fieldName2=row[2];errorMessage=row[3];}
else
errorMessage=row[2];if(requirement.match("^length"))
{lengthRequirements=requirement;requirement="length";}
if(requirement.match("^range"))
{rangeRequirements=requirement;requirement="range";}
switch(requirement)
{case"required":if(form[fieldName].type==undefined)
{var oneIsChecked=false;for(var j=0;j<form[fieldName].length;j++)
{if(form[fieldName][j].checked)
oneIsChecked=true;}
if(!oneIsChecked)
{if(!rsv.processError(form[fieldName],errorMessage))
return false;}}
else if(form[fieldName].type=="select-multiple")
{var oneIsSelected=false;for(var k=0;k<form[fieldName].length;k++)
{if(form[fieldName][k].selected)
oneIsSelected=true;}
if(!oneIsSelected||form[fieldName].length==0)
{if(!rsv.processError(form[fieldName],errorMessage))
return false;}}
else if(form[fieldName].type=="checkbox")
{if(!form[fieldName].checked)
{if(!rsv.processError(form[fieldName],errorMessage))
return false;}}
else if(!form[fieldName].value)
{if(!rsv.processError(form[fieldName],errorMessage))
return false;}
break;case"digits_only":if(form[fieldName].value&&form[fieldName].value.match(/\D/))
{if(!rsv.processError(form[fieldName],errorMessage))
return false;}
break;case"letters_only":if(form[fieldName].value&&form[fieldName].value.match(/[^a-zA-Z]/))
{if(!rsv.processError(form[fieldName],errorMessage))
return false;}
break;case"is_alpha":if(form[fieldName].value&&form[fieldName].value.match(/\W/))
{if(!rsv.processError(form[fieldName],errorMessage))
return false;}
break;case"custom_alpha":var conversion={"L":"[A-Z]","V":"[AEIOU]","l":"[a-z]","v":"[aeiou]","D":"[a-zA-Z]","F":"[aeiouAEIOU]","C":"[BCDFGHJKLMNPQRSTVWXYZ]","x":"[0-9]","c":"[bcdfghjklmnpqrstvwxyz]","X":"[1-9]","E":"[bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ]"};var reg_exp_str="";for(var j=0;j<fieldName2.length;j++)
{if(conversion[fieldName2.charAt(j)])
reg_exp_str+=conversion[fieldName2.charAt(j)];else
reg_exp_str+=fieldName2.charAt(j);}
var reg_exp=new RegExp(reg_exp_str);if(form[fieldName].value&&reg_exp.exec(form[fieldName].value)==null)
{if(!rsv.processError(form[fieldName],errorMessage))
return false;}
break;case"reg_exp":var reg_exp_str=fieldName2;if(row.length==5)
var reg_exp=new RegExp(reg_exp_str,fieldName3);else
var reg_exp=new RegExp(reg_exp_str);if(form[fieldName].value&&reg_exp.exec(form[fieldName].value)==null)
{if(!rsv.processError(form[fieldName],errorMessage))
return false;}
break;case"length":comparison_rule="";rule_string="";if(lengthRequirements.match(/length=/))
{comparison_rule="equal";rule_string=lengthRequirements.replace("length=","");}
else if(lengthRequirements.match(/length>=/))
{comparison_rule="greater_than_or_equal";rule_string=lengthRequirements.replace("length>=","");}
else if(lengthRequirements.match(/length>/))
{comparison_rule="greater_than";rule_string=lengthRequirements.replace("length>","");}
else if(lengthRequirements.match(/length<=/))
{comparison_rule="less_than_or_equal";rule_string=lengthRequirements.replace("length<=","");}
else if(lengthRequirements.match(/length</))
{comparison_rule="less_than";rule_string=lengthRequirements.replace("length<","");}
switch(comparison_rule)
{case"greater_than_or_equal":if(!(form[fieldName].value.length>=parseInt(rule_string)))
{if(!rsv.processError(form[fieldName],errorMessage))
return false;}
break;case"greater_than":if(!(form[fieldName].value.length>parseInt(rule_string)))
{if(!rsv.processError(form[fieldName],errorMessage))
return false;}
break;case"less_than_or_equal":if(!(form[fieldName].value.length<=parseInt(rule_string)))
{if(!rsv.processError(form[fieldName],errorMessage))
return false;}
break;case"less_than":if(!(form[fieldName].value.length<parseInt(rule_string)))
{if(!rsv.processError(form[fieldName],errorMessage))
return false;}
break;case"equal":var range_or_exact_number=rule_string.match(/[^_]+/);var fieldCount=range_or_exact_number[0].split("-");if(fieldCount.length==2)
{if(form[fieldName].value.length<fieldCount[0]||form[fieldName].value.length>fieldCount[1])
{if(!rsv.processError(form[fieldName],errorMessage))
return false;}}
else
{if(form[fieldName].value.length!=fieldCount[0])
{if(!rsv.processError(form[fieldName],errorMessage))
return false;}}
break;}
break;case"valid_email":if(form[fieldName].value&&!rsv.isValidEmail(form[fieldName].value))
{if(!rsv.processError(form[fieldName],errorMessage))
return false;}
break;case"valid_date":var isLaterDate=false;if(date_flag=="later_date")
isLaterDate=true;else if(date_flag=="any_date")
isLaterDate=false;if(!rsv.isValidDate(form[fieldName].value,form[fieldName2].value,form[fieldName3].value,isLaterDate))
{if(!rsv.processError(form[fieldName],errorMessage))
return false;}
break;case"same_as":if(form[fieldName].value!=form[fieldName2].value)
{if(!rsv.processError(form[fieldName],errorMessage))
return false;}
break;case"range":comparison_rule="";rule_string="";if(rangeRequirements.match(/range=/))
{comparison_rule="equal";rule_string=rangeRequirements.replace("range=","");}
else if(rangeRequirements.match(/range>=/))
{comparison_rule="greater_than_or_equal";rule_string=rangeRequirements.replace("range>=","");}
else if(rangeRequirements.match(/range>/))
{comparison_rule="greater_than";rule_string=rangeRequirements.replace("range>","");}
else if(rangeRequirements.match(/range<=/))
{comparison_rule="less_than_or_equal";rule_string=rangeRequirements.replace("range<=","");}
else if(rangeRequirements.match(/range</))
{comparison_rule="less_than";rule_string=rangeRequirements.replace("range<","");}
switch(comparison_rule)
{case"greater_than_or_equal":if(!(form[fieldName].value>=Number(rule_string)))
{if(!rsv.processError(form[fieldName],errorMessage))
return false;}
break;case"greater_than":if(!(form[fieldName].value>Number(rule_string)))
{if(!rsv.processError(form[fieldName],errorMessage))
return false;}
break;case"less_than_or_equal":if(!(form[fieldName].value<=Number(rule_string)))
{if(!rsv.processError(form[fieldName],errorMessage))
return false;}
break;case"less_than":if(!(form[fieldName].value<Number(rule_string)))
{if(!rsv.processError(form[fieldName],errorMessage))
return false;}
break;case"equal":var rangeValues=rule_string.split("-");if((form[fieldName].value<Number(rangeValues[0]))||(form[fieldName].value>Number(rangeValues[1])))
{if(!rsv.processError(form[fieldName],errorMessage))
return false;}
break;}
break;case"function":custom_function=fieldName;eval("var result = "+custom_function+"()");if(result.constructor.toString().indexOf("Array")!=-1)
{for(var j=0;j<result.length;j++)
{if(!rsv.processError(result[j][0],result[j][1]))
return false;}}
break;default:alert("Unknown requirement flag in validateFields(): "+requirement);return false;}}
if(typeof rsv.customErrorHandler=='function')
return rsv.customErrorHandler(form,rsv.returnHash);else if(rsv.displayType=="alert-all")
{var errorStr=rsv.errorTextIntro+"\n\n";for(var i=0;i<rsv.returnHash.length;i++)
{errorStr+=rsv.errorJSItemBullet+rsv.returnHash[i][1]+"\n";if(rsv.styleOffendingFields)
rsv.styleField(rsv.returnHash[i][0],i==0);}
if(rsv.returnHash.length>0)
{alert(errorStr);return false;}}
else if(rsv.displayType=="display-html")
{var success=rsv.displayHTMLErrors(form,rsv.returnHash);if(!success)
return false;}
if(typeof rsv.onCompleteHandler=='function')
return rsv.onCompleteHandler();else
return true;}
rsv.processError=function(obj,message)
{message=message.replace(/%%C%%/ig,",");var continueProcessing=true;switch(rsv.displayType)
{case"alert-one":alert(message);rsv.styleField(obj,true);continueProcessing=false;break;case"alert-all":case"display-html":rsv.returnHash.push([obj,message]);break;}
return continueProcessing;}
rsv.displayHTMLErrors=function(f,errorInfo)
{var errorHTML=rsv.errorTextIntro+"<br /><br />";for(var i=0;i<errorInfo.length;i++)
{errorHTML+=rsv.errorHTMLItemBullet+errorInfo[i][1]+"<br />";if(rsv.styleOffendingFields)
rsv.styleField(errorInfo[i][0],i==0);}
if(errorInfo.length>0)
{document.getElementById(rsv.errorTargetElementId).style.display="block";document.getElementById(rsv.errorTargetElementId).innerHTML=errorHTML;return false;}
return true;}
rsv.styleField=function(obj,focus)
{if(obj.type==undefined)
{if(focus)
obj[0].focus();}
else
{if(rsv.styleOffendingFields)
obj.style.cssText=rsv.offendingFieldStyle;if(focus)
obj.focus();}}
rsv.isValidEmail=function(str)
{var str2=str.replace(/^\s*/,"");var s=str2.replace(/\s*$/,"");var at="@";var dot=".";var lat=s.indexOf(at);var lstr=s.length;var ldot=s.indexOf(dot);if(s.indexOf(at)==-1||(s.indexOf(at)==-1||s.indexOf(at)==0||s.indexOf(at)==lstr)||(s.indexOf(dot)==-1||s.indexOf(dot)==0||s.indexOf(dot)==lstr)||(s.indexOf(at,(lat+1))!=-1)||(s.substring(lat-1,lat)==dot||s.substring(lat+1,lat+2)==dot)||(s.indexOf(dot,(lat+2))==-1)||(s.indexOf(" ")!=-1))
{return false;}
return true;}
rsv.isWhitespace=function(s)
{var whitespaceChars=" \t\n\r\f";if((s==null)||(s.length==0))
return true;for(var i=0;i<s.length;i++)
{var c=s.charAt(i);if(whitespaceChars.indexOf(c)==-1)
return false;}
return true;}
rsv.isValidDate=function(month,day,year,isLaterDate)
{var daysInMonth;if(year%4==0)
daysInMonth=[31,29,31,30,31,30,31,31,30,31,30,31];else
daysInMonth=[31,28,31,30,31,30,31,31,30,31,30,31];if(!month||!day||!year)return false;if(1>month||month>12)return false;if(year<0)return false;if(1>day||day>daysInMonth[month-1])return false;if(isLaterDate)
{var today=new Date();var currMonth=today.getMonth()+1;var currDay=today.getDate();var currYear=today.getFullYear();if(String(currMonth).length==1)currMonth="0"+currMonth;if(String(currDay).length==1)currDay="0"+currDay;var currDate=String(currYear)+String(currMonth)+String(currDay);if(String(month).length==1)month="0"+month;if(String(day).length==1)day="0"+day;incomingDate=String(year)+String(month)+String(day);if(Number(currDate)>Number(incomingDate))
return false;}
return true;}