/** CMS4PEOPLE 2008 **/
/** script.cnt_cf.js 1.03 **/

var inProgress = false;
var cnt_cf_currID = 0;

/**
 * Versenden eines Kontaktformulars
 */

function cnt_cf_send(id)
{
    if (inProgress == true)
		return;
	// Kontaktformular bestimmen
    contact_form = document.getElementById('cnt_contactform_' + id);
    // Ajax-Parameter bestimmen
    message_area = contact_form.getElementsByTagName('textarea')[0];
    ajax_params = "message="+escape(message_area.value);
    message_area.disabled = 'disabled';
    input_elements = contact_form.getElementsByTagName('input');
    filled = false;
    for(i = 0; i < input_elements.length; i++)
    {
    	if (input_elements[i].value != "" && input_elements[i].name != "key")
    		filled = true;
    	ajax_params += "&" + input_elements[i].name + "=" + escape(input_elements[i].value);
    }
	if (filled)
	{
        for(i = 0; i < input_elements.length; i++)
    	{
   		    input_elements[i].disabled = 'disabled';
    	}

	    // Statusvars setzen
		inProgress = true;
		cnt_cf_currID = id;
		document.getElementById('cnt_contactform_info_' + cnt_cf_currID).innerHTML = "Ihre Nachricht wird gesendet ....";
		// AJAX
		request = new Ajax();
	    request.setUrl('/system/content/contactform/ajax.email_form.php');
	    request.setCallback('cnt_fn_sendCallback');
	    request.sendRequest(ajax_params);
	}
	else
		alert("Bitte füllen Sie mindestens ein Feld aus");
}


function cnt_fn_sendCallback(ajax_request)
{
	error_code = ajax_request.responseXML.getElementsByTagName("error_code")[0].childNodes[0].nodeValue;
	info_msg = error_code == 0 ? "Ihre Nachricht wurde erfolgreich gesendet." : "Leider konnte Ihre Nachricht NICHT gesendet werden.";
	document.getElementById('cnt_contactform_info_' + cnt_cf_currID).innerHTML = info_msg;
	inProgress = false;
	cnt_cf_currID = 0;
}