// **************************************
// * rd_javascript_lib.js		*
// * Version 3.0			*
// * a library of usefull functions 	*
// * for writting javascript		*
// *					*
// * Emil Diego				*
// * Reddrop, Inc.			*
// * emil@reddrop.com			*
// **************************************

var isNav, isIE;
var isMac, isWin;

isNav = false;
isIE  = false;
isMac = false;
isWin = false;

// Determine which browser we are using
if (parseInt(navigator.appVersion) >= 4) {
	if (navigator.appName == "Netscape") {
		isNav = true;
	} else {
		isIE = true;
	}
}

// Determine which os the browser is running on
if ((navigator.platform).substr(0, 3) == "Mac") {
	isMac = true;
} else {
	isWin = true;
}

//*******************************
//* Image Manipulation		*
//*******************************
//*
//* rdFindImage
//* Find an image given the name and return it.
//* If we are running in netscape we have to check all the layers, since the image arrays are seperated for each layer
function rdFindImage(sName) {
	var index;
	var temp_image = null;
	var num_layers = 0;
	
	
	
	if (isNav) {
		var	i = 0;
		if (document.layers == null)
			num_layer = 0;
		else
			num_layers = document.layers.length;
		if (num_layers > 0) {
			// search the main document first.  then search all layers
			for (index = 0; index < document.images.length; index++) {
				if (document.images[index].name == sName) {
					return document.images[index];
				}
			}
			
			// we need to search all layers for the images.
			for (index = 0; index < num_layers; index++) {
				for (i = 0; i < document.layers[index].document.images.length; i++) {	
					if (document.layers[index].document.images[i].name == sName) {
						return document.layers[index].document.images[i];
					}
				}
			}
			
		} else {
			// just search the document images collection.
			for (index = 0; index < document.images.length; index++) {
				if (document.images[index].name == sName) {
					return document.images[index];
				}
			}
		}
		
	} else {
		for (index = 0; index < document.images.length; index++) {
			if (document.images[index].name == sName) {
				return document.images[index];
			}	
		}
	}
	return null;
}

//*
//* rdButtonOn
//* Used in mouse over events to highlight a selected image button.
//* this function assumes that an images exists called <imgName>_on.
function ButtonOn(imgName) {
	imgOn = eval(imgName + '_on.src');
	
	if (isNav) {
		var temp_obj = rdFindImage(imgName);
		temp_obj.src = imgOn;

	} else {
		document.images [imgName].src = imgOn;
	}
}

//*
//* rdButtonOff
//* Used in mouse over events to turn off a selected image button.
//* this function assumes that an images exists called <imgName>_off.
function ButtonOff(imgName) {
	
	imgOff = eval(imgName + '_off.src');
	
	if (isNav) {
		var temp_obj = rdFindImage(imgName);
		temp_obj.src = imgOff;
	} else {
		document [imgName].src = imgOff;
	}
}





//*******************************
//* Style Sheet Manipulation	*
//*******************************
//*
//* rdFindLayer
//* find a layer or style given the name and return it
function rdFindLayer(sName) {
	var index;
	var tmp_obj = null;
	
	if (isNav) {
		var num_layers = 0;
		if (document.layers == null) {
			//* Must be netscape 6 or greater.  Doesn't support layers anymore
			tmp_obj = document.getElementById(sName);
  			if (tmp_obj != null) 
  				return tmp_obj;
		} else {
			//* Netscape version less than 6
			num_layers = document.layers.length;
			for (index = 0; index < num_layers; index++) {
				if (document.layers[index].name == sName)
					return document.layers[index];	
				
			}
			
		}
		
		return null;
	} else {
		
		tmp_obj = document.all[sName];
		if (tmp_obj == null) {
			//* Not valid
			return null;
		} else {
			//* valid
			return tmp_obj;
		}
		
		/*
		for (index = 0; index < document.all.length; index++) {
			if (document.all[index].id == sName) {
				return document.all[index];
			}		
		}	
		return null;
		*/
	}
}

//*
//* rdShowLayer
//* find a layer specified by the name and make it visible
function rdShowLayer(sName) {
	var	temp_obj = null;
	
	temp_obj = rdFindLayer(sName);	
	//alert(temp_obj);
	if (temp_obj != null) {
		// we fo und it
		if (isNav) {
			//alert(temp_obj.visibility);
			temp_obj.visibility = "show";
		} else {
			//alert(temp_obj.style.visibility);
			temp_obj.style.visibility = "visible";
		}
	} else {
		// we didn't find it
		return false;
	}
	return true;	
}

//*
//* rdHideLayer
//* find a layer specified by the name and make it invisible
function rdHideLayer(sName) {
	var	temp_obj = null;
	
	temp_obj = rdFindLayer(sName);
	if (temp_obj != null) {
		// we fo und it

		if (isNav) {
			temp_obj.visibility = "hide";
		} else {
			temp_obj.style.visibility = "hidden";
		}
		
		return true;
		
	} else {
		// we didn't find it
		return false;
	}

	return true;	
}



		

//*******************************
//* ANCHORS			*
//*******************************
//*
//* rdGetAnchorElement
//* Returns an anchor with the specified name
function rdGetAnchorElement(sName) {
	var xElem = null;	

	if (isIE) {
		xElem = document.all [sName];
		
		return xElem;
		
	} else {
		var	i = 0;
		var 	index = 0;
		for (index = 0; index < document.layers.length; index++) {
			for (i = 0; i < document.layers[index].document.anchors.length; i++) {
				if (document.layers[index].document.anchors[i].name == sName) {
					return document.layers[index].document.anchors[i];
				}
			}
		}
	}
}

//*
//* rdGetAnchorCount
//* Return the number of anchors in the page
function rdGetAnchorCount() {
	var count = 0;
	if (isIE) {
		count = document.all.length;
	} else {
		count = document.anchors.length;
	}
	
	return count;	
}


//*******************************
//* Misc			*
//*******************************
//*
//* rdSetWindowStatus
//* set the window status bar message.
function rdSetWindowStatus(xWindow, sMsg) {
	
	xWindow.status = sMsg;
	
}

//*
//* rdEmptyLink
//* Used in netscape in the HREF to allow the event handlers.
function rdEmptyLink() {
	
	return false;
}
