var enter = 0;

function clearField (field, defaultvalue)
{
if (field.value==defaultvalue) 
	{
	field.value='';
	}
}

function fillField (field, defaultvalue)
{
if (field.value=='') 
	{
	field.value=defaultvalue;
	}
}

function validateForm ()
{
/*making form pform and making the other variables different from the form element names prevents bugs in IE*/
pform = $('contactform');
pname = pform['name'];
pemail = pform['email'];
pmessage = pform['message'];
reason = pform['reasonForContact'];
pquotemessage = pform['quotemessage'];

var i = 0;
if ($F(pname) == 'What is your name?' || $F(pname) == '')
	{
	$('error').innerHTML = 'I need your name, valid email address and message before this can be sent.';
	pname.setStyle({color: '#FF3377'});
	i = 1;
	}
else {
	pname.setStyle({color: '#FFFFFF'});
	}
	
if ($F(pemail) == 'What is your email address?' || $F(pemail) == '' || $F(pemail).search(/@/) < 1 || $F(pemail).search(/\./) < 1) {
	$('error').innerHTML = 'I need your name, valid email address and message before this can be sent.';
	pemail.setStyle({color: '#FF3377'});
	i = 1;
	}
else {
	pemail.setStyle({color: '#FFFFFF'});
	}
	
if (($F(pmessage) == 'Talk to me.' || $F(pmessage) == '') && $F(reason) != 'would like a quote')
	{
	$('error').innerHTML = 'I need your name, valid email address and message before this can be sent.';
	pmessage.setStyle({color: '#FF3377'});
	i = 1;
	}
else if ($F(reason) == 'would like a quote' && ($F(pquotemessage) == 'Please describe the plan for the website and whatever design specifications you have.' || $F(pquotemessage) == ''))
	{
	$('error').innerHTML = 'I need your name, valid email address and message before this can be sent.';
	pquotemessage.setStyle({color: '#FF3377'});
	i = 1;
	}
else {
	pmessage.setStyle({color: '#FFFFFF'});

	if ($(pquotemessage).visible())
	{pquotemessage.setStyle({color: '#FFFFFF'});}
	}
	
if (i == 0)
	{
	new Ajax.Request('ajax/sendmessage.php', {
	parameters: $('contactform').serialize(),
	onSuccess: function(transport) {    if (transport.responseText.match(/yes/)) 
		{alert ('Your message has been sent successfully!');
		pform.reset();
		$('ifQuote').hide();
		$('comment').show();
		$('error').hide();
		pageTransition ('who');
		
		}
else		{alert ('An error occurred, please try again later!');}
	},
	onFailure: function(fail) 
	{alert ('An error occurred, please try again later!');}
	
	});
}



}



function pageTransition (where) {

changePage(where);

if (enter != 1)
	{
enter = 1;
new Effect.Move($('navigation'), {x : 0, y : -125, mode: 'relative'}); 

new Effect.Fade($('navigation'), {duration: 1.0 });

window.setTimeout(function() {$('smallnavigation').appear({duration: 0.5 });}, 1000);

window.setTimeout(function() {$('navigation').hide();}, 1000);
	}	
	
window.setTimeout(function() {
if (where == 'who')
	{$('whocontent').setOpacity(1);
	Effect.SlideDown('whocontent');}
if (where == 'portfolio')
	{$('portfoliocontent').setOpacity(1);
	Effect.SlideDown('portfoliocontent');}
if (where == 'contact')
	{$('contactcontent').setOpacity(1);
	Effect.SlideDown('contactcontent');}
}, 1000);

/*Clear content if doubled up on same page and corrects whatever transition problems might happen*/
window.setTimeout(function() {
if (where == 'who')
	{
	$('whocontent').show();
	$('whocontent').setOpacity(1.0);
	$('portfoliocontent').hide();
	$('contactcontent').hide();
	}
else if (where == 'portfolio')
	{
	$('portfoliocontent').show();
	$('portfoliocontent').setOpacity(1.0);
	$('whocontent').hide();
	$('contactcontent').hide();
	}
else if (where == 'contact')
	{
	$('contactcontent').show();
	$('contactcontent').setOpacity(1.0);
	$('whocontent').hide();
	$('portfoliocontent').hide();
	}

}, 2100);
}




function changePage(where) {
$('smallwhopage').style.display = (where == 'who') ? 'inline' : 'none';
$('smallwho').style.display = (where != 'who') ? 'inline' : 'none';

$('smallportfoliopage').style.display = (where == 'portfolio') ? 'inline' : 'none';
$('smallportfolio').style.display = (where != 'portfolio') ? 'inline' : 'none';


$('smallcontactpage').style.display = (where == 'contact') ? 'inline' : 'none';
$('smallcontact').style.display = (where != 'contact') ? 'inline' : 'none';

if (where=='who')
{
$('portfoliotitle').hide();
$('contacttitle').hide();
$('whotitle').show();
}
else if (where=='portfolio')
{
$('whotitle').hide();
$('contacttitle').hide();
$('portfoliotitle').show();
}
else if (where=='contact')
{
$('whotitle').hide();
$('portfoliotitle').hide();
$('contacttitle').show();
}

if (Element.visible('whocontent'))
	{
	new Effect.Fade('whocontent', {duration: 1.0 });
	/*Keeps the scroll bar from appearing and disappearing*/
	window.setTimeout(function() {$('whocontent').hide();}, 2000);
	}
if (Element.visible('portfoliocontent'))
	{
	new Effect.Fade('portfoliocontent', {duration: 1.0 });
	window.setTimeout(function() {$('portfoliocontent').hide();}, 2000);
	}
if (Element.visible('contactcontent'))
	{
	new Effect.Fade('contactcontent', {duration: 1.0 });
	window.setTimeout(function() {$('contactcontent').hide();}, 2000);
	}
	
}

function getQuoteForm(divID)
	{
	if (divID.value == 'would like a quote' && !Element.visible('ifQuote')) 
		{
		
		Effect.BlindDown('ifQuote'); $('comment').hide();
		} 
	else if (divID.value != 'would like a quote' && Element.visible('ifQuote'))
		{
		Effect.BlindUp('ifQuote'); $('comment').show();
		}
	}

function lightup(imageobject, opacity)
   {    imageobject.style.MozOpacity=opacity/100;    imageobject.filters.alpha.opacity=opacity;	}
