/****************************************************************************
 * Code for browser detection                                               *
 ****************************************************************************/

var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie3    = (is_ie && (is_major < 4));
var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
var is_ie4up  = (is_ie && (is_major >= 4));
var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);
var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );

if (!is_ie6up || !is_win) 
{ 
	alert("Attention, cette animation est prévue pour fonctionner sous Internet Explorer 6.\nIl semblerait que votre navigateur ne soit pas compatible.");
}

/****************************************************************************
 * General purpose DHTML functions                                          *
 ****************************************************************************/

// function to retrive x coordinate of mouse
function getMouseLeft(evt)
{
	if(document.all)
		return window.event.clientX + document.body.scrollLeft;
	else if(document.getElementById || document.layers)
		return evt.pageX; 
}

// function to retrive x coordinate of mouse
function getMouseTop(evt)
{
	if(document.all)
		return window.event.clientY + document.body.scrollTop;
	else if(document.getElementById || document.layers)
		return evt.pageY; 
}

// Function to get object reference to the given object
function getObj(obj)
{
	if (document.layers) 
	{
		if (typeof obj == "string") 
		{
			return document.layers[obj]
		} 
		else 
		{
			return obj
		}
	}
	if (document.all) 
	{
		if (typeof obj == "string") 
		{
			return document.all(obj)
		} 
		else 
		{
			return obj
		}
	}
	if (document.getElementById) 
	{
		if (typeof obj == "string") 
		{
			return document.getElementById(obj)
		} 
		else 
		{
			return obj
		}
	}
	return null	
}

// position an object at a specific pixel coordinate
function shiftTo(obj, x, y) 
{
	obj = getObj(obj)
	
	if (obj.moveTo) 
	{
		obj.moveTo(x,y)
	} 
	else if (typeof obj.style.left != "undefined") 
	{
		obj.style.left = x
		obj.style.top = y
	}
}


// Function to show object
function showObj(obj)
{
	obj = getObj(obj);
	if(document.all || document.getElementById)
		obj.style.visibility = "visible";
	else if (document.layers)
		obj.visibility = "show";	
}

// Function to hide object
function hideObj(obj)
{
	obj = getObj(obj);
	if(document.all || document.getElementById)
		obj.style.visibility = "hidden";
	else if (document.layers)
		obj.visibility = "hide";	
}

// Function to write text in div
function printHTML(obj, textToWrite)
{
	obj = getObj(obj);
	if(document.all || document.getElementById)
	{
		obj.innerHTML = textToWrite;
	}
	else if (document.layers)
	{
		obj.document.open();
		obj.document.write(textToWrite);
		obj.document.close();		
	}
}


/****************************************************************************
 * HTML user interface related functions                                    * 
 ****************************************************************************/
function setStatus(message)
{
	document.all("status_div").innerHTML = message;	
	window.status = "";
}

/*FLOLOCATION
function updateLocationBox()
{
	// First index is description text
	for(i = 0; i < WebViewer.GetNamedLocationCount(); i++)
	{
		locations.options[i + 1] = new Option(WebViewer.GetNamedLocationByIndex(i))
	}
}


function changeLocation()
{
	if (locations.selectedIndex > 0)
	{
		WebViewer.SetNamedLocation(locations.options[locations.selectedIndex].text);
		setStatus("Location " + locations.options[locations.selectedIndex].text + " is now set");
	}
}
*/

function showToolTip(message)
{
	showObj("tooltip_div");
	printHTML("tooltip_div", "&nbsp;" + message + "&nbsp;");
	shiftTo("tooltip_div", getMouseLeft() + 20, getMouseTop() + 5);
	window.status = "";
}


function showToolTipAt(message, x, y)
{
	showObj("tooltip_div");
	printHTML("tooltip_div", "&nbsp;" + message + "&nbsp;");
	shiftTo("tooltip_div", x, y);
	window.status = "";
}


function hideToolTip()
{
	hideObj("tooltip_div");
	window.status = "";
}


/****************************************************************************
 * Background color functions                                               *
 ****************************************************************************/
function setBackground()
{
	colorsObj = backcolors	

	if (colorsObj.selectedIndex == 0)
	{
		setDefaultColors();
		setStatus('Black background set');
	}
	else if (colorsObj.selectedIndex == 1)
	{
		setBlueColors();
		setStatus('Blue background set');
	}
	else if (colorsObj.selectedIndex == 2)
	{
		setLightColors();
		setStatus('White background set');
	}
}


function setDefaultColors()
{
      /* parameters are for WebViewer.setClassColor class, state, r, g, b, a
         normally state = 0, and a = 1.0
         default line colors should be solid-color / 2 instead of white */

	WebViewer.setBackgroundColor(0.0, 0.0, 0.0)
	WebViewer.setClassColor(SOLIDCOLOR, 1,0, 0.7, 0.7, 0.7,1.0)
	WebViewer.setClassColor(LINECOLOR, 1,0, 0.49, 0.49, 0.49,1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 2,0, 0.9, 0.0, 0.0,1.0)
	WebViewer.setClassColor(LINECOLOR, 2,0, 0.81, 0.0, 0.0,1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 3,0, 0.3, 0.9, 0.3,1.0)
	WebViewer.setClassColor(LINECOLOR, 3,0, 0.09, 0.81, 0.09,1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 4,0, 0.0, 0.3, 0.9,1.0)
	WebViewer.setClassColor(LINECOLOR, 4,0, 0.0, 0.09, 0.81,1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 5,0, 0.3, 0.9, 0.9,1.0)
	WebViewer.setClassColor(LINECOLOR, 5,0, 0.09, 0.81, 0.81,1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 6,0, 0.9, 0.9, 0.2,1.0)
	WebViewer.setClassColor(LINECOLOR, 6,0, 0.81, 0.81, 0.04,1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 7,0, 0.9, 0.0, 0.9,1.0)
	WebViewer.setClassColor(LINECOLOR, 7,0, 0.81, 0.0, 0.81,1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 8,0, 0.4, 0.4, 0.4,1.0)
	WebViewer.setClassColor(LINECOLOR, 8,0, 0.16, 0.16, 0.16,1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 9,0, 0.7, 0.2, 0.3,1.0)
	WebViewer.setClassColor(LINECOLOR, 9,0, 0.49, 0.04, 0.09,1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 10,0, 0.4, 0.7, 0.2,1.0)
	WebViewer.setClassColor(LINECOLOR, 10,0, 0.16, 0.49, 0.04,1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 11,0, 0.2, 0.6, 0.7,1.0)
	WebViewer.setClassColor(LINECOLOR, 11,0, 0.04, 0.36, 0.49,1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 12,0, 0.8, 0.4, 0.9,1.0)
	WebViewer.setClassColor(LINECOLOR, 12,0, 0.64, 0.16, 0.81,1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 13,0, 0.9, 0.4, 0.0,1.0)
	WebViewer.setClassColor(LINECOLOR, 13,0, 0.81, 0.16, 0.0,1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 14,0, 0.6, 0.3, 0.0,1.0)
	WebViewer.setClassColor(LINECOLOR, 14,0, 0.36, 0.09, 0.0,1.0)
}


function setLightColors()
{
      /* parameters are for WebViewer.setClassColor class, state, r, g, b, a
         normally state = 0, and a = 1.0 */

	WebViewer.setBackgroundColor(1.0, 1.0, 1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 1, 0, 0.7, 0.7, 0.7, 1.0)
	WebViewer.setClassColor(LINECOLOR,  1, 0, 0.85, 0.85, 0.85, 1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 2, 0, 0.9, 0.0, 0.0, 1.0)
	WebViewer.setClassColor(LINECOLOR,  2, 0, 0.95, 0.5, 0.5, 1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 3, 0, 0.3, 0.9, 0.3, 1.0)
	WebViewer.setClassColor(LINECOLOR,  3, 0, 0.65, 0.95, 0.65, 1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 4, 0, 0.0, 0.3, 0.9, 1.0)
	WebViewer.setClassColor(LINECOLOR,  4, 0, 0.5, 0.65, 0.95, 1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 5, 0, 0.3, 0.9, 0.9, 1.0)
	WebViewer.setClassColor(LINECOLOR,  5, 0, 0.65, 0.95, 0.95, 1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 6, 0, 0.9, 0.9, 0.2, 1.0)
	WebViewer.setClassColor(LINECOLOR,  6, 0, 0.95, 0.95, 0.6, 1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 7, 0, 0.9, 0.0, 0.9, 1.0)
	WebViewer.setClassColor(LINECOLOR,  7, 0, 0.95, 0.5, 0.95, 1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 8, 0, 0.4, 0.4, 0.4, 1.0)
	WebViewer.setClassColor(LINECOLOR,  8, 0, 0.7, 0.7, 0.7, 1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 9, 0, 0.7, 0.2, 0.3, 1.0)
	WebViewer.setClassColor(LINECOLOR,  9, 0, 0.85, 0.6, 0.65, 1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 10, 0, 0.4, 0.7, 0.2, 1.0)
	WebViewer.setClassColor(LINECOLOR,  10, 0, 0.7, 0.85, 0.6, 1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 11, 0, 0.2, 0.6, 0.7, 1.0)
	WebViewer.setClassColor(LINECOLOR,  11, 0, 0.6, 0.8, 0.85, 1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 12, 0, 0.8, 0.4, 0.9, 1.0)
	WebViewer.setClassColor(LINECOLOR,  12, 0, 0.9, 0.7, 0.95, 1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 13, 0, 0.9, 0.4, 0.0, 1.0)
	WebViewer.setClassColor(LINECOLOR,  13, 0, 0.95, 0.7, 0.5, 1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 14, 0, 0.6, 0.3, 0.0, 1.0)
	WebViewer.setClassColor(LINECOLOR,  14, 0, 0.8, 0.65, 0.5, 1.0)
}


function setBlueColors() 
{
      /* parameters are for WebViewer.setClassColor class, state, r, g, b, a
         normally state = 0, and a = 1.0
         default line colors should be solid-color / 2 instead of white */

	WebViewer.setBackgroundColor(0.2, 0.2, 0.5)
	WebViewer.setClassColor(SOLIDCOLOR, 1,0, 0.7, 0.7, 0.7,1.0)
	WebViewer.setClassColor(LINECOLOR, 1,0, 0.45, 0.45, 0.75,1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 2,0, 0.9, 0.0, 0.0,1.0)
	WebViewer.setClassColor(LINECOLOR, 2,0, 0.55, 0.1, 0.4,1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 3,0, 0.3, 0.9, 0.3,1.0)
	WebViewer.setClassColor(LINECOLOR, 3,0, 0.25, 0.55, 0.55,1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 4,0, 0.0, 0.3, 0.9,1.0)
	WebViewer.setClassColor(LINECOLOR, 4,0, 0.1, 0.25, 0.85,1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 5,0, 0.3, 0.9, 0.9,1.0)
	WebViewer.setClassColor(LINECOLOR, 5,0, 0.25, 0.55, 0.85,1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 6,0, 0.9, 0.9, 0.2,1.0)
	WebViewer.setClassColor(LINECOLOR, 6,0, 0.55, 0.55, 0.5,1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 7,0, 0.9, 0.0, 0.9,1.0)
	WebViewer.setClassColor(LINECOLOR, 7,0, 0.55, 0.1, 0.85,1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 8,0, 0.4, 0.4, 0.4,1.0)
	WebViewer.setClassColor(LINECOLOR, 8,0, 0.3, 0.3, 0.6,1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 9,0, 0.7, 0.2, 0.3,1.0)
	WebViewer.setClassColor(LINECOLOR, 9,0, 0.45, 0.2, 0.55,1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 10,0, 0.4, 0.7, 0.2,1.0)
	WebViewer.setClassColor(LINECOLOR, 10,0, 0.3, 0.45, 0.5,1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 11,0, 0.2, 0.6, 0.7,1.0)
	WebViewer.setClassColor(LINECOLOR, 11,0, 0.2, 0.4, 0.75,1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 12,0, 0.8, 0.4, 0.9,1.0)
	WebViewer.setClassColor(LINECOLOR, 12,0, 0.5, 0.3, 0.85,1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 13,0, 0.9, 0.4, 0.0,1.0)
	WebViewer.setClassColor(LINECOLOR, 13,0, 0.55, 0.3, 0.4,1.0)
	WebViewer.setClassColor(SOLIDCOLOR, 14,0, 0.6, 0.3, 0.0,1.0)
	WebViewer.setClassColor(LINECOLOR, 14,0, 0.4, 0.25, 0.4,1.0)
}

/****************************************************************************
 * Images for mouseover efects.                                             *
 ****************************************************************************/

var panOnImage = new Image();
var panOffImage = new Image();
var rotateOnImage = new Image();
var rotateOffImage = new Image();
var flyOnImage = new Image();
var flyOffImage = new Image();
var centerOnImage = new Image();
var centerOffImage = new Image();
var homeOnImage = new Image();
var homeOffImage = new Image();
var cancelOnImage = new Image();
var cancelOffImage = new Image();
var captureOnImage = new Image();
var captureOffImage = new Image();

panOnImage.src = "images/pan_button_on.gif";
panOffImage.src = "images/pan_button.gif";
rotateOnImage.src = "images/rotate_button_on.gif";
rotateOffImage.src = "images/rotate_button.gif";
flyOnImage.src = "images/fly_button_on.gif";
flyOffImage.src = "images/fly_button.gif";
centerOnImage.src = "images/center_button_on.gif";
centerOffImage.src = "images/center_button.gif";
homeOnImage.src = "images/home_button_on.gif";
homeOffImage.src = "images/home_button.gif";
cancelOnImage.src = "images/cancel_button_on.gif";
cancelOffImage.src = "images/cancel_button.gif";
captureOnImage.src = "images/capture_button_on.gif";
captureOffImage.src = "images/capture_button.gif";

/****************************************************************************
 * WebViewer command functions                                              *
 ****************************************************************************/

function showSnapShotForm()
{
	showObj(snapshot_div);
	hideObj("button_div");
}

function getSnapshot()
{
	WebViewer.copyBitmapToClipboard();
	setStatus('Model copied to the clipboard');
	hideObj('snapshot_div');
	showObj('button_div');
}

var helpWindow;
function openHelp()
{
	if (helpWindow)
		helpWindow.close();

	helpWindow = window.open("help/sys_import_receiving_webviewer_models.html","help","width=650,height=665,resizable=yes, scrollbars=yes");
}

function mailTextLink()
{
	textLink = WebViewer.getCurrentLocationAsString();
	url = "mailto:?body=" + escape(textLink) + "&subject=" + escape(textLink);
	location = url;
}

function mailUrl()
{
	urlLink = " " + parseModelUrl("index.html") + "?" + WebViewer.getCurrentLocationAsUrlParameter();
	url = "mailto:?body=" + escape(urlLink) + "&subject=" + escape(urlLink);
	location = url;
}

function setLocationByURL()
{
	WebViewer.setCurrentLocationFromUrlParameter(unescape(location.search));
}

// Variable for storing CGI value given in URL
var vpoint
function initialize()
{
	if (WebViewer.INTERACTORMODE)
	{
		WebViewer.loadData(parseModelUrl("1.zsol"));
		/*FLOLOCATION
		updateLocationBox();
		*/
		WebViewer.INTERACTORMODE = INTERACTOR_MODE_PRE_PAN;
		
		if (location.search.length != 0)
			setTimeout("setLocationByURL()", 400);
	}
	else
		setTimeout ("initialize()", 100);
}
