var org_cellfex_validatorDataContainer = '';
var org_cellfex_validatorContainer = '';

$(document).ready(function(){
	$('.org_cellfex_validate_email, .org_cellfex_validate_date, .org_cellfex_validate_date_DDMMYYYYDot, .org_cellfex_validate_integer, .org_cellfex_validate_float').change(function(){
			var org_cellfex_validatorDataContainer = '#'+$(this).attr('id');
			var org_cellfex_validatorContainer = '#org_cellfex_validator_'+$(this).attr('id');
			$(org_cellfex_validatorContainer).addClass('org_cellfex_validator_container');
			$(org_cellfex_validatorContainer).css('width', '15px');
			$(org_cellfex_validatorContainer).css('height', '15px');
			$(org_cellfex_validatorContainer).css('background-position', '0 0');
			$(org_cellfex_validatorContainer).css('background-image', 'url(cellfex/plugins/org.cellfex.package.default/js/org_cellfex_validator_loader.gif)');
            var org_cellfex_validatorType;
            if ($(this).hasClass('org_cellfex_validate_email')) {
                org_cellfex_validatorType = 'email';
            } else if ($(this).hasClass('org_cellfex_validate_date')) {
                org_cellfex_validatorType = 'dateGeneralFormat';
            } else if ($(this).hasClass('org_cellfex_validate_date_DDMMYYYYDot')) {
                org_cellfex_validatorType = 'dateDDMMYYYYDotFormat';
            } else if ($(this).hasClass('org_cellfex_validate_integer')) {
                org_cellfex_validatorType = 'integer';
            } else if ($(this).hasClass('org_cellfex_validate_float')) {
                org_cellfex_validatorType = 'float';
            }
            $.get("./index.php", { org_cellfex_validator: org_cellfex_validatorType+":"+$(this).val() }, function(data) {
                $(org_cellfex_validatorContainer).css('background-image', 'url(cellfex/plugins/org.cellfex.package.default/js/org_cellfex_validator_response.png)');
				if (data=='true') {
					$(org_cellfex_validatorDataContainer).attr('validated', 'true');
					$(org_cellfex_validatorContainer).css('background-position', '0 0');
				} else {
					$(org_cellfex_validatorDataContainer).attr('validated', 'false');
					$(org_cellfex_validatorContainer).css('background-position', '-15px 0');
				}			
			});
		});

	$('.org_cellfex_validate_equal').each(function(){
		$(this).change(function(){
			var org_cellfex_validatorThisValue = $(this).val();
			var org_cellfex_validatorRelated = $(this).attr('rel');
			data = 'true';
			$('rel=['+org_cellfex_validatorRelated+']').each(function(){
				if ($(this).val()!=org_cellfex_validatorThisValue){
					var org_cellfex_validatorContainer = '#org_cellfex_validator_'+$(this).attr('id');
					$(org_cellfex_validatorContainer).css('background-position', '0 0');
					$(org_cellfex_validatorContainer).css('background-image', 'url(cellfex/plugins/org.cellfex.package.default/js/org_cellfex_validator_response.png)');
					if (data=='true'){
						$(org_cellfex_validatorContainer).css('background-position', '0 0');
					} else {
						$(org_cellfex_validatorContainer).css('background-position', '-15px 0');
					}	
				}
			});
		});
	});			
});

