$(document).ready(function() {
formvalidation();
$('.form_customize_additional_filter').each(function() {
var temp = '';
$(this).closest('form').find('.form_item').each(function() {
//hide form item if form_customize="hide" and no data
if($(this).attr("form_customize") == "hide" && !hasVal($(this).find('input,textarea,select'))) {
$(this).hide();
}
//populate customize additional filter table
if($(this).is(':hidden')) {
temp += '
' + $(this).find('.form_item_label').html() + ' | |
';
}
});
$(this).html('');
});
});
function formvalidation() {
$('.formname').change(function() {
$(this).val(function(i, val) {
return val.replace(/[^A-Za-z0-9\u00C0-\u017E\.\ \-\']/g, '');
});
});
$('.formtel').change(function() {
$(this).val(function(i, val) {
return val.replace(/[^\(\)\+\-\.\ 0-9]/g, '');
});
});
$('.forminteger, .formpositiveinteger').change(function() {
$(this).val(function(i, val) {
return val.replace(/[^0-9]/g, '');
});
});
$('.formmoney').change(function() {
$(this).val(function(i, val) {
val = val.replace(/,/g, '.');
return val.replace(/[^0-9\.]/g, '');
});
if($(this).val() == '' || $(this).val().match(/^[0-9]*(\.[0-9]{2,4})?$/)) {
$(this).css('backgroundColor', '');
}
else {
$(this).css('backgroundColor', '#FF8080');
}
});
$('.formpercent').change(function() {
$(this).val(function(i, val) {
val = val.replace(/,/g, '.');
return val.replace(/[^0-9\.]/g, '');
});
if($(this).val() == '' || $(this).val().match(/^[0-9]{1,3}(\.[0-9]{1,2})?$/) && $(this).val() <= 100) {
$(this).css('backgroundColor', '');
}
else {
$(this).css('backgroundColor', '#FF8080');
}
});
$('.formdatum, .formdate').change(function() {
$(this).val(function(i, val) {
val = val.replace(/-/g, '.');
return val.replace(/[^0-9\.]/g, '');
});
if($(this).val() == '' || $(this).val().match(/^[0123]?[0-9]\.[01]?[0-9]\.[12][0-9]{3}$/)) {
$(this).css('backgroundColor', '');
}
else {
$(this).css('backgroundColor', '#FF8080');
}
});
$('.formtime').change(function() {
$(this).val(function(i, val) {
return val.replace(/[^0-9\:]/g, ':');
});
if($(this).val() == '' || ($(this).val().match(/^[012]?[0-9]\:[0-5][0-9]$/) && parseInt($(this).val().split(":")[0], 10) >= 7 && parseInt($(this).val().split(":")[0], 10) < 22)) {
$(this).css('backgroundColor', '');
}
else {
$(this).css('backgroundColor', '#FF8080');
}
});
$('.formduration').change(function() {
$(this).val(function(i, val) {
return val.replace(/[^0-9]/g, '');
});
if($(this).val() == '' || $(this).val() % 900 == 0) {
$(this).css('backgroundColor', '');
}
else {
$(this).css('backgroundColor', '#FF8080');
}
});
$('.formemail').change(function() {
$(this).val(function(i, val) {
return val.replace(/[^A-Za-z0-9_.\-@+%]/g, '').toLowerCase();
});
if($(this).val() == '' || $(this).val().match(/^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$/)) {
$(this).css('backgroundColor', '');
}
else {
$(this).css('backgroundColor', '#FF8080');
}
});
$('.formusername').change(function() {
$(this).val(function(i, val) {
return val.replace(/[^A-Za-z0-9_.\-@+%]/g, '').toLowerCase();
});
if($(this).val() == '' || $(this).val().match(/^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$/) || $(this).val().match(/^[A-Za-z0-9\.\ \-\']+\.[A-Za-z0-9\.\ \-\']+$/)) {
$(this).css('backgroundColor', '');
}
else {
$(this).css('backgroundColor', '#FF8080');
}
});
$('.formpassword').change(function() {
if($(this).val() == '' || $(this).val().match(/^.{8}.*$/)) {
$(this).css('backgroundColor', '');
}
else {
$(this).css('backgroundColor', '#FF8080');
}
});
$('.formnewpassword').change(function() {
if($(this).val() == '' || $(this).val().match(/^.{8}.*$/) && $(this).val().match(/[A-Z]/) && $(this).val().match(/[a-z]/) && $(this).val().match(/[0-9]/)) {
$(this).css('backgroundColor', '');
}
else {
$(this).css('backgroundColor', '#FF8080');
}
});
//multiline fields
$('.formmultiline_popup').focus(function() {
$(this).css('height', '48px');
});
$('.formmultiline_popup').blur(function() {
$(this).css('height', '16px');
});
$('.formmultiline_autosize').each(function() {
formmultiline_autosize($(this));
});
$('.formmultiline_autosize').keyup(function() {
formmultiline_autosize($(this));
});
function formmultiline_autosize(obj) {
var cols = obj.attr("cols");
var lines = obj.val().split("\n");
var linecount = 0;
for(var i = 0; i < lines.length; i++) {
linecount += Math.ceil(lines[i].length / cols); // take into account long lines
}
obj.attr("rows", linecount + 1);
}
//customizable forms
$('.form_customize_filter_hide').click(function() {
var fieldid = $(this).closest('.form_item').find('input,textarea,select').attr('id');
$(this).closest('.form_item').hide();
$.ajax({
data: {
action: "formcustomize_user_toggle",
entity: "formcustomize_user",
1312: page,
1313: fieldid,
1314: 0
},
url: "ajax.php",
type: "post"
});
$(this).closest('form').find('.form_customize_additional_filter').find('table').append('' + $(this).closest('.form_item').find('.form_item_label').html() + ' | |
');
});
$(document).on('click', '.form_customize_filter_show', function() {
var fieldid = $(this).attr("fieldid");
$('#' + fieldid).closest('.form_item').show();
$.ajax({
data: {
action: "formcustomize_user_toggle",
entity: "formcustomize_user",
1312: page,
1313: fieldid,
1314: 1
},
url: "ajax.php",
type: "post"
});
$(this).closest('tr').remove();
});
$('.form_customize_additional_filter_show').click(function() {
$(this).next('.form_customize_additional_filter').toggle();
if($(this).next('.form_customize_additional_filter').is(":hidden")) {
$(this).find("a").html('→ ' + $(this).find("a").html().substring(2));
}
else {
$(this).find("a").html('↓ ' + $(this).find("a").html().substring(2));
}
});
}
function hasVal(obj) {
var hasVal = false;
obj.each(function() {
if($(this).attr("type") == "radio" || $(this).attr("type") == "checkbox") { // type=radio,checkbox
if($(this).prop("checked")) {
hasVal = true;
}
}
else if($(this).prop("tagName") == "SELECT") { //