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, width, height){
	if(!headerText)
	{
		headerText = '';	
	}
	
	insertOverLay('overlay', 'overlay');
	insertOverLayContentContainer('overlayContentContainer', 'overlayContentContainer', headerText);
	
	type = type.toLowerCase();
	switch(type)
	{
		case "flash":
		  insertFlash('overlayContentContainer', 'imageContainer', value, width, height);
		  break;
		default:
	} 

	recenterContentContainer('overlayContentContainer');
}

function insertFlash(containerId, id, src, width, height){
	
	htmlOutput = '<div style="font-weight: bold; text-align: right;"><a href="javascript:removeOverLay()">close [x]</a></div><div style="padding:8px; background-color:#FFFFFF"><div id="' + id + '"><div id="playerdiv"></div></div></div>';	
	//$(containerId).insert(htmlOutput);
	$(containerId).innerHTML = htmlOutput;
	
	var flashvars = { videoLink: "/flash/video/homepage.flv", defaultVideo: "1", videoVolume: "75", image: "/flash/video/Default.jpg", autoplay: "false" };
	var params = {allowScriptAccess: "sameDomain", allowFullScreen: "false", quality: "high", bgcolor: "#FFFFFF", scale: "noborder", menu: "false", wmode: "transparent"};
	var attributes = {};
	swfobject.embedSWF("/flash/videoplayer.swf", "playerdiv", "320", "240", "9.0.0", "/flash/expressInstall.swf", flashvars, params, attributes);
}

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();

	if(tmpHeight1 > tmpHeight2){
		tmpHeight = tmpHeight1;
	}else{
		tmpHeight = tmpHeight2;
	}
	
	$(id).style.height = tmpHeight + "px";
}

function insertOverLay(id, className){

	$(document.body).insert("<div class='" + className + "' id='" + id + "'>&nbsp;</div>");
	
	resizeOverLay('overlay', 'outerContainer');
	
	//setVisibilityBySelector('select', 'hidden');
}
function insertOverLayContentContainer(id, className, headerText){
	htmlOutput  = '<div class="' + className + '" id="' + id + '">';
	htmlOutput += "<div class='header'>" + headerText + "</div>";
	htmlOutput += '<div style="font-weight:bold; text-align:right;"><a href="javascript:removeOverLay()">close [x]</a></div>';
	htmlOutput += '</div>';
	$(document.body).insert(htmlOutput);
}
function removeOverLay(){
	if( $('hideContent') ) {
		$('hideContent').toggle();
	}
	if( $('hideContent2') ) {
		$('hideContent2').toggle();
	}
	if($('videoContainer')){
		$('videoContainer').remove();
	}
	
	$('overlayContentContainer').remove();
	$('overlay').remove();
	
	setVisibilityBySelector('select', 'visible');
	//document.body.style.overflow = "";
}
function fixURLsToOpenInANewWindow(objContainer)
{
	for(i = 0; i < objContainer.childNodes.length; i++)
	{
		objNode = objContainer.childNodes[i]
		if(objNode.tagName == 'A')
		{
			// Set the node's target to _blank to cause it to open a new window...
			objNode.target="_blank";
			objNode.className = "blue";
		}
	}
}
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;
		}
	}
}