// used to replace images by id tag
function ReplaceImage(id, img)
{
	document.getElementById(id).src = img
}


// used to hilite a selected item in a list
function HiliteWebPart(w)
{ 
	w.className = "webpart_hilite"
	w.style.cursor='hand'
	//opacity(w.id, 100, 75, 0)
}


// used to un-hilite a selected item in a list
function UnHiliteWebPart(w)
{ 
	w.className = "webpart"
	//opacity(w.id, 75, 100, 0)
}


// used to hilite a selected item in a list
function Hilite(item)
{ 
	item.className = "hilite_item"
}


// used to un-hilite a selected item in a list
function UnHilite(item)
{ 
	item.className = "un_hilite_item"
}


// used to replace text in pop-ups using hidden text
function ReplaceHTML(o1,o2)
{
	document.getElementById(o2).innerHTML = document.getElementById(o1).innerHTML
}


// used toggle visibility of an item
function ToggleItem(id)
{
	if (document.getElementById(id).visibility == "visible")
	{
		changeObjectVisibility(id,'hidden')
	}
	else
	{
		changeObjectVisibility(id,'visible')
	}
}


// used to show info pop-ups ////////////////////////////////////////////////////////////////////////////////////////////////////
function ShowPopup (targetObjectId, eventObj, optPos) {
	var xOffset = 30;
	var yOffset = -30;
	var newXCoordinate
	var newYCoordinate

    if(eventObj) {
		// hide any currently-visible popups
		HideCurrentPopup();
		// stop event from bubbling up any farther
		eventObj.cancelBubble = true;
		// move popup div to current cursor position 
		// (add scrollTop to account for scrolling for IE)
		if (optPos)
		{
			newXCoordinate = optPos.offsetLeft + optPos.offsetWidth - document.getElementById(targetObjectId).offsetWidth + 3;
			newYCoordinate = optPos.offsetTop + optPos.offsetHeight;
		}
		else
		{
			newXCoordinate = (eventObj.pageX)?eventObj.pageX + xOffset:eventObj.x + xOffset + ((document.body.scrollLeft)?document.body.scrollLeft:0);
			newYCoordinate = (eventObj.pageY)?eventObj.pageY + yOffset:eventObj.y + yOffset + ((document.body.scrollTop)?document.body.scrollTop:0);
		}
		moveObject(targetObjectId, newXCoordinate, newYCoordinate);

		// and make it visible
		if( changeObjectVisibility(targetObjectId, 'visible') ) {
			// if we successfully showed the popup
			// store its Id on a globally-accessible object
			window.currentlyVisiblePopup = targetObjectId;
			return true;
		} else {
			// we couldn't show the popup
			return false;
		}
		} else {
		// there was no event object, so we won't be able to position anything, so give up
		return false;
    }
}

function HideCurrentPopup() {
    // note: we've stored the currently-visible popup on the global object window.currentlyVisiblePopup
    if(window.currentlyVisiblePopup) {
		changeObjectVisibility(window.currentlyVisiblePopup, 'hidden');
		window.currentlyVisiblePopup = false;
    }
}


function getStyleObject(objectId) {
    // cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
		// W3C DOM
		return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
		// MSIE 4 DOM
		return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
		// NN 4 DOM.. note: this won't find nested layers
		return document.layers[objectId];
    } else {
		return false;
    }
} 

function changeObjectVisibility(objectId, newVisibility) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
		styleObject.visibility = newVisibility;
		return true;
    } else {
		// we couldn't find the object, so we can't change its visibility
		return false;
    }
} 

function moveObject(objectId, newXCoordinate, newYCoordinate) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
		styleObject.left = newXCoordinate;
		styleObject.top = newYCoordinate;
		return true;
    } else {
		// we couldn't find the object, so we can't very well move it
		return false;
    }
} 


// These functions are used to show a large pop up window //////////////////////////////////////////////////////////////////////////////////////////
function ShowPopUpWindow(s,t)
{
	LockForm()
    ResizePopUpWindow()
    document.all("PopUpWindowFrame").src = s
    document.all("PopUpWindowTitle").innerText = t
    document.all("PopUpWindow").style.visibility = "visible"
    opacity('PopUpWindow',0,100,1000);
}

function HidePopUpWindow()
{    
    // Restore form as hidden
    opacity('PopUpWindow',100,0,0);
    document.all("PopUpWindow").style.visibility = "hidden"
    document.all("PopUpWindowFrame").src = 'Blank.htm'
    EnableForm()

}

function LockForm()
{
	window.scrollTo(0,0);
	document.body.scroll = "No";
    var body=document.body;
    var wx=body.clientWidth,wy=body.clientHeight;
    var shader=document.createElement('div');
    shader.id='shader';
    shader.style.background ="#000000"
    shader.style.filter = "alpha(opacity=50)"
    shader.style.position = "absolute"
    shader.style.top = "0"
    shader.style.left = "0" 
    shader.style.zIndex = "2" 
    shader.style.width = wx
    shader.style.height = wy
    document.body.appendChild(shader)
}

function EnableForm()
{
    var shader=document.getElementById('shader');
    shader.parentNode.removeChild(shader);
    document.body.scroll = "Yes";
}

function ResizePopUpWindow()
{
	var frame = document.getElementById("PopUpWindow");

    var body=document.body;
    var wx=body.clientWidth,wy=body.clientHeight;
    frame.style.top = "10"
    frame.style.left = "10" 
    frame.style.width = wx - 20
    frame.style.height = wy - 20
//	var htmlheight = document.body.parentNode.scrollHeight;
//	var windowheight = window.innerHeight;
//	if ( htmlheight < windowheight ) 
//	{ 
//		document.body.style.height = windowheight + "px"; 
//		frame.style.height = windowheight*.95 + "px"; 
//	}  
//	else 
//	{ 
//		document.body.style.height = htmlheight + "px"; 
//		frame.style.height = htmlheight*.95 + "px"; 
//	}
}

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 
