// INITIAL CODE
_d=document;
_w=window;

s_a='undefined'; // Taken from SmartMenus s_loader.js

// The following function is used to blur objects
// It includes special logic to blur select fields in IE
// o = object to blur, t = tag name of object
function _blur(o){
	t = o.tagName?o.tagName.toLowerCase():'';
	alert(t);
	if(!(s_iE&&t=='select')){if(o.blur)o.blur()}
	else{_w.focus()} // This is the special "hack" for IE
}


// BROWSER DETECTION
s_ua=navigator.userAgent.toLowerCase();
s_dl=_d.getElementById?1:0;
s_iE=_d.all&&!_w.innerWidth&&s_ua.indexOf('msie')!=-1?1:0;
s_oP=s_ua.indexOf('opera')!=-1&&_d.clear?1:0;
s_oP7=s_oP&&_d.appendChild?1:0;
s_oP7m=s_oP&&!s_oP7?1:0;
s_nS4=_d.layers?1:0;
s_kNv=s_ua.indexOf('konqueror')!=-1?parseFloat(s_ua.substring(s_ua.indexOf('konqueror/')+10)):0;
s_kN=s_kNv>=2.2?1:0;
s_kN3p=s_kNv>=3?1:0;
s_kN31p=s_kNv>=3.1?1:0;
s_kN32p=s_kNv>=3.2?1:0;
s_nS=s_dl&&!_d.all&&s_ua.indexOf('opera')==-1&&!s_kN?1:0;
s_win=s_ua.indexOf('windows')!=-1?1:0; // Added to default code from SmartMenus
s_mC=s_ua.indexOf('mac')!=-1?1:0;
s_sF=s_mC&&s_ua.indexOf('safari')!=-1?1:0;
s_eS=s_ua.indexOf('escape')!=-1?1:0;
s_iE5M=s_mC&&s_iE&&s_dl&&!s_eS?1:0;
//s_iE5M=s_mC&&s_iE&&s_dl?1:0;
s_iE4M=s_mC&&s_iE&&!s_dl?1:0; // Outdated???
s_iE4=!s_mC&&s_iE&&!s_dl?1:0;
s_iE7=s_iE&&typeof(XMLHttpRequest)!=s_a?1:0;

// s_pS (boolean) = public site, eg "www.domain.com
with(location){var s_pS=(hostname!=''&&hostname.indexOf('.')!=-1);}
// s_xPsP2 (boolean) = SP2
//with(navigator){var s_xPsP2=(userAgent.indexOf('NT 5.1')!=-1&&appMinorVersion.indexOf('SP2')!=-1);}
// s_iEsP2 (boolean) = Internet Explorer in SP2
s_iEsP2=(s_ua.indexOf("sv1")!=-1);


// SAFE ONLOAD
function _addOnload(f){var l=_w.onload;_w.onload=!l?f:function(){	l();f();}
}


// DHTML


function gE(e,f){if (s_nS4){f=(f)?f:self;var V=f.document.layers;if (V[e]) return V[e];	for (var W=0; W<V.length;) 	t=gE(e,V[W++]); return t;}if(_d.all) return _d.all[e];return _d.getElementById(e);}

// Show element
function sE(e,x,y) {if (s_nS4) e.visibility='show';else 	e.style.visibility='visible';if (x) sX(e,x);if (y) sY(e,y);}

// Hide element
function hE(e) {if (s_nS4)	e.visibility='hide';else e.style.visibility='hidden';}

//Get visibility
function gV(e){var v=(s_nS4)?e:e.style;v=v.visibility;return (v=='show'||v=='visible');}

//Set z-index
function sZ(e,z) {if(s_nS4)e.zIndex=z;else	e.style.zIndex=z;}

//Get x position (relative)
function gX(e) {if(s_nS4)	return parseInt(e.left);else if(s_oP)	return parseInt(e.style.pixelLeft);else 	return parseInt(e.style.left);}

//Get y position (relative)
function gY(e){if(s_nS4)return parseInt(e.top);else if(s_oP)return parseInt(e.style.pixelTop); else return parseInt(e.style.top);}

// sx AND sY MAYBE NEED TO ADD STRING "px"!
//Set x position
function sX(e,x){if(s_nS4)e.left=x;else if(s_oP)e.style.pixelLeft=x;else e.style.left=x;}
//Set y position
function sY(e,y){if(s_nS4)e.top=y;else if(s_oP)e.style.pixelTop=y;else e.style.top=y;}

//Get position --> id = element id, a = 'x' or 'y', isImg = true or false
// !!! IMPORTANT: I HAVE REPLACED s_getO(id) WITH gE(id)
// !!! ALSO, I HAVE CHANGED
// !!!      oC+=a=='x'?oP.offsetLeft:oP.offsetTop;
// !!! TO   oC+=a=='x'?oP.offsetLeft-oP.scrollLeft:oP.offsetTop-oP.scrollTop;
//function gPos(id,a,isImg){var bodyStyleMarginTop=0;var o=isImg?_d.images[id]:gE(id);if(!o)return a=='x'?-630:0;if(s_nS4)return isImg?(a=='x'?o.x:o.y):(a=='x'?o.pageX:o.pageY);var oP,oC,ieW;oP=o.offsetParent;oC=a=='x'?o.offsetLeft:o.offsetTop;ieW=s_iE&&!s_mC?1:0;while(oP){if(ieW&&oP.tagName&&oP.tagName.toLowerCase()=='table'&&oP.border&&oP.border>0)oC++;oC+=a=='x'?oP.offsetLeft:oP.offsetTop;oP=oP.offsetParent};if(s_kN31p){return a=='x'?(document.body.style&&document.body.style.marginLeft?parseInt(document.body.style.marginLeft)+oC:document.body.marginWidth?parseInt(document.body.marginWidth)+oC:document.body.leftMargin?parseInt(document.body.leftMargin)+oC:oC+10):(document.body.style&&document.body.style.marginTop?parseInt(document.body.style.marginTop)+oC:document.body.marginHeight?parseInt(document.body.marginHeight)+oC:document.body.topMargin?parseInt(document.body.topMargin)+oC:oC+10)};return s_oP&&!s_oP7?a=='x'?oC:oC+bodyStyleMarginTop:oC};
//function gPos(id,a,isImg){var bodyStyleMarginTop=0;var o=isImg?_d.images[id]:gE(id);if(!o)return a=='x'?-630:0;if(s_nS4)return isImg?(a=='x'?o.x:o.y):(a=='x'?o.pageX:o.pageY);var oP,oC,ieW;oP=o.offsetParent;oC=a=='x'?o.offsetLeft:o.offsetTop;ieW=s_iE&&!s_mC?1:0;while(oP){if(ieW&&oP.tagName&&oP.tagName.toLowerCase()=='table'&&oP.border&&oP.border>0)oC++;oC+=a=='x'?oP.offsetLeft-oP.scrollLeft:oP.offsetTop-oP.scrollTop;oP=oP.offsetParent};if(s_kN31p){return a=='x'?(document.body.style&&document.body.style.marginLeft?parseInt(document.body.style.marginLeft)+oC:document.body.marginWidth?parseInt(document.body.marginWidth)+oC:document.body.leftMargin?parseInt(document.body.leftMargin)+oC:oC+10):(document.body.style&&document.body.style.marginTop?parseInt(document.body.style.marginTop)+oC:document.body.marginHeight?parseInt(document.body.marginHeight)+oC:document.body.topMargin?parseInt(document.body.topMargin)+oC:oC+10)};return s_oP&&!s_oP7?a=='x'?oC:oC+bodyStyleMarginTop:oC};

// !!! NOW ADDED oC+=a=='x'?_d.body.scrollLeft:_d.body.scrollTop;
function gPos(id,a,isImg){var bodyStyleMarginTop=0;var o=isImg?_d.images[id]:gE(id);if(!o)return a=='x'?-630:0;if(s_nS4)return isImg?(a=='x'?o.x:o.y):(a=='x'?o.pageX:o.pageY);var oP,oC,ieW;oP=o.offsetParent;oC=a=='x'?o.offsetLeft:o.offsetTop;ieW=s_iE&&!s_mC?1:0;while(oP){if(ieW&&oP.tagName&&oP.tagName.toLowerCase()=='table'&&oP.border&&oP.border>0)oC++;oC+=a=='x'?oP.offsetLeft-oP.scrollLeft:oP.offsetTop-oP.scrollTop;oP=oP.offsetParent};oC+=a=='x'?_d.body.scrollLeft:_d.body.scrollTop;if(s_kN31p){return a=='x'?(document.body.style&&document.body.style.marginLeft?parseInt(document.body.style.marginLeft)+oC:document.body.marginWidth?parseInt(document.body.marginWidth)+oC:document.body.leftMargin?parseInt(document.body.leftMargin)+oC:oC+10):(document.body.style&&document.body.style.marginTop?parseInt(document.body.style.marginTop)+oC:document.body.marginHeight?parseInt(document.body.marginHeight)+oC:document.body.topMargin?parseInt(document.body.topMargin)+oC:oC+10)};return s_oP&&!s_oP7?a=='x'?oC:oC+bodyStyleMarginTop:oC};

// NOT QUITE SURE WHETHER GET WIDTH AND HEIGHT OF ELEMENT WORKS CORRECT IN ALL VERSIONS OF OPERA
function gW(e,a){if(s_nS4)return e.clip.width;else if(s_oP&&!s_oP7)return e.style.pixelWidth;else return e.offsetWidth;}

// THE FOLLOWING FUNCTIONS DO  N O T  WORK!
//a = 1 means, that special function is used to get content width in other browsers
//      than IE and NS4, because offsetWidth is else not returned correctly if the
//      object is clipped (container table has smaller width)
//function gW(e,a){if(s_nS4)return e.clip.width;else if(s_oP&&!s_oP7)return e.style.pixelWidth;else return a?gW2(e):e.offsetWidth;}

//t = temp variable to store original overflow value
//w = width
//function gW2(e){
//	var t=e.style.overflow;
//     e.style.overflow='auto';
//     var w=e.scrollWidth;
//     e.style.overflow=t;
//     return w;
//}

//function gW2(el){
//	var frag = document.createDocumentFragment();
//	var p1=document.createElement('DIV');
//	var p2=document.createElement('DIV');
//	p2.style.visibility='hidden';
//	p1.style.width=el.style.width;
//	p1.style.height=el.style.height;
//	p2.style.position='absolute';
//	p1.style.position='relative';
//	p1.innerHTML=el.innerHTML;
//	document.body.appendChild(p2);
//	p2.appendChild(p1);
//	var w=p1.offsetWidth;
//	document.body.removeChild(p2);
//    return w;
//}

//Get height	
function gH(e){if(s_nS4)return e.clip.height;else if(s_oP&&!s_oP7)return e.style.pixelHeight;else return e.offsetHeight;}
// NOT QUITE SURE WHETHER SET WIDTH AND HEIGHT OF ELEMENT WORKS CORRECT IN ALL VERSIONS OF OPERA
//Set width
function sW(e,w){if(s_nS4)e.clip.width=w;else if(s_oP)e.style.pixelWidth=w;else e.style.width=w;}

//Set height	
function sH(e,h){if(s_nS4)e.clip.height=h;else if(s_oP)e.style.pixelHeight=h;else e.style.height=h;}

//Set clip
function sC(e,t,r,b,x){if(s_nS4){X=e.clip;X.top=t;X.right=r;X.bottom=b;X.left=x;}else e.style.clip='rect('+t+' '+r+' '+b+' '+x+')';}

//Write html
function wH(e,h){if(s_nS4){Y=e.document;Y.write(h);Y.close();}if(e.innerHTML)e.innerHTML=h;}

function toggle(n) {var obj = gE(n,''); if (obj == null) return; if (obj.style.display == null || obj.style.display == 'none'){obj.style.display = 'block';}	else{	obj.style.display = 'none';}}

function collapse(n) {var obj = gE(n,''); if (obj == null) return; obj.style.display = 'none';}

function expand(n) {var obj = gE(n,''); if (obj == null) return; obj.style.display = 'block';}


// WINDOW RELATED
// Window width and height - do not call before onload
function _winW(){return s_nS4?innerWidth:_d.body.offsetWidth;}
function _winH(){return s_nS4?innerHeight:_d.body.offsetHeight;}

// Function that opens link in popup
// u = url, t = target, w = width, h = height, s = scrollable (boolean)
// x = horizontal position (can be omitted), y = vertical position (can be omitted)
function _popup(u,t,w,h,s,x,y){
	if(!t){
			_w.location.href=u;
	}else{
// ADD CODE, THAT REMEMBERS ALL WINDOW OBJECTS GLOBALLY
// THAT WAY WE CAN ADD CODE THAT CHECKS IF A WINDOW IS CLOSED, AND IF NOT CAN GIVE FOCUS TO IT WITHOUT RELOADING THE PAGE
		eval('pop_'+t+'=_w.open(\''+u+'\',\''+t+'\''+(!w?'':(',\'width='+w+',height='+h+',screenX='+(x?x:((_winW()-w)/2))+',left='+(x?x:((_winW()-w)/2))+',screenY='+(y?y:25)+',top='+(y?y:25)+',scrollbars='+(s?'yes':'no')+'\''))+');pop_'+t+'.focus();');
		//eval('pop_'+t+'=_w.open(\''+u+'\',\''+t+'\''+(!w?'':(	',\'
	// IN IE SP2 POSSIBLY ADDITIONAL HEIGHT HAS TO BE ADDED BECAUSE OF FORCED STATUS BAR OF 20-25 px HEIGHT
	// USE THE BOOLEAN EXPRESSION (s_pS&&s_iEsP2) TO DETECT CASES, WHERE STATUS BAR IS ADDED AUTOMATICALLY
		//		width='+w+',height='+h+',
	// IF WINDOW IS NOT "FULLSCREEN", THE FOLLOWING DOES NOT WORK VERY WELL
		//		screenX='+(x?x:((_winW()-w)/2))+',left='+(x?x:((_winW()-w)/2))+',
		//		screenY='+(y?y:25)+',top='+(y?y:25)+',
		//		scrollbars='+(s?'yes':'no')
		//		+'\''
		//	))+');pop_'+t+'.focus();');
		return eval('pop_'+t)
	}
}
