
/* Last Modified $Date: 1/12/06 1:05p $ by $Author: Esadikov $ (Version history stored in Source Control) */

// set up browser detect vars
var isNS4 = (navigator.appName.indexOf("Netscape") != -1 && navigator.appVersion.charAt(0) == "4");
var isMOZ = (navigator.appName.indexOf("Netscape") != -1 && parseInt(navigator.appVersion.charAt(0)) >= 5);
var isIE = (navigator.appName.indexOf("Microsoft") != -1);
var browserVersion = parseInt(navigator.appVersion.charAt(0));
if (isIE) {
    temp = navigator.appVersion.split("MSIE")
    browserVersion = parseFloat(temp[1])
}
//alert("isNS4 = " + isNS4 + "\nisMoz = " + isMOZ + "\nisIE = " + isIE + "\nbrowserVersion = " + browserVersion);

// adapted from MM_findObj
function findObject(name, doc) {

	// get document, if it hasn't been passed
	if (!doc) doc = document;

	// declare object reference
	var obj = null;

	// check document and document.all collections	
	if (!(obj = doc[name]) && doc.all) {
		obj = doc.all[name];
	}
	
	// check document.layers collection
	if (!obj && document.layers) {
		for (var i = 0; !obj && i < doc.layers.length; i++) {	
			obj = findObject(name, doc.layers[i].document);
		}
	}
		
	if (!obj && doc.getElementById) {
		obj = doc.getElementById(name);
	}
	
	return obj;
}

/*
 * This function highlights an image
 *
 * @param	image - the name of the image to be flipped
 * @param	dir - path to image dir (ex: "../images/nav/")
 * @param	imgName - optional, if name attribute is different from the image file name
 */
function over(image, dir, imgName) { 
	if (document.images) {
		var img = (imgName) ? findObject(imgName) : findObject(image);
		// store reference to old image for the out function
		img.rsrc = img.src;
		img.src = dir + image + "_on.gif";
	}
}

/**
 * This function restores an image
 *
 * @param	image - the name of the image to be flopped
 * @param	imgName - optional, if name attribute is different from the image file name
 */
function out(image) {
	if (document.images) {
		var img = findObject(image);
		// set source to stored reference to the old image
		img.src = img.rsrc;
	}
}

function pickRandom(range) {
	if (Math.random) {
		return Math.round(Math.random() * (range-1));
	}
    else {
        return 0;
    }
}

function liOver(obj) {
    if (isIE) obj.className += " over";
}
function liOut(obj) {
    if (isIE) obj.className = obj.className.replace(" over", "");
}

function getPinned() {
    var primaryNav = document.getElementById("primaryNav");
    for (var p = 0; p < primaryNav.childNodes.length; p++) {
        if (primaryNav.childNodes[p].nodeName == "UL") {
            var navList = primaryNav.childNodes[p];
            for (var n = 0; n < navList.childNodes.length; n++) {
                if (navList.childNodes[n].className && navList.childNodes[n].className.indexOf("pin") > -1) {
                    return navList.childNodes[n];
                }
            }
        }
    }
    return null;
}

function hidePinned(obj) {
    if (obj.className.indexOf("pin") == -1) {
        var pinned = getPinned();
        if (pinned != null) {
            for (var c = 0; c < pinned.childNodes.length; c ++) {
                if (pinned.childNodes[c].nodeName == "UL") {
                    if (isIE) pinned.childNodes[c].style.display = "none";
                    else pinned.childNodes[c].style.visibility = "hidden";
                }
            }
        }
    }
}

function showPinned(obj) {
    if (obj.className.indexOf("pin") == -1) {
        var pinned = getPinned();
        if (pinned != null) {
            for (var c = 0; c < pinned.childNodes.length; c ++) {
                if (pinned.childNodes[c].nodeName == "UL") {
                    if (isIE) pinned.childNodes[c].style.display = "block";
                    else pinned.childNodes[c].style.visibility = "visible";
                }
            }
        }
    }
}

function openWindow(url, name, options) {
	var win = window.open(url,name,options);
    if (win != null) {
        win.focus();
    }
    return win;
}

function openSizedWindow(url, w, h, name) {
	if (!name) name = 'newWindow';
	var win = window.open(url,name,'toolbar=no,menubar=no,scrollbars=no,resizable=no,width=' + w + ',height=' + h);
    if (win != null) {
        win.focus();
    }
    return win;
}

function openReSizableWindow(url, w, h, name) {
	if (!name) name = 'newWindow';
	var win = window.open(url,name,'toolbar=no,menubar=no,resizable=yes,scrollbars=yes,width=' + w + ',height=' + h);
    if (win != null) {
        win.focus();
    }
    return win;
}

function openSizedWindowWithSB(url, w, h, name) {
	if (!name) name = 'newWindow';
	var win = window.open(url,name,'toolbar=no,menubar=no,resizable=no,scrollbars=yes,width=' + w + ',height=' + h);
    if (win != null) {
        win.focus();
    }
    return win;
}

function jumpTo(selectBox) {
	var url = selectBox.options[selectBox.selectedIndex].value;
	if (url != "") window.location.href = url;
}

function smWindow(url, name) {
    if (!name) name = 'newWindow';
    openReSizableWindow(url, 420, 300, name);
}

function lgWindow(url, name) {
    if (!name) name = 'newWindow';
    openReSizableWindow(url, 790, 550, name);
}


function showPic(n){
	var largeImage=document.getElementById("tn_large");
	var oldSrc=largeImage.src;
	var newSrc=oldSrc.replace(/tn[1-9]/,"tn"+n);
	largeImage.src=newSrc; 
}

/** Roatating Case Studies */
/**
 * This function returns a random number in the specified range
 *
 * @param	range- max integer value of the random number
 */
function pickRandom(range) {
	if (Math.random) {
		return Math.round(Math.random() * (range-1));
	}
	else {
		var now = new Date();
		return (now.getTime() / 1000) % range;
	}
}


/** Return the cookie value by its name. Returns null if no such cookie found.*/
function getCookie(cookieName)
{
	var results = document.cookie.match(cookieName + '=(.*?)(;|$)');

	if( results )
	{
		return (unescape(results[1]));
	}
  	else
  	{
    	return null;
    }
}

function createCookie(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=/";
}

/** find object on the page, by ID */
function bgGetElementById(id) {
	var elem = null;
	if (document.all) {
		elem = document.all[id];
	}
	else if (document.getElementById) {
		elem = document.getElementById(id);
	}
	return elem;
}
