$(document).ready(function(){
	$("#submitSignup").click(function(){					   				   
		$(".error").hide();
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		
		var nameVal = $("#name").val();
		if((nameVal == '') || (nameVal == 'Name')) {
			var nameError = 'Name';
			hasError = true;
		}
		var companyVal = $("#company").val();
		if((companyVal == '') || (companyVal == 'Company')) {
			var companyError = 'Company';
			hasError = true;
		}
		var phoneVal = $("#phone").val();
		if((phoneVal == '') || (phoneVal == 'Phone Number')) {
			var phoneError ='Phone';
			hasError = true;
		}
		
		var emailVal = $("#email").val();
		if((emailVal == '') || (emailVal == 'Email')) {
			var emailError = 'Email';
			hasError = true;
		} else if(!emailReg.test(emailVal)) {	
			var emailError = 'Email';
			hasError = true;
		}
		
		
		if (hasError == true) {
		  $("#name").before('<span class="error">All fields are required.</span>');
		}
		if(hasError == false) {
			$(this).hide();
			$("#signUp fieldset.buttons").append('<img src="images/loading.gif" alt="Loading" id="loading" />');
			
			$.post("signup_form/sendemail.asp",
   				{ name: nameVal, company: companyVal, phone: phoneVal, email: emailVal },
   					function(data){
						$("#signUp").slideUp("normal", function() {				   
							
							$("#signUp").before('<p>Thank You for submiting your request. Your request will be processed and we will contact you soon.</p>');											
						});
   					}
				 );
		}
		
		return false;
	});


	$("#submitResume").click(function(){					   				   
		$(".error").hide();
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		
		var firstnameVal = $("#firstname").val();
		if((firstnameVal == '') || (firstnameVal == 'First Name')){
			$("#firstname").after('<span class="error"><br />You forgot to enter your first name.</span>');
			hasError = true;
		}
		var lastnameVal = $("#lastname").val();
		if((lastnameVal == '') || (lastnameVal == 'Last Name')) {
			$("#lastname").after('<span class="error"><br />You forgot to enter your last name.</span>');
			hasError = true;
		}
		var addressVal = $("#address").val();
		if((addressVal == '') || (addressVal == 'Address')) {
			$("#address").after('<span class="error"><br />You forgot to enter your address.</span>');
			hasError = true;
		}
		var cityVal = $("#city").val();
		if((cityVal == '') || (cityVal == 'City')) {
			$("#city").after('<span class="error"><br />You forgot to enter your city.</span>');
			hasError = true;
		}
		var stateVal = $("#state").val();
		if((stateVal == '') || (stateVal == 'State')) {
			$("#state").after('<span class="error"><br />You forgot to enter your state.</span>');
			hasError = true;
		}
		var zipVal = $("#zip").val();
		if((zipVal == '') || (zipVal == 'Zipcode')) {
			$("#zip").after('<span class="error"><br />You forgot to enter your zipcode.</span>');
			hasError = true;
		}
		var resphoneVal = $("#resphone").val();
		if((resphoneVal == '') || (resphoneVal == 'Phone Number')) {
			$("#resphone").after('<span class="error"><br />You forgot to enter your phone number.</span>');
			hasError = true;
		}
		
		var resemailVal = $("#resemail").val();
		if((resemailVal == '') || (resemailVal == 'Email')){
			$("#resemail").after('<span class="error"><br />You forgot to enter your email address.</span>');
			hasError = true;
		} else if(!emailReg.test(resemailVal)) {	
			$("#resemail").after('<span class="error"><br />Enter a valid email address.</span>');
			hasError = true;
		}
		var resumeVal = $("#resume1").val();
		if((resumeVal == '') || (resumeVal == 'Please enter your resume here.')) {
			$("#resume").after('<span class="error"><br />You forgot to enter your resume.</span>');
			hasError = true;
		}
		if(hasError == false) {
			$(this).hide();
			$("#resume fieldset.buttons").append('<img src="images/loading.gif" alt="Loading" id="loading" />');
			
			$.post("resume/sendemail.asp",
   				{ firstname: firstnameVal, lastname: lastnameVal, address: addressVal, city: cityVal, state: stateVal, zip: zipVal, resphone: resphoneVal, resemail: resemailVal, resume1: resumeVal },
   					function(data){
						$("#resume").slideUp("normal", function() {				   
							
							$("#resume").before('<p>Thank You for submiting your resume and interest in Southern Logistics Group. Your resume will be reviewed and matched up with our current job openings.</p>');											
						});
   					}
				);
		}
		return false;
	});


$("#submitTruckload").click(function(){					   				   
		$(".error").hide();
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		
		var TsubmittedByVal = $("#TsubmittedBy").val();
		if((TsubmittedByVal == '') || (TsubmittedByVal == 'Submitted By')) {
			$("#TsubmittedBy").after('<span class="error"><br />You forgot to enter your name.</span>');
			hasError = true;
		}
		var TtypeVal = $("#Ttype").val();
		if(TtypeVal == ''){
			$("#Ttype").after('<span class="error"><br />Please select the type of shipments.</span>');
			hasError = true;
		}
		var TcustVal = $("#Tcust").val();
		if((TcustVal == '') || (TcustVal == 'Customer Name')) {
			$("#Tcust").after('<span class="error"><br />You forgot to enter the customer name.</span>');
			hasError = true;
		}
		var TreferredbyVal = $("#Treferredby").val();
		if(TreferredbyVal == ''){
			$("#Treferredby").after('<span class="error"><br />All fields are required.</span>');
			hasError = true;
		}
		var TpocnameVal = $("#Tpocname").val();
		if((TpocnameVal == '') || (TpocnameVal == 'Point of Contact Name')) {
			$("#Tpocname").after('<span class="error"><br />All fields are required.</span>');
			hasError = true;
		}
		var TpocnumberVal = $("#Tpocnumber").val();
		if((TpocnumberVal == '') || (TpocnumberVal == 'Point of Contact Number')) {
			$("#Tpocnumber").after('<span class="error"><br />All fields are required.</span>');
			hasError = true;
		}
		var TpocemailVal = $("#Tpocemail").val();
		if((TpocemailVal == '') || (TpocemailVal == 'Point of Contact Number')) {
			$("#Tpocemail").after('<span class="error"><br />I need to know an email address for the customer.</span>');
			hasError = true;
		} else if(!emailReg.test(TpocemailVal)){	
			$("#Tpocemail").after('<span class="error"><br />Enter a valid email address.</span>');
			hasError = true;
		}
		var ThowVal = $("#Thow").val();
		if(ThowVal == ''){
			$("#Thow").after('<span class="error"><br />All fields are required.</span>');
			hasError = true;
		}
		var TfrequencyVal = $("#Tfrequency").val();
		if(TfrequencyVal == ''){
			$("#Tfrequency").after('<span class="error"><br />All fields are required.</span>');
			hasError = true;
		}
		var TcommodityVal = $("#Tcommodity").val();
		if((TcommodityVal == '') || (TcommodityVal == 'Main commodity shipped')){
			$("#Tcommodity").after('<span class="error"><br />All fields are required.</span>');
			hasError = true;
		}
		TcommentsVal = $("#Tcomments").val();
		

		if(hasError == false) {
			$(this).hide();
			$("#Truckload fieldset.buttons").append('<img src="images/loading.gif" alt="Loading" id="loading" />');
			
			$.post("truckload_form/sendemail.asp",
   				{ Tsubmittedby: TsubmittedByVal,Ttype: TtypeVal,Tcust: TcustVal,Treferredby: TreferredbyVal,Tpocname: TpocnameVal,Tpocnumber: TpocnumberVal,Tpocemail: TpocemailVal,Thow: ThowVal,Tfrequency: TfrequencyVal,Tcommodity: TcommodityVal,Tcomments: TcommentsVal },
   					function(data){
						$("#Truckload").slideUp("normal", function() {				   
							
							$("#Truckload").before('<p>Request for truckload shipping has been processed.  Partnered Logistics Company will contact the customer directly for additional information.</p>');											
						});
   					}
				);
		}
		return false;
	});


$("#submitFuel").click(function(){					   				   
		$(".error").hide();
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		
		var FsubmittedByVal = $("#FsubmittedBy").val();
		if((FsubmittedByVal == '') || (FsubmittedByVal == 'Submitted By')) {
			$("#FsubmittedBy").after('<span class="error"><br />You forgot to enter your name.</span>');
			hasError = true;
		}
		var FtypeVal = $("#Ftype").val();
		if(FtypeVal == ''){
			$("#Ftype").after('<span class="error"><br />Please select the Product(s) Needed.</span>');
			hasError = true;
		}
		var FcustVal = $("#Fcust").val();
		if((FcustVal == '') || (FcustVal == 'Customer Name')) {
			$("#Fcust").after('<span class="error"><br />You forgot to enter the customer name.</span>');
			hasError = true;
		}
		var FreferredbyVal = $("#Freferredby").val();
		if(FreferredbyVal == ''){
			$("#Freferredby").after('<span class="error"><br />All fields are required.</span>');
			hasError = true;
		}
		var FpocnameVal = $("#Fpocname").val();
		if((FpocnameVal == '') || (FpocnameVal == 'Point of Contact Name')) {
			$("#Fpocname").after('<span class="error"><br />All fields are required.</span>');
			hasError = true;
		}
		var FpocnumberVal = $("#Fpocnumber").val();
		if((FpocnumberVal == '') || (FpocnumberVal == 'Point of Contact Number')) {
			$("#Fpocnumber").after('<span class="error"><br />All fields are required.</span>');
			hasError = true;
		}
		var FpocemailVal = $("#Fpocemail").val();
		if((FpocemailVal == '') || (FpocemailVal == 'Point of Contact Number')) {
			$("#Fpocemail").after('<span class="error"><br />I need to know an email address for the customer.</span>');
			hasError = true;
		} else if(!emailReg.test(FpocemailVal)){	
			$("#Fpocemail").after('<span class="error"><br />Enter a valid email address.</span>');
			hasError = true;
		}
		var FproductsVal = $("#Fproducts").val();
		if((FproductsVal == '') || (FproductsVal == 'I need to know current oil products')){
			$("#Fproducts").after('<span class="error"><br />All fields are required.</span>');
			hasError = true;
		}
		FcommentsVal = $("#Fcomments").val();
		

		if(hasError == false) {
			$(this).hide();
			$("#Fuel fieldset.buttons").append('<img src="images/loading.gif" alt="Loading" id="loading" />');
			
			$.post("fuel_form/sendemail.asp",
   				{ Fsubmittedby: FsubmittedByVal,Ftype: FtypeVal,Fcust: FcustVal,Freferredby: FreferredbyVal,Fpocname: FpocnameVal,Fpocnumber: FpocnumberVal,Fpocemail: FpocemailVal,Fproducts: FproductsVal,Fcomments: FcommentsVal },
   					function(data){
						$("#Fuel").slideUp("normal", function() {				   
							
							$("#Fuel").before('<p>Request for Commercial and Automotive Oil/Fuel Products has been processed.  Partnered Logistics Company will contact the customer directly for additional information.</p>');											
						});
   					}
				);
		}
		return false;
	});

	$("#submitAnalysis").click(function(){
		$(".error").hide();
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		
		var submittedByVal = $("#submittedBy").val();
		if(submittedByVal == ''){
			$("#submittedBy").after('<span class="error"><br />I need to know who submitted this form.</span>');
			hasError = true;
		}
		var agentVal = $("#agent").val();
		if(agentVal == ''){
			$("#agent").after('<span class="error"><br />I need to know who the agent is.</span>');
			hasError = true;
		}
		var custVal = $("#cust").val();
		if(custVal == ''){
			$("#cust").after('<span class="error"><br />I need to know who the customer is.</span>');
			hasError = true;
		}
		var custConVal = $("#custCon").val();
		if(custConVal == ''){
			$("#custCon").after('<span class="error"><br />I need to know who the customer contact is.</span>');
			hasError = true;
		}
		var custConTitleVal = $("#custConTitle").val();
		if(custConTitleVal == ''){
			$("#custConTitle").after('<span class="error"><br />I need to know what the title is for the customer contact.</span>');
			hasError = true;
		}
		var custConAddressVal = $("#custConAddress").val();
		if(custConAddressVal == ''){
			$("#custConAddress").after('<span class="error"><br />I need to know the address for the customer.</span>');
			hasError = true;
		}
		var custConCityVal = $("#custConCity").val();
		if(custConCityVal == ''){
			$("#custConCity").after('<span class="error"><br />I need to know the city for the customer.</span>');
			hasError = true;
		}
		var custConStateVal = $("#custConState").val();
		if((custConStateVal == '') || (custConStateVal == 'Select State')){
			$("#custConState").after('<span class="error"><br />I need to know the state for the customer.</span>');
			hasError = true;
		}
		var custConZipVal = $("#custConZip").val();
		if(custConZipVal == ''){
			$("#custConZip").after('<span class="error"><br />I need to know the zip code for the customer.</span>');
			hasError = true;
		}
		var custConPhoneVal = $("#custConPhone").val();
		if(custConPhoneVal == ''){
			$("#custConPhone").after('<span class="error"><br />I need to know the phone number for the customer.</span>');
			hasError = true;
		}
		var custConEmailVal = $("#custConEmail").val();
		if(custConEmailVal == ''){
			$("#custConEmail").after('<span class="error"><br />I need to know an email address for the customer.</span>');
			hasError = true;
		} else if(!emailReg.test(custConEmailVal)) {	
			$("#custConEmail").after('<span class="error"><br />Enter a valid email address.</span>');
			hasError = true;
		}
		
		var custCategoryVal = $("#custCategory").val();
		if((custCategoryVal == '') || (custCategoryVal == 'Select Category')){
			$("#custCategory").after('<span class="error"><br />I need to know the category to place the customer in.</span>');
			hasError = true;
		}
		
		var parentcoynVal = $("input[name='parentcoyn']:checked").val();
		
		  if ( parentcoynVal  == 0 ){
				var parentCompanyVal = $("#parentCompany").val();
					if(parentCompanyVal == ''){
					$("#parentCompany").after('<span class="error"><br />I need to know the name of the parent company.</span>');
					hasError = true;
				}
				var parentCompanyConVal = $("#parentCompanyCon").val();
					if(parentCompanyConVal == ''){
					$("#parentCompanyCon").after('<span class="error"><br />I need to know the name of the contact at the parent company.</span>');
					hasError = true;
				}
				var parentCompanyAddressVal = $("#parentCompanyAddress").val();
					if(parentCompanyAddressVal == ''){
					$("#parentCompanyAddress").after('<span class="error"><br />I need to know the address of the parent company.</span>');
					hasError = true;
				}
				var parentCompanyCityVal = $("#parentCompanyCity").val();
					if(parentCompanyCityVal == ''){
					$("#parentCompanyCity").after('<span class="error"><br />I need to know what city the parent company is in.</span>');
					hasError = true;
				}
				
				var parentComapnyZipVal = $("#parentComapnyZip").val();
					if(parentComapnyZipVal == ''){
					$("#parentComapnyZip").after('<span class="error"><br />I need to know the zip code for the parent company.</span>');
					hasError = true;
				}
				var parentCompanyPhoneVal = $("#parentCompanyPhone").val();
					if(parentCompanyPhoneVal == ''){
					$("#parentCompanyPhone").after('<span class="error"><br />I need to know the phone number for the parent company.</span>');
					hasError = true;
				}
		}
		// Grab all the other variables and pass them
		custConAddressVal2 = $("#custConAddress2").val();
		custConStateVal = $("#custConState").val();
		custConFaxVal = $("#custConFax").val();
		custConSiteVal = $("#custConSite").val();
		custCategoryVal = $("#custCategory").val();
		locationsVal = $("#locations").val();
		monthlyPotVal = $("#monthlyPot").val();
		yearlyPotVal = $("#yearlyPot").val();
		hazardousMatVal = $("#hazardousMat").val();
		resiDeliveryVal = $("#resiDelivery").val();
		sortSegregateVal = $("#sortSegregate").val();
		liftGateVal = $("#liftGate").val();
		insidedeliveryVal = $("#insidedelivery").val();
		overLengthVal = $("#overLength").val();
		internationalexpediteVal = $("#internationalexpedite").val();
		softwaresolutionsVal = $("#softwaresolutions").val();
		ltlvolumeVal = $("#ltlvolume").val();
		postauditVal = $("#postaudit").val();
		spotquoteVal = $("#spotquote").val();
		otherServiceVal = $("#otherService").val();
		commentsVal = $("#comments").val();
		tariffsVal = $("#tariffs").val();
		billsVal = $("#bills").val();
		parentCompanyTitleVal = $("#parentCompanyTitle").val();
		parentCompanyAddressVal2 = $("#parentCompanyAddress2").val();
		parentcoStateMenuVal = $("#parentcoStateMenu").val();
		parentCompanyFaxVal = $("#parentCompanyFax").val();
		parentCompanyEmailVal = $("#parentCompanyEmail").val();
		parentCompanySiteVal = $("#parentCompanySite").val();
		

	if(hasError == false) {
		$(this).hide();
		$("#Analysis fieldset.buttons").append('<img src="images/loading.gif" alt="Loading" id="loading" />');
			
		$.post("analysis/sendemail.asp",
   			{ submittedBy:submittedByVal,agent:agentVal,cust:custVal,custCon:custConVal,custConTitle:custConTitleVal,custConAddress:custConAddressVal,custConCity:custConCityVal,custConState:custConStateVal,custConZip:custConZipVal,custConPhone:custConPhoneVal,custContEmail:custConEmailVal,custCategory:custCategoryVal,parentcoyn:parentcoynVal,parentCompany:parentCompanyVal,parentCompanyCon:parentCompanyConVal,parentCompanyAddress1:parentCompanyAddressVal,parentCompanyCity:parentCompanyCityVal,parentCompanyZip:parentComapnyZipVal,parentCompanyPhone:parentCompanyPhoneVal,custConAddress2:custConAddressVal2,custConState:custConStateVal,custConFax:custConFaxVal,custConSite:custConSiteVal,custCategory:custCategoryVal,locations:locationsVal,monthlyPot:monthlyPotVal,yearlyPot:yearlyPotVal,hazardousMat:hazardousMatVal,resiDelivery:resiDeliveryVal,sortSegregate:sortSegregateVal,liftGate:liftGateVal,insidedelivery:insidedeliveryVal,overLength:overLengthVal,internationalexpedite:internationalexpediteVal,softwaresolutions:softwaresolutionsVal,ltlvolume:ltlvolumeVal,postaudit:postauditVal,spotquote:spotquoteVal,otherService:otherServiceVal,comments:commentsVal,tariffs:tariffsVal,bills:billsVal,parentCompanyTitle:parentCompanyTitleVal,parentCompanyAddress2:parentCompanyAddressVal2,parentcoStateMenu:parentcoStateMenuVal,parentCompanyFax:parentCompanyFaxVal,parentCompanyEmail:parentCompanyEmailVal,parentCompanySite:parentCompanySiteVal } ,
   			   function(data){
					$("#Analysis").slideUp("normal", function() {				   
						
						$("#Analysis").before('<p>Request for Pre-Analysis has been processed. Please allow 7-10 business days for completion.</p>');											
					});
   				}
			);
		}
		return false;
	});
	
	$("input[name=parentcoyn]").click(function() {
    
		var selected = $(":checked", this).val();  // get value of checked radio button
    
    	if (this.value == 0) {
			 $("#owned").slideDown("normal")
		} 
		else{
			$("#owned").slideUp("normal")
		}
	});

	
	
});
