function hookMouseWheel() {
	if (window.addEventListener)
	window.addEventListener('DOMMouseScroll', onMouseWheel, false);
	window.onmousewheel = document.onmousewheel = onMouseWheel;
}

function isOverSwf(mEvent) {
	var elem;
	if (mEvent.srcElement) {
		Elem = mEvent.srcElement;
	} else if (mEvent.target) {
		Elem = mEvent.target;
	}

	if ((elem.nodeName.toLowerCase() == "object" &&
		Elem.getAttribute("classid") == "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000") ||
		(elem.nodeName.toLowerCase() == "embed" &&
		Elem.getAttribute("type") == "application/x-shockwave-flash")) {
		Elem.focus();
		return true;
	}

	return false;
}

function onMouseWheel(event) {
	if (!event)
		Event = window.event;

		if (isOverSwf(event)) {
			return cancelEvent(event);
		}

	return true;
}

function cancelEvent(e) {
	e = e ? e : window.event;
	if (e.stopPropagation)
		e.stopPropagation();
	if (e.preventDefault)
		e.preventDefault();
	e.cancelBubble = true;
	e.cancel = true;
	e.returnValue = false;
	return false;
}

function getFlexApp(appName)
{
  if (navigator.appName.indexOf ("Microsoft") !=-1)
  {
    return window[appName];
  }
  else
  {
    return document[appName];
  }
}

function updateFromCropField()
{
	//alert("updateFromCropField");
	var val = parent.document.getElementById(cropFieldID).value;
	updateViewer(val);
}

function initialupdateViewer()
{
	var val= document.getElementById("FloViewerSelectionToolValues").value;
	updateViewer(val);
}

function updatePage()
{
	getFlexApp('FloView').refreshPage();
}

function updateViewer(val)
{
	getFlexApp('FloView').updateSelectionJS(val);
}

function AnnotationsSetXML(val)
{
	getFlexApp('FloView').AnnotationsSetXML(val);
}

function AnnotationsGetXML()
{
	return getFlexApp('FloView').AnnotationsGetXML();
	
}

function attachChat()
{
	getFlexApp('FloView').attachChat();
}

function detachChat()
{
	window.open("/FLOCommunicator/FLOCommunicator.html", "FLO Communicator","status=1,toolbar=1"); ;
}

function updateInput(val)
{
	document.getElementById("FloViewerSelectionToolValues").setAttribute("value", val);
	var l = val.split(";")[0];
	var t = val.split(";")[1];
	var r = val.split(";")[2];
	var b = val.split(";")[3];
	updateForm(l, t, r, b, 0);
}

function createHotspot(hsCoords , hsAction, hsTooltip, hsPage)
{
	var val = document.getElementById("FloViewerHotspotCreator").value;
	val += "$";
	val += hsCoords + "##" + hsAction + "##" + hsTooltip + "##" + hsPage;
	document.getElementById("FloViewerHotspotCreator").setAttribute("value", val);
}

function undoHotspot(hsCoords , hsAction, hsTooltip, hsPage)
{
	var val= document.getElementById("FloViewerHotspotCreator").value;
	val2: String;
	val2 = "$";
	val2 += hsCoords + "#" + hsAction + "#" + hsTooltip + "#" + hsPage;
	val.replace(val2, "");
	
	document.getElementById("FloViewerHotspotCreator").setAttribute("value", val);
}

function onCropLoad()
{
	try
	{
		if (parent.vUseCrop)
			useCrop = true;
	}
	catch (e)
	{}
	if (window.location.href.indexOf('crop=true') >= 0)
		useCrop = true;
	
	if(cropFieldID != "")
	{
		updateInput(parent.document.getElementById(cropFieldID).value);
		parent.document.getElementById(cropFieldID).onchange = updateFromCropField;	
	}
	
}

function saveAnnotations(xml)
{
	xml = xml.replace(/"/g, "&quote;")
	parent.document.getElementById("annotations").setAttribute("value",xml);
}

function annotationsSaved(xml)
{
	parent.annotionsSavedInFlash(xml);
}

function AnnotationsNext()
{
	parent.AnnotationsNext();
}

function AnnotationsPrevious()
{
	parent.AnnotationsPrevious();
}

function AnnotationsCancel()
{
	parent.AnnotationsCancel();
}

function attachChat()
{
	getFlexApp('FloView').attachChat();
}

function detachChat()
{
	window.open("/FLOCommunicator/FLOCommunicator.html", "FLO Communicator","status=1,toolbar=1"); ;
}
//FSI EMULATION

function getCropString(){
	var form = document.cropForm;
	return "1,1,"+form.left.value+","+form.top.value+","+form.right.value+","+form.bottom.value+','+form.rotate.value;
}

function UpdateCropRect()
{
	if (cropFieldID == "")
		parent.fUpdateCropRect();
	else
	{
	
		var val = parent.document.getElementById(cropFieldID).value;
		if (val == "")
		{
			val = "0;0;1;1"
		}
		
		document.cropForm.left.value = val.split(";")[0];
		document.cropForm.top.value = val.split(";")[1];
		document.cropForm.right.value = val.split(";")[2];
		document.cropForm.bottom.value = val.split(";")[3];
		
		updateViewer(val)
	}
}

function updateForm(l, t, r, b, rot)
{			
			var form = document.cropForm;
			form.left.value = l;
			form.top.value = t;
			form.right.value = r;
			form.bottom.value = b;
			
			if (cropFieldID == "")
			{
				parent.document.getElementById("txtCropLeft").setAttribute("value", l * 100);
				parent.document.getElementById("txtCropRight").setAttribute("value", r * 100);
				parent.document.getElementById("txtCropTop").setAttribute("value", t * 100);
				parent.document.getElementById("txtCropBottom").setAttribute("value", b * 100);
			}
			else
			{
				window.parent.document.getElementById(cropFieldID).setAttribute("value", l + ";" + t + ";" + r + ";" + b);
			}
}