var url=location.host;
url = "http://"+url+"/";
/*	var myGlobalHandlers = {
		onCreate: function(){
			Element.show('loading');
		},
			
		onComplete: function() {
			if(Ajax.activeRequestCount == 0){
				Element.hide('loading');
		}
		}
	};

	Ajax.Responders.register(myGlobalHandlers);
*/		
function formSubmitter(updateMe,form)
{
	var flag = new Ajax.Updater(updateMe,url+'emailer.php', {parameters: Form.serialize(form) });
/*
	if (flag)
	{
		$(updateMe).update(
						"<h3>Thank you for contacting us!</h3><p>You will be hearing from us very soon.</p><p><a href='javascript:void(0);' onclick='Modalbox.hide(); return false;'>Back to the site!</a></p>"
						);
	}
	else
	{
		$(updateMe).update(
						"<h3>Oh no!  There's been a problem!</h3><p>Please contact us directly at <a href='mailto:support@unconfusing.com'>support@unconfusing.com</a></p>"
						);
		}
*/
}

function email(form)
{
		new Ajax.Updater('message',url+'includes/emailer.php', {  parameters: Form.serialize(form)	} );
		$(form).reset();
	}
	
function makeComment(artid,authid,m)
{
	new Ajax.Updater("makeComment",url+"includes/commentForm.php", {  parameters: { artidfk: artid, m: m, authid: authid  } } );
	}
	
function hider(hidethis)
{
	$(hidethis).hide();
	}
	
function commentSave(form,sec)
{
	
	var valid = new Validation(form, {onSubmit:false});
    var result = valid.validate();
	
	if (result)
	{
	
	if ($F('secure') != sec)
	{
		alert("Please correctly solve the math problem to continue!");
		}
		else
		{
		$('saving').show();
		new Ajax.Updater("readComments",url+'includes/commentSave.php', {  method: "post", evalScripts: true, parameters: Form.serialize(form), onSuccess: function(){
	  $('makeComment').update('<h1>Comment added successfully!</h1>');
	  
	  Element.hide.delay(1, 'makeCommentLink');
	  }
    } );
		}
	}
}

function updateComments()
{
		new Ajax.Updater('readComments',url+'includes/comments.php', {  parameters: { id: $F('artidfk') }	} );
}



function blogSearch(term,caller)
{
	$('searchNotice').show();

		new Ajax.Updater("blogPosts",url+"includes/blogPosts.php", {  parameters: { s: term, f: caller } , onSuccess: function(){
		  $('searchNotice').hide();
		  }				 
		 } );

}

function clearKeywords()
{
		$('searchBox').clear();
		blogSearch('','');
}

function searcher()
{
	kw = $F('searchBox');
	if (kw.length > 2)
	{
		blogSearch($F('searchBox'),'keyword');
		}
}