var config = new Array(); var ready = true; jQuery(document).ready(function(){ jQuery("form").submit(function() { fsubmit(jQuery(this).attr('name')); return false; }); }); function fsubmit(key) { jQuery("form[@name='"+key+"'] *").removeClass("error"); jQuery(".alert").hide(); jQuery(".good-alert").show(); eval('validate_showErrorMethod = validate_'+key+'_showErrorMethod;'); if (validate_showErrorMethod.indexOf("#")!= -1) { jQuery(validate_showErrorMethod+" > *").remove("*"); } var res = new Array(0); res = checkForm(key); for (element in res) { if (element.length > 0) { var tttt = 11; displayErrors(res, key); break; } } if (tttt != 11) { eval('validate_sendMethod = validate_'+key+'_sendMethod;'); if (validate_sendMethod == 'ajax') { post(key); } else { jQuery("form[name='"+key+"']").submit(); } } } function post(fName) { if (ready) { var b = jQuery("form[name='"+fName+"'] input, form[name='"+fName+"'] textarea, form[name='"+fName+"'] select"); var newstr = ""; b.each(function() { if (jQuery(this).attr("type") == "radio") { if (jQuery(this).attr("checked") == true) { radioname = jQuery(this).attr("name"); radioval = jQuery(this).val(); newstr += radioname + '=' + radioval + '&'; } } else { if (jQuery(this).val() == "") { jQuery(this).val(""); } newstr += this.name + '=' + jQuery(this).val() + '&'; } }); newstr += 'ajax=true'; newstr += '&formName='+fName; jQuery.ajax({ type: "POST", url: jQuery("form[id='"+fName+"']").attr('action'), data: newstr, success: function(msg){ if (msg.match('@s@')) { eval('validate_preloaderId = validate_'+fName+'_preloaderId;'); jQuery(validate_preloaderId).hide(); var text1 = msg.replace(/@s@/g,''); eval('validate_showErrorMethod = validate_'+fName+'_showErrorMethod;'); eval('validate_lastaction = validate_'+fName+'_lastaction;'); if (validate_showErrorMethod.match("#")) { jQuery(validate_showErrorMethod).html(text1); } else { if(validate_lastaction =='hide' || validate_lastaction == 'hideSend') { alert(text1); } } if (validate_lastaction == 'hide') { jQuery("form[id='"+fName+"']").css('display','none'); } if (validate_lastaction == 'hideSend') { jQuery("#send").hide(); } if (validate_lastaction != 'hide' && validate_lastaction != 'hideSend') { window.location.href = '/'+validate_lastaction; } ready = false; setTimeout('readyFalse()', 15000); } else { eval('validate_capId = validate_'+fName+'_capId;'); var src = jQuery("captcha", msg).text(); if (src.length == 0) { src = msg.substr(14, 32); } src = "/libs/imgcode/"+src+".jpg"; jQuery(validate_capId).attr("src", src); text1 = jQuery("errors", msg).text(); if (text1.length == 0) { text1 = msg.substr(msg.indexOf("")+8, msg.indexOf("")-msg.indexOf("")-8); } eval('validate_preloaderId = validate_'+fName+'_preloaderId;'); jQuery(validate_preloaderId).hide(); eval('validate_showErrorMethod = validate_'+fName+'_showErrorMethod;'); if (validate_showErrorMethod.indexOf("#")!= -1) { text1 = "

"+text1+"

"; jQuery(text1).appendTo(validate_showErrorMethod); } else { alert(text1); } } } }); eval('validate_preloaderId = validate_'+fName+'_preloaderId;'); jQuery(validate_preloaderId).show(); } else { eval('validate_showErrorMethod = validate_'+fName+'_showErrorMethod;'); if (validate_showErrorMethod.indexOf("#")!= -1) { jQuery("

Слишком частое отправление запроса, подождите, пожалуйста

").appendTo(validate_showErrorMethod); } else { alert("Слишком частое отправление запроса, подождите, пожалуйста"); } } } function readyFalse() { ready = true; } function displayErrors(array, formName) { eval('validate_highlight = validate_'+formName+'_highlight;'); eval('validate_showErrorMethod = validate_'+formName+'_showErrorMethod;'); if (validate_highlight) { highlight(array, formName); } if (validate_showErrorMethod == "alert") { alertError(array); } if (validate_showErrorMethod.indexOf("#")!= -1) { showErrorInDiv(array, validate_showErrorMethod); } } function highlight(array, formName) { for (field in array) { for (error in array[field]) { //jQuery("form[@name='"+formName+"'] *[name='"+field+"']").css('background','#e97451'); jQuery("form[@name='"+formName+"'] *[name='"+field+"']").addClass("error"); jQuery("#validate-bad_"+field).show(); jQuery("#validate-good_"+field).hide(); } } } function alertError(array) { var string = ""; out: for (field in array) { for (error in array[field]) { var newError = getError(error, array[field]['caption'], array[field][error]); string += newError+"\n"; continue out; } } alert(string); } function showErrorInDiv(array, id) { var string = ""; out: for (field in array) { for (error in array[field]) { var newError = getError(error, array[field]['caption'], array[field][error]); string += "

"+newError+"

"; continue out; } } $(id).append(string); } function getError($errorType, $fieldName, $value) { return $string; } //Проверка формы //formName - имя формы function checkForm(formName) { var res; var error = new Array(0); var newArr = config[formName]; for(elem in newArr) { res = checkField(elem, newArr[elem], formName); for (what in res) { if (what.length > 0) { error[elem] = new Array(); error[elem] = res; error[elem]['caption'] = newArr[elem]['caption']; break; } else { delete error[elem]; break; } } } return error; } //Проверяет Field //field - имя поля //value - массив с ограничителями и их значения //formName - имя формы function checkField(field, value, formName) { var error2 = new Array(0); var res; var newArr = value; for (var handler in newArr) { if (handler != 'caption') { functionName = "check_"+handler; res = eval(functionName+"('"+field+"','"+ newArr[handler]+"','"+ formName+"')"); if (!res) { error2[handler] = newArr[handler]; } else { delete error2[handler]; } } } return error2; } /*Обработчики*/ function check_maxlength(field, value, formName) { try{ var string = jQuery("#"+field+"").val(); }catch(e){ var string = jQuery("#"+field+"").html(); } if (string.length > parseInt(value)) { return false; } return true; } function check_captcha(field, value, formName) { return true; } /*Min-lenght validation*/ function check_minlength(field, value, formName) { try{ var string = jQuery("#"+field+"").val(); }catch(e){ var string = jQuery("#"+field+"").html(); } if (string.length < parseInt(value)) { return false; } return true; } /*Only numbers validation*/ function check_numberonly(field, value, formName) { try{ var string = jQuery("#"+field+"").val(); }catch(e){ var string = jQuery("#"+field+"").html(); } var reg = new RegExp("[^0-9]+", 'i'); var result = reg.test(string); if (result) { return false; } return true; } /*No numbers validation*/ function check_nonumber(field, value, formName) { try{ var string = jQuery("#"+field+"").val(); }catch(e){ var string = jQuery("#"+field+"").html(); } var reg = new RegExp("[0-9]", 'i'); var result = reg.test(string); if (result) { return false; } return true; } /*Only numbers and symbols validation*/ function check_numberandsimbols(field, value, formName) { try{ var string = jQuery("#"+field+"").val(); }catch(e){ var string = jQuery("#"+field+"").html(); } var reg = new RegExp("[^0-9-_+@\s]", 'i'); var result = reg.test(string); if (!result) { return false; } return true; } /*E-mail validation*/ function check_email(field, value, formName) { try{ var string = jQuery("#"+field+"").val(); }catch(e){ var string = jQuery("#"+field+"").html(); } var reg = new RegExp("[0-9a-z_]+@[0-9a-z_^.]+\\.[a-z]{2,3}", 'i'); var result = reg.test(string); if (!result) { return false; } return true; } /*No empty validation*/ function check_noempty(field, value, formName) { try{ var string = jQuery("#"+field+"").val(); }catch(e){ var string = jQuery("#"+field+"").html(); } if (string.length < 1) { return false; } if (string == value) { return false; } return true; } /*checkbox validation*/ function check_checkbox(field, value, formName) { var string = jQuery("#"+field+"").attr('checked'); if (!string) { return false; } return true; } /*sameAs (password reply) validation*/ function check_sameas(field, value, formName) { try{ var string = jQuery("#"+field+"").val(); }catch(e){ var string = jQuery("#"+field+"").html(); } try { var string2 = jQuery("#"+value+"").val(); }catch(e) { var string2 = jQuery("#"+value+"").html(); } if (string != string2) { return false; } return true; }