function set_red(what) { document.getElementById(what).style.color = "FF0000"; } function set_back(what) { document.getElementById(what).style.color = ""; } document.getElementById('forma').onsubmit=submiting; function submiting(){ iderr=document.getElementById('errs'); clear_elem(iderr); id=document.getElementById('email'); if(isempti(id.value)) { add_ch_br(iderr,'Ошибка! Введите ваш e-mail.'); set_red('s_email'); } else if(!isemail(id.value)) { add_ch_br(iderr,'Ошибка! Неправильный e-mail.'); set_red('s_email'); } else { set_back('s_email'); } var temp=0; id=document.getElementById('lname'); if(isempti(id.value))temp++; id=document.getElementById('labout'); if(isempti(id.value))temp++; if(temp==2) { add_ch_br(iderr,"Ошибка! А что будет являться телом ссылки? Либо поле "название ссылки", либо поле "описание" должно быть заполнено."); set_red('s_lname'); set_red('s_labout'); } else { set_back('s_lname'); set_back('s_labout'); } id=document.getElementById('sel'); if(id.value=="") { add_ch_br(iderr,"Ошибка! Тот раздел, который вы выбрали выбирать нельзя."); set_red('s_sel'); } else { set_back('s_sel'); } id=document.getElementById('url'); str2=id.value.replace('http:\/\/',''); str2=str2.replace('www\.',''); if(isempti(str2)) { add_ch_br(iderr,"Ошибка! Введите url вашего сайта."); set_red('s_url'); } else { set_back('s_url'); } id_back=document.getElementById('back1'); if(id_back.value) { str1=id_back.value.replace('http:\/\/',''); str1=str1.replace('www\.',''); if(isempti(str1)) { add_ch_br(iderr,"Ошибка! Введите url страницы на которой расположена ссылка на "); set_red('s_back1'); } else { if(str1.indexOf('/')!=-1)str1=str1.substring(0,str1.indexOf('/')); if(str2.indexOf('/')!=-1)str2=str2.substring(0,str2.indexOf('/')); if(str1!=str2) { add_ch_br(iderr,"Ошибка! URL вашего сайта и сайта на котором стоит ссылка на должны совпадать."); set_red('s_url'); set_red('s_back1'); } else { set_back('s_url'); set_back('s_back1'); } } } if(iderr.lastChild) { return false; } else { return true; } } function isemail(str){ if(!(/[^@]+@\w+\.\w+/.test(str)))return false; return true; } function isempti(str){ if (str==null||str.length==0)return true; return !/\S/.test(str); } function add_ch_br(id,text) { newText= document.createTextNode(text); li = document.createElement('li'); li.appendChild(newText); id.appendChild(li); } function clear_elem(id) { if (id.lastChild) { while(id.lastChild) { id.removeChild(id.lastChild) } } }