var url=location.host;
url = "http://"+url+"/";
	
function formSubmitter(updateMe,form)
{
	//var flag = new Ajax.Updater(updateMe,url+'emailer.php', {parameters: Form.serialize(form) });
	$.post(url+'emailer.php', $("#"+form).serialize(), function(data){   $("#"+updateMe).html(data);  });
	
}

function email(form)
{
		//new Ajax.Updater('message',url+'includes/emailer.php', {  parameters: Form.serialize(form)	} );
	var flag = $.post(url+'emailer.php', $("#"+form).serialize(),
   function(data){
     $("#message").html(data);
	 $(form).reset();
   });
		//$(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();
	
	$.post(url+"includes/blogPosts.php",{ s: term, f: caller },function(data){ $('#searchNotice').hide(); $("#blogPosts").html(data); });

}

function clearKeywords()
{
		$('searchBox').clear();
		blogSearch('','');
}

function searcher()
{
	kw = $F('searchBox');
	if (kw.length > 2)
	{
		blogSearch($F('searchBox'),'keyword');
		}
}

$(document).ready(function(){ 
$("#header-searcher").focus(function () { $(this).addClass('searchReady'); }); 
$("#header-searcher").blur(function () { $(this).removeClass('searchReady'); }); 
});

function mainSearch()
{
	
	var n = $("#header-searcher").val();
	var ln = n.length;
	
	if ( ln > 3)
	{ 	
		$.ajax({
		  url: "/includes/searchProcessor.php",
		  type: "POST",
		  data: {q:n},
		success: function(data){ $("#maincontent").html(data); }
   		});	
	}
	
}