// assoc edit functions

function showContactForm(mailto, subject, formTitle) {

	pars = encodeURI('mailto=' + mailto + '&subject=' + subject + '&formTitle=' + formTitle);
	new Ajax.Request("inc_ajax.php?action=showContactForm", 
			{
		  		parameters: pars,
		  		onComplete: function(req) {
					$('contactFormBox').innerHTML = req.responseText;
					new Effect.SlideDown('contactFormBox');
				}
			});  		  	
}

function hideContactForm() {
	new Effect.SlideUp('contactFormBox');
	hide('contactFormBox')
}

function contactFormSend() {
	
	formID = 'contactForm';
		
//	var valid = new Validation('contactForm');
//    var result = valid.validate();
//    if (!result) return;

	var pars = Form.serialize($(formID));
	
	//
	formDump = $('contactFormBox').innerHTML;
	$('contactFormBox').innerHTML = '<br /><br/><center><img src="images/working.gif">&nbsp;Sending message</center>';	
	
	new Ajax.Request("inc_ajax.php?action=sendContactForm", 
			{
		  		parameters: pars,
		  		onComplete: function(req) {

					var err = 0;
					if (req.responseText == "-1") {
						$('contactFormBox').innerHTML = formDump;
						alert("Please complete contact form");
						err = 1;
					}
					
					if (req.responseText == "-2") {
						$('contactFormBox').innerHTML = formDump;
						alert("Please enter a valid email address");
						err = 1;
					}

				
		  		 	// sent ok
		  		 	if (req.responseText == "1") {
		  		 	 	$('contactFormBox').innerHTML = '<br /><br /><center>Message Sent</center>';
	 	 				hideContactForm();			
					} 
					else if (err == 0) {
						$('contactFormBox').innerHTML = formDump;
		  		 		alert(req.responseText);
					}
				}
			});  		  	
		
}
