Obormot
Постоялец
- Регистрация
- 10 Янв 2012
- Сообщения
- 88
- Реакции
- 2
- Автор темы
- #11
код userform.js
Код:
if(top!=self){top.location.replace(document.location);alert("For security reasons, framing is not allowed; click OK to remove the frames.")}
var ua = navigator.userAgent.toLowerCase();
var browser={
isOpera : ua.indexOf("opera")>-1,
isAvant : ua.indexOf("avant")>-1,
isIE : !this.isOpera && navigator.appName.indexOf("Microsoft")>-1,
isIE6 : this.isIE && ua.charAt(30)==6,
isIE7 : ua.indexOf('msie 7')>-1,
isChrome : ua.indexOf("chrome")>-1,
isFlock : ua.indexOf("flock")>-1,
isSafari : ua.indexOf("safari")>-1,
isMozilla : (!this.isOpera&&!this.isIE&&!this.isSafari&&!this.isFlock),
isFireFox2 : this.isMozilla && ua.indexOf("firefox/2")>-1,
isFireFox3 : this.isMozilla && ua.indexOf("firefox/3")>-1,
isGecko : ua.indexOf('gecko')>-1 && !this.isSafari,
isWebkit : ua.indexOf('applewebkit/')>-1,
inWindows : ua.indexOf('windows')>-1 || ua.indexOf('win32')>-1,
inMac : ua.indexOf('macintosh')>-1 || ua.indexOf('mac os x')>-1,
inLinux : ua.indexOf('linux')>-1
}
var isOpera = ua.indexOf("opera")>-1;
var isIE = !isOpera && navigator.appName.indexOf("Microsoft")>-1;
var isIE6 = ua.indexOf('msie 6') > -1;
var isIE7 = ua.indexOf('msie 7') > -1;
var isFlock = ua.indexOf("flock")>-1;
var isSafari = ua.indexOf("safari")>-1;
var isMozilla = (!isOpera&&!isIE&&!isSafari&&!isFlock);
var isFireFox2 = isMozilla && ua.indexOf("firefox/2")>-1;
var isFireFox3 = isMozilla && ua.indexOf("firefox/3")>-1;
var isGecko = ua.indexOf('gecko') > -1 && ua.indexOf('safari') == -1;
var isWebkit = ua.indexOf('applewebkit/') > -1;
var isWindows = ua.indexOf('windows') > -1 || ua.indexOf('win32') > -1;
var isMac = ua.indexOf('macintosh') > -1 || ua.indexOf('mac os x') > -1;
var isLinux = ua.indexOf('linux') > -1;
function userForm ( fname )
{
var _d = document;
if(!_d[fname]){return}
this._df = _d[fname];
this.o = _d;
if(typeof this._df.tz != 'undefined'){
var _dt = new Date();
this._df.tz.value = _dt.getTimezoneOffset();
}
this.verify = function(submitt){
var el = this._df.elements, msg='';
var submitt = typeof submitt == 'undefined' ? 0 : 1;
if(el.length){
verifyForm:
for(var n in el){
if(el[n]){
if(typeof el[n].type != 'undefined'){
switch(true){
case el[n].type == 'text' || el[n].type == 'password':
this.o = el[n];
var emailPattern = /^[a-zA-Z0-9._-]{3,}@[a-zA-Z0-9.-]{3,}\.[a-zA-Z]{2,4}$/;
var namePattern = /^[a-zA-Zа-яА-я0-9_\.\s\-]{3,}$/;
var usernamePattern = /^[a-zA-Z0-9_\-]{5,}$/;
var passwordPattern = /^[a-zA-Z0-9_@!#\$%&\(\)\[\]\?<>\-]{8,48}$/;
switch(el[n].name){
case 'email' :
if(fname == 'forgotPasswordForm' && typeof this._df.username != 'undefined'){
if(!emailPattern.test(this._df.email.value) && (!usernamePattern.test(this._df.username.value) || this._df.username.value.indexOf(' ') !=-1)){
msg='Please enter a valid email address or \nusername (5 or more: 0-9, a-Z, -, or _)';break verifyForm
}
}
else {
if(!emailPattern.test(this._df.email.value)){msg='Please enter a valid email address';break verifyForm}
}
break;
case 'username' :
if(fname == 'forgotPasswordForm' && typeof this._df.email != 'undefined'){
if(!emailPattern.test(this._df.email.value) && (!usernamePattern.test(this._df.username.value) || this._df.username.value.indexOf(' ') !=-1)){
msg='Please enter a valid email address or \nusername (5 or more: 0-9, a-Z, -, or _)';break verifyForm
}
}
else {
if(!usernamePattern.test(this._df.username.value)){msg='Please enter a valid \nusername (5 or more: 0-9, a-Z, -, or _)';break verifyForm}
}
break;
case 'password' :
if(typeof this._df.password2 != 'undefined'){
if(!passwordPattern.test(this._df.password.value)){msg='Please enter a valid password (8 to 48 characters)';break verifyForm}
if(this._df.password.value != this._df.password2.value){msg='Passwords do not match!';break verifyForm}
}
break;
case 'name' :
if(!namePattern.test(this._df.name.value) || this._df.name.value.indexOf(' ') !=-1){msg='Please enter a valid name';break verifyForm}
break;
}
break;
}
}
}
}
}
if(msg){this.o.focus();this.o.select();alert(msg);return false}
if(submitt){this._df.submit()}
return true;
}
};
var newLoc = null;
function performAction(retVal)
{
if(retVal && newLoc != null) window.location.href = newLoc;
newLoc = null;
}
function confirmAction( act, loc)
{
var _txt = lang.You_are_about_to +act+ lang.Do_you_wish_to_proceed;
newLoc = loc;
diconfirm(performAction,_txt);
}
function dosearch(){
var df = document.search;
if(df.q.value.length > 2){
df.submit()
}
}
function adv_search()
{
var df = document.contests;
df.q.value = '';
if(df._incl.value != ''){
df.q.value += ' +'+ df._incl.value.split(" ").join(" +");
df._incl.value = ''
}
if(df._excl.value != ''){
df.q.value += ' -'+ df._excl.value.split(" ").join(" -");
df._excl.value = ''
}
if(df._phrase.value != ''){
df.q.value += ' "'+ df._phrase.value +'"';
df._phrase.value = ''
}
if(df.q.value != ''){
df.submit()
}else{df._incl.focus()}
return false
}
function hideMe(o)
{
$(o).slideUp();
}
function showHide(id)
{
if ($('#'+id+'_on').css('display')=='none') {
$('#'+id+'_on').slideDown();
$('#'+id+'_off').slideUp();
} else {
$('#'+id+'_on').slideUp();
$('#'+id+'_off').slideDown();
}
return false;
}
function setHandler(obj, typ, func)
{
if(obj.addEventListener){
obj.addEventListener(typ,func,false);
} else if(obj.attachEvent){
obj.attachEvent("on"+typ,func);
}
}
/* ===================__forms__=================== */
/* =============================================== */
var formName = null;
function post_listing_form(retVal)
{
if(retVal && formName != null) document[formName].submit();
formName = null;
}
// multiple checkboxed listing forms
function listing_form(frm, task)
{
if(formName != null) return true;
var i=0, cnt=0, ckd=0, cbox=true, keys= new Array('','r','a','d','c');
for(var n=0;n<keys.length;n++){
while(cbox = document.getElementById('cbox'+keys[n]+'_'+i)){
cnt++; if(cbox.checked){ckd++} i++;
}i=0;
}
if (!ckd){alert('No items are checked');return false}
else {
switch(task){
case 'delete_forever':
case 'delete':
var _txt = 'Are you sure you wish to '+(task.replace("_"," "))+ (cnt==ckd ? ' all ' : '\nthe ') +ckd+' item'+ (ckd==1?'':'s') +'?';
diconfirm(post_listing_form,_txt);
break;
}
document[frm].task.value = task;
if(document[frm].method == 'get'){
document[frm].method = 'post';
if(document[frm].action.indexOf('page=')==-1){
document[frm].action += '?page='+ document[frm].page.value +'&content='+ document[frm].content.value;
}
}
formName = frm
return false;
}
}
function orderBy(fn,dr){document.cookie = "orderBy="+dr+"|"+fn}
var c_date = new Date();
c_date.setTime(c_date.getTime()+(365*24*60*60*1000));
var c_expires = "; expires="+c_date.toGMTString();
c_local=c_date.getTimezoneOffset();
document.cookie = "_utcm="+c_local+c_expires+"; path=/";
function clear_file_upload(_id)
{
var _id = typeof _id == 'undefined' ? 'file_upload' : _id;
document.getElementById(_id).innerHTML = document.getElementById(_id).innerHTML
}