


function VolunteerYourTime ( element )
{
	ria_Component.call( this , element );
	ria.createComponents();
	
	/*if ( ria.bool( this.jsdata.showPhotos ) ) {
		var cmd = new vytphotoadmin_cmd_LoadHomeImages();
		cmd.execute( {} , this );
	}
	if ( ria.bool( this.jsdata.showSpotlight ) ) {
		var cmd = new vytspotlightadmin_cmd_LoadSpotlights();
		cmd.execute( {} , this );		
	}*/
	if ( ria.bool( this.jsdata.showHome ) ) {
		var cmd = new vythomeadmin_cmd_LoadHome();
		cmd.execute( {} , this );		
	}
	
}

VolunteerYourTime.prototype = new ria_Component();
VolunteerYourTime.prototype.constructor = VolunteerYourTime;

VolunteerYourTime.prototype.homeLoaded = function( result )
{
	this.home_page_data = result;
	var tpl = new vytadmin_vythomeadmin_tpl_HomePage();
	ria.log( tpl );
	this.$("#home").html( tpl.parse({data:this.home_page_data,showEdit:false}) );	
}

VolunteerYourTime.prototype.homeDidntLoad = function()
{
	ria.log('oops');
}

/*VolunteerYourTime.prototype.imagesLoaded = function( response )
{
	this.images = response.images;	
	var image = Math.round( Math.random() * (this.images.length-1) );
	var caption;
	if ( ria.isNull( this.images[image].caption ) ) {
		caption = "";
	}else{
		caption = this.images[image].caption;
	}
	
	this.$('#photos').html("<img src='/files/images/" + this.images[image].full + "' /><div class='caption'>" + caption + "</div>");
}

VolunteerYourTime.prototype.spotlightsLoaded = function( response )
{
	this.spotlights = response.spotlights;
	
	var tpl = new vyt_tpl_spotlights();
	this.$("#spotlights").html( tpl.parse( {spotlights:this.spotlights} ) );
	
	this.$("#edit_spotlight").hide();
}*/

VolunteerYourTime.prototype.onClick = function( action , value , event )
{
	switch ( action ) {		
		case "lead_search" :
			alert("HISDF");
			break;
	}
}

VolunteerYourTime.prototype.onBounce = function( action , value , event )
{
	switch ( action ) {
		case "a" :
			break;
	}
}

function VYTSearch_VYTSearch ( element )
{
	ria_Component.call( this , element );
	
	var tpl = new vyt_vytsearch_tpl_VYTSearch();
	this.element.html(tpl.parse(this));
	
	this.url_root = this.jsdata.url_root;
	
	this.open_modal = ( ria.isNull( this.jsdata.open_modal ) ) ? true : ria.bool( this.jsdata.open_modal);
	
	GlobalEventManager.addEventListener("components_initialized" , this.init , this );
	
	//ria.log( $.cookie('selected_tab') );
	var urlvar = $.getUrlVar("tab_state");
	if ( !ria.isNull( urlvar ) ) {
		$.cookie('selected_tab', decodeURIComponent( urlvar ) , {expires: 7, path: '/'} );
	}	
	//ria.log( $.cookie('selected_tab') );
	
	this.element.css("visibility","hidden");
	
	//start widget tracking
	 var g = window._gaq || (window._gaq = []);

	 g.push(['_setAccount', 'UA-26321004-2']);
	 g.push(['_setDomainName', document.domain ]);
	 g.push(['_setAllowLinker', true]);
	 g.push(['_trackPageview']);
	
	 (function() {
	    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
	 })();

	 this.radio_clicked = 0;
	 this.tab_title = "";
}

VYTSearch_VYTSearch.prototype = new ria_Component();
VYTSearch_VYTSearch.prototype.constructor = VYTSearch_VYTSearch;

VYTSearch_VYTSearch.prototype.animate = true;

VYTSearch_VYTSearch.prototype.init = function()
{
	var cmd = new vyt_vytsearch_cmd_LoadTree();
	cmd.execute( {url_root:this.url_root} , this );
	
	GlobalEventManager.removeEventListener("components_initialized" , this );
}

VYTSearch_VYTSearch.prototype.treeLoaded = function( tree )
{
	this.decision_tree = tree;
	this._createIds( tree );
	this.volunteer_tree = tree;
	
	
	switch ( $.cookie('selected_tab') ) {
		case "agencies_search" :
			this.switchToAgencies();
			break;
		case "lead_search" :
			this.switchToLead();
			break;
		case "gift_search" :
			this.switchToGift();
			break;
		case "volunteer_search" :
		default:
			this.switchToVolunteer();
			break;
	}
	
	this.element.css("visibility","visible");
	
	//this.switchToAgencies();
}
	VYTSearch_VYTSearch.prototype._createIds = function( tree , idPrefix )
	{
		if ( ria.isNull( idPrefix ) )
			idPrefix = "c";
		
		for ( var i=0; i<tree.length; i++ ) {
			var element = tree[i];
			element.id = idPrefix + "_" + i;
			if ( !ria.isNull(element.children) && element.children.length > 0 )
			{
				this._createIds( element.children , element.id );
			}
		}
	}

	
VYTSearch_VYTSearch.prototype.trackEvent = function( label )
{
	var g = window._gaq || (window._gaq = []);
	g.push(['_setAccount', 'UA-26321004-2']);
	g.push(['_setDomainName', document.domain ]);
	g.push(['_setAllowLinker', true]);
	//g.push(['_trackEvent', 'widget' , this._state , label ]);
	g.push(['_trackEvent', this._state , this._state +"||"+ label ]);
}
	
VYTSearch_VYTSearch.prototype.allow_multiple_leaves = true;
VYTSearch_VYTSearch.prototype._state;
VYTSearch_VYTSearch.prototype.onClick = function( action , value , event )
{
	switch ( action ) {		
		case "volunteer_search" :
			ria.end( event );
			this.switchToVolunteer();
			this.trackEvent('tab selected');
			break;
		case "lead_search" :
			ria.end( event );
			this.switchToLead();
			this.trackEvent('tab selected');
			break;
		case "gift_search" :
			ria.end( event );
			this.switchToGift();
			this.trackEvent('tab selected');
			break;
		case "agencies_search" :
			ria.end( event );
			this.switchToAgencies();
			this.trackEvent('tab selected');
			break;
			
		case "choose" :
			ria.end( event );
			var choice = this.selectDecision( value );
			if ( this._state == "gift_search" || this._state == "lead_search" ) {
				if ( choice.selected ) {
					this.$(".more_info").hide();
				}else{
					this.$(".more_info").show();
				}
			}
			if ( choice.selected ) {
				this.trackEvent(choice.data +" - selected");
			}else{
				this.trackEvent(choice.data +" - deselected");
			}
			
			this.displayChoices();			
			break;
		case "checkbox_choose" :
			var values = ria.getAssocFormData( this.$('#checkbox_form') );
			var valuesArray = [];
			for ( var i in values ) {
				valuesArray.push( i );
			}

			var selectedDecisionsTitles = this.selectDecisionChildren( value , valuesArray );
			//don't kill the checkbox selection
			//ria.end( event );

			//happens twice
			this.radio_clicked++;
			if ( this.radio_clicked >= 2) {
				this.trackEvent(selectedDecisionsTitles.join("|") );
				this.radio_clicked = 0;
			}
			break;
			
		case "cancel" :
			ria.end( event );			
			this.clearDecisionTree();		
			this.displayChoices();
			
			this.trackEvent('search canceled');
			
			if ( this._state == "gift_search" || this._state == "lead_search" ) {
				this.$(".more_info").show();
			}
			
			break;
		case "search" :
			this.trackEvent('search initiated');
			
			this.doSearch();
			ria.end( event );
			break;
		case "login_volunteer" :
			var formData = ria.getAssocFormData( this.$("#user_login") );
			this.trackEvent('volunteer login');
			
			this.$("#user_login_proxy #screen_name").val( formData['login_name'] );
			this.$("#user_login_proxy #password_from_form").val( formData['password'] );
			if ( !ria.isNull( formData['expire_state'] ) )
				this.$("#user_login_proxy #expire_state").val( formData['expire_state'] );
			this.$("#user_login_proxy").submit();
			break;	
		case "login_agency" :
			var formData = ria.getAssocFormData( this.$("#user_login") );
			this.trackEvent('agency login');
			
			this.$("#agency_login_proxy #agency_name").val( formData['login_name'] );
			this.$("#agency_login_proxy #password").val( formData['password'] );
			if ( !ria.isNull( formData['expire_state'] ) )
				this.$("#agency_login_proxy #expire_state").val( formData['expire_state'] );
			this.$("#agency_login_proxy").submit();
			break;		
	}
}

VYTSearch_VYTSearch.prototype.switchToVolunteer = function()
{
	this._state = "volunteer_search";
	this.clearDecisionTree();//clear old one...
	
	var tpl = new vyt_vytsearch_tpl_states_Volunteer();
	this.$('.search_form_container').html(tpl.parse({}));
	this.choiceflow = this.$('.choiceflow');
	this.choices_div = this.$('#choices');			
				
	this.$(".search_nav_item").removeClass("selected");			
	this.$(".search_nav_item.volunteer").addClass("selected");
	
	this.$('.search_nav').addClass("volunteer");
	this.$('.search_nav').removeClass("lead");
	this.$('.search_nav').removeClass("gift");
	this.$('.search_nav').removeClass("agencies");
	
	this.decision_tree = this.volunteer_tree;
	this.allow_multiple_leaves = true;
	
	this.animate = false;
	this.displayChoices();
	this.animate = true;
	
	$.cookie('selected_tab', 'volunteer_search', {expires: 7, path: '/'});
}
VYTSearch_VYTSearch.prototype.switchToLead = function()
{
	this._state = "lead_search";
	this.clearDecisionTree();//clear old one...
	
	var tpl = new vyt_vytsearch_tpl_states_Lead();			
	this.$('.search_form_container').html(tpl.parse({}));
	this.choiceflow = this.$('.choiceflow');
	this.choices_div = this.$('#choices');
	
	this.$(".search_nav_item").removeClass("selected");			
	this.$(".search_nav_item.lead").addClass("selected");
	
	this.$('.search_nav').removeClass("volunteer");
	this.$('.search_nav').addClass("lead");
	this.$('.search_nav').removeClass("gift");
	this.$('.search_nav').removeClass("agencies");
	
	this._createIds( this.lead_tree );

	this.decision_tree = this.lead_tree;
	this.allow_multiple_leaves = false;
	this.animate = false;
	this.displayChoices();
	this.animate = true;		
	
	$.cookie('selected_tab', 'lead_search', {expires: 7, path: '/'});
}
VYTSearch_VYTSearch.prototype.switchToGift = function()
{
	this._state = "gift_search";
	this.clearDecisionTree();//clear old one...
	
	var tpl = new vyt_vytsearch_tpl_states_Gift();			
	this.$('.search_form_container').html(tpl.parse({}));
	this.choiceflow = this.$('.choiceflow');
	this.choices_div = this.$('#choices');
	
	this.$(".search_nav_item").removeClass("selected");			
	this.$(".search_nav_item.gift").addClass("selected");
	
	this.$('.search_nav').removeClass("volunteer");
	this.$('.search_nav').removeClass("lead");
	this.$('.search_nav').addClass("gift");
	this.$('.search_nav').removeClass("agencies");

	this._createIds( this.gift_tree );

	this.decision_tree = this.gift_tree;
	this.allow_multiple_leaves = false;
	this.animate = false;
	this.displayChoices();
	this.animate = true;	
	
	$.cookie('selected_tab', 'gift_search', {expires: 7, path: '/'});
}
VYTSearch_VYTSearch.prototype.switchToAgencies = function()
{
	this._state = "agencies_search";
	
	this.clearDecisionTree();//clear old one...
	var tpl = new vyt_vytsearch_tpl_states_Agencies();			
	this.$('.search_form_container').html(tpl.parse({}));
	
	this.$(".search_nav_item").removeClass("selected");			
	this.$(".search_nav_item.agencies").addClass("selected");
	this.$('.search_nav').removeClass("volunteer");
	this.$('.search_nav').removeClass("lead");
	this.$('.search_nav').removeClass("gift");
	this.$('.search_nav').addClass("agencies");
	
	$.cookie('selected_tab', 'agencies_search', {expires: 7, path: '/'});
}

	VYTSearch_VYTSearch.prototype.clearDecisionTree = function()
	{
		for ( var i=0; i<this.decision_tree.length; i++ ) {
			var decision = this.decision_tree[i];
			decision.selected = false;
		}
	}

	VYTSearch_VYTSearch.prototype.selectDecisionChildren = function( decisionId , values , tree )
	{
		var decision = this.findDecision( decisionId , tree );
		var selectedDecisionsTitles = [];
		
		var children = decision.children;
		if ( ria.isNull( children ) ) {
			ria.output( "NO CHILDREN FOR " + decisionId , decision );
			return;			
		}
		for ( var i=0; i<children.length; i++ ) {
			var decision = children[ i ];	
			
			if ( $.inArray( decision.id , values ) != -1 ) {
				decision.selected = true;
				selectedDecisionsTitles.push( decision.data );
			}else{
				decision.selected = false;
			}
		}
		return selectedDecisionsTitles;
	}
	
	VYTSearch_VYTSearch.prototype.findDecision = function( decisionId , tree )
	{
		if ( ria.isNull( tree ) )
			tree = this.decision_tree;
		
		var decision = false;
		var focusedDec, childDecision;
		for ( var i=0; i<tree.length; i++ ) {
			var focusedDec = tree[ i ];	
			if ( !ria.isNull( focusedDec.id ) && focusedDec.id == decisionId ) {
				return focusedDec;
			}
			if ( !ria.isNull( focusedDec.children ) && focusedDec.children.length > 0 ) {
				childDecision = this.findDecision( decisionId , focusedDec.children );
				if ( childDecision !== false )
					return childDecision;
			} 
		}
		return decision;
	}

VYTSearch_VYTSearch.prototype.onSubmit = function( formid , event )
{
	switch ( formid ) {
		case "search_form" :
			this.doSearch();
			break;
			
		case "user_login" :
			var formData = ria.getAssocFormData(event.target);
			//http://volunteer.truist.com/uwdc/agency/login.aspx
			ria.log( event );
			
			/*var searchStr = [];
			for ( var i in formData ) {
				searchStr.push( i + "=" + encodeURIComponent( formData[i] ) );
			}

			document.location = this.appendState( "http://volunteer.truist.com/uwdc/agency/login.aspx?" + searchStr.join("&") );
			*/
			break;
	}
}

VYTSearch_VYTSearch.prototype.appendState = function( urlStr )
{
	if ( urlStr.indexOf( "?" ) == -1 ) 
		urlStr += "?";
		
	return urlStr + "&tab_state=" + this._state;
}


VYTSearch_VYTSearch.prototype.doSearch = function()
{
	if ( this._state == "gift_search" ) {
		var values = ria.getAssocFormData( this.$("#search_form") );
		var selectedIds = this.getSelectedIds( this.gift_tree );

		var searchStr = [];
		searchStr.push("__form_submitted__=_org_giftmatch_search_tcl_1");	
		searchStr.push("__init_request__=_org_giftmatch_search_tcl_1");
		searchStr.push("keyword=" + values.keyword );
		searchStr.push("zip=&radius=100");
		for ( var i=0; i<selectedIds.length; i++ ) {
			searchStr.push( "term_id=" + selectedIds[i] );
		}
		searchStr.push("__form_op__org_giftmatch_search_tcl_1__=Search");
		searchStr = searchStr.join("&");
		
		var url = this.appendState( "http://volunteer.truist.com/uwdc/org/giftmatch/search.tcl?" + searchStr );

		if ( this.open_modal ) {
			this.window({
				 "title":"Search Preview"
				,"content":"<iframe style='width: 850px; height: 500px;' src='" + url + "'></iframe>"
			});
		}else{
			document.location = url;
		}
		
	}else if ( this._state == "agencies_search" ) {
		
		//http://volunteer.truist.com/uwdc/agency/login.aspx
		/*
		return_url	
		agency_name	test
		password	test
		Go.x	33
		Go.y	6
		 * 
		 * */
	
	}else if ( this._state == "lead_search" ) {
		var values = ria.getAssocFormData( this.$("#search_form") );
		var selectedIds = this.getSelectedIds( this.lead_tree );
		
		var searchStr = [];
		searchStr.push("__form_submitted__=_org_board_search_tcl_1");	
		searchStr.push("__init_request__=_org_board_search_tcl_1");
		searchStr.push( "keyword=" + values.keyword );	
		searchStr.push( "zip=" );
		searchStr.push( "radius=100" );
		searchStr.push("__form_op__org_board_search_tcl_1__=" + encodeURIComponent("Search Board & Committee Match Positions") );
		for ( var i=0; i<selectedIds.length; i++ ) {
			searchStr.push( "term_id=" + selectedIds[i] );
		}
		searchStr = encodeURI( searchStr.join("&") );
		
		
		//http://volunteer.truist.com/uwdc/org/board/cat.aspx?term_id=
		var url = this.appendState( "http://volunteer.truist.com/uwdc/org/board/search.tcl?" + searchStr );
		if ( this.open_modal ) {
			this.window({
				 "title":"Search Preview"
				,"content":"<iframe style='width: 850px; height: 500px;' src='" + url + "'></iframe>"
			});
		}else{
			document.location = url;
		}
		
	}else if ( this._state == "volunteer_search" ) {		
		var values = ria.getAssocFormData( this.$("#search_form") );
	
		var selectedIds = this.getSelectedIds();
		var searchStr = [];
		searchStr.push( "js_p=0");
		searchStr.push( "target=");	
		searchStr.push( "__form_submitted__=_volunteer_search_aspx_2");
		searchStr.push( "__init_request__=_volunteer_search_aspx_2");
		searchStr.push( "__form_submitted__=_volunteer_search_aspx_3");
		searchStr.push( "__init_request__=_volunteer_search_aspx_3");
		searchStr.push( "keyword=" + values.keyword );	
		searchStr.push( "city=");
		searchStr.push( "zip=" + values.zip );
		searchStr.push( "radius=%2B");
		searchStr.push( "one_time_p=");
		for ( var i=0; i<selectedIds.length; i++ ) {
			searchStr.push( "term_id=" + selectedIds[i] );
		}
		searchStr.push( "x=4");
		searchStr.push( "y=27");
		searchStr.push( "__form_submitted__=_volunteer_search_aspx_1");
		searchStr.push( "__init_request__=_volunteer_search_aspx_1");
		searchStr = searchStr.join("&");
		var url = this.appendState( "http://volunteer.truist.com/uwdc/volunteer/search-2?" + searchStr );
		if ( this.open_modal ) {
			this.window({
				 "title":"Search Preview"
				,"content":"<iframe style='width: 850px; height: 500px;' src='" + url + "'></iframe>"
			});
		}else{
			document.location = url;
		}
		
		
	}
}


VYTSearch_VYTSearch.prototype.displayChoices = function( tree , html , level , location )
{
	if ( ria.isNull( tree ) )
		tree = this.decision_tree;
	
	var do_render = false;
	var tpl = new vyt_vytsearch_tpl_choices();
	if ( ria.isNull( level ) ) {
		level = 0;
		do_render = true;
		location = "0";
	}
	
	if ( ria.isNull( html ) ) {
		html = tpl.parse( {
			 choice:{children:tree}
			,choiceClass:"primary_choice"
			,level:level
			,location:location
		});
	}
	
	level++;	
	for ( var i=0; i<tree.length; i++ ) {
		var choice = tree[ i ];
		
		if (    !ria.isNull( choice.children ) 
				&& choice.selected == true 
				&& choice.children.length > 0 ) 
		{
			html += tpl.parse({
						 choice:choice
						,choiceClass:"sub_choice"
						,level:level
						,location:location + "_" + i
					});
			var childrenResult = this.displayChoices( choice.children , html , level , location + "_" + i );
			html = childrenResult.html;
			level = childrenResult.level;
		}else{
			if ( choice.selected ) {
				var checkboxtpl = new vyt_vytsearch_tpl_checkboxchoices();
				html += checkboxtpl.parse({
						 choice:choice
						,choiceClass:"sub_choice"
						,level:level
						,location:location + "_" + i
					});
			}			
		}
	}
	
	if ( do_render ) {
		this.choices_div.html( html );
		this.$(".valigned").each( function (i) {
			var me = $(this);
			me.css("padding-top",me.parent().height()/2 - me.height()/2 - 2 );
		});
		
		if ( this.animate ) {
			
			var offset = 5;
			//not sure why this doesn't comput correctly the first time...
			if ( ria.isNull( this.firstTime ) ) {
				offset = 25;
				this.firstTime = false;
			}
			this.$("#choices_container").animate({
				height: this.choices_div.height()+offset
			});
			
		}else{
			this.$("#choices_container").height( this.choices_div.height()+5 );
		}		
	}
	
	return {html:html,level:level,location:location};//,rows:rows};
}


VYTSearch_VYTSearch.prototype.getSelectedIds = function( tree , selections , depth )
{
	if ( ria.isNull( tree ) )
		tree = this.decision_tree;
	if ( ria.isNull( selections ) )
		selections = {};
	if ( ria.isNull( depth ) )
		depth = 0;
	if ( ria.isNull( selections["depth_" + depth ] ) )
		selections["depth_" + depth ] = [];
	
	for ( var i=0; i<tree.length; i++ ) {
		var decision = tree[ i ];
		if ( decision.selected == true 
				&& !ria.isNull( decision.metadata )
				&& !ria.isNull( decision.metadata.args )
		) {			
			$.merge( selections["depth_" + depth ] , decision.metadata.args );			
		}		
		//cycle through children...
		if ( !ria.isNull( decision.children ) && decision.children.length > 0 ) {
			this.getSelectedIds( decision.children , selections , depth+1 ) ;
		}
	}	
	
	if ( depth == 0 ) {
		var topMostSelections = [];
		for ( var i=0; i<5; i++ ) {
			if ( ria.isNull( selections["depth_" + i ] ) ) {
				break;
			}else{
				if ( selections["depth_" + i ].length > 0 ) {
					topMostSelections = selections["depth_" + i ];
				}
			}			
		}
		//now make them unique
		var uniqueObj = {};
		var uniqueArr = [];
		for ( var a=0; a<topMostSelections.length; a++ ) {
			var id = topMostSelections[a];
			if ( ria.isNull( uniqueObj["id_" + id ] ) ) {
				uniqueObj["id_" + id ] = true;
				uniqueArr.push( id );
			}
		}		
		
		return uniqueArr;
	}
}

VYTSearch_VYTSearch.prototype.onBounce = function( action , value , event )
{
	switch ( action ) {
		case "a" :
			break;
	}
}

VYTSearch_VYTSearch.prototype.selectDecision = function( value , tree , level )
{
	if ( ria.isNull( tree ) )
		tree = this.decision_tree;
	if ( ria.isNull( level ) )
		level = 1;
	
	var targetDecision = false;
	for ( var i=0; i<tree.length; i++ ) {
		var decision = tree[ i ];
		if ( decision.id == value ) {
			//void out the other children....			
			if ( level != 3 ) {
				if ( !ria.isNull( decision.children ) && decision.children.length > 0 ) {
					this.selectAllDecisionChildren( decision.children , false );
				}
			}			
			decision.selected = ( ria.isNull( decision.selected ) ) ? true : !decision.selected;
			targetDecision = decision;
		}else{
			//set the rest to false
			if ( level != 3 || !this.allow_multiple_leaves ) {//leafs can have more than one
				decision.selected = false;
			}
		}
		
		//cycle through children...
		if ( !ria.isNull( decision.children ) && decision.children.length > 0 ) {
			var childDecision = this.selectDecision( value , decision.children , level + 1 ) ;
			if ( childDecision !== false ) {
				decision.selected = true;
				targetDecision = childDecision;
			}
		}
	}	
	return targetDecision;
}

VYTSearch_VYTSearch.prototype.selectAllDecisionChildren = function( tree , value )
{
	if ( ria.isNull( tree ) )
		tree = this.decision_tree;
	if ( ria.isNull( value ) )
		value = false;
	
	for ( var i=0; i<tree.length; i++ ) {
		var decision = tree[ i ];	
		decision.selected = value;
		if ( !ria.isNull( decision.children ) && decision.children.length > 0 ) {
			this.selectAllDecisionChildren( decision.children , value );
		}
	}	
}

//https://volunteer.truist.com/uwdc/org/giftmatch/cat.aspx?term_id=
VYTSearch_VYTSearch.prototype.gift_tree = [
	{data:"By Category...",metadata:{id:""},children:[
	    {data:"Computer Equipment",metadata:{args:["2746754"]}}
	   ,{data:"Children's Items",metadata:{args:["2746767"]}}
	   ,{data:"Clothes/Clothing",metadata:{args:["2746774"]}}
	   ,{data:"Education Materials",metadata:{args:["2746778"]}}
	   ,{data:"Food/Water",metadata:{args:["2746791"]}}
	   ,{data:"Gift Certificates",metadata:{args:["2746794"]}}
	   ,{data:"Home & Shelter Equipment/Supplies",metadata:{args:["2746800"]}}
	   ,{data:"Office Equipment/Supplies",metadata:{args:["2746812"]}}
	   ,{data:"Office Supplies",metadata:{args:["2746817"]}}
	   ,{data:"Other",metadata:{args:["2746822"]}}
	   ,{data:"Training",metadata:{args:["2746832"]}}
	   ,{data:"Personal Care",metadata:{args:["2746827"]}}
	   ,{data:"Transportation",metadata:{args:["2746840"]}}
	 ]} 
]

//http://volunteer.truist.com/uwdc/org/board/cat.aspx?term_id=2158485
VYTSearch_VYTSearch.prototype.lead_tree = [
	{data:"By Category...",metadata:{id:""},children:[
	    {data:"Arts and Culture",metadata:{args:["2158419"]}}
	   ,{data:"Education",metadata:{args:["2158431"]}}
	   ,{data:"Environment and Animals",metadata:{args:["2158440"]}}
	   ,{data:"Human Services",metadata:{args:["2158456"]}}
	   ,{data:"International/Foreign Affairs",metadata:{args:["2158480"]}}
	   ,{data:"Public, Societal Benefit",metadata:{args:["2158485"]}}
	   ,{data:"Skills and Expertise",metadata:{args:["2158501"]}}
	]} 
]

function vyt_vytsearch_cmd_LoadTree ( )
{
	this.dataType = 'jsonp';
}

vyt_vytsearch_cmd_LoadTree.prototype = new ria_cmd_Command();
vyt_vytsearch_cmd_LoadTree.prototype.constructor = vyt_vytsearch_cmd_LoadTree;

vyt_vytsearch_cmd_LoadTree.prototype.loadingStarted = function()
{
 	//PopupManager.showGlobalLoading();
}

/*
 * Triggered when a service is done loading regardless of success/failure
 * */
vyt_vytsearch_cmd_LoadTree.prototype.loadingDone = function()
{
	//PopupManager.hideGlobalLoading();
}

vyt_vytsearch_cmd_LoadTree.prototype.execute = function( data , scope , encodeArgs )
{
	this.url = data.url_root + "files/tree.php";
	ria.log( this.url );
	ria_cmd_Command.prototype.execute.call( this , data , scope , encodeArgs );
}

vyt_vytsearch_cmd_LoadTree.prototype.success = function( results, status )
{
	ria_cmd_Command.prototype.success.call( this, results, status );	
	this.scope.treeLoaded( results.result );
}




function vythomeadmin_cmd_LoadHome ( )
{
	this.url = "/files/home.json";
}

vythomeadmin_cmd_LoadHome.prototype = new ria_cmd_Command();
vythomeadmin_cmd_LoadHome.prototype.constructor = vythomeadmin_cmd_LoadHome;

vythomeadmin_cmd_LoadHome.prototype.execute = function( data , scope , encodeArgs )
{
	ria_cmd_Command.prototype.execute.call( this , data , scope , encodeArgs );
}

vythomeadmin_cmd_LoadHome.prototype.failure = function( status , errorThrown )
{
	this.loadingDone();
	this.scope.homeDidntLoad();
}

vythomeadmin_cmd_LoadHome.prototype.success = function( results, status )
{
	ria_cmd_Command.prototype.success.call( this, results, status );	
	this.scope.homeLoaded( results.result );
}





vytadmin_vythomeadmin_tpl_HomePage = function () {
	return new microtemplate_Template( '<#  	if ( ria.isNull( showEdit ) ) 		var showEdit = false;  #>   <div class="homepage_wrapper"> 	<div class="homepage"> 		 		<div class="stories"> 			<#  				var stories = data.stories; 				for ( var i=0; i<stories.length; i++ ) { 					story = stories[i]; 					if ( i== 0 ) { 					 			#> 						<div class="story main_story"> 							<h2 class="headline"><#= story.headline #></h2> 							<div class="image">								 								<# if ( !ria.isNull( story.youtube_id ) && story.youtube_id.length > 0 ) { #> 									<iframe width="350" height="340" src="http://www.youtube.com/embed/<#= story.youtube_id #>" frameborder="0" allowfullscreen></iframe> 								<# }else{ #> 									<img src="/files/images/<#= story.image_large #>" /> 								<# } #> 							</div> 							 							<!--div class="content"--> 								<#= story.content #> 							<!--/div--> 							<# if ( showEdit ) { #> 								<div class="edit"><a href="#" 													clickaction="edit_story"  													clickvalue="<#= i #>">edit</a></div> 							<# } #>				 						</div>					 						<div class="hr"></div> 			<#  					}else{ 			#> 			 						<div class="story"> 							 							<div class="image"> 								<# if ( !ria.isNull( story.youtube_id ) && story.youtube_id.length > 0 ) { #> 									<iframe width="130" height="130" src="http://www.youtube.com/embed/<#= story.youtube_id #>" frameborder="0" allowfullscreen></iframe> 								<# }else{ #> 									<img src="/files/images/<#= story.image_small #>" /> 								<# } #> 							</div> 							<h2 class="headline"><#= story.headline #></h2> 							<!--div class="content"--> 								<#= story.content #> 							<!--/div--> 							<# if ( showEdit ) { #> 								<div class="edit"><a href="#" 													clickaction="edit_story"  													clickvalue="<#= i #>">edit</a></div> 							<# } #>				 						</div>					 						<div class="hr"></div> 			<# 					} 			 				}  			#> 			<div class="clear"></div> 		</div> 	 		 		<div class="spotlight_header"></div> 		 		<div class="spotlights"> 			<# 				var spotlights = data.spotlights; 				for ( var i=0; i<spotlights.length; i++ ) { 					spotlight = spotlights[i]; 			#> 					<div class="spotlight"> 						<div class="image"><img src="/files/images/<#= spotlight.image_small #>" /></div> 						<div class="description"><#= spotlight.description #></div> 						<div class="details"> 							<a class="details_link" target="_new"  								title="<#= spotlight.description #>"  								href="<#= spotlight.url #>"></a> 						</div> 						<# if ( showEdit ) { #> 							<div class="edit"><a href="#"  												clickaction="edit_spotlight"  												clickvalue="<#= i #>">edit</a></div> 						<# } #> 					</div> 					<div class="hr"></div> 			<# } #> 			<div class="clear"></div> 		</div> 		<div class="clear"></div> 	</div> </div>' );
};



vyt_vytsearch_tpl_choices = function () {
	return new microtemplate_Template( '<#   /*CHECK FOR SELECTED ITEM...*/ var selected_choice = false; for ( var c=0; c<choice.children.length; c++ ) {  	var focusedChoice = choice.children[c]; 	if ( focusedChoice.selected == true ) { 		selected_choice = focusedChoice; 	} }  if ( selected_choice != false ) { #>  	<div class="choice_stack"> 		<# if ( level > 0 ) { #> 			<div class="arrow"></div> 		<# } #> 		<div class="<#= choiceClass #>_box selected_choice" 			clickaction="choose"  			clickvalue="<#= selected_choice.id #>"> 			<a href="#"	clickaction="choose"  				clickvalue="<#= selected_choice.id #>" 				class="valigned <#= choiceClass #> selected_choice"> 					<#= selected_choice.data #> 			</a> 		</div> 	</div> 	 <# }else{ #> 	 	<div class="choice_stack"> 		<#  			/*FIgure out if chiLdren should be checkboxes...*/ 			var tpl = new vyt_vytsearch_tpl_checkboxchoices(); 			var use_checkboxes = true; 						 			for ( var c=0; c<choice.children.length; c++ ) {  				var focusedChoice = choice.children[c]; 				if ( !ria.isNull( focusedChoice.children ) && focusedChoice.children.length > 0 ) { 					use_checkboxes = false; 					break; 				} 			}  			if ( use_checkboxes ) { 				#><#= tpl.parse({ 						 choice:choice 						,choiceClass:"sub_choice" 						,level:level 						,location:location 					}) #><# 			}else{ 				 				if ( level > 0 ) {  					#><div class="arrow"></div><#  				}  				 				for ( var c=0; c<choice.children.length; c++ ) {  					var focusedChoice = choice.children[c]; 					 					var positionClass = "right"; 					if ( c%2 == 0 ) 						positionClass = "left"; 						 					if ( c >= 2 )  						positionClass += " padTop"; 					 					var css = "font-size: 12px;"; 					var cls = ""; 					if ( focusedChoice.data.length > 30 ) { 						css = "font-size: 11px;"; 						cls = "long"; 					} 					 					/*if ( focusedChoice.data.length > 70 ) { 						css = "font-size: 10px; font-weight: normal"; 						cls = "long"; 					}*/ 					 					#> 					<div class="<#= choiceClass #>_box <#= positionClass #>" 						clickaction="choose"  						clickvalue="<#= focusedChoice.id #>"> 							<a href="#" style="<#= ( choiceClass != \'primary_choice\' ) ? css : \'\' #>" 							clickaction="choose"  							clickvalue="<#= focusedChoice.id #>" 							class="valigned <#= choiceClass #> <#= cls #> <#= ( focusedChoice.selected == true ) ? \'selected\' : \'\' #>"> 								<#= focusedChoice.data #> 						</a> 					</div><# 				}  		 			} 		#> 		<div class="clear"></div> 	</div>  <# } #> <div class="clear"></div>  ' );
};



vyt_vytsearch_tpl_checkboxchoices = function () {
	return new microtemplate_Template( ' <div class="arrow"></div> <img src="<#= root #>vyt_v2/images/vyt/checkboxes_top.png" height="10" /><div class="checkbox_choice_stack" 	clickaction="checkbox_choose" 	clickvalue="<#= choice.id #>" 	catchallclicks="y"> 	<form id="checkbox_form"> 		<#  			if ( !ria.isNull( choice.children ) ) { 				for ( var c=0; c<choice.children.length; c++ ) {  					var focusedChoice = choice.children[c];	 		#> 					<label> 						<input type="checkbox" <#= ( focusedChoice.selected == true ) ? \'checked="yes"\' : \'\' #> 							id="<#= focusedChoice.id #>" name="<#= focusedChoice.id #>" /> 						<#= focusedChoice.data #>				 					</label> 		<#  				}  			} 		#> 	</form>  	<div class="clear"></div> 	<a href="#" class="submit_checkboxes_btn" clickaction="search">Search</a> 	<a href="#" class="cancel_checkboxes_btn" clickaction="cancel">cancel</a> 	<div class="clear"></div> </div><div><img src="<#= root #>vyt_v2/images/vyt/checkboxes_bottom.png" height="10" /></div>' );
};



vyt_vytsearch_tpl_VYTSearch = function () {
	return new microtemplate_Template( '  <div class="search_nav volunteer"> 	<div class="search_nav_positioner"> 		<a href="#" class="search_nav_item selected volunteer"  			clickaction="volunteer_search">Volunteer</a> 		<a href="#" class="search_nav_item lead"  			clickaction="lead_search">Lead</a> 		<a href="#" class="search_nav_item gift"  			clickaction="gift_search">Give</a> 		<a href="#" class="search_nav_item agencies"  			clickaction="agencies_search">Login</a> 	</div> </div> <div class="search_form_container"></div> <div class="search_footer"></div>' );
};



vyt_vytsearch_tpl_states_Volunteer = function () {
	return new microtemplate_Template( ' <div class="search_form volunteer"> 	<form id="search_form" onsubmit="ria.submit( event )"> 		<div style="width: 370px;"> 			<span>keyword</span> 			<input id="keyword" name="keyword" class="volunteer_keyword" /> 			<span>zip code</span> 			<input id="zip" name="zip" /> 		</div> 		<a href="#" class="submit_btn" onclick="ria.submit( event )">Search</a> 		<input type="submit" style="display: none;" /> 	</form> 	<div style="clear: both;"></div> </div> <div class="intro_text"> 	<a href="http://volunteer.truist.com/uwdc/volunteer/calendar/" class="search_wt_btn calendar">Calendar</a> 	Use the search tool to find a volunteer opportunity that is right for you!<br /> 	<span style="font-style: normal;font-size: 13px;">I am looking for a volunteer opportunity that...</span> 	 </div>	 <div id="choices_container" style="height: 80px; overflow: hidden;"> 	<div id="choices"></div> </div>' );
};



vyt_vytsearch_tpl_states_Gift = function () {
	return new microtemplate_Template( '<div class="search_form gift"> 	<form id="search_form" onsubmit="ria.submit( event )"> 		<span>keyword</span> 		<input id="keyword" name="keyword" class="gift_keyword" /> 		<a href="#" class="submit_btn" onclick="ria.submit( event )">Search</a> 		<input type="submit" style="display: none;" /> 	</form> </div> <div class="intro_text"> 	Search by category or browse all to see the items that nonprofit organizations in Dane 	County need. </div>	 <div id="choices_container" style="height: 80px; overflow: hidden;"> 	<div class="more_info"> 		<div style="text-align: center; margin-top: 10px;"> 			<a href="http://volunteer.truist.com/uwdc/org/giftmatch/dir-all.html">View All Needed Items</a> 		</div> 		<div style="text-align: center; margin-top: 10px;"> 			<a href="http://volunteer.truist.com/uwdc/volunteer/giftmatch/ae.aspx">Donate an Item</a> 		</div> 	</div> 	<div id="choices"></div>	 </div>' );
};



vyt_vytsearch_tpl_states_Lead = function () {
	return new microtemplate_Template( '<div class="search_form lead"> 	<form id="search_form" onsubmit="ria.submit( event )"> 		<span>keyword</span> 		<input id="keyword" name="keyword" class="lead_keyword" /> 		<a href="#" class="submit_btn" onclick="ria.submit( event )">Search</a> 		<input type="submit" style="display: none;" /> 	</form> </div> <div class="intro_text">Are you interested in becoming a board member, committee member, consultant for a nonprofit organization? 		</div>	 <div id="choices_container" style="height: 80px; overflow: hidden;"> 	<div class="more_info"> 		Use this tool to search for leadership volunteer opportunities where you can use your skills and expertise. 	</div> 	<div id="choices"></div>	 </div>' );
};



vyt_vytsearch_tpl_states_Agencies = function () {
	return new microtemplate_Template( '    <div class="agencies"> 	<div class="agency_content"> 		<div class="agency_text"> 			Not registered yet? Create a New Account:<br />   			Agencies looking to recruit volunteers<br /> 			<a href="http://volunteer.truist.com/uwdc/agency/signup.aspx">CLICK HERE</a> 			<br /><br />   			Volunteers looking to become a registered user  			<a href="http://volunteer.truist.com/uwdc/volunteer/register/?final_return_url=&screen_name=">CLICK HERE</a> 			 			<a href="http://volunteer.truist.com/uwdc/user/logout.aspx" class="blue_btn logout">Logout</a>		 		</div> 		<div class="user login_form"> 			<h2>Login</h2> 			<form id="user_login" onsubmit="ria.submit( event )"> 				<div style="height: 30px;"> 					<div style="float: left; width: 70px;">Login Name</div> 					<input id="login_name" name="login_name" type="text" /> 				</div> 				<div style="clear:both;"> 					<div style="float: left; width: 70px;">Password</div> 					<input id="password" name="password" type="password" /> 				</div> 				 				<div class="forget"> 					<div><a href="https://volunteer.truist.com/uwdc/user/login/forgot-password.aspx">Forgot password?</a></div> 				</div> 				<div class="remember"> 					<label><input id="expire_state" name="expire_state" type="checkbox" value="p" />Remember</label> 				</div> 				<div class="nav"> 					<a href="#" clickaction="login_volunteer">Volunteer Login</a> 					<a href="#" clickaction="login_agency" style="margin-right: 15px;">Agency Login</a>					 				</div>				 			</form> 			<form id="agency_login_proxy" action="https://volunteer.truist.com/uwdc/agency/login.aspx" method="POST"> 				<input type="hidden" id="agency_name" name="agency_name" value="" /> 				<input type="hidden" id="password" name="password" value="" /> 				<input type="hidden" id="expire_state" name="expire_state" value="" /> 			</form> 			<form id="user_login_proxy" action="https://volunteer.truist.com/uwdc/register/user-login.tcl" method="POST"> 				<input type="hidden" id="screen_name" name="screen_name" value="" /> 				<input type="hidden" id="password_from_form" name="password_from_form" value="" /> 				<input type="hidden" id="expire_state" name="expire_state" value="" /> 			</form> 		</div> 	</div> </div>' );
};

$(document).ready( function() {	ria.createComponents();	} );
