
function submitContactForm(dom_form_id, provider_id, user_id){

	//validation of form content
	var validation = true;
	var save_success = true;
	var error_message_array = new Array();

	var form_provider_contact = $(dom_form_id);

	var values = new Object();

	//treatment_resetter

	var htmlOptions = $("#target_treatments")[0].options;
	var treatments = new Array();
	for (a = 0; a < htmlOptions.length; a++) {
		treatments.push(htmlOptions[a].value);
	}
	values.treatments = treatments.join("|");

	var all_form_elements = $(".provider_contact:input");
	for (i = 0; i < all_form_elements.length; i++) {
		values[all_form_elements[i].name] = all_form_elements[i].value;
	}
	values.gender = $("input:radio[@name='gender']:checked").val();

	/*
	console.debug(values);
	return;
	*/

	// ANTI SPAM: field "email" ist the fake email field, use "email_to_use" instead!
	if (values.email.length != 0) {
		validation = false;
		return true;
	}

	/* validation of selected treatments
	if (typeof values.treatments == "undefined" || values.treatments.length == 0) {
		validation = false;
		error_message_array.push(error_messages["error_treatments"]);;
	}
	*/
	if (typeof values.first_name == "undefined" || values.first_name.length == 0) {
		validation = false;
		error_message_array.push(error_messages["error_first_name"]);;
	}
	if (typeof values.last_name == "undefined" || values.last_name.length == 0) {
		validation = false;
		error_message_array.push(error_messages["error_last_name"]);;
	}
	if (typeof values.email_to_use == "undefined" || values.email_to_use.length == 0) {
		validation = false;
		error_message_array.push(error_messages["error_email"]);;
	} else {
		values.email = values.email_to_use;
		delete(values.email_to_use);
	}

	if (validation == true) {
		$.getJSON(path + 'application/controller/handleFrontendUserData.NEW.php?action=send_provider_contact&user_id=' + user_id + '&provider_id=' + provider_id,
			values,
			function(json){
				if (json.success == true) {
					trackProviderContact(provider_id);
					var thankyou_link = "";
					if (locale == "de") {
						thankyou_link = "anbieter/vielen-dank";
					} else if (locale == "en") {
						thankyou_link = "provider/thank-you";
					} else if (locale == "ru") {
						thankyou_link = "predstavitel/thank-you";
					}
					document.location.href = path + thankyou_link;
				} else {
					validation = false;
				}
			}
		);
	}

	if ((validation == false || save_success == false) && error_message_array.length > 0){
		var error_message_string = "";
		jQuery.each(error_message_array, function(index, single_message){
			error_message_string += "<li>" + single_message + "</li>";
		});
		error_message_complete = "<ul style=\"padding: 0px 0px 10px 18px;\">" + error_message_string + "</ul>";
		$.nyroModalManual({
			content: "<h4>" + error_message_title + "</h4>" + "<p>" + error_message_complete + "</p><button class='nyroModalClose'>" + error_message_button + "</button>",
			modal: true,
			minHeight: 0
		});
	}

	return;
}


/**
 * deleteProviderFromNotepad
 * @param {Object} user_id
 * @param {Object} provider_id
 */
function memorizeDirectContactProvider(provider_id, checked){
	if (typeof provider_id != "undefined") {
		// post request to server
		$.getJSON(path + 'application/controller/handleFrontendUserData.NEW.php?action=provider_direct_contact_memorize&provider_id=' + provider_id + '&checked=' + checked,
			function(json){
				if (json.success == true) {
				} else {
				}
			}
		);
	}
}


function submitDirectContactForm(dom_form_id, user_id){

	var validation = true;
	var save_success = true;
	var error_message_array = new Array();

	$.getJSON(path + 'application/controller/handleFrontendUserData.NEW.php?action=provider_direct_contact_check',
		function(json){
			if (json.success == true) {

				//validation of form content
				var form_provider_contact = $(dom_form_id);

				var values = new Object();

				var all_form_elements = $(".provider_contact:input");
				for (i = 0; i < all_form_elements.length; i++) {
					values[all_form_elements[i].name] = all_form_elements[i].value;
				}

				if (typeof values.provider_id == "undefined" || values.provider_id.length == 0) {
					// direct contact form on search result page
					var provider = new Array();
					provider = json.provider;
					values['provider'] = provider.join("|");
				} else {
					// direct contact form on provider detail pages
					values['provider'] = values.provider_id;
				}

				// ANTI SPAM: field "email" ist the fake email field, use "email_to_use" instead!
				if (values.email.length != 0) {
					validation = false;
					return true;
				}

				if (typeof values.provider == "undefined" || values.provider.length == 0) {
					validation = false;
					error_message_array.push(error_messages["error_provider"]);;
				}
				/*
				if (typeof values.first_name == "undefined" || values.first_name.length == 0) {
					validation = false;
					error_message_array.push(error_messages["error_first_name"]);;
				}
				if (typeof values.last_name == "undefined" || values.last_name.length == 0) {
					validation = false;
					error_message_array.push(error_messages["error_last_name"]);;
				}
				*/
				if (typeof values.email_to_use == "undefined" || values.email_to_use.length == 0) {
					validation = false;
					error_message_array.push(error_messages["error_email"]);;
				} else {
					values.email = values.email_to_use;
					delete(values.email_to_use);
				}
				if (typeof values.free_text == "undefined" || values.free_text.length == 0) {
					validation = false;
					error_message_array.push(error_messages["error_free_text"]);;
				}

				if (validation == true) {
					$.getJSON(path + 'application/controller/handleFrontendUserData.NEW.php?action=send_provider_direct_contact&user_id=' + user_id,
						values,
						function(json){
							if (json.success > 0) {
								// track provider contacts
								jQuery.each(provider, function(index, single_provider_id){
									trackProviderContact(single_provider_id);
								});
								// redirect to thank you page
								var thankyou_link = "";
								if (locale == "de") {
									thankyou_link = "anbieter/vielen-dank";
								} else if (locale == "en") {
									thankyou_link = "provider/thank-you";
								} else if (locale == "ru") {
									thankyou_link = "predstavitel/thank-you";
								}
								document.location.href = path + thankyou_link;
							} else {
								validation = false;
								showErrorMessage(error_message_array);
							}
						}
					);
				} else {
					showErrorMessage(error_message_array);
				}

			} else {
				validation = false;
				error_message_array.push(error_messages["error_provider"]);
				showErrorMessage(error_message_array);
			}
		}
	);

	if ((validation == false || save_success == false) && error_message_array.length > 0){
		var error_message_string = "";
		jQuery.each(error_message_array, function(index, single_message){
			error_message_string += "<li>" + single_message + "</li>";
		});
		error_message_complete = "<ul style=\"padding: 0px 0px 10px 18px;\">" + error_message_string + "</ul>";
		$.nyroModalManual({
			content: "<h4>" + error_message_title + "</h4>" + "<p>" + error_message_complete + "</p><button class='nyroModalClose'>" + error_message_button + "</button>",
			modal: true,
			minHeight: 0
		});
	}

	return;
}

function submitDirectContactStaticExportForm(dom_form_id, user_id){

	var validation = true;
	var save_success = true;
	var error_message_array = new Array();

	var form_provider_contact = $(dom_form_id);

	var values = new Object();

	var all_form_elements = $(".provider_contact:input");
	for (i = 0; i < all_form_elements.length; i++) {
		values[all_form_elements[i].name] = all_form_elements[i].value;
	}

	var provider_ids = $("input:checkbox[@name='contact_input']:checked")
	var provider = new Array();
	for (a = 0; a < provider_ids.length; a++) {
		provider.push(provider_ids[a].value);
	}
	values['provider'] = provider.join("|");

	// ANTI SPAM: field "email" ist the fake email field, use "email_to_use" instead!
	if (values.email.length != 0) {
		validation = false;
		return true;
	}

	if (typeof values.provider == "undefined" || values.provider.length == 0) {
		validation = false;
		error_message_array.push(error_messages["error_provider"]);;
	}
	/*
	if (typeof values.first_name == "undefined" || values.first_name.length == 0) {
		validation = false;
		error_message_array.push(error_messages["error_first_name"]);;
	}
	if (typeof values.last_name == "undefined" || values.last_name.length == 0) {
		validation = false;
		error_message_array.push(error_messages["error_last_name"]);;
	}
	*/
	if (typeof values.email_to_use == "undefined" || values.email_to_use.length == 0) {
		validation = false;
		error_message_array.push(error_messages["error_email"]);;
	} else {
		values.email = values.email_to_use;
		delete(values.email_to_use);
	}
	if (typeof values.free_text == "undefined" || values.free_text.length == 0) {
		validation = false;
		error_message_array.push(error_messages["error_free_text"]);;
	}

	if (validation == true) {
		$.getJSON(path + 'application/controller/handleFrontendUserData.NEW.php?action=send_provider_direct_contact&user_id=' + user_id,
			values,
			function(json){
				if (json.success > 0) {
					// track provider contacts
					jQuery.each(provider, function(index, single_provider_id){
						trackProviderContact(single_provider_id);
					});
					// redirect to thank you page
					var thankyou_link = "";
					if (locale == "de") {
						thankyou_link = "anbieter/vielen-dank";
					} else if (locale == "en") {
						thankyou_link = "provider/thank-you";
					} else if (locale == "ru") {
						thankyou_link = "predstavitel/thank-you";
					}
					document.location.href = path + thankyou_link;
				} else {
					validation = false;
					showErrorMessage(error_message_array);
				}
			}
		);
	} else {
		showErrorMessage(error_message_array);
	}


	if ((validation == false || save_success == false) && error_message_array.length > 0){
		var error_message_string = "";
		jQuery.each(error_message_array, function(index, single_message){
			error_message_string += "<li>" + single_message + "</li>";
		});
		error_message_complete = "<ul style=\"padding: 0px 0px 10px 18px;\">" + error_message_string + "</ul>";
		$.nyroModalManual({
			content: "<h4>" + error_message_title + "</h4>" + "<p>" + error_message_complete + "</p><button class='nyroModalClose'>" + error_message_button + "</button>",
			modal: true,
			minHeight: 0
		});
	}

	return;
}

/**
 *
 * @access public
 * @return void
 **/
function showErrorMessage(error_message_array){
	var error_message_string = "";
	jQuery.each(error_message_array, function(index, single_message){
		error_message_string += "<li>" + single_message + "</li>";
	});
	error_message_complete = "<ul style=\"padding: 0px 0px 10px 18px;\">" + error_message_string + "</ul>";
	$.nyroModalManual({
		content: "<h4>" + error_message_title + "</h4>" + "<p>" + error_message_complete + "</p><button class='nyroModalClose'>" + error_message_button + "</button>",
		modal: true,
		minHeight: 0
	});
}


function submitDirectContactContentForm(dom_form_id, user_id){

	//validation of form content
	var validation = true;
	var save_success = true;
	var error_message_array = new Array();

	var form_provider_contact = $(dom_form_id);

	var values = new Object();

	var all_form_elements = $(".provider_contact:input");
	for (i = 0; i < all_form_elements.length; i++) {
		values[all_form_elements[i].name] = all_form_elements[i].value;
	}

	if (typeof values.provider_id == "undefined" || values.provider_id.length == 0) {
		 // direct contact form on content embeded search result
		var provider_ids = $("input:checkbox[@name='contact_input']:checked")
		var provider = new Array();
		for (a = 0; a < provider_ids.length; a++) {
			provider.push(provider_ids[a].value);
		}
		values['provider'] = provider.join("|");
	} else {
		// direct contact form on provider detail pages
		values['provider'] = values.provider_id;
	}

	//console.debug(values);
	//return;

	// ANTI SPAM: field "email" ist the fake email field, use "email_to_use" instead!
	if (values.email.length != 0) {
		validation = false;
		return true;
	}

	if (typeof values.provider == "undefined" || values.provider.length == 0) {
		validation = false;
		error_message_array.push(error_messages["error_provider"]);;
	}
	/*
	if (typeof values.first_name == "undefined" || values.first_name.length == 0) {
		validation = false;
		error_message_array.push(error_messages["error_first_name"]);;
	}
	if (typeof values.last_name == "undefined" || values.last_name.length == 0) {
		validation = false;
		error_message_array.push(error_messages["error_last_name"]);;
	}
	*/
	if (typeof values.email_to_use == "undefined" || values.email_to_use.length == 0) {
		validation = false;
		error_message_array.push(error_messages["error_email"]);;
	} else {
		values.email = values.email_to_use;
		delete(values.email_to_use);
	}
	if (typeof values.free_text == "undefined" || values.free_text.length == 0) {
		validation = false;
		error_message_array.push(error_messages["error_free_text"]);;
	}

	if (validation == true) {
		$.getJSON(path + 'application/controller/handleFrontendUserData.NEW.php?action=send_provider_direct_content_contact&user_id=' + user_id,
			values,
			function(json){
				if (json.success > 0) {
					if (typeof values.provider_id == "undefined" || values.provider_id.length == 0) {
						for (x = 0; x < provider_ids.length; x++) {
							trackProviderContact(provider_ids[x].value);
						}
					} else {
						trackProviderContact(values.provider_id);
					}
					var thankyou_link = "";
					if (locale == "de") {
						thankyou_link = "anbieter/vielen-dank";
					} else if (locale == "en") {
						thankyou_link = "provider/thank-you";
					} else if (locale == "ru") {
						thankyou_link = "predstavitel/thank-you";
					}
					document.location.href = path + thankyou_link;
				} else {
					validation = false;
				}
			}
		);
	}

	if ((validation == false || save_success == false) && error_message_array.length > 0){
		var error_message_string = "";
		jQuery.each(error_message_array, function(index, single_message){
			error_message_string += "<li>" + single_message + "</li>";
		});
		error_message_complete = "<ul style=\"padding: 0px 0px 10px 18px;\">" + error_message_string + "</ul>";
		$.nyroModalManual({
			content: "<h4>" + error_message_title + "</h4>" + "<p>" + error_message_complete + "</p><button class='nyroModalClose'>" + error_message_button + "</button>",
			modal: true,
			minHeight: 0
		});
	}

	return;
}


/**
 *
 * @access public
 * @return void
 **/
function trackProviderContact(provider_id){
	$.getJSON(path + 'application/controller/handleFrontendUserData.NEW.php?action=get_provider_url_alias_name&provider_id=' + provider_id,
		function(json){
			if (json.success == true) {
				pageTracker._trackPageview('/provider-contact/' + json.url_alias_name);
			}
		}
	);
}