/**
 * EZ Contact
 * Frontend JavaScript
 * 
 * (c) EZdesign.de
 *
 * Author:   Timo Besenreuther
 * Created:  2009-04-20
 * Modified: 2010-08-30
 */


$(document).ready(function() {
	$('#EzContactForm textarea.Growing').each(function() {
		// growing textarea is only included when needed
		$(this).growingTextarea();
	});
	
	$('#EzContactForm input, #EzContactForm textarea').focus(function() {
		$(this).addClass('Focused');
	}).blur(function() {
		$(this).removeClass('Focused');
	});
});


function EzContactCheck() {
	var errors = new Array();
	var values = new Array();
	for (id in EzContactMandatory) {
		var el = $('#'+id);
		if (el.is('input[type=checkbox]')) {
			if (!el.is(':checked')) {
				errors.push(EzContactMandatory[id]);
			}
		} else {
			var val = trim(el.val());
			if (!val || val == "" || val == " ") {
				errors.push(EzContactMandatory[id]);
			}
		}
	}
	if (errors.length > 0) {
		$('#EzContactError').html('<b>'+EzContactMandatoryFieldsError+'</b> '+errors.join(', ')+'.').show();
		if (typeof(EzContactErrorCallback) != 'undefined') {
			EzContactErrorCallback(errors);
		}
	} else {
		$('#EzContactSent').val('1');
		$('#EzContactForm').attr('action', window.location.href).submit();
	}
}

function trim(str) {
	return str.replace(/^\s+/, '').replace (/\s+$/, '');
}

