// tools.js
// 2005/04/08
//
d = window.document
loaded = false;
active = '1';
delay=300;
timer = null;
// popped = 0;
cookieStr = cookie_load('wilsonfan');
searchStr = '';
var myquery =  self.location.search.substr(1);
if(myquery != '') {
	var params = myquery.split('&');
	for(i=0;i<params.length;i++) {
		var tmpval = params[i].split('=');
		if(tmpval[0]== 'sid') {
			searchStr = tmpval[1];
			break;
		}
	}
	if(searchStr != '' ) {
//		alert(searchStr);
		document.cookie ="wilsonfan=" + searchStr;
	}
}



function init(){
	loaded = true;
}

function set_submenu(num) {
	document.images[ 'ar' + num].src ='/images/common/menu_arrow_at.gif';
}

// browser detection object

function lib_bwCheck(){
	this.ver = parseInt(navigator.appVersion);
	this.agent = navigator.userAgent.toLowerCase();
	this.dom = document.getElementById?1:0
	this.opera = (this.agent.indexOf("opera")>-1);
	this.opera5 = (this.agent.indexOf("opera 5")>-1 || this.agent.indexOf("opera/5")>-1);
	this.nav = ((this.agent.indexOf('mozilla')>-1) && (this.agent.indexOf('spoofer')==-1) 
	&& (this.agent.indexOf('compatible') == -1) && (this.agent.indexOf('opera')==-1) 
	&& (this.agent.indexOf('webtv')==-1) && (this.agent.indexOf('hotjava')==-1));
	this.nav4up = (this.nav && (this.ver == 4));
	this.nav6up = (this.nav && (this.ver >= 5));
	this.gecko = (this.agent.indexOf('gecko')>-1);
	this.ie5 = (this.agent.indexOf("msie 5")>-1 && this.dom && !this.opera)?1:0
	this.ie6 = (this.agent.indexOf("msie 6")>-1 && this.dom && !this.opera)?1:0
	this.ie4 = (document.all && !this.dom && !this.opera)?1:0
	this.ie = ((this.agent.indexOf("msie") != -1) && (this.agent.indexOf("opera") == -1));
	this.ie4up = (this.ie && (this.ver >= 4));
	this.mac = this.agent.indexOf("mac")>-1
	this.ns6 = (this.dom && this.ver>=5)?1:0
	this.ns4 = (document.layers && !this.dom)?1:0
	this.bw = (this.ie6||this.ie5||this.ie4||this.ns4||this.ns6||this.opera)
	return this
}
bw = new lib_bwCheck() // Browser object

function lib_pfCheck(){
	this.ver = parseInt(navigator.appVersion);
	this.agent = navigator.userAgent.toLowerCase();	
	this.win = ((this.agent.indexOf("win")!=-1) || (this.agent.indexOf("16bit")!=-1) );
	// NOTE: On Opera 3.0, the userAgent string includes "Windows 95/NT4" on all
	// Win32; can't distinguish between Win95 and WinNT.
	this.win95 = ((this.agent.indexOf("win95")!=-1) || (this.agent.indexOf("windows 95")!=-1));

	// is this a 16 bit compiled version?
	this.win16 = ((this.agent.indexOf("win16")!=-1) || (this.agent.indexOf("16bit")!=-1) || 
		(this.agent.indexOf("windows 3.1")!=-1) || (this.agent.indexOf("windows 16-bit")!=-1) );  
	this.win31 = ((this.agent.indexOf("windows 3.1")!=-1) || (this.agent.indexOf("win16")!=-1) || 
		(this.agent.indexOf("windows 16-bit")!=-1));

	this.winme = ((this.agent.indexOf("win 9x 4.90")!=-1));
	this.win2k = ((this.agent.indexOf("windows nt 5.0")!=-1));
	
	// NOTE: Reliable detection of Win98 may not be possible. It appears that:
	//       - On Nav 4.x and before you'll get plain "Windows" in userAgent.
	//       - On Mercury client, the 32-bit version will return "Win98", but
	//         the 16-bit version running on Win98 will still return "Win95".
	this.win98 = ((this.agent.indexOf("win98")!=-1) || (this.agent.indexOf("windows 98")!=-1));
	this.winnt = ((this.agent.indexOf("winnt")!=-1) || (this.agent.indexOf("windows nt")!=-1));
	this.win32 = (this.win95 || this.winnt || this.win98 || ((this.ver >= 4) && (navigator.platform == "Win32")) || 
		(this.agent.indexOf("win32")!=-1) || (this.agent.indexOf("32bit")!=-1));	
	this.os2 = ((this.agent.indexOf("os/2")!=-1) || (navigator.appVersion.indexOf("OS/2")!=-1) || 
		(this.agent.indexOf("ibm-webexplorer")!=-1));
	this.mac = (this.agent.indexOf("mac")!=-1);
	this.mac68k = (this.mac && ((this.agent.indexOf("68k")!=-1) || (this.agent.indexOf("68000")!=-1)));
	this.macppc = (this.mac && ((this.agent.indexOf("ppc")!=-1) || (this.agent.indexOf("powerpc")!=-1)));
	
	return this
}
pf = new lib_pfCheck() // Platform object

lib_cssCheck();

///////
function lib_obj(obj){
	this.el = bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval('document.' + obj):0;
	this.css = bw.dom?document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?document.layers[obj]:0;
	this.moveIt = lib_moveIt;
	this.showIt = lib_showIt;
	this.hideIt = lib_hideIt;
	return this;
}

function lib_moveIt(x,y){
	if (x){this.x=x; this.css.left = x;}
	if (y){this.y=y; this.css.top = y;}
}
function lib_showIt(){this.css.visibility = "visible"}
function lib_hideIt(){this.css.visibility = "hidden"}
/////// 

function changeactive(which,obj) {
	if (loaded){
		// change destination of fan/index to member area index if cookie is present
//		if(which=='2' && cookieStr != null) {
//			obj.href='/cgi-bin/fan/memcontents.cgi?sid=' + cookieStr;
//		}
		clearTimeout(timer);
		m_rollover('item' + which);
//		popped = 1;
		mDiv['m' + active].hideIt();
		m_rollout('item' + active);
		active =which;
		mDiv['m' + active].showIt();
		m_rollover('item' + active);		
	}
}

function killIt(){
	if (loaded){
		mDiv['m' + active].hideIt();
		m_rollout('item' + active);	
	}
}

function killmenu(){
	if (loaded){
		timer = setTimeout("killIt()",delay);
	}
}

function sleep(){
	clearTimeout(timer);
}

function prepare_menus() {
	mDiv = new Array();
	for (var i=0;i<4;i++){
		mDiv['m' +i] = new lib_obj('m' +i);
	}
}

function get_memlinkurl(memitem) {
	var memItems = new Array('wpsc', 'standby');
	var myurl = '<a href="';
	if(cookieStr != null) {
		myurl += ('/cgi-bin/fan/mem_' + memItems[memitem] + '.cgi?sid=' + cookieStr + '"');
	} else {
		myurl += 'fan/';
		myurl += memItems[memitem] + '/index.html"';
	}
	myurl +=  ' target="_self">';
	document.write(myurl);
}

function check_memaccess(memitem) {
	// check if member access
	if(cookieStr != null) {
		var memItems = new Array('wpsc', 'standby');
		var myurl = ('/cgi-bin/fan/mem_' + memItems[memitem] + '.cgi?sid=' + cookieStr);
		self.location.href = myurl;		
	} else {
		return true;
	}
}

function cookie_load(name) {
	this.$document = document;
	this.$name = name;
	var allcookies = this.$document.cookie;
  	if (allcookies == "") return null;
	var start = allcookies.indexOf(this.name + '=');
   	if (start == -1) return false;   // Cookie not defined for this page.
	start += this.$name.length + 1;  // Skip name and equals sign.
	var end = allcookies.indexOf(';', start);
	if (end == -1) end = allcookies.length;
	var cookieval = allcookies.split('=')[1];
	return cookieval;
}

function load_menu_rollovers(){
	mro_ar = new Array();
	for (var i=0;i<menu_ar.length;i++){
		mro_ar[menu_ar[i]] = new Array();
		mro_ar[menu_ar[i]]['off']=new Image();
		mro_ar[menu_ar[i]]['on']=new Image();
		mro_ar[menu_ar[i]]['off'].src= "/images/common/m" + menu_ar[i]+".gif";
		mro_ar[menu_ar[i]]['on'].src= "/images/common/m" +  menu_ar[i]+"_on.gif";
	}
}

function m_rollover(which){
	document.images[which].src =mro_ar[which]['on'].src;
}

function m_rollout(which){
	document.images[which].src =mro_ar[which]['off'].src;
}

//
// DHTML fix detection for Netscape browser resize
if (d.layers) {
	origWidth=innerWidth;
	origHeight=innerHeight;
	onresize=DHTMLfix;
}
		
// DHTML fix for Netscape browser resize
function DHTMLfix() {
	if (origWidth != innerWidth || origHeight != innerHeight) {
		location.reload();
	}
}

function fixNav(){
	if(d.layers){
		DHTMLfix();
	} else {
		history.go(0);
	}
}

//
// X Position Layer relative to anchor image
function get_xPos(object,offset){
	if(d.layers && !d.dom){
		xPos = d.images[object].x
	} else {
		xPos = d.images[object].offsetLeft;
		tempEl = d.images[object].offsetParent;
		while (tempEl != null) {
			xPos += tempEl.offsetLeft;
		    tempEl = tempEl.offsetParent;
		}
	}
	if (offset) xPos = xPos + offset;
	return xPos;
}

// Y Position Layer relative to anchor image 
function get_yPos(object,offset){
	if(d.layers && !d.dom){
		yPos = d.images[object].y
	} else {
		yPos = d.images[object].offsetTop;
		tempEl = d.images[object].offsetParent;
		while (tempEl != null) {
			yPos += tempEl.offsetTop;
		    tempEl = tempEl.offsetParent;
		}
	}
	if (offset) yPos = yPos + offset;
	return yPos
}

//
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
 d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function RunSwf(pass,name,ext,w,h){
	document.write("<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' ");
	document.write("codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' ");
	document.write("width='" + w + "' height='" + h + "' id='name' align='middle'>");
	document.write("<param name='allowScriptAccess' value='sameDomain' /><param name='wmode' value='opaque'/>");
	document.write("<param name='movie' value='" + pass + name + ext + "' />");
	document.write("<param name='quality' value='high' /><param name='bgcolor' value='#ffffff' />");
	document.write("<embed src='" + pass + name + ext + "' quality='high' bgcolor='#ffffff' ");
	document.write("width='" + w + "' height='" + h + "' name='name' align='middle' ");
	document.write("allowScriptAccess='sameDomain' wmode='opaque' type='application/x-shockwave-flash' ");
	document.write("pluginspage='http://www.macromedia.com/go/getflashplayer' />");
	document.write("</object>");
}