function setVisibilityBySelector(selector, newState){
	var topAry = $$(selector);
	
	for (i=0; i<topAry.length; i++) 
	{
		topAry[i].style.visibility = newState;
		//visible,hidden
	}
}

function openOverLay(value, type, headerText){
	if(!headerText)
	{
		headerText = '';	
	}
	
	insertOverLay('overlay', 'overlay');
	insertOverLayContentContainer('overlayContentContainer', 'overlayContentContainer', headerText);
	
	type = type.toLowerCase();
	switch(type)
	{
		case "video":
		  insertVideo('overlayContentContainer', 'videoContainer', value);
		  break;    
		case "image":
		  insertImage('overlayContentContainer', 'imageContainer', value);
		  break;
		default:
	} 

	recenterContentContainer('overlayContentContainer');
}

function recenterContentContainer(id){
	
	contentContainerWidth = $(id).getWidth();	
	contentContainerHeight = $(id).getHeight();
	tmpLeft = (document.viewport.getWidth()/2) - (contentContainerWidth/2);
	tmpTop = (document.viewport.getHeight()/2) - (contentContainerHeight/2);
	
	if(tmpLeft < 0){
		tmpLeft = 0;
	}
	
	if(tmpTop < 0){
		tmpTop = 0;
	}
	topOffset = document.viewport.getScrollOffsets().top;
	
	$(id).style.left = tmpLeft + "px";
	$(id).style.top = tmpTop + topOffset + "px";
}

function resizeOverLay(id, outterContainerId){
	
	tmpHeight1 = $(outterContainerId).getHeight();
	tmpHeight2 = $(document.body).getHeight();
//	tmpWidth1 = $(outterContainerId).getWidth();
//	tmpWidth2 = $(document.body).getWidth();

	if(tmpHeight1 > tmpHeight2){
		tmpHeight = tmpHeight1;
	}else{
		tmpHeight = tmpHeight2;
	}
	
/*	if(tmpWidth1 > tmpWidth2){
		tmpWidth = tmpWidth1;
	}else{
		tmpWidth = tmpWidth2;
	}
*/
	$(id).style.height = tmpHeight + "px";
//	$(id).style.width = tmpWidth + "px";
}

function insertOverLay(id, className){
	tmpStartHeight = $(document.body).getHeight();
	//document.body.style.overflow = "hidden";
	
	$(document.body).insert("<div class='" + className + "' id='" + id + "'>&nbsp;</div>");
	
	resizeOverLay('overlay', 'outterContainer');
	
	setVisibilityBySelector('select', 'hidden');
}

function insertOverLayContentContainer(id, className, headerText){
	htmlOutput  = '<div class="' + className + '" id="' + id + '">';
	htmlOutput += "<div class='header'>" + headerText + "</div>";
	htmlOutput += '<div class="right"><a href="javascript:removeOverLay()">Close</a></div>';
	htmlOutput += '</div>';
	$(document.body).insert(htmlOutput);
}

function removeOverLay(){
	
	if($('videoContainer')){
		$('videoContainer').closer();;
	}
	
	$('overlayContentContainer').remove();
	$('overlay').remove();
	
	setVisibilityBySelector('select', 'visible');
	//document.body.style.overflow = "";
}

function insertVideo(containerId, id, myFlashVars){
	htmlOutput = '<div style="padding:8px; background-color:#FFFFFF"><div id="' + id + '"></div></div>';	
	$(containerId).insert(htmlOutput);

	/*
	myParams = {
		wmode:"transparent",
		allowScriptAccess:'sameDomain'
	};
	*/
	myParams = 
	{
		allowScriptAccess:'sameDomain'
	};
	
	//swfobject.registerObject("mediaPlayer", "9.0.0");
	
	swfobject.embedSWF("/VF/corporation/resources/swf/Media_player.swf", id, "360", "300", "9.0.0", "/VF/corporation/resources/swf/Media_player.swf", myFlashVars, myParams);
}

function insertImage(containerId, id, src){
	
	htmlOutput = '<div style="padding:8px; background-color:#FFFFFF"><div id="' + id + '"><img src="' + src + '" alt="" onload="recenterContentContainer(\'' + containerId + '\');" /></div></div>';	
	$(containerId).insert(htmlOutput);
}

Event.observe(window, "resize", function() {
	
	if($('overlay')){
		resizeOverLay('overlay', 'outterContainer');						 
		recenterContentContainer('overlayContentContainer');
	}
});

function fixURLsToOpenInANewWindow(objContainer)
{
	/* 06.30.08 TMW changed function to get all "A" tags inside the object pased in */
	var links = $$('#' + $(objContainer).identify() + ' a'); // 2009.04.09 TMW Updte to prototype function //objContainer.getElementsByTagName("A");
	
	for(i = 0; i < links.length; i++) {
		links[i].target = "_blank";
		if (links[i].className != "black") {  // 2009.04.09 TMW only change links that are not set to black by the News Function
			links[i].className = "blue";
		}
	}
	/* 06.30.08 TMW Removed for(i = 0; i < objContainer.childNodes.length; i++)
	{
		objNode = objContainer.childNodes[i]
		if(objNode.tagName.toUpperCase() == 'A')
		{
			// Set the node's target to _blank to cause it to open a new window...
			objNode.target="_blank";
			objNode.className = "blue";
		}
		//fixURLsToOpenInANewWindow(objNode);
	}*/
}

function popUpWindow(strURL, intWidth, intHeight)
{
	intLeft = (window.screen.width - (intWidth))/2;
	intTop = (window.screen.height - (intHeight))/2;
	objWindow = window.open(strURL,'_blank', 'width=' + intWidth + ', height=' + intHeight + ', left=' + intLeft +  ', top=' + intTop + ', location=yes, titlebar=yes, toolbar=yes, fullscreen=yes, scrollbars=yes, resizable=yes, menubar=yes, status=yes');
}

blnIsIE = navigator.appName.indexOf("Internet Explorer") == -1?false:true;
function insertAtCursor(myField, myValue)
{
	//IE support
	if(blnIsIE)
	{
		if (document.selection)
		{
			myField.focus();
			sel = document.selection.createRange();
			sel.text = myValue;
		}
	}
	else
	{
		if(myField.selectionStart || myField.selectionStart == 0)
		{
			var startPos = myField.selectionStart;var endPos = myField.selectionEnd;
			myField.value = myField.value.substring(0, startPos)+ myValue+ myField.value.substring(endPos, myField.value.length);
		} 
		else 
		{
			myField.value += myValue;
		}
	}
}

// Victor - November 13, 2008 -- Trying to prevent errors resulting from copy/paste operations of titles that have special characters...
function detectAndReplaceSpecialChars(txtField)
{
	/*
		Need to replace any instances of the following symbols to their respective HTML counterpatrs...
	
		8482 = Trademark Symbol  ==> &trade;
		174 = Registered Symbol	 ==> &reg;
		169 = Copyright Symbol   ==> &copy;
		
	*/
	str = txtField.value;
	
	specialChar = String.fromCharCode(8482);
	specialCharPattern = new RegExp(specialChar, "g");
	str = str.replace(specialCharPattern, "&trade;");
	
	specialChar = String.fromCharCode(174);
	specialCharPattern = new RegExp(specialChar, "g");
	str = str.replace(specialCharPattern, "&reg;");
	
	specialChar = String.fromCharCode(169);
	specialCharPattern = new RegExp(specialChar, "g");
	str = str.replace(specialCharPattern, "&copy;");

	// Set the clean value back to the field...
	txtField.value = str;
}
