
/**
 * Works with jQuery <= 1.4.0 // checked and modified by riquito
 *
 */

(function($){

var jQuery=$,undefined;

window.submitFormByClass=function(className, formId, submitButton) {
 	
	if(!className) className = '.toBeSubmitted';
	if(!formId) formId = '#mainForm';

    var out='';
	if(submitButton) {
		out = '<input type="hidden" name="' + $(submitButton).attr("name") + '" value="' + $(submitButton).attr("value") + '">';
	}
	
	var classNameArray = className.split(',');
	
	$.each(['input','select','textarea'],
		function(idx,element) {
			
			var tmpClassNameArray = [];
			var className;
			
			for (var keyVar in classNameArray ) {
			   tmpClassNameArray[keyVar] = classNameArray[keyVar] + ' ' + element;
			}
			className = tmpClassNameArray.join(', ');
			
			$(className).each(
			
				function(){
					var value = '';
					var add = 1;

                    var attrType=$(this).attr('type');
					
					if (attrType == 'submit' || attrType == 'button') add = 0;
					
					if($(this).val()) {
						if(attrType == 'radio' || attrType == 'checkbox') {
							add = 0;
							if($(this).attr('checked')) {
								value = $(this).val();
								add = 1;							
							} 
						} else {
							value = $(this).val();
                            if (value.constructor == Array) value=value[0]; // was a select multiple
						}
					}
					
					if(add) {
						if(element != 'textarea') {
							out += '<input type="hidden" name="' + $(this).attr("name") + '" value="' + value + '">';
						} else {
							out += '<textarea style="display: none;" name="' + $(this).attr("name") + '">' + value + '</textarea>';
						}
					}
				}
			)
		}
	);
	
	$(formId).append(out);
	$(formId).submit();

}


var lastLogTime = new Array();

window.ajaxLog=function(url, object, path, seconds) {
	
	 var time = new Date();
	 var now = time.getTime();
	 if(!seconds) seconds = 10;
	 seconds = seconds * 1000;
	 
	 if(!(lastLogTime[object] > (now - seconds))) {
		$.ajax({
		   type: "GET",
		   url: url + "&object=" + object + '&path=' + path
		 });
		 lastLogTime[object] = now;
	 }
}

})(jQuery);
