/*
 * Project: SLKV
 * Commons Utils functions
 * Date:  
 */
var _w=window,
	_d=document,
	_l=_w.location,
	__mouseX=0,__mouseY=0,
	__winWidth=0,__winHeight=0,
	__vertScroll=0,__horiScroll=0;
_d.gtn_=_d.getElementsByTagName;
_d.gid_=_d.getElementById;
_d.ce_=_d.createElement;
var _CLS_="className";
var _UDF_="undefined";
var _IMGEXT_="gif";
var _IMGPATH_="_images/";
function BrowserChecking(){
	var b=navigator.appName;
	if(b.indexOf('Netscape')!=-1)this.b="ns";
	else if(b=="Opera"||(navigator.userAgent.indexOf("Opera")>0))this.b="opera";
	else if(b=="Microsoft Internet Explorer")this.b="ie";
	if(!b)alert('Unidentified browser.\nThis browser is not supported!');
	this.version=navigator.appVersion;
	this.fv=parseFloat(this.version);
	this.v=parseInt(this.version);
	this.ns=(this.b=="ns"&&this.v>=4);
	this.ns4=(this.b=="ns"&&this.v==4);
	this.ns6=(this.b=="ns"&&this.v==5);
	this.ns7=(navigator.userAgent.indexOf('Netscape/7')>0);
	this.ie=(this.b=="ie"&&this.v>=4);
	this.ie4=(this.version.indexOf('MSIE 4')>0);
	this.ie5=(this.version.indexOf('MSIE 5')>0);
	this.ie55=(this.version.indexOf('MSIE 5.5')>0);
	this.ie6=(this.version.indexOf('MSIE 6.0')>0);
	this.ie7=(this.version.indexOf('MSIE 7.0')>0);
	if(this.ie){
		this.iev=parseInt(this.version.substring(this.version.indexOf('MSIE ')+5));
		this.ieFixed=(navigator.appMinorVersion.split(';').length>3)||(navigator.userAgent.indexOf('NT 5.1')>0);
	}
	this.opera=(this.b=="opera");
	this.dom=(_d.ce_&&_d.appendChild&&_d.gtn_)?true:false;
	this.def=(this.ie||this.dom); // most used browsers, for faster if loops
	this.dyn=(this.dom||this.ie||this.ns4);
	var ua=navigator.userAgent.toLowerCase();
	if(ua.indexOf("win")>-1)this.platform="win32";
	else if(ua.indexOf("mac")>-1)this.platform="mac";
	else this.platform="other";
}
var is=new BrowserChecking();
function isObject(v){
	return (typeof v=="object");
}
function isString(v){
	return (typeof v=="string");
}
function __getParent(){
	return _d._dEs[this.getAttribute("pID__")];
}
function __firstObject(obj){
	if(obj)for(var i in obj)if(typeof obj[i]=='object'&&obj[i])return obj[i];
	return null;
}
var _tag=new Object();
_tag.tbl=function(w,h,b,cp,cs,cls,bg,s,id){
	w=w!=0?' width="'+(w?w:'100%')+'"':'';
	h=h?' height="'+h+'"':'';
	b=' border="'+(b?b:'0')+'"';
	cp=' cellpadding="'+(cp?cp:'0')+'"';
	cs=' cellspacing="'+(cs?cs:'0')+'"';
	cls=cls?' class="'+cls+'"':'';
	bg=bg?' background="'+bg+'"':'';
	s=s?' style="'+s+'"':'';
	id=id?' id="'+id+'"':'';
	return '<table'+w+h+b+cp+cs+cls+bg+s+id+'>';
}
_tag.tbl_=function(){
	return '</table>';
}
_tag.td=function(w,bg,cls,nw){
	w=w?' width="'+w+'"':'';
	bg=bg?' background="'+bg+'"':'';
	cls=cls?' class="'+cls+'"':'';
	return '<td'+w+bg+cls+(nw?' nowrap':'')+'>';
}
_tag._td=function(){
	return '</td>';
}
_tag.img=function(s,w,h){
	if(!is.ie||(s.toLowerCase()).indexOf('.png')<0)return '<img src="'+s+'"'+(w?' width="'+w+'px"':'')+(h?' height="'+h+'px"':'')+' />';
	else return '<div style="width:'+(w?w:1)+';height:'+(h?h:1)+';filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+s+'\',sizingMethod=\''+(w&&h?'scale':'image')+'\');"></div>';
}
function getImage(src){
	return _IMGPATH_ + src + "." + _IMGEXT_;
}
function getSpacer(){
	return "spacer." + _IMGEXT_;
}
function attachEvent(e,evt,hdl){
	if(e){
		if(e.addEventListener)e.addEventListener(evt,hdl,false);
		else if(e.attachEvent)e.attachEvent("on"+evt,hdl);
		else e["on"+evt]=hdl;
	}
}
function detachEvent(e,evt,hdl){
	if(e){
		if(e.removeEventListener)e.removeEventListener(evt,hdl,false);
		else if(e.detachEvent)e.detachEvent("on"+evt,hdl);
		else e["on"+evt]=null;
	}
}
function getWinWidth(d,w){
	var ww=0;
	if(!d)d=_d;
	if(!w)w=_w;
	if(d.body&&d.body.clientWidth)ww=d.body.clientWidth;
	else if(d.documentElement&&d.documentElement.clientWidth)ww=d.documentElement.clientWidth;
	else if(d.body&&d.body.offsetWidth)ww=d.body.offsetWidth;
	else if(w.innerWidth)ww=w.innerWidth;
	return ww;
}
function getWinHeight(d,w){
	var wh=0;
	if(!d)d=_d;
	if(!w)w=_w;
	if(w.innerHeight) {
		wh=w.innerHeight;
	}else if(d.documentElement&&d.documentElement.clientHeight){
		wh=d.documentElement.clientHeight;
	}else if(d.body&&d.body.clientHeight){
		wh=d.body.clientHeight;
	}
	return wh;
}
function __unSelectable(e){
	var i,t;
	if(is.ie){
		e=_w.event;
		if(!e){
			for(i=0;i<_w.frames.length;i++)
				if(_w.frames[i]&&_w.frames[i].event){
					e=_w.frames[i].event;
					break;
				}
		}
	}
	if(!e)return false;
	t=is.ie?e.srcElement:e.target;
	if(t&&typeof t.form!=_UDF_&&t.tagName.toLowerCase()!='label')return true;
	else return false;
}
function __emptyFunc(evt){
	return false;
}	
function __removeEvents(el){
	var i;
	for(i in el)if(el[i]&&typeof el[i]=="function")el[i]=null;
	if(el.childNodes)for(i in el.childNodes)__removeEvents(el.childNodes[i]);
}
function getClientPos(e){
	if(!e)return null;
	if(isString(e))e=_d.gid_(e);
	else if(e.el&&e.type=="DynInteface")e=e.el;
	if(!e)return null;
	var l=e.offsetLeft,t=e.offsetTop,p=e.parentNode,_wd=e.offsetWidth?e.offsetWidth:e.clientWidth;
	while(p&&p.offsetLeft!=null&&p.offsetTop!=null&&p.tagName.toLowerCase()!="body"){
		if(p.tagName.toLowerCase()!='tr'){
			if  (p.offsetLeft==24 && is.ns){l+=21;_wd+=3}
			else{
			    l+=p.offsetLeft;
			}	
			t+=p.offsetTop;
		}
		if(is.ie&&p.style){
			if(p.style.borderLeftStyle&&p.style.borderLeftStyle!='none'&&p.style.borderLeftWidth)l+=parseInt(p.style.borderLeftWidth);
			else if(p.style.borderStyle&&p.style.borderStyle!='none'&&p.style.borderWidth)l+=parseInt(p.style.borderWidth);
			if(p.style.borderTopStyle&&p.style.borderTopStyle!='none'&&p.style.borderTopWidth)t+=parseInt(p.style.borderTopWidth);
			else if(p.style.borderStyle&&p.style.borderStyle!='none'&&p.style.borderWidth)t+=parseInt(p.style.borderWidth);
		}
		p=p.offsetParent;
	}
	return {left:l,top:t,width:_wd,height:e.offsetHeight?e.offsetHeight:e.clientHeight};
}

function _TO(){};
var p=_TO.prototype;
p._g=function(e,t){return e.getElementsByTagName(t);}
p._n=function(e){return e.nextSibling;}
p._p=function(e){return e.previousSibling;}
p._f=function(e){return e.firstChild;}
p._l=function(e){return e.lastChild;}
p._pn=function(e){return e.parentNode;}
p._a=function(p,c){p.appendChild(c);};
var _to=new _TO();
function isEmail(emailStr){
	var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; 
	// not valid 
	var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; 
	// valid 
	if ( !reg1.test( emailStr ) && reg2.test( emailStr ) ) { 
		return true; 
	} else { 
		return false; 
	} 
}
function IsNumeric(ch){
	if (ch=="0"||ch=="1"||ch=="2"||ch=="3"||ch=="4"||ch=="5"||ch=="6"||ch=="7"||ch=="8"||ch=="9")return true;
	else return false;
}
function IsNumber(str){
	var i, ch;
	for (i=0; i<str.length; i++){
		ch = str.substring(i,i+1);
		if (!IsNumeric(ch))return false;
	}
	return true;
}

