/* Author: 

*/
$(document).ready(function() {

	//////////////////////////////////////////////////////////
	// News Ticker, Quotes Ticker, and Logos Ticker
	//////////////////////////////////////////////////////////
	$('#newsTicker').cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		pause: 1
	});
	$('#quotesTicker').cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		pause: 1, 
		timeout: 7500
	});
	$('#logosTicker').cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		timeout: 2000
	});

	//////////////////////////////////////////////////////////
	// Show/Hide Plugin Settings
	//////////////////////////////////////////////////////////
	// Hide divs for show/hide plugin
	$('.slide').hide();
	// Show more/less links for show/hide plugin
	$('.show_hide').show();
	// Show/Hide Plugin settings
	$('.show_hide').showHide({
		// speed you want the toggle to happen	
		speed: 1000,
		// the animation effect you want. Remove this line if you dont want an effect and if you haven't included jQuery UI
		easing: '',
		// if you dont want the button text to change, set this to 0
		changeText: 1,
		// the button text to show when a div is closed
		showText: '[+] More',
		// the button text to show when a div is open
		hideText: '[-] Less'
	});

	//////////////////////////////////////////////////////////
	// AJAX jQuery Form w/Validation
	// Modified Dec 31, 2011 Paul Harris
	//////////////////////////////////////////////////////////
	$('#submitForm').click(function() {
		$('.error').hide();
		var hasError = false;
		var first_nameVal = $('#first_name').val();
		if (first_nameVal === '') {
			$('#first_name').after('<span class="error">Please enter your first name.</span>');
			hasError = true;
		}
		var last_nameVal = $('#last_name').val();
		if (last_nameVal === '') {
			$('#last_name').after('<span class="error">Please enter your last name.</span>');
			hasError = true;
		}
		var phoneVal = $('#phone').val();
		if (phoneVal === '') {
			$('#phone').after('<span class="error">Please enter your phone number.</span>');
			hasError = true;
		}
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		var emailVal = $('#email').val();
		if (emailVal === '') {
			$('#email').after('<span class="error">Please enter your email address.</span>');
			hasError = true;
		} else if (!emailReg.test(emailVal)) {
			$('#email').after('<span class="error">Please enter a valid email address.</span>');
			hasError = true;
		}
		var companyVal = $('#company').val();
		if (companyVal === '') {
			$('#company').after('<span class="error">Please enter your company name.</span>');
			hasError = true;
		}
		var titleVal = $('#title').val();
		if (titleVal === '') {
			$('#title').after('<span class="error">Please enter your job title.</span>');
			hasError = true;
		}
		var oidVal = $('#oid').val();
		var lead_sourceVal = $('#lead_source').val();
		var contactMethodVal = $('#contactMethod').val();
		var companyCatVal = $('#companyCat').val();
		var serviceVal = $('#service').val();
		var timeFrameVal = $('#timeFrame').val();
		var titleVal = $('#title').val();
		var employeeNumVal = $('#employeeNum').val();		
		var messageVal = $('#message').val();		
		var messageTypeVal = $('#msgType').val();
		if (hasError === false) {
			$(this).hide();
			$('#sendEmail p.buttons').append('<img id="loading" src="../img/form_btn_loading.png" alt="Loading" width="106" height="35">');
			//$.post('../inc/form_sendemail.php', {
			//Changed to SF 1/2/2012
			$.post('../inc/form_sendsf.php', {
				oid: oidVal,
				lead_source: lead_sourceVal,
				first_name: first_nameVal,
				last_name: last_nameVal,
				company: companyVal,
				phone: phoneVal,
				email: emailVal,
				contactMethod: contactMethodVal,
				companyCat: companyCatVal,
				service: serviceVal,
				timeFrame: timeFrameVal,
				title: titleVal,
				employeeNum: employeeNumVal,
				message: messageVal,				
				//msgType redundant - evaluate for removal as cURL uses lead_source for SF
				msgType: messageTypeVal
			}, function(data) {
				$('#sendEmail').slideUp('slow', 'swing', function() {
					$('#sendEmail').replaceWith('<h3>Thank you!</h3><p>Your message was sent to us. We\'ll get back to you as soon as we can.</p>');
				});
			});
		}
		return false;
	});

	//////////////////////////////////////////////////////////
	// AJAX jQuery Form 2 w/Validation for test drive invitation
	// Modified Feb 9, 2012 Paul Harris
	//////////////////////////////////////////////////////////
	$('#submitForm2').click(function() {
		$('.error').hide();
		var hasError = false;	
		
		var first_nameVal_a = $('#first_name_a').val();
		if (first_nameVal_a === '') {
			$('#first_name_a').after('<span class="error">Please enter your first name.</span>');
			hasError = true;
		}
		var last_nameVal_a = $('#last_name_a').val();
		if (last_nameVal_a=== '') {
			$('#last_name_a').after('<span class="error">Please enter your last name.</span>');
			hasError = true;
		}		
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		
		var emailVal = $('#email_a').val();
		if (emailVal === '') {
			$('#email_a').after('<span class="error">Please enter your email address.</span>');
			hasError = true;
		} else if (!emailReg.test(emailVal)) {
			$('#email_a').after('<span class="error">Please enter a valid email address.</span>');
			hasError = true;
		}	
		var first_nameVal_b = $('#first_name_b').val();
		if (first_nameVal_b === '') {
			$('#first_name_b').after('<span class="error">Please enter colleague\'s first name.</span>');
			hasError = true;
		}
		var last_nameVal_b = $('#last_name_b').val();
		if (last_nameVal_b === '') {
			$('#last_name_b').after('<span class="error">Please enter colleague\'s last name.</span>');
			hasError = true;
		}
		var emailVal2 = $('#email_b').val();
		if (emailVal2 === '') {
			$('#email_b').after('<span class="error">Please enter your colleague\'s email address.</span>');
			hasError = true;
		} else if (!emailReg.test(emailVal2)) {
			$('#email_b').after('<span class="error">Please enter a valid email address.</span>');
			hasError = true;
		}
		var messageVal = $('#message').val();		
		var messageTypeVal = $('#msgType').val();
		if (hasError === false) {
			$(this).hide();
			$('#sendEmail2 p.buttons').append('<img id="loading" src="../img/form_btn_loading.png" alt="Loading" width="106" height="35">');
			//$.post('../inc/form_sendemail.php', {
			//Changed to invite 2/9/2012
			$.post('../inc/invite_sendemail.php', {					   
				first_name_a: first_nameVal_a ,
				last_name_a: last_nameVal_a,
				email_a: emailVal,
				first_name_b: first_nameVal_b ,
				last_name_b: last_nameVal_b,				
				email_b: emailVal2,				
				message: messageVal,				
				msgType: messageTypeVal
			}, function(data) {
				//$('#sendEmail2').slideUp('slow', 'swing', function() {
					//$('#sendEmail2').replaceWith('<h3>THANKS FOR SHARING THE SECRET</h3><p>Your invitation to take a Webalo test drive was sent to your colleague, and we\'re extremely grateful for the referral.</p>');
				$('#thankyou').slideUp(2400, 'swing', function() {
					$(this).html('<div class=\"container clearfix\"><div class=\"grid_6\"><h1><strong>THANKS FOR SHARING THE SECRET</strong></h1></div></div><div id=\"sect1\" class=\"container clearfix\"><div class=\"grid_6\"><h2 class=\"stress\">Your invitation to take a Webalo test drive was sent to your colleague, and we\'re extremely grateful for the referral.</h2></div>').slideDown(2400);
					
				});
			});
		}
		return false;
	});
});

   
 
