// shortcuts for common objects
_W=window; _D=_W.document;

// _G: wrapper and shortcut for getElementById
function _G(id){if(_D.getElementById){return _D.getElementById(id+'')}else{return null}}

// _GT: wrapper and shortcut for getElementsByTagName
function _GT(t,d){if(_D.getElementsByTagName){return (d?d:_D).getElementsByTagName(t+'')}else{return []}}

// _GA: wrapper and shortcut for getAttribute
function _GA(o,id){var t='';if(typeof(o)=='object'){if(o.getAttribute){t = o.getAttribute(id+'')};return t}}

// _GC: getClassByName
function _GC(t,d){var i,j,a,b,k,l,r=[]; a=(d?d:_D).getElementsByTagName("*");k=a.length;for(i=0;i<k;i++){if(a[i].className){b=a[i].className.split(' ');l=b.length;for(j=0;j<l;j++){if(t==b[j]){r[r.length]=a[i]};}}};return r;}

// _E: wrapper and shortcut for createElement
//		p - note to append to (default document)
//     id - set id of element
//   hide - if true hide element on creation
function _E(n,p,id,hide){var e=null;if(_D.createElement){e=_D.createElement(n); if(hide){e.style.display='none'}; (p?p:_D.body).appendChild(e)};if(id){e.id=id};return e}

// _GC: wrapper and shortcut for createElement
function _O(o){return typeof(o)=='object'?true:false}


function pad(t,i,n){var r=t+'',c=n?n:'0';while(r.length<i){r=c+r;};return r;}
function trim(s){s = (s + '');while(1){if((s.charAt(0)==' ')||(s.charAt(0)=="\t")){s = s.substring(1,s.length);}else{break;};};while(1){if((s.charAt(s.length-1)==' ')||(s.charAt(s.length-1)=="\t")){s = s.substring(0,s.length-1);}else{break;};};return s;};



// hooks for user-generated events
var Hooks = {
	h:[[],[],[]],p:function(t){return t=='all'?-1:(t=='before'?0:(t=='after'?2:1))},e:function(n,t,bR,p1,p2,p3,p4,p5){var f,p=Hooks.p(t);if(_O(Hooks.h[p][n])){for(f in Hooks.h[p][n]){if(Hooks.h[p][n][f]==true){eval(f)(p1,p2,p3,p4,p5);}};if(bR){Hooks.Reset(n)}}},

	Add: function(n,f,t){var p=this.p(t);if(!_O(this.h[p][n])){this.h[p][n]=[]};this.h[p][n][f]=true},
	Delete: function(n,f){if(!_O(this.h[1][n])){return};this.h[1][n][f]=false},
	Reset: function(n,t){var p=this.p(t);this.h[1][n]=[];if(p==-1){this.h[0][n]=this.h[2][n]=[]}},
	Count: function(n,t){var i=0,j,p=this.p(t),f,a=p<0?[0,1,2]:[1],o;for(j in a){o=this.h[a[j]][n];if(_O(o)){for(f in o){if(o[f]){i++}}}};return i},
	Exec: function(n,bR,p1,p2,p3,p4,p5){Hooks.e(n,'before',false,p1,p2,p3,p4,p5);Hooks.e(n,0,bR,p1,p2,p3,p4,p5);Hooks.e(n,'after',false,p1,p2,p3,p4,p5);}
}



// work with cookies
var Cookie = {
	// get cookie (name)
	Get: function(n){var dc=document.cookie,p=n+"=",b=dc.indexOf("; "+p),e; if(b == -1){b=dc.indexOf(p);if(b != 0) return null;}else{b += 2;};e=dc.indexOf(";",b);if(e == -1){e = dc.length;};return unescape(dc.substring(b+p.length,e));},

	// set cookie (name, value, days = 1)
	Set: function(n,v,d){var t = new Date(),e=t;if (d==null||d==0)d=1;e.setTime(t.getTime() + 3600000*24*d);document.cookie=n+"="+escape(v)+"; expires="+e.toGMTString()+'; path=/';},

	// del cookie (name, path, domain = '')
	Delete: function(n,p,d){if(Cookie.Get(n)){document.cookie=n+"="+((p)?"; path="+p:"")+((d)?"; domain="+d:"")+"; expires=Thu, 01-Jan-70 00:00:01 GMT";};}
}




// parse current window location
var url = window.location.href;
var url_proto = url.replace(/(.*):\/\/([^\/]+)(.*)/ig,'$1');
var url_host = url.replace(/(.*):\/\/([^\/]+)(.*)/ig,'$2');
var url_path = url.replace(/(.*):\/\/([^\/]+)(.*)/ig,'$3');
var a = url_path.split('#'); url_path = a[0];
var url_path_comment = url.replace(/(.*):\/\/([^\/]+)(.*)#(.*)/ig,'$4');
var url_root = url_proto+'://'+url_host+'/';





// convert useful window events to hooks
_W.onload = function(){
	Hooks.Exec('Window_OnLoad');
}
_W.onfocus = function(){
	Hooks.Exec('Window_OnFocus');
}
_W.onunload = function(){
	Hooks.Exec('Window_OnUnload');
}
if(typeof(_W.onresizeend) == 'function'){
	_W.onresizeend = function(){
		Hooks.Exec('Window_OnResize');
	}
}else{
	_W.onresize = function(){
		Hooks.Exec('Window_OnResize');
	}
}




// global mouse position
var m_x = m_y = 0;
document.onmousemove = function(e){
	m_x = (window.event ? window.event.clientX: (e ? (e.pageX ? e.pageX : 0) : 0));
	m_y = (window.event ? window.event.clientY: (e ? (e.pageY ? e.pageY : 0) : 0));
}




// parse useragent and try detect browser
_ua = navigator.userAgent.toUpperCase();
_mac = (_ua.indexOf("MAC") != -1) ? true : false;
_opera = (_ua.indexOf("OPERA") != -1) ? true : false;
_safari = (_ua.indexOf("SAFARI") != -1) ? true : false;
_khtml = (_ua.indexOf("KHTML") != -1) ? true : false;
_ie = ((document.all&&!_opera) ? true : false);
_win = (_ua.indexOf("WIN") < 0) ? false : true;








// base object
_S = new Object();
// core variables
_S.V = new Object();
// hooks
_S.__H = new Array();
_S.__H[0] = new Array();
_S.__H[1] = new Array();
_S.__H[2] = new Array();

_W = window;
_D = window.document;

var _L = new Array();

// screen dimensions
_S.V.SW = (screen?(screen.availWidth?screen.availWidth:screen.width):640);
_S.V.SH = (screen?(screen.availHeight?screen.availHeight:screen.height):480);

// popup default width/height values
_S.V.PW = '700';
_S.V.PH = '600';
_S.V.PR = 1; //sizeable
_S.V.PSB = 1; // scrollbar


_S.V.__page_load_chk = -1;


// open window
_S.W = function(U,T,P){
	return window.open(U,T,P);
}


// main popup. only url is required
_S.P = function(U,pW,pH,bSB,bM,bRT){
  var X,Y,W,H,O,bFS;
	W=pW?pW:_S.V.PW;
	H=pH?pH:_S.V.PH;
	X=(_S.V.SW>W?((_S.V.SW/2)-(W/2)):0);
	Y=(_S.V.SH>H?((_S.V.SH/2)-(H/2)):0);
	bFS = (_S.V.SW<W||_S.V.SH<H);
	O=_S.W(U,"","scrollbars="+(((typeof(bSB)=="undefined"?_S.V.PSB:bSB)||bFS)?1:0)+",toolbar=0,status=0,menubar=0,directories=0,resizable="+((_S.V.PR||bFS)?'1'+(bFS?',maximized=1':''):0)+",location=0,"+(screen?"width="+(_S.V.SW<W?_S.V.SW:W)+",height="+(_S.V.SH<H?_S.V.SH:H)+",":'')+"left="+X+",top="+Y+",screenX="+X+",screenY="+Y+',modal='+(bM?1:0));
//	O.opener=self;
	if(O.focus){O.focus()};
	if(bRT){return O};
};

// popup dialog
_S.PD = function(U,pW,pH,bSB){
	return _S.P(U,pW,pH,bSB,1);
}

// popup text
_S.PT = function(T,pW,pH,bSB){
	var k=_S.P('',pW,pH,bSB,1,1);var d=k.document;d.write("<html><head></head><body style='background-color:#fff;margin:0;padding:0;'>"+T+"</body></html>");d.close();
}

_S.PP = function(U,W,H){
	var k=_S.P('',W,H,0,0,1);var d=k.document;d.write("<html><head><title>"+W+"x"+H+"</title></head><body style='background-color:#fff;margin:0;padding:0;'><a href='javascript:close()' style='display: block' title='Click to close'><img src='"+U+"' width='"+W+"' height='"+H+"' border='0' alt='Click to close'></a></body></html>");d.close();
}

