﻿var ua=navigator.userAgent.toLowerCase();
var pr = {
	//获取对象：id,tagName
	$:function(id,tag){
		if(!tag){return document.getElementById(id);}
		else if(typeof id=='string'){return document.getElementById(id).getElementsByTagName(tag);}
		else{return id.getElementsByTagName(tag);}
		},
	//获取Class对象(数组)：obj,className
	$s:function(obj,css){
		if(!obj){obj=this.$(document,'*');}
		var objs=[];
		var cssName=new RegExp("\\b"+css+"\\b");
		for(i=0;i<obj.length;i++){if(obj[i].className.match(cssName)){objs.push(obj[i]);}}
		return objs;
		},
	//浏览器判断：s.ie,s.firefox,s.chrome,s.opera,s.safari
	s:(s=ua.match(/msie ([\d.]+)/))?s.ie=s[1]:
	(s=ua.match(/firefox\/([\d.]+)/))?s.firefox=s[1]:
	(s=ua.match(/chrome\/([\d.]+)/))?s.chrome=s[1]:
	(s=ua.match(/opera.([\d.]+)/))?s.opera=s[1]:
	(s=ua.match(/version\/([\d.]+).*safari/))?s.safari=s[1]:0,
	//选项卡
	tabs:function(obja,a,b,objb){
		var d=new RegExp("\\b"+b+"\\b","ig");
		for(i=0;i<obja.length;i++){
			if(i==a){obja[a].className+=" "+b;if(objb){objb[a].className+=" "+b}}
			else{obja[i].className=obja[i].className.replace(d,"");if(objb){objb[i].className=objb[i].className.replace(d,"");}}
			}
		},
	//隔行换色
	colorLine:function(objs,css,onmm,off){
		for(i=0;i<objs.length;i++){
			var cssTemp=new RegExp("\\b"+css+"\\b","ig");
			if(!onmm){objs[i].className+=(i%2>0)?"":" "+css;}
			else if(off=="+"){objs[i][onmm]=function(){this.className+=" "+css;}}
			else if(off=="-"){objs[i][onmm]=function(){this.className=this.className.replace(cssTemp,"");}}
			else if(off=="~"){objs[i].ai=i;objs[i][onmm]=function(){pr.tabs(objs,this.ai,css);}}
			}
		},
	//返回全半角字符长度
	stringLen:function(s){
		var w=0;
		for (var i=0;i<s.length;i++) {
			var c=s.charCodeAt(i);
			if((c>=0x0001 && c<=0x007e) || (0xff60<=c && c<=0xff9f)){w++;}
			else{w+=2;}
			}
		return w;
		},
	//表单判断
	forms:function(obj,text,type,typeto,string){
		var obj=this.$(obj);
		if(type=="fontLen" && this.stringLen(obj[text])<4 || this.stringLen(obj[text])>16){obj.focus();return false}
		else if(type=="mail" && !obj[text].match(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)){obj.focus();return false}
		else if(type=="alert" && eval(typeto)){eval(string);obj.focus();return false}
		}
	}