// JavaScript Document

function sendOneNet()
{
	var nameValue = $("#onenet_FirstName").val();
	var surnameValue = $("#onenet_surname").val();
	var emailValue = $("#onenet_email").val();
	var subjectValue = $("#onenet_subject").val();
	var messageValue = $("#onenet_message").val();
	
	if(checkEmail(emailValue) || nameValue == '' || surnameValue == '') {
		$("#onenetFeedback").addClass('redbold');
	}else{
		$.post('lib/php/sendEmail.php',{name: nameValue, surname: surnameValue, email: emailValue, subject: subjectValue, message: messageValue, type: 'onenet'},function(data){
																																  
			if(data == 'email success'){
				$("#contactForm").html("Your message has been sent");
			}else{
				$("#contactForm").html("Sorry there seems to have been a problem completing your request. Please refresh and try again.");
			}
			
			$("#onenetFeedback").removeClass('red');
			
			$("#onenet_FirstName").val('');
			$("#onenet_surname").val('');
			$("#onenet_email").val('');
			$("#onenet_subject").val('');
			$("#onenet_message").val('');
			
		});
	}
}


function sendCareersContact()
{
	var nameValue = $("#CareerName").val();
	var surnameValue = $("#CareerSurname").val();
	var emailValue = $("#CareerEmail").val();
	var telephoneValue = $("#CareerTelephone").val();
	var townValue = $("#CareerTown").val();
	var messageValue = $("#CareerMessage").val();

	if(checkEmail(emailValue) || nameValue == '' || surnameValue == '' || townValue == '') {
		$("#CareersContactFeedback").addClass('redbold');
	}else{
		$.post('lib/php/sendEmail.php',{name: nameValue, surname: surnameValue, email: emailValue, telephone: telephoneValue, Town: townValue, Message: messageValue, type: 'Careers'},function(data){
																																  
			if(data == 'email success'){
				$("#careersContactForm").html("Your message has been sent");
			}else{
				$("#careersContactForm").html("Sorry there seems to have been a problem completing your request. Please refresh and try again.");
			}
			
			$("#MobileEmailFeedback").removeClass('red');
			
			$("#CareerName").val('');
			$("#CareerSurname").val('');
			$("#CareerEmail").val('');
			$("#CareerTelephone").val('');
			$("#CareerTown").val('');
			$("#CareerMessage").val('');
			
		});
	}
}


function sendEmailContact()
{
	var nameValue = $("#EmailName").val();
	var surnameValue = $("#EmailSurname").val();
	var organisationValue = $("#EmailOrganisation").val();
	var telephoneValue = $("#EmailTelephone").val();
	var emailValue = $("#EmailEmail").val();
	var subjectValue = $("#EmailSubject").val();
	
	var accessValue = $("#EmailAccess").val();
	var accessadditionalValue = $("#EmailAccessAdditional").val();
	var usersValue = $("#EmailUsers").val();
	var messageValue = $("#Emailmessage").val();

	if(checkEmail(emailValue) || nameValue == '' || surnameValue == '' || accessValue == '' || usersValue == '') {
		$("#MobileEmailFeedback").addClass('redbold');
	}else{
		$.post('lib/php/sendEmail.php',{name: nameValue, surname: surnameValue, organisation: organisationValue, telephone: telephoneValue, EmailAccess: accessValue, subject: subjectValue, message: messageValue, MobileEmailAdditional: accessadditionalValue,  EmailUsers: usersValue, email: emailValue, type: 'MobileEmail'},function(data){
																																  
			if(data == 'email success'){
				$("#MobileEmailForm").html("Your message has been sent");
			}else{
				$("#MobileEmailForm").html("Sorry there seems to have been a problem completing your request. Please refresh and try again.");
			}
			
			$("#MobileEmailFeedback").removeClass('red');
			
			$("#EmailName").val('');
			$("#EmailSurname").val('');
			$("#EmailOrganisation").val('');
			$("#EmailTelephone").val('');
			$("#EmailEmail").val('');
			$("#EmailSubject").val('');
			
			$("#EmailAccess").val('');
			$("#EmailAccessAdditional").val('');
			$("#EmailUsers").val('');
			$("#Emailmessage").val('');
		});
	}
}


function sendEnewsletter()
{
	var nameValue = $("#enews_FirstName").val();
	var surnameValue = $("#enews_surname").val();
	var organisationValue = $("#enews_organisation").val();
	var emailValue = $("#enews_email").val();
	
	if(checkEmail(emailValue) || nameValue == '' || surnameValue == '') {
		$("#enewsFeedback").addClass('redbold');
	}else{
		$.post('lib/php/sendEmail.php',{name: nameValue, surname: surnameValue, organisation: organisationValue, email: emailValue, type: 'Enewsletter'},function(data){
																																  
			if(data == 'email success'){
				$("#enewsletterForm").html("Thank you for signing up to our E-newsletter");
			}else{
				$("#enewsletterForm").html("Sorry there seems to have been a problem completing your request. Please refresh and try again.");
			}
			
			$("#enewsFeedback").removeClass('red');
			
			$("#enews_FirstName").val('');
			$("#enews_surname").val('');
			$("#enews_organisation").val('');
			$("#enews_email").val('');
			
		});
	}
}

function sendCallBack()
{
	var nameValue = $("#callback_first_name").val();
	var surnameValue = $("#callback_surname").val();
	var organisationValue = $("#callback_organisation").val();
	var emailValue = $("#callback_email").val();
	var telephoneValue = $("#callback_telephone").val();
	
	if(checkEmail(emailValue) || nameValue == '' || surnameValue == '' || telephoneValue == '') {
		$("#CallBackFeedback").addClass('redbold');
	}else{
		$.post('lib/php/sendEmail.php',{name: nameValue, surname: surnameValue, telephone: telephoneValue, organisation: organisationValue, email: emailValue, type: 'CallBack'},function(data){
																																  
			if(data == 'email success'){
				$("#callBackForm").html("Your call back request has been sent");
			}else{
				$("#callBackForm").html("Sorry there seems to have been a problem completing your request. Please refresh and try again.");
			}
			
			$("#CallBackFeedback").removeClass('red');
			
			$("#callback_first_name").val('');
			$("#callback_surname").val('');
			$("#callback_organisation").val('');
			$("#callback_email").val('');
			$("#callback_telephone").val('');
			
		});
	}
}

function sendContact()
{
	var nameValue = $("#contact_FirstName").val();
	var surnameValue = $("#contact_surname").val();
	var organisationValue = $("#contact_organisation").val();
	var emailValue = $("#contact_email").val();
	var messageValue = $("#contact_message").val();
	
	if(checkEmail(emailValue) || nameValue == '' || surnameValue == '') {
		$("#ContactFeedback").addClass('redbold');
	}else{
		$.post('lib/php/sendEmail.php',{name: nameValue, surname: surnameValue, organisation: organisationValue, email: emailValue, message: messageValue, type: 'Enquiry'},function(data){
																																  
			if(data == 'email success'){
				$("#contactForm").html("Your message has been sent");
			}else{
				$("#contactForm").html("Sorry there seems to have been a problem completing your request. Please refresh and try again.");
			}
			
			$("#ContactFeedback").removeClass('red');
			
			$("#contact_FirstName").val('');
			$("#contact_surname").val('');
			$("#contact_organisation").val('');
			$("#contact_email").val('');
			$("#contact_message").val('');
			
		});
	}
}

function sendVehicleInstallations()
{
	var nameValue = $("#vehicle_first_name").val();
	var surnameValue = $("#vehicle_surname").val();
	var organisationValue = $("#vehicle_organisation").val();
	var emailValue = $("#vehicle_email").val();
	
	if(checkEmail(emailValue) || nameValue == '' || surnameValue == '') {
		$("#VehicleFeedback").addClass('redbold');
	}else{
		$.post('lib/php/sendEmail.php',{name: nameValue, surname: surnameValue, organisation: organisationValue, email: emailValue, type: 'Vehicle'},function(data){
																																  
			if(data == 'email success'){
				$("#VehicleInstallationsForm").html("Thank you for registering your interest in a vehicle installation quote");
			}else{
				$("#VehicleInstallationsForm").html("Sorry there seems to have been a problem completing your request. Please refresh and try again.");
			}
			
			$("#VehicleFeedback").removeClass('red');
			
			$("#vehicle_first_name").val('');
			$("#vehicle_surname").val('');
			$("#vehicle_organisation").val('');
			$("#vehicle_email").val('');
			
		});
	}
}

function sendProductInfo()
{
	var nameValue = $("#product_FirstName").val();
	var surnameValue = $("#product_surname").val();
	var emailValue = $("#product_email").val();
	var telephoneValue = $("#product_telephone").val();
	var subjectValue = $("#product_subject").val();
	var messageValue = $("#product_message").val();
	var productValue = $("#product_id").val();
	
	if(checkEmail(emailValue) || nameValue == '' || surnameValue == '') {
		$("#ProductFeedback").addClass('redbold');
	}else{
		$.post('lib/php/sendEmail.php',{name: nameValue, surname: surnameValue, email: emailValue, telephone: telephoneValue, subject: subjectValue, message: messageValue, product_id: productValue, type: 'Product'},function(data){
 			if(data == 'email success'){
				$("#ProductInfoForm").html("Thank you for registering your interest, we will get back to you as soon as we can");
			}else{
				$("#ProductInfoForm").html("Sorry there seems to have been a problem completing your request. Please refresh and try again.");
			}
 			$("#ProductFeedback").removeClass('red');
			
 			$("#product_FirstName").val('');
			$("#product_surname").val('');
			$("#product_email").val('');
			$("#product_telephone").val('');
			$("#product_subject").val('');
			$("#product_message").val('');
 			$("#product_id").val('');
		});
	}
}


function sendTariffs()
{
	var nameValue = $("#tariff_name").val();
	var surnameValue = $("#tariff_surname").val();
	var organisationValue = $("#tariff_organisation").val();
	var emailValue = $("#tariff_email").val();
	var telephoneValue = $("#tariff_telephone").val();
	var basedValue = $("#based").val();
	var connectionValue = $("#connections").val();
	var currentValue = $("#current").val();
	var expiryValue = $("#expiry").val();
	var TimeToContactValue = $("#TimeToContact").val();
	
	if(checkEmail(emailValue) || nameValue == '' || surnameValue == '' || organisationValue == '') {
		$("#TariffFeedback").addClass('redbold');
	}else{
		$.post('lib/php/sendEmail.php',{name: nameValue, surname: surnameValue, organisation: organisationValue, email: emailValue, telephone: telephoneValue, based: basedValue, connections: connectionValue, current: currentValue, expiry: expiryValue, TimeToContact: TimeToContactValue, type: 'Tariffs'},function(data){
																																  
			if(data == 'email success'){
				$("#TariffForm").html("Thank you for registering your interest in our tariffs, we will be in contact soon");
			}else{
				$("#TariffForm").html("Sorry there seems to have been a problem completing your request. Please refresh and try again.");
			}
			
			$("#TariffFeedback").removeClass('red');
			
			$("#tariff_name").val('');
			$("#tariff_surname").val('');
			$("#tariff_organisation").val('');
			$("#tariff_email").val('');
			$("#tariff_telephone").val('');
			$("#based").val('');
			$("#connections").val('');
			$("#current").val('');
			$("#expiry").val('');
			$("#TimeToContact").val('');
			
		});
	}
}

function checkEmail(myForm)

{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm)){
		return (false)
	}
	return (true)
}
