// JavaScript Document
var isMouseDown = false;
var tempX = 0;
var tempY = 0;
var topZ = 3


function DisplayDiv(divID,toppos,leftpos)
{
	DivOnTop(divID);
	document.getElementById(divID).style.top = toppos;
	document.getElementById(divID).style.left = leftpos;
	//document.getElementById(divID).style.display = 'block';
	new Effect.Grow(divID);
	new Draggable(divID,{handle:divID + '-handle'});

}

function HideDiv(divID)
{
	//document.getElementById(divID).style.display = 'none';
	Effect.Shrink(divID);
}

function startMove()
{
	isMouseDown = true;
	tempX = 0;
	tempY = 0;
}

function stopMove()
{
	isMouseDown = false;
	tempX = 0;
	tempY = 0;
}

function DivOnTop(divID)
{
	topZ += 1;
	document.getElementById(divID).style.zIndex = topZ;
}


function MoveDiv(divID, mouseX, mouseY)
{
	if (isMouseDown)
	{
		var xChange = 0;
		var yChange = 0;
		if (tempX != 0)
		{
			xChange = mouseX - tempX;
		}
		if (tempY != 0)
		{
			yChange = mouseY - tempY;
		}
		tempX = mouseX;
		tempY = mouseY;
		var valTop = parseInt(document.getElementById(divID).style.top.substr(0,document.getElementById(divID).style.top.indexOf('px'))) + yChange;
		var valLeft = parseInt(document.getElementById(divID).style.left.substr(0,document.getElementById(divID).style.left.indexOf('px'))) + xChange;
		document.getElementById(divID).style.top = valTop + 'px';
		document.getElementById(divID).style.left = valLeft + 'px';
	}
}

function openWindow(elName,elID, elWidth, elHeight, content, posX, posY)
{
		win = new Window(elID,{className: "alphacube", title: elName,width: elWidth, height: elHeight, top: posY, left: posX, destroyOnClose: true, showEffect: Effect.Grow, hideEffect: Effect.Shrink, resizable: true, closable: true, draggable: true});
		win.setHTMLContent(content);
		win.show(false);
}

function openURLWindow(elName,elID, elWidth, elHeight, aURL, posX, posY)
{
		win = new Window(elID,{className: "alphacube", title: elName,width: elWidth, height: elHeight, top: posY, left: posX, destroyOnClose: true, showEffect: Effect.Grow, hideEffect: Effect.Shrink, resizable: true, closable: true, draggable: true});
		win.setURL(aURL);
		win.show(false);
}

function displayPDFPopUp(elName,elID, elWidth, elHeight, posX, posY,thePDF)
{
	topZ += 1;
	var pdfViewer = document.createElement("Object");
	pdfViewer.setAttribute('id','objectreader_' + elID);
	pdfViewer.setAttribute('type','application/pdf');
	pdfViewer.setAttribute('width', (elWidth - 10));
	pdfViewer.setAttribute('height', (elHeight - 45));
	pdfViewer.setAttribute('data', thePDF);
	//Your Adobe Reader&reg; is not compatible with this feature, please <a href="<%=LinkPrefix & Application("Full_Server_Path")%>/media/pdf/<%=Request("pdf")%>" target="_blank">click here</a> to view the content.
	try {
		pdfViewer.setAttribute('innerHTML', '<br ' + '\/><p>Your Adobe Reader&reg; is not compatible with this feature, please <' + 'a href="' + thePDF + '" target="_blank">click here<' + '\/a> to view the content.<' + '\/p><br ' + '\/>');
	}
	catch (e) {
		pdfViewer.setAttribute('altHTML', '<br ' + '\/><p>Your Adobe Reader&reg; is not compatible with this feature, please <' + 'a href="' + thePDF + '" target="_blank">click here<' + '\/a> to view the content.<' + '\/p><br ' + '\/>');
	}
	//window.alert(pdfViewer.outerHTML);
	openWindow (elName,elID, elWidth, elHeight, pdfViewer.outerHTML, posX, posY);
}  //displayPDFPopUp

function displaySWFPopUp(elName,elID, elWidth, elHeight, posX, posY,theSWF,theFlash)
{
	topZ += 1;
	var swfViewer = document.createElement("Object");
	swfViewer.setAttribute('id', 'objectplayer_' + elID);
	swfViewer.setAttribute('type', 'application/swf');
	swfViewer.setAttribute('classid', 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000');
	swfViewer.setAttribute('codebase', 'http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,18,0');
	swfViewer.setAttribute('width', (elWidth - 10));
	swfViewer.setAttribute('height', (elHeight - 45));
	swfViewer.setAttribute('style', 'border-right:0;');
	var param0 = document.createElement("param");
	param0.setAttribute("name", "movie");
	param0.setAttribute("value", theSWF);
	var param1 = document.createElement("param");
	param1.setAttribute("name", "salign");
	param1.setAttribute("value", "lt");
	var param2 = document.createElement("param");
	param2.setAttribute("name", "quality");
	param2.setAttribute("value", "high");
	var param3 = document.createElement("param");
	param3.setAttribute("name", "scalar");
	param3.setAttribute("value", "noscale");
	var param4 = document.createElement("param");
	param4.setAttribute("name", "autoStart");
	param4.setAttribute("value", false);
	var param5 = document.createElement("param");
	param5.setAttribute("name", "showControls");
	param5.setAttribute("value", "true");
	var param6 = document.createElement("param");
	param6.setAttribute("name", "loop");
	param6.setAttribute("value", "false");
	var param7 = document.createElement("param");
	param7.setAttribute("name", "controller");
	param7.setAttribute("value", "true");			
	var param8 = document.createElement("param");
	param8.setAttribute("name", "wmode");
	param8.setAttribute("value", "transparent");			
	var param9 = document.createElement("param");
	param9.setAttribute("name", "FlashVars");
	param9.setAttribute("value", theFlash);			
	/*
	var param8 = document.createElement("param");
	param8.setAttribute("name", "content-type");
	param8.setAttribute("value", "audio/mp4");
	*/				
	swfViewer.appendChild(param0);
	swfViewer.appendChild(param1);
	swfViewer.appendChild(param2);
	swfViewer.appendChild(param3);
	swfViewer.appendChild(param4);
	swfViewer.appendChild(param5);
	swfViewer.appendChild(param6);
	swfViewer.appendChild(param7);
	swfViewer.appendChild(param8);
	swfViewer.appendChild(param9);
//			object.appendChild(param8);			
	embed = document.createElement("embed");
	embed.setAttribute("src", theSWF);
	embed.setAttribute("loop", "false");
//	embed.setAttribute("pluginspage", "http://microsoft.com/windows/mediaplayer/en/download/");
	embed.setAttribute("autostart", false);
	embed.setAttribute("showcontrols", "true");
	embed.setAttribute("controller", "true");
	embed.setAttribute("quality", "high");
	embed.setAttribute("scale", "noscale");
	embed.setAttribute("menu", "true");
	embed.setAttribute("autostart", "false");
	embed.setAttribute("salign", "LT");
	embed.setAttribute("type","application/x-shockwave-flash");
	embed.setAttribute("pluginspage", "http://www.macromedia.com/go/getflashplayer");
	embed.setAttribute("wmode", "transparent");
	embed.setAttribute("width", (elWidth - 10));
	embed.setAttribute("height", (elHeight - 45));
	embed.setAttribute("flashvars",theFlash);
//			embed.setAttribute("content-type", "audio/mp4");			
	//Your Adobe Reader&reg; is not compatible with this feature, please <a href="<%=LinkPrefix & Application("Full_Server_Path")%>/media/pdf/<%=Request("pdf")%>" target="_blank">click here</a> to view the content.
	try {
		swfViewer.setAttribute('innerHTML', '<br ' + '\/><p>Your Adobe Flash Playerer&reg; is not compatible with this feature, please <' + 'a href="http://get.adobe.com/flashplayer/?promoid=BUIGP" target="_blank">click here<' + '\/a> to download the latest player.<' + '\/p><br ' + '\/>');
	}
	catch (e) {
		swfViewer.setAttribute('altHTML', '<br ' + '\/><p>Your Adobe Flash Playerer&reg; is not compatible with this feature, please <' + 'a href="http://get.adobe.com/flashplayer/?promoid=BUIGP" target="_blank">click here<' + '\/a> to download the latest player.<' + '\/p><br ' + '\/>');
	}
	//window.alert(pdfViewer.outerHTML);
	var content;
	try
	{
		swfViewer.appendChild(embed);
		var tempDiv = document.createElement("Div");
		tempDiv.appendChild(swfViewer);
		content = tempDiv.innerHTML;
	}
	catch (e)
	{
		content = embed.outerHTML;
	}
	openWindow (elName,elID, elWidth, elHeight, content, posX, posY);
}  //displayPDFPopUp


/*
Below is the suggested structure for the moveable div

<div id="divName" style="position:absolute; z-index:3; display:none; border-top:2px solid black;  border-left:2px solid black; border-right:3px solid black; border-bottom:3px solid black; width:75%; background-color:#FFFFFF; font-size:18px;">
	<div style="background-color:#E5E5E5; width:100%;" onmousedown="DivOnTop('divName');startMove()" onmouseup="stopMove()" onmouseout="stopMove()" onmousemove="MoveDiv('divName',event.clientX,event.clientY)">
		<button type="button" onclick="HideDiv('divName')" style="position:relative; top:0; right: 20px; float:right; background-color:red; color:white; font-weight: bold; border:2px solid white;">X</button>
		&nbsp;
	</div>
</div>

*/