
	//pokEmail constructor
	RPCI.pokEmail = { 
			
		events : [], oMsg : '', noClick : false,
		
		hideForm : function(){RPCI.pokEmail.toggleViews();},
		
		gutz : ''
			+ '<label for="rp_poketo" class="label" >TO:</label>'
			+ '<input type="text" class="text" id="rp_poketo" name="to" /><br/>'
			+ '<label for="rp_pokefrom" class="label" >FROM:</label>'
			+ '<input type="text" class="text" id="rp_pokefrom" name="from" /><br/>'
			+ '<input type="checkbox" name="contact" class="rp_pokecheckbox" id="rp_pokespam" value="true" />'
			+ '<label id="rp_pokewarn" for="rp_pokespam" '
			+ ' title="Click so that the RPCI:Alliance can contact you at your email address" > '
			+ ' Contact me!</label>'
			+ ' <br/>'
			+ ' <input type="button" class="rp_pokebutton" id="rp_pokEsubmit" '
			+ ' name="rp_pokEsubmit" value="GO" /> '
			+ ' <input type="hidden" name="page" value="' + window.location.href + '" />'
		,
					
		init : function(){
			if(RPCI.autoload){	
				if(this.startUp({
					parentNode : '#quicklinks', 
					server : '/Applications/PokEmail/a_pokEmail.asp' })){
					RPCI.autobay['pokEmail'] =  RPCI.pokEmail;
				}
			}
		},	
		
		toggleViews : function(sWhich){
			//toggle view
			
			if(!sWhich){
				if(this.lbl.css('display') != 'block'){this.lbl.show();this.cls.hide();this.form.hide();}			
				else{this.lbl.hide(); this.cls.show(); this.form.show();}
			}else{
				if(sWhich == 'label'){this.lbl.show();this.cls.hide();this.form.hide();}			
				else{this.lbl.hide(); this.cls.show(); this.form.show();}
			}
	         
	    },
	    
	    sendForm : function(){ 
			var form = this.t.form;
			var t = this.t;
			
			
			    
				form['contact'].value = form['contact'].checked;			
				if(form['to'].value.trim() <= 0 || form['from'].value.trim() <= 0){			    
					t.userMessage("Please enter a recipiant(<strong>TO:</strong>) and  a sender(<strong>FROM:</strong>) "
					+   " email address into each field before sending.");	
				}else{						
					t.ajax.data = '?' +
						'contact=' + form['contact'].value + '&' +
						'from=' + escape(form['from'].value) +  '&' +
						'to=' + escape(form['to'].value) + '&'  +
						'page=' + escape(window.location.href);						
					;
									
					//sb bug: sb.ajax.eatForm is having issues in IE 6.0
					//t.ajax.eatForm(form);					
					t.ajax.fetch(); 
				}
			
			
	    }, 
	    
	    showForm : function(){if(!RPCI.pokEmail.noClick)RPCI.pokEmail.toggleViews();},
			
		startUp : function(args){
			var t = this;

			//map args
			for(i in args)if(gettype(this[i]) != 'function')this[i] = args[i];

			//set parent node - manditory
			if(gettype(args.parentNode) == 'string' || gettype(args.parentNode) == 'element'){
			this.parentNode = s$(args.parentNode);				
			}else{return false;}	


			//check for ajax - manditory
			if(!this.server)alert(this.server);
			this.ajax = new ajax({
				url: this.server, handler: function(d){t.gotEm(d)}, 
				method: 'post', debug: 0});
			if(!this.ajax)return false;	 
				

			//set defaults
			this.oMsg = (this.oMsg.trim() == '')?"Email This Page":this.oMsg;
			this.pika = new sc.element({nodeName : 'LI', id : 'rp_pokeball'}); 
			this.lbl = new sc.element({nodeName: 'RP_PIKA', innerHTML : this.oMsg});
			this.cls = new sc.element({nodeName : 'RP_RETREAT', innerHTML : 'X', title: 'Close this form'});			    
			this.form = new sc.element({nodeName: 'FORM', id : 'rp_pokEform', innerHTML : this.gutz});
			this.maxTries = args.maxTries || 3;
			this.tries = 0;
			
			
			
			//thet gangs all here!
			this.lbl.appendTo(this.pika);
			this.cls.appendTo(this.pika);
			this.form.appendTo(this.pika);
			this.pika.appendTo(this.parentNode);
			
			var pushy = $('#rp_pokEsubmit');
			pushy.t = this;
		
			//set starting events		
			this.events['sendForm'] = sc.events.add(pushy, 'click', this.sendForm);
			this.events['showForm'] = events.add(this.lbl, 'click', this.showForm);
			this.events['closeForm'] = events.add(this.cls, 'click', this.hideForm);
			
			//try{this.toggleViews();}catch(e){sc.consol.dump(e);}
			this.toggleViews();

		return true;  
		},	
	    
	    gotEm : function(r){			
		var blam = eval(r);var t = this;var m;
		var sorry = "Sorry your message wasn't sent.  Please check the email addresses and try again";
		var myBad = "Sorry, there seems to be a problem on our end. Please try again later";		
			
			try{
				if(blam.ok){
					this.userMessage(blam.message);
					this.form['to'].value = '';
					this.form['from'].value = '';
					this.form.reset();
				}else{	
					if(this.tries++ >= this.maxTries)sorry = myBad;		
					this.userMessage(sorry);
				}
			}catch(e){sc.console.dump(e);}
		},
		
		userMessage : function(sMsg){
			var label =  this.lbl;var t = this;			
			this.toggleViews('label');label.innerHTML= sMsg;			
					
			this.noClick = true;
			this.lbl.css('cursor', 'default');
			
			sc.timer.wait(5,function(){
				label.innerHTML = t.oMsg;
				t.noClick = false; 
				t.lbl.css('cursor', 'pointer');
			});
		}

	
	}
	
	
	