/*
MNC JavaScript stuff
date: 2010-10-10
author:Mitch Gohman
*/
var SKOUR = {}

SKOUR.email_show = function (event) {
	$("#theLight h2").html('Send Us An Email');
	$("#theLight .content").html('');
	
	var duplicateForm = $("table.emailUs").clone();
	$(duplicateForm).appendTo("#theLight .content");
	
	$("#theLight, #theDark").css({ display:'block' });
	event.preventDefault();
	
}

SKOUR.appoint_show = function (event) {
	$("#theLight h2").html('Make An Appointment');
	$("#theLight .content").html('');
	
	var duplicateForm = $("table.appointments").clone();
	$(duplicateForm).appendTo("#theLight .content");
	
	$("#theLight, #theDark").css({ display:'block' });
	event.preventDefault();
	
}

SKOUR.techQuestions_show = function (event) {
	$("#theLight h2").html('Technical Questions');
	$("#theLight .content").html('');
	
	var duplicateForm = $("table.techQuestions").clone();
	$(duplicateForm).appendTo("#theLight .content");
	
	$("#theLight, #theDark").css({ display:'block' });
	event.preventDefault();
	
}
SKOUR.email_close = function () { $("#theLight, #theDark").css({ display:'none' }); }

SKOUR.email_process = function () { 
	var postFormElements = $('input,textarea','#theLight .emailUs').serialize();
	$.post('proc_formEmail.php',postFormElements, function(data) {
		if (data == 'sent success')
			{
			$("#theLight .content").html('<p>Your email has been sent successfully. A representative get back to you as soon as possible.</p>');	
			}
		}
	);
}

SKOUR.appoint_process = function () { 
	var postFormElements = $('input,textarea','#theLight .appointments').serialize();
	$.post('proc_formAppointment.php',postFormElements, function(data) {
		if (data == 'sent success')
			{
			$("#theLight .content").html('<p>Your <strong>Appointment Request</strong> has been sent successfully. A representative get back to you as soon as possible.</p>');	
			}
		}
	);
}

SKOUR.technical_process = function () { 
	var postFormElements = $('input,textarea','#theLight .techQuestions').serialize();
	$.post('proc_formTechnical.php',postFormElements, function(data) {
		if (data == 'sent success')
			{
			$("#theLight .content").html('<p>Your <strong>Technical Question</strong> has been sent successfully. A representative get back to you as soon as possible.</p>');	
			}
		}
	);
}

SKOUR.email_process_validate = function(event) {
	//check the fields
	var reqFields = $("#theLight .emailUs .required");
	var error = false;
	var feedback = '';
	var validEmail = false;
	var missingField = false;
	
	for (var i = 0; i < reqFields.length; i++)
		{
		var value = $(reqFields[i]).attr('value');
		if (value.length < 1)	
			{
			$(reqFields[i]).addClass('missing');
			missingField = true;
			}
			else
			{
			$(reqFields[i]).removeClass('missing');
			//see if its a valid email
			emailValue = $("#theLight .emailUs .email").attr('value');
			validEmail = SKOUR.isValidEmail(emailValue);
			
			if (!validEmail)
				{
				$(reqFields[i]).addClass('missing');
				missingField = true;
				}
				
			}
		}
	
	
	if (!validEmail)
		{
		feedback += 'The email you provided does not appear to be valid. ';
		error = true;
		$("#theLight .emailUs .email").addClass('missing');
		}
	
	if (missingField)
		{
		feedback += 'You forgot to fill out one of the required fields.';
		error = true;
		}
	
	//do not send form
	if (error)
		{
		event.preventDefault();
		alert(feedback + 'Please check the form and try again.');
		}
		else
		{
		SKOUR.email_process();	
		}
}

SKOUR.appoint_process_validate = function(event) {
	//check the fields
	var reqFields = $("#theLight .appointments .required");
	var error = false;
	var feedback = '';
	var validEmail = false;
	var missingField = false;
	
	for (var i = 0; i < reqFields.length; i++)
		{
		var value = $(reqFields[i]).attr('value');
		if (value.length < 1)	
			{
			$(reqFields[i]).addClass('missing');
			missingField = true;
			}
			else
			{
			$(reqFields[i]).removeClass('missing');
			//see if its a valid email
			emailValue = $("#theLight .appointments .email").attr('value');
			validEmail = SKOUR.isValidEmail(emailValue);
			
			if (!validEmail)
				{
				$(reqFields[i]).addClass('missing');
				missingField = true;
				}
				
			}
		}
	
	
	if (!validEmail)
		{
		feedback += 'The email you provided does not appear to be valid. ';
		error = true;
		$("#theLight .emailUs .email").addClass('missing');
		}
	
	if (missingField)
		{
		feedback += 'You forgot to fill out one of the required fields.';
		error = true;
		}
	
	//do not send form
	if (error)
		{
		event.preventDefault();
		alert(feedback + 'Please check the form and try again.');
		}
		else
		{
		SKOUR.appoint_process();	
		}
}

SKOUR.technical_process_validate = function(event) {
	//check the fields
	var reqFields = $("#theLight .techQuestions .required");
	var error = false;
	var feedback = '';
	var validEmail = false;
	var missingField = false;
	
	for (var i = 0; i < reqFields.length; i++)
		{
		var value = $(reqFields[i]).attr('value');
		if (value.length < 1)	
			{
			$(reqFields[i]).addClass('missing');
			missingField = true;
			}
			else
			{
			$(reqFields[i]).removeClass('missing');
			//see if its a valid email
			emailValue = $("#theLight .techQuestions .email").attr('value');
			validEmail = SKOUR.isValidEmail(emailValue);
			
			if (!validEmail)
				{
				$(reqFields[i]).addClass('missing');
				missingField = true;
				}
				
			}
		}
	
	
	if (!validEmail)
		{
		feedback += 'The email you provided does not appear to be valid. ';
		error = true;
		$("#theLight .emailUs .email").addClass('missing');
		}
	
	if (missingField)
		{
		feedback += 'You forgot to fill out one of the required fields.';
		error = true;
		}
	
	//do not send form
	if (error)
		{
		event.preventDefault();
		alert(feedback + 'Please check the form and try again.');
		}
		else
		{
		SKOUR.technical_process();	
		}
}

SKOUR.isValidEmail = function(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

SKOUR.splashCurrent = 1;

SKOUR.splash_slide = function() {
	$("#splash img").css({'margin-top':'0px'});
	var topImage = $("#splash img:first");	
	
	setTimeout(function() {
			$(topImage).animate({'margin-top':'-312px'},1000,
			function() { 
				$(topImage).appendTo("#splash");
				SKOUR.splash_slide();
			});
		},4000);
}


SKOUR.weServiceFade = function() {
	$("#serviceLogos .featured img:last").fadeTo(1000,0,
		function() { 
			$(this).prependTo("#serviceLogos .featured").css({'opacity':1}); 
			setTimeout(SKOUR.weServiceFade,2000);
			}
		);	
}

