﻿function sendCallForm() {

	$("#contact_error_ul").children().remove();
	var hasError = false;


	var name = $("#contact_call_name").val();
	var phonenumber = $("#contact_call_phonenumber").val();
	var message = $("#contact_call_message").val();

	if ((name == '') || ($("#contact_call_name").attr("title") == name)) {
		$("#contact_error_ul").append("<li style='margin-top: 10px; line-height: 15px; color: Red;' class='ui-state-default'><span class='error' style='color: #878787;'>Name</span></li>");
		hasError = true;
	}

	if ((phonenumber == '') || ($("#contact_call_phonenumber").attr("title") == phonenumber)) {
		$("#contact_error_ul").append("<li style='margin-top: 10px; line-height: 15px; color: Red;' class='ui-state-default'><span class='error' style='color: #878787;'>Telefon</span></li>");
		hasError = true;
	}

	if ((message == '') || ($("#contact_call_message").attr("title") == message)) {
		$("#contact_error_ul").append("<li style='margin-top: 10px; line-height: 15px; color: Red;' class='ui-state-default'><span class='error' style='color: #878787;'>Nachricht</span></li>");
		hasError = true;
	}


	if (hasError == false) {
		$.ajax({
			type: "POST",
			url: "/Contact.asmx/CallContact",
			data: "{'name': '" + name + "', 'phonenumber': '" + phonenumber + "', 'message': '" + message + "' }",
			contentType: "application/json; charset=utf-8",
			dataType: "json",

			success: function (msg) {
				$.colorbox({
					width: "400px",
					height: "500px",
					initialWidth: "400px",
					initialHeight: "500px",
					innerWidth: "400px",
					innerHeight: "500px",
					speed: 800,
					inline: true,
					href: "#ajax_contact_success",
					transition: "elastic"
				});

			},
			error: function (msg) {
				$("#contact_error_ul").append("<li style='margin-top: 10px; line-height: 15px; color: Red;' class='ui-state-default'><span class='error' style='color: #878787;'>Das Formular konnte nicht versendet werden. Bitte versuchen Sie es erneut.</span></li>");
				$.colorbox({
					width: "400px",
					height: "500px",
					initialWidth: "400px",
					initialHeight: "500px",
					innerWidth: "400px",
					innerHeight: "500px",
					speed: 800,
					inline: true,
					href: "#ajax_contact_error",
					transition: "elastic"
				});

			}
		});
	}
	else {

		$.colorbox({
			width: "400px",
			height: "500px",
			initialWidth: "400px",
			initialHeight: "500px",
			innerWidth: "400px",
			innerHeight: "500px",
			speed: 800,
			inline: true,
			href: "#ajax_contact_error",
			transition: "elastic"

		});





	}
	return false;

}



function sendDirecForm() {
	$("#contact_error_ul").children().remove();
	var hasError = false;
	//		var emailReg = /^([w-.]+@([w-]+.)+[w-]{2,4})?$/;

	var firstname = $("#contact_first_name").val();
	var lastname = $("#contact_last_name").val();
	var companyname = $("#contact_company_name").val();
	var emailFromVal = $("#contact_email").val();
	var message = $("#contact_message").val();

	if ((firstname == '') || ($("#contact_first_name").attr("title") == firstname)) {
		$("#contact_error_ul").append("<li style='margin-top: 10px; line-height: 15px; color: Red;' class='ui-state-default'><span class='error' style='color: #878787;'>Vorname</span></li>");
		hasError = true;
	}

	if ((lastname == '') || ($("#contact_last_name").attr("title") == lastname)) {
		$("#contact_error_ul").append("<li style='margin-top: 10px; line-height: 15px; color: Red;' class='ui-state-default'><span class='error' style='color: #878787;'>Nachname</span></li>");
		hasError = true;
	}

	if ((companyname == '') || ($("#contact_company_name").attr("title") == companyname)) {
		$("#contact_error_ul").append("<li style='margin-top: 10px; line-height: 15px; color: Red;' class='ui-state-default'><span class='error' style='color: #878787;'>Firma</span></li>");
		hasError = true;
	}

	if ((emailFromVal == '') || ($("#contact_email").attr("title") == emailFromVal)) {
		$("#contact_error_ul").append("<li style='margin-top: 10px; line-height: 15px; color: Red;' class='ui-state-default'><span class='error' style='color: #878787;'>korrekte E-Mail-Adresse, bitte prüfen Sie die Schreibweise</span></li>");
		hasError = true;
	}
	//		else if(!emailReg.test(emailFromVal)) {
	//			$("#contact_email").after('<span class="error">Enter a valid email address to send to.</span>');
	//			hasError = true;
	//		}

	if ((message == '') || ($("#contact_message").attr("title") == message)) {
		$("#contact_error_ul").append("<li style='margin-top: 10px; line-height: 15px; color: Red;' class='ui-state-default'><span class='error' style='color: #878787;'>Nachricht</span></li>");
		hasError = true;
	}

	if (hasError == false) {
		$.ajax({
			type: "POST",
			url: "/Contact.asmx/DirectContact",
			data: "{'first_name': '" + firstname + "', 'last_name': '" + lastname + "', 'company_name': '" + companyname + "', 'email_adress': '" + emailFromVal + "', 'message': '" + message + "' }",
			contentType: "application/json; charset=utf-8",
			dataType: "json",

			success: function (msg) {
				$.colorbox({
					width: "400px",
					height: "500px",
					initialWidth: "400px",
					initialHeight: "500px",
					innerWidth: "400px",
					innerHeight: "500px",
					speed: 800,
					inline: true,
					href: "#ajax_contact_success",
					transition: "elastic"
				});

			},
			error: function (msg) {
				$("#contact_error_ul").append("<li style='margin-top: 10px; line-height: 15px; color: Red;' class='ui-state-default'><span class='error' style='color: #878787;'>Das Formular konnte nicht versendet werden. Bitte versuchen Sie es erneut.</span></li>");
				$.colorbox({
					width: "400px",
					height: "500px",
					initialWidth: "400px",
					initialHeight: "500px",
					innerWidth: "400px",
					innerHeight: "500px",
					speed: 800,
					inline: true,
					href: "#ajax_contact_error",
					transition: "elastic"
				});

			}
		});
	}
	else {

		$.colorbox({
			width: "400px",
			height: "500px",
			initialWidth: "400px",
			initialHeight: "500px",
			innerWidth: "400px",
			innerHeight: "500px",
			speed: 800,
			inline: true,
			href: "#ajax_contact_error",
			transition: "elastic"
		});





	}
	return false;


}
