function WireUpIndex()
{
    var formEvents = [
        {"key":"contact_name", "value":"Name"},
        {"key":"contact_name_last", "value":"Name"},
        {"key":"contact_email", "value":"E-mail"},
        {"key":"contact_email_last", "value":"E-mail"},
        {"key":"contact_phone", "value":"Phone (optional)"},
        {"key":"contact_phone_last", "value":"Phone (optional)"},
        {"key":"contact_comments", "value":"Comments"},
        {"key":"contact_comments_last", "value":"Comments"}
    ];

    formEvents.each(function(f) {
        $(f.key).onfocus= function() { ClearCustomBox( f.key, f.value ); }
        $(f.key).onblur= function() { ResetBox( f.key, f.value ); }
    });
    
    $('sliderLeft').onclick = function() { mainScroll.moveLeft(); }
    $('sliderRight').onclick = function() { mainScroll.moveRight(); }
}

function WireUpContact()
{
    var formEvents = [
        {"key":"contact_name", "value":"Name"},
        {"key":"contact_email", "value":"E-mail"},
        {"key":"contact_phone", "value":"Phone (optional)"},
        {"key":"contact_comments", "value":"Comments"},
    ];

    formEvents.each(function(f) {
        $(f.key).onfocus= function() { ClearCustomBox( f.key, f.value ); }
        $(f.key).onblur= function() { ResetBox( f.key, f.value ); }
    });
}

function SubmitContact(source)
{
    if( document.getElementById("contact_name").value == "" || document.getElementById("contact_name").value == "Name" )
    {
        alert( "Please enter your name." );
        document.getElementById("contact_name").focus();
        return( false );
    }

    var EmailRegex = "^[a-zA-Z0-9\-\_\.]+\@[a-zA-Z0-9\-\_\.]+\.[a-zA-Z0-9]+$";
    if( document.getElementById("contact_email").value.search( EmailRegex ) == -1 )
    {
        alert( "The email address you have entered is invalid.  Please try again." );
        document.getElementById("contact_email").focus();
        return( false );
    }

    DoContactPost(source);
    
    return( false );
}

function DoContactPost(source)
{
	var postTo = "/webserv/clientServ.php";
	
	postData  = "function=contactform"
	postData += "&contact_name=" + $('contact_name').value;
	postData += "&contact_email=" + $('contact_email').value;
    postData += "&contact_comments=" + $('contact_comments').value;
    postData += "&contact_phone=" + $('contact_phone').value;
    postData += "&cb1=" + $('cb1').checked;
    postData += "&cb2=" + $('cb2').checked;
    postData += "&cb3=" + $('cb3').checked;
    postData += "&cb4=" + $('cb4').checked;
    postData += "&newsletter=" + $('cb_newsletter').checked;
	postData += "&source=" + source;
	
	new Ajax.Request(postTo, {
			method: 'post',
            postBody: postData,
			onSuccess: 
				function (msg) {
                    alert( "Thanks for contacting us.  Your email has been sent.\n\nWe'll get back to you as soon as we can (normally within a few hours or less).")
				}
		}
	);
}

function NewsletterPost(emailObj)
{
	var EmailRegex = "^[a-zA-Z0-9\-\_\.]+\@[a-zA-Z0-9\-\_\.]+\.[a-zA-Z0-9]+$";
    if( emailObj.value.search( EmailRegex ) == -1 )
    {
        alert( "The email address you have entered is invalid.  Please try again." );
		emailObj.focus();
        return( false );
    }
	
	var postTo = "/webserv.php";
	
	postData  = "function=NewsletterPost"
	postData += "&emailAddress=" + emailObj.value;
	
	new Ajax.Request(postTo, {
			method: 'post',
            postBody: postData,
			onSuccess: 
				function (msg) {
					emailObj.value = "";
                    alert( "Your email has been added.  Thank you for your interest.");
				}
		}
	);
	return(false);
}

function SubmitTestimonial()
{
	if($('firstName').value == "" ) {
		alert("Please type in your first name.");
		return(false);
	}
	
	if($('lastInitial').value == "" ) {
		alert("Please type in your last initial.");
		return(false);
	}
	
	if($('state').value == "" ) {
		alert("Please select the state where you live.");
		return(false);
	}
	
	if($('product').value == "" ) {
		alert("Please select the product you are commenting about.");
		return(false);
	}
	
	if($('comments').value == "" ) {
		alert("Please type in your comments.");
		return(false);
	}


	var postTo = "/webserv.php";
	
	postData  = "function=TestimonialPost"
	postData += "&firstName=" + escape($('firstName').value);
	postData += "&lastInitial=" + escape($('lastInitial').value);
	postData += "&state=" + escape($('state').value);
	postData += "&product=" + escape($('product').value);
	postData += "&comments=" + escape($('comments').value);
	
	new Ajax.Request(postTo, {
			method: 'post',
            postBody: postData,
			onSuccess: 
				function (msg) {
                    alert( "Your testimonial has been submitted. Thank you for your comments.");
				}
		}
	);
	return(false);
}

function SubmitContactForm()
{
	if($('custName').value == "" ) {
		alert("Please type in your name.");
		$('custName').focus();
		return(false);
	}
	
	var EmailRegex = "^[a-zA-Z0-9\-\_\.]+\@[a-zA-Z0-9\-\_\.]+\.[a-zA-Z0-9]+$";
    if( $('custEmail').value.search( EmailRegex ) == -1 )
    {
        alert( "The email address you have entered is invalid.  Please try again." );
		$('custEmail').focus();
        return( false );
    }
	
	if($('comments').value == "" ) {
		alert("Please type in your comments.");
		$('comments').focus();
		return(false);
	}


	var postTo = "/webserv.php";
	
	postData  = "function=ContactFormPost"
	postData += "&custName=" + escape($('custName').value);
	postData += "&custEmail=" + escape($('custEmail').value);
	postData += "&comments=" + escape($('comments').value);
	
	new Ajax.Request(postTo, {
			method: 'post',
            postBody: postData,
			onSuccess: 
				function (msg) {
                    alert( "Your comments have been sent.  Someone will be in contact with you shortly.");
					$('custName').value = "";
					$('custEmail').value = "";
					$('comments').value = "";
				}
		}
	);
	return(false);
}

function ResetBox( curr_box, new_value )
{
    if( document.getElementById( curr_box ).value == "" )
    {
        document.getElementById( curr_box ).value = new_value;
    }
}

function ClearCustomBox( curr_box, origValue )
{
    if( document.getElementById( curr_box ).value == origValue )
    {
        document.getElementById( curr_box ).value = "";
    }
}