var browser = navigator.appName;
var versionInfo = navigator.appVersion;
var versionNum = parseFloat(versionInfo);
var vendor = navigator.vendor;
var IE = "Microsoft Internet Explorer";
var IE6 = "MSIE 6.0";
var IE7 = "MSIE 7.0";
var safari = "Apple Computer, Inc.";
var imagePath = "images/";
var classAttribute = classAttr();   //Get the appropriate class attribute to set. IE and Firefox use different attributes for class in the DOM.

/***** Begin preload images *****/
var origImg = [];	//Array of images for rollovers
origImg[0] = '';

var overImg = [];	// Array of images to preload
overImg[0] = '';

var preloadFlag = false;
function preloadImages() {
	for (i=0; i<overImg.length; i++) {
		var images = [];
		images[i] = new Image();
		images[i].src = imagePath + overImg[i];
	}
	preloadFlag = true;
}
/***** End preload images *****/

/***** Begin image rollover funtion *****/
// This function grabs the src attribute and replaces "off" with "on" (for mouseover) or "on" with "off (for mouseout) in the attribute string. KM
function rollover(event) {
	var etype = event.type;
	var imgSrc = getObjectAttribute(this,"src");
	var newImgSrc;
	
	if (etype == 'mouseover'){
	    newImgSrc = imgSrc.replace('off.','on.','gi');
		this.setAttribute('src',newImgSrc);
	}
	
	else if (etype == 'mouseout') {
	    newImgSrc = imgSrc.replace('on.','off.','gi');
		this.setAttribute('src',newImgSrc);
	}
}

// IE 6 transparent PNG rollover function. KM
function rolloverPNG(event) {
	var etype = event.type;
	var imgSrc = getObjectAttribute(this,"name");
	var newImgSrc;
	
	if (etype == 'mouseover'){
	    newImgSrc = imgSrc.replace('off.','on.','gi');
		this.setAttribute('src',newImgSrc);
	}
	
	else if (etype == 'mouseout') {
	    newImgSrc = imgSrc.replace('on.','off.','gi');
		this.setAttribute('src',newImgSrc);
	}
}

/* Function to initalize rollover */
function initRollovers() {
    var rollovers = getElementsByClass('rollover', null, null); //Get elements with a class of "rollover"

    if (rollovers.length > 0) {		//If there is at least one element with a class "rollover"
        for (var i = 0; i < rollovers.length; i++) {	//Loop through all elements with class "rollover"
            var classValue = rollovers[i].getAttribute(classAttribute);

            if ((versionInfo.match(IE6) !== null) && (classValue.match('tpng') !== null)) { //If the browser is IE6 and a transparent png				
                addEvent(rollovers[i], 'mouseover', rolloverPNG); //Attach mouseover event
                addEvent(rollovers[i], 'mouseout', rolloverPNG); //Attach mouseout event				
            }
            else {
                addEvent(rollovers[i], 'mouseover', rollover); //Attach mouseover event
                addEvent(rollovers[i], 'mouseout', rollover); //Attach mouseout event
            }
        }
    }
}

// When function needs to be added inline (e.g. dynamically added content) KM
function rolloverInline(imgId,type) {
	var imgObj = _gel(imgId);
	var imgSrc = getObjectAttribute(imgObj,'src');
	var newImgSrc;	

	if (type == 'over'){
	    newImgSrc = imgSrc.replace('off.','on.','gi');
		imgObj.setAttribute('src',newImgSrc);
	}

	

	else if (type == 'out') {
	    newImgSrc = imgSrc.replace('on.','off.','gi');
		imgObj.setAttribute('src',newImgSrc);
	}
}
/***** End image rollover function *****/

/***** Begin pop up functions *****/
function popWindow(href,title,sb,width,height) {
	window.open(href,title,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars='+ sb +',resizable=0,width='+ width +',height='+ height +',top=150,left=150');
}
/***** End pop up functions *****/

/***** Begin clear value functions *****/
// This function can be used to add a focus event to any input with a class of "clear-value". Needs jquery.js
function initClearValue(UpdatePanelID) {
    var selector = ".clear-value";
    var input = $(selector);

    if (input.length > 0) {
        for (var i = 0; i < input.length; i++) {           
            $(input[i]).focus(function() {
                $(this).val("");
                $(this).removeClass("clear-value");
                $(this).unbind("focus");
            });
        }
    }
}
/***** End clear value functions *****/

//requires JQuery
$().ready(function() {
    initRollovers();
});