/* OPEN WINDOWS */
function setCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function delCookie(name) {
	setCookie(name,"",-1);
}
function addLoadEvent(func) {   
	var oldonload = window.onload;   
	if (typeof window.onload != 'function') {   
		window.onload = func;   
	} else {   
		window.onload = function() {   
			if (oldonload) {   
				oldonload();   
			}   
			func();   
		}   
	}   
}  
function elExpand(id ){
 
	this.id  = id;
	this.el =   document.getElementById(id);
	this.durSeconds = 1; 
	if (this.el) {
		this.exists = true;
		this.el.style.overflow='hidden';
		//this.el.style.position='relative';
		 
		if (this.el.fullHeight) this.fullHeight = this.el.fullHeight;
		else{
			this.fullHeight = this.el.offsetHeight;
			this.el.fullHeight = this.fullHeight;
		}
		if (this.fullHeight==0 || this.el.style.display=='none'){
			this.closed = true;
			this.el.style.visibility='hidden';
			this.el.style.display='block';
			this.fullHeight = this.el.offsetHeight;
			this.el.style.display='none';
			this.el.style.visibility='visible';
		}
		//this.adjust = parseInt(this.fullHeight/10);
	}
	 
	this.close = function(){
		this.endHeight = 0;
		this.startHeight = this.fullHeight ;
		this.height = this.startHeight;
		this.dir=-1;
		//this.heightAdjust = 0 - this.adjust;
		//if(this.timerID) clearInterval(this.timerID);
		this.startTime = new Date().getTime();
		this.resize();
	}
	
	this.open = function(){
		this.endHeight = this.fullHeight;
		this.startHeight = 0 ;
		this.dir=1;
		this.height = this.startHeight;
		//this.heightAdjust = this.adjust;
		//if(this.timerID) clearInterval(this.timerID);
		this.startTime = new Date().getTime();
		this.resize();
	}
	
    this.resize = function() {
		var elapsedTime = new Date().getTime() - this.startTime; // milliseconds
		var perCent =  parseInt(elapsedTime / ( 3*  this.durSeconds ));
        //this.height += this.heightAdjust;
		//if (this.heightAdjust > 0 && this.height > this.endHeight) this.height = this.endHeight;
		//if (this.heightAdjust < 0 && this.height < this.endHeight) this.height = this.endHeight;
		if (this.dir==1) {
			this.height = this.endHeight /100 * perCent;
			if (this.height > this.endHeight) this.height = this.endHeight;
		}
		else {
			this.height = this.startHeight - (this.startHeight /100 * perCent) ;
			if (this.height < this.endHeight) this.height = this.endHeight;
		}
		this.el.style.height = this.height  + 'px';
		if (this.height == this.endHeight){ // FINISHED!
			if(this.timerID) clearInterval(this.timerID);
			if ( this.endHeight==0) {	// CLOSING
				this.el.style.display='none';
				this.closed = true;
			}
			else this.closed = false;
			this.timerID=false;
			 
		}
		else if (! this.timerID ){
			this.el.style.display='block';
			var pThis = this;
			var f = function(){pThis.resize();}
			this.timerID = window.setInterval (f, 40);
		}
    }
}

function popWin(a,width, height, opts){
	url = a.href;
    if (! width)  width = 800; //screen.availWidth * .8;
    if (! height)  height = 640; // screen.availHeight * .8;
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
	if (! opts) opts = 'sc';
	var options = 'status='; options +=  (opts.indexOf('st')!= -1) ?  'yes' : 'no';
	options += ',toolbar=' ; options +=  (opts.indexOf('tb')!= -1) ?  'yes' : 'no';
	options += ',scrollbars=' ; options +=  (opts.indexOf('sc')!= -1) ?  'yes' : 'no';
	options += ',resizable=' ; options +=  (opts.indexOf('rs')!= -1) ?  'yes' : 'no';
	options += ',location=' ; options +=  (opts.indexOf('lo')!= -1) ?  'yes' : 'no';
	
	//toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no
    var windowFeatures = options + ",width=" + width + ",height=" + height + ",left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top;
     
	myWindow = window.open(url, "subWind", windowFeatures);
	myWindow.focus();
	return(false);
}

/* LOGIN FUNCTIONS */
elLogin = false; 
function showMiniLogin(){
	
	if (! elLogin) elLogin = new elExpand('miniLoginJS')
	if (elLogin){
		elLogin.open();
		document.getElementById("loginEmail").setFocus; 
		return(false); 
	}
	else return(true);
	
	var el = document.getElementById("miniLoginJS")
	if (el){
		el.style.display = "block";
		document.getElementById("loginEmail").setFocus; 
		return(false); 
	}
	else return(true);
}
function hideMiniLogin(){
	if (! elLogin) elLogin = new elExpand('miniLoginJS')
	if (elLogin){
		elLogin.close();
		return(false); 
	}
	else return(true);
	
	var el = document.getElementById("miniLoginJS");
	if (el){
		el.style.display = "none";
		return(false); 
	}
	else return(true); 
}
/*		BLOCK TOGGLE FUNCTIONS		*/
var btHideText='Hide';
var btShowText='Show';
var btElems = new Array;
 
function btInit(blockClass, btnClass, hideText, showText){
	if (hideText) btHideText = hideText;
	if (showText) btShowText = showText;
	
	// Hide the blocks
	var allElems = document.getElementsByTagName('*');
	var shown = 0;
	for (var i = 0; i < allElems.length; i++) {
		var thisElem = allElems[i];
		// Hide the blocks
		if (thisElem.className && thisElem.className == blockClass) thisElem.style.display = 'none';
		// Show the buttons
		else if (thisElem.className && thisElem.className == btnClass) thisElem.style.display = 'inline';
	}
}
function btSwitch(elLink, divID){
	if( btElems[divID] ) el = btElems[divID];
	else {
		var el = new elExpand(divID); //document.getElementById(divID);
		btElems[divID] = el;
	}
	if (el.exists) {
		if (el.closed) {
			el.open() ;
			elLink.firstChild.data = btHideText;
		}
		else{	
			el.close();  ;
			elLink.firstChild.data = btShowText;
		}
		elLink.blur();
	}
	
	return(false);
}



function loaded(){ 	if (getQSParam('pf')==1) self.setTimeout('pagePrint()', 500);}
function getQSParam(name){
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if (pair[0] == name) {
return pair[1];
}
}
}
function qbButtonClick(closeTitle, openTitle){
strID= "qbContent";
if (document.getElementById) el = window.document.getElementById(strID);
else if (document.all) el = window.document.all[strID];

if (!closeTitle) var closeTitle = 'Close';
if (!openTitle) var openTitle = 'Search';

var btnText = xbGetInnerHTML(window,'qbButton')
var elBbtn   =xbGetElement(window,'qbButton') // Info container
if(elBbtn) btnText = elBbtn.value;

if (btnText==closeTitle){
	//xbSetInnerHTML(window,'qbButton', openTitle)
	elBbtn.value = openTitle;
     xbSetElClass(elBbtn, 'qbButtonClose')
     xbElClose(el);
}
else{
	//xbSetInnerHTML(window,'qbButton', closeTitle)
	if(elBbtn){
		elBbtn.value = closeTitle;
		xbSetElClass(elBbtn, 'qbButtonOpen')
		xbElOpen(el);
	}
}
if(elBbtn)elBbtn.blur();
}
// -------------------------------------------
function pagePrint(){
if ( window.print ){
if (window.event) window.event.cancelBubble = true;
window.focus();
window.print( );
}
else alert("Sorry! Your browser doesn't support this function.");
}
// -------------------------------------------
function openPrintWindow(url){

	var scW = screen.availWidth ? screen.availWidth : screen.width;
	var scH = screen.availHeight ? screen.availHeight : screen.height;
	winW=Math.round(scW * .8);
	winH=Math.round(scH * .8);
	var winL=Math.round(scW-winW)/2;
	var winT=Math.round(scH-winH)/2;
	strOptions= 'height=' + winH +  ',width=' + winW + ',left='+winL+',top='+winT;
	strOptions += "toolbar=no,"; strOptions += "location=no,"; strOptions += "directories=no,";
	strOptions += "status=no,"; strOptions += "menubar=yes,"; strOptions += "scrollbars=yes,"; strOptions += "resizable=no";
	winName='Print';

	if (!window.winPrint){
		try{ winPrint = window.open(url,winName,strOptions);}
		catch(e){return(false);}; //window.alert("Popup window blocked " + e.number);}
	} else { // has been defined
		if (winPrint.closed){
			try{ winPrint.close(); winPrint = window.open(url,winName,strOptions);}
			catch(e){return(false);}; //window.alert("Popup window blocked " + e.number);}
		} else {
			try{ winPrint = window.open(url,winName,strOptions);}
			catch(e){window.alert("Popup window blocked " + e.number); }
		}
	}
	return(winPrint);

}
// -------------------------------------------
function openImgWindow(imgURL,imgW,imgH,caption,txFlag,sizeImg){

     var sizeImg = (sizeImg == null) ? true : sizeImg;
	var scW = screen.availWidth ? screen.availWidth : screen.width;
	var scH = screen.availHeight ? screen.availHeight : screen.height;
	scH = scH - 100;
	scW = scW - 20;
	var scrollBars = '';
	var vScrollBarW = (is_ie)? 30: 10;
	var hScrollBarH = 0;
	vScale = scH / imgH;
	if ( vScale < 1 ){
		imgH = Math.round(imgH * vScale);
		imgW = Math.round(imgW * vScale);
		scrollBars = 'scrollbars=yes,';
		vScrollBarW = 20;
	}
	hScale = scW / imgW  ;
	if ( hScale < 1 ){
		imgH = Math.round(imgH * hScale);
		imgW = Math.round(imgW * hScale);
		scrollBars = 'scrollbars=yes,';
		hScrollBarH = 20;
	}
     scrollBars = 'scrollbars=yes,';
	winH=Math.round(imgH)+80+ hScrollBarH;
	winW=Math.round(imgW)+40 + vScrollBarW;
	if ( caption && caption.length > 1 ){
		charsPerLine = winH/12;
		lines=caption.length/charsPerLine;
		winH = Math.round(winH + 40  + (10 * lines));
	}
	winH = ( winH > (scH-20) )? scH-20 : winH;
	winW = ( winW > (scW-20) )? scW-20 : winW;
	winL=Math.round(scW-winW)/2;
	winT=Math.round(scH-winH)/2;
	url='about:blank';
	options= 'height=' + winH +  ',width=' + winW + ',toolbar=no,directories=yes,' + scrollBars + 'status=no,menubar=yes,resizable=yes,left='+winL+',top='+winT;

	winName='winImage';
	// Open the window

	if (!window.winImage){
		try{ winImage = window.open(url,winName,options);}
		catch(e){return(false);}; //window.alert("Popup window blocked " + e.number);}
	} else { // has been defined
		if (!winImage.closed){
			try{ winImage.close(); winImage = window.open(url,winName,options);}
			catch(e){return(false);}; //window.alert("Popup window blocked " + e.number);}
		} else {
			try{ winImage = window.open(url,winName,options);}
			catch(e){window.alert("Popup window blocked " + e.number); }
		}
	}
	if (winImage){
		winImage.focus();
		if(caption){
			arrayTemp = caption.split('|');
			caption = arrayTemp[0];
			text = arrayTemp[1];
		}
		/* BODGE ALERT!! this assumes that the relative part of the path leads to the site's root!! */
		//pos = window.location.lastIndexOf('/pages/');
		// relRoot=window.location.substring(0, pos+3);
		// pos = imgURL.lastIndexOf('../');	relRoot=imgURL.substring(0, pos+3);
		var path = window.location.href;
		pos = path.lastIndexOf('/pages/');
          relRoot=path.substring(0, pos+1);

		html='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/strict.dtd">\n';
		html+='<html><head>\n';
		html+='<link rel="stylesheet"  href="' + relRoot + 'style/popup.css" type="text/css">\n';
		html+='<title>Image Viewer<\/title><\/head>\n';
		html+='<body>\n';
		if (caption) html+='<p class="pTitle" align="center">'+caption+'<\/p>\n';
		if (txFlag=='1'){	// Transparent overlay
			html += '<center><div  style="width:' + imgW + 'px; height:' + imgH + 'px; margin: 0 0 20px 0;';
			html += 'background-image:url(' + imgURL + ');background-repeat: no-repeat;">';
			txPath= '../../style/images/transparent.gif';
			html += '<img src="'+txPath+'" width="'+imgW+'" height="'+imgH+'" border="0" alt="'+caption+'"\/>';
			html += '</div></center>';
		}
		else {
			if(sizeImg) html+='<center><img src="'+imgURL+'" width="'+imgW+'" height="'+imgH+'" border="0" alt="'+caption+'"\/></center>\n';
			else html+='<center><img src="'+imgURL+'" border="0" alt="'+caption+'"\/></center>\n';
		}
		try{ if(text) html+='<p class="pText" align="center">'+text+'<\/p>\n';}
		catch(e){};
		html+='<center><a href="javascript:window.close();" >Close Window</a></center>\n';
		html+='<\/body><\/html>\n';

		winImage.document.write(html);
		winImage.document.close();
          winImage.focus();
		return (false);
	}
	else return (true);
}
// -------------------------------------------
function openViewer(url){
var scW = screen.width; //screen.availWidth ? screen.availWidth : screen.width;
var scH = screen.height; //screen.availHeight ? screen.availHeight : screen.height;
var winW=800; //scW *.66;
var winH=640; //scH *.66;
var winL=Math.round(scW-winW)/2;
var winT=Math.round(scH-winH)/2;
var strOptions = 'height=' + winH +  ',width=' + winW + ',toolbar=no,directories=no,status=no,' + 'menubar=no,scrollbars=yes,resizable=no,left='+winL+',top='+winT;
var winName='winView';
return (openWindow(url,winName,strOptions));
}
// -------------------------------------------
function openPopup(url, winName,winW, winH ){
var scW = screen.availWidth ? screen.availWidth : screen.width;
var scH = screen.availHeight ? screen.availHeight : screen.height;
if (! winW ) var winW=800; //scW *.66;
if (! winH ) var winH=640; //scH *.66;
var winL=Math.round(scW-winW)/2;
var winT=Math.round(scH-winH)/2;
var strOptions = 'height=' + winH +  ',width=' + winW + ',toolbar=no,directories=no,status=no,' + 'menubar=yes,scrollbars=yes,resizable=no,left='+winL+',top='+winT;
if (!winName) winName='winInfo';
return (openWindow(url,winName,strOptions));
}
// -------------------------------------------
function openDownload(url ){
var scW = screen.availWidth ? screen.availWidth : screen.width;
var scH = screen.availHeight ? screen.availHeight : screen.height;
var winW=640;
var winH=480;
var winL=Math.round(scW-winW)/2;
var winT=Math.round(scH-winH)/2;
strOptions = 'height=' + winH +  ',width=' + winW + ', toolbar=no,directories=no,status=no,' + 'menubar=yes,scrollbars=yes,resizable=no,left='+winL+',top='+winT;
winName='winDownload';
return (openWindow(url,winName,strOptions));
}
// -------------------------------------------
function openWindow(url, winName, strOptions, winW, winH){
var winName='winPop';

var scW = screen.availWidth ? screen.availWidth : screen.width;
var scH = screen.availHeight ? screen.availHeight : screen.height;
if (! winW ) winW=Math.round(scW * .9);
if (! winH) winH=Math.round(scH * .9);
var winL=Math.round(scW-winW)/2;
var winT=Math.round(scH-winH)/2;
if (! strOptions) strOptions= 'height=' + winH +  ',width=' + winW + ',location=yes,toolbar=yes,directories=yes,status=yes,' + 'menubar=yes,scrollbars=yes,resizable=yes,left='+winL+',top='+winT;
if (!window.winName){

try{ winName =  window.open(url,winName,strOptions);}
catch(e){return(false);};//window.alert("Popup window blocked " + e.number);}
} else {
if (!winName.closed){
try{ winName.close(); winName = window.open(url,winName,strOptions);}
catch(e){return(false);};//window.alert("Popup window blocked " + e.number);}
} else {
try{ winName = window.open(url,winName,strOptions);}
catch(e){return(false);};//window.alert("Popup window blocked " + e.number); }
}
}
if (winName ) winName.focus();
return (false);
}
function newWin(aEl){  	var url = aEl.href;return(openWindow(url));}
// -------------------------------------------
function Banner_start(){
	if (is_win && (is_ie5up || is_gecko || is_opera5up )) {
		elTest = xbGetElement(window,this.textID)
		if ( this.firstCall == 1 ) this.firstCall = 0;
		else if ( elTest != null  ){
			xbSetInnerHTML(window,this.titleID,this.titles[this.banIndex]);
			xbSetInnerHTML(window,this.textID,this.text[this.banIndex]);
			this.banIndex++;
			if ( this.banIndex >= this.text.length ) this.banIndex = 0;
		}
		// Set callback
		var pThis = this;
		var f = function(){pThis.start();}
	this.timerID = window.setTimeout(f, this.banDuration * 1000);
	}
}
// ==============================
function Banner() {
	this.banIndex = 1;
	this.titleID='bannerTitle';
	this.textID='bannerText';
	this.titles = new Array();
	this.text = new Array();
	this.banCount=0;
	this.banDuration=5;
	this.firstCall=1;
	this.start = Banner_start;
}
// ==============================
function xbGetElement(win,strID){
	if (document.layers) return (xbGetNS4Element(win, strID))
	if (document.getElementById) return(win.document.getElementById(strID));
	else if (document.all) return( win.document.all[strID]);
}
// ==============================
function xbGetInnerHTML(win,strID){
var el = xbGetElement( win, strID );
if (el){
	if ( ! win.document.layers ){
		if (win.document.getElementById) return( el.innerHTML );
		else if (win.document.all)  return(el.innerHTML );
	}
}
}
// ==============================
function xbElClose(el){
if (document.getElementById || document.all) {
	el.style.visibility = 'hidden';
	el.style.display = 'none';
}
else if (document.layers)  el.visibility = 'hidden';
}
// ==============================
function xbElOpen(el, dispMode){
if (document.getElementById || document.all) {
	el.style.visibility = 'visible';
	if (! dispMode) dispMode='B';
	el.style.display = (dispMode=='B') ? 'block' : 'inline';
}
else if (document.layers)  el.visibility = 'visible';
}
// ==============================
function xbSetInnerHTML(win,strID,strHTML){
var el = xbGetElement( win, strID )
if ( el && ! win.document.layers ){
	if (win.document.getElementById)  el.innerHTML = strHTML;
	else if (win.document.all)  el.innerHTML  = strHTML;
}
}
// ==============================
function xbElHide(el){
if (document.getElementById || document.all) el.style.visibility = 'hidden';
else if (document.layers)  el.visibility = 'hidden';
}
// ==============================
function xbIsVisible(el){
var visible;
if (document.getElementById || document.all) visible = (el.style.visibility == 'visible');
else if (document.layers)   visible = (el.visibility == 'visible');
return(visible);
}
// ==============================
function xbElShow(el){
if (document.getElementById || document.all) {
	el.style.visibility = 'visible';
	el.style.display = 'block';
}
else if (document.layers)  el.visibility = 'visible';
}
// ==============================
function xbSetElClass(el,strClass){
if (el != null){
	if (document.layers ) ; //unsupported in document.layers.X
	else if (document.getElementById) el.className = strClass;
	else if (document.all ) el.className = strClass;
}
}
// ==============================
function setFormFocus(){
var frm = document.forms[0];
var done = false;
	if (document.forms.length == 0) return;
 	for (f = 0; f < frm.elements.length; f++){
 		if (! done){
            	if (frm.elements[f].type){
                 	if ( frm.elements[f].type.substr(0,5) != "selec" && frm.elements[f].type != "hidden" && frm.elements[f].type != "reset" && frm.elements[f].type != "submit" && ! frm.elements[f].disabled && ! frm.elements[f].readOnly){
					frm.elements[f].focus();
	 				done = true;
	 			             }
	  		 }
 		}
 	}
}
 
function elVisible(blockID){
var state;
     el = xbGetElement(window,blockID);
     if (document.layers) state = el.visibility ;
     else state = el.style.visibility;
	return( (state=='visible')? true: false);
}

 
vdsTimer=null;
vdsTop=0;

var agt=navigator.userAgent.toLowerCase();
// Note: On IE5, these return 4, so use is_ie5up to detect IE5.
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var is_gecko = (agt.indexOf('gecko') != -1);
var is_moz = (agt.indexOf('mozilla') != -1);
var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
var is_nav6up = (is_nav && (is_major >= 5));
var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie3    = (is_ie && (is_major < 4));
var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
var is_opera = (agt.indexOf("opera") != -1);
var is_opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
var is_opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
var is_opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
var is_opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
var is_opera5up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4);
var is_win = (agt.indexOf("win")!=-1);
var is_mac = (agt.indexOf("mac")!=-1);
window.onload=loaded;
/* Fixes IE Hourglass on mous-over */
try { document.execCommand("BackgroundImageCache", false, true);} 
catch(err) {}
