/*********************************************************************************
 Global variables
*********************************************************************************/
//Default browsercheck
function browsercheck(){
    this.ver=navigator.appVersion
    this.agent=navigator.userAgent
    this.dom=document.getElementById?1:0;
    this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
    this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0;
    this.ie4=(document.all && !this.dom)?1:0;
    this.ie=this.ie4||this.ie5||this.ie6
    this.mac=this.agent.indexOf("Mac")>-1
    this.opera5=this.agent.indexOf("Opera 5")>-1
    this.ns6=(this.dom && parseInt(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.opera5 || this.dom)
    return this
}
var bw=browsercheck();

window.name = "MainWin";

if(!bw.bw){
        alert("I'm sorry some of the scripts on this page may not work with\n" +
              "your browser.  Please update your browser and visit again.\n");
}


var PageImages = new Array();
var PageAltImages = new Array();
var nest = "";
var loaded = 0;


/*********************************************************************************
Images Preload
*********************************************************************************/
		
function LoadActiveImages() {
	var num = document.images.length;
	for (var i = 0; i < num; i++) {
		var thisImage = document.images[i];
		var thisImageSrc = thisImage.src;
		var imageName = thisImageSrc.substring(0,thisImageSrc.lastIndexOf("_o"));
		//document.write(imageName + "<BR>");
		if (thisImageSrc.lastIndexOf("_off") != -1) {
			PageImages[i] = new Image(thisImage.width, thisImage.height);
      	    PageImages[i].src = imageName + "_on.gif";
		} else if (thisImage.src.lastIndexOf("_on") != -1) {
			PageAltImages[i] = new Image(thisImage.width, thisImage.height);
      	    PageAltImages[i].src = imageName + "_off.gif";
		}
    }
}
	
/*********************************************************************************
Image Swap
*********************************************************************************/
function imageSwap(which, state) {
     	
	//which - required input of image name
	//state - required input of image rollover state (1 for on, 0 for off)
	//div1,div2,... - optional input layer hierarchy for Netscape 4.0 browsers
	var divNest=''
	var argLength = arguments.length
	
	//loop over the arguments, to check for any passed div id's, and set the nesting
	if (argLength>2) {
		for (var i = 2; i < argLength; i++)  
		divNest=divNest+'document.'+arguments[i]+'.';
	}
	
	//get the element obj reference
 bw.dom?thisImage=document.getElementById(which):bw.ie4?document.all[which]:thisImage=eval(divNest+"document[which]");
	
	//find the image src name
	var imageName = thisImage.src.substring(0,thisImage.src.lastIndexOf("_o"));
	//toggle the src name based on state
	state == 0?endString = "_off.gif":endString = "_on.gif";
	//alert(layerOver);
	//set the image src to the new src
	bw.dom?thisImage.setAttribute("src",imageName + endString):thisImage.src=imageName + endString;
}

/*********************************************************************************
Window Functions
*********************************************************************************/	

// suppress errors
/*function stopError() {
	return true;
}
window.onerror = stopError;
*/

if (window.focus) {
	self.focus();
}

function popWindow(URL,name,widgets) {
	popwin = window.open(URL,name,widgets);
	popwin.focus();	
	popwin.opener = self;
	popwin.name = name;
	window.name = "MainWin";			
}

function popTypedWin(url, windowname, type, strWidth, strHeight) {
	/*if(self.name == windowname){
		self.name="blech"
	};*/
	//closeWin();//close any open window
	//alert("called popwin"+self.name);
	if (type == "fullScreen" || type == "console") {//if this is a fullscreen popup, get the screen properties to center the window
		strScreenWidth = screen.availWidth - 10;
		strScreenHeight = screen.availHeight - 160;
	}
	
	var tools="";
	if (type == "standard" || type == "fullScreen") {
		tools = "resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width="+strScreenWidth+",height="+strScreenHeight+",top=0,left=0";
	}
	if (type == "console") {
		newTop = 10;//(strScreenHeight-strHeight)/2
		newLeft = (strScreenWidth-strWidth-10)/2;
		tools = "resizable=no,toolbar=no,location=no,scrollbars=no,width="+strWidth+",height="+strHeight+",left="+newLeft+",top="+newTop+"";
	}
	//alert("newLeft "+newLeft + " "+newTop + " " +strWidth);
	newWindow = window.open(url, windowname, tools);
	newWindow.name=windowname;
	newWindow.focus();
	newWindow.opener = self;
}
/*
	popup code used to launch window holding Flash version of Horizons site
	for use as follows:
		<a href="horizons.html" 
			onClick="popTypedWin(this.href,'newWin','console',756,520);return false;" 
			onKeyPress="this.onClick();" 
			target="newWin" 
			title="This site requires Flash 6.">Flash site</a>
*/
function closeWin(){
	window.close()
}

function printPage(lang) {
  if (window.print) {
    window.print() 
  } else if (lang == "fr/") {
    alert("Dsol, votre fureteur ne supporte pas cette fonction. Utilisez l'option impression de votre fureteur pour imprimer cette page."); 
  } else if (lang == "en/") {
    alert("Sorry, your browser doesn't support this feature. \nUse the print option on your browser to print this page"); 
  } else {
  	alert("Sorry, your browser doesn't support this feature. \nUse the print option on your browser to print this page"); 
  }
}

/**************************************************************************************
show and hide a div
**************************************************************************************/
function getStyleObject(strId) {
	//alert(strId);
	if (document.getElementById && document.getElementById(strId)) {
		return document.getElementById(strId).style;
	} else if (document.all && document.all(strId)) {
		return document.all(strId).style;
	} else {
		return false;
	}
}

function element(strId) {
	//alert(strId);
	if (document.getElementById && document.getElementById(strId)) {
		return document.getElementById(strId);
	} else if (document.all && document.all(strId)) {
		return document.all(strId);
	} else {
		return false;
	}
}
	
function fnExpand(strDivId, objSymbol, blnSwitch) {
	//alert(strDivId);
	//event.cancelBubble = true;
	var objStyle = getStyleObject(strDivId);
	//alert(objStyle.display);
	if (objStyle.display == "none") {
		objStyle.display = "";
		//alert('will be minus');
		//alert(objSymbol);
		if (blnSwitch == 1) {
			objSymbol.src = "../images/btn-minus.gif";		
		}
		//alert(objSymbol.src);
	} else {
		objStyle.display = "none"
		//alert('will be plus');
		if (blnSwitch == 1) {
			objSymbol.src = "../images/btn-plus.gif";	
		}	
	}
}

//SHOW / HIDE DIVS
//deprecated rename others in fc code someday
function fnShowDiv(strDivId){showDiv(strDivId)}function fnHideDiv(strDivId){hideDiv(strDivId)}


function showDiv(strDivId) {
	var objStyle = getStyleObject(strDivId);
	objStyle.display = "block";	
}

function hideDiv(strDivId) {
	var objStyle = getStyleObject(strDivId);
	objStyle.display = "none";	
}

function showDivs() {
	for(var i=0; i<arguments.length; i++) {
		showDiv(arguments[i])
	}
}

function hideDivs() {
	for(var i=0; i<arguments.length; i++) {
		hideDiv(arguments[i])
	}
}

function toggleDivs() {
	for(var i=0; i<arguments.length; i++) {
		toggleDiv(arguments[i])
	}
}

function toggleDiv(strDivId) {
	divStyle = getStyleObject(strDivId)
	divStyle.display = element(strDivId).offsetWidth > 0 ? "none" : "block"
}

//SHOW / HIDE INLINE ELEMENTS

function toggleInlines(args) {
	for(var i=0; i<arguments.length; i++) {
		toggleInline(arguments[i])
	}
}

function toggleInline(strInlineId) {
	inlineStyle = getStyleObject(strInlineId)
	inlineStyle.display = element(strInlineId).offsetWidth > 0 ? "none" : "inline"
}

// SHOW / HIDE TABLE ROWS
function showRow(strRowId) {
	var objStyle = getStyleObject(strRowId);
	objStyle.display = "table-row";	
}

function hideRow(strRowId) {
	var objStyle = getStyleObject(strRowId);
	objStyle.display = "none";	
}


function toggleRows() {
	for(var i=0; i<arguments.length; i++) {
		toggleRow(arguments[i])
	}
}

function toggleRow(strRowId) {
	rowStyle = getStyleObject(strRowId)
	rowStyle.display = element(strRowId).offsetWidth > 0 ? "none" : "table-row"
}


