//--------------REQUIRED FOR SUCKERFISH FIX PSEUDO HOVER IERUBBISH----------------//

sfHover = function() {
	myEl = $('volnavlist')
	
	if($chk(myEl)){
		
	var sfEls = myEl.getElements('LI');
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
	
	};
}

sfHoverAdmin = function() {
	myEl = $('voladminlist')
	
	if($chk(myEl)){
		
	var sfEls = myEl.getElements('LI');
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
	
	};
}

//-------------Google Analytics---------------------------//

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-26002455-3']);
  _gaq.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);
  })();


window.addEvent('domready', function(){
//MooTools.lang.setLanguage("en-GB");

	//Suckerfish for IE 6
	sfHover()
	sfHoverAdmin()

	//set local
	Locale.use('en-GB');
	

	//Check all checkme boxes on click
	//var checkAll = $('ucuc');
	//if (checkAll != NULL){
	$$('#ucuc').addEvent('click', function() {
		if($('ucuc').get('rel') == 'yes')
		{
			do_check = false;
			$('ucuc').set('src','/images/icon_checkbox.png').set('rel','no');
		}
		else
		{
			do_check = true;
			$('ucuc').set('src','/images/icon_checkbox_checked.png').set('rel','yes');
		}
		$$('.check-me').each(function(el) { el.checked = do_check; });
	});
	//};
	
	
	// implement extra features to the element class
	
	Element.implement({
		//implement centre
		centreEl: function() {
			//have to set display block otherwise has no height
			
			this.setStyles({opacity:0, 'display':'block'});
			elSc = window.getScroll();
			elsize = this.getSize()
			var postop = window.getSize()
			
			postopmiddle = (elSc.y+(postop.y/2)) - (elsize.y/2)
			posleftmiddle = (postop.x/2) - (elsize.x/2)
			
			//need to check to see if the element height is larger then the portal
			if (postopmiddle<0){postopmiddle = 0};
			this.setStyles({'top':postopmiddle+'px', 'left':posleftmiddle+'px'});
			
		},
		
		centreElFade: function() {
			//so we can measure it but cant see it and fade it in
			this.setStyles({opacity:0, 'display':'block'});
			elSc = window.getScroll();
			elsize = this.getSize()
			var postop = window.getSize()
			postopmiddle = (elSc.y+(postop.y/2)) - (elsize.y/2)
			posleftmiddle = (postop.x/2) - (elsize.x/2)
			
			//need to check to see if the element height is larger then the portal
			if (postopmiddle<0){postopmiddle = 0};
			//el.setStyles({'top':top+'px', 'left':left+'px'});
			this.setStyles({'top':postopmiddle, 'left':posleftmiddle});
			this.fade('in');
		},
		
		//implement a block level fade
		fadeToggleBlock: function () {
		
			currentStyle = this.getStyle('display')
			if (currentStyle == 'block'){
				//we are fading out
				//no point fading out unless chaining as it will switch ti display none immediately
				//this.fade('out');
				this.setStyles({'display':'none'});
			}else{
				this.setStyles({opacity:0, 'display':'block'});
				this.fade('in');
			}
			
			
		},

		//implement show
		fadeShow: function() {
			//set display:none and opacity 0
			this.setStyles({opacity:0, 'display':'block'});
			this.fade('in');
		},
		//implement hide
		fadeHide: function() {
			this.fade('out');
			this.setStyles({'display':'none'});
		},
		//implement fade destroy	
		ElFadeDestroy: function(){
			
			
			//alert(this.id)
			//this.fade('out').get('tween').chain(function() { this.dispose(); }); 


			var fx = new Fx.Tween(this);
				fx.start('opacity', '0').chain(function() {
				this.start('display', 'none')
			});
			
			
			
			/*var myChain = new Chain();
			
			myChain.chain(
			function(el) {this.fade('out'); this.callChain();},
			function(el) {this.dispose(); this.callChain();}
			);
			
			myChain.callChain(this);*/		
		},
		//implement our toggle	
		ElToggleHide: function(){
			
			
			//alert(this.id)
			//this.fade('out').get('tween').chain(function() { this.dispose(); }); 
			vState = this.get('opacity')
			vHidden = this.getStyle('display')
			
			if (vHidden=='none'||vState==0){
				//this is a block level which has display none
				//give it back being a block
				this.setStyles({opacity:0, 'display':'block'});
				this.fade('in')
				
			}else{

					this.fade('out').get('tween').chain(
						(function() {
							this.setStyle('display','none');
						}).bind(this)
					);
								
				
			};
			
			
		},

		
		flash: function(to,from,reps,prop,dur) {
			
			//defaults
			if(!reps) { reps = 1; }
			if(!prop) { prop = 'background-color'; }
			if(!dur) { dur = 250; }
			
			//create effect
			var effect = new Fx.Tween(this, {
					duration: dur,
					link: 'chain'
				})
			
			//do it!
			for(x = 1; x <= reps; x++)
			{
				effect.start(prop,from,to).start(prop,to,from);
			}
		}
		
	
	});



	/* Tips 1 */
	var myTips = new Tips('.Tips1');

	//closes fadeins
	$each($$('.closethis'), function(el){
		//have to fade out te window then fade out the overlay
		el.addEvent('click', function(event) {
		//close the parent
		var parent = el.getParent('div');
		parent.fade('out').get('tween').chain(function(){$('overlay_').dispose();});
		
		 });
	});

	//adds a visual clue to focusing
	$each($$('input[type=text]'), function(el){
								
	el.addEvent('focus', function(e) {
		el.setStyle('background-color','#ffffdd');
								  });
	
	el.addEvent('blur', function(e) {
		el.setStyle('background-color','');
								  });
	
	});	
	
	//adds flashes any errorText
	$each($$('.errorText'), function(el){
		cBC = el.getStyle('background-color')
		if (cBC == '' || cBC == 'transparent') {cBC='#fff'}
		el.flash('#FF9999', cBC, 1, null,1000)	
		
	 });
	 
	//adds flashes any notification text
	$each($$('.notifyText'), function(el){
		cBC = el.getStyle('background-color')
		if (cBC == '' || cBC == 'transparent') {cBC='#fff'}
		el.flash('#fcf287', cBC, 1, null,1000)	
		
	 });
	 
	 
	//adds a visual clue to pseudoButton CLASSES
	$each($$('.pseudoButton'), function(el){
	//get the current colour of the button
	
	el.addEvent('mouseover', function(e) {
		vEC = $(e.target).getStyle('background-color');
		vENC = '#' + colorscale(vEC, 0.5)
		el.setStyles({'cursor':'pointer'});
		el.tween('background-color', vENC)
		});
	
	el.addEvent('mouseout', function(e) {
		vEC = $(e.target).getStyle('background-color');
		vENC = '#' + colorscale(vEC, 0.5)
		el.setStyles({'curosr':'default'});
		el.tween('background-color', this.vEC)
		});
								  
	
	});
	
	
	//button rollovers
	$$('.btnRoll').addEvent('mouseover', function(event) { this.setStyle('background-position','top'); });
	$$('.btnRoll').addEvent('mouseout', function(event) { this.setStyle('background-position','bottom'); });

	// zebra stripe tables with shade-table class
	var count = 0;
	
	$$('table.shade-table tr').each(function(el) {
		el.addClass(count++ % 2 == 0 ? 'trodd' : 'treven');
	});
	
	count = 0;
	$$('table.shade-table-postit tr').each(function(el) {
		el.addClass(count++ % 2 == 0 ? 'troddpost' : 'trevenpost');
	});



	//Editing volunteer groups on admin page
	$$('.volGroup').addEvent('click', function(e) {
		var tgt = $(e.target)
		var tgtArr = tgt.id.split('|')
		if(!tgtArr[0]){
			//get its parent instead
			var tgt = tgt.getParent();
			var tgtArr = tgt.id.split('|')
			};
		$('oGID').value = tgtArr[1]
		$('oGroupName').value = tgtArr[2]
		$('open_editGroup').fadeShow();

	});


	//adds a visual clue to TOGGLING CLASSES
	$each($$('.toggler'), function(el){
										
	el.addEvent('mouseover', function(e) {
		el.setStyles({'background-color':'#fffe9e', 'cursor':'pointer', 'color':'#333'});
								  });
	
	el.addEvent('mouseout', function(e) {
		el.setStyles({'background-color':'', 'curosr':'default', 'color':''});
								  });
	
	});
	
	$each($$('.togglerLight'), function(el){
								
	el.addEvent('mouseover', function(e) {
		el.setStyles({'background-color':'#ffffdd', 'cursor':'pointer'});
								  });
	
	el.addEvent('mouseout', function(e) {
		el.setStyles({'background-color':'', 'curosr':'default'});
								  });
	
	});
	
	$each($$('.togglerGreen'), function(el){
								
	el.addEvent('mouseover', function(e) {
		el.setStyles({'background-color':'#659a00', 'cursor':'pointer', 'color':'#fff'});
								  });
	
	el.addEvent('mouseout', function(e) {
		el.setStyles({'background-color':'', 'curosr':'default', 'color':''});
								  });
	
	});



	
$$('.textnumber').addEvent('click', function(e) {
								
		var tgt = e.target || e.srcElement; // IE doesn't use .target
		//stick in the values of theclicked number to the form
		var tgtArr = tgt.id.split('|')
		//if the target is empty then they have clicked osmething inside the table division
		$('tNumber').value = tgtArr[1];
		$('tVolID').value = tgtArr[0];
		//make the form appear in the middle
		$$('.toggleTgt').tween('opacity',0);
		$('open_textmessageform').centreElFade();
		
		
	  });



$$('.phours').addEvent('click', function(event) {
			
		var tgt = $(event.target)
		//stick in the values of theclicked number to the form
		var tgtArr = tgt.id.split('|')
		if(!tgtArr[0]){
			//get its parent instead
			var tgt = tgt.getParent();
			var tgtArr = tgt.id.split('|')
			};

		//if the target is empty then they have clicked osmething inside the table division
		HvID = tgtArr[0];
		HpID = tgtArr[1];
		//get some details from their loggable hours
		
		//alert('/admin/ajax_plhours.htm?pID='+HpID+'&vID='+HvID)
		var myRequest = new Request({
		url:'/admin/ajax_plhours.htm?pID='+HpID+'&vID='+HvID,
		method: 'post',
		onComplete: function(returned){
		//lets get rid of that column
			myel = $('open_plhoursform')
			myel.set('html',returned);
			myel.centreElFade();
		}									
							
		});
		myRequest.send();		
		
	  });

$$('.interview').addEvent('click', function(event) {

		var tgt = $(event.target)
		if(!tgt.id){
			//get its parent instead
			var tgt = tgt.getParent();
			};
			
		$('iVolID').value = tgt.id

		var myTogglingChain = new Chain();
				
		myTogglingChain.chain(
		function(el) {$$('.toggleTgt').fade('out'); this.callChain();},
		function(el) {$('open_interviewform').centreElFade(); this.callChain();}
		);
		
		myTogglingChain.callChain('something');	
		
	  });


	/* PREPARE TOGGLE TARGETS  */
	$each($$('.toggleTgtCentreNB'),function(el){el.setStyles({ 'opacity':0 , 'visibility': 'visible' });});

	/* PREPARE TOGGLE TARGETS  */
	$each($$('.toggleTgt'),function(el){el.setStyles({ 'opacity':0 , 'display': 'none' });});

	//centres all the toggle targets and sets them to opacity 0 but display block for later fades.
	//sets z-index to 1 so they are above any screen wipes
	$each($$('.toggleTgtCentre'),function(el)
	{
	el.setStyles({ 'opacity':0 , 'display': 'block', 'z-index':10 });
	elsize = el.getSize()
	var postop = window.getSize()
	postopmiddle = (postop.y/2) - (elsize.y/2)
	posleftmiddle = (postop.x/2) - (elsize.x/2)
	
	//need to check to see if the element height is larger then the portal
	if (postopmiddle<0){postopmiddle = 0};
	//el.setStyles({'top':top+'px', 'left':left+'px'});
	el.setStyles({'top':postopmiddle, 'left':posleftmiddle});
	});
	
	$$('.toggling').addEvent('click', function(e) {
		
		var tgt = $(e.target) // IE doesn't use .target
		var elClickedstr = tgt.id.split('|');
		el=$("open_" + elClickedstr[0]);
		if (el.hasClass('popup')&&el.getStyle('display')=='none'){ 
			//have to display block it and center it
			el.setStyles({opacity:0, 'display':'block'});
			el.centreEl()
		};
		
		el.ElToggleHide()
		
		//remove the overlay if it exists.
		o = $('overlay_');
		if (o) {o.dispose();};
			
		// hide autosuggest if it exists
		a = $('autosuggest');
		if (a) {a.fadeToggleBlock()} //dont destroy as may need it again
		
	});
	
	
	$$('.togglingNC').addEvent('click', function(e) {
		//have to split at _ for unique IDs added after the string we need
		var tgt = e.target || e.srcElement; // IE doesn't use .target
		var elClickedstr = tgt.id;
		pos = elClickedstr.indexOf('|');
		//capture that ID as an object
		if (pos !=-1){el=$("open_" + elClickedstr.substring(0,pos));}
		else {el=$("open_" + elClickedstr);}
		el.fade('toggle');
	});

	
	$$('.closeMe').addEvent('click', function(e) {
		//have to split at _ for unique IDs added after the string we need
		var tgt = $(e.target)
		var elClickedstr = tgt.id;
		pos = elClickedstr.indexOf('|');
		//capture that ID as an object
		if (pos !=-1){el=$("open_" + elClickedstr.substring(0,pos));}
		else {el=$("open_" + elClickedstr);}
		el.fade('out');
	});
	
	$$('.togglingNC').addEvent('click', function(e) {
		//have to split at _ for unique IDs added after the string we need
		var tgt = e.target || e.srcElement; // IE doesn't use .target
		var elClickedstr = tgt.id;
		pos = elClickedstr.indexOf('|');
		//capture that ID as an object
		if (pos !=-1){el=$("open_" + elClickedstr.substring(0,pos));}
		else {el=$("open_" + elClickedstr);}
		el.fade('toggle');
	});
	
	//====== CHECK FOR AND CONTROL LOGIN POPUP========//
	
	
	var isLogin = $('open_loginPopup')
	
	if (isLogin) {
		
			$('open_loginPopup').addEvent('mouseleave', function(e){
				//check to see if a form has focus
				if (!lostFocus){
				//fadeout the popup
					popup = $('open_loginPopup')
					popup.fade('out');
				};
			});
			
			
			lostFocus = false
		
			$each($$('.loginFrontToggle'), function(el){
				el.addEvent('mouseover', function(e){
					popup = $('open_loginPopup')
					posDiv = $('loginFrontToggle')
					vPos = posDiv.getCoordinates();
					vPosPop = popup.getCoordinates
		
					//position login div
					popup.setStyles({'top':0 , 'left': vPos.right-719});
					//pop up login div
					popup.fade('in');
				});
				
			});
			
			$$('.loseFocus').addEvent('focus', function(e){
				
				lostFocus = true
				//add a manual close button on the login form
				//this is all because we cannot guarantee that automcomplete=off works in FF, IE etc
				periodical = focusReset.periodical(2 * 1000, this);
		
			});
			
			
			
			var focusReset = (function() {
				
				lostFocus = false;
				$clear(periodical);
				
			});
	
	};
	
	$$('.emailaddSchool').addEvent('click', function(e) {
								
		var tgt = $(e.target)
		//stick in the values of theclicked number to the form
		var tgtArr = tgt.id.split('|')
		if(!tgtArr[0]){
			//get its parent instead
			var tgt = tgt.getParent();
			var tgtArr = tgt.id.split('|')
			};
		
		$('eToAddress').value = tgtArr[0]
		//make the form appear in the middle
		$('open_emailform').centreEl();
		
		//toggle off anyother open toggle targets and fade in the one we are interested in
		var myTogglingChain = new Chain();
		
		myTogglingChain.chain(
		function(el) {$$('.toggleTgtCentre').fade('out'); this.callChain();},
		function(el) {$('open_emailform').fade('toggle'); this.callChain();}
		);
		
		myTogglingChain.callChain('something');		
		
		Event.stop;
	  });
	
	$$('.emailadd').addEvent('click', function(e) {
								
		var tgt = $(e.target)
		//stick in the values of theclicked number to the form
		var tgtArr = tgt.id.split('|')
		if(!tgtArr[0]){
			//get its parent instead
			var tgt = tgt.getParent();
			var tgtArr = tgt.id.split('|')
			};
		
		$('eVolID').value = tgtArr[0]
		//make the form appear in the middle
		$('open_emailform').centreEl();
		
		//toggle off anyother open toggle targets and fade in the one we are interested in
		var myTogglingChain = new Chain();
		
		myTogglingChain.chain(
		function(el) {$$('.toggleTgt').fade('out'); this.callChain();},
		function(el) {$('open_emailform').fade('toggle'); this.callChain();}
		);
		
		myTogglingChain.callChain('something');		
		
		Event.stop;
	  });
	
	
	$$('.emailaddProvider').addEvent('click', function(e) {
								
		var tgt = $(e.target)
		//stick in the values of theclicked number to the form
		var tgtArr = tgt.id.split('|')
		if(!tgtArr[0]){
			//get its parent instead
			var tgt = tgt.getParent();
			var tgtArr = tgt.id.split('|')
			};
		
		$('ePEmail').value = tgtArr[0] //set the email address to this provider
		//make the form appear in the middle
		$('open_emailformprov').centreEl();
		
		//toggle off anyother open toggle targets and fade in the one we are interested in
		var myTogglingChain = new Chain();
		
		myTogglingChain.chain(
		function(el) {$$('.toggleTgtCentre').fade('out'); this.callChain();},
		function(el) {$('open_emailformprov').fade('in'); this.callChain();}
		);
		
		myTogglingChain.callChain('something');		
		
		Event.stop;
	  });	
	
	  
	
	$$('.textProvider').addEvent('click', function(e) {
				
				
		var tgt = $(e.target)
		//stick in the values of theclicked number to the form
		var tgtArr = tgt.id.split('|')
		if(!tgtArr[0]){
			//get its parent instead
			var tgt = tgt.getParent();
			var tgtArr = tgt.id.split('|')
			};
		
		//make the form appear in the middle
		$('open_textform').centreEl();

						
		//toggle off anyother open toggle targets and fade in the one we are interested in
		var myTogglingChain = new Chain();
		
		myTogglingChain.chain(
		function(el) {$$('.toggleTgtCentre').fade('out'); this.callChain();},
		function(el) {$('open_textform').fade('toggle'); this.callChain();}
		);
		
		myTogglingChain.callChain('something');	
		
		Event.stop;
	  });	
	
	
});  //END OF DOM READY FUNCTION




function alertoverlay(additionalheight){

//create a div
//make it the same size as the browser height (not window height)
//transaprent background
//fade it in
//make sure it has a low z-index

mynew  = new Element('div', {
   'class': 'dopngfix',
   'styles': {
        'display': 'block',
        'border': '1px solid black',
		'height' : window.getScrollHeight()+additionalheight,
		'width' : '100%',
		'background' : 'url(/images/back_trans_repeat.png) repeat',
		'position' : 'absolute',
		'top' : '0',
		'left' : '0',
		'z-index' : '0'
	 },
    'events': {
        'click': function(){
            this.remove();
			//remove the popup as well
			//$$('.toggleTgtCentre').setStyles({visibility:'hidden',opacity:0});
        },
        'mousedown': function(){
            //aaa
        }
    },
		'id' : 'overlay_'


});

mynew.injectInside(document.body)

};

function rating(el){

//ok set the value of the hidden field on the form

var stars = el.id.match(/\d+/);
$('aRating').value = stars;
$('aRatingNew').value = stars;

}

function saveNotes(){
	//pick up all the form elements
	//alert('/admin/ajax_saveNotes.htm?'+$('notesform').toQueryString())
		var myRequest = new Request({
			url:'/admin/ajax_saveNotes.htm',
			method: 'post',
			data: {'eVolID':$('NVolID').value, 'Notes':$('NNotes').value},
			onComplete: function(){
				//lets get rid of that column
				$('open_notesform').fade('out')
				//update notes if they exist
				upEl = $('volNotesText')
				if($chk(upEl)){
					upEl.empty;
					upEl.set('html', $('NNotes').value);
				};
//Sets the "disabled" property to true, along with the attribute.

			}									
									
		});
		myRequest.send();

return false
};



function sendText(){
	//pick up all the form elements
	//alert('ajax_sendtext.htm?'+$('textform').toQueryString()+'&tFromYou=0')
		var myRequest = new Request({
			url:'/admin/ajax_sendtext.htm',
			method: 'post',
			data:  {tMessage : $('tMessage').value , tNumber : $('tNumber').value, tVolID : $('tVolID').value, tFromYou : 0},
			onComplete: function(responseText){
				alert(responseText);
				//lets get rid of that column
				$('open_textmessageform').fade('out');
			}									
									
		});
		//alert('About to send the text request')
		myRequest.send();

return false
}


function sendTextProvider(){
	//pick up all the form elements
	//alert('ajax_sendtext.htm?'+$('textform').toQueryString()+'&tFromYou=0')
		var myRequest = new Request({
			url:'/admin/ajax_sendtext.htm',
			method: 'post',
			data:  {tMessage : $('tMessage').value , tNumber : $('tNumber').value, tVolID : $('tVolID').value, tFromYou : 0},
			onComplete: function(responseText){
				alert(responseText);
				//lets get rid of that column
				$('open_textmessageform').fade('out');
			}									
									
		});
		//alert('About to send the text request')
		myRequest.send();

return false
}


function sendEmailFromProvider(){
	//pick up all the form elements
	
	url = '/providers/ajax_sendemail_from_provider.htm?'+$('emailform').toQueryString()
	//alert(url)
	var myRequest = new Request({
		//maintain this link as non relative so it
		//can pick up the provider/admin or regular version of the ajax file
		url:'/providers/ajax_sendemail_from_provider.htm',
		method: 'post',
		data:  {eMessage : $('eMessage').value , eSubject : $('eSubject').value, ePID : $('ePID').value, eToAddress : $('eToAddress').value },

		onComplete: function(responseText){
		//lets get rid of that form
		$('open_emailform').fade('out');
		}
							
	});
	myRequest.send();


return false;

};

function sendEmailToProvider(){
	//pick up all the form elements
	
	//alert(url)
	var myRequest = new Request({
		//maintain this link as non relative so it
		//can pick up the provider/admin or regular version of the ajax file
		url:'/ajax_sendemail_to_provider.htm',
		method: 'post',
		data:  {ePMessage : $('ePMessage').value , ePSubject : $('ePSubject').value,  ePVolID : $('ePVolID').value, ePID : $('ePID').value, ePEmail : $('ePEmail').value },

		onComplete: function(responseText){
		//lets get rid of that form
		$('open_emailformprov').fade('out');
		}
							
	});
	myRequest.send();


return false;

};


function sendEmailFromCoach(){
	//pick up all the form elements
	
	url = '/coaches/ajax_sendemail_from_coach.htm?'+$('emailform').toQueryString()
	//alert(url)
	var myRequest = new Request({
		//maintain this link as non relative so it
		//can pick up the provider/admin or regular version of the ajax file
		url:'/coaches/ajax_sendemail_from_coach.htm',
		method: 'post',
		data:  {eMessage : $('eMessage').value , eSubject : $('eSubject').value, eCID : $('eCID').value, eToAddress : $('eToAddress').value },

		onComplete: function(responseText){
		//lets get rid of that form
		$('open_emailform').fade('out');
		}
							
	});
	myRequest.send();


return false;

};


function sendEmailFromSchool(){
	//pick up all the form elements
	url = '/schools/ajax_sendemail_from_school.htm?'+$('emailform').toQueryString()
	//alert(url)
	var myRequest = new Request({
		//maintain this link as non relative so it
		//can pick up the provider/admin or regular version of the ajax file
		url:'/schools/ajax_sendemail_from_school.htm',
		method: 'post',
		data:  {eMessage : $('eMessage').value , eSubject : $('eSubject').value, eScID : $('eScID').value, eToAddress : $('eToAddress').value },

		onComplete: function(responseText){
		//lets get rid of that form
		$('open_emailform').fade('out');
		}
							
	});
	myRequest.send();


return false;

};


function sendEmail(){
	//pick up all the form elements
	
	var myRequest = new Request({
		//maintain this link as non relative so it
		//can pick up the provider/admin or regular version of the ajax file
		url:'ajax_sendemail.htm',
		method: 'post',
		data:  {eMessage : $('eMessage').value , eSubject : $('eSubject').value, eVolID : $('eVolID').value},

		onComplete: function(returned){
		//lets get rid of that form
		$('open_emailform').fade('out');
		}
							
	});
	myRequest.send();


return false

};



function sendInterview(){
	
	//alert('/admin/ajax_sendinterview.htm'+$('interviewform').toQueryString());

	//pick up all the form elements
		var myRequest = new Request({
			url:'/admin/ajax_sendinterview.htm',
			method: 'post',
			onComplete: function(){
				//lets get rid of that column
				$('open_interviewform').tween('opacity',0)
				rowid = $('iVolID').value
				
				//this only works on the induction search page, on the other pages you dont want to remove the row so it isnt called interviewrow
				myel = $('interviewrow_'+rowid)
				if(myel){ myel.dispose(); }
				
			}									
									
		});
		myRequest.send($('interviewform').toQueryString());

return false
}

//just a little thing for setting the selected value of a menu when you dont know the index
function setSelectedIndex(menuO, menuV) {
    for ( var i = 0; i < menuO.options.length; i++ ) {
        if ( menuO.options[i].value == menuV ) {
            menuO.options[i].selected = true;
            return;
        }
    }
}

function confirmFormSubmit(message)
{
var agree=confirm(message+'\n\nAre you sure you wish to continue and make these changes..?');
if (agree){return true}else{return false}
}


/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Joseph Myers | http://www.codelib.net/ */

function colorscale(hexstr, scalefactor) {
/* declared variables first, in order;
  afterwards, undeclared local variables */
  var r = scalefactor;
  var a, i;
  
  if (r < 0 || typeof(hexstr) != 'string')
    return hexstr;
    hexstr = hexstr.replace(/[^0-9a-f]+/ig, '');
    if (hexstr.length == 3) {
    a = hexstr.split('');
  } else if (hexstr.length == 6) {
    a = hexstr.match(/(\w{2})/g);
  } else
    return hexstr;
  for (i=0; i<a.length; i++) {
    if (a[i].length == 2)
      a[i] = parseInt(a[i], 16);
    else {
      a[i] = parseInt(a[i], 16);
      a[i] = a[i]*16 + a[i];
  }
}

var maxColor = parseInt('ff', 16);

function relsize(a) {
  if (a == maxColor)
  return Infinity;
  return a/(maxColor-a);
}

function relsizeinv(y) {
  if (y == Infinity)
  return maxColor;
  return maxColor*y/(1+y);
}

for (i=0; i<a.length; i++) {
  a[i] = relsizeinv(relsize(a[i])*r);
  a[i] = Math.floor(a[i]).toString(16);
  if (a[i].length == 1)
  a[i] = '0' + a[i];
}
return a.join('');
}


/**
 * Roar - Notifications
 *
 * Inspired by Growl
 *
 * @version		1.0.1
 *
 * @license		MIT-style license
 * @author		Harald Kirschner <mail [at] digitarald.de>
 * @copyright	Author
 */

var Roar = new Class({

	Implements: [Options, Events, Chain],

	options: {
		duration: 3000,
		position: 'upperLeft',
		container: null,
		bodyFx: null,
		itemFx: null,
		margin: {x: 10, y: 10},
		offset: 10,
		className: 'roar',
		onShow: $empty,
		onHide: $empty,
		onRender: $empty
	},

	initialize: function(options) {
		this.setOptions(options);
		this.items = [];
		this.container = $(this.options.container) || document;
	},

	alert: function(title, message, options) {
		var params = Array.link(arguments, {title: String.type, message: String.type, options: Object.type});
		var items = [new Element('h3', {'html': $pick(params.title, '')})];
		if (params.message) items.push(new Element('p', {'html': params.message}));
		return this.inject(items, params.options);
	},

	inject: function(elements, options) {
		if (!this.body) this.render();
		options = options || {};

		var offset = [-this.options.offset, 0];
		var last = this.items.getLast();
		if (last) {
			offset[0] = last.retrieve('roar:offset');
			offset[1] = offset[0] + last.offsetHeight + this.options.offset;
		}
		var to = {'opacity': 1};
		to[this.align.y] = offset;

		var item = new Element('div', {
			'class': this.options.className,
			'opacity': 0
		}).adopt(
			new Element('div', {
				'class': 'roar-bg',
				'opacity': 0.7
			}),
			elements
		);

		item.setStyle(this.align.x, 0).store('roar:offset', offset[1]).set('morph', $merge({
			unit: 'px',
			link: 'cancel',
			onStart: Chain.prototype.clearChain,
			transition: Fx.Transitions.Back.easeOut
		}, this.options.itemFx));

		var remove = this.remove.create({
			bind: this,
			arguments: [item],
			delay: 10
		});
		this.items.push(item.addEvent('click', remove));

		if (this.options.duration) {
			var over = false;
			var trigger = (function() {
				trigger = null;
				if (!over) remove();
			}).delay(this.options.duration);
			item.addEvents({
				mouseover: function() {
					over = true;
				},
				mouseout: function() {
					over = false;
					if (!trigger) remove();
				}
			});
		}
		item.inject(this.body).morph(to);
		return this.fireEvent('onShow', [item, this.items.length]);
	},

	remove: function(item) {
		var index = this.items.indexOf(item);
		if (index == -1) return this;
		this.items.splice(index, 1);
		item.removeEvents();
		var to = {opacity: 0};
		to[this.align.y] = item.getStyle(this.align.y).toInt() - item.offsetHeight - this.options.offset;
		item.morph(to).get('morph').chain(item.destroy.bind(item));
		return this.fireEvent('onHide', [item, this.items.length]).callChain(item);
	},

	empty: function() {
		while (this.items.length) this.remove(this.items[0]);
		return this;
	},

	render: function() {
		this.position = this.options.position;
		if ($type(this.position) == 'string') {
			var position = {x: 'center', y: 'center'};
			this.align = {x: 'left', y: 'top'};
			if ((/left|west/i).test(this.position)) position.x = 'left';
			else if ((/right|east/i).test(this.position)) this.align.x = position.x = 'right';
			if ((/upper|top|north/i).test(this.position)) position.y = 'top';
			else if ((/bottom|lower|south/i).test(this.position)) this.align.y = position.y = 'bottom';
			this.position = position;
		}
		this.body = new Element('div', {'class': 'roar-body'}).inject(document.body);
		if (Browser.Engine.trident4) this.body.addClass('roar-body-ugly');
		this.moveTo = this.body.setStyles.bind(this.body);
		this.reposition();
		if (this.options.bodyFx) {
			var morph = new Fx.Morph(this.body, $merge({
				unit: 'px',
				chain: 'cancel',
				transition: Fx.Transitions.Circ.easeOut
			}, this.options.bodyFx));
			this.moveTo = morph.start.bind(morph);
		}
		var repos = this.reposition.bind(this);
		window.addEvents({
			scroll: repos,
			resize: repos
		});
		this.fireEvent('onRender', this.body);
	},

	reposition: function() {
		var max = document.getCoordinates(), scroll = document.getScroll(), margin = this.options.margin;
		max.left += scroll.x;
		max.right += scroll.x;
		max.top += scroll.y;
		max.bottom += scroll.y;
		var rel = ($type(this.container) == 'element') ? this.container.getCoordinates() : max;
		this.moveTo({
			left: (this.position.x == 'right')
				? (Math.min(rel.right, max.right) - margin.x)
				: (Math.max(rel.left, max.left) + margin.x),
			top: (this.position.y == 'bottom')
				? (Math.min(rel.bottom, max.bottom) - margin.y)
				: (Math.max(rel.top, max.top) + margin.y)
		});
	}

});

//implement a standard ROAR notification
var roar = new Roar({
	position: 'upperleft',
	duration: 6000 // 6 seconds until message fades out,
});


function alertoverlay(additionalheight){

//create a div
//make it the same size as the browser height (not window height)
//transaprent background
//fade it in
//make sure it has a low z-index
mynew  = new Element('div', {
    'styles': {
        'display': 'block',
        'border': '1px solid black',
		'height' : window.getScrollHeight(),
		'width' : '100%',
		'background' : 'url(/images/background_trans_repeat.png) repeat',
		'position' : 'absolute',
		'top' : '0',
		'left' : '0',
		'z-index' : '0'
	 },
    'events': {
        'click': function(){
            this.dispose();
			//remove the popup as well
			//need to do a search for any with open_ in their name
			//$$('[^=open_]').fadeHide();
			$each($$('.popup'), function(el){
				//alert(el);
				el.fade('out')
			});

        },
        'mousedown': function(){
            //aaa
        }
    },
		'id' : 'overlay_'


});

mynew.injectInside(document.body)
};



