/******************
   Accessibility
©2008 DividedMedia
******************/

function writeEmail()
{
	var address = $$('.emailaddress');
	
	if(address)
	{
		for(var i = 0; i < address.length; i++)
		{
			address[i].href	  		= address[i].href.split("-at-").join("@"); 
			address[i].innerHTML	= address[i].innerHTML.split("-at-").join("@");
			
			address[i].href	  		= address[i].href.split("-dot-").join("."); 
			address[i].innerHTML	= address[i].innerHTML.split("-dot-").join(".");
		}
	}
}

function setupTargetLinks()
{
	var arrLinks = $$('a.targetblank');
	
	if(arrLinks)
	{ 
		for(var i = 0; i < arrLinks.length; i++)
		{
			arrLinks[i].set('target', 'blank');
		}
	}
}


function setupForm()
{		
	var arrTextBoxes = $$('input');
	for(var i = 0; i < arrTextBoxes.length; i++)
	{
		if(arrTextBoxes[i].type == 'text')
		{
			addInputEvents(arrTextBoxes[i]);
		}
	}
	
	var arrTextAreas = $$('textarea');
	if(arrTextAreas.length == 1)
	{	
		addInputEvents(arrTextAreas[0]);	
	}
	
	var objForm = $('frmcontact');
	if(objForm)
	{	
		objForm.addEvent('submit', function(e)
									{
										var strErrors = "";
										var bContinue = true;
										
										if($('strName').value == 'name')
										{
											strErrors += "- Your Name\n";
											bContinue = false;
										}									
										if($('strEmail').value == 'email address')
										{
											strErrors += "- Your Email Address\n";
											bContinue = false;
										}								
										/*if($('strPhone').value == 'phone number')
										{
											strErrors += "- Your Phone Number\n";
											bContinue = false;
										}*/	
										if($('strMessage') && $('strMessage').value == 'message')
										{
											strErrors += "- Your Message\n";
											bContinue = false;
										}								
										
										if(!bContinue)
										{
											alert("Please complete the following fields:\n"+strErrors);
											
											if (e && e.preventDefault)
											{
												e.preventDefault();
											}
										}
										
										return bContinue;
									});
	}
}

function addInputEvents(objInput)
{ 
	objInput.label = objInput.value;
	
	objInput.addEvent('focus', function(){
												
													if(this.value == this.label)
													{
														this.value = '';																
													}
												
												});
	
	objInput.addEvent('blur', function(){
												
													if(this.value == '')
													{
														this.value = this.label;																
													}
												
												});	
}



window.addEvent('domready', function()
{
	writeEmail(); 
	setupTargetLinks();	
	
	if((document.location.toString().indexOf("contact-us.php") > -1) ||
	   (document.location.toString().indexOf("join-our-mailing-list.php") > -1))
	{
		setupForm();
	}
});